@fudrouter/fsrouter 0.6.73 → 0.6.74
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/lib/headroom/detect.js +97 -7
- package/dist/lib/headroom/process.js +136 -4
- package/dist/routes/headroom/extras/route.js +58 -0
- package/dist/routes/headroom/restart/route.js +33 -0
- package/package.json +1 -1
- package/public/assets/EndpointPageClient.C2WMTYy0.js +6 -0
- package/public/assets/{Loading.Bj-WGl4k.js → Loading.BHPtQ9vj.js} +1 -1
- package/public/assets/{NoAuthProxyCard.qAv57b-0.js → NoAuthProxyCard.BDcXaWvM.js} +1 -1
- package/public/assets/index.Be3gbrBl.js +89 -0
- package/public/assets/index.COMgQZYj.css +1 -0
- package/public/assets/{page.CbkENBd5.js → page.-lpNgYAw.js} +1 -1
- package/public/assets/{page.CssmrzTT.js → page.11hpNKmq.js} +1 -1
- package/public/assets/{page.C72FTTJr.js → page.B-LxsnqU.js} +1 -1
- package/public/assets/{page.sOFOrxqq.js → page.B-dzeIUC.js} +1 -1
- package/public/assets/{page.CsxWmPoI.js → page.B-nBR75u.js} +1 -1
- package/public/assets/{page.Dx_GRRdT.js → page.B3QqvLep.js} +1 -1
- package/public/assets/{page.DPyOkPVo.js → page.B8xdkCWA.js} +1 -1
- package/public/assets/{page.DUI8kqOY.js → page.BFb7yUd8.js} +1 -1
- package/public/assets/page.BbPPdoas.js +1 -0
- package/public/assets/page.BdS20a1O.js +1 -0
- package/public/assets/{page.DibhF7f-.js → page.BfmI9KYe.js} +1 -1
- package/public/assets/{page.DX4Nno6M.js → page.BgGJovOg.js} +1 -1
- package/public/assets/{page.BnmTC5jG.js → page.C0gBvR4O.js} +1 -1
- package/public/assets/{page.D5gj98Oe.js → page.C6bYizL7.js} +1 -1
- package/public/assets/{page.vla5Mzki.js → page.C8sLEMa6.js} +1 -1
- package/public/assets/{page.CXd_R9yU.js → page.CCNsZBXp.js} +1 -1
- package/public/assets/{page.CQlVGoXg.js → page.CF_YSLwP.js} +1 -1
- package/public/assets/{page.BbO1pspY.js → page.CPTtRDxw.js} +1 -1
- package/public/assets/{page.D1oKew1j.js → page.CdMmlUEm.js} +1 -1
- package/public/assets/{page.DxMDTbSx.js → page.Cged1bOZ.js} +1 -1
- package/public/assets/{page.Cj5h09Zo.js → page.Ch647dVk.js} +1 -1
- package/public/assets/{page.DVIHRbxB.js → page.CpvXDkQF.js} +1 -1
- package/public/assets/{page.i4KDuWcM.js → page.CrBl7f8N.js} +1 -1
- package/public/assets/{page.BSLJ4tx5.js → page.CrP7niA2.js} +1 -1
- package/public/assets/{page.CnTop8Zt.js → page.CvUFZzXr.js} +1 -1
- package/public/assets/{page.O2ddJYoT.js → page.CyUqJPmx.js} +1 -1
- package/public/assets/{page.DBhu4Arl.js → page.D8Rp8fFR.js} +1 -1
- package/public/assets/{page.CPZav1_c.js → page.Df9qtrdG.js} +1 -1
- package/public/assets/{page.Qkkv8roc.js → page.DiL4Gwqe.js} +1 -1
- package/public/assets/{page.BdmJ3yY3.js → page.Dl1apZE2.js} +1 -1
- package/public/assets/{page.1qjqvrwX.js → page.HV0w1d5C.js} +1 -1
- package/public/assets/{page.ChX1NqmC.js → page.N1x4YL8_.js} +1 -1
- package/public/assets/{page.Dh5f0XJC.js → page.P2Ny5veR.js} +1 -1
- package/public/assets/{page.CSs3-gdt.js → page.fOOCr18J.js} +1 -1
- package/public/assets/{page.Ir7KvKcF.js → page.sUIPWIiF.js} +1 -1
- package/public/assets/{page.CzlQTyAL.js → page.tE7PpWYW.js} +1 -1
- package/public/assets/{page.DzZLqI5Q.js → page.uziaGZsT.js} +1 -1
- package/public/index.html +2 -2
- package/public/assets/EndpointPageClient.LyNNvZ4z.js +0 -6
- package/public/assets/index.BuPfZebu.css +0 -1
- package/public/assets/index.CShjRV_B.js +0 -89
- package/public/assets/page.DD_czjjP.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var KS=Object.defineProperty;var qS=(e,t,r)=>t in e?KS(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ma=(e,t,r)=>qS(e,typeof t!="symbol"?t+"":t,r);import{j as m,n as at,u as Uv,M as hr,B as ue,f as Y,g as Qa,A as Hv,c as Vv,F as Ja,O as Kv,i as Yd,k as qv,l as Yv,h as Xd,P as YS}from"./index.CShjRV_B.js";import{b as g,r as Vc,g as Xv,W as XS,c as Gv,i as GS}from"./router.Cjj1--8t.js";function xe({label:e,type:t="text",placeholder:r,value:n,onChange:i,error:a,hint:o,icon:s,disabled:l=!1,required:c=!1,className:u,inputClassName:d,...f}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",u),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,c&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[s&&m.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:s})}),m.jsx("input",{type:t,placeholder:r,value:n,onChange:i,disabled:l,className:at("w-full py-2.5 px-3 text-sm text-text-main bg-surface-2 rounded-[10px]","border border-transparent placeholder-text-muted/70","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 ease-out disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",s&&"pl-10",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",d),...f})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function ZS({label:e,options:t=[],value:r,onChange:n,placeholder:i="Select an option",error:a,hint:o,disabled:s=!1,required:l=!1,className:c,selectClassName:u,...d}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",c),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,l&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[m.jsxs("select",{value:r,onChange:n,disabled:s,className:at("w-full py-2.5 px-3 pr-10 text-sm text-text-main","bg-surface-2 border border-transparent rounded-[10px] appearance-none","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",u),...d,children:[m.jsx("option",{value:"",disabled:!0,children:i}),t.map(f=>m.jsx("option",{value:f.value,children:f.label},f.value))]}),m.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"expand_more"})})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function zt({children:e,title:t,subtitle:r,icon:n,action:i,padding:a="md",hover:o=!1,elev:s=!1,className:l,...c}){const u={none:"",xs:"p-3",sm:"p-4",md:"p-6",lg:"p-8"};return m.jsxs("div",{className:at("bg-surface border border-border-subtle",s?"rounded-[14px] shadow-[var(--shadow-elev)]":"rounded-[14px] shadow-[var(--shadow-soft)]",o&&"hover:shadow-[var(--shadow-warm)] hover:border-brand-500/30 transition-all cursor-pointer",u[a],l),...c,children:[(t||i)&&m.jsxs("div",{className:"flex items-center justify-between mb-4",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[n&&m.jsx("div",{className:"p-2 rounded-[10px] bg-bg text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:n})}),m.jsxs("div",{children:[t&&m.jsx("h3",{className:"text-text-main font-semibold",children:t}),r&&m.jsx("p",{className:"text-sm text-text-muted",children:r})]})]}),i]}),e]})}zt.Section=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-4 rounded-[10px]","bg-bg border border-border-subtle",r),...n,children:t})};zt.Row=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-3 -mx-3 px-3 transition-colors","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50",r),...n,children:t})};zt.ListItem=function({children:t,actions:r,className:n,...i}){return m.jsxs("div",{className:at("group flex items-center justify-between p-3 -mx-3 px-3","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50 transition-colors",n),...i,children:[m.jsx("div",{className:"flex-1 min-w-0",children:t}),r&&m.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:r})]})};const QS={default:"bg-surface-2 text-text-muted",primary:"bg-brand-500/10 text-brand-600 dark:text-brand-300",success:"bg-green-500/10 text-green-600 dark:text-green-400",warning:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",error:"bg-red-500/10 text-red-600 dark:text-red-400",info:"bg-blue-500/10 text-blue-600 dark:text-blue-400"},JS={sm:"px-2 py-0.5 text-[10px]",md:"px-2.5 py-1 text-xs",lg:"px-3 py-1.5 text-sm"};function Ci({children:e,variant:t="default",size:r="md",dot:n=!1,icon:i,className:a}){return m.jsxs("span",{className:at("inline-flex items-center gap-1.5 rounded-full font-semibold",QS[t],JS[r],a),children:[n&&m.jsx("span",{className:at("size-1.5 rounded-full",t==="success"&&"bg-green-500",t==="warning"&&"bg-yellow-500",t==="error"&&"bg-red-500",t==="info"&&"bg-blue-500",t==="primary"&&"bg-brand-500",t==="default"&&"bg-gray-500")}),i&&m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:i}),e]})}function Js({checked:e=!1,onChange:t,label:r,description:n,disabled:i=!1,size:a="md",className:o}){const s={sm:{track:"w-8 h-4",thumb:"size-3",translate:"translate-x-4"},md:{track:"w-11 h-6",thumb:"size-5",translate:"translate-x-5"},lg:{track:"w-14 h-7",thumb:"size-6",translate:"translate-x-7"}},l=()=>{!i&&t&&t(!e)};return m.jsxs("div",{className:at("flex items-center gap-3",i&&"opacity-50 cursor-not-allowed",o),children:[m.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:i,onClick:l,className:at("relative inline-flex shrink-0 cursor-pointer rounded-full","transition-colors duration-200 ease-in-out","focus:outline-none focus:ring-2 focus:ring-brand-500/30",e?"bg-brand-500":"bg-surface-3",s[a].track,i&&"cursor-not-allowed"),children:m.jsx("span",{className:at("pointer-events-none inline-block rounded-full bg-white shadow-sm","transform transition duration-200 ease-in-out",e?s[a].translate:"translate-x-0.5",s[a].thumb,"mt-0.5")})}),(r||n)&&m.jsxs("div",{className:"flex flex-col",children:[r&&m.jsx("span",{className:"text-sm font-medium text-text-main",children:r}),n&&m.jsx("span",{className:"text-xs text-text-muted",children:n})]})]})}function Kc({isOpen:e,provider:t,providerInfo:r,onSuccess:n,onClose:i,oauthMeta:a,idcConfig:o}){const[s,l]=g.useState("waiting"),[c,u]=g.useState(null),[d,f]=g.useState(""),[h,p]=g.useState(null),[y,x]=g.useState(!1),[v,S]=g.useState(null),[b,w]=g.useState(!1),E=g.useRef(null),A=g.useRef(!1),_=g.useRef(!1),{copied:O,copy:j}=Uv(),[M,N]=g.useState(!1),[k,z]=g.useState("/callback?code=..."),P=g.useRef(!1);g.useEffect(()=>{typeof window<"u"&&(N(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),z(`${window.location.origin}/callback?code=...`))},[]);const I=g.useCallback(async(q,X)=>{if(c)try{const F=await fetch(`/api/oauth/${t}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,redirectUri:c.redirectUri,codeVerifier:c.codeVerifier,state:X,...a?{meta:a}:{}})}),B=await F.json();if(!F.ok)throw new Error(B.error);l("success"),n==null||n()}catch(F){p(F.message),l("error")}},[c,t,n,a]),C=g.useCallback(async q=>{if(c!=null&&c.state)try{const X=await fetch("/api/oauth/xai/manual-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,state:c.state})}),F=await X.json();if(!X.ok)throw new Error(F.error);l("success"),n==null||n()}catch(X){p(X.message),l("error")}},[c,n]),T=g.useCallback(async(q,X,F,B,K)=>{A.current=!1,w(!0);const R=Date.now()+(Number.isFinite(K)&&K>0?K:12e4);for(;Date.now()<R;){if(A.current){console.log("[OAuthModal] Polling aborted"),w(!1);return}if(await new Promise(Z=>setTimeout(Z,F*1e3)),A.current){console.log("[OAuthModal] Polling aborted after sleep"),w(!1);return}try{const J=await(await fetch(`/api/oauth/${t}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:q,codeVerifier:X,extraData:B})})).json();if(J.success){A.current=!0,l("success"),w(!1),n==null||n();return}if(J.error==="expired_token"||J.error==="access_denied")throw new Error(J.errorDescription||J.error);J.error==="slow_down"&&(F=Math.min(F+5,30))}catch(Z){p(Z.message),l("error"),w(!1);return}}p("Authorization timeout"),l("error"),w(!1)},[t,n]),$=g.useCallback(async()=>{if(t)try{if(p(null),["github","qwen","kiro","kimi-coding","kilocode","codebuddy-cn","qoder","grok-cli"].includes(t)){x(!0),l("waiting");const re=new URL(`/api/oauth/${t}/device-code`,window.location.origin);t==="kiro"&&(o!=null&&o.startUrl)&&(re.searchParams.set("start_url",o.startUrl),o.region&&re.searchParams.set("region",o.region),re.searchParams.set("auth_method","idc"));const le=await fetch(re.toString()),se=await le.json();if(!le.ok)throw new Error(se.error);S(se);const ce=se.verification_uri_complete||se.verification_uri;ce&&window.open(ce,"_blank","noopener,noreferrer");const ke=t==="kiro"?{_clientId:se._clientId,_clientSecret:se._clientSecret,_region:se._region,_authMethod:se._authMethod,_startUrl:se._startUrl}:t==="qoder"?{_qoderNonce:se._qoderNonce,_qoderMachineId:se._qoderMachineId,_qoderVerifier:se.codeVerifier}:null;T(se.device_code,se.codeVerifier,se.interval||5,ke,Number.isFinite(se.expires_in)&&se.expires_in>0?se.expires_in*1e3:void 0);return}const X=window.location.port||(window.location.protocol==="https:"?"443":"80");let F;t==="codex"?F="http://localhost:1455/auth/callback":t==="xai"?F="http://127.0.0.1:56121/callback":F=`http://localhost:${X}/callback`;const B=new URL(`/api/oauth/${t}/authorize`,window.location.origin);B.searchParams.set("redirect_uri",F),a&&Object.entries(a).forEach(([re,le])=>{le&&B.searchParams.set(re,le)});const K=await fetch(B.toString()),U=await K.json();if(!K.ok)throw new Error(U.error);let R=!1,Z=!1;if(t==="codex")try{const re=new URL("/api/oauth/codex/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();R=se.success,Z=!!se.serverSide}catch{R=!1}let J=!1,ee=!1;if(t==="xai")try{const re=new URL("/api/oauth/xai/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();if(J=se.success,ee=!!se.serverSide,!J&&se.reason==="port_busy")throw new Error("Port 56121 in use; close the conflicting process and retry")}catch(re){if(re!=null&&re.message)throw re;J=!1}if(u({...U,redirectUri:F,codexServerSide:Z,xaiServerSide:ee}),!U.authUrl)throw U.flowType==="device_code"?new Error(`Provider ${t} uses device-code login but is not wired in the OAuth modal device-code list`):new Error("No authorization URL returned from OAuth provider");t==="codex"&&R||t==="xai"&&J?(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input")):!M||t==="codex"||t==="xai"?(l("input"),window.open(U.authUrl,"_blank")):(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input"))}catch(q){p(q.message),l("error")}},[t,M,T,a,o]);g.useEffect(()=>{if(e&&t){if(_.current)return;_.current=!0,u(null),f(""),p(null),x(!1),S(null),w(!1),A.current=!1,$()}else e||(A.current=!0,_.current=!1,t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}))},[e,t,$]),g.useEffect(()=>{const q=c!=null&&c.codexServerSide?"codex":c!=null&&c.xaiServerSide?"xai":null;if(!q||!(c!=null&&c.state)||P.current)return;let X=!1;const F=1500,B=200;let K=0;const U=async()=>{if(!(X||P.current)){K+=1;try{const Z=await(await fetch(`/api/oauth/${q}/poll-status?state=${encodeURIComponent(c.state)}`)).json();if(X||P.current)return;if(Z.status==="done"){P.current=!0,l("success"),n==null||n();return}if(Z.status==="error"){P.current=!0,p(Z.error||"Authentication failed"),l("error");return}}catch{}if(K>=B){P.current=!0,p("Authentication timeout"),l("error");return}setTimeout(U,F)}};return setTimeout(U,F),()=>{X=!0}},[c,n]),g.useEffect(()=>{if(!c)return;P.current=!1;const q=async K=>{if(P.current)return;const{code:U,token:R,state:Z,error:J,errorDescription:ee}=K;if(J){P.current=!0,p(ee||J),l("error");return}(R||U)&&(P.current=!0,await I(R||U,Z))},X=K=>{var Z;const U=K.origin.includes("localhost")||K.origin.includes("127.0.0.1"),R=K.origin===window.location.origin;!U&&!R||((Z=K.data)==null?void 0:Z.type)==="oauth_callback"&&q(K.data.data)};window.addEventListener("message",X);let F;try{F=new BroadcastChannel("oauth_callback"),F.onmessage=K=>q(K.data)}catch{console.log("BroadcastChannel not supported")}const B=K=>{if(K.key==="oauth_callback"&&K.newValue)try{const U=JSON.parse(K.newValue);q(U),localStorage.removeItem("oauth_callback")}catch{console.log("Failed to parse localStorage data")}};window.addEventListener("storage",B);try{const K=localStorage.getItem("oauth_callback");if(K){const U=JSON.parse(K);U.timestamp&&Date.now()-U.timestamp<3e4&&q(U),localStorage.removeItem("oauth_callback")}}catch{}return()=>{window.removeEventListener("message",X),window.removeEventListener("storage",B),F&&F.close()}},[c,I]);const D=async()=>{try{p(null);const q=d.trim();if(q.startsWith("eyJ")&&q.includes(".")){await I(q,null);return}if(t==="xai"&&q&&!q.includes("://")&&!q.includes("?")&&!q.includes("code=")){await C(q);return}if(t==="kimchi"&&q&&!q.includes("://")&&!q.includes("?")){await I(q,null);return}const X=new URL(q),F=X.searchParams.get("code"),B=X.searchParams.get("token"),K=X.searchParams.get("state"),U=X.searchParams.get("error");if(U)throw new Error(X.searchParams.get("error_description")||U);if(!F&&!B)throw new Error(t==="xai"?"Paste the callback URL or copied xAI code":t==="kimchi"?"No Kimchi token found in URL":"No authorization code found in URL");await I(B||F,K)}catch(q){p(q.message),l("error")}},L=g.useCallback(()=>{t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}),i()},[i,t]);if(!t||!r)return null;const V=t==="xai",H=t==="kimchi",Q=(v==null?void 0:v.verification_uri_complete)||(v==null?void 0:v.verification_uri)||"",te=V?"Connect Grok Build OAuth":`Connect ${r.name}`,G=V?"http://127.0.0.1:56121/callback?code=... or copied code":H?`${k.replace("code=...","token=...")} or copied token`:k;return m.jsx(hr,{isOpen:e,title:te,onClose:L,size:"lg",children:m.jsxs("div",{className:"flex flex-col gap-4",children:[(s==="waiting"||s==="input")&&!y&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border border-border rounded-lg bg-sidebar/50",children:[m.jsx("span",{className:"material-symbols-outlined text-base text-primary animate-spin",children:"progress_activity"}),m.jsx("span",{className:"text-sm",children:V?"Waiting for Grok Build OAuth…":"Waiting for popup authorization…"})]}),m.jsxs("div",{className:"flex items-center gap-3 my-1",children:[m.jsx("div",{className:"flex-1 h-px bg-border"}),m.jsx("span",{className:"text-xs text-text-muted uppercase tracking-wider",children:"Or paste callback URL manually"}),m.jsx("div",{className:"flex-1 h-px bg-border"})]}),m.jsxs("div",{className:"space-y-4",children:[m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 1: Open this ",V?"Grok Build OAuth URL":"URL"," in your browser"]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(xe,{value:(c==null?void 0:c.authUrl)||"",readOnly:!0,className:"flex-1 font-mono text-xs"}),m.jsx(ue,{variant:"secondary",icon:O==="auth_url"?"check":"content_copy",onClick:()=>j(c==null?void 0:c.authUrl,"auth_url"),disabled:!(c!=null&&c.authUrl),children:"Copy"})]})]}),m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 2: Paste the ",t==="xai"?"callback URL or copied code":H?"callback URL or copied token":"callback URL"," here"]}),m.jsx("p",{className:"text-xs text-text-muted mb-2",children:t==="xai"?"If xAI shows a code instead of redirecting, paste that code here.":H?"After authorization, copy the full callback URL or token from your browser.":"After authorization, copy the full URL from your browser."}),m.jsx(xe,{value:d,onChange:q=>f(q.target.value),placeholder:G,className:"font-mono text-xs"})]})]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:D,fullWidth:!0,disabled:!d,children:"Connect"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),s==="waiting"&&y&&v&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"text-center py-4",children:[m.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Visit the login URL below and authorize:"}),m.jsxs("div",{className:"bg-sidebar p-4 rounded-lg mb-4",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Login URL"}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("code",{className:"flex-1 text-sm break-all",children:Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="login_url"?"check":"content_copy",onClick:()=>j(Q,"login_url"),disabled:!Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:"open_in_new",onClick:()=>window.open(Q,"_blank","noopener,noreferrer"),disabled:!Q,children:"Open"})]})]}),m.jsxs("div",{className:"bg-primary/10 p-4 rounded-lg",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Your Code"}),m.jsxs("div",{className:"flex items-center justify-center gap-2",children:[m.jsx("p",{className:"text-2xl font-mono font-bold text-primary",children:v.user_code}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="user_code"?"check":"content_copy",onClick:()=>j(v.user_code,"user_code")})]})]})]}),b&&m.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),"Waiting for authorization..."]})]}),s==="success"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-green-600",children:"check_circle"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connected Successfully!"}),m.jsxs("p",{className:"text-sm text-text-muted mb-4",children:["Your ",r.name," account has been connected."]}),m.jsx(ue,{onClick:L,fullWidth:!0,children:"Done"})]}),s==="error"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-red-600",children:"error"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connection Failed"}),m.jsx("p",{className:"text-sm text-red-600 mb-4",children:h}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:$,variant:"secondary",fullWidth:!0,children:"Try Again"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})]})})}Kc.propTypes={isOpen:Y.bool.isRequired,provider:Y.string,providerInfo:Y.shape({name:Y.string}),onSuccess:Y.func,onClose:Y.func.isRequired,oauthMeta:Y.object,idcConfig:Y.shape({startUrl:Y.string,region:Y.string})};const Gd=[...Object.keys(Kv),...Object.keys(Ja),...Object.keys(Vv),...Object.keys(Hv)],Zd=Object.keys(Ja).filter(e=>Ja[e].noAuth);function eA({isOpen:e,onClose:t,onSelect:r,onDeselect:n,selectedModel:i,activeProviders:a=[],title:o="Select Model",modelAliases:s={},kindFilter:l=null,addedModelValues:c=[],closeOnSelect:u=!0}){const d=g.useMemo(()=>l?a.filter(C=>{const T=Qa[C.provider];return((T==null?void 0:T.serviceKinds)||["llm"]).includes(l)}):a,[a,l]),[f,h]=g.useState(""),[p,y]=g.useState([]),[x,v]=g.useState([]),[S,b]=g.useState([]),[w,E]=g.useState({}),A=async()=>{try{const C=await fetch("/api/combos");if(!C.ok)throw new Error(`Failed to fetch combos: ${C.status}`);const T=await C.json();y(T.combos||[])}catch(C){console.error("Error fetching combos:",C),y([])}};g.useEffect(()=>{e&&A()},[e]);const _=async()=>{try{const C=await fetch("/api/provider-nodes");if(!C.ok)throw new Error(`Failed to fetch provider nodes: ${C.status}`);const T=await C.json();v(T.nodes||[])}catch(C){console.error("Error fetching provider nodes:",C),v([])}};g.useEffect(()=>{e&&_()},[e]);const O=async()=>{try{const C=await fetch("/api/models/custom");if(!C.ok)throw new Error(`Failed to fetch custom models: ${C.status}`);const T=await C.json();b(T.models||[])}catch(C){console.error("Error fetching custom models:",C),b([])}};g.useEffect(()=>{e&&O()},[e]);const j=async()=>{try{const C=await fetch("/api/models/disabled");if(!C.ok)throw new Error(`Failed to fetch disabled models: ${C.status}`);const T=await C.json();E(T.disabled||{})}catch(C){console.error("Error fetching disabled models:",C),E({})}};g.useEffect(()=>{e&&j()},[e]);const M=g.useMemo(()=>({...Kv,...Ja,...Vv,...Hv}),[]),N=g.useMemo(()=>{const C={},T=new Set(["webSearch","webFetch"]),$=new Set(["image","tts","stt","embedding","imageToText"]),D=new Set(["tts","image","webFetch"]),L=G=>l?$.has(l)?G.filter(q=>q.isPlaceholder||q.type===l):G:G.filter(q=>q.isPlaceholder||!q.type||q.type==="llm"),V=d.map(G=>G.provider),H=l?Zd.filter(G=>{var q;return(((q=Qa[G])==null?void 0:q.serviceKinds)||["llm"]).includes(l)}):Zd;return[...new Set([...V,...H])].sort((G,q)=>{const X=Gd.indexOf(G),F=Gd.indexOf(q);return(X===-1?999:X)-(F===-1?999:F)}).forEach(G=>{var B;const q=Yd(G),X=M[G]||{name:G,color:"#666"},F=qv(G)||Yv(G);if(l&&T.has(l)){C[G]={name:X.name,alias:q,color:X.color,models:[{id:G,name:X.name,value:G}]};return}if(X.passthroughModels){let U=Object.entries(s).filter(([,R])=>R.startsWith(`${q}/`)).map(([R,Z])=>({id:Z.replace(`${q}/`,""),name:R,value:Z}));if(l&&$.has(l)&&(U=Xd(G).filter(R=>R.type===l).map(R=>({id:R.id,name:R.name,value:`${q}/${R.id}`,type:R.type})),U.length===0&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(U=[{id:G,name:X.name,value:q}])),U.length>0){const R=x.find(J=>J.id===G),Z=(R==null?void 0:R.name)||X.name;C[G]={name:Z,alias:q,color:X.color,models:U}}}else if(F){if(l&&$.has(l))return;const K=a.find(re=>re.provider===G),U=x.find(re=>re.id===G),R=(K==null?void 0:K.name)||(U==null?void 0:U.name)||X.name,Z=((B=K==null?void 0:K.providerSpecificData)==null?void 0:B.prefix)||(U==null?void 0:U.prefix)||G,J=Object.entries(s).filter(([,re])=>re.startsWith(`${G}/`)).map(([re,le])=>({id:le.replace(`${G}/`,""),name:re,value:`${Z}/${le.replace(`${G}/`,"")}`})),ee=J.length>0?J:[{id:`__placeholder__${G}`,name:`${Z}/model-id`,value:`${Z}/model-id`,isPlaceholder:!0}];C[G]={name:R,alias:Z,color:X.color,models:ee,isCustom:!0,hasModels:J.length>0}}else{const K=Xd(G),U=new Set(K.map(ce=>ce.id)),R=K.length>0,Z=Object.entries(s).filter(([ce,ke])=>ke.startsWith(`${q}/`)&&(R?ce===ke.replace(`${q}/`,""):!0)&&!U.has(ke.replace(`${q}/`,""))).map(([ce,ke])=>({id:ke.replace(`${q}/`,""),name:ce,value:ke,isCustom:!0})),J=new Set(Z.map(ce=>ce.id)),ee=S.filter(ce=>ce.providerAlias===q&&!U.has(ce.id)&&!J.has(ce.id)).map(ce=>({id:ce.id,name:ce.name||ce.id,value:`${q}/${ce.id}`,isCustom:!0})),re=[...K.map(ce=>({id:ce.id,name:ce.name,value:`${q}/${ce.id}`,type:ce.type})),...Z,...ee],le=new Set;let se=L(re.filter(ce=>le.has(ce.value)?!1:(le.add(ce.value),!0)));se.length===0&&l&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(se=[{id:G,name:X.name,value:q}]),se.length>0&&(C[G]={name:X.name,alias:q,color:X.color,models:se})}}),Object.entries(C).forEach(([G,q])=>{const X=Yd(G),F=new Set([...w[X]||[],...w[G]||[]]);F.size!==0&&(q.models=q.models.filter(B=>!F.has(B.id)),q.models.length===0&&delete C[G])}),C},[d,s,M,x,S,w,l,a]),k=g.useMemo(()=>{if(l)return[];if(!f.trim())return p;const C=f.toLowerCase();return p.filter(T=>T.name.toLowerCase().includes(C))},[p,f,l]),z=C=>{const T=C.filter(D=>c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name)),$=C.filter(D=>!c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name));return[...T,...$]},P=g.useMemo(()=>{const C=f.trim().toLowerCase(),T={};return Object.entries(N).forEach(([$,D])=>{let L=D.models;if(C){const V=D.name.toLowerCase().includes(C);if(L=L.filter(H=>H.name.toLowerCase().includes(C)||H.id.toLowerCase().includes(C)),L.length===0&&!V)return}T[$]={...D,models:z(L)}}),T},[N,f,c]),I=C=>{const T=(C==null?void 0:C.value)||(C==null?void 0:C.name)||C;c.includes(T)&&n?n(C):r(C),u&&(t(),h(""))};return m.jsxs(hr,{isOpen:e,onClose:()=>{t(),h("")},title:o,size:"md",className:"p-4!",footer:null,children:[m.jsxs("div",{className:"flex items-center gap-2 mb-3 px-2.5 py-2 bg-primary/8 border border-primary/20 rounded-lg text-xs text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined text-primary shrink-0",style:{fontSize:"14px"},children:"info"}),m.jsx("span",{children:"Click to add, click again to remove. Changes are saved automatically."})]}),m.jsx("div",{className:"mb-3",children:m.jsxs("div",{className:"relative",children:[m.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-text-muted text-[16px]",children:"search"}),m.jsx("input",{type:"text",placeholder:"Search...",value:f,onChange:C=>h(C.target.value),className:"w-full pl-8 pr-3 py-1.5 bg-surface border border-border rounded text-xs focus:outline-none focus:ring-1 focus:ring-primary/50"})]})}),m.jsxs("div",{className:"max-h-[400px] overflow-y-auto space-y-3",children:[k.length>0&&m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx("span",{className:"material-symbols-outlined text-primary text-[14px]",children:"layers"}),m.jsx("span",{className:"text-xs font-medium text-primary",children:"Combos"}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",k.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(C=>{const T=i===C.name;return m.jsxs("button",{onClick:()=>I({id:C.name,name:C.name,value:C.name}),className:`
|
|
1
|
+
var KS=Object.defineProperty;var qS=(e,t,r)=>t in e?KS(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ma=(e,t,r)=>qS(e,typeof t!="symbol"?t+"":t,r);import{j as m,n as at,u as Uv,M as hr,B as ue,f as Y,g as Qa,A as Hv,c as Vv,F as Ja,O as Kv,i as Yd,k as qv,l as Yv,h as Xd,P as YS}from"./index.Be3gbrBl.js";import{b as g,r as Vc,g as Xv,W as XS,c as Gv,i as GS}from"./router.Cjj1--8t.js";function xe({label:e,type:t="text",placeholder:r,value:n,onChange:i,error:a,hint:o,icon:s,disabled:l=!1,required:c=!1,className:u,inputClassName:d,...f}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",u),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,c&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[s&&m.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:s})}),m.jsx("input",{type:t,placeholder:r,value:n,onChange:i,disabled:l,className:at("w-full py-2.5 px-3 text-sm text-text-main bg-surface-2 rounded-[10px]","border border-transparent placeholder-text-muted/70","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 ease-out disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",s&&"pl-10",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",d),...f})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function ZS({label:e,options:t=[],value:r,onChange:n,placeholder:i="Select an option",error:a,hint:o,disabled:s=!1,required:l=!1,className:c,selectClassName:u,...d}){return m.jsxs("div",{className:at("flex flex-col gap-1.5",c),children:[e&&m.jsxs("label",{className:"text-sm font-medium text-text-main",children:[e,l&&m.jsx("span",{className:"text-red-500 ml-1",children:"*"})]}),m.jsxs("div",{className:"relative",children:[m.jsxs("select",{value:r,onChange:n,disabled:s,className:at("w-full py-2.5 px-3 pr-10 text-sm text-text-main","bg-surface-2 border border-transparent rounded-[10px] appearance-none","focus:outline-none focus:ring-2 focus:ring-brand-500/30 focus:border-brand-500/40","transition-all duration-150 disabled:opacity-50 disabled:cursor-not-allowed","text-[16px] sm:text-sm",a&&"ring-1 ring-red-500 focus:ring-2 focus:ring-red-500/40 border-red-500/40",u),...d,children:[m.jsx("option",{value:"",disabled:!0,children:i}),t.map(f=>m.jsx("option",{value:f.value,children:f.label},f.value))]}),m.jsx("div",{className:"absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:"expand_more"})})]}),a&&m.jsxs("p",{className:"text-xs text-red-500 flex items-center gap-1",children:[m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:"error"}),a]}),o&&!a&&m.jsx("p",{className:"text-xs text-text-muted",children:o})]})}function zt({children:e,title:t,subtitle:r,icon:n,action:i,padding:a="md",hover:o=!1,elev:s=!1,className:l,...c}){const u={none:"",xs:"p-3",sm:"p-4",md:"p-6",lg:"p-8"};return m.jsxs("div",{className:at("bg-surface border border-border-subtle",s?"rounded-[14px] shadow-[var(--shadow-elev)]":"rounded-[14px] shadow-[var(--shadow-soft)]",o&&"hover:shadow-[var(--shadow-warm)] hover:border-brand-500/30 transition-all cursor-pointer",u[a],l),...c,children:[(t||i)&&m.jsxs("div",{className:"flex items-center justify-between mb-4",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[n&&m.jsx("div",{className:"p-2 rounded-[10px] bg-bg text-text-muted",children:m.jsx("span",{className:"material-symbols-outlined text-[20px]",children:n})}),m.jsxs("div",{children:[t&&m.jsx("h3",{className:"text-text-main font-semibold",children:t}),r&&m.jsx("p",{className:"text-sm text-text-muted",children:r})]})]}),i]}),e]})}zt.Section=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-4 rounded-[10px]","bg-bg border border-border-subtle",r),...n,children:t})};zt.Row=function({children:t,className:r,...n}){return m.jsx("div",{className:at("p-3 -mx-3 px-3 transition-colors","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50",r),...n,children:t})};zt.ListItem=function({children:t,actions:r,className:n,...i}){return m.jsxs("div",{className:at("group flex items-center justify-between p-3 -mx-3 px-3","border-b border-border-subtle last:border-b-0","hover:bg-surface-2/50 transition-colors",n),...i,children:[m.jsx("div",{className:"flex-1 min-w-0",children:t}),r&&m.jsx("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:r})]})};const QS={default:"bg-surface-2 text-text-muted",primary:"bg-brand-500/10 text-brand-600 dark:text-brand-300",success:"bg-green-500/10 text-green-600 dark:text-green-400",warning:"bg-yellow-500/10 text-yellow-600 dark:text-yellow-400",error:"bg-red-500/10 text-red-600 dark:text-red-400",info:"bg-blue-500/10 text-blue-600 dark:text-blue-400"},JS={sm:"px-2 py-0.5 text-[10px]",md:"px-2.5 py-1 text-xs",lg:"px-3 py-1.5 text-sm"};function Ci({children:e,variant:t="default",size:r="md",dot:n=!1,icon:i,className:a}){return m.jsxs("span",{className:at("inline-flex items-center gap-1.5 rounded-full font-semibold",QS[t],JS[r],a),children:[n&&m.jsx("span",{className:at("size-1.5 rounded-full",t==="success"&&"bg-green-500",t==="warning"&&"bg-yellow-500",t==="error"&&"bg-red-500",t==="info"&&"bg-blue-500",t==="primary"&&"bg-brand-500",t==="default"&&"bg-gray-500")}),i&&m.jsx("span",{className:"material-symbols-outlined text-[14px]",children:i}),e]})}function Js({checked:e=!1,onChange:t,label:r,description:n,disabled:i=!1,size:a="md",className:o}){const s={sm:{track:"w-8 h-4",thumb:"size-3",translate:"translate-x-4"},md:{track:"w-11 h-6",thumb:"size-5",translate:"translate-x-5"},lg:{track:"w-14 h-7",thumb:"size-6",translate:"translate-x-7"}},l=()=>{!i&&t&&t(!e)};return m.jsxs("div",{className:at("flex items-center gap-3",i&&"opacity-50 cursor-not-allowed",o),children:[m.jsx("button",{type:"button",role:"switch","aria-checked":e,disabled:i,onClick:l,className:at("relative inline-flex shrink-0 cursor-pointer rounded-full","transition-colors duration-200 ease-in-out","focus:outline-none focus:ring-2 focus:ring-brand-500/30",e?"bg-brand-500":"bg-surface-3",s[a].track,i&&"cursor-not-allowed"),children:m.jsx("span",{className:at("pointer-events-none inline-block rounded-full bg-white shadow-sm","transform transition duration-200 ease-in-out",e?s[a].translate:"translate-x-0.5",s[a].thumb,"mt-0.5")})}),(r||n)&&m.jsxs("div",{className:"flex flex-col",children:[r&&m.jsx("span",{className:"text-sm font-medium text-text-main",children:r}),n&&m.jsx("span",{className:"text-xs text-text-muted",children:n})]})]})}function Kc({isOpen:e,provider:t,providerInfo:r,onSuccess:n,onClose:i,oauthMeta:a,idcConfig:o}){const[s,l]=g.useState("waiting"),[c,u]=g.useState(null),[d,f]=g.useState(""),[h,p]=g.useState(null),[y,x]=g.useState(!1),[v,S]=g.useState(null),[b,w]=g.useState(!1),E=g.useRef(null),A=g.useRef(!1),_=g.useRef(!1),{copied:O,copy:j}=Uv(),[M,N]=g.useState(!1),[k,z]=g.useState("/callback?code=..."),P=g.useRef(!1);g.useEffect(()=>{typeof window<"u"&&(N(window.location.hostname==="localhost"||window.location.hostname==="127.0.0.1"),z(`${window.location.origin}/callback?code=...`))},[]);const I=g.useCallback(async(q,X)=>{if(c)try{const F=await fetch(`/api/oauth/${t}/exchange`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,redirectUri:c.redirectUri,codeVerifier:c.codeVerifier,state:X,...a?{meta:a}:{}})}),B=await F.json();if(!F.ok)throw new Error(B.error);l("success"),n==null||n()}catch(F){p(F.message),l("error")}},[c,t,n,a]),C=g.useCallback(async q=>{if(c!=null&&c.state)try{const X=await fetch("/api/oauth/xai/manual-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:q,state:c.state})}),F=await X.json();if(!X.ok)throw new Error(F.error);l("success"),n==null||n()}catch(X){p(X.message),l("error")}},[c,n]),T=g.useCallback(async(q,X,F,B,K)=>{A.current=!1,w(!0);const R=Date.now()+(Number.isFinite(K)&&K>0?K:12e4);for(;Date.now()<R;){if(A.current){console.log("[OAuthModal] Polling aborted"),w(!1);return}if(await new Promise(Z=>setTimeout(Z,F*1e3)),A.current){console.log("[OAuthModal] Polling aborted after sleep"),w(!1);return}try{const J=await(await fetch(`/api/oauth/${t}/poll`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({deviceCode:q,codeVerifier:X,extraData:B})})).json();if(J.success){A.current=!0,l("success"),w(!1),n==null||n();return}if(J.error==="expired_token"||J.error==="access_denied")throw new Error(J.errorDescription||J.error);J.error==="slow_down"&&(F=Math.min(F+5,30))}catch(Z){p(Z.message),l("error"),w(!1);return}}p("Authorization timeout"),l("error"),w(!1)},[t,n]),$=g.useCallback(async()=>{if(t)try{if(p(null),["github","qwen","kiro","kimi-coding","kilocode","codebuddy-cn","qoder","grok-cli"].includes(t)){x(!0),l("waiting");const re=new URL(`/api/oauth/${t}/device-code`,window.location.origin);t==="kiro"&&(o!=null&&o.startUrl)&&(re.searchParams.set("start_url",o.startUrl),o.region&&re.searchParams.set("region",o.region),re.searchParams.set("auth_method","idc"));const le=await fetch(re.toString()),se=await le.json();if(!le.ok)throw new Error(se.error);S(se);const ce=se.verification_uri_complete||se.verification_uri;ce&&window.open(ce,"_blank","noopener,noreferrer");const ke=t==="kiro"?{_clientId:se._clientId,_clientSecret:se._clientSecret,_region:se._region,_authMethod:se._authMethod,_startUrl:se._startUrl}:t==="qoder"?{_qoderNonce:se._qoderNonce,_qoderMachineId:se._qoderMachineId,_qoderVerifier:se.codeVerifier}:null;T(se.device_code,se.codeVerifier,se.interval||5,ke,Number.isFinite(se.expires_in)&&se.expires_in>0?se.expires_in*1e3:void 0);return}const X=window.location.port||(window.location.protocol==="https:"?"443":"80");let F;t==="codex"?F="http://localhost:1455/auth/callback":t==="xai"?F="http://127.0.0.1:56121/callback":F=`http://localhost:${X}/callback`;const B=new URL(`/api/oauth/${t}/authorize`,window.location.origin);B.searchParams.set("redirect_uri",F),a&&Object.entries(a).forEach(([re,le])=>{le&&B.searchParams.set(re,le)});const K=await fetch(B.toString()),U=await K.json();if(!K.ok)throw new Error(U.error);let R=!1,Z=!1;if(t==="codex")try{const re=new URL("/api/oauth/codex/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();R=se.success,Z=!!se.serverSide}catch{R=!1}let J=!1,ee=!1;if(t==="xai")try{const re=new URL("/api/oauth/xai/start-proxy",window.location.origin);re.searchParams.set("app_port",X),re.searchParams.set("state",U.state),re.searchParams.set("code_verifier",U.codeVerifier),re.searchParams.set("redirect_uri",F);const se=await(await fetch(re.toString())).json();if(J=se.success,ee=!!se.serverSide,!J&&se.reason==="port_busy")throw new Error("Port 56121 in use; close the conflicting process and retry")}catch(re){if(re!=null&&re.message)throw re;J=!1}if(u({...U,redirectUri:F,codexServerSide:Z,xaiServerSide:ee}),!U.authUrl)throw U.flowType==="device_code"?new Error(`Provider ${t} uses device-code login but is not wired in the OAuth modal device-code list`):new Error("No authorization URL returned from OAuth provider");t==="codex"&&R||t==="xai"&&J?(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input")):!M||t==="codex"||t==="xai"?(l("input"),window.open(U.authUrl,"_blank")):(l("waiting"),E.current=window.open(U.authUrl,"oauth_popup","width=600,height=700"),E.current||l("input"))}catch(q){p(q.message),l("error")}},[t,M,T,a,o]);g.useEffect(()=>{if(e&&t){if(_.current)return;_.current=!0,u(null),f(""),p(null),x(!1),S(null),w(!1),A.current=!1,$()}else e||(A.current=!0,_.current=!1,t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}))},[e,t,$]),g.useEffect(()=>{const q=c!=null&&c.codexServerSide?"codex":c!=null&&c.xaiServerSide?"xai":null;if(!q||!(c!=null&&c.state)||P.current)return;let X=!1;const F=1500,B=200;let K=0;const U=async()=>{if(!(X||P.current)){K+=1;try{const Z=await(await fetch(`/api/oauth/${q}/poll-status?state=${encodeURIComponent(c.state)}`)).json();if(X||P.current)return;if(Z.status==="done"){P.current=!0,l("success"),n==null||n();return}if(Z.status==="error"){P.current=!0,p(Z.error||"Authentication failed"),l("error");return}}catch{}if(K>=B){P.current=!0,p("Authentication timeout"),l("error");return}setTimeout(U,F)}};return setTimeout(U,F),()=>{X=!0}},[c,n]),g.useEffect(()=>{if(!c)return;P.current=!1;const q=async K=>{if(P.current)return;const{code:U,token:R,state:Z,error:J,errorDescription:ee}=K;if(J){P.current=!0,p(ee||J),l("error");return}(R||U)&&(P.current=!0,await I(R||U,Z))},X=K=>{var Z;const U=K.origin.includes("localhost")||K.origin.includes("127.0.0.1"),R=K.origin===window.location.origin;!U&&!R||((Z=K.data)==null?void 0:Z.type)==="oauth_callback"&&q(K.data.data)};window.addEventListener("message",X);let F;try{F=new BroadcastChannel("oauth_callback"),F.onmessage=K=>q(K.data)}catch{console.log("BroadcastChannel not supported")}const B=K=>{if(K.key==="oauth_callback"&&K.newValue)try{const U=JSON.parse(K.newValue);q(U),localStorage.removeItem("oauth_callback")}catch{console.log("Failed to parse localStorage data")}};window.addEventListener("storage",B);try{const K=localStorage.getItem("oauth_callback");if(K){const U=JSON.parse(K);U.timestamp&&Date.now()-U.timestamp<3e4&&q(U),localStorage.removeItem("oauth_callback")}}catch{}return()=>{window.removeEventListener("message",X),window.removeEventListener("storage",B),F&&F.close()}},[c,I]);const D=async()=>{try{p(null);const q=d.trim();if(q.startsWith("eyJ")&&q.includes(".")){await I(q,null);return}if(t==="xai"&&q&&!q.includes("://")&&!q.includes("?")&&!q.includes("code=")){await C(q);return}if(t==="kimchi"&&q&&!q.includes("://")&&!q.includes("?")){await I(q,null);return}const X=new URL(q),F=X.searchParams.get("code"),B=X.searchParams.get("token"),K=X.searchParams.get("state"),U=X.searchParams.get("error");if(U)throw new Error(X.searchParams.get("error_description")||U);if(!F&&!B)throw new Error(t==="xai"?"Paste the callback URL or copied xAI code":t==="kimchi"?"No Kimchi token found in URL":"No authorization code found in URL");await I(B||F,K)}catch(q){p(q.message),l("error")}},L=g.useCallback(()=>{t==="codex"?fetch("/api/oauth/codex/stop-proxy").catch(()=>{}):t==="xai"&&fetch("/api/oauth/xai/stop-proxy").catch(()=>{}),i()},[i,t]);if(!t||!r)return null;const V=t==="xai",H=t==="kimchi",Q=(v==null?void 0:v.verification_uri_complete)||(v==null?void 0:v.verification_uri)||"",te=V?"Connect Grok Build OAuth":`Connect ${r.name}`,G=V?"http://127.0.0.1:56121/callback?code=... or copied code":H?`${k.replace("code=...","token=...")} or copied token`:k;return m.jsx(hr,{isOpen:e,title:te,onClose:L,size:"lg",children:m.jsxs("div",{className:"flex flex-col gap-4",children:[(s==="waiting"||s==="input")&&!y&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 border border-border rounded-lg bg-sidebar/50",children:[m.jsx("span",{className:"material-symbols-outlined text-base text-primary animate-spin",children:"progress_activity"}),m.jsx("span",{className:"text-sm",children:V?"Waiting for Grok Build OAuth…":"Waiting for popup authorization…"})]}),m.jsxs("div",{className:"flex items-center gap-3 my-1",children:[m.jsx("div",{className:"flex-1 h-px bg-border"}),m.jsx("span",{className:"text-xs text-text-muted uppercase tracking-wider",children:"Or paste callback URL manually"}),m.jsx("div",{className:"flex-1 h-px bg-border"})]}),m.jsxs("div",{className:"space-y-4",children:[m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 1: Open this ",V?"Grok Build OAuth URL":"URL"," in your browser"]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(xe,{value:(c==null?void 0:c.authUrl)||"",readOnly:!0,className:"flex-1 font-mono text-xs"}),m.jsx(ue,{variant:"secondary",icon:O==="auth_url"?"check":"content_copy",onClick:()=>j(c==null?void 0:c.authUrl,"auth_url"),disabled:!(c!=null&&c.authUrl),children:"Copy"})]})]}),m.jsxs("div",{children:[m.jsxs("p",{className:"text-sm font-medium mb-2",children:["Step 2: Paste the ",t==="xai"?"callback URL or copied code":H?"callback URL or copied token":"callback URL"," here"]}),m.jsx("p",{className:"text-xs text-text-muted mb-2",children:t==="xai"?"If xAI shows a code instead of redirecting, paste that code here.":H?"After authorization, copy the full callback URL or token from your browser.":"After authorization, copy the full URL from your browser."}),m.jsx(xe,{value:d,onChange:q=>f(q.target.value),placeholder:G,className:"font-mono text-xs"})]})]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:D,fullWidth:!0,disabled:!d,children:"Connect"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]}),s==="waiting"&&y&&v&&m.jsxs(m.Fragment,{children:[m.jsxs("div",{className:"text-center py-4",children:[m.jsx("p",{className:"text-sm text-text-muted mb-4",children:"Visit the login URL below and authorize:"}),m.jsxs("div",{className:"bg-sidebar p-4 rounded-lg mb-4",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Login URL"}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("code",{className:"flex-1 text-sm break-all",children:Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="login_url"?"check":"content_copy",onClick:()=>j(Q,"login_url"),disabled:!Q}),m.jsx(ue,{size:"sm",variant:"ghost",icon:"open_in_new",onClick:()=>window.open(Q,"_blank","noopener,noreferrer"),disabled:!Q,children:"Open"})]})]}),m.jsxs("div",{className:"bg-primary/10 p-4 rounded-lg",children:[m.jsx("p",{className:"text-xs text-text-muted mb-1",children:"Your Code"}),m.jsxs("div",{className:"flex items-center justify-center gap-2",children:[m.jsx("p",{className:"text-2xl font-mono font-bold text-primary",children:v.user_code}),m.jsx(ue,{size:"sm",variant:"ghost",icon:O==="user_code"?"check":"content_copy",onClick:()=>j(v.user_code,"user_code")})]})]})]}),b&&m.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined animate-spin",children:"progress_activity"}),"Waiting for authorization..."]})]}),s==="success"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-green-100 dark:bg-green-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-green-600",children:"check_circle"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connected Successfully!"}),m.jsxs("p",{className:"text-sm text-text-muted mb-4",children:["Your ",r.name," account has been connected."]}),m.jsx(ue,{onClick:L,fullWidth:!0,children:"Done"})]}),s==="error"&&m.jsxs("div",{className:"text-center py-6",children:[m.jsx("div",{className:"size-16 mx-auto mb-4 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center",children:m.jsx("span",{className:"material-symbols-outlined text-3xl text-red-600",children:"error"})}),m.jsx("h3",{className:"text-lg font-semibold mb-2",children:"Connection Failed"}),m.jsx("p",{className:"text-sm text-red-600 mb-4",children:h}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx(ue,{onClick:$,variant:"secondary",fullWidth:!0,children:"Try Again"}),m.jsx(ue,{onClick:L,variant:"ghost",fullWidth:!0,children:"Cancel"})]})]})]})})}Kc.propTypes={isOpen:Y.bool.isRequired,provider:Y.string,providerInfo:Y.shape({name:Y.string}),onSuccess:Y.func,onClose:Y.func.isRequired,oauthMeta:Y.object,idcConfig:Y.shape({startUrl:Y.string,region:Y.string})};const Gd=[...Object.keys(Kv),...Object.keys(Ja),...Object.keys(Vv),...Object.keys(Hv)],Zd=Object.keys(Ja).filter(e=>Ja[e].noAuth);function eA({isOpen:e,onClose:t,onSelect:r,onDeselect:n,selectedModel:i,activeProviders:a=[],title:o="Select Model",modelAliases:s={},kindFilter:l=null,addedModelValues:c=[],closeOnSelect:u=!0}){const d=g.useMemo(()=>l?a.filter(C=>{const T=Qa[C.provider];return((T==null?void 0:T.serviceKinds)||["llm"]).includes(l)}):a,[a,l]),[f,h]=g.useState(""),[p,y]=g.useState([]),[x,v]=g.useState([]),[S,b]=g.useState([]),[w,E]=g.useState({}),A=async()=>{try{const C=await fetch("/api/combos");if(!C.ok)throw new Error(`Failed to fetch combos: ${C.status}`);const T=await C.json();y(T.combos||[])}catch(C){console.error("Error fetching combos:",C),y([])}};g.useEffect(()=>{e&&A()},[e]);const _=async()=>{try{const C=await fetch("/api/provider-nodes");if(!C.ok)throw new Error(`Failed to fetch provider nodes: ${C.status}`);const T=await C.json();v(T.nodes||[])}catch(C){console.error("Error fetching provider nodes:",C),v([])}};g.useEffect(()=>{e&&_()},[e]);const O=async()=>{try{const C=await fetch("/api/models/custom");if(!C.ok)throw new Error(`Failed to fetch custom models: ${C.status}`);const T=await C.json();b(T.models||[])}catch(C){console.error("Error fetching custom models:",C),b([])}};g.useEffect(()=>{e&&O()},[e]);const j=async()=>{try{const C=await fetch("/api/models/disabled");if(!C.ok)throw new Error(`Failed to fetch disabled models: ${C.status}`);const T=await C.json();E(T.disabled||{})}catch(C){console.error("Error fetching disabled models:",C),E({})}};g.useEffect(()=>{e&&j()},[e]);const M=g.useMemo(()=>({...Kv,...Ja,...Vv,...Hv}),[]),N=g.useMemo(()=>{const C={},T=new Set(["webSearch","webFetch"]),$=new Set(["image","tts","stt","embedding","imageToText"]),D=new Set(["tts","image","webFetch"]),L=G=>l?$.has(l)?G.filter(q=>q.isPlaceholder||q.type===l):G:G.filter(q=>q.isPlaceholder||!q.type||q.type==="llm"),V=d.map(G=>G.provider),H=l?Zd.filter(G=>{var q;return(((q=Qa[G])==null?void 0:q.serviceKinds)||["llm"]).includes(l)}):Zd;return[...new Set([...V,...H])].sort((G,q)=>{const X=Gd.indexOf(G),F=Gd.indexOf(q);return(X===-1?999:X)-(F===-1?999:F)}).forEach(G=>{var B;const q=Yd(G),X=M[G]||{name:G,color:"#666"},F=qv(G)||Yv(G);if(l&&T.has(l)){C[G]={name:X.name,alias:q,color:X.color,models:[{id:G,name:X.name,value:G}]};return}if(X.passthroughModels){let U=Object.entries(s).filter(([,R])=>R.startsWith(`${q}/`)).map(([R,Z])=>({id:Z.replace(`${q}/`,""),name:R,value:Z}));if(l&&$.has(l)&&(U=Xd(G).filter(R=>R.type===l).map(R=>({id:R.id,name:R.name,value:`${q}/${R.id}`,type:R.type})),U.length===0&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(U=[{id:G,name:X.name,value:q}])),U.length>0){const R=x.find(J=>J.id===G),Z=(R==null?void 0:R.name)||X.name;C[G]={name:Z,alias:q,color:X.color,models:U}}}else if(F){if(l&&$.has(l))return;const K=a.find(re=>re.provider===G),U=x.find(re=>re.id===G),R=(K==null?void 0:K.name)||(U==null?void 0:U.name)||X.name,Z=((B=K==null?void 0:K.providerSpecificData)==null?void 0:B.prefix)||(U==null?void 0:U.prefix)||G,J=Object.entries(s).filter(([,re])=>re.startsWith(`${G}/`)).map(([re,le])=>({id:le.replace(`${G}/`,""),name:re,value:`${Z}/${le.replace(`${G}/`,"")}`})),ee=J.length>0?J:[{id:`__placeholder__${G}`,name:`${Z}/model-id`,value:`${Z}/model-id`,isPlaceholder:!0}];C[G]={name:R,alias:Z,color:X.color,models:ee,isCustom:!0,hasModels:J.length>0}}else{const K=Xd(G),U=new Set(K.map(ce=>ce.id)),R=K.length>0,Z=Object.entries(s).filter(([ce,ke])=>ke.startsWith(`${q}/`)&&(R?ce===ke.replace(`${q}/`,""):!0)&&!U.has(ke.replace(`${q}/`,""))).map(([ce,ke])=>({id:ke.replace(`${q}/`,""),name:ce,value:ke,isCustom:!0})),J=new Set(Z.map(ce=>ce.id)),ee=S.filter(ce=>ce.providerAlias===q&&!U.has(ce.id)&&!J.has(ce.id)).map(ce=>({id:ce.id,name:ce.name||ce.id,value:`${q}/${ce.id}`,isCustom:!0})),re=[...K.map(ce=>({id:ce.id,name:ce.name,value:`${q}/${ce.id}`,type:ce.type})),...Z,...ee],le=new Set;let se=L(re.filter(ce=>le.has(ce.value)?!1:(le.add(ce.value),!0)));se.length===0&&l&&D.has(l)&&(X.serviceKinds||["llm"]).includes(l)&&(se=[{id:G,name:X.name,value:q}]),se.length>0&&(C[G]={name:X.name,alias:q,color:X.color,models:se})}}),Object.entries(C).forEach(([G,q])=>{const X=Yd(G),F=new Set([...w[X]||[],...w[G]||[]]);F.size!==0&&(q.models=q.models.filter(B=>!F.has(B.id)),q.models.length===0&&delete C[G])}),C},[d,s,M,x,S,w,l,a]),k=g.useMemo(()=>{if(l)return[];if(!f.trim())return p;const C=f.toLowerCase();return p.filter(T=>T.name.toLowerCase().includes(C))},[p,f,l]),z=C=>{const T=C.filter(D=>c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name)),$=C.filter(D=>!c.includes(D.value)).sort((D,L)=>D.name.localeCompare(L.name));return[...T,...$]},P=g.useMemo(()=>{const C=f.trim().toLowerCase(),T={};return Object.entries(N).forEach(([$,D])=>{let L=D.models;if(C){const V=D.name.toLowerCase().includes(C);if(L=L.filter(H=>H.name.toLowerCase().includes(C)||H.id.toLowerCase().includes(C)),L.length===0&&!V)return}T[$]={...D,models:z(L)}}),T},[N,f,c]),I=C=>{const T=(C==null?void 0:C.value)||(C==null?void 0:C.name)||C;c.includes(T)&&n?n(C):r(C),u&&(t(),h(""))};return m.jsxs(hr,{isOpen:e,onClose:()=>{t(),h("")},title:o,size:"md",className:"p-4!",footer:null,children:[m.jsxs("div",{className:"flex items-center gap-2 mb-3 px-2.5 py-2 bg-primary/8 border border-primary/20 rounded-lg text-xs text-text-muted",children:[m.jsx("span",{className:"material-symbols-outlined text-primary shrink-0",style:{fontSize:"14px"},children:"info"}),m.jsx("span",{children:"Click to add, click again to remove. Changes are saved automatically."})]}),m.jsx("div",{className:"mb-3",children:m.jsxs("div",{className:"relative",children:[m.jsx("span",{className:"material-symbols-outlined absolute left-2.5 top-1/2 -translate-y-1/2 text-text-muted text-[16px]",children:"search"}),m.jsx("input",{type:"text",placeholder:"Search...",value:f,onChange:C=>h(C.target.value),className:"w-full pl-8 pr-3 py-1.5 bg-surface border border-border rounded text-xs focus:outline-none focus:ring-1 focus:ring-primary/50"})]})}),m.jsxs("div",{className:"max-h-[400px] overflow-y-auto space-y-3",children:[k.length>0&&m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx("span",{className:"material-symbols-outlined text-primary text-[14px]",children:"layers"}),m.jsx("span",{className:"text-xs font-medium text-primary",children:"Combos"}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",k.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:k.map(C=>{const T=i===C.name;return m.jsxs("button",{onClick:()=>I({id:C.name,name:C.name,value:C.name}),className:`
|
|
2
2
|
px-2 py-1 rounded-xl text-xs font-medium transition-all border hover:cursor-pointer flex items-center gap-1
|
|
3
3
|
${T?"bg-primary text-white border-primary":c.includes(C.name)?"bg-primary border-primary text-white hover:bg-primary-hover":"bg-surface border-border text-text-main hover:border-primary/50 hover:bg-primary/5"}
|
|
4
4
|
`,children:[c.includes(C.name)&&m.jsx("span",{className:"material-symbols-outlined leading-none",style:{fontSize:"10px"},children:"check"}),C.name]},C.id)})})]}),Object.entries(P).map(([C,T])=>m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5 sticky top-0 bg-surface py-0.5",children:[m.jsx(YS,{src:C==="codebuddy"||C==="cb"?"/providers/codebuddy.svg":`/providers/${C}.png`,alt:T.name,size:14,fallbackText:(T.name||C).slice(0,2).toUpperCase(),fallbackColor:T.color}),m.jsx("span",{className:"text-xs font-medium text-primary",children:T.name}),m.jsxs("span",{className:"text-[10px] text-text-muted",children:["(",T.models.length,")"]})]}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:T.models.map($=>{const D=i===$.value,L=$.isPlaceholder;return m.jsx("button",{onClick:()=>I($),title:L?"Select to pre-fill, then edit model ID in the input":void 0,className:`
|