@fudrouter/fsrouter 0.6.107 โ 0.6.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routes/db/info/route.js +22 -0
- package/package.json +1 -1
- package/public/.vite/manifest.json +85 -85
- package/public/assets/EndpointPageClient.BN-D__UM.js +6 -0
- package/public/assets/Loading.BoU3gy5K.js +1 -0
- package/public/assets/NoAuthProxyCard.CLW2-XwE.js +89 -0
- package/public/assets/index.BO_pNnMt.js +89 -0
- package/public/assets/page.-P08pALK.js +6 -0
- package/public/assets/page.-PU2bgJe.js +1 -0
- package/public/assets/page.2bfZgPuP.js +1 -0
- package/public/assets/page.Asf9tesx.js +1 -0
- package/public/assets/page.B11lN3QC.js +1 -0
- package/public/assets/page.B1ZhgC-Y.js +1 -0
- package/public/assets/page.B28QUiM4.js +1 -0
- package/public/assets/page.BBnpNaQh.js +6 -0
- package/public/assets/page.BOy_Vt2f.js +1 -0
- package/public/assets/page.BRDONwuI.js +1 -0
- package/public/assets/page.BWFxAlAj.js +1 -0
- package/public/assets/page.BebFlAF6.js +1 -0
- package/public/assets/page.BqxsFxH_.js +2 -0
- package/public/assets/page.C1Z5-h5h.js +1 -0
- package/public/assets/page.CIxYSsJm.js +1 -0
- package/public/assets/page.CQLGTJxs.js +1 -0
- package/public/assets/page.CTO5ojlP.js +1 -0
- package/public/assets/page.CTx0rdSY.js +1 -0
- package/public/assets/page.CXAgJ2hd.js +1 -0
- package/public/assets/page.CdVrDM5I.js +1 -0
- package/public/assets/page.CgidHjOu.js +1 -0
- package/public/assets/page.CqPzqV4I.js +7 -0
- package/public/assets/page.Cr-bxDIh.js +4 -0
- package/public/assets/page.CsL3JXbA.js +1 -0
- package/public/assets/page.D6eEvzRr.js +5 -0
- package/public/assets/page.DHyqPTHy.js +1 -0
- package/public/assets/page.DS5iFEwr.js +31 -0
- package/public/assets/page.Dre9jdlU.js +1 -0
- package/public/assets/page.IyBPROCc.js +1 -0
- package/public/assets/page.KoOCODPg.js +5 -0
- package/public/assets/page.MP_9jcAE.js +1 -0
- package/public/assets/page.WAG7HQOU.js +2 -0
- package/public/assets/page.XKedaymF.js +1 -0
- package/public/assets/page.ZZHz9al1.js +64 -0
- package/public/assets/page.alTMqTdj.js +1 -0
- package/public/assets/page.tpebkgG7.js +1 -0
- package/public/assets/page.xIh7b02j.js +23 -0
- package/public/index.html +4 -4
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import{u as ze,j as e,M as Ue,B as q,w as De,x as Be,y as ke,z as He,h as We}from"./index.BO_pNnMt.js";import{b as t,L as Te,h as Je,N as qe}from"./router.Cjj1--8t.js";import{C as Le}from"./cliTools.CsdwAybi.js";import{g as Pe}from"./machine.CagOtseJ.js";import{I as Ge,M as fe,C as ge}from"./NoAuthProxyCard.CLW2-XwE.js";import{C as Ve}from"./Loading.BoU3gy5K.js";import"./zustand.akaTi5uX.js";function ye({isOpen:d,onClose:r,title:L="Manual Configuration",configs:Y=[]}){const{copy:g}=ze(),[l,A]=t.useState(null),O=(E,_)=>{g(E,`manualconfig-${_}`),A(_),setTimeout(()=>A(null),2e3)};return e.jsx(Ue,{isOpen:d,onClose:r,title:L,size:"xl",children:e.jsx("div",{className:"flex flex-col gap-4",children:Y.map((E,_)=>e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-text-main",children:E.filename}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>O(E.content,_),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:l===_?"check":"content_copy"}),l===_?"Copied!":"Copy"]})]}),e.jsx("pre",{className:"px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs overflow-x-auto whitespace-pre-wrap break-all max-h-60 overflow-y-auto border border-border",children:E.content})]},_))})})}const Ye=/^[a-zA-Z0-9_.\-]+$/;function Xe({index:d,model:r,isFirst:L,isLast:Y,onEdit:g,onMoveUp:l,onMoveDown:A,onRemove:O}){const[E,_]=t.useState(!1),[B,U]=t.useState(r),o=()=>{const i=B.trim();i&&i!==r?g(i):U(r),_(!1)},s=i=>{i.key==="Enter"&&o(),i.key==="Escape"&&(U(r),_(!1))};return e.jsxs("div",{className:"group flex min-w-0 items-center gap-1.5 rounded-md bg-black/[0.02] px-2 py-1 transition-colors hover:bg-black/[0.04] dark:bg-white/[0.02] dark:hover:bg-white/[0.04]",children:[e.jsx("span",{className:"text-[10px] font-medium text-text-muted w-3 text-center shrink-0",children:d+1}),E?e.jsx("input",{autoFocus:!0,value:B,onChange:i=>U(i.target.value),onBlur:o,onKeyDown:s,className:"min-w-0 flex-1 rounded border border-primary/40 bg-white px-1.5 py-0.5 font-mono text-xs text-text-main outline-none dark:bg-black/20"}):e.jsx("div",{className:"min-w-0 flex-1 cursor-text truncate rounded px-1.5 py-0.5 font-mono text-xs text-text-main hover:bg-black/5 dark:hover:bg-white/5",onClick:()=>_(!0),title:"Click to edit",children:r}),e.jsxs("div",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx("button",{onClick:l,disabled:L,className:`p-0.5 rounded ${L?"text-text-muted/20 cursor-not-allowed":"text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`,title:"Move up",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_upward"})}),e.jsx("button",{onClick:A,disabled:Y,className:`p-0.5 rounded ${Y?"text-text-muted/20 cursor-not-allowed":"text-text-muted hover:text-primary hover:bg-black/5 dark:hover:bg-white/5"}`,title:"Move down",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"arrow_downward"})})]}),e.jsx("button",{onClick:O,className:"p-0.5 hover:bg-red-500/10 rounded text-text-muted hover:text-red-500 transition-all",title:"Remove",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]})}function Qe({isOpen:d,combo:r,onClose:L,onSave:Y,activeProviders:g,kindFilter:l=null,forcePrefix:A="",title:O}){const E=r!=null&&r.name?A&&r.name.startsWith(A)?r.name.slice(A.length):r.name:"",[_,B]=t.useState(E),[U,o]=t.useState((r==null?void 0:r.models)||[]),[s,i]=t.useState(!1),[M,Q]=t.useState(!1),[P,K]=t.useState(""),[ee,W]=t.useState({});t.useEffect(()=>{d&&fetch("/api/models/alias").then(m=>m.ok?m.json():null).then(m=>m&&W(m.aliases||{})).catch(()=>{})},[d]);const b=m=>{if(!m.trim())return K("Name is required"),!1;const h=A+m;return Ye.test(h)?(K(""),!0):(K("Only letters, numbers, -, _ and . allowed"),!1)},y=m=>{let h=m.target.value;A&&h.startsWith(A)&&(h=h.slice(A.length)),B(h),h?b(h):K("")},w=m=>{U.includes(m.value)||o([...U,m.value])},x=m=>{o(U.filter(h=>h!==m.value))},C=m=>o(U.filter((h,v)=>v!==m)),j=m=>{if(m===0)return;const h=[...U];[h[m-1],h[m]]=[h[m],h[m-1]],o(h)},T=m=>{if(m===U.length-1)return;const h=[...U];[h[m],h[m+1]]=[h[m+1],h[m]],o(h)},p=async()=>{b(_)&&(Q(!0),await Y({name:A+_.trim(),models:U}),Q(!1))},a=!!r;return e.jsxs(e.Fragment,{children:[e.jsx(Ue,{isOpen:d,onClose:L,title:O||(a?"Edit Combo":"Create Combo"),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{children:[A?e.jsxs(e.Fragment,{children:[e.jsx("label",{className:"text-sm font-medium mb-1 block",children:"Combo Name"}),e.jsxs("div",{className:"flex items-stretch",children:[e.jsx("span",{className:"inline-flex items-center px-2 rounded-l border border-r-0 border-black/10 dark:border-white/10 bg-black/[0.04] dark:bg-white/[0.04] text-text-muted font-mono text-sm",children:A}),e.jsx("input",{value:_,onChange:y,placeholder:"my-combo",className:"flex-1 min-w-0 rounded-r border border-black/10 dark:border-white/10 bg-white dark:bg-black/20 px-2 py-1.5 font-mono text-sm outline-none focus:border-primary"})]}),P&&e.jsx("p",{className:"text-[11px] text-red-500 mt-0.5",children:P})]}):e.jsx(Ge,{label:"Combo Name",value:_,onChange:y,placeholder:"my-combo",error:P}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-0.5",children:[A?`Auto-prefixed with "${A}". `:"","Only letters, numbers, -, _ and . allowed"]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-1.5 block",children:"Models"}),U.length===0?e.jsxs("div",{className:"text-center py-4 border border-dashed border-black/10 dark:border-white/10 rounded-lg bg-black/[0.01] dark:bg-white/[0.01]",children:[e.jsx("span",{className:"material-symbols-outlined text-text-muted text-xl mb-1",children:"layers"}),e.jsx("p",{className:"text-xs text-text-muted",children:"No models added yet"})]}):e.jsx("div",{className:"flex max-h-[55vh] min-w-0 flex-col gap-1 overflow-y-auto sm:max-h-[350px]",children:U.map((m,h)=>e.jsx(Xe,{index:h,model:m,isFirst:h===0,isLast:h===U.length-1,onEdit:v=>{const I=[...U];I[h]=v,o(I)},onMoveUp:()=>j(h),onMoveDown:()=>T(h),onRemove:()=>C(h)},h))}),e.jsxs("button",{onClick:()=>i(!0),className:"w-full mt-2 py-2 border border-dashed border-black/10 dark:border-white/10 rounded-lg text-xs text-primary font-medium hover:text-primary hover:border-primary/50 transition-colors flex items-center justify-center gap-1",children:[e.jsx("span",{className:"material-symbols-outlined text-[16px]",children:"add"}),"Add Model"]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row",children:[e.jsx(q,{onClick:L,variant:"ghost",fullWidth:!0,size:"sm",children:"Cancel"}),e.jsx(q,{onClick:p,fullWidth:!0,size:"sm",disabled:!_.trim()||!!P||M,children:M?"Saving...":a?"Save":"Create"})]})]})}),e.jsx(fe,{isOpen:s,onClose:()=>i(!1),onSelect:w,onDeselect:x,activeProviders:g,modelAliases:ee,title:"Add Model to Combo",kindFilter:l,addedModelValues:U,closeOnSelect:!1})]})}const Ze="/api/cli-tools/cowork-mcp-registry",Ke="/api/cli-tools/cowork-mcp-tools";function et({isOpen:d,onClose:r,onAdd:L,addedNames:Y=[]}){const[g,l]=t.useState([]),[A,O]=t.useState(!1),[E,_]=t.useState(""),[B,U]=t.useState("all"),[o,s]=t.useState(null),[i,M]=t.useState(null),[Q,P]=t.useState({}),[K,ee]=t.useState({}),[W,b]=t.useState({});t.useEffect(()=>{d&&(g.length>0||(O(!0),fetch(Ze).then(a=>a.json()).then(a=>{a.error?s(a.error):l(a.servers||[])}).catch(a=>s(a.message)).finally(()=>O(!1))))},[d]);const y=t.useMemo(()=>new Set(Y),[Y]),w=t.useMemo(()=>{const a=E.trim().toLowerCase();return g.filter(m=>B==="authless"&&m.oauth||B==="oauth"&&!m.oauth?!1:a?(m.title||"").toLowerCase().includes(a)||(m.description||"").toLowerCase().includes(a)||(m.name||"").toLowerCase().includes(a):!0)},[g,E,B]),x=async a=>{if(!Q[a.url]){ee(m=>({...m,[a.url]:!0}));try{const h=await(await fetch(Ke,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:a.url})})).json(),v=h.tools||[],I=Array.isArray(a.toolNames)?a.toolNames:[],G=v.length>0?v.map(V=>V.name):I;P(V=>({...V,[a.url]:{tools:v,requiresAuth:!!h.requiresAuth,error:h.error}})),b(V=>({...V,[a.url]:Object.fromEntries(G.map(ae=>[ae,!0]))}))}catch(m){P(h=>({...h,[a.url]:{tools:[],error:m.message}}))}finally{ee(m=>({...m,[a.url]:!1}))}}},C=a=>{if(i===a.url){M(null);return}M(a.url),x(a)},j=(a,m)=>{b(h=>{var v;return{...h,[a]:{...h[a],[m]:!((v=h[a])!=null&&v[m])}}})},T=(a,m)=>{const h=W[a]||{};b(v=>({...v,[a]:Object.fromEntries(Object.keys(h).map(I=>[I,m]))}))},p=a=>{const m=W[a.url]||{},h=Object.keys(m).filter(v=>m[v]);L==null||L({name:a.slug||a.name,title:a.title,description:a.description,url:a.url,transport:a.transport,oauth:a.oauth,toolNames:h}),M(null)};return e.jsx(Ue,{isOpen:d,onClose:r,title:"Browse MCP Marketplace",size:"lg",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"text",value:E,onChange:a=>_(a.target.value),placeholder:"Search by name or description...",className:"flex-1 px-2 py-1.5 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50"}),e.jsxs("select",{value:B,onChange:a=>U(a.target.value),className:"px-2 py-1.5 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50",children:[e.jsx("option",{value:"all",children:"All"}),e.jsx("option",{value:"authless",children:"Authless"}),e.jsx("option",{value:"oauth",children:"OAuth"})]})]}),o&&e.jsx("div",{className:"px-2 py-1.5 rounded text-xs bg-red-500/10 text-red-600",children:o}),A&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted text-xs py-4 justify-center",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[18px]",children:"progress_activity"}),e.jsx("span",{children:"Loading registry..."})]}),!A&&e.jsxs("div",{className:"flex flex-col gap-1 max-h-[60vh] overflow-y-auto",children:[w.length===0&&e.jsx("div",{className:"text-center text-xs text-text-muted py-6",children:"No servers match filter"}),w.map(a=>{const m=y.has(a.slug||a.name),h=i===a.url,v=Q[a.url],I=K[a.url],G=W[a.url]||{},V=Object.keys(G),ae=Object.values(G).filter(Boolean).length;return e.jsxs("div",{className:"rounded border border-transparent hover:border-border",children:[e.jsxs("div",{className:"flex items-start gap-2 px-2 py-2 hover:bg-black/5 dark:hover:bg-white/5",children:[a.iconUrl?e.jsx("img",{src:a.iconUrl,alt:"",className:"size-7 rounded shrink-0 object-contain",onError:F=>{F.target.style.display="none"}}):e.jsx("div",{className:"size-7 rounded bg-surface shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-medium text-xs",children:a.title}),a.oauth?e.jsx("span",{className:"px-1 py-0.5 text-[9px] rounded bg-amber-500/10 text-amber-600",children:"OAuth"}):e.jsx("span",{className:"px-1 py-0.5 text-[9px] rounded bg-green-500/10 text-green-600",children:"Authless"}),a.toolCount>0&&e.jsxs("span",{className:"text-[10px] text-text-muted",children:[a.toolCount," tools"]})]}),a.description&&e.jsx("p",{className:"text-[10px] text-text-muted line-clamp-2 mt-0.5",children:a.description})]}),e.jsx("button",{onClick:()=>m?null:C(a),disabled:m,className:`shrink-0 px-2 py-1 rounded text-[10px] font-medium transition-colors ${m?"bg-green-500/10 text-green-600 cursor-default":h?"bg-surface border border-border text-text-muted hover:bg-black/5":"bg-primary/10 border border-primary/40 text-primary hover:bg-primary/20"}`,children:m?"Added":h?"Cancel":"+ Add"})]}),h&&e.jsxs("div",{className:"px-3 py-2 bg-surface/40 border-t border-border flex flex-col gap-2",children:[I&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted text-[10px] py-1",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin text-[14px]",children:"progress_activity"}),e.jsx("span",{children:"Probing server for tools..."})]}),!I&&(v==null?void 0:v.requiresAuth)&&e.jsx("p",{className:"text-[10px] text-amber-600 bg-amber-500/10 px-2 py-1 rounded",children:"๐ OAuth required. Add now and authenticate after Apply; tool list will be discovered after first connect."}),!I&&(v==null?void 0:v.error)&&!(v!=null&&v.requiresAuth)&&e.jsxs("p",{className:"text-[10px] text-red-600 bg-red-500/10 px-2 py-1 rounded",children:["Probe failed: ",v.error]}),!I&&V.length===0&&!(v!=null&&v.requiresAuth)&&!(v!=null&&v.error)&&e.jsx("p",{className:"text-[10px] text-text-muted",children:"No tools advertised by server."}),!I&&V.length>0&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[ae,"/",V.length," tools enabled"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{onClick:()=>T(a.url,!0),className:"text-[10px] text-primary hover:underline",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"ยท"}),e.jsx("button",{onClick:()=>T(a.url,!1),className:"text-[10px] text-primary hover:underline",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-1 max-h-40 overflow-y-auto",children:V.map(F=>e.jsxs("label",{className:"flex items-center gap-1.5 text-[10px] cursor-pointer hover:bg-black/5 dark:hover:bg-white/5 px-1 rounded",children:[e.jsx("input",{type:"checkbox",checked:!!G[F],onChange:()=>j(a.url,F),className:"size-3"}),e.jsx("span",{className:"truncate",children:F})]},F))})]}),e.jsx("button",{onClick:()=>p(a),className:"self-end px-2 py-1 rounded text-[10px] font-medium bg-primary text-white hover:bg-primary/90",children:"โ Confirm Add"})]})]},a.url)})]}),e.jsxs("div",{className:"text-[10px] text-text-muted text-right",children:[w.length," of ",g.length," servers"]})]})})}const Fe="fsrouter.cliToolEndpointPresets",ve="__custom__",Re="__save__",tt=d=>{const r=(d||"").replace(/\/+$/,"");return r?/\/v1$/.test(r)?r:`${r}/v1`:""},st=()=>{if(typeof window>"u")return[];try{const d=JSON.parse(window.localStorage.getItem(Fe)||"[]");return Array.isArray(d)?d.filter(r=>(r==null?void 0:r.name)&&(r==null?void 0:r.baseUrl)):[]}catch{return[]}},Ie=d=>{typeof window>"u"||window.localStorage.setItem(Fe,JSON.stringify(d))},lt=({requiresExternalUrl:d,tunnelEnabled:r,tunnelPublicUrl:L,tailscaleEnabled:Y,tailscaleUrl:g,cloudEnabled:l,cloudUrl:A,savedPresets:O,withV1:E})=>{const _=[],B=U=>E?tt(U):(U||"").replace(/\/+$/,"");if(!d){const U=B(`http://127.0.0.1:${De()}`);_.push({value:"local",label:U,url:U})}if(r&&L){const U=B(L);_.push({value:"tunnel",label:U,url:U})}if(Y&&g){const U=B(g);_.push({value:"tailscale",label:U,url:U})}if(l&&A){const U=B(A);_.push({value:"cloud",label:U,url:U})}return O.forEach(U=>{_.push({value:`saved:${U.name}`,label:U.baseUrl,url:U.baseUrl,saved:!0})}),_.push({value:ve,label:"Custom URL...",url:""}),_};function je({value:d,onChange:r,requiresExternalUrl:L=!1,tunnelEnabled:Y=!1,tunnelPublicUrl:g="",tailscaleEnabled:l=!1,tailscaleUrl:A="",cloudEnabled:O=!1,cloudUrl:E="",withV1:_=!0}){const[B,U]=t.useState([]),[o,s]=t.useState(""),[i,M]=t.useState(""),Q=t.useRef(!1);t.useEffect(()=>{U(st())},[]);const P=t.useMemo(()=>lt({requiresExternalUrl:L,tunnelEnabled:Y,tunnelPublicUrl:g,tailscaleEnabled:l,tailscaleUrl:A,cloudEnabled:O,cloudUrl:E,savedPresets:B,withV1:_}),[L,Y,g,l,A,O,E,B,_]);t.useEffect(()=>{if(Q.current||P.length===0)return;Q.current=!0;const x=P.find(C=>C.value!==ve);x?(s(x.value),r(x.url)):s(ve)},[P,r]);const K=x=>{const C=x.target.value;if(C===Re){const T=(d||"").trim();if(!T)return;let p=T;try{p=new URL(T).host}catch{}const a=window.prompt("Save endpoint as:",p);if(!(a!=null&&a.trim()))return;const m=[...B.filter(h=>h.name!==a.trim()),{name:a.trim(),baseUrl:T}].sort((h,v)=>h.name.localeCompare(v.name));U(m),Ie(m);return}if(s(C),C===ve){M(""),r("");return}const j=P.find(T=>T.value===C);j&&r(j.url)},ee=x=>{const C=x.target.value;M(C),r(C)},W=()=>{if(!o.startsWith("saved:"))return;const x=o.slice(6),C=B.filter(j=>j.name!==x);U(C),Ie(C),s(ve),M(""),r("")},b=o.startsWith("saved:"),y=o===ve,w=y&&(i||"").trim().length>0;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("select",{value:o,onChange:K,className:"flex-1 min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[P.map(x=>e.jsx("option",{value:x.value,children:x.label},x.value)),w&&e.jsx("option",{value:Re,children:"+ Save current as..."})]}),b&&e.jsx("button",{type:"button",onClick:W,className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors shrink-0",title:"Delete saved endpoint",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"delete"})})]}),y&&e.jsx("input",{type:"text",value:i,onChange:ee,placeholder:_?"https://example.com/v1":"https://example.com",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}const we="__custom__";function be({value:d,onChange:r,apiKeys:L=[],cloudEnabled:Y=!1,className:g=""}){const l=!L.some(s=>s.key===d)&&d!=="",[A,O]=t.useState(()=>d?L.some(s=>s.key===d)?d:we:L.length>0?L[0].key:we),[E,_]=t.useState(l?d:""),B=s=>{const i=s.target.value;O(i),i===we?(_(""),r("")):r(i)},U=s=>{const i=s.target.value;_(i),r(i)};return L.length===0&&A!==we&&A!==we?e.jsx("span",{className:`min-w-0 rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5 ${g}`,children:Y?"No API keys - Create one in Keys page":"sk_fsrouter (default)"}):e.jsxs("div",{className:`flex flex-col gap-1.5 ${g}`,children:[e.jsxs("select",{value:A,onChange:B,className:"w-full min-w-0 px-2 py-2 bg-surface rounded text-xs border border-border focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5",children:[L.map(s=>e.jsx("option",{value:s.key,children:s.key},s.id)),e.jsx("option",{value:we,children:"Custom..."})]}),A===we&&e.jsx("input",{type:"text",value:E,onChange:U,placeholder:"sk-...",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"})]})}const Se=d=>(d||"").replace(/\/+$/,"");function Ne(d,r={}){if(!d)return!1;const L=Se(d),{tunnelPublicUrl:Y,tailscaleUrl:g,cloudUrl:l}=r;return!!(/localhost|127\.0\.0\.1|0\.0\.0\.0/.test(L)||Y&&L.startsWith(Se(Y))||g&&L.startsWith(Se(g))||l&&L.startsWith(Se(l)))}var rt={};const at=rt.NEXT_PUBLIC_CLOUD_URL;function nt({tool:d,isExpanded:r,onToggle:L,activeProviders:Y,modelMappings:g,onModelMappingChange:l,baseUrl:A,hasActiveProviders:O,apiKeys:E,cloudEnabled:_,initialStatus:B,tunnelEnabled:U,tunnelPublicUrl:o,tailscaleEnabled:s,tailscaleUrl:i}){var pe,R;const[M,Q]=t.useState(B||null),[P,K]=t.useState(!1),[ee,W]=t.useState(!1),[b,y]=t.useState(!1),[w,x]=t.useState(null),[C,j]=t.useState(!1),[T,p]=t.useState(!1),[a,m]=t.useState(null),[h,v]=t.useState(""),[I,G]=t.useState({}),[V,ae]=t.useState(!1),[F,oe]=t.useState(""),[ie,te]=t.useState(!1),se=t.useRef(!1),ne=(()=>{var z,le;if(!(M!=null&&M.installed))return null;const n=(le=(z=M.settings)==null?void 0:z.env)==null?void 0:le.ANTHROPIC_BASE_URL;return n?Ne(n,{tunnelPublicUrl:o,tailscaleUrl:i,cloudUrl:_?at:null})?"configured":"other":"not_configured"})();t.useEffect(()=>{(E==null?void 0:E.length)>0&&!h&&v(E[0].key)},[E,h]),t.useEffect(()=>{B&&Q(B)},[B]),t.useEffect(()=>{r&&!M&&(f(),H()),r&&H()},[r]),t.useEffect(()=>{fetch("/api/settings").then(n=>n.json()).then(n=>{te(!!n.ccFilterNaming)}).catch(()=>{})},[]);const ue=async n=>{const z=n.target.checked;te(z),await fetch("/api/settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({ccFilterNaming:z})}).catch(()=>{})},H=async()=>{try{const n=await fetch("/api/models/alias"),z=await n.json();n.ok&&G(z.aliases||{})}catch(n){console.log("Error fetching model aliases:",n)}};t.useEffect(()=>{var n;if(M!=null&&M.installed&&!se.current){se.current=!0;const z=((n=M.settings)==null?void 0:n.env)||{};d.defaultModels.forEach(k=>{if(k.envKey){const J=z[k.envKey]||k.defaultValue||"";J&&l(k.alias,J)}});const le=z.ANTHROPIC_AUTH_TOKEN;le&&(E!=null&&E.some(k=>k.key===le))&&v(le)}},[M,E,d.defaultModels,l]);const f=async()=>{K(!0);try{const z=await(await fetch("/api/cli-tools/claude-settings")).json();Q(z)}catch(n){Q({installed:!1,error:n.message})}finally{K(!1)}},$=()=>{const n=F||A;return n.endsWith("/v1")?n:`${n}/v1`},X=()=>{const n=F||A;return n.endsWith("/v1")?n:`${n}/v1`},u=async()=>{W(!0),x(null);try{const n={ANTHROPIC_BASE_URL:$()},z=(h==null?void 0:h.trim())||((E==null?void 0:E.length)>0?E[0].key:null)||(_?null:"sk_fsrouter");z&&(n.ANTHROPIC_AUTH_TOKEN=z),d.defaultModels.forEach(J=>{const de=g[J.alias];de&&J.envKey&&(n[J.envKey]=de)});const le=await fetch("/api/cli-tools/claude-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({env:n})}),k=await le.json();le.ok?(x({type:"success",text:"Settings applied successfully!"}),Q(J=>({...J,hasBackup:!0,settings:{...J==null?void 0:J.settings,env:n}}))):x({type:"error",text:k.error||"Failed to apply settings"})}catch(n){x({type:"error",text:n.message})}finally{W(!1)}},N=async()=>{y(!0),x(null);try{const n=await fetch("/api/cli-tools/claude-settings",{method:"DELETE"}),z=await n.json();n.ok?(x({type:"success",text:"Settings reset successfully!"}),d.defaultModels.forEach(le=>l(le.alias,le.defaultValue||"")),v("")):x({type:"error",text:z.error||"Failed to reset settings"})}catch(n){x({type:"error",text:n.message})}finally{y(!1)}},S=n=>{m(n),p(!0)},ce=n=>{a&&l(a,n.value)},xe=()=>{const n=h&&h.trim()?h:_?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",z={ANTHROPIC_BASE_URL:$(),ANTHROPIC_AUTH_TOKEN:n};return d.defaultModels.forEach(le=>{const k=g[le.alias];k&&le.envKey&&(z[le.envKey]=k)}),[{filename:"~/.claude/settings.json",content:JSON.stringify({hasCompletedOnboarding:!0,env:z},null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/claude.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:n=>{n.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),ne==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),ne==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),ne==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[P&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Claude CLI..."})]}),!P&&M&&!M.installed&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Claude CLI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-9",children:[e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>ae(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>j(!C),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:C?"expand_less":"help"}),C?"Hide":"How to Install"]})]})]}),C&&e.jsxs("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Installation Guide"}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),e.jsx("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g @anthropic-ai/claude-code"})]}),e.jsxs("p",{className:"text-text-muted",children:["After installation, run ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"claude"})," to verify."]})]})]})]}),!P&&(M==null?void 0:M.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:F||X(),onChange:oe,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:U,tunnelPublicUrl:o,tailscaleEnabled:s,tailscaleUrl:i})]}),((R=(pe=M==null?void 0:M.settings)==null?void 0:pe.env)==null?void 0:R.ANTHROPIC_BASE_URL)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:M.settings.env.ANTHROPIC_BASE_URL})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:h,onChange:v,apiKeys:E,cloudEnabled:_})]}),d.defaultModels.map(n=>e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:n.name}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:g[n.alias]||"",onChange:z=>l(n.alias,z.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),g[n.alias]&&e.jsx("button",{onClick:()=>l(n.alias,""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>S(n.alias),disabled:!O,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${O?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]},n.alias)),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Filter naming"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[e.jsx("input",{type:"checkbox",checked:ie,onChange:ue,className:"w-3.5 h-3.5 accent-primary cursor-pointer"}),e.jsx("span",{className:"text-xs text-text-muted",children:"Filter naming requests"})]}),e.jsx(Be,{text:"Intercepts Claude Code's topic-naming requests and returns a fake response locally, saving API tokens.",children:e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px] cursor-help",children:"info"})})]})]}),w&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${w.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:w.type==="success"?"check_circle":"error"}),e.jsx("span",{children:w.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:u,disabled:!O,loading:ee,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:N,disabled:!(M!=null&&M.hasFSRouter),loading:b,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>ae(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:T,onClose:()=>p(!1),onSelect:ce,selectedModel:a?g[a]:null,activeProviders:Y,modelAliases:I,title:`Select model for ${a}`}),e.jsx(ye,{isOpen:V,onClose:()=>ae(!1),title:"Claude CLI - Manual Configuration",configs:xe()})]})}function ot({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,apiKeys:g,activeProviders:l,cloudEnabled:A,initialStatus:O,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U}){const[o,s]=t.useState(O||null),[i,M]=t.useState(!1),[Q,P]=t.useState(!1),[K,ee]=t.useState(!1),[W,b]=t.useState(null),[y,w]=t.useState(!1),[x,C]=t.useState(""),[j,T]=t.useState(""),[p,a]=t.useState(""),[m,h]=t.useState(!1),[v,I]=t.useState(!1),[G,V]=t.useState({}),[ae,F]=t.useState(!1),[oe,ie]=t.useState("");t.useEffect(()=>{(g==null?void 0:g.length)>0&&!x&&C(g[0].key)},[g,x]),t.useEffect(()=>{O&&s(O)},[O]),t.useEffect(()=>{r&&!o&&(H(),te()),r&&te()},[r]);const te=async()=>{try{const N=await fetch("/api/models/alias"),S=await N.json();N.ok&&V(S.aliases||{})}catch(N){console.log("Error fetching model aliases:",N)}};t.useEffect(()=>{if(o!=null&&o.config){const N=o.config.match(/^model\s*=\s*"([^"]+)"/m);N&&T(N[1]);const S=o.config.match(/\[agents\.subagent\]\s*\n\s*model\s*=\s*"([^"]+)"/m);S&&a(S[1])}},[o]);const Z=(()=>{if(!(o!=null&&o.installed))return null;if(!o.config)return"not_configured";const N=o.config.match(/base_url\s*=\s*"([^"]+)"/),S=N?N[1]:"";return Ne(S,{tunnelPublicUrl:_,tailscaleUrl:U})?"configured":"other"})(),ne=()=>{const N=oe||`${Y}/v1`;return N.endsWith("/v1")?N:`${N}/v1`},ue=()=>oe||`${Y}/v1`,H=async()=>{M(!0);try{const S=await(await fetch("/api/cli-tools/codex-settings")).json();s(S)}catch(N){s({installed:!1,error:N.message})}finally{M(!1)}},f=async()=>{P(!0),b(null);try{const N=x&&x.trim()||A?x:"sk_fsrouter",S=await fetch("/api/cli-tools/codex-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ne(),apiKey:N,model:j,subagentModel:p||j})}),ce=await S.json();S.ok?(b({type:"success",text:"Settings applied successfully!"}),H()):b({type:"error",text:ce.error||"Failed to apply settings"})}catch(N){b({type:"error",text:N.message})}finally{P(!1)}},$=async()=>{ee(!0),b(null);try{const N=await fetch("/api/cli-tools/codex-settings",{method:"DELETE"}),S=await N.json();N.ok?(b({type:"success",text:"Settings reset successfully!"}),T(""),a(""),H()):b({type:"error",text:S.error||"Failed to reset settings"})}catch(N){b({type:"error",text:N.message})}finally{ee(!1)}},X=N=>{T(N.value),p||a(N.value),h(!1)},u=()=>{const N=x&&x.trim()?x:A?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",S=p||j,ce=`# FSRouter Configuration for Codex CLI
|
|
2
|
+
model = "${j}"
|
|
3
|
+
model_provider = "fsrouter"
|
|
4
|
+
|
|
5
|
+
[model_providers.fsrouter]
|
|
6
|
+
name = "FSRouter"
|
|
7
|
+
base_url = "${ne()}"
|
|
8
|
+
wire_api = "responses"
|
|
9
|
+
|
|
10
|
+
[agents.subagent]
|
|
11
|
+
model = "${S}"
|
|
12
|
+
`,xe=JSON.stringify({auth_mode:"apikey",OPENAI_API_KEY:N},null,2);return[{filename:"~/.codex/config.toml",content:ce},{filename:"~/.codex/auth.json",content:xe}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/codex.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:N=>{N.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),Z==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),Z==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),Z==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Codex CLI..."})]}),!i&&o&&!o.installed&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Codex CLI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-9",children:[e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>F(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>w(!y),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:y?"expand_less":"help"}),y?"Hide":"How to Install"]})]})]}),y&&e.jsxs("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Installation Guide"}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),e.jsx("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g @openai/codex"})]}),e.jsxs("p",{className:"text-text-muted",children:["After installation, run ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"codex"})," to verify."]}),e.jsx("div",{className:"pt-2 border-t border-border",children:e.jsxs("p",{className:"text-text-muted text-xs",children:["Codex uses ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"~/.codex/auth.json"})," with ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"OPENAI_API_KEY"}),'. Click "Apply" to auto-configure.']})})]})]})]}),!i&&(o==null?void 0:o.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:oe||ue(),onChange:ie,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U})]}),(o==null?void 0:o.config)&&(()=>{const N=o.config.match(/base_url\s*=\s*"([^"]+)"/),S=N?N[1]:null;return S?e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:S})]}):null})(),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:x,onChange:C,apiKeys:g,cloudEnabled:A})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:j,onChange:N=>T(N.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),j&&e.jsx("button",{onClick:()=>T(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>h(!0),disabled:!(l!=null&&l.length),className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${l!=null&&l.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Subagent Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:p,onChange:N=>a(N.target.value),placeholder:j||"provider/model-id (defaults to main model)",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),p&&e.jsx("button",{onClick:()=>a(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear (will use main model)",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>I(!0),disabled:!(l!=null&&l.length),className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${l!=null&&l.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),W&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${W.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:W.type==="success"?"check_circle":"error"}),e.jsx("span",{children:W.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:f,disabled:!x&&A&&g.length>0||!j,loading:Q,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:$,disabled:K,loading:K,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>F(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:m,onClose:()=>h(!1),onSelect:X,selectedModel:j,activeProviders:l,modelAliases:G,title:"Select Model for Codex"}),e.jsx(fe,{isOpen:v,onClose:()=>I(!1),onSelect:N=>{a(N.value),I(!1)},selectedModel:p,activeProviders:l,modelAliases:G,title:"Select Subagent Model for Codex"}),e.jsx(ye,{isOpen:ae,onClose:()=>F(!1),title:"Codex CLI - Manual Configuration",configs:u()})]})}var it={};const ct=it.NEXT_PUBLIC_CLOUD_URL;function dt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,hasActiveProviders:g,apiKeys:l,activeProviders:A,cloudEnabled:O,initialStatus:E,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o}){var ce,xe,pe;const[s,i]=t.useState(E||null),[M,Q]=t.useState(!1),[P,K]=t.useState(!1),[ee,W]=t.useState(!1),[b,y]=t.useState(null),[w,x]=t.useState(""),[C,j]=t.useState([]),[T,p]=t.useState(""),[a,m]=t.useState(!1),[h,v]=t.useState({}),[I,G]=t.useState(!1),[V,ae]=t.useState(!1),[F,oe]=t.useState(""),ie=t.useRef(!1),se=(()=>{var n,z;if(!(s!=null&&s.installed))return null;const R=(z=(n=s.settings)==null?void 0:n.customModels)==null?void 0:z.find(le=>{var k;return(k=le.id)==null?void 0:k.startsWith("custom:FSRouter")});return R?Ne(R.baseUrl,{tunnelPublicUrl:B,tailscaleUrl:o,cloudUrl:O?ct:null})?"configured":"other":"not_configured"})();t.useEffect(()=>{(l==null?void 0:l.length)>0&&!w&&x(l[0].key)},[l,w]),t.useEffect(()=>{E&&i(E)},[E]),t.useEffect(()=>{r&&!s&&(ne(),Z()),r&&Z()},[r]);const Z=async()=>{try{const R=await fetch("/api/models/alias"),n=await R.json();R.ok&&v(n.aliases||{})}catch(R){console.log("Error fetching model aliases:",R)}};t.useEffect(()=>{var R,n,z;if(s!=null&&s.installed&&!ie.current){ie.current=!0;const le=(((R=s.settings)==null?void 0:R.customModels)||[]).filter(k=>{var J;return(J=k.id)==null?void 0:J.startsWith("custom:FSRouter")}).sort((k,J)=>(k.index||0)-(J.index||0)).map(k=>k.model);if(le.length>0)j(le);else{const k=(z=(n=s.settings)==null?void 0:n.customModels)==null?void 0:z.find(J=>J.id==="custom:FSRouter-0");k!=null&&k.model&&j([k.model])}}},[s]);const ne=async()=>{Q(!0);try{const n=await(await fetch("/api/cli-tools/droid-settings")).json();i(n)}catch(R){i({installed:!1,error:R.message})}finally{Q(!1)}},ue=()=>{const R=F||Y;return R.endsWith("/v1")?R:`${R}/v1`},H=()=>{const R=F||Y;return R.endsWith("/v1")?R:`${R}/v1`},f=()=>{const R=T.trim();!R||C.includes(R)||(j(n=>[...n,R]),p(""))},$=R=>j(n=>n.filter(z=>z!==R)),X=R=>{!R.value||C.includes(R.value)||(j(n=>[...n,R.value]),m(!1))},u=async()=>{K(!0),y(null);try{const R=(w==null?void 0:w.trim())||((l==null?void 0:l.length)>0?l[0].key:null)||(O?null:"sk_fsrouter"),n=await fetch("/api/cli-tools/droid-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ue(),apiKey:R,models:C,activeModel:C[0]||""})}),z=await n.json();n.ok?(y({type:"success",text:"Settings applied successfully!"}),ne()):y({type:"error",text:z.error||"Failed to apply settings"})}catch(R){y({type:"error",text:R.message})}finally{K(!1)}},N=async()=>{W(!0),y(null);try{const R=await fetch("/api/cli-tools/droid-settings",{method:"DELETE"}),n=await R.json();R.ok?(y({type:"success",text:"Settings reset successfully!"}),j([]),ne()):y({type:"error",text:n.error||"Failed to reset settings"})}catch(R){y({type:"error",text:R.message})}finally{W(!1)}},S=()=>{const R=w&&w.trim()?w:O?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",n={customModels:C.map((J,de)=>({model:J,id:`custom:FSRouter-${de}`,index:de,baseUrl:ue(),apiKey:R,displayName:J,maxOutputTokens:131072,noImageSupport:!1,provider:"openai"}))},z=typeof navigator<"u"&&navigator.platform;return[{filename:(z==null?void 0:z.toLowerCase().includes("win"))?"%USERPROFILE%\\.factory\\settings.json":"~/.factory/settings.json",content:JSON.stringify(n,null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/droid.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:R=>{R.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),se==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),se==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),se==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[M&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Factory Droid CLI..."})]}),!M&&s&&!s.installed&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Factory Droid CLI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-9",children:[e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>G(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>ae(!V),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:V?"expand_less":"help"}),V?"Hide":"How to Install"]})]})]}),V&&e.jsxs("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Installation Guide"}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-text-muted mb-1",children:"macOS / Linux / Windows:"}),e.jsx("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"curl -fsSL https://app.factory.ai/cli | sh"})]}),e.jsxs("p",{className:"text-text-muted",children:["After installation, run ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"droid"})," to verify."]})]})]})]}),!M&&(s==null?void 0:s.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:F||H(),onChange:oe,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o})]}),((pe=(xe=(ce=s==null?void 0:s.settings)==null?void 0:ce.customModels)==null?void 0:xe.find(R=>{var n;return(n=R.id)==null?void 0:n.startsWith("custom:FSRouter")}))==null?void 0:pe.baseUrl)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:s.settings.customModels.find(R=>{var n;return(n=R.id)==null?void 0:n.startsWith("custom:FSRouter")}).baseUrl})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:w,onChange:x,apiKeys:l,cloudEnabled:O})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsxs("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:["Models ",C.length>0&&e.jsxs("span",{className:"text-primary",children:["(",C.length,")"]})]}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"flex-1 flex flex-col gap-1",children:[C.length>0&&e.jsx("div",{className:"flex flex-col gap-0.5 mb-1",children:C.map(R=>e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-bg-secondary rounded border border-border",children:[e.jsx("span",{className:"flex-1 text-xs font-mono truncate",children:R}),e.jsx("button",{onClick:()=>$(R),className:"text-text-muted hover:text-red-500 transition-colors shrink-0",title:"Remove",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},R))}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("input",{type:"text",value:T,onChange:R=>p(R.target.value),onKeyDown:R=>{R.key==="Enter"&&(R.preventDefault(),f())},placeholder:"provider/model-id",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),e.jsx("button",{onClick:()=>m(!0),disabled:!g,className:`px-2 py-1.5 rounded border text-xs shrink-0 ${g?"bg-surface border-border hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"}),e.jsx("button",{onClick:f,disabled:!T.trim(),className:"px-2 py-1.5 rounded border bg-surface border-border hover:border-primary text-xs shrink-0 disabled:opacity-50",title:"Add model",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"add"})})]})]})]})]}),b&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${b.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:b.type==="success"?"check_circle":"error"}),e.jsx("span",{children:b.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:u,disabled:C.length===0,loading:P,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:N,disabled:!(s!=null&&s.hasFSRouter),loading:ee,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>G(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:a,onClose:()=>m(!1),onSelect:X,selectedModel:null,activeProviders:A,modelAliases:h,title:"Select Model for Factory Droid"}),e.jsx(ye,{isOpen:I,onClose:()=>G(!1),title:"Factory Droid - Manual Configuration",configs:S()})]})}function mt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,hasActiveProviders:g,apiKeys:l,activeProviders:A,cloudEnabled:O,initialStatus:E,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o}){var ce,xe,pe,R;const[s,i]=t.useState(E||null),[M,Q]=t.useState(!1),[P,K]=t.useState(!1),[ee,W]=t.useState(!1),[b,y]=t.useState(null),[w,x]=t.useState(""),[C,j]=t.useState(""),[T,p]=t.useState({}),[a,m]=t.useState(null),[h,v]=t.useState(!1),[I,G]=t.useState({}),[V,ae]=t.useState(!1),[F,oe]=t.useState(""),ie=t.useRef(!1),se=(()=>{var z,le,k;if(!(s!=null&&s.installed))return null;const n=(k=(le=(z=s.settings)==null?void 0:z.models)==null?void 0:le.providers)==null?void 0:k.fsrouter;return n?Ne(n.baseUrl,{tunnelPublicUrl:B,tailscaleUrl:o})?"configured":"other":"not_configured"})();t.useEffect(()=>{(l==null?void 0:l.length)>0&&!w&&x(l[0].key)},[l,w]),t.useEffect(()=>{E&&i(E)},[E]),t.useEffect(()=>{r&&!s&&(ne(),Z()),r&&Z()},[r]);const Z=async()=>{try{const n=await fetch("/api/models/alias"),z=await n.json();n.ok&&G(z.aliases||{})}catch(n){console.log("Error fetching model aliases:",n)}};t.useEffect(()=>{var n,z,le,k,J,de,he;if(s!=null&&s.installed&&!ie.current){ie.current=!0;const c=(le=(z=(n=s.settings)==null?void 0:n.models)==null?void 0:z.providers)==null?void 0:le.fsrouter;if(c){const me=(he=(de=(J=(k=s.settings)==null?void 0:k.agents)==null?void 0:J.defaults)==null?void 0:de.model)==null?void 0:he.primary;me&&j(me.replace("fsrouter/","")),c.apiKey&&(l!=null&&l.some(Ce=>Ce.key===c.apiKey))&&x(c.apiKey)}const D=s.agents||[],re={};D.forEach(me=>{me.currentModel&&(re[me.id]=me.currentModel)}),p(re)}},[s,l]);const ne=async()=>{Q(!0);try{const z=await(await fetch("/api/cli-tools/openclaw-settings")).json();i(z)}catch(n){i({installed:!1,error:n.message})}finally{Q(!1)}},ue=n=>n.replace("://localhost","://127.0.0.1"),H=()=>typeof window<"u"?ue(window.location.origin):ke(),f=()=>{const n=F||H();return n.endsWith("/v1")?n:`${n}/v1`},$=()=>{const n=F||H();return n.endsWith("/v1")?n:`${n}/v1`},X=async()=>{K(!0),y(null);try{const n=(w==null?void 0:w.trim())||((l==null?void 0:l.length)>0?l[0].key:null)||(O?null:"sk_fsrouter"),z=await fetch("/api/cli-tools/openclaw-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:f(),apiKey:n,model:C,agentModels:T})}),le=await z.json();z.ok?(y({type:"success",text:"Settings applied successfully!"}),ne()):y({type:"error",text:le.error||"Failed to apply settings"})}catch(n){y({type:"error",text:n.message})}finally{K(!1)}},u=async()=>{W(!0),y(null);try{const n=await fetch("/api/cli-tools/openclaw-settings",{method:"DELETE"}),z=await n.json();n.ok?(y({type:"success",text:"Settings reset successfully!"}),j(""),x(""),ne()):y({type:"error",text:z.error||"Failed to reset settings"})}catch(n){y({type:"error",text:n.message})}finally{W(!1)}},N=n=>{a?(p(z=>({...z,[a]:n.value})),m(null)):j(n.value),v(!1)},S=()=>{const n=w&&w.trim()?w:O?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",z={agents:{defaults:{model:{primary:`fsrouter/${C||"provider/model-id"}`}}},models:{providers:{fsrouter:{baseUrl:f(),apiKey:n,api:"openai-completions",models:[{id:C||"provider/model-id",name:(C||"provider/model-id").split("/").pop()}]}}}};return[{filename:"~/.openclaw/openclaw.json",content:JSON.stringify(z,null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/openclaw.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:n=>{n.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),se==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),se==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),se==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[M&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Open Claw CLI..."})]}),!M&&s&&!s.installed&&e.jsx("div",{className:"flex flex-col gap-4",children:e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Open Claw CLI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsx("div",{className:"flex items-center gap-2 pl-9",children:e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>ae(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!M&&(s==null?void 0:s.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:F||$(),onChange:oe,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o})]}),((R=(pe=(xe=(ce=s==null?void 0:s.settings)==null?void 0:ce.models)==null?void 0:xe.providers)==null?void 0:pe.fsrouter)==null?void 0:R.baseUrl)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:s.settings.models.providers.fsrouter.baseUrl})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:w,onChange:x,apiKeys:l,cloudEnabled:O})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:C,onChange:n=>j(n.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),C&&e.jsx("button",{onClick:()=>j(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>{m(null),v(!0)},disabled:!g,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${g?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]}),(s.agents||[]).filter(n=>n.agentDir).map(n=>e.jsxs("div",{className:"flex items-center gap-2 pl-4",children:[e.jsxs("span",{className:"w-32 shrink-0 text-xs text-primary text-right truncate",title:n.name||n.id,children:["Agent ",n.name||n.id]}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:T[n.id]||"",onChange:z=>p(le=>({...le,[n.id]:z.target.value})),placeholder:`default (${C||"provider/model-id"})`,className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),T[n.id]&&e.jsx("button",{onClick:()=>p(z=>({...z,[n.id]:""})),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>{m(n.id),v(!0)},disabled:!g,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${g?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]},n.id))]}),b&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${b.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:b.type==="success"?"check_circle":"error"}),e.jsx("span",{children:b.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:X,disabled:!C,loading:P,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:u,disabled:!(s!=null&&s.hasFSRouter),loading:ee,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>ae(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:h,onClose:()=>v(!1),onSelect:N,selectedModel:C,activeProviders:A,modelAliases:I,title:"Select Model for Open Claw"}),e.jsx(ye,{isOpen:V,onClose:()=>ae(!1),title:"Open Claw - Manual Configuration",configs:S()})]})}const _e="/api/cli-tools/hermes-settings";function xt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,hasActiveProviders:g,apiKeys:l,activeProviders:A,cloudEnabled:O,initialStatus:E,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o}){var $,X;const[s,i]=t.useState(E||null),[M,Q]=t.useState(!1),[P,K]=t.useState(!1),[ee,W]=t.useState(!1),[b,y]=t.useState(null),[w,x]=t.useState(""),[C,j]=t.useState(""),[T,p]=t.useState(!1),[a,m]=t.useState({}),[h,v]=t.useState(!1),[I,G]=t.useState(""),V=t.useRef(!1),F=(()=>{var N;if(!(s!=null&&s.installed))return null;const u=(N=s.settings)==null?void 0:N.model;return u!=null&&u.base_url?Ne(u.base_url,{tunnelPublicUrl:B,tailscaleUrl:o})?"configured":"other":"not_configured"})();t.useEffect(()=>{(l==null?void 0:l.length)>0&&!w&&x(l[0].key)},[l,w]),t.useEffect(()=>{E&&i(E)},[E]),t.useEffect(()=>{r&&!s&&(ie(),oe()),r&&oe()},[r]);const oe=async()=>{try{const u=await fetch("/api/models/alias"),N=await u.json();u.ok&&m(N.aliases||{})}catch(u){console.log("Error fetching model aliases:",u)}};t.useEffect(()=>{var u;if(s!=null&&s.installed&&!V.current){V.current=!0;const N=(u=s.settings)==null?void 0:u.model;N!=null&&N.default&&j(N.default)}},[s]);const ie=async()=>{Q(!0);try{const N=await(await fetch(_e)).json();i(N)}catch(u){i({installed:!1,error:u.message})}finally{Q(!1)}},te=u=>u.replace("://localhost","://127.0.0.1"),se=()=>typeof window<"u"?te(window.location.origin):ke(),Z=()=>{const u=I||se();return u.endsWith("/v1")?u:`${u}/v1`},ne=async()=>{K(!0),y(null);try{const u=(w==null?void 0:w.trim())||((l==null?void 0:l.length)>0?l[0].key:null)||(O?null:"sk_fsrouter"),N=await fetch(_e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:Z(),apiKey:u,model:C})}),S=await N.json();N.ok?(y({type:"success",text:"Settings applied successfully!"}),ie()):y({type:"error",text:S.error||"Failed to apply settings"})}catch(u){y({type:"error",text:u.message})}finally{K(!1)}},ue=async()=>{W(!0),y(null);try{const u=await fetch(_e,{method:"DELETE"}),N=await u.json();u.ok?(y({type:"success",text:"Settings reset successfully!"}),j(""),ie()):y({type:"error",text:N.error||"Failed to reset settings"})}catch(u){y({type:"error",text:u.message})}finally{W(!1)}},H=u=>{j(u.value),p(!1)},f=()=>{const u=w&&w.trim()?w:O?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",N=`model:
|
|
13
|
+
default: "${C||"provider/model-id"}"
|
|
14
|
+
provider: "custom"
|
|
15
|
+
base_url: "${Z()}"
|
|
16
|
+
`,S=`OPENAI_API_KEY=${u}
|
|
17
|
+
`;return[{filename:"~/.hermes/config.yaml",content:N},{filename:"~/.hermes/.env",content:S}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/hermes.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:u=>{u.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),F==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),F==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),F==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[M&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Hermes Agent..."})]}),!M&&s&&!s.installed&&e.jsx("div",{className:"flex flex-col gap-4",children:e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Hermes Agent not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Install: curl -fsSL https://raw.githubusercontent.com/NousResearch/hermes-agent/main/scripts/install.sh | bash"})]})]}),e.jsx("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 pl-0 sm:pl-9",children:e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>v(!0),className:"w-full sm:w-auto !bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!M&&(s==null?void 0:s.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:I||Z(),onChange:G,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o})]}),((X=($=s==null?void 0:s.settings)==null?void 0:$.model)==null?void 0:X.base_url)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:s.settings.model.base_url})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:w,onChange:x,apiKeys:l,cloudEnabled:O})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:C,onChange:u=>j(u.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),C&&e.jsx("button",{onClick:()=>j(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>p(!0),disabled:!g,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${g?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]})]}),b&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${b.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:b.type==="success"?"check_circle":"error"}),e.jsx("span",{children:b.text})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:ne,disabled:!C,loading:P,className:"w-full sm:w-auto",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:ue,disabled:!(s!=null&&s.hasFSRouter),loading:ee,className:"w-full sm:w-auto",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>v(!0),className:"w-full sm:w-auto",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:T,onClose:()=>p(!1),onSelect:H,selectedModel:C,activeProviders:A,modelAliases:a,title:"Select Model for Hermes Agent"}),e.jsx(ye,{isOpen:h,onClose:()=>v(!1),title:"Hermes Agent - Manual Configuration",configs:f()})]})}function ut({toolId:d,tool:r,isExpanded:L,onToggle:Y,baseUrl:g,apiKeys:l,activeProviders:A=[],cloudEnabled:O=!1,tunnelEnabled:E=!1}){const[_,B]=t.useState(null),[U,o]=t.useState(!1),[s,i]=t.useState(""),[M,Q]=t.useState(()=>(l==null?void 0:l.length)>0?l[0].key:""),P=p=>{const a=M&&M.trim()?M:O?"your-api-key":"sk_fsrouter",m=g||ke(),h=m.endsWith("/v1")?m:`${m}/v1`;return p.replace(/\{\{baseUrl\}\}/g,h).replace(/\{\{apiKey\}\}/g,a).replace(/\{\{model\}\}/g,s||"provider/model-id")},{copy:K}=ze(),ee=async(p,a)=>{await K(P(p),`toolcard-${a}`),B(a),setTimeout(()=>B(null),2e3)},W=p=>{i(p.value)},b=A.length>0,y=()=>e.jsx("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:e.jsx(be,{value:M,onChange:Q,apiKeys:l,cloudEnabled:O,className:"flex-1"})}),w=()=>e.jsxs("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:[e.jsx("input",{type:"text",value:s,onChange:p=>i(p.target.value),placeholder:"provider/model-id",className:"w-full sm:w-auto flex-1 px-3 py-2 bg-bg-secondary rounded-lg text-sm border border-border focus:outline-none focus:ring-1 focus:ring-primary/50"}),e.jsx("button",{onClick:()=>o(!0),disabled:!b,className:`shrink-0 px-3 py-2 rounded-lg border text-sm transition-colors ${b?"bg-bg-secondary border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"}),s&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>ee(s,"model"),className:"shrink-0 px-3 py-2 bg-bg-secondary hover:bg-bg-tertiary rounded-lg border border-border transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-lg",children:_==="model"?"check":"content_copy"})}),e.jsx("button",{onClick:()=>i(""),className:"p-2 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-lg",children:"close"})})]})]}),x=()=>!r.notes||r.notes.length===0?null:e.jsx("div",{className:"flex flex-col gap-2 mb-4",children:r.notes.map((p,a)=>{if(p.type==="cloudCheck"&&(O||E))return null;const m=p.type==="warning",h=p.type==="cloudCheck"&&!O&&!E;let v="bg-blue-500/10 border-blue-500/30",I="text-blue-600 dark:text-blue-400",G="text-blue-500",V="info";return m?(v="bg-yellow-500/10 border-yellow-500/30",I="text-yellow-600 dark:text-yellow-400",G="text-yellow-500",V="warning"):h&&(v="bg-red-500/10 border-red-500/30",I="text-red-600 dark:text-red-400",G="text-red-500",V="error"),e.jsxs("div",{className:`flex items-start gap-3 p-3 rounded-lg border ${v}`,children:[e.jsx("span",{className:`material-symbols-outlined text-lg ${G}`,children:V}),e.jsx("p",{className:`text-sm ${I}`,children:p.text})]},a)})}),C=()=>!(r.requiresExternalUrl&&!O&&!E||r.requiresCloud&&!O),j=()=>r.guideSteps?e.jsxs("div",{className:"flex flex-col gap-4",children:[x(),C()&&r.guideSteps.map(p=>e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"size-8 rounded-full flex items-center justify-center shrink-0 text-sm font-semibold text-white",style:{backgroundColor:r.color},children:p.step}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium text-text",children:p.title}),p.desc&&e.jsx("p",{className:"text-sm text-text-muted mt-0.5",children:p.desc}),p.type==="apiKeySelector"&&y(),p.type==="modelSelector"&&w(),p.value&&e.jsxs("div",{className:"mt-2 flex flex-col sm:flex-row sm:items-center gap-2",children:[e.jsx("code",{className:"w-full sm:w-auto flex-1 px-3 py-2 bg-bg-secondary rounded-lg text-sm font-mono border border-border truncate",children:P(p.value)}),p.copyable&&e.jsx("button",{onClick:()=>ee(p.value,`${p.step}-${p.title}`),className:"shrink-0 px-3 py-2 bg-bg-secondary hover:bg-bg-tertiary rounded-lg border border-border transition-colors",children:e.jsx("span",{className:"material-symbols-outlined text-lg",children:_===`${p.step}-${p.title}`?"check":"content_copy"})})]})]})]},p.step)),C()&&r.codeBlock&&e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:r.codeBlock.language}),e.jsxs("button",{onClick:()=>ee(r.codeBlock.code,"codeblock"),className:"flex items-center gap-1 px-2 py-1 text-xs bg-bg-secondary hover:bg-bg-tertiary rounded border border-border transition-colors",children:[e.jsx("span",{className:"material-symbols-outlined text-sm",children:_==="codeblock"?"check":"content_copy"}),_==="codeblock"?"Copied!":"Copy"]})]}),e.jsx("pre",{className:"p-4 bg-bg-secondary rounded-lg border border-border overflow-x-auto",children:e.jsx("code",{className:"text-sm font-mono whitespace-pre",children:P(r.codeBlock.code)})})]})]}):e.jsx("p",{className:"text-text-muted text-sm",children:"Coming soon..."}),T=()=>r.image?e.jsx("img",{src:r.image,alt:r.name,width:32,height:32,className:"size-8 object-contain rounded-lg",onError:p=>{p.target.style.display="none"}}):r.icon?e.jsx("span",{className:"material-symbols-outlined text-xl",style:{color:r.color},children:r.icon}):e.jsx("img",{src:`/providers/${d}.png`,alt:r.name,width:32,height:32,className:"size-8 object-contain rounded-lg",onError:p=>{p.target.style.display="none"}});return e.jsxs(ge,{padding:"xs",className:"overflow-hidden overflow-x-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between hover:cursor-pointer",onClick:Y,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"size-8 rounded-lg flex items-center justify-center shrink-0",children:T()}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"font-medium text-sm",children:r.name}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:r.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${L?"rotate-180":""}`,children:"expand_more"})]}),L&&e.jsx("div",{className:"mt-6 pt-6 border-t border-border",children:j()}),e.jsx(fe,{isOpen:U,onClose:()=>o(!1),onSelect:W,selectedModel:s,activeProviders:A,title:"Select Model"})]})}function pt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,apiKeys:g,activeProviders:l,cloudEnabled:A,initialStatus:O,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U}){var R,n,z,le;const[o,s]=t.useState(O||null),[i,M]=t.useState(!1),[Q,P]=t.useState(!1),[K,ee]=t.useState(!1),[W,b]=t.useState(null),[y,w]=t.useState(!1),[x,C]=t.useState(""),[j,T]=t.useState(""),[p,a]=t.useState(""),[m,h]=t.useState(!1),[v,I]=t.useState(!1),[G,V]=t.useState({}),[ae,F]=t.useState(!1),[oe,ie]=t.useState(""),[te,se]=t.useState([]),[Z,ne]=t.useState(""),ue=t.useRef([]);t.useEffect(()=>{ue.current=te},[te]),t.useEffect(()=>{(g==null?void 0:g.length)>0&&!x&&C(g[0].key)},[g,x]),t.useEffect(()=>{O&&s(O)},[O]),t.useEffect(()=>{r&&!o&&(S(),H()),r&&H()},[r]),t.useEffect(()=>{var k,J,de,he,c,D;(k=o==null?void 0:o.opencode)!=null&&k.models&&se(o.opencode.models),(J=o==null?void 0:o.opencode)!=null&&J.activeModel&&ne(o.opencode.activeModel),(D=(c=(he=(de=o==null?void 0:o.config)==null?void 0:de.agent)==null?void 0:he.explorer)==null?void 0:c.model)!=null&&D.startsWith("fsrouter/")&&a(o.config.agent.explorer.model.replace("fsrouter/",""))},[o]);const H=async()=>{try{const k=await fetch("/api/models/alias"),J=await k.json();k.ok&&V(J.aliases||{})}catch(k){console.log("Error fetching model aliases:",k)}},f=async k=>{try{const J=x&&x.trim()||A?x:"sk_fsrouter",de=k.includes(Z)?Z:k[0]||"";await fetch("/api/cli-tools/opencode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:u(),apiKey:J,models:k,activeModel:de,subagentModel:p})})}catch(J){console.log("Error saving models:",J)}},X=(()=>{var J,de,he,c;if(!(o!=null&&o.installed))return null;if(!o.config||!o.hasFSRouter)return"not_configured";const k=((c=(he=(de=(J=o.config)==null?void 0:J.provider)==null?void 0:de.fsrouter)==null?void 0:he.options)==null?void 0:c.baseURL)||"";return Ne(k,{tunnelPublicUrl:_,tailscaleUrl:U})?"configured":"other"})(),u=()=>{const k=oe||Y;return k.endsWith("/v1")?k:`${k}/v1`},N=()=>oe||`${Y}/v1`,S=async()=>{M(!0);try{const J=await(await fetch("/api/cli-tools/opencode-settings")).json();s(J)}catch(k){s({installed:!1,error:k.message})}finally{M(!1)}},ce=async()=>{P(!0),b(null);try{const k=x&&x.trim()||A?x:"sk_fsrouter",J=await fetch("/api/cli-tools/opencode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:u(),apiKey:k,models:te,activeModel:Z===""?"":Z||te[0],subagentModel:p})}),de=await J.json();J.ok?(b({type:"success",text:"Settings applied successfully!"}),S()):b({type:"error",text:de.error||"Failed to apply settings"})}catch(k){b({type:"error",text:k.message})}finally{P(!1)}},xe=async()=>{ee(!0),b(null);try{const k=await fetch("/api/cli-tools/opencode-settings",{method:"DELETE"}),J=await k.json();k.ok?(b({type:"success",text:"Settings reset successfully!"}),T(""),a(""),se([]),ne(""),S()):b({type:"error",text:J.error||"Failed to reset settings"})}catch(k){b({type:"error",text:k.message})}finally{ee(!1)}},pe=()=>{const k=x&&x.trim()?x:A?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",J=te.length>0?te:["provider/model-id"],de=Z||te[0]||J[0],he=p||de,c={};return J.forEach(D=>{c[D]={name:D,modalities:{input:["text","image"],output:["text"]}}}),[{filename:"~/.config/opencode/opencode.json",content:JSON.stringify({provider:{fsrouter:{npm:"@ai-sdk/openai-compatible",options:{baseURL:u(),apiKey:k},models:c}},model:`fsrouter/${de}`,agent:{explorer:{description:"Fast explorer subagent for codebase exploration",mode:"subagent",model:`fsrouter/${he}`}}},null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/opencode.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:k=>{k.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),X==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),X==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),X==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking OpenCode CLI..."})]}),!i&&o&&!o.installed&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"OpenCode CLI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-9",children:[e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>F(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>w(!y),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:y?"expand_less":"help"}),y?"Hide":"How to Install"]})]})]}),y&&e.jsxs("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Installation Guide"}),e.jsxs("div",{className:"space-y-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-text-muted mb-1",children:"macOS / Linux:"}),e.jsx("code",{className:"block px-3 py-2 bg-black/5 dark:bg-white/5 rounded font-mono text-xs",children:"npm install -g opencode-ai"})]}),e.jsxs("p",{className:"text-text-muted",children:["After installation, run ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/5 rounded",children:"opencode"})," to verify."]})]})]})]}),!i&&(o==null?void 0:o.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:oe||N(),onChange:ie,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U})]}),((le=(z=(n=(R=o==null?void 0:o.config)==null?void 0:R.provider)==null?void 0:n.fsrouter)==null?void 0:z.options)==null?void 0:le.baseURL)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:o.config.provider.fsrouter.options.baseURL})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:x,onChange:C,apiKeys:g,cloudEnabled:A})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[e.jsx("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Models"}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),e.jsxs("div",{className:"flex-1 flex flex-col gap-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:te.length===0?e.jsx("span",{className:"text-xs text-text-muted",children:"No models selected"}):te.map(k=>e.jsxs("span",{onClick:async()=>{if(k===Z)try{(await fetch("/api/cli-tools/opencode-settings",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({clearActiveModel:!0})})).ok&&(ne(""),S())}catch(J){console.log("Error clearing active model:",J)}else ne(k)},className:`inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs cursor-pointer transition-colors ${k===Z?"bg-primary/10 text-primary border border-primary":"bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border"}`,title:k===Z?"Click to clear active model":"Click to set as active",children:[k===Z&&e.jsx("span",{className:"material-symbols-outlined text-[10px]",children:"star"}),k,e.jsx("button",{onClick:async J=>{J.stopPropagation();try{if((await fetch(`/api/cli-tools/opencode-settings?model=${encodeURIComponent(k)}`,{method:"DELETE"})).ok){const he=te.filter(c=>c!==k);se(he),Z===k&&ne(""),S()}}catch(de){console.log("Error removing model:",de)}},className:"ml-0.5 hover:text-red-500",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},k))}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("button",{onClick:()=>h(!0),disabled:!(l!=null&&l.length),className:`px-2 py-1 rounded border text-xs transition-colors ${l!=null&&l.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Add Model"}),e.jsx("span",{className:"text-xs text-text-muted",children:te.length>0&&Z?e.jsxs(e.Fragment,{children:["Active: ",e.jsx("span",{className:"text-primary",children:Z})]}):te.length>0?e.jsx("span",{className:"text-yellow-500",children:"Click a model to set/clear active"}):"Select models to add"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Subagent Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("input",{type:"text",value:p,onChange:k=>a(k.target.value),placeholder:j||"provider/model-id (defaults to main model)",className:"w-full min-w-0 px-2 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),e.jsx("button",{onClick:()=>I(!0),disabled:!(l!=null&&l.length),className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${l!=null&&l.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"}),p&&e.jsx("button",{onClick:()=>a(""),className:"p-1 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear (will use main model)",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]})]}),W&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${W.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:W.type==="success"?"check_circle":"error"}),e.jsx("span",{children:W.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:ce,disabled:te.length===0,loading:Q,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:xe,disabled:!o.hasFSRouter,loading:K,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>F(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:m,onClose:()=>{h(!1),f(ue.current)},onSelect:k=>{te.includes(k.value)||(se([...te,k.value]),Z||ne(k.value))},onDeselect:k=>{const J=te.filter(de=>de!==k.value);se(J),Z===k.value&&ne(J[0]||"")},selectedModel:null,activeProviders:l,modelAliases:G,addedModelValues:te,closeOnSelect:!1,title:"Add Model for OpenCode"}),e.jsx(fe,{isOpen:v,onClose:()=>I(!1),onSelect:k=>{a(k.value),I(!1)},selectedModel:p,activeProviders:l,modelAliases:G,title:"Select Subagent Model for OpenCode"}),e.jsx(ye,{isOpen:ae,onClose:()=>F(!1),title:"OpenCode - Manual Configuration",configs:pe()})]})}const Me="/api/cli-tools/cowork-settings",$e=d=>(d||"").replace(/\/v1\/?$/,""),ft=d=>{const r=(d||"").replace(/\/+$/,"");return r?/\/v1$/.test(r)?r:`${r}/v1`:""};function ht({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,apiKeys:g,activeProviders:l,hasActiveProviders:A,cloudEnabled:O,cloudUrl:E,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o,initialStatus:s}){var he;const[i,M]=t.useState(s||null),[Q,P]=t.useState(!1),[K,ee]=t.useState(!1),[W,b]=t.useState(!1),[y,w]=t.useState(null),[x,C]=t.useState(""),[j,T]=t.useState([]),[p,a]=t.useState(!1),[m,h]=t.useState(""),[v,I]=t.useState([]),[G,V]=t.useState([]),[ae,F]=t.useState([]),[oe,ie]=t.useState({}),[te,se]=t.useState(!1),[Z,ne]=t.useState(!1),[ue,H]=t.useState(!1),[f,$]=t.useState(!1),[X,u]=t.useState({type:"url",name:"",url:"",command:"",args:""});t.useEffect(()=>{(g==null?void 0:g.length)>0&&!x&&C(g[0].key)},[g,x]),t.useEffect(()=>{s&&M(s)},[s]),t.useEffect(()=>{r&&!i&&N()},[r]),t.useEffect(()=>{r&&fetch("/api/models/alias").then(c=>c.ok?c.json():null).then(c=>{c&&ie(c.aliases||{})}).catch(()=>{})},[r]),t.useEffect(()=>{var c,D,re,me,Ce,Ee;(D=(c=i==null?void 0:i.cowork)==null?void 0:c.models)!=null&&D.length&&T(i.cowork.models),(re=i==null?void 0:i.cowork)!=null&&re.baseUrl&&!m&&h($e(i.cowork.baseUrl)),Array.isArray((me=i==null?void 0:i.cowork)==null?void 0:me.plugins)&&i.cowork.plugins.length>0?I(i.cowork.plugins):v.length===0&&Array.isArray(i==null?void 0:i.defaultPlugins)&&I(i.defaultPlugins),Array.isArray((Ce=i==null?void 0:i.cowork)==null?void 0:Ce.localPlugins)&&V(i.cowork.localPlugins),Array.isArray((Ee=i==null?void 0:i.cowork)==null?void 0:Ee.customPlugins)&&i.cowork.customPlugins.length>0&&F(i.cowork.customPlugins)},[i]);const N=async()=>{P(!0);try{const D=await(await fetch(Me)).json();M(D)}catch(c){M({installed:!1,error:c.message})}finally{P(!1)}},S=()=>ft(m),xe=(()=>{var D;return i!=null&&i.installed?((D=i==null?void 0:i.cowork)==null?void 0:D.baseUrl)?i.hasFSRouter?"configured":"other":"not_configured":null})(),pe=async()=>{w(null);const c=S();if(j.length===0){w({type:"error",text:"Please select at least one model"});return}ee(!0);try{const D=(x==null?void 0:x.trim())||((g==null?void 0:g.length)>0?g[0].key:null)||(O?null:"sk_fsrouter"),re=await fetch(Me,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:c,apiKey:D,models:j,plugins:v,localPlugins:G,customPlugins:ae})}),me=await re.json();re.ok?(w({type:"success",text:"Settings applied. Quit & reopen Claude Desktop to load."}),N()):w({type:"error",text:me.error||"Failed to apply settings"})}catch(D){w({type:"error",text:D.message})}finally{ee(!1)}},R=async({name:c,models:D})=>{try{const re=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:c,models:D})});if(!re.ok){const me=await re.json();w({type:"error",text:me.error||"Failed to create combo"});return}j.includes(c)||T([...j,c]),se(!1),w({type:"success",text:`Combo "${c}" created and added.`})}catch(re){w({type:"error",text:re.message})}},n=c=>{const D=(c==null?void 0:c.value)||(c==null?void 0:c.name)||c;!D||j.includes(D)||T(re=>[...re,D])},z=c=>{const D=(c==null?void 0:c.value)||(c==null?void 0:c.name)||c;T(re=>re.filter(me=>me!==D))},le=async()=>{b(!0),w(null);try{const c=await fetch(Me,{method:"DELETE"}),D=await c.json();c.ok?(w({type:"success",text:"Settings reset successfully"}),T([]),I((i==null?void 0:i.defaultPlugins)||[]),V([]),F([]),N()):w({type:"error",text:D.error||"Failed to reset"})}catch(c){w({type:"error",text:c.message})}finally{b(!1)}},k=c=>{v.some(D=>D.name===c.name)||I([...v,c])},J=c=>{I(v.filter(D=>D.name!==c))},de=()=>{const c=x&&x.trim()?x:O?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",D=j.length>0?j:["provider/model-id"],re={inferenceProvider:"gateway",inferenceGatewayBaseUrl:S()||"https://your-public-host/v1",inferenceGatewayApiKey:c,inferenceModels:D.map(me=>({name:me}))};return[{filename:"~/Library/Application Support/Claude-3p/configLibrary/<appliedId>.json",content:JSON.stringify(re,null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:d.image,alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:c=>{c.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),xe==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),xe==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),xe==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[Q&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Claude Cowork..."})]}),!Q&&i&&!i.installed&&e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Claude Desktop (Cowork mode) not detected"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Open Claude Desktop โ Help โ Troubleshooting โ Enable Developer mode โ Configure third-party inference, then return here."})]})]}),e.jsx("div",{className:"pl-9",children:e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>a(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]}),!Q&&(i==null?void 0:i.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:S(),onChange:c=>h($e(c)),tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o,cloudEnabled:O,cloudUrl:E})]}),((he=i==null?void 0:i.cowork)==null?void 0:he.baseUrl)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:i.cowork.baseUrl})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:x,onChange:C,apiKeys:g,cloudEnabled:O})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right",children:"Models"}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px]",children:"arrow_forward"}),e.jsxs("div",{className:"flex-1 flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:j.length===0?e.jsx("span",{className:"text-xs text-text-muted",children:"No models selected"}):j.map(c=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border",children:[c,e.jsx("button",{onClick:()=>z(c),className:"ml-0.5 hover:text-red-500",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},c))}),e.jsx("button",{onClick:()=>se(!0),disabled:!A,className:`shrink-0 px-2 py-1.5 rounded border text-xs whitespace-nowrap transition-colors ${A?"bg-primary/10 border-primary/40 text-primary hover:bg-primary/20 cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"+ Combo"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[e.jsx("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-2",children:"MCP"}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-2",children:"arrow_forward"}),e.jsxs("div",{className:"flex-1 flex flex-col gap-1",children:[v.filter(c=>c.name!=="exa").map(c=>e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 bg-surface rounded border border-border",children:[e.jsx("span",{className:"text-xs font-medium min-w-0 truncate flex-shrink-0",children:c.title||c.name}),c.oauth&&e.jsx("span",{className:"text-[8px] text-amber-600 shrink-0",children:"OAuth"}),e.jsxs("div",{className:"flex-1 flex flex-wrap gap-1 overflow-hidden",style:{maxHeight:"1.5rem"},children:[Array.isArray(c.toolNames)&&c.toolNames.slice(0,6).map(D=>e.jsx("span",{className:"text-[9px] px-1 py-0.5 rounded bg-black/5 dark:bg-white/5 text-text-muted whitespace-nowrap",children:D},D)),Array.isArray(c.toolNames)&&c.toolNames.length>6&&e.jsxs("span",{className:"text-[9px] px-1 py-0.5 rounded bg-black/5 dark:bg-white/5 text-text-muted whitespace-nowrap",children:["+",c.toolNames.length-6]})]}),e.jsx("button",{onClick:()=>J(c.name),className:"shrink-0 hover:text-red-500 ml-auto",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},c.name)),ae.map(c=>e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 bg-surface rounded border border-border",children:[e.jsx("span",{className:"text-xs font-medium min-w-0 truncate flex-shrink-0",children:c.name}),e.jsx("span",{className:"text-[8px] px-1 py-0.5 rounded bg-blue-500/10 text-blue-500 shrink-0",children:"custom"}),e.jsx("span",{className:"flex-1 text-[9px] text-text-muted truncate",children:c.url||c.command}),e.jsx("button",{onClick:()=>F(ae.filter(D=>D.name!==c.name)),className:"shrink-0 hover:text-red-500 ml-auto",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},c.name)),v.filter(c=>c.name!=="exa").length===0&&ae.length===0&&e.jsx("div",{className:"px-2 py-1.5 bg-surface rounded border border-border text-xs text-text-muted",children:"No MCPs added"}),e.jsxs("div",{className:"flex items-center gap-2 mt-0.5",children:[e.jsx("button",{onClick:()=>H(!0),className:"px-2 py-1 rounded border text-xs bg-primary/10 border-primary/40 text-primary hover:bg-primary/20 cursor-pointer whitespace-nowrap",children:"+ Browse"}),e.jsx("button",{onClick:()=>{u({type:"url",name:"",url:"",command:"",args:""}),$(!0)},className:"px-2 py-1 rounded border text-xs bg-surface border-border text-text-muted hover:border-primary hover:text-primary cursor-pointer whitespace-nowrap",children:"+ Custom"}),e.jsx("a",{href:"https://mcp.so",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-text-muted hover:text-primary underline ml-auto",children:"Find MCPs โ"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[e.jsx("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Tools"}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),e.jsxs("div",{className:"flex-1 flex flex-col gap-1.5",children:[(()=>{const c=v.some(re=>re.name==="exa"),D=((i==null?void 0:i.defaultPlugins)||[]).find(re=>re.name==="exa");return e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer px-2 py-1.5 bg-surface rounded border border-border",children:[e.jsx("input",{type:"checkbox",checked:c,onChange:re=>{re.target.checked&&D?I([...v.filter(me=>me.name!=="exa"),D]):I(v.filter(me=>me.name!=="exa"))},className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium",children:"Web Search & Fetch (Exa)"}),e.jsx("p",{className:"text-[10px] text-text-muted leading-snug",children:"Replaces built-in WebSearch/WebFetch. Auto-strips duplicates from tool list."})]})]})})(),(()=>{const c=((i==null?void 0:i.localStdioPlugins)||[]).find(re=>re.name==="browsermcp");if(!c)return null;const D=G.includes("browsermcp");return e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer px-2 py-1.5 bg-surface rounded border border-border",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:re=>V(re.target.checked?[...G,"browsermcp"]:G.filter(me=>me!=="browsermcp")),className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs font-medium",children:"Browser Control (Browser MCP)"}),e.jsxs("p",{className:"text-[10px] text-text-muted leading-snug",children:["Controls your running Chrome. Auto-strips Cowork's built-in browser tools."," ",e.jsx("a",{href:c.extensionUrl,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline",children:"Install Chrome extension"})]})]})]})})()]})]}),Array.isArray(i==null?void 0:i.localStdioPlugins)&&i.localStdioPlugins.filter(c=>c.name!=="browsermcp").length>0&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[e.jsx("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Local Plugins"}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),e.jsxs("div",{className:"flex-1 flex flex-col gap-2",children:[e.jsx("div",{className:"flex flex-col gap-1.5 px-2 py-1.5 bg-surface rounded border border-border",children:i.localStdioPlugins.filter(c=>c.name!=="browsermcp").map(c=>{const D=G.includes(c.name);return e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:D,onChange:re=>V(re.target.checked?[...G,c.name]:G.filter(me=>me!==c.name)),className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-xs font-medium",children:c.title}),e.jsx("span",{className:"text-[8px] text-amber-600",children:"stdio"})]}),e.jsx("p",{className:"text-[10px] text-text-muted leading-snug",children:c.description}),c.extensionUrl&&e.jsx("a",{href:c.extensionUrl,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-primary underline",children:"Install Chrome extension"})]})]},c.name)})}),e.jsxs("p",{className:"text-[10px] text-text-muted leading-snug",children:["โ ๏ธ Local plugins run as subprocess via ",e.jsx("code",{className:"px-1 py-0.5 rounded bg-black/5 dark:bg-white/5",children:"npx"}),". Requires Node.js installed."]})]})]})]}),y&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${y.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:y.type==="success"?"check_circle":"error"}),e.jsx("span",{children:y.text})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:pe,disabled:j.length===0,loading:K,className:"w-full sm:w-auto",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:le,disabled:!i.hasFSRouter,loading:W,className:"w-full sm:w-auto",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>a(!0),className:"w-full sm:w-auto",children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(ye,{isOpen:p,onClose:()=>a(!1),title:"Claude Cowork - Manual Configuration",configs:de()}),e.jsx(Qe,{isOpen:te,combo:null,onClose:()=>se(!1),onSave:R,activeProviders:l,forcePrefix:"claude-",title:"Create Cowork Combo"}),e.jsx(fe,{isOpen:Z,onClose:()=>ne(!1),onSelect:n,onDeselect:z,activeProviders:l,modelAliases:oe,title:"Select Cowork Model",addedModelValues:j,closeOnSelect:!1}),e.jsx(et,{isOpen:ue,onClose:()=>H(!1),onAdd:k,addedNames:v.map(c=>c.name)}),f&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40",onClick:()=>$(!1),children:e.jsxs("div",{className:"bg-surface border border-border rounded-xl shadow-xl w-full max-w-sm mx-4 p-5 flex flex-col gap-4",onClick:c=>c.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"font-semibold text-sm",children:"Add Custom MCP"}),e.jsx("button",{onClick:()=>$(!1),className:"text-text-muted hover:text-text-main",children:e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"close"})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>u(c=>({...c,type:"url"})),className:`flex-1 py-1.5 rounded border text-xs font-medium transition-colors ${X.type==="url"?"bg-primary/10 border-primary/40 text-primary":"border-border text-text-muted hover:border-primary/40"}`,children:"URL (SSE)"}),e.jsx("button",{onClick:()=>u(c=>({...c,type:"cmd"})),className:`flex-1 py-1.5 rounded border text-xs font-medium transition-colors ${X.type==="cmd"?"bg-primary/10 border-primary/40 text-primary":"border-border text-text-muted hover:border-primary/40"}`,children:"Command (stdio)"})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-medium",children:"Name"}),e.jsx("input",{type:"text",placeholder:"my-mcp",value:X.name,onChange:c=>u(D=>({...D,name:c.target.value.replace(/\s+/g,"-").toLowerCase()})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}),X.type==="url"?e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-medium",children:"SSE URL"}),e.jsx("input",{type:"text",placeholder:"https://your-mcp-server.com/sse",value:X.url,onChange:c=>u(D=>({...D,url:c.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-medium",children:"Command"}),e.jsx("input",{type:"text",placeholder:"npx",value:X.command,onChange:c=>u(D=>({...D,command:c.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-medium",children:["Args ",e.jsx("span",{className:"font-normal",children:"(comma-separated)"})]}),e.jsx("input",{type:"text",placeholder:"-y, @some/mcp-package",value:X.args,onChange:c=>u(D=>({...D,args:c.target.value})),className:"px-2 py-1.5 rounded border border-border bg-surface text-xs outline-none focus:border-primary"})]})]})]}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:()=>$(!1),className:"px-3 py-1.5 rounded border border-border text-xs text-text-muted hover:bg-surface cursor-pointer",children:"Cancel"}),e.jsx("button",{onClick:()=>{const c=X.name.trim();if(c){if(X.type==="url"){if(!X.url.trim())return;F(D=>[...D.filter(re=>re.name!==c),{name:c,url:X.url.trim(),transport:"sse",custom:!0}])}else{if(!X.command.trim())return;const D=X.args.split(",").map(re=>re.trim()).filter(Boolean);F(re=>[...re.filter(me=>me.name!==c),{name:c,command:X.command.trim(),args:D,custom:!0}])}$(!1)}},className:"px-3 py-1.5 rounded bg-primary text-white text-xs font-medium hover:opacity-90 cursor-pointer",children:"Add"})]})]})})]})}function gt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,apiKeys:g,activeProviders:l,cloudEnabled:A,initialStatus:O,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U}){const[o,s]=t.useState(O||null),[i,M]=t.useState(!1),[Q,P]=t.useState(!1),[K,ee]=t.useState(!1),[W,b]=t.useState(null),[y,w]=t.useState(""),[x,C]=t.useState(""),[j,T]=t.useState({}),[p,a]=t.useState(!1),[m,h]=t.useState([]),[v,I]=t.useState(!1),G=t.useRef([]);t.useEffect(()=>{G.current=m},[m]),t.useEffect(()=>{(g==null?void 0:g.length)>0&&!y&&w(g[0].key)},[g,y]),t.useEffect(()=>{O&&s(O)},[O]),t.useEffect(()=>{r&&!o&&(Z(),V()),r&&V()},[r]),t.useEffect(()=>{var f;if(o!=null&&o.config&&Array.isArray(o.config)&&m.length===0){const $=o.config.find(X=>X.name==="FSRouter");((f=$==null?void 0:$.models)==null?void 0:f.length)>0&&h($.models.map(X=>X.id))}},[o]);const V=async()=>{try{const f=await fetch("/api/models/alias"),$=await f.json();f.ok&&T($.aliases||{})}catch(f){console.log("Error fetching model aliases:",f)}},ae=async f=>{try{const $=y&&y.trim()||A?y:"sk_fsrouter";await fetch("/api/cli-tools/copilot-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ie(),apiKey:$,models:f})})}catch($){console.log("Error saving models:",$)}},oe=(()=>{if(!o)return null;if(!o.hasFSRouter)return"not_configured";const f=o.currentUrl||"";return Ne(f,{tunnelPublicUrl:_,tailscaleUrl:U})?"configured":"other"})(),ie=()=>{const f=x||Y;return f.endsWith("/v1")?f:`${f}/v1`},te=()=>x||`${Y}/v1`,se=f=>h($=>$.filter(X=>X!==f)),Z=async()=>{M(!0);try{const $=await(await fetch("/api/cli-tools/copilot-settings")).json();s($)}catch(f){s({error:f.message})}finally{M(!1)}},ne=async()=>{P(!0),b(null);try{const f=y&&y.trim()||A?y:"sk_fsrouter",$=await fetch("/api/cli-tools/copilot-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ie(),apiKey:f,models:m})}),X=await $.json();$.ok?(b({type:"success",text:X.message||"Settings applied! Reload VS Code."}),Z()):b({type:"error",text:X.error||"Failed to apply settings"})}catch(f){b({type:"error",text:f.message})}finally{P(!1)}},ue=async()=>{ee(!0),b(null);try{const f=await fetch("/api/cli-tools/copilot-settings",{method:"DELETE"}),$=await f.json();f.ok?(b({type:"success",text:"Settings reset successfully!"}),h([]),Z()):b({type:"error",text:$.error||"Failed to reset settings"})}catch(f){b({type:"error",text:f.message})}finally{ee(!1)}},H=()=>{const f=y&&y.trim()?y:A?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",$=ie(),X=m.length>0?m:["provider/model-id"];return[{filename:"~/Library/Application Support/Code/User/chatLanguageModels.json",content:JSON.stringify([{name:"FSRouter",vendor:"azure",apiKey:f,models:X.map(u=>({id:u,name:u,url:`${$}/chat/completions#models.ai.azure.com`,toolCalling:!0,vision:!1,maxInputTokens:128e3,maxOutputTokens:16e3}))}],null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/copilot.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:f=>{f.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),oe==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),oe==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),oe==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Copilot config..."})]}),!i&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-start gap-3 p-3 bg-blue-500/10 border border-blue-500/30 rounded-lg",children:[e.jsx("span",{className:"material-symbols-outlined text-blue-500 text-lg",children:"info"}),e.jsxs("div",{className:"text-xs text-blue-700 dark:text-blue-300",children:[e.jsxs("p",{className:"font-medium",children:["Writes to ",e.jsx("code",{className:"px-1 bg-black/5 dark:bg-white/10 rounded",children:"chatLanguageModels.json"})]}),e.jsx("p",{className:"mt-0.5 opacity-80",children:"Reload VS Code after applying for changes to take effect."})]})]}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:x||te(),onChange:C,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:y,onChange:w,apiKeys:g,cloudEnabled:A})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-start sm:gap-2",children:[e.jsx("span",{className:"w-32 shrink-0 text-sm font-semibold text-text-main text-right pt-1",children:"Models"}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[14px] mt-1.5",children:"arrow_forward"}),e.jsxs("div",{className:"flex-1 flex flex-col gap-2",children:[e.jsx("div",{className:"flex flex-wrap gap-1.5 min-h-[28px] px-2 py-1.5 bg-surface rounded border border-border",children:m.length===0?e.jsx("span",{className:"text-xs text-text-muted",children:"No models selected"}):m.map(f=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded text-xs bg-black/5 dark:bg-white/5 text-text-muted border border-transparent hover:border-border",children:[f,e.jsx("button",{onClick:$=>{$.stopPropagation(),se(f)},className:"ml-0.5 hover:text-red-500",children:e.jsx("span",{className:"material-symbols-outlined text-[12px]",children:"close"})})]},f))}),e.jsx("div",{children:e.jsx("button",{onClick:()=>I(!0),disabled:!(l!=null&&l.length),className:`px-2 py-1 rounded border text-xs transition-colors ${l!=null&&l.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Add Model"})})]})]})]}),W&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${W.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:W.type==="success"?"check_circle":"error"}),e.jsx("span",{children:W.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:ne,disabled:m.length===0,loading:Q,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:ue,disabled:!(o!=null&&o.hasFSRouter),loading:K,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>a(!0),disabled:m.length===0,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:v,onClose:()=>{I(!1),ae(G.current)},onSelect:f=>{m.includes(f.value)||h([...m,f.value])},onDeselect:f=>{h(m.filter($=>$!==f.value))},selectedModel:null,activeProviders:l,modelAliases:j,addedModelValues:m,closeOnSelect:!1,title:"Add Model for GitHub Copilot"}),e.jsx(ye,{isOpen:p,onClose:()=>a(!1),title:"GitHub Copilot - Manual Configuration",configs:H()})]})}function bt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,apiKeys:g,activeProviders:l,cloudEnabled:A,initialStatus:O,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U}){var H;const[o,s]=t.useState(O||null),[i,M]=t.useState(!1),[Q,P]=t.useState(!1),[K,ee]=t.useState(!1),[W,b]=t.useState(null),[y,w]=t.useState(!1),[x,C]=t.useState(""),[j,T]=t.useState(""),[p,a]=t.useState(!1),[m,h]=t.useState({}),[v,I]=t.useState(!1),[G,V]=t.useState("");t.useEffect(()=>{(g==null?void 0:g.length)>0&&!x&&C(g[0].key)},[g,x]),t.useEffect(()=>{O&&s(O)},[O]),t.useEffect(()=>{r&&!o&&(se(),ae()),r&&ae()},[r]),t.useEffect(()=>{var f;(f=o==null?void 0:o.settings)!=null&&f.openAiModelId&&T(o.settings.openAiModelId)},[o]);const ae=async()=>{try{const f=await fetch("/api/models/alias"),$=await f.json();f.ok&&h($.aliases||{})}catch(f){console.log("Error fetching model aliases:",f)}},oe=(()=>{var $;if(!(o!=null&&o.installed))return null;if(!o.hasFSRouter)return"not_configured";const f=(($=o.settings)==null?void 0:$.openAiBaseUrl)||"";return Ne(f,{tunnelPublicUrl:_,tailscaleUrl:U})?"configured":"other"})(),ie=()=>{const f=G||`${Y}/v1`;return f.endsWith("/v1")?f:`${f}/v1`},te=()=>G||`${Y}/v1`,se=async()=>{M(!0);try{const $=await(await fetch("/api/cli-tools/cline-settings")).json();s($)}catch(f){s({installed:!1,error:f.message})}finally{M(!1)}},Z=async()=>{P(!0),b(null);try{const f=x&&x.trim()||A?x:"sk_fsrouter",$=await fetch("/api/cli-tools/cline-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ie(),apiKey:f,model:j})}),X=await $.json();$.ok?(b({type:"success",text:"Settings applied successfully!"}),se()):b({type:"error",text:X.error||"Failed to apply settings"})}catch(f){b({type:"error",text:f.message})}finally{P(!1)}},ne=async()=>{ee(!0),b(null);try{const f=await fetch("/api/cli-tools/cline-settings",{method:"DELETE"}),$=await f.json();f.ok?(b({type:"success",text:"Settings reset successfully!"}),T(""),se()):b({type:"error",text:$.error||"Failed to reset settings"})}catch(f){b({type:"error",text:f.message})}finally{ee(!1)}},ue=()=>{const f=x&&x.trim()?x:A?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",$=ie(),X=$.endsWith("/v1")?$.slice(0,-3):$;return[{filename:"~/.cline/data/globalState.json",content:JSON.stringify({actModeApiProvider:"openai",planModeApiProvider:"openai",openAiBaseUrl:X,openAiModelId:j||"provider/model-id",planModeOpenAiModelId:j||"provider/model-id"},null,2)},{filename:"~/.cline/data/secrets.json",content:JSON.stringify({openAiApiKey:f},null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/cline.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:f=>{f.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),oe==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),oe==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),oe==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Cline..."})]}),!i&&o&&!o.installed&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Cline not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-9",children:[e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>I(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>w(!y),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:y?"expand_less":"help"}),y?"Hide":"How to Install"]})]})]}),y&&e.jsxs("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Installation Guide"}),e.jsx("div",{className:"space-y-3 text-sm",children:e.jsxs("p",{className:"text-text-muted",children:["Install Cline VS Code extension or CLI from ",e.jsx("a",{className:"text-primary underline",href:"https://docs.cline.bot/",target:"_blank",rel:"noreferrer",children:"docs.cline.bot"}),"."]})})]})]}),!i&&(o==null?void 0:o.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:G||te(),onChange:V,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U})]}),((H=o==null?void 0:o.settings)==null?void 0:H.openAiBaseUrl)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:o.settings.openAiBaseUrl})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:x,onChange:C,apiKeys:g,cloudEnabled:A})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:j,onChange:f=>T(f.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),j&&e.jsx("button",{onClick:()=>T(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>a(!0),disabled:!(l!=null&&l.length),className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${l!=null&&l.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),W&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${W.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:W.type==="success"?"check_circle":"error"}),e.jsx("span",{children:W.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:Z,disabled:!x&&A&&g.length>0||!j,loading:Q,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:ne,disabled:K,loading:K,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>I(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:p,onClose:()=>a(!1),onSelect:f=>{T(f.value),a(!1)},selectedModel:j,activeProviders:l,modelAliases:m,title:"Select Model for Cline"}),e.jsx(ye,{isOpen:v,onClose:()=>I(!1),title:"Cline - Manual Configuration",configs:ue()})]})}function yt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,apiKeys:g,activeProviders:l,cloudEnabled:A,initialStatus:O,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U}){const[o,s]=t.useState(O||null),[i,M]=t.useState(!1),[Q,P]=t.useState(!1),[K,ee]=t.useState(!1),[W,b]=t.useState(null),[y,w]=t.useState(!1),[x,C]=t.useState(""),[j,T]=t.useState(""),[p,a]=t.useState(!1),[m,h]=t.useState({}),[v,I]=t.useState(!1),[G,V]=t.useState("");t.useEffect(()=>{(g==null?void 0:g.length)>0&&!x&&C(g[0].key)},[g,x]),t.useEffect(()=>{O&&s(O)},[O]),t.useEffect(()=>{r&&!o&&(se(),ae()),r&&ae()},[r]);const ae=async()=>{try{const H=await fetch("/api/models/alias"),f=await H.json();H.ok&&h(f.aliases||{})}catch(H){console.log("Error fetching model aliases:",H)}},oe=o!=null&&o.installed?o.hasFSRouter?"configured":"not_configured":null,ie=()=>{const H=G||`${Y}/v1`;return H.endsWith("/v1")?H:`${H}/v1`},te=()=>G||`${Y}/v1`,se=async()=>{M(!0);try{const f=await(await fetch("/api/cli-tools/kilo-settings")).json();s(f)}catch(H){s({installed:!1,error:H.message})}finally{M(!1)}},Z=async()=>{P(!0),b(null);try{const H=x&&x.trim()||A?x:"sk_fsrouter",f=await fetch("/api/cli-tools/kilo-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:ie(),apiKey:H,model:j})}),$=await f.json();f.ok?(b({type:"success",text:"Settings applied successfully!"}),se()):b({type:"error",text:$.error||"Failed to apply settings"})}catch(H){b({type:"error",text:H.message})}finally{P(!1)}},ne=async()=>{ee(!0),b(null);try{const H=await fetch("/api/cli-tools/kilo-settings",{method:"DELETE"}),f=await H.json();H.ok?(b({type:"success",text:"Settings reset successfully!"}),T(""),se()):b({type:"error",text:f.error||"Failed to reset settings"})}catch(H){b({type:"error",text:H.message})}finally{ee(!1)}},ue=()=>{const H=x&&x.trim()?x:A?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter";return[{filename:"~/.local/share/kilo/auth.json",content:JSON.stringify({"openai-compatible":{type:"api-key",apiKey:H,baseUrl:ie(),model:j||"provider/model-id"}},null,2)}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:"/providers/kilocode.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:H=>{H.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),oe==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),oe==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[i&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking Kilo Code..."})]}),!i&&o&&!o.installed&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"Kilo Code not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pl-9",children:[e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>I(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:()=>w(!y),children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:y?"expand_less":"help"}),y?"Hide":"How to Install"]})]})]}),y&&e.jsxs("div",{className:"p-4 bg-surface border border-border rounded-lg",children:[e.jsx("h4",{className:"font-medium mb-3",children:"Installation Guide"}),e.jsxs("p",{className:"text-sm text-text-muted",children:["Install Kilo Code from ",e.jsx("a",{className:"text-primary underline",href:"https://kilocode.ai",target:"_blank",rel:"noreferrer",children:"kilocode.ai"})," or VS Code extension marketplace."]})]})]}),!i&&(o==null?void 0:o.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:G||te(),onChange:V,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:E,tunnelPublicUrl:_,tailscaleEnabled:B,tailscaleUrl:U})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:x,onChange:C,apiKeys:g,cloudEnabled:A})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:j,onChange:H=>T(H.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),j&&e.jsx("button",{onClick:()=>T(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>a(!0),disabled:!(l!=null&&l.length),className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${l!=null&&l.length?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select Model"})]})]}),W&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${W.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:W.type==="success"?"check_circle":"error"}),e.jsx("span",{children:W.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:Z,disabled:!x&&A&&g.length>0||!j,loading:Q,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:ne,disabled:K,loading:K,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>I(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:p,onClose:()=>a(!1),onSelect:H=>{T(H.value),a(!1)},selectedModel:j,activeProviders:l,modelAliases:m,title:"Select Model for Kilo Code"}),e.jsx(ye,{isOpen:v,onClose:()=>I(!1),title:"Kilo Code - Manual Configuration",configs:ue()})]})}const Ae="/api/cli-tools/deepseek-tui-settings";function jt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,hasActiveProviders:g,apiKeys:l,activeProviders:A,cloudEnabled:O,initialStatus:E,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o}){var $,X;const[s,i]=t.useState(E||null),[M,Q]=t.useState(!1),[P,K]=t.useState(!1),[ee,W]=t.useState(!1),[b,y]=t.useState(null),[w,x]=t.useState(""),[C,j]=t.useState(""),[T,p]=t.useState(!1),[a,m]=t.useState({}),[h,v]=t.useState(!1),[I,G]=t.useState(""),V=t.useRef(!1),F=(()=>{var N;if(!(s!=null&&s.installed))return null;const u=(N=s.settings)==null?void 0:N["providers.openai"];return u!=null&&u.base_url?Ne(u.base_url,{tunnelPublicUrl:B,tailscaleUrl:o})?"configured":"other":"not_configured"})();t.useEffect(()=>{(l==null?void 0:l.length)>0&&!w&&x(l[0].key)},[l,w]),t.useEffect(()=>{E&&i(E)},[E]),t.useEffect(()=>{r&&!s&&(ie(),oe()),r&&oe()},[r]);const oe=async()=>{try{const u=await fetch("/api/models/alias"),N=await u.json();u.ok&&m(N.aliases||{})}catch(u){console.log("Error fetching model aliases:",u)}};t.useEffect(()=>{var u;if(s!=null&&s.installed&&!V.current){V.current=!0;const N=(u=s.settings)==null?void 0:u["providers.openai"];N!=null&&N.model&&j(N.model)}},[s]);const ie=async()=>{Q(!0);try{const N=await(await fetch(Ae)).json();i(N)}catch(u){i({installed:!1,error:u.message})}finally{Q(!1)}},te=u=>u.replace("://localhost","://127.0.0.1"),se=()=>typeof window<"u"?te(window.location.origin):ke(),Z=()=>{const u=I||se();return u.endsWith("/v1")?u:`${u}/v1`},ne=async()=>{K(!0),y(null);try{const u=(w==null?void 0:w.trim())||((l==null?void 0:l.length)>0?l[0].key:null)||(O?null:"sk_fsrouter"),N=await fetch(Ae,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:Z(),apiKey:u,model:C})}),S=await N.json();N.ok?(y({type:"success",text:"Settings applied successfully!"}),ie()):y({type:"error",text:S.error||"Failed to apply settings"})}catch(u){y({type:"error",text:u.message})}finally{K(!1)}},ue=async()=>{W(!0),y(null);try{const u=await fetch(Ae,{method:"DELETE"}),N=await u.json();u.ok?(y({type:"success",text:"Settings reset successfully!"}),j(""),ie()):y({type:"error",text:N.error||"Failed to reset settings"})}catch(u){y({type:"error",text:u.message})}finally{W(!1)}},H=u=>{j(u.value),p(!1)},f=()=>{const u=w&&w.trim()?w:O?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter";return[{filename:"~/.deepseek/config.toml",content:`[providers.openai]
|
|
18
|
+
base_url = "${Z()}"
|
|
19
|
+
api_key = "${u}"
|
|
20
|
+
model = "${C||"provider/model-id"}"
|
|
21
|
+
`}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:d.image||"/providers/deepseek-tui.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:u=>{u.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),F==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),F==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),F==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[M&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking DeepSeek TUI..."})]}),!M&&s&&!s.installed&&e.jsx("div",{className:"flex flex-col gap-4",children:e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"DeepSeek TUI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted mt-1",children:"Install via npm:"}),e.jsx("code",{className:"block mt-2 p-2 bg-black/20 rounded text-xs font-mono",children:"npm install -g deepseek-tui"}),e.jsx("p",{className:"text-sm text-text-muted mt-2",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsx("div",{className:"flex items-center gap-2 pl-9",children:e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>v(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!M&&(s==null?void 0:s.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[d.notes&&d.notes.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mb-2",children:d.notes.map((u,N)=>e.jsxs("div",{className:`flex items-start gap-2 p-2 rounded text-xs ${u.type==="warning"?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":u.type==="error"?"bg-red-500/10 text-red-600 dark:text-red-400":"bg-blue-500/10 text-blue-600 dark:text-blue-400"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mt-0.5",children:u.type==="warning"?"warning":u.type==="error"?"error":"info"}),e.jsx("span",{children:u.text})]},N))}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:I||Z(),onChange:G,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o})]}),((X=($=s==null?void 0:s.settings)==null?void 0:$["providers.openai"])==null?void 0:X.base_url)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:s.settings["providers.openai"].base_url})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:w,onChange:x,apiKeys:l,cloudEnabled:O})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:C,onChange:u=>j(u.target.value),placeholder:"provider/model-id",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),C&&e.jsx("button",{onClick:()=>j(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>p(!0),disabled:!g,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${g?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]})]}),b&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${b.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:b.type==="success"?"check_circle":"error"}),e.jsx("span",{children:b.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:ne,disabled:!C,loading:P,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:ue,disabled:!(s!=null&&s.hasFSRouter),loading:ee,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>v(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:T,onClose:()=>p(!1),onSelect:H,selectedModel:C,activeProviders:A,modelAliases:a,title:"Select Model for DeepSeek TUI"}),e.jsx(ye,{isOpen:h,onClose:()=>v(!1),title:"DeepSeek TUI - Manual Configuration",configs:f()})]})}function Nt({tool:d,isExpanded:r,onToggle:L,baseUrl:Y,hasActiveProviders:g,apiKeys:l,activeProviders:A,cloudEnabled:O,initialStatus:E,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o}){var X,u,N;const[s,i]=t.useState(E||null),[M,Q]=t.useState(!1),[P,K]=t.useState(!1),[ee,W]=t.useState(!1),[b,y]=t.useState(null),[w,x]=t.useState(""),[C,j]=t.useState(""),[T,p]=t.useState(!1),[a,m]=t.useState({}),[h,v]=t.useState(!1),[I,G]=t.useState(""),V=t.useRef(!1),F=(()=>{var ce,xe;if(!(s!=null&&s.installed))return null;if(!(s!=null&&s.hasFSRouter))return"not_configured";const S=(xe=(ce=s.config)==null?void 0:ce.providers)==null?void 0:xe.fsrouter;return S?Ne(S.base_url,{tunnelPublicUrl:B,tailscaleUrl:o})?"configured":"other":"not_configured"})();t.useEffect(()=>{(l==null?void 0:l.length)>0&&!w&&x(l[0].key)},[l,w]),t.useEffect(()=>{E&&i(E)},[E]),t.useEffect(()=>{r&&!s&&(ie(),oe()),r&&oe()},[r]);const oe=async()=>{try{const S=await fetch("/api/models/alias"),ce=await S.json();S.ok&&m(ce.aliases||{})}catch(S){console.log("Error fetching model aliases:",S)}};t.useEffect(()=>{var S,ce;if(s!=null&&s.installed&&!V.current){V.current=!0;const xe=(ce=(S=s.config)==null?void 0:S.providers)==null?void 0:ce.fsrouter;if(xe){xe.default_model&&j(xe.default_model);const pe=s.envApiKey;pe&&(l!=null&&l.some(R=>R.key===pe))&&x(pe)}}},[s,l]);const ie=async()=>{Q(!0);try{const ce=await(await fetch("/api/cli-tools/jcode-settings")).json();i(ce)}catch(S){i({installed:!1,error:S.message})}finally{Q(!1)}},te=S=>S.replace("://localhost","://127.0.0.1"),se=()=>typeof window<"u"?te(window.location.origin):ke(),Z=()=>{const S=I||se();return S.endsWith("/v1")?S:`${S}/v1`},ne=()=>{const S=I||se();return S.endsWith("/v1")?S:`${S}/v1`},ue=async()=>{K(!0),y(null);try{const S=(w==null?void 0:w.trim())||((l==null?void 0:l.length)>0?l[0].key:null)||(O?null:"sk_fsrouter"),ce=await fetch("/api/cli-tools/jcode-settings",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({baseUrl:Z(),apiKey:S,models:C?[C]:[]})}),xe=await ce.json();ce.ok?(y({type:"success",text:"Settings applied successfully!"}),ie()):y({type:"error",text:xe.error||"Failed to apply settings"})}catch(S){y({type:"error",text:S.message})}finally{K(!1)}},H=async()=>{W(!0),y(null);try{const S=await fetch("/api/cli-tools/jcode-settings",{method:"DELETE"}),ce=await S.json();S.ok?(y({type:"success",text:"Settings reset successfully!"}),j(""),x(""),ie()):y({type:"error",text:ce.error||"Failed to reset settings"})}catch(S){y({type:"error",text:S.message})}finally{W(!1)}},f=S=>{j(S.value),p(!1)},$=()=>{const S=w&&w.trim()?w:O?"<API_KEY_FROM_DASHBOARD>":"sk_fsrouter",ce=`[providers.fsrouter]
|
|
22
|
+
type = "openai-compatible"
|
|
23
|
+
base_url = "${Z()}"
|
|
24
|
+
auth = "bearer"
|
|
25
|
+
api_key_env = "JCODE_9ROUTER_API_KEY"
|
|
26
|
+
env_file = "provider-fsrouter.env"
|
|
27
|
+
default_model = "${C||"cc/claude-opus-4-7"}"
|
|
28
|
+
requires_api_key = true
|
|
29
|
+
|
|
30
|
+
[[providers.fsrouter.models]]
|
|
31
|
+
id = "${C||"cc/claude-opus-4-7"}"`,xe=`JCODE_9ROUTER_API_KEY="${S}"`;return[{filename:"~/.jcode/config.toml",content:ce},{filename:"~/.config/jcode/provider-fsrouter.env",content:xe}]};return e.jsxs(ge,{padding:"xs",className:"overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 hover:cursor-pointer sm:items-center",onClick:L,children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 flex items-center justify-center shrink-0",children:e.jsx("img",{src:d.image||"/providers/jcode.png",alt:d.name,width:32,height:32,className:"size-8 object-contain rounded-lg",sizes:"32px",onError:S=>{S.target.style.display="none"}})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"font-medium text-sm",children:d.name}),F==="configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-green-500/10 text-green-600 dark:text-green-400 rounded-full",children:"Connected"}),F==="not_configured"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-yellow-500/10 text-yellow-600 dark:text-yellow-400 rounded-full",children:"Not configured"}),F==="other"&&e.jsx("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-blue-500/10 text-blue-600 dark:text-blue-400 rounded-full",children:"Other"})]}),e.jsx("p",{className:"text-xs text-text-muted truncate",children:d.description})]})]}),e.jsx("span",{className:`material-symbols-outlined text-text-muted text-[20px] transition-transform ${r?"rotate-180":""}`,children:"expand_more"})]}),r&&e.jsxs("div",{className:"mt-4 pt-4 border-t border-border flex flex-col gap-4",children:[M&&e.jsxs("div",{className:"flex items-center gap-2 text-text-muted",children:[e.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),e.jsx("span",{children:"Checking jcode CLI..."})]}),!M&&s&&!s.installed&&e.jsx("div",{className:"flex flex-col gap-4",children:e.jsxs("div",{className:"flex flex-col gap-3 p-4 bg-yellow-500/10 border border-yellow-500/30 rounded-lg",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-yellow-500",children:"warning"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium text-yellow-600 dark:text-yellow-400",children:"jcode CLI not detected locally"}),e.jsx("p",{className:"text-sm text-text-muted mt-1",children:"Install jcode to enable automatic configuration:"}),e.jsx("code",{className:"block mt-2 p-2 bg-black/20 rounded text-xs font-mono",children:"curl -fsSL https://raw.githubusercontent.com/1jehuang/jcode/master/scripts/install.sh | bash"}),e.jsx("p",{className:"text-sm text-text-muted mt-2",children:"Manual configuration is still available if fsrouter is deployed on a remote server."})]})]}),e.jsx("div",{className:"flex items-center gap-2 pl-9",children:e.jsxs(q,{variant:"secondary",size:"sm",onClick:()=>v(!0),className:"!bg-yellow-500/20 !border-yellow-500/40 !text-yellow-700 dark:!text-yellow-300 hover:!bg-yellow-500/30",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px] mr-1",children:"content_copy"}),"Manual Config"]})})]})}),!M&&(s==null?void 0:s.installed)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[d.notes&&d.notes.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mb-2",children:d.notes.map((S,ce)=>e.jsxs("div",{className:`flex items-start gap-2 p-2 rounded text-xs ${S.type==="info"?"bg-blue-500/10 text-blue-600 dark:text-blue-400":S.type==="warning"?"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400":"bg-gray-500/10 text-text-muted"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mt-0.5",children:S.type==="info"?"info":S.type==="warning"?"warning":"help"}),e.jsx("span",{children:S.text})]},ce))}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Select Endpoint"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(je,{value:I||ne(),onChange:G,requiresExternalUrl:d.requiresExternalUrl,tunnelEnabled:_,tunnelPublicUrl:B,tailscaleEnabled:U,tailscaleUrl:o})]}),((N=(u=(X=s==null?void 0:s.config)==null?void 0:X.providers)==null?void 0:u.fsrouter)==null?void 0:N.base_url)&&e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Current"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx("span",{className:"min-w-0 truncate rounded bg-surface/40 px-2 py-2 text-xs text-text-muted sm:py-1.5",children:s.config.providers.fsrouter.base_url})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"API Key"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsx(be,{value:w,onChange:x,apiKeys:l,cloudEnabled:O})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-1.5 sm:grid-cols-[8rem_auto_1fr_auto] sm:items-center sm:gap-2",children:[e.jsx("span",{className:"text-xs font-semibold text-text-main sm:text-right sm:text-sm",children:"Default Model"}),e.jsx("span",{className:"material-symbols-outlined hidden text-text-muted text-[14px] sm:inline",children:"arrow_forward"}),e.jsxs("div",{className:"relative w-full min-w-0",children:[e.jsx("input",{type:"text",value:C,onChange:S=>j(S.target.value),placeholder:"cc/claude-opus-4-7",className:"w-full min-w-0 pl-2 pr-7 py-2 bg-surface rounded border border-border text-xs focus:outline-none focus:ring-1 focus:ring-primary/50 sm:py-1.5"}),C&&e.jsx("button",{onClick:()=>j(""),className:"absolute right-1 top-1/2 -translate-y-1/2 p-0.5 text-text-muted hover:text-red-500 rounded transition-colors",title:"Clear",children:e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"close"})})]}),e.jsx("button",{onClick:()=>p(!0),disabled:!g,className:`w-full sm:w-auto rounded border px-2 py-2 text-xs transition-colors sm:py-1.5 whitespace-nowrap sm:shrink-0 ${g?"bg-surface border-border text-text-main hover:border-primary cursor-pointer":"opacity-50 cursor-not-allowed border-border"}`,children:"Select"})]}),e.jsxs("div",{className:"flex flex-col gap-1 p-3 bg-blue-500/5 border border-blue-500/20 rounded-lg",children:[e.jsx("p",{className:"text-xs font-medium text-blue-600 dark:text-blue-400",children:"Usage:"}),e.jsx("code",{className:"text-xs font-mono text-text-muted",children:"jcode --provider-profile fsrouter"}),e.jsxs("code",{className:"text-xs font-mono text-text-muted",children:["jcode --provider-profile fsrouter --model ",C||"cc/claude-opus-4-7"]})]})]}),b&&e.jsxs("div",{className:`flex items-center gap-2 px-2 py-1.5 rounded text-xs ${b.type==="success"?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px]",children:b.type==="success"?"check_circle":"error"}),e.jsx("span",{children:b.text})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:flex sm:items-center",children:[e.jsxs(q,{variant:"primary",size:"sm",onClick:ue,disabled:!C,loading:P,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"save"}),"Apply"]}),e.jsxs(q,{variant:"outline",size:"sm",onClick:H,disabled:!(s!=null&&s.hasFSRouter),loading:ee,children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"restore"}),"Reset"]}),e.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>v(!0),children:[e.jsx("span",{className:"material-symbols-outlined text-[14px] mr-1",children:"content_copy"}),"Manual Config"]})]})]})]}),e.jsx(fe,{isOpen:T,onClose:()=>p(!1),onSelect:f,selectedModel:C,activeProviders:A,modelAliases:a,title:"Select Model for jcode"}),e.jsx(ye,{isOpen:h,onClose:()=>v(!1),title:"jcode - Manual Configuration",configs:$()})]})}var wt={};const Oe=wt.NEXT_PUBLIC_CLOUD_URL;function vt({toolId:d,machineId:r}){const L=Le[d],[Y,g]=t.useState([]),[l,A]=t.useState(!0),[O,E]=t.useState({}),[_,B]=t.useState(!1),[U,o]=t.useState(!1),[s,i]=t.useState(""),[M,Q]=t.useState(!1),[P,K]=t.useState(""),[ee,W]=t.useState([]);t.useEffect(()=>{let j=!0;return(async()=>{var T,p,a,m,h,v;try{const[I,G,V,ae]=await Promise.all([fetch("/api/providers"),fetch("/api/settings"),fetch("/api/tunnel/status"),fetch("/api/keys")]);if(!j)return;if(I.ok){const F=await I.json();g(F.connections||[])}if(G.ok){const F=await G.json();B(F.cloudEnabled||!1)}if(V.ok){const F=await V.json();o(!!((T=F.tunnel)!=null&&T.enabled||(p=F.tunnel)!=null&&p.settingsEnabled)),i(((a=F.tunnel)==null?void 0:a.publicUrl)||""),Q(!!((m=F.tailscale)!=null&&m.enabled||(h=F.tailscale)!=null&&h.settingsEnabled)),K(((v=F.tailscale)==null?void 0:v.tunnelUrl)||"")}if(ae.ok){const F=await ae.json();W(F.keys||[])}}catch(I){console.log("Error loading tool data:",I)}finally{j&&A(!1)}})(),()=>{j=!1}},[]);const b=()=>Y.filter(j=>j.isActive!==!1),y=()=>{const j=b(),T=[],p=new Set;return j.forEach(a=>{const m=He[a.provider]||a.provider;We(a.provider).forEach(v=>{const I=`${m}/${v.id}`;p.has(I)||(p.add(I),T.push({value:I,label:`${m}/${v.id}`,provider:a.provider,alias:m,connectionName:a.name,modelId:v.id}))})}),T},w=t.useCallback((j,T,p)=>{E(a=>{var m;return((m=a[j])==null?void 0:m[T])===p?a:{...a,[j]:{...a[j],[T]:p}}})},[]),x=()=>U&&s?s:_&&Oe?Oe:typeof window<"u"?window.location.origin:ke(),C=()=>{const T=y().length>0,p={tool:L,isExpanded:!0,onToggle:()=>{},baseUrl:x(),apiKeys:ee,tunnelEnabled:U,tunnelPublicUrl:s,tailscaleEnabled:M,tailscaleUrl:P};switch(d){case"claude":return e.jsx(nt,{...p,activeProviders:b(),modelMappings:O[d]||{},onModelMappingChange:(a,m)=>w(d,a,m),hasActiveProviders:T,cloudEnabled:_});case"codex":return e.jsx(ot,{...p,activeProviders:b(),cloudEnabled:_});case"opencode":return e.jsx(pt,{...p,activeProviders:b(),cloudEnabled:_});case"cowork":return e.jsx(ht,{...p,activeProviders:b(),hasActiveProviders:T,cloudEnabled:_,cloudUrl:Oe,tunnelEnabled:U,tunnelPublicUrl:s,tailscaleEnabled:M,tailscaleUrl:P});case"droid":return e.jsx(dt,{...p,activeProviders:b(),hasActiveProviders:T,cloudEnabled:_});case"openclaw":return e.jsx(mt,{...p,activeProviders:b(),hasActiveProviders:T,cloudEnabled:_});case"hermes":return e.jsx(xt,{...p,activeProviders:b(),hasActiveProviders:T,cloudEnabled:_});case"copilot":return e.jsx(gt,{...p,activeProviders:b(),cloudEnabled:_});case"cline":return e.jsx(bt,{...p,activeProviders:b(),cloudEnabled:_});case"kilo":return e.jsx(yt,{...p,activeProviders:b(),cloudEnabled:_});case"deepseek-tui":return e.jsx(jt,{...p,activeProviders:b(),hasActiveProviders:T,cloudEnabled:_});case"jcode":return e.jsx(Nt,{...p,activeProviders:b(),hasActiveProviders:T,cloudEnabled:_});default:return e.jsx(ut,{toolId:d,...p,activeProviders:b(),cloudEnabled:_,tunnelEnabled:U})}};return L?e.jsxs("div",{className:"mx-auto flex w-full max-w-5xl flex-col gap-4 px-1 sm:px-0",children:[e.jsxs(Te,{to:"/dashboard/cli-tools",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary w-fit",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"arrow_back"}),"Back to CLI Tools"]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("h1",{className:"text-xl font-semibold text-text-main sm:text-2xl",children:L.name}),e.jsx("p",{className:"text-sm text-text-muted",children:L.description})]}),l?e.jsx(Ve,{}):C()]}):e.jsxs("div",{className:"mx-auto flex w-full max-w-5xl flex-col gap-4 px-1 sm:px-0",children:[e.jsxs(Te,{to:"/dashboard/cli-tools",className:"inline-flex items-center gap-1 text-sm text-text-muted hover:text-primary w-fit",children:[e.jsx("span",{className:"material-symbols-outlined text-[18px]",children:"arrow_back"}),"Back to CLI Tools"]}),e.jsx("p",{className:"text-sm text-text-muted",children:"Tool not found or disabled."})]})}function Ut(){const{toolId:d}=Je(),[r,L]=t.useState(null),[Y,g]=t.useState(!0);return t.useEffect(()=>{let l=!0;return Pe().then(A=>{l&&(L(A),g(!1))}).catch(()=>{l&&g(!1)}),()=>{l=!1}},[]),!d||!Le[d]?e.jsx(qe,{to:"/dashboard/cli-tools",replace:!0}):Y?e.jsx("div",{className:"text-text-muted text-sm py-12 text-center",children:"Loading..."}):e.jsx(vt,{toolId:d,machineId:r})}export{Ut as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{K as g,j as e,B as P,g as w,P as C}from"./index.BO_pNnMt.js";import{d as z,b as p,L as k}from"./router.Cjj1--8t.js";import{C as y,B as b}from"./NoAuthProxyCard.CLW2-XwE.js";import"./zustand.akaTi5uX.js";function v(t){const a=Object.entries(t).some(([n,r])=>n.startsWith("modelLock_")&&r&&new Date(r).getTime()>Date.now());return t.testStatus==="unavailable"&&!a?"active":t.testStatus}function F({provider:t,kind:a,connections:n}){var c;const r=w[t.id],i=!!(r!=null&&r.noAuth),s=n.filter(o=>o.provider===t.id),m=s.filter(o=>{const l=v(o);return l==="active"||l==="success"}).length,d=s.filter(o=>{const l=v(o);return l==="error"||l==="expired"||l==="unavailable"}).length,x=s.length,f=x>0&&s.every(o=>o.isActive===!1),u=()=>i?e.jsx(b,{variant:"success",size:"sm",children:"Ready"}):f?e.jsx(b,{variant:"default",size:"sm",children:"Disabled"}):x===0?e.jsx("span",{className:"text-xs text-text-muted",children:"No connections"}):e.jsxs(e.Fragment,{children:[m>0&&e.jsxs(b,{variant:"success",size:"sm",dot:!0,children:[m," Connected"]}),d>0&&e.jsxs(b,{variant:"error",size:"sm",dot:!0,children:[d," Error"]}),m===0&&d===0&&e.jsxs(b,{variant:"default",size:"sm",children:[x," Added"]})]});return e.jsx(k,{to:`/dashboard/media-providers/${a}/${t.id}`,className:"group",children:e.jsx(y,{padding:"xs",className:`h-full hover:bg-black/[0.01] dark:hover:bg-white/[0.01] transition-colors cursor-pointer ${f?"opacity-50":""}`,children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("div",{className:"size-8 rounded-lg flex items-center justify-center shrink-0",style:{backgroundColor:`${((c=t.color)==null?void 0:c.length)>7?t.color:(t.color??"#888")+"15"}`},children:e.jsx(C,{src:`/providers/${t.id}.png`,alt:t.name,size:30,className:"object-contain rounded-lg max-w-[30px] max-h-[30px]",fallbackText:t.textIcon||t.id.slice(0,2).toUpperCase(),fallbackColor:t.color})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-sm",children:t.name}),e.jsx("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:u()})]})]})})})}function A({combos:t}){return t.length===0?e.jsx("p",{className:"text-xs text-text-muted italic",children:"No combos yet."}):e.jsx("div",{className:"flex flex-col gap-2",children:t.map(a=>e.jsx(k,{to:`/dashboard/media-providers/combo/${a.id}`,children:e.jsx(y,{padding:"xs",className:"hover:bg-black/[0.02] dark:hover:bg-white/[0.02] transition-colors cursor-pointer",children:e.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[e.jsx("span",{className:"material-symbols-outlined text-primary text-[18px]",children:"layers"}),e.jsx("code",{className:"text-sm font-mono font-medium flex-1 truncate",children:a.name}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1 sm:shrink-0",children:[a.models.slice(0,6).map((n,r)=>{const i=typeof n=="string"?n.split("/")[0]:"",s=w[i];return e.jsx("div",{title:(s==null?void 0:s.name)||n,className:"size-5 rounded flex items-center justify-center",style:{backgroundColor:`${(s==null?void 0:s.color)??"#888"}15`},children:e.jsx(C,{src:`/providers/${i}.png`,alt:(s==null?void 0:s.name)||i,size:18,className:"object-contain rounded max-w-[18px] max-h-[18px]",fallbackText:(s==null?void 0:s.textIcon)||i.slice(0,2).toUpperCase(),fallbackColor:s==null?void 0:s.color})},`${n}-${r}`)}),a.models.length>6&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1",children:["+",a.models.length-6]})]}),e.jsx("span",{className:"text-[11px] text-text-muted shrink-0",children:a.models.length}),e.jsx("span",{className:"material-symbols-outlined text-text-muted text-[16px]",children:"chevron_right"})]})})},a.id))})}function N({title:t,icon:a,kind:n,providers:r,connections:i,combos:s,onCreateCombo:m}){return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between mb-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"material-symbols-outlined text-primary",children:a}),e.jsx("h2",{className:"text-base font-semibold",children:t}),e.jsxs("span",{className:"text-xs text-text-muted",children:["(",r.length," providers ยท ",s.length," combos)"]})]}),e.jsx(P,{size:"sm",icon:"add",onClick:m,children:"Create Combo"})]}),s.length>0&&e.jsx("div",{className:"mb-4",children:e.jsx(A,{combos:s})}),r.length===0?e.jsx("div",{className:"text-center py-8 border border-dashed border-border rounded-xl text-text-muted text-sm",children:"No providers."}):e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4",children:r.map(d=>e.jsx(F,{provider:d,kind:n,connections:i},d.id))})]})}function T(){const t=z(),[a,n]=p.useState([]),[r,i]=p.useState([]),s=async()=>{try{const[c,o]=await Promise.all([fetch("/api/providers",{cache:"no-store"}),fetch("/api/combos",{cache:"no-store"})]);c.ok&&n((await c.json()).connections||[]),o.ok&&i((await o.json()).combos||[])}catch{}};p.useEffect(()=>{s()},[]);const m=g("webSearch"),d=g("webFetch"),x=r.filter(c=>c.kind==="webSearch"),f=r.filter(c=>c.kind==="webFetch"),u=async c=>{const o=c==="webSearch"?"search-combo":"fetch-combo";let l=o,S=1;const $=new Set(r.map(h=>h.name));for(;$.has(l);)l=`${o}-${S++}`;const j=await fetch("/api/combos",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:l,models:[],kind:c})});if(j.ok){const h=await j.json();t(`/dashboard/media-providers/combo/${h.id}`)}else{const h=await j.json();alert(h.error||"Failed to create combo")}};return e.jsxs("div",{className:"flex flex-col gap-8",children:[e.jsx(N,{title:"Web Search",icon:"search",kind:"webSearch",providers:m,connections:a,combos:x,onCreateCombo:()=>u("webSearch")}),e.jsx("div",{className:"border-t border-border"}),e.jsx(N,{title:"Web Fetch",icon:"travel_explore",kind:"webFetch",providers:d,connections:a,combos:f,onCreateCombo:()=>u("webFetch")})]})}export{T as default};
|