@kaitranntt/ccs 7.69.1-dev.2 → 7.69.1-dev.4
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/cliproxy/binary/version-cache.d.ts +10 -0
- package/dist/cliproxy/binary/version-cache.d.ts.map +1 -1
- package/dist/cliproxy/binary/version-cache.js +29 -7
- package/dist/cliproxy/binary/version-cache.js.map +1 -1
- package/dist/cliproxy/binary/version-checker.d.ts +14 -3
- package/dist/cliproxy/binary/version-checker.d.ts.map +1 -1
- package/dist/cliproxy/binary/version-checker.js +65 -36
- package/dist/cliproxy/binary/version-checker.js.map +1 -1
- package/dist/ui/assets/accounts-D7sfwYrK.js +1 -0
- package/dist/ui/assets/{alert-dialog-QyEXocpn.js → alert-dialog-CuN8HTEx.js} +1 -1
- package/dist/ui/assets/api-CI8RoZ-m.js +4 -0
- package/dist/ui/assets/{auth-section-BszF77uT.js → auth-section-C49fRTna.js} +1 -1
- package/dist/ui/assets/{backups-section-D6RgaOx1.js → backups-section-DeJGo6Co.js} +1 -1
- package/dist/ui/assets/channels-CEHW5H6N.js +1 -0
- package/dist/ui/assets/{checkbox-Dzwkj_Pg.js → checkbox-DVHcE1RO.js} +1 -1
- package/dist/ui/assets/claude-extension-CLmICnx_.js +1 -0
- package/dist/ui/assets/cliproxy-BQuYNZ_b.js +3 -0
- package/dist/ui/assets/cliproxy-ai-providers-Bjx7XtY6.js +15 -0
- package/dist/ui/assets/cliproxy-control-panel-DoLho1iE.js +1 -0
- package/dist/ui/assets/codex-BDfvFO8E.js +27 -0
- package/dist/ui/assets/confirm-dialog-D_5v8muu.js +1 -0
- package/dist/ui/assets/copilot-B4waN1q6.js +3 -0
- package/dist/ui/assets/{cursor-BrcDgu6X.js → cursor-DHHZs05u.js} +1 -1
- package/dist/ui/assets/droid-CZePX0Pf.js +2 -0
- package/dist/ui/assets/{globalenv-section-DoX37DqB.js → globalenv-section-nQDFHMda.js} +1 -1
- package/dist/ui/assets/{health-D_gdcxnc.js → health-BfS7V7RZ.js} +1 -1
- package/dist/ui/assets/{index-CTGpqIx6.js → index-B9VMppQ3.js} +1 -1
- package/dist/ui/assets/index-BDfXfBTa.js +72 -0
- package/dist/ui/assets/{index-DoVPk3vW.js → index-C5CFzca_.js} +1 -1
- package/dist/ui/assets/index-CRiWOwLR.js +1 -0
- package/dist/ui/assets/index-EboJtDBz.js +1 -0
- package/dist/ui/assets/index-yt8jgaSK.js +1 -0
- package/dist/ui/assets/logs-GW0Oy6XF.js +1 -0
- package/dist/ui/assets/{masked-input-C2H-Ax0Z.js → masked-input-D1Ilmeh7.js} +1 -1
- package/dist/ui/assets/proxy-status-widget-Bdh67BxQ.js +1 -0
- package/dist/ui/assets/{raw-json-settings-editor-panel-WxTn7-hS.js → raw-json-settings-editor-panel-DwzGE_kH.js} +1 -1
- package/dist/ui/assets/{searchable-select-1zOULoec.js → searchable-select-DbhlbNK0.js} +1 -1
- package/dist/ui/assets/{separator-BCfZ54mZ.js → separator-DziIoy6O.js} +1 -1
- package/dist/ui/assets/{shared-DlTbnc9n.js → shared-XJ2EhJPB.js} +1 -1
- package/dist/ui/assets/{table-Bx2cnkWN.js → table-D5bWyv-8.js} +1 -1
- package/dist/ui/assets/{updates-SiZKOnUD.js → updates-ClhhaqwU.js} +1 -1
- package/dist/ui/index.html +1 -1
- package/dist/web-server/routes/cliproxy-stats-routes.d.ts +37 -0
- package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
- package/dist/web-server/routes/cliproxy-stats-routes.js +56 -10
- package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
- package/package.json +1 -1
- package/dist/ui/assets/accounts-D9eEaNx9.js +0 -1
- package/dist/ui/assets/api-7vQe0xOg.js +0 -4
- package/dist/ui/assets/channels-B1vgnNJX.js +0 -1
- package/dist/ui/assets/claude-extension-CKO4bJ22.js +0 -1
- package/dist/ui/assets/cliproxy-ai-providers-CmbFYVoR.js +0 -15
- package/dist/ui/assets/cliproxy-control-panel-M8ZfUq3C.js +0 -1
- package/dist/ui/assets/cliproxy-kHd-oC5W.js +0 -3
- package/dist/ui/assets/codex-BJ0RdMuh.js +0 -27
- package/dist/ui/assets/confirm-dialog-BlSaX2gK.js +0 -1
- package/dist/ui/assets/copilot-NJKZQXQ_.js +0 -3
- package/dist/ui/assets/droid-B9u9ZB-a.js +0 -2
- package/dist/ui/assets/index-BNU4Hhe_.js +0 -1
- package/dist/ui/assets/index-DFEMq3KP.js +0 -1
- package/dist/ui/assets/index-DOn6k1jF.js +0 -72
- package/dist/ui/assets/index-h08p9xL5.js +0 -1
- package/dist/ui/assets/logs-DtH4YMt4.js +0 -1
- package/dist/ui/assets/proxy-status-widget-BOrsn86w.js +0 -1
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{bb as v,bc as Pe,B as S,d as N,a as ie,V as ne,n as H,L as T,aF as Y,I as ce,r as ke,s as Fe,t as Te,v as Me,w as X,x as he,bd as Le,S as b,be as Re,bf as Ae,bg as Ee,Q as Oe,R as _e,U as Z,bh as qe,c as se}from"./index-DOn6k1jF.js";import{r as w}from"./react-vendor-CNOkPC89.js";import{a as De,u as _,b as M}from"./tanstack-CrmUhA7Z.js";import{C as Ie}from"./confirm-dialog-BlSaX2gK.js";import{R as ge,L as fe,at as Ke,aa as Ue,Z as de,_ as Qe,T as je,aw as $e,b as Je,ad as ze,aE as Be,aO as me,K as Ge,Y as He,aP as Ve,x as we,I as ve}from"./icons-KVCk4_U8.js";import{S as ae}from"./separator-BCfZ54mZ.js";import{S as We}from"./searchable-select-1zOULoec.js";import{t as q}from"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-QyEXocpn.js";async function Ye(){const t=await fetch(v("/copilot/status"));if(!t.ok)throw new Error("Failed to fetch copilot status");return t.json()}async function Xe(){const t=await fetch(v("/copilot/config"));if(!t.ok)throw new Error("Failed to fetch copilot config");return t.json()}async function Ze(){const t=await fetch(v("/copilot/models"));if(!t.ok)throw new Error("Failed to fetch copilot models");return t.json()}async function et(){const t=await fetch(v("/copilot/settings/raw"));if(!t.ok)throw new Error("Failed to fetch copilot raw settings");return t.json()}async function tt(t){const s=await fetch(v("/copilot/config"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!s.ok)throw new Error("Failed to update copilot config");return s.json()}async function st(t){const s=await fetch(v("/copilot/settings/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(s.status===409)throw new Pe("Copilot raw settings changed externally");if(!s.ok)throw new Error("Failed to save copilot raw settings");return s.json()}async function at(){const t=await fetch(v("/copilot/auth/start"),{method:"POST"});if(!t.ok)throw new Error("Failed to start auth");return t.json()}async function it(){const t=await fetch(v("/copilot/daemon/start"),{method:"POST"});if(!t.ok)throw new Error("Failed to start daemon");return t.json()}async function nt(){const t=await fetch(v("/copilot/daemon/stop"),{method:"POST"});if(!t.ok)throw new Error("Failed to stop daemon");return t.json()}async function ot(){const t=await fetch(v("/copilot/info"));if(!t.ok)throw new Error("Failed to fetch copilot info");return t.json()}async function lt(t){const s=await fetch(v("/copilot/install"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t?{version:t}:{})});if(!s.ok)throw new Error("Failed to install copilot-api");return s.json()}function Ne(){const t=De(),s=_({queryKey:["copilot-status"],queryFn:Ye,refetchInterval:5e3}),l=_({queryKey:["copilot-config"],queryFn:Xe}),c=_({queryKey:["copilot-models"],queryFn:Ze}),i=_({queryKey:["copilot-raw-settings"],queryFn:et}),d=_({queryKey:["copilot-info"],queryFn:ot}),r=M({mutationFn:tt,onSuccess:()=>{t.invalidateQueries({queryKey:["copilot-status"]}),t.invalidateQueries({queryKey:["copilot-config"]}),t.invalidateQueries({queryKey:["copilot-raw-settings"]})}}),n=M({mutationFn:st,onSuccess:()=>{t.invalidateQueries({queryKey:["copilot-status"]}),t.invalidateQueries({queryKey:["copilot-config"]}),t.invalidateQueries({queryKey:["copilot-raw-settings"]})}}),x=M({mutationFn:at,onSuccess:()=>{t.invalidateQueries({queryKey:["copilot-status"]})}}),p=M({mutationFn:it,onSuccess:()=>{t.invalidateQueries({queryKey:["copilot-status"]})}}),g=M({mutationFn:nt,onSuccess:()=>{t.invalidateQueries({queryKey:["copilot-status"]})}}),o=M({mutationFn:lt,onSuccess:()=>{t.invalidateQueries({queryKey:["copilot-status"]}),t.invalidateQueries({queryKey:["copilot-info"]})}});return w.useMemo(()=>({status:s.data,statusLoading:s.isLoading,statusError:s.error,refetchStatus:s.refetch,config:l.data,configLoading:l.isLoading,models:c.data?.models??[],currentModel:c.data?.current,modelsLoading:c.isLoading,rawSettings:i.data,rawSettingsLoading:i.isLoading,refetchRawSettings:i.refetch,updateConfig:r.mutate,updateConfigAsync:r.mutateAsync,isUpdating:r.isPending,saveRawSettings:n.mutate,saveRawSettingsAsync:n.mutateAsync,isSavingRawSettings:n.isPending,startAuth:x.mutate,startAuthAsync:x.mutateAsync,isAuthenticating:x.isPending,authResult:x.data,startDaemon:p.mutate,isStartingDaemon:p.isPending,stopDaemon:g.mutate,isStoppingDaemon:g.isPending,info:d.data,infoLoading:d.isLoading,refetchInfo:d.refetch,install:o.mutate,installAsync:o.mutateAsync,isInstalling:o.isPending}),[s.data,s.isLoading,s.error,s.refetch,l.data,l.isLoading,c.data,c.isLoading,i.data,i.isLoading,i.refetch,r.mutate,r.mutateAsync,r.isPending,n.mutate,n.mutateAsync,n.isPending,x.mutate,x.mutateAsync,x.isPending,x.data,p.mutate,p.isPending,g.mutate,g.isPending,d.data,d.isLoading,d.refetch,o.mutate,o.mutateAsync,o.isPending])}function rt({rawSettings:t,rawSettingsLoading:s,isUpdating:l,isSavingRawSettings:c,hasChanges:i,isRawJsonValid:d,onRefresh:r,onSave:n}){return e.jsxs("div",{className:"px-6 py-4 border-b bg-background flex items-center justify-between shrink-0",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Copilot Configuration"}),t&&e.jsx(S,{variant:"outline",className:"text-xs",children:"copilot.settings.json"})]}),t&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified:"," ",t.exists?new Date(t.mtime).toLocaleString():"Never saved"]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(N,{variant:"ghost",size:"sm",onClick:r,disabled:s,children:e.jsx(ge,{className:`w-4 h-4 ${s?"animate-spin":""}`})}),e.jsx(N,{size:"sm",onClick:n,disabled:l||c||!i||!d,children:l||c?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]})}const ct=[{name:"GPT-4.1 (Free)",description:"Free tier - no premium usage",default:"gpt-4.1",opus:"gpt-4.1",sonnet:"gpt-4.1",haiku:"gpt-4.1"},{name:"GPT-5 Mini (Free)",description:"Free tier - lightweight model",default:"gpt-5-mini",opus:"gpt-5-mini",sonnet:"gpt-5-mini",haiku:"gpt-5-mini"}],dt=[{name:"Claude Opus 4.5",description:"Pro+ (3x) - Most capable reasoning",default:"claude-opus-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"},{name:"Claude Sonnet 4.5",description:"Pro+ (1x) - Balanced performance",default:"claude-sonnet-4.5",opus:"claude-opus-4.5",sonnet:"claude-sonnet-4.5",haiku:"claude-haiku-4.5"},{name:"GPT-5.2",description:"Pro+ (1x) - Latest OpenAI (Preview)",default:"gpt-5.2",opus:"gpt-5.2",sonnet:"gpt-5.1",haiku:"gpt-5-mini"},{name:"GPT-5.1 Codex Max",description:"Pro+ (1x) - Best for coding",default:"gpt-5.1-codex-max",opus:"gpt-5.1-codex-max",sonnet:"gpt-5.1-codex",haiku:"gpt-5.1-codex-mini"},{name:"Gemini 2.5 Pro",description:"Pro+ (1x) - Google latest",default:"gemini-2.5-pro",opus:"gemini-2.5-pro",sonnet:"gemini-2.5-pro",haiku:"gemini-3-flash"}];function ue(t){switch(t){case"free":return"bg-green-100 text-green-700 border-green-200";case"pro":return"bg-blue-100 text-blue-700 border-blue-200";case"pro+":return"bg-purple-100 text-purple-700 border-purple-200";case"business":return"bg-orange-100 text-orange-700 border-orange-200";case"enterprise":return"bg-red-100 text-red-700 border-red-200";default:return"bg-muted text-muted-foreground"}}function mt(t){return t==null?null:t===0?"Free":t<1?`${t}x`:t===1?"1x":`${t}x`}function z({label:t,description:s,value:l,onChange:c,models:i,disabled:d}){const{t:r}=ie();return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium",children:t}),s&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:s})]}),e.jsx(We,{value:l||void 0,onChange:c,disabled:d,placeholder:r("componentModelSelector.selectModel"),searchPlaceholder:r("searchableSelect.searchModels"),emptyText:r("searchableSelect.noResults"),triggerClassName:"h-9",groups:[{key:"models",label:r("componentModelSelector.availableModelsCount",{count:i.length})}],options:i.map(n=>({value:n.id,groupKey:"models",searchText:`${n.name||n.id} ${n.id}`,keywords:[n.minPlan??"",n.preview?"preview":""],triggerContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:n.id}),n.minPlan&&e.jsx(S,{variant:"outline",className:`text-[9px] px-1 py-0 h-4 ${ue(n.minPlan)}`,children:n.minPlan})]}),itemContent:e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:n.name||n.id}),n.minPlan&&e.jsx(S,{variant:"outline",className:`text-[9px] px-1 py-0 h-4 ${ue(n.minPlan)}`,children:n.minPlan}),n.multiplier!==void 0&&e.jsx("span",{className:"text-[9px] text-muted-foreground",children:mt(n.multiplier)}),n.preview&&e.jsx(S,{variant:"secondary",className:"text-[9px] px-1 py-0 h-4",children:r("componentModelSelector.preview")})]})}))})]})}function ee(t){if(t>=1e6){const s=t/1e6;return s%1===0?`${s}M`:`${s.toFixed(1)}M`}if(t>=1e3){const s=t/1e3;return s%1===0?`${s}K`:`${s.toFixed(1)}K`}return`${t}`}function ut(t){if(!t?.limits)return null;const s=[];return t.limits.maxPromptTokens&&s.push(`prompt ${ee(t.limits.maxPromptTokens)}`),t.limits.maxContextWindowTokens&&s.push(`context ${ee(t.limits.maxContextWindowTokens)}`),t.limits.maxOutputTokens&&s.push(`output ${ee(t.limits.maxOutputTokens)}`),s.length>0?s.join(" | "):null}function xt({currentModel:t,opusModel:s,sonnetModel:l,haikuModel:c,models:i,modelsLoading:d,onApplyPreset:r,onUpdateModel:n,onUpdateOpusModel:x,onUpdateSonnetModel:p,onUpdateHaikuModel:g}){const o=[{label:"Default",id:t},{label:"Opus",id:s||t},{label:"Sonnet",id:l||t},{label:"Haiku",id:c||t}].map(({label:a,id:u})=>{const y=i.find(P=>P.id===u),C=ut(y);return C?{label:a,id:u,limits:C}:null}).filter(a=>a!==null);return e.jsx(ne,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(H,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium mb-2 flex items-center gap-2",children:[e.jsx(Ue,{className:"w-4 h-4"}),"Presets"]}),e.jsx("p",{className:"text-xs text-muted-foreground mb-3",children:"Apply pre-configured model mappings"}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(S,{variant:"outline",className:"text-[10px] bg-green-100 text-green-700 border-green-200",children:"Free Tier"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"No premium usage count"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ct.map(a=>e.jsxs(N,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>r(a),title:a.description,children:[e.jsx(de,{className:"w-3 h-3 text-green-600"}),a.name]},a.name))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(S,{variant:"outline",className:"text-[10px] bg-blue-100 text-blue-700 border-blue-200",children:"Pro+ Required"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Uses premium request quota"})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:dt.map(a=>e.jsxs(N,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>r(a),title:a.description,children:[e.jsx(de,{className:"w-3 h-3"}),a.name]},a.name))})]})]}),e.jsx(ae,{}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-2",children:"Model Mapping"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Configure which models to use for each tier"}),e.jsxs("div",{className:"mb-4 rounded-lg border border-amber-500/30 bg-amber-500/10 p-3 text-xs text-amber-900 dark:text-amber-200",children:[e.jsx("p",{className:"font-medium",children:"GitHub Copilot controls prompt/context limits upstream."}),e.jsx("p",{className:"mt-1",children:"CCS can switch Copilot models, but it cannot increase the provider's max prompt or context window."}),o.length>0?e.jsx("div",{className:"mt-2 space-y-1 text-[11px] font-mono",children:o.map(a=>e.jsxs("p",{children:[a.label,": ",a.id," (",a.limits,")"]},`${a.label}-${a.id}`))}):e.jsx("p",{className:"mt-2 text-[11px] font-mono",children:"Start the daemon to inspect live model limits from GitHub Copilot metadata."})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(z,{label:"Default Model",description:"Used when no specific tier is requested",value:t,onChange:n,models:i,disabled:d}),e.jsx(z,{label:"Opus (Most capable)",description:"For complex reasoning tasks",value:s||t,onChange:x,models:i,disabled:d}),e.jsx(z,{label:"Sonnet (Balanced)",description:"Balance of speed and capability",value:l||t,onChange:p,models:i,disabled:d}),e.jsx(z,{label:"Haiku (Fast)",description:"Quick responses for simple tasks",value:c||t,onChange:g,models:i,disabled:d})]})]})]})})})}function pt({enabled:t,autoStart:s,port:l,accountType:c,rateLimit:i,waitOnLimit:d,onUpdateEnabled:r,onUpdateAutoStart:n,onUpdatePort:x,onUpdateAccountType:p,onUpdateRateLimit:g,onUpdateWaitOnLimit:o}){const{t:a}=ie();return e.jsx(ne,{value:"settings",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(H,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{htmlFor:"enabled",className:"text-sm font-medium",children:a("copilotSettings.enableCopilot")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a("copilotSettings.enableCopilotDesc")})]}),e.jsx(Y,{id:"enabled",checked:t,onCheckedChange:r})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:a("copilotSettings.basicSettings")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"port",className:"text-xs",children:a("copilotPage.port")}),e.jsx(ce,{id:"port",type:"number",value:l,onChange:u=>x(parseInt(u.target.value,10)),min:1024,max:65535,className:"max-w-[150px] h-8"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"account-type",className:"text-xs",children:a("copilotSettings.accountType")}),e.jsxs(ke,{value:c,onValueChange:p,children:[e.jsx(Fe,{id:"account-type",className:"max-w-[150px] h-8",children:e.jsx(Te,{})}),e.jsxs(Me,{children:[e.jsx(X,{value:"individual",children:a("copilotSettings.accountTypeIndividual")}),e.jsx(X,{value:"business",children:a("copilotSettings.accountTypeBusiness")}),e.jsx(X,{value:"enterprise",children:a("copilotSettings.accountTypeEnterprise")})]})]})]})]}),e.jsx(ae,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:a("copilotSettings.rateLimiting")}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(T,{htmlFor:"rate-limit",className:"text-xs",children:a("copilotSettings.rateLimitSeconds")}),e.jsx(ce,{id:"rate-limit",type:"number",value:i,onChange:u=>g(u.target.value),placeholder:a("copilotSettings.noLimit"),min:0,className:"max-w-[150px] h-8"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{htmlFor:"wait-on-limit",className:"text-xs",children:a("copilotSettings.waitOnRateLimit")}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a("copilotSettings.waitOnRateLimitDesc")})]}),e.jsx(Y,{id:"wait-on-limit",checked:d,onCheckedChange:o})]})]}),e.jsx(ae,{}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:a("copilotSettings.daemonSettings")}),e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(T,{htmlFor:"auto-start",className:"text-xs",children:a("copilotSettings.autoStartDaemon")}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a("copilotSettings.autoStartDaemonDesc")})]}),e.jsx(Y,{id:"auto-start",checked:s,onCheckedChange:n})]})]})]})})})}function B({label:t,command:s}){return e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:t}),e.jsxs("div",{className:"mt-1 flex gap-2",children:[e.jsx("code",{className:"flex-1 px-2 py-1.5 bg-muted rounded text-xs font-mono truncate",children:s}),e.jsx(he,{value:s,size:"icon",className:"h-6 w-6"})]})]})}function ht({rawSettings:t}){return e.jsx(ne,{value:"info",className:"h-full mt-0 border-0 p-0 data-[state=inactive]:hidden",children:e.jsx(H,{className:"h-full",children:e.jsxs("div",{className:"p-4 space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h3",{className:"text-sm font-medium flex items-center gap-2 mb-3",children:[e.jsx(Qe,{className:"w-4 h-4"}),"Configuration Info"]}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Provider"}),e.jsx("span",{className:"font-mono",children:"GitHub Copilot"})]}),t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"File Path"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:t.path}),e.jsx(he,{value:t.path,size:"icon",className:"h-5 w-5"})]})]}),e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-2 text-sm items-center",children:[e.jsx("span",{className:"font-medium text-muted-foreground",children:"Status"}),e.jsx(S,{variant:"outline",className:t.exists?"w-fit text-green-600 border-green-200 bg-green-50":"w-fit text-muted-foreground",children:t.exists?"File exists":"Using defaults"})]})]})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Quick Usage"}),e.jsxs("div",{className:"space-y-3 bg-card rounded-lg border p-4 shadow-sm",children:[e.jsx(B,{label:"Run with Copilot",command:"ccs copilot"}),e.jsx(B,{label:"Authenticate",command:"ccs copilot auth"}),e.jsx(B,{label:"Start daemon",command:"ccs copilot --start"}),e.jsx(B,{label:"Stop daemon",command:"ccs copilot --stop"})]})]})]})})})}const gt=["ANTHROPIC_BASE_URL","ANTHROPIC_AUTH_TOKEN"];function xe(t){const s=t?.env||{};return gt.filter(l=>!s[l]?.trim())}function pe(t){if(!t||t.length===0)return[];const s=new Map;return t.forEach(l=>{s.set(l.message,l)}),[...s.values()]}function ft(){const{config:t,configLoading:s,models:l,modelsLoading:c,rawSettings:i,rawSettingsLoading:d,updateConfigAsync:r,isUpdating:n,saveRawSettingsAsync:x,isSavingRawSettings:p,refetchRawSettings:g}=Ne(),[o,a]=w.useState({}),[u,y]=w.useState(null),[C,P]=w.useState(!1),D=o.enabled??t?.enabled??!1,I=o.autoStart??t?.auto_start??!1,L=o.port??t?.port??4141,K=o.accountType??t?.account_type??"individual",R=o.model??t?.model??"claude-sonnet-4-6",A=o.rateLimit??t?.rate_limit?.toString()??"",f=o.waitOnLimit??t?.wait_on_limit??!0,U=o.opusModel??t?.opus_model??"",Q=o.sonnetModel??t?.sonnet_model??"",$=o.haikuModel??t?.haiku_model??"",J=(h,j)=>{a(E=>({...E,[h]:j}))},V=h=>{a(j=>({...j,model:h.default,opusModel:h.opus,sonnetModel:h.sonnet,haikuModel:h.haiku})),q.success(`Applied "${h.name}" preset`)},k=w.useMemo(()=>u!==null?u:i?.settings?JSON.stringify(i.settings,null,2):`{
|
|
2
|
-
"env": {}
|
|
3
|
-
}`,[u,i]),m=w.useCallback(h=>{y(h)},[]),oe=w.useMemo(()=>{try{return JSON.parse(k),!0}catch{return!1}},[k]),be=w.useMemo(()=>{const h=Object.keys(o).length>0,j=u!==null&&u!==JSON.stringify(i?.settings,null,2);return h||j},[o,u,i]),le=w.useMemo(()=>{if(u!==null)try{return JSON.parse(u)}catch{return i?.settings}return i?.settings},[u,i?.settings]),ye=w.useMemo(()=>xe(le),[le]),Se=w.useMemo(()=>pe([...t?.warnings??[],...i?.warnings??[]]),[t?.warnings,i?.warnings]),re=async({overwriteRawSettings:h=!1}={})=>{try{const j=[];if(Object.keys(o).length>0){const F=await r({enabled:D,auto_start:I,port:L,account_type:K,model:R,rate_limit:A?parseInt(A,10):null,wait_on_limit:f,opus_model:U||void 0,sonnet_model:Q||void 0,haiku_model:$||void 0});j.push(...F.warnings??[])}let E=[];if(u!==null&&oe){const F=JSON.parse(k);E=xe(F);const Ce=await x({settings:F,expectedMtime:h?void 0:i?.mtime});j.push(...Ce.warnings??[])}const W=pe(j),O=[];W.length>0&&O.push(W.map(F=>F.message).join(" ")),E.length>0&&O.push(`Missing fields will use defaults: ${E.join(", ")}`),W.length>0?q.warning("Copilot configuration saved with model adjustments",{description:O.join(" ")}):O.length>0?q.success("Copilot configuration saved",{description:O.join(" ")}):q.success("Copilot configuration saved"),a({}),y(null)}catch(j){Le(j)?P(!0):q.error("Failed to save settings")}};return{configLoading:s,rawSettingsLoading:d,modelsLoading:c,isUpdating:n,isSavingRawSettings:p,models:l,rawSettings:i,rawJsonContent:k,rawJsonEdits:u,enabled:D,autoStart:I,port:L,accountType:K,currentModel:R,rateLimit:A,waitOnLimit:f,opusModel:U,sonnetModel:Q,haikuModel:$,isRawJsonValid:oe,hasChanges:be,normalizationWarnings:Se,conflictDialog:C,updateField:J,applyPreset:V,handleRawJsonChange:m,handleSave:re,handleConflictResolve:async h=>{P(!1),h?await re({overwriteRawSettings:!0}):y(null)},refetchRawSettings:g,missingRequiredFields:ye}}function jt(){const{configLoading:t,rawSettingsLoading:s,modelsLoading:l,isUpdating:c,isSavingRawSettings:i,models:d,rawSettings:r,rawJsonContent:n,rawJsonEdits:x,enabled:p,autoStart:g,port:o,accountType:a,currentModel:u,rateLimit:y,waitOnLimit:C,opusModel:P,sonnetModel:D,haikuModel:I,isRawJsonValid:L,hasChanges:K,normalizationWarnings:R,conflictDialog:A,updateField:f,applyPreset:U,handleRawJsonChange:Q,handleSave:$,handleConflictResolve:J,refetchRawSettings:V,missingRequiredFields:k}=ft();return t||s?e.jsxs("div",{className:"space-y-6",children:[e.jsx(b,{className:"h-10 w-full"}),e.jsx(b,{className:"h-10 w-full"}),e.jsx(b,{className:"h-10 w-full"}),e.jsx(b,{className:"h-10 w-full"})]}):e.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden",children:[e.jsx(rt,{rawSettings:r,rawSettingsLoading:s,isUpdating:c,isSavingRawSettings:i,hasChanges:K,isRawJsonValid:L,onRefresh:()=>V(),onSave:$}),R.length>0&&e.jsx("div",{className:"px-6 pt-4 shrink-0",children:e.jsxs(Re,{variant:"warning",children:[e.jsx(je,{className:"h-4 w-4"}),e.jsx(Ae,{children:"Deprecated Copilot models detected"}),e.jsxs(Ee,{className:"space-y-2",children:[e.jsx("p",{children:"Loading this page did not rewrite your files. Save the Copilot configuration to persist these replacements."}),e.jsx("div",{className:"space-y-1",children:R.map(m=>e.jsx("p",{children:m.message},m.message))})]})]})}),e.jsxs("div",{className:"flex-1 flex divide-x overflow-hidden",children:[e.jsx("div",{className:"w-[540px] shrink-0 flex flex-col overflow-hidden bg-muted/5",children:e.jsx("div",{className:"h-full flex flex-col",children:e.jsxs(Oe,{defaultValue:"config",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(_e,{className:"w-full",children:[e.jsx(Z,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(Z,{value:"settings",className:"flex-1",children:"Settings"}),e.jsx(Z,{value:"info",className:"flex-1",children:"Info"})]})}),e.jsxs("div",{className:"flex-1 overflow-hidden flex flex-col",children:[e.jsx(xt,{currentModel:u,opusModel:P,sonnetModel:D,haikuModel:I,models:d,modelsLoading:l,onApplyPreset:U,onUpdateModel:m=>f("model",m),onUpdateOpusModel:m=>f("opusModel",m),onUpdateSonnetModel:m=>f("sonnetModel",m),onUpdateHaikuModel:m=>f("haikuModel",m)}),e.jsx(pt,{enabled:p,autoStart:g,port:o,accountType:a,rateLimit:y,waitOnLimit:C,onUpdateEnabled:m=>f("enabled",m),onUpdateAutoStart:m=>f("autoStart",m),onUpdatePort:m=>f("port",m),onUpdateAccountType:m=>f("accountType",m),onUpdateRateLimit:m=>f("rateLimit",m),onUpdateWaitOnLimit:m=>f("waitOnLimit",m)}),e.jsx(ht,{rawSettings:r})]})]})})}),e.jsxs("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-2 bg-muted/30 border-b flex items-center gap-2 shrink-0 h-[45px]",children:[e.jsx($e,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Raw Configuration (JSON)"})]}),e.jsx(qe,{rawJsonContent:n,isRawJsonValid:L,rawJsonEdits:x,rawSettingsEnv:r?.settings?.env,onChange:Q,missingRequiredFields:k})]})]}),e.jsx(Ie,{open:A,title:"File Modified Externally",description:"This settings file was modified by another process. Overwrite with your changes or discard?",confirmText:"Overwrite",variant:"destructive",onConfirm:()=>J(!0),onCancel:()=>J(!1)})]})}function te({title:t,children:s}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide px-3",children:t}),e.jsx("div",{className:"space-y-1",children:s})]})}function G({icon:t,label:s,status:l,statusText:c,variant:i="default"}){return e.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/50",children:[e.jsx(t,{className:"w-4 h-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("span",{className:"text-sm",children:s})}),e.jsx("div",{className:"flex items-center gap-1.5",children:l?e.jsxs(e.Fragment,{children:[e.jsx(we,{className:se("w-4 h-4",i==="warning"?"text-yellow-500":"text-green-500")}),e.jsx("span",{className:se("text-xs",i==="warning"?"text-yellow-500":"text-green-500"),children:c||"Yes"})]}):e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:c||"No"})]})})]})}function wt(){return e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsx(b,{className:"h-8 w-full"}),e.jsx(b,{className:"h-12 w-full"}),e.jsx(b,{className:"h-12 w-full"}),e.jsx(b,{className:"h-12 w-full"})]})}function Et(){const{t}=ie(),{status:s,statusLoading:l,refetchStatus:c,startAuth:i,isAuthenticating:d,startDaemon:r,isStartingDaemon:n,stopDaemon:x,isStoppingDaemon:p,install:g,isInstalling:o}=Ne();return e.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"w-80 border-r flex flex-col bg-muted/30 shrink-0",children:[e.jsxs("div",{className:"p-4 border-b bg-background",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Je,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"font-semibold",children:t("copilotPage.title")})]}),e.jsx(N,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>c(),disabled:l,children:e.jsx(ge,{className:se("w-4 h-4",l&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t("copilotPage.subtitle")})]}),e.jsx(H,{className:"flex-1",children:l?e.jsx(wt,{}):e.jsxs("div",{className:"p-3 space-y-4",children:[e.jsxs("div",{className:"rounded-md border border-yellow-500/50 bg-yellow-500/15 p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(je,{className:"h-4 w-4 text-yellow-600 dark:text-yellow-400 shrink-0"}),e.jsx("span",{className:"text-xs font-semibold text-yellow-800 dark:text-yellow-200",children:t("copilotPage.unofficialTitle")})]}),e.jsxs("ul",{className:"text-[11px] text-yellow-700 dark:text-yellow-300 space-y-0.5 pl-6 list-disc",children:[e.jsx("li",{children:t("copilotPage.unofficialItem1")}),e.jsx("li",{children:t("copilotPage.unofficialItem2")}),e.jsx("li",{children:t("copilotPage.unofficialItem3")})]})]}),e.jsxs(te,{title:t("copilotPage.setup"),children:[e.jsx(G,{icon:ze,label:"copilot-api",status:s?.installed??!1,statusText:s?.installed?s.version?`v${s.version}`:t("copilotPage.installed"):t("copilotPage.missing")}),!s?.installed&&e.jsx(N,{size:"sm",className:"w-full mt-2",onClick:()=>g(void 0),disabled:o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),t("copilotPage.installing")]}):e.jsxs(e.Fragment,{children:[e.jsx(Be,{className:"w-3.5 h-3.5 mr-1.5"}),t("copilotPage.installCopilotApi")]})}),s?.installed&&e.jsx(G,{icon:me,label:t("copilotPage.integration"),status:s?.enabled??!1,statusText:s?.enabled?t("copilotPage.enabled"):t("copilotPage.disabled")})]}),s?.installed&&e.jsxs(te,{title:t("copilotPage.auth"),children:[e.jsx(G,{icon:Ge,label:t("copilotPage.github"),status:s?.authenticated??!1,statusText:s?.authenticated?t("copilotPage.connected"):t("copilotPage.notConnected")}),!s?.authenticated&&e.jsx(N,{size:"sm",className:"w-full mt-2",onClick:()=>i(),disabled:d,children:t(d?"copilotPage.authenticating":"copilotPage.authenticate")})]}),s?.authenticated&&e.jsxs(te,{title:t("copilotPage.daemon"),children:[e.jsx(G,{icon:He,label:t("copilotPage.status"),status:s?.daemon_running??!1,statusText:s?.daemon_running?t("copilotPage.running"):t("copilotPage.stopped")}),e.jsxs("div",{className:"px-3 py-1 text-xs text-muted-foreground",children:[t("copilotPage.port"),": ",s?.port??4141]}),e.jsx("div",{className:"px-1",children:s?.daemon_running?e.jsxs(N,{size:"sm",variant:"outline",className:"w-full",onClick:()=>x(),disabled:p,children:[e.jsx(Ve,{className:"w-3.5 h-3.5 mr-1.5"}),t(p?"copilotPage.stopping":"copilotPage.stop")]}):e.jsxs(N,{size:"sm",variant:"outline",className:"w-full",onClick:()=>r(),disabled:n,children:[e.jsx(me,{className:"w-3.5 h-3.5 mr-1.5"}),t(n?"copilotPage.starting":"copilotPage.start")]})})]})]})}),e.jsx("div",{className:"p-3 border-t bg-background text-xs text-muted-foreground",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{children:t("copilotPage.proxy")}),s?.daemon_running?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(we,{className:"w-3 h-3 text-green-500"}),t("copilotPage.active")]}):e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ve,{className:"w-3 h-3 text-muted-foreground"}),t("copilotPage.inactive")]})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-background overflow-hidden",children:e.jsx(jt,{})})]})}export{Et as CopilotPage};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as Q}from"./react-vendor-CNOkPC89.js";import{t as j}from"./notifications-B2HqRBj7.js";import{bb as X,bc as ye,C as b,j as v,k as y,B as P,b as N,r as H,s as q,t as W,v as Y,w as k,I as oe,a as Ne,bi as we,bj as ne,bk as ke,Q as Se,R as Pe,U,V,n as T,bd as Ee,c as Ce}from"./index-DOn6k1jF.js";import{a as Te,u as ae,b as Ae}from"./tanstack-CrmUhA7Z.js";import{a as Re}from"./raw-json-settings-editor-panel-WxTn7-hS.js";import{ax as _e,aB as De,N as Oe,L as Be,S as Me,aX as Fe,x as Le,I as Ie,T as Ke,ad as Ue,ah as Ve,p as ie}from"./icons-KVCk4_U8.js";import{S as A}from"./separator-BCfZ54mZ.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function $e(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{settings:null,parseError:"JSON root must be an object."}:{settings:r,parseError:null}}catch(r){return{settings:null,parseError:r.message}}}async function ze(){const s=await fetch(X("/droid/diagnostics"));if(!s.ok)throw new Error("Failed to fetch Droid diagnostics");return s.json()}async function Je(){const s=await fetch(X("/droid/settings/raw"));if(!s.ok)throw new Error("Failed to fetch Droid raw settings");return s.json()}async function Qe(s){const r=await fetch(X("/droid/settings/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(r.status===409)throw new ye("Droid raw settings changed externally");if(!r.ok){const n=await r.json().catch(()=>null);throw new Error(n?.error||"Failed to save Droid raw settings")}return r.json()}function He(){const s=Te(),r=ae({queryKey:["droid-diagnostics"],queryFn:ze,refetchInterval:1e4}),n=ae({queryKey:["droid-raw-settings"],queryFn:Je}),o=Ae({mutationFn:Qe,onSuccess:(d,l)=>{s.setQueryData(["droid-raw-settings"],t=>{const a=t?.path??"~/.factory/settings.json",u=t?.resolvedPath??a,x=$e(l.rawText);return{path:a,resolvedPath:u,exists:!0,mtime:d.mtime,rawText:l.rawText,settings:x.settings,parseError:x.parseError}}),s.invalidateQueries({queryKey:["droid-diagnostics"]})}});return Q.useMemo(()=>({diagnostics:r.data,diagnosticsLoading:r.isLoading,diagnosticsError:r.error,refetchDiagnostics:r.refetch,rawSettings:n.data,rawSettingsLoading:n.isLoading,rawSettingsError:n.error,refetchRawSettings:n.refetch,saveRawSettings:o.mutate,saveRawSettingsAsync:o.mutateAsync,isSavingRawSettings:o.isPending}),[r.data,r.isLoading,r.error,r.refetch,n.data,n.isLoading,n.error,n.refetch,o.mutate,o.mutateAsync,o.isPending])}const qe=["customModels","custom_models"],We={low:4e3,medium:12e3,high:3e4,max:5e4,xhigh:64e3},Ye=["low","medium","high","max","xhigh"];function h(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function p(s){return typeof s=="string"&&s.trim()?s.trim():null}function _(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function G(s){if(!s)return"unknown";const r=s.toLowerCase();return r==="anthropic"?"anthropic":r==="openai"?"openai":r==="generic-chat-completion-api"?"generic-chat-completion-api":"unknown"}function Ge(s,r,n){return`${s}:${r}:${encodeURIComponent(String(n))}`}function Xe(s){const r=s.indexOf(":"),n=s.indexOf(":",r+1);if(r<=0||n<=r+1)return null;const o=s.slice(0,r),d=s.slice(r+1,n),l=s.slice(n+1);if(o!=="customModels"&&o!=="custom_models"||d!=="array"&&d!=="object")return null;const t=decodeURIComponent(l);if(d==="array"){const a=Number.parseInt(t,10);return!Number.isInteger(a)||a<0?null:{rootKey:o,locationType:d,locationKey:a}}return{rootKey:o,locationType:d,locationKey:t}}function Ze(s){return!s||s<=0?null:s<=4e3?"low":s<=12e3?"medium":s<=3e4?"high":s<=5e4?"max":"xhigh"}function es(s){return Object.prototype.hasOwnProperty.call(s,"extraArgs")?"extraArgs":Object.prototype.hasOwnProperty.call(s,"extra_args")?"extra_args":"extraArgs"}function le(s){return JSON.parse(JSON.stringify(s))}function ss(s){const r=[];for(const n of qe){const o=s[n];if(Array.isArray(o)){o.forEach((d,l)=>{h(d)&&r.push({rootKey:n,locationType:"array",locationKey:l,entry:d})});continue}if(h(o))for(const[d,l]of Object.entries(o))h(l)&&r.push({rootKey:n,locationType:"object",locationKey:d,entry:l})}return r}function de(s,r){const n=Xe(r);if(!n)return null;const o=s[n.rootKey];if(n.locationType==="array"){if(!Array.isArray(o))return null;const t=o[n.locationKey];if(!h(t))return null;const a=p(t.provider);return{entry:t,providerKind:G(a)}}if(!h(o))return null;const d=o[n.locationKey];if(!h(d))return null;const l=p(d.provider);return{entry:d,providerKind:G(l)}}function rs(s,r){const n=r.extraArgs??r.extra_args,o=h(n)?n:null;if(!o)return{effort:null,anthropicBudgetTokens:null};const d=p(o.reasoning_effort)??p(o.reasoningEffort),l=h(o.reasoning)?o.reasoning:null,t=l?p(l.effort):null,a=h(o.thinking)?o.thinking:null,u=a?p(a.type):null,x=a?_(a.budget_tokens)??_(a.budgetTokens):null;return s==="openai"?{effort:t??d,anthropicBudgetTokens:null}:s==="anthropic"?u==="enabled"?{effort:Ze(x)??"high",anthropicBudgetTokens:x}:{effort:t??d,anthropicBudgetTokens:x}:{effort:d??t,anthropicBudgetTokens:null}}function ts(s){if(!s)return null;const r=s.trim().toLowerCase();return!r||r==="default"||r==="unset"||r==="off"||r==="none"||r==="disabled"?null:r}function ce(s){const r=es(s),n=s[r],o=h(n)?{...n}:{};return{extraArgsKey:r,extraArgs:o}}function ue(s,r,n){if(Object.keys(n).length===0){delete s[r];return}s[r]=n}function ns(s){return ss(s).map(({rootKey:r,locationType:n,locationKey:o,entry:d})=>{const l=p(d.displayName)??p(d.model_display_name)??"Unnamed model",t=p(d.model)??"",a=p(d.provider)??"unknown",u=G(a),x=rs(u,d);return{id:Ge(r,n,o),rootKey:r,locationType:n,locationKey:o,displayName:l,model:t,provider:a,providerKind:u,effort:x.effort,anthropicBudgetTokens:x.anthropicBudgetTokens}})}function as(s,r,n){const o=le(s),d=de(o,r);if(!d)return null;const l=ts(n),{extraArgsKey:t,extraArgs:a}=ce(d.entry);if(d.providerKind==="openai")if(delete a.reasoning_effort,delete a.reasoningEffort,!l)delete a.reasoning;else{const u=h(a.reasoning)?a.reasoning:{};a.reasoning={...u,effort:l}}else if(d.providerKind==="anthropic")if(delete a.reasoning_effort,delete a.reasoningEffort,delete a.reasoning,!l)delete a.thinking;else{const u=h(a.thinking)?{...a.thinking}:{},x=_(u.budget_tokens)??_(u.budgetTokens);delete u.budgetTokens,a.thinking={...u,type:"enabled",budget_tokens:x??We[l]??3e4}}else delete a.reasoning,delete a.reasoningEffort,l?a.reasoning_effort=l:delete a.reasoning_effort;return ue(d.entry,t,a),o}function is(s,r,n){const o=le(s),d=de(o,r);if(!d||d.providerKind!=="anthropic")return null;const{extraArgsKey:l,extraArgs:t}=ce(d.entry),a=h(t.thinking)?{...t.thinking}:{};if(a.type="enabled",n===null)delete a.budget_tokens,delete a.budgetTokens;else{const u=Math.max(1024,Math.floor(n));a.budget_tokens=u,delete a.budgetTokens}return t.thinking=a,ue(d.entry,l,t),o}const $="__unset__";function os(s){return s.providerKind==="openai"?"Writes: extraArgs.reasoning.effort":s.providerKind==="anthropic"?"Writes: extraArgs.thinking.{type,budget_tokens}":"Writes: extraArgs.reasoning_effort"}function ls({models:s,disabled:r,disabledReason:n,onEffortChange:o,onAnthropicBudgetChange:d}){return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(_e,{className:"h-4 w-4"}),"BYOK Reasoning / Thinking",e.jsx(P,{variant:"outline",className:"text-[10px] font-normal",children:"customModels"})]})}),e.jsxs(N,{className:"space-y-3",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),s.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No BYOK custom models found in settings.json (`customModels` or `custom_models`)."}):e.jsx("div",{className:"space-y-2",children:s.map(l=>e.jsxs("div",{className:"rounded-md border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-medium truncate",children:l.displayName}),e.jsx("p",{className:"text-[11px] font-mono text-muted-foreground truncate",children:l.model||"(missing model id)"})]}),e.jsx(P,{variant:"outline",className:"font-mono text-[10px] shrink-0",children:l.provider})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:"Reasoning Effort"}),e.jsxs(H,{value:l.effort??$,onValueChange:t=>o(l.id,t===$?null:t),disabled:r,children:[e.jsx(q,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:"Use provider default"})}),e.jsxs(Y,{children:[e.jsx(k,{value:$,children:"Use provider default"}),Ye.map(t=>e.jsx(k,{value:t,children:t},t))]})]})]}),l.providerKind==="anthropic"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:"Thinking Budget Tokens"}),e.jsx(oe,{type:"number",min:1024,step:1024,value:l.anthropicBudgetTokens??"",placeholder:"auto",className:"h-8 text-xs",disabled:r,onChange:t=>{const a=t.target.value.trim();if(!a){d(l.id,null);return}const u=Number.parseInt(a,10);Number.isFinite(u)&&d(l.id,Math.max(1024,u))}})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:os(l)})]},l.id))})]})]})}const C="__unset__",ds=[{key:"reasoningEffort",label:"Reasoning Effort",description:"none | medium | high | max",options:[{value:"none",label:"none"},{value:"medium",label:"medium"},{value:"high",label:"high"},{value:"max",label:"max"}]},{key:"autonomyLevel",label:"Autonomy Level",description:"suggest | aggressive | full",options:[{value:"suggest",label:"suggest"},{value:"aggressive",label:"aggressive"},{value:"full",label:"full"}]},{key:"diffMode",label:"Diff Mode",description:"auto | none | inline | split",options:[{value:"auto",label:"auto"},{value:"none",label:"none"},{value:"inline",label:"inline"},{value:"split",label:"split"}]}],cs=[{key:"todoEnabled",label:"Todo Enabled"},{key:"todoAutoRefresh",label:"Todo Auto Refresh"},{key:"autoCompactEnabled",label:"Auto Compact Enabled"},{key:"soundEnabled",label:"Sound Enabled"}],us=[{key:"maxTurns",label:"Max Turns",min:1,step:1},{key:"maxToolCalls",label:"Max Tool Calls",min:1,step:1},{key:"autoCompactThreshold",label:"Auto Compact Threshold",min:1e3,step:1e3}];function ms(s){return s===!0?"true":s===!1?"false":C}function xs(s){return s==="true"?!0:s==="false"?!1:null}function gs({values:s,disabled:r,disabledReason:n,onEnumSettingChange:o,onBooleanSettingChange:d,onNumberSettingChange:l}){return e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4"}),"Quick Settings",e.jsx(P,{variant:"outline",className:"text-[10px] font-normal",children:"settings.json"})]})}),e.jsxs(N,{className:"space-y-4",children:[n&&e.jsx("p",{className:"text-xs text-amber-600",children:n}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[ds.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(H,{value:s[t.key]??C,onValueChange:a=>o(t.key,a===C?null:a),disabled:r,children:[e.jsx(q,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:"Use default"})}),e.jsxs(Y,{children:[e.jsx(k,{value:C,children:"Use default"}),t.options.map(a=>e.jsx(k,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t.description})]},t.key)),us.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsx(oe,{type:"number",min:t.min,step:t.step,value:s[t.key]??"",onChange:a=>{const u=a.target.value.trim();if(!u){l(t.key,null);return}const x=Number.parseInt(u,10);Number.isFinite(x)&&l(t.key,Math.max(t.min,x))},className:"h-8 text-xs",disabled:r})]},t.key)),cs.map(t=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:t.label}),e.jsxs(H,{value:ms(s[t.key]),onValueChange:a=>d(t.key,xs(a)),disabled:r,children:[e.jsx(q,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:"Use default"})}),e.jsxs(Y,{children:[e.jsx(k,{value:C,children:"Use default"}),e.jsx(k,{value:"true",children:"true"}),e.jsx(k,{value:"false",children:"false"})]})]})]},t.key))]})]})]})}const fs=[{id:"droid-cli-overview",label:"Droid CLI Overview",url:"https://docs.factory.ai/cli/",description:"Primary entry docs for setup, auth, and core CLI usage."},{id:"droid-byok-overview",label:"BYOK Overview",url:"https://docs.factory.ai/cli/byok/overview/",description:"BYOK model/provider shape, provider values, and migration notes."},{id:"droid-settings-reference",label:"settings.json Reference",url:"https://docs.factory.ai/cli/configuration/settings/",description:"Supported settings keys, defaults, and allowed values."}],hs=[{provider:"anthropic",label:"Anthropic Messages API",apiFormat:"Messages API",url:"https://docs.anthropic.com/en/api/messages"},{provider:"openai",label:"OpenAI Responses API",apiFormat:"Responses API",url:"https://platform.openai.com/docs/api-reference/responses"},{provider:"generic-chat-completion-api",label:"OpenAI Chat Completions Spec",apiFormat:"Chat Completions API",url:"https://platform.openai.com/docs/api-reference/chat"}];function ps(s){const r=/https?:\/\/[^\s)]+/g,n=[];let o=0,d;for(;(d=r.exec(s))!==null;){const[l]=d,t=d.index;t>o&&n.push(s.slice(o,t)),n.push(e.jsx("a",{href:l,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:l},`${l}-${t}`)),o=t+l.length}return o<s.length&&n.push(s.slice(o)),n.length>0?n:[s]}function js(s){return!s||!Number.isFinite(s)?"N/A":new Date(s).toLocaleString()}function bs(s){return!s||s<=0?"0 B":s<1024?`${s} B`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(2)} MB`}function vs(s){try{const r=JSON.parse(s);return!r||typeof r!="object"||Array.isArray(r)?{valid:!1,error:"JSON root must be an object."}:{valid:!0,value:r}}catch(r){return{valid:!1,error:r.message}}}function z(s){return typeof s=="string"?s:null}function J(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function R(s){return typeof s=="boolean"?s:null}function g({label:s,value:r,mono:n=!1}){return e.jsxs("div",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-muted-foreground shrink-0",children:s}),e.jsx("span",{className:Ce("text-right break-all",n&&"font-mono text-xs"),children:r})]})}function _s(){const{t:s}=Ne(),{diagnostics:r,diagnosticsLoading:n,diagnosticsError:o,refetchDiagnostics:d,rawSettings:l,rawSettingsLoading:t,refetchRawSettings:a,saveRawSettingsAsync:u,isSavingRawSettings:x}=He(),[D,O]=Q.useState(null),B=l?.rawText??"{}",M=D??B,Z=D!==null&&D!==B,c=vs(M),F=c.valid?{valid:!0}:{valid:!1,error:c.error},ee=m=>{if(m===B){O(null);return}O(m)},L=m=>{ee(JSON.stringify(m,null,2)+`
|
|
2
|
-
`)},I=(m,w)=>{if(!c.valid){j.error(s("droidPage.fixJsonBeforeQuickSettings"));return}const S={...c.value};w==null?delete S[m]:S[m]=w,L(S)},me=c.valid?{reasoningEffort:z(c.value.reasoningEffort),autonomyLevel:z(c.value.autonomyLevel),diffMode:z(c.value.diffMode),maxTurns:J(c.value.maxTurns),maxToolCalls:J(c.value.maxToolCalls),autoCompactThreshold:J(c.value.autoCompactThreshold),todoEnabled:R(c.value.todoEnabled),todoAutoRefresh:R(c.value.todoAutoRefresh),autoCompactEnabled:R(c.value.autoCompactEnabled),soundEnabled:R(c.value.soundEnabled)}:{reasoningEffort:null,autonomyLevel:null,diffMode:null,maxTurns:null,maxToolCalls:null,autoCompactThreshold:null,todoEnabled:null,todoAutoRefresh:null,autoCompactEnabled:null,soundEnabled:null},xe=c.valid?ns(c.value):[],ge=async()=>{await Promise.all([d(),a()])},fe=async()=>{if(!F.valid){j.error(s("droidPage.invalidJson",{value:F.error}));return}try{await u({rawText:M,expectedMtime:l?.exists?l.mtime:void 0}),O(null),j.success(s("droidPage.saved"))}catch(m){Ee(m)?j.error(s("droidPage.changedExternally")):j.error(m.message||s("droidPage.failedSave"))}},se=r?.byok.customModels??[],re=Q.useMemo(()=>Object.entries(r?.byok.providerBreakdown??{}).sort((m,w)=>w[1]-m[1]),[r?.byok.providerBreakdown]),he=()=>{if(n)return e.jsxs("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:[e.jsx(Be,{className:"h-5 w-5 animate-spin mr-2"}),s("droidPage.loadingDiagnostics")]});if(o||!r)return e.jsx("div",{className:"flex h-full items-center justify-center text-destructive px-6 text-center",children:s("droidPage.failedDiagnostics")});const m=r.docsReference??{notes:[],links:[],providerDocs:[],providerValues:[],settingsHierarchy:[]},w=m.notes??[],S=m.links??[],te=m.providerDocs??[],pe=S.length>0?S:fs,je=te.length>0?te:hs,be=m.providerValues??[],ve=m.settingsHierarchy??[],K="mt-0 h-full border-0 p-0 data-[state=inactive]:hidden";return e.jsxs(Se,{defaultValue:"byok",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Pe,{className:"grid w-full grid-cols-3",children:[e.jsx(U,{value:"overview",children:s("droidPage.overview")}),e.jsx(U,{value:"byok",children:s("droidPage.byok")}),e.jsx(U,{value:"docs",children:s("droidPage.docs")})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden px-4 pb-4 pt-3",children:[e.jsx(V,{value:"overview",className:K,children:e.jsx(T,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4"}),s("droidPage.runtimeInstall")]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:s("droidPage.status")}),e.jsx(P,{variant:r.binary.installed?"default":"secondary",children:r.binary.installed?s("droidPage.detected"):s("droidPage.notFound")})]}),e.jsx(g,{label:s("droidPage.detectionSource"),value:r.binary.source,mono:!0}),e.jsx(g,{label:s("droidPage.binaryPath"),value:r.binary.path||s("droidPage.notFound"),mono:!0}),e.jsx(g,{label:s("droidPage.installDirectory"),value:r.binary.installDir||"N/A",mono:!0}),e.jsx(g,{label:s("droidPage.version"),value:r.binary.version||"Unknown",mono:!0}),e.jsx(g,{label:s("droidPage.overridePath"),value:r.binary.overridePath||"Not set",mono:!0})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Fe,{className:"h-4 w-4"}),s("droidPage.configFiles")]})}),e.jsx(N,{className:"space-y-3",children:[r.files.settings,r.files.legacyConfig].map(i=>e.jsxs("div",{className:"rounded-md border p-3 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"font-medium text-sm",children:i.label}),i.exists?e.jsx(Le,{className:"h-4 w-4 text-green-600"}):e.jsx(Ie,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(g,{label:s("droidPage.path"),value:i.path,mono:!0}),e.jsx(g,{label:s("droidPage.resolved"),value:i.resolvedPath,mono:!0}),e.jsx(g,{label:s("droidPage.size"),value:bs(i.sizeBytes)}),e.jsx(g,{label:s("droidPage.lastModified"),value:js(i.mtimeMs)}),i.parseError&&e.jsx("p",{className:"text-xs text-amber-600",children:s("droidPage.parseWarning",{value:i.parseError})}),i.readError&&e.jsx("p",{className:"text-xs text-destructive",children:s("droidPage.readWarning",{value:i.readError})})]},i.label))})]}),r.warnings.length>0&&e.jsxs(b,{className:"border-amber-200 bg-amber-50/50 dark:bg-amber-950/20",children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4 text-amber-600"}),s("droidPage.warnings")]})}),e.jsx(N,{className:"space-y-1.5",children:r.warnings.map(i=>e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-300",children:["- ",i]},i))})]})]})})}),e.jsx(V,{value:"byok",className:K,children:e.jsx(T,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsx(gs,{values:me,disabled:t||!c.valid,disabledReason:c.valid?null:`Quick settings disabled: ${c.error}`,onEnumSettingChange:(i,f)=>{I(i,f)},onBooleanSettingChange:(i,f)=>{I(i,f)},onNumberSettingChange:(i,f)=>{I(i,f)}}),e.jsx(ls,{models:xe,disabled:t||!c.valid,disabledReason:c.valid?null:`${s("droidPage.byok")}: ${c.error}`,onEffortChange:(i,f)=>{if(!c.valid){j.error(s("droidPage.fixJsonBeforeReasoning"));return}const E=as(c.value,i,f);if(!E){j.error(s("droidPage.unableUpdateReasoning"));return}L(E)},onAnthropicBudgetChange:(i,f)=>{if(!c.valid){j.error(s("droidPage.fixJsonBeforeBudget"));return}const E=is(c.value,i,f);if(!E){j.error(s("droidPage.anthropicOnlyBudget"));return}L(E)}}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ue,{className:"h-4 w-4"}),s("droidPage.byokSummary")]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsx(g,{label:s("droidPage.activeModelSelector"),value:r.byok.activeModelSelector||"Not set",mono:!0}),e.jsx(g,{label:s("droidPage.customModels"),value:String(r.byok.customModelCount)}),e.jsx(g,{label:s("droidPage.ccsManaged"),value:String(r.byok.ccsManagedCount)}),e.jsx(g,{label:s("droidPage.userManaged"),value:String(r.byok.userManagedCount)}),e.jsx(g,{label:s("droidPage.malformedEntries"),value:String(r.byok.invalidModelEntryCount)}),e.jsx(A,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.providers")}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[re.length===0&&e.jsx(P,{variant:"secondary",className:"font-mono",children:s("droidPage.none")}),re.map(([i,f])=>e.jsxs(P,{variant:"outline",className:"font-mono text-xs",children:[i,": ",f]},i))]})]})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsx(y,{className:"text-base",children:s("droidPage.customModelsTitle")})}),e.jsx(N,{children:e.jsxs("div",{className:"rounded-md border overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-[2fr_1fr_2fr] bg-muted/40 px-3 py-2 text-xs font-medium",children:[e.jsx("span",{children:s("droidPage.modelName")}),e.jsx("span",{children:s("droidPage.provider")}),e.jsx("span",{children:s("droidPage.baseUrl")})]}),e.jsx(T,{className:"h-52",children:e.jsxs("div",{className:"divide-y",children:[se.length===0&&e.jsx("div",{className:"px-3 py-4 text-xs text-muted-foreground",children:s("droidPage.noCustomModels")}),se.map(i=>e.jsxs("div",{className:"grid grid-cols-[2fr_1fr_2fr] gap-2 px-3 py-2 text-xs",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:i.displayName}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:i.model})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",children:i.provider}),e.jsx("p",{className:"text-muted-foreground",children:i.apiKeyPreview||"no-key"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",title:i.baseUrl,children:i.host||i.baseUrl}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:i.baseUrl})]})]},`${i.displayName}-${i.model}-${i.baseUrl}`))]})})]})})]})]})})}),e.jsx(V,{value:"docs",className:K,children:e.jsx(T,{className:"h-full",children:e.jsx("div",{className:"space-y-4 pr-1",children:e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsxs(y,{className:"text-base flex items-center gap-2",children:[e.jsx(Ve,{className:"h-4 w-4"}),s("droidPage.docsAlignedNotes")]})}),e.jsxs(N,{className:"space-y-2 text-sm",children:[w.map((i,f)=>e.jsxs("p",{className:"text-muted-foreground",children:["- ",ps(i)]},`${f}-${i}`)),e.jsx(A,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("droidPage.factoryDocs")}),e.jsx("div",{className:"space-y-1.5",children:pe.map(i=>e.jsxs("a",{href:i.url,target:"_blank",rel:"noreferrer",className:"block rounded-md border px-2.5 py-2 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:i.label}),e.jsx(ie,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:i.description}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:i.url})]},i.id))})]}),e.jsx(A,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:s("droidPage.providerFactCheckDocs")}),e.jsx("div",{className:"space-y-1.5",children:je.map(i=>e.jsxs("a",{href:i.url,target:"_blank",rel:"noreferrer",className:"block rounded-md border px-2.5 py-2 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-xs font-medium",children:i.label}),e.jsx(ie,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["provider: ",i.provider," | format: ",i.apiFormat]}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:i.url})]},`${i.provider}-${i.url}`))})]}),e.jsx(A,{}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.providerValues",{value:be.join(", ")})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("droidPage.settingsHierarchy",{value:ve.join(" -> ")})})]})]})})})})]})]})};return e.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:e.jsxs(we,{direction:"horizontal",className:"h-full",children:[e.jsx(ne,{defaultSize:45,minSize:35,children:e.jsx("div",{className:"h-full border-r bg-muted/20",children:he()})}),e.jsx(ke,{className:"w-2 bg-border hover:bg-primary/20 transition-colors cursor-col-resize flex items-center justify-center group",children:e.jsx(Oe,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary"})}),e.jsx(ne,{defaultSize:55,minSize:35,children:e.jsx(Re,{title:s("droidPage.settingsTitle"),pathLabel:l?.path||"~/.factory/settings.json",loading:t,parseWarning:l?.parseError,value:M,dirty:Z,saving:x,saveDisabled:!Z||x||t||!F.valid,onChange:m=>{ee(m)},onSave:fe,onRefresh:ge})})]})})}export{_s as DroidPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as d}from"./react-vendor-CNOkPC89.js";import{bv as je,Y as re,be as ae,bg as te,d as B,n as Ne,B as c,c as u,aF as ye,I as G,r as se,s as ne,t as ie,v as de,w as O}from"./index-DOn6k1jF.js";import{R as J,w as le,x as ke,a8 as oe,aB as we,A as Ce,aa as Be,as as Me,t as Se,s as _e,a9 as Pe,aK as Re}from"./icons-KVCk4_U8.js";import"./tanstack-CrmUhA7Z.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";const M="__no_backend__";function ce(t){return!!t&&typeof t=="object"&&!Array.isArray(t)&&Object.values(t).every(a=>typeof a=="string")}function Ae(t){if(!t||typeof t!="object"||Array.isArray(t))return!1;const a=t;return!!a.config&&typeof a.config.enabled=="boolean"&&typeof a.config.timeout=="number"&&ce(a.config.providerModels)&&(a.config.fallbackBackend===null||typeof a.config.fallbackBackend=="string")&&ce(a.config.profileBackends)&&!!a.summary&&typeof a.summary.state=="string"&&typeof a.summary.title=="string"&&typeof a.summary.detail=="string"&&Array.isArray(a.backends)&&Array.isArray(a.profiles)&&!!a.catalog&&Array.isArray(a.catalog.knownBackends)&&Array.isArray(a.catalog.profileNames)&&typeof a.summary.nativeProfileCount=="number"}function Te(t){return Object.entries(t).sort(([a],[l])=>a.localeCompare(l)).map(([a,l],g)=>({id:`${a}-${l}-${g}`,profileName:a,backendId:l}))}function De(t){switch(t){case"ready":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-900 dark:text-emerald-200";case"partial":return"border-amber-500/25 bg-amber-500/10 text-amber-900 dark:text-amber-200";case"needs_setup":return"border-rose-500/25 bg-rose-500/10 text-rose-900 dark:text-rose-200";case"disabled":return"border-border/80 bg-background/85 text-muted-foreground"}}function Ie(t){switch(t){case"ready":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200";case"starts_on_launch":return"border-sky-500/25 bg-sky-500/10 text-sky-800 dark:text-sky-200";case"needs_auth":return"border-rose-500/25 bg-rose-500/10 text-rose-800 dark:text-rose-200";case"needs_proxy":return"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200";case"review":return"border-border/80 bg-background/85 text-muted-foreground"}}function me(t){switch(t){case"active":return"Active";case"bypassed":return"Bypassed";case"fallback":return"Native fallback";case"setup":return"Needs setup";case"disabled":return"Disabled";case"native":return"Native";case"unresolved":return"Native only"}}function ue(t){switch(t){case"active":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200";case"bypassed":return"border-sky-500/25 bg-sky-500/10 text-sky-800 dark:text-sky-200";case"fallback":case"setup":return"border-amber-500/25 bg-amber-500/10 text-amber-800 dark:text-amber-200";case"native":return"border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-200";case"disabled":case"unresolved":return"border-border/80 bg-background/85 text-muted-foreground"}}function Ee(t){switch(t){case"starts_on_launch":return"Starts on launch";case"needs_auth":return"Needs auth";case"needs_proxy":return"Needs proxy";case"review":return"Review";case"ready":return"Ready"}}function $e(t){if(!t)return"No model configured.";switch(t.state){case"needs_auth":return t.authReason||"Authenticate to route here.";case"needs_proxy":return t.proxyReason||"Proxy unavailable.";case"starts_on_launch":return"Auth ready. Launches locally on demand.";case"review":return"Needs manual review.";case"ready":return null}}function ze(t){switch(t){case"profile-backend":return"Explicit mapping";case"fallback-backend":return"Fallback backend";case"cliproxy-provider":return"Provider match";case"cliproxy-bridge":return"Bridge match";case"native-compatible":return"Native path";case"copilot-alias":return"Copilot alias";default:return t.replace(/-/g," ")}}function y(t){return"border-border/50 bg-background/40"}function Fe(t){switch(t){case"ready":return"bg-[linear-gradient(90deg,rgba(16,185,129,0.08),transparent_18%),linear-gradient(180deg,rgba(255,255,255,0.72),rgba(255,255,255,0.46))] dark:bg-[linear-gradient(90deg,rgba(16,185,129,0.12),transparent_18%),linear-gradient(180deg,rgba(15,23,42,0.82),rgba(15,23,42,0.56))]";case"starts_on_launch":return"bg-[linear-gradient(90deg,rgba(14,165,233,0.08),transparent_18%),linear-gradient(180deg,rgba(255,255,255,0.72),rgba(255,255,255,0.46))] dark:bg-[linear-gradient(90deg,rgba(14,165,233,0.12),transparent_18%),linear-gradient(180deg,rgba(15,23,42,0.82),rgba(15,23,42,0.56))]";case"needs_auth":return"bg-[linear-gradient(90deg,rgba(244,63,94,0.08),transparent_18%),linear-gradient(180deg,rgba(255,255,255,0.72),rgba(255,255,255,0.46))] dark:bg-[linear-gradient(90deg,rgba(244,63,94,0.12),transparent_18%),linear-gradient(180deg,rgba(15,23,42,0.82),rgba(15,23,42,0.56))]";case"needs_proxy":return"bg-[linear-gradient(90deg,rgba(245,158,11,0.08),transparent_18%),linear-gradient(180deg,rgba(255,255,255,0.72),rgba(255,255,255,0.46))] dark:bg-[linear-gradient(90deg,rgba(245,158,11,0.12),transparent_18%),linear-gradient(180deg,rgba(15,23,42,0.82),rgba(15,23,42,0.56))]";case"review":default:return"bg-[linear-gradient(180deg,rgba(255,255,255,0.74),rgba(255,255,255,0.5))] dark:bg-[linear-gradient(180deg,rgba(15,23,42,0.8),rgba(15,23,42,0.58))]"}}function Oe(t){switch(t){case"ready":return"from-emerald-500 to-emerald-400/30";case"starts_on_launch":return"from-sky-500 to-sky-400/30";case"needs_auth":return"from-rose-500 to-rose-400/30";case"needs_proxy":return"from-amber-500 to-amber-400/30";case"review":default:return"from-slate-400 to-slate-300/20"}}function Ke(t,a){return a.nativeReadPreference?t%2===0?"bg-emerald-500/[0.06]":"bg-emerald-500/[0.08]":t%2===0?"bg-background/75":"bg-muted/18"}function Le(t){const a=[`${t.activeProfileCount} routed`,`${t.nativeProfileCount} native`];return t.mappedProfileCount>0&&a.push(`${t.mappedProfileCount} override${t.mappedProfileCount===1?"":"s"}`),a.join(" · ")}function Ve(t){return Object.entries(t).reduce((a,[l,g])=>{const j=g.trim();return a[l]=j||null,a},{})}function q(t){return Object.entries(t).filter(([,a])=>a.trim().length>0).map(([a])=>a)}function Ue(t){return t.reduce((a,l)=>{const g=l.profileName.trim();return!g||!l.backendId||(a[g]=l.backendId),a},{})}function ge(t,a){const l=Number.parseInt(t.trim(),10);return Number.isInteger(l)?String(Math.min(600,Math.max(10,l))):a}function T({title:t,description:a,icon:l,meta:g,action:j,children:o,className:D}){return e.jsxs("div",{className:u("relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/25 p-4 shadow-sm",D),children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-primary/40 via-primary/10 to-transparent"}),e.jsxs("div",{className:"relative space-y-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-xl border border-primary/20 bg-primary/10 text-primary",children:l}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold tracking-tight",children:t}),g]}),e.jsx("p",{className:"mt-0.5 text-sm leading-5 text-muted-foreground",children:a})]})]}),j&&e.jsx("div",{className:"shrink-0",children:j})]}),e.jsx("div",{className:"space-y-3",children:o})]})]})}function er(){const{fetchRawConfig:t}=je(),[a,l]=d.useState(null),[g,j]=d.useState(!0),[o,D]=d.useState(!1),[I,N]=d.useState(null),[S,K]=d.useState(null),[E,Y]=d.useState(!1),[_,Q]=d.useState(!0),[L,V]=d.useState("60"),[f,P]=d.useState(""),[k,$]=d.useState({}),[x,z]=d.useState([]),w=d.useCallback(r=>{Q(r.config.enabled),V(String(r.config.timeout)),P(r.config.fallbackBackend??""),$(r.catalog.knownBackends.reduce((s,n)=>(s[n]=r.config.providerModels[n]??"",s),{})),z(Te(r.config.profileBackends))},[]),U=d.useCallback(async()=>{try{j(!0),N(null);const r=await re.imageAnalysis.get();if(!Ae(r))throw new Error("Image settings returned an unexpected response. Restart the dashboard server so the new API route is available.");l(r),w(r)}catch(r){N(r instanceof Error?r.message:"Failed to load image settings.")}finally{j(!1)}},[w]);d.useEffect(()=>{U(),t()},[U,t]),d.useEffect(()=>{if(!S)return;const r=window.setTimeout(()=>K(null),2500);return()=>window.clearTimeout(r)},[S]),d.useEffect(()=>{a&&Object.keys(a.config.profileBackends).length>0&&Y(!0)},[a]);const m=d.useMemo(()=>q(k),[k]),W=d.useMemo(()=>{if(!a)return[];const r=a.catalog.knownBackends.filter(n=>m.includes(n)),s=a.catalog.knownBackends.filter(n=>!m.includes(n));return[...r,...s]},[m,a]),F=d.useMemo(()=>a?.profiles.filter(r=>r.nativeReadPreference)??[],[a]);d.useEffect(()=>{if(m.length===0){P("");return}m.includes(f)||P(m[0])},[m,f]);const R=d.useCallback(async r=>{if(!a)return!1;const s=r?.enabled??_,n=r?.providerModels??k,i=q(n),b=ge(r?.timeout??L,String(a.config.timeout)),h=r?.fallbackBackend??f,C=i.length===0?"":i.includes(h)?h:i[0],p=r?.mappingDrafts??x,A={enabled:s,timeout:b,fallbackBackend:C,providerModels:Ve(n),profileBackends:Ue(p)},ve={enabled:a.config.enabled,timeout:String(a.config.timeout),fallbackBackend:a.config.fallbackBackend??"",providerModels:a.catalog.knownBackends.reduce((v,ee)=>(v[ee]=a.config.providerModels[ee]??null,v),{}),profileBackends:a.config.profileBackends};if(JSON.stringify(A)===JSON.stringify(ve))return!0;if(s&&i.length===0)return N("Keep at least one provider model configured, or disable Image globally."),w(a),!1;try{D(!0),N(null);const v=await re.imageAnalysis.update({enabled:s,timeout:Number.parseInt(b,10),fallbackBackend:C||null,providerModels:A.providerModels,profileBackends:A.profileBackends});return l(v),w(v),K("Image settings saved."),await t(),!0}catch(v){return N(v instanceof Error?v.message:"Failed to save image settings."),w(a),!1}finally{D(!1)}},[a,_,f,t,w,x,k,L]),X=async()=>{g||o||(K(null),await Promise.all([U(),t()]))},xe=async r=>{if(!o){if(r&&m.length===0){N("Keep at least one provider model configured, or disable Image globally.");return}Q(r),await R({enabled:r})}},be=async r=>{if(!a||o)return;const s=ge(r,String(a.config.timeout));V(s),await R({timeout:s})},pe=async r=>{o||(P(r),await R({fallbackBackend:r}))},Z=async(r,s)=>{if(!a||o)return;const n=s.trim(),i={...k,[r]:n},b=q(i);if(_&&b.length===0){N("Disable Image first or keep one backend configured."),$(C=>({...C,[r]:a.config.providerModels[r]??""}));return}const h=b.length===0?"":b.includes(f)?f:b[0];$(i),P(h),await R({providerModels:i,fallbackBackend:h})},fe=(r,s)=>{z(n=>n.map(i=>i.id===r?{...i,...s}:i))},H=async r=>{o||(z(r),await R({mappingDrafts:r}))},he=x.filter(r=>r.profileName.trim()&&r.backendId).length;return g?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground",children:[e.jsx(J,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading image settings..."})]})}):a?e.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${I||S?"translate-y-0 opacity-100":"pointer-events-none -translate-y-2 opacity-0"}`,children:[I&&e.jsxs(ae,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(le,{className:"h-4 w-4"}),e.jsx(te,{children:I})]}),S&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-green-200 bg-green-50 px-3 py-2 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ke,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:S})]})]}),e.jsx(Ne,{className:"min-h-0 flex-1",children:e.jsxs("div",{className:"space-y-6 p-5",children:[e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border bg-gradient-to-br from-background via-background to-muted/30 p-4 shadow-sm",children:[e.jsx("div",{className:"absolute inset-x-0 top-0 h-px bg-gradient-to-r from-primary/70 via-primary/20 to-transparent"}),e.jsx("div",{className:"pointer-events-none absolute inset-0 opacity-[0.035]",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"inline-flex h-8 w-8 items-center justify-center rounded-xl border border-primary/20 bg-primary/8 text-primary",children:e.jsx(oe,{className:"h-4 w-4"})}),e.jsx("p",{className:"text-sm font-semibold tracking-tight",children:"Image"})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(c,{className:u("border",De(a.summary.state)),children:a.summary.title}),e.jsx("span",{children:Le(a.summary)})]})]}),e.jsx(B,{variant:"ghost",size:"sm",onClick:X,disabled:g||o,"aria-label":"Refresh",title:"Refresh",children:e.jsx(J,{className:`h-4 w-4 ${g?"animate-spin":""}`})})]}),e.jsxs("div",{className:"mt-3 grid gap-2 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border bg-background/72 px-3 py-2.5 backdrop-blur-sm",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Active routes"}),e.jsx("div",{className:"mt-1.5 text-xl font-semibold text-foreground",children:a.summary.activeProfileCount}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Current target path"})]}),e.jsxs("div",{className:"rounded-[18px] border bg-background/72 px-3 py-2.5 backdrop-blur-sm",children:[e.jsx("div",{className:"text-[10px] font-medium uppercase tracking-[0.14em] text-muted-foreground",children:"Native path"}),e.jsx("div",{className:"mt-1.5 text-xl font-semibold text-foreground",children:a.summary.nativeProfileCount}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:"Skip transformer"})]})]})]})]}),e.jsxs(T,{tone:"amber",eyebrow:"Control deck",title:"Core setup",description:"Global toggle, timeout, and fallback.",icon:e.jsx(we,{className:"h-4 w-4"}),meta:e.jsxs(c,{variant:"outline",className:"border-amber-500/25 bg-amber-500/10 text-[10px]",children:[m.length," configured"]}),children:[e.jsxs("div",{className:"grid gap-2 lg:grid-cols-3",children:[e.jsxs("div",{className:u("rounded-[18px] border px-3.5 py-3 shadow-sm",y()),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-amber-700/75 dark:text-amber-300/75",children:"Enabled"}),e.jsxs("div",{className:"mt-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"text-sm font-semibold text-foreground",children:_?"Transformer on":"Transformer off"}),e.jsx("p",{className:"text-[11px] leading-4 text-muted-foreground",children:"Profile flags stay untouched."})]}),e.jsx(ye,{checked:_,onCheckedChange:r=>{xe(r)},disabled:o})]})]}),e.jsxs("div",{className:u("rounded-[18px] border px-3.5 py-3 shadow-sm",y()),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-amber-700/75 dark:text-amber-300/75",children:"Timeout"}),e.jsxs("div",{className:"mt-2.5 flex items-center gap-2",children:[e.jsx(G,{value:L,onChange:r=>V(r.target.value),inputMode:"numeric",className:"h-10 border-amber-500/15 bg-background/90 text-base",disabled:o,onBlur:r=>{be(r.currentTarget.value)},onKeyDown:r=>{r.key==="Enter"&&r.currentTarget.blur()}}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"sec"})]}),e.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:"Keeps large reads from hanging."})]}),e.jsxs("div",{className:u("rounded-[18px] border px-3.5 py-3 shadow-sm",y()),children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.14em] text-amber-700/75 dark:text-amber-300/75",children:"Fallback backend"}),e.jsx("div",{className:"mt-2.5",children:e.jsxs(se,{value:f||M,onValueChange:r=>{pe(r===M?"":r)},disabled:o,children:[e.jsx(ne,{className:"h-10 border-amber-500/15 bg-background/90",children:e.jsx(ie,{placeholder:"Choose backend"})}),e.jsx(de,{children:m.length===0?e.jsx(O,{value:M,children:"Configure a model first"}):m.map(r=>e.jsx(O,{value:r,children:r},r))})]})}),e.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:"Used when no direct route exists."})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-1.5",children:[e.jsxs("div",{className:"rounded-full border border-amber-500/15 bg-background/80 px-2.5 py-1 text-[11px] text-muted-foreground",children:[he," overrides"]}),e.jsxs("div",{className:"rounded-full border border-amber-500/15 bg-background/80 px-2.5 py-1 text-[11px] text-muted-foreground",children:[F.length," native"]}),e.jsxs("div",{className:"rounded-full border border-amber-500/15 bg-background/80 px-2.5 py-1 text-[11px] text-muted-foreground",children:[f||"No fallback"," fallback"]})]})]}),e.jsx(T,{tone:"cyan",eyebrow:"Route inventory",title:"Backend routes",description:"Model entry plus route health.",icon:e.jsx(Ce,{className:"h-4 w-4"}),meta:e.jsxs(c,{variant:"outline",className:"border-cyan-500/25 bg-cyan-500/10 text-[10px]",children:[W.length," backends"]}),children:e.jsx("div",{className:"overflow-hidden rounded-[20px] border border-cyan-500/12 bg-background/65 shadow-sm backdrop-blur-sm",children:W.map((r,s)=>{const n=a.backends.find(p=>p.backendId===r),i=n?.displayName||r,b=k[r]??"",h=$e(n),C=b?[`${n?.profilesUsing??0} active`,n?.authReadiness==="missing"?"auth missing":n?.proxyReadiness==="stopped"?"starts on launch":null].filter(Boolean).join(" · "):"No model configured.";return e.jsxs("div",{className:u("relative px-3 py-3 md:px-4",s>0&&"border-t border-cyan-500/10",Fe(n?.state)),children:[e.jsx("div",{className:u("absolute bottom-3 left-0 top-3 w-1 rounded-r-full bg-gradient-to-b",Oe(n?.state))}),e.jsxs("div",{className:"pl-2.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h4",{className:"text-sm font-semibold text-foreground",children:i}),e.jsx(c,{variant:"outline",className:"font-mono text-[10px]",children:r}),n?.profilesUsing?e.jsxs(c,{variant:"outline",className:"border-cyan-500/20 bg-cyan-500/10 text-[10px]",children:[n.profilesUsing," active"]}):null]}),e.jsx("p",{className:"mt-0.5 text-[11px] leading-4 text-muted-foreground",children:C})]}),e.jsx(c,{className:u("border",n?Ie(n.state):"border-border/80 bg-background/85 text-muted-foreground"),children:n?Ee(n.state):"Inactive"})]}),e.jsxs("div",{className:"mt-2 flex flex-col gap-2 sm:flex-row",children:[e.jsx(G,{className:"h-10 flex-1 border-cyan-500/15 bg-background/88 text-base",placeholder:"Set model",value:b,disabled:o,onChange:p=>$(A=>({...A,[r]:p.target.value})),onBlur:p=>{Z(r,p.currentTarget.value)},onKeyDown:p=>{p.key==="Enter"&&p.currentTarget.blur()}}),b.trim().length>0&&e.jsx(B,{type:"button",variant:"outline",size:"sm",className:"h-10 sm:self-stretch",disabled:o,onClick:()=>{Z(r,"")},children:"Clear"})]}),h&&e.jsx("p",{className:"mt-1.5 text-[11px] leading-4 text-muted-foreground",children:h})]})]},r)})})}),e.jsx(T,{tone:"emerald",eyebrow:"Native path",title:"Native reading",description:"Profiles that skip the transformer.",icon:e.jsx(Be,{className:"h-4 w-4"}),meta:e.jsxs(c,{variant:"outline",children:[F.length," profiles"]}),children:F.length===0?e.jsx("div",{className:u("rounded-[18px] border border-dashed px-3.5 py-3.5 text-sm text-muted-foreground",y()),children:"No profiles prefer native reading yet."}):e.jsx("div",{className:"grid gap-2 md:grid-cols-2",children:F.map(r=>e.jsx("div",{className:u("rounded-[18px] border px-3.5 py-3 shadow-sm",y()),children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:r.name}),e.jsx(c,{variant:"outline",className:"text-[10px]",children:r.kind==="variant"?"Variant":"Profile"}),e.jsx(c,{variant:"outline",className:"text-[10px]",children:r.nativeImageCapable?"Verified":"Review"})]}),e.jsxs("div",{className:"mt-1 text-[11px] leading-4 text-muted-foreground",children:[r.profileModel||"Model not detected"," ·"," ",r.nativeImageReason||"Native read preferred."]})]}),e.jsx(c,{className:u("border",ue(r.currentTargetMode)),children:me(r.currentTargetMode)})]})},`native-${r.kind}-${r.name}`))})}),e.jsxs(T,{tone:"slate",eyebrow:"Override lab",title:"Profile routing",description:"Only for explicit route overrides.",icon:e.jsx(Re,{className:"h-4 w-4"}),meta:e.jsx(c,{variant:"outline",className:"border-amber-500/25 bg-amber-500/10 text-[10px] text-amber-800 dark:text-amber-200",children:"Advanced"}),action:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:()=>Y(r=>!r),children:[E?e.jsx(Se,{className:"mr-1 h-4 w-4"}):e.jsx(_e,{className:"mr-1 h-4 w-4"}),E?"Hide":"Show"]}),E&&e.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:()=>z(r=>[...r,{id:`mapping-${Date.now()}`,profileName:"",backendId:m[0]??""}]),disabled:m.length===0||o,children:[e.jsx(Pe,{className:"mr-1 h-4 w-4"}),"Add mapping"]})]}),className:"border-dashed",children:[e.jsx("datalist",{id:"image-profile-suggestions",children:a.catalog.profileNames.map(r=>e.jsx("option",{value:r},r))}),E?e.jsx("div",{className:"space-y-2",children:x.length===0?e.jsx("div",{className:u("rounded-[18px] border border-dashed px-3.5 py-3.5 text-sm text-muted-foreground",y()),children:"No explicit overrides saved."}):e.jsx("div",{className:"space-y-2",children:x.map(r=>e.jsxs("div",{className:"rounded-[18px] border border-slate-400/20 bg-[linear-gradient(180deg,rgba(255,255,255,0.72),rgba(248,250,252,0.52))] p-3 shadow-sm dark:bg-[linear-gradient(180deg,rgba(15,23,42,0.84),rgba(15,23,42,0.56))]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] leading-4 text-muted-foreground",children:[e.jsx("span",{children:"Direct override"}),!(r.profileName.trim()&&r.backendId)&&e.jsx(c,{variant:"outline",className:"text-[10px]",children:"Draft"})]}),e.jsxs(B,{type:"button",variant:"ghost",size:"sm",disabled:o,onClick:()=>{const s=x.filter(n=>n.id!==r.id);H(s)},children:[e.jsx(Me,{className:"mr-1 h-4 w-4"}),"Remove"]})]}),e.jsxs("div",{className:"mt-2 grid gap-2 sm:grid-cols-2",children:[e.jsx(G,{value:r.profileName,list:"image-profile-suggestions",disabled:o,placeholder:"Profile or variant name",className:"h-10 border-slate-400/15 bg-background/88 text-base",onChange:s=>{fe(r.id,{profileName:s.target.value})},onBlur:s=>{const n=x.map(i=>i.id===r.id?{...i,profileName:s.currentTarget.value.trim()}:i);H(n)},onKeyDown:s=>{s.key==="Enter"&&s.currentTarget.blur()}}),e.jsxs(se,{value:r.backendId||M,disabled:o,onValueChange:s=>{const n=x.map(i=>i.id===r.id?{...i,backendId:s===M?"":s}:i);H(n)},children:[e.jsx(ne,{className:"h-10 border-slate-400/15 bg-background/88",children:e.jsx(ie,{placeholder:"Choose backend"})}),e.jsx(de,{children:m.length===0?e.jsx(O,{value:M,children:"Configure a model first"}):m.map(s=>e.jsx(O,{value:s,children:s},s))})]})]})]},r.id))})}):e.jsxs("div",{className:u("rounded-[18px] border border-dashed px-3.5 py-3 text-sm text-muted-foreground",y()),children:["Hidden by default.",x.length>0?` ${x.length} override${x.length===1?"":"s"} saved.`:" No overrides saved."]})]}),e.jsx(T,{tone:"slate",eyebrow:"Audit view",title:"Coverage",description:"Read-only routing ledger for the current path.",icon:e.jsx(oe,{className:"h-4 w-4"}),meta:e.jsxs(c,{variant:"outline",children:[a.profiles.length," profiles"]}),children:e.jsx("div",{className:"overflow-hidden rounded-[20px] border border-slate-400/15 bg-background/75 shadow-sm backdrop-blur-sm",children:a.profiles.map((r,s)=>e.jsxs("div",{className:u("grid gap-2 px-3.5 py-2.5 md:grid-cols-[minmax(0,1fr)_auto] md:items-center",s>0&&"border-t border-slate-400/12",Ke(s,r)),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:r.name}),e.jsx(c,{variant:"outline",className:"text-[10px]",children:r.kind==="variant"?"Variant":"Profile"}),e.jsx(c,{variant:"outline",className:"font-mono text-[10px] uppercase",children:r.target}),r.nativeReadPreference&&e.jsx(c,{variant:"outline",className:"border-emerald-500/20 bg-emerald-500/10 text-[10px]",children:"Native"})]}),e.jsxs("div",{className:"mt-0.5 text-[11px] leading-4 text-muted-foreground",children:[r.backendDisplayName||r.profileModel||"Native file access"," ·"," ",ze(r.resolutionSource)]})]}),e.jsxs("div",{className:"flex items-center gap-2 md:justify-end",children:[r.profileModel&&e.jsx(c,{variant:"outline",className:"font-mono text-[10px]",children:r.profileModel}),e.jsx(c,{className:u("border",ue(r.currentTargetMode)),children:me(r.currentTargetMode)})]})]},`${r.kind}-${r.name}`))})})]})})]}):e.jsxs("div",{className:"p-5",children:[e.jsxs(ae,{variant:"destructive",children:[e.jsx(le,{className:"h-4 w-4"}),e.jsx(te,{children:I??"Failed to load image settings."})]}),e.jsx("div",{className:"mt-4",children:e.jsxs(B,{variant:"outline",size:"sm",onClick:X,children:[e.jsx(J,{className:"mr-1 h-4 w-4"}),"Retry"]})})]})}export{er as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as f,c as pe}from"./react-vendor-CNOkPC89.js";import{u as M,a as ee,C as p,b as g,S as h,c,P as N,B as I,d as H,e as se,f as ge,g as te,h as je,i as ae,j as y,k as D,l as ye,m as Ne,n as we,o as be}from"./index-DOn6k1jF.js";import{a3 as ve,al as re,am as z,an as ne,a1 as le,aa as ke,G as Ce,ao as Se,R as De,$ as Q,U as Le,Z as ie,v as $e,ad as G,ap as Te,Y as Fe,C as Re,aq as Me,ar as Pe}from"./icons-KVCk4_U8.js";import{a as Be,u as P}from"./tanstack-CrmUhA7Z.js";import{K as $,L as Y,f as k,H as Ae}from"./utils-CzKF5WmX.js";import{R as oe,A as Ue,C as qe,X as Ie,Y as V,T as ce,a as Z,P as Oe,b as Ke,c as Ee}from"./charts-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-Bcoyqxpq.js";import"./code-highlight-BRUf_pqB.js";function Ge({data:s,isLoading:t}){const{privacyMode:r}=M(),{t:n}=ee();if(t)return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:[1,2,3,4,5].map(a=>e.jsx(p,{children:e.jsx(g,{className:"p-6",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-8 w-[80px]"})]}),e.jsx(h,{className:"h-8 w-8 rounded-lg"})]})})},a))});const l=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),i=s?.totalCost?Math.round(l/s.totalCost*100):0,x=[{title:n("analyticsSummary.totalTokens"),value:s?.totalTokens??0,icon:ve,format:a=>R(a),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:n("analyticsSummary.totalTokensSubtitle",{input:R(s?.totalInputTokens??0),output:R(s?.totalOutputTokens??0)})},{title:n("analyticsSummary.totalCost"),value:s?.totalCost??0,icon:re,format:a=>`$${a.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:n("analyticsSummary.totalCostSubtitle",{value:s?.averageCostPerDay?.toFixed(2)??"0.00"})},{title:n("analyticsSummary.cacheTokens"),value:s?.totalCacheTokens??0,icon:z,format:a=>R(a),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:n("analyticsSummary.cacheTokensSubtitle",{cost:l.toFixed(2),percent:i})},{title:n("analyticsSummary.inputCost"),value:s?.tokenBreakdown?.input?.cost??0,icon:ne,format:a=>`$${a.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:R(s?.tokenBreakdown?.input?.tokens??0)})},{title:n("analyticsSummary.outputCost"),value:s?.tokenBreakdown?.output?.cost??0,icon:le,format:a=>`$${a.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:n("analyticsSummary.tokensSubtitle",{value:R(s?.tokenBreakdown?.output?.tokens??0)})}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:x.map((a,o)=>{const d=a.icon;return e.jsx(p,{className:"hover:shadow-md transition-shadow",children:e.jsx(g,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between space-x-2",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground truncate",children:a.title}),e.jsx("p",{className:c("text-xl font-bold truncate",r&&N),children:a.format(a.value)}),a.subtitle&&e.jsx("p",{className:c("text-[10px] text-muted-foreground truncate",r&&N),children:a.subtitle})]}),e.jsx("div",{className:c("p-2 rounded-lg shrink-0",a.bgColor),children:e.jsx(d,{className:c("h-4 w-4",a.color)})})]})})},o)})})}function R(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function We({model:s}){const{privacyMode:t}=M(),r=He(s.ioRatio);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary shrink-0"}),e.jsx("h4",{className:"font-semibold leading-none truncate",title:s.model,children:s.model})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(I,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(I,{variant:r.variant,className:"text-[10px] h-5 px-1.5",children:[s.ioRatio.toFixed(0),":1 I/O"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("p",{className:c("text-lg font-bold",t&&N),children:["$",s.cost.toFixed(2)]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Cost"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsx("p",{className:c("text-lg font-bold",t&&N),children:ze(s.tokens)}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider",children:"Total Tokens"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("h5",{className:"text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:"Token Breakdown"}),e.jsxs("div",{className:c("space-y-1",t&&N),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:ne}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:le}),e.jsx(W,{label:"Cache Write",tokens:s.cacheCreationTokens,cost:s.costBreakdown.cacheCreation.cost,color:"#e09f3e",icon:z}),e.jsx(W,{label:"Cache Read",tokens:s.cacheReadTokens,cost:s.costBreakdown.cacheRead.cost,color:"#9e2a2b",icon:z})]})]}),e.jsxs("div",{className:"p-2.5 rounded-md border bg-muted/20 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-xs font-medium",children:"Input/Output Ratio"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-snug",children:r.description})]})]})}function W({label:s,tokens:t,cost:r,color:n,icon:l}){return t===0?null:e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("div",{className:"w-1 h-6 rounded-full shrink-0",style:{backgroundColor:n}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-medium truncate",children:s}),e.jsxs("span",{className:"font-mono text-muted-foreground",children:["$",r.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(l,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:_e(t)})]})]})]})}function He(s){return s>=200?{variant:"destructive",description:"Extended thinking or large context loading. Expected for reasoning models."}:s>=50?{variant:"secondary",description:"More input than output. Typical for analysis tasks."}:s>=5?{variant:"outline",description:"Balanced input/output ratio for typical coding tasks."}:{variant:"default",description:"More output than input. Generation-heavy workload."}}function _e(s){return s.toLocaleString()}function ze(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}const Ye="/api";function b(s){const t=s.getFullYear(),r=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${r}${n}`}const T={summary:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/summary?${t}`)},trends:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/daily?${t}`)},hourly:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),L(`/usage/hourly?${t}`)},models:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/models?${t}`)},sessions:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),s?.limit&&t.append("limit",s.limit.toString()),s?.offset&&t.append("offset",s.offset.toString()),L(`/usage/sessions?${t}`)},monthly:(s,t)=>{const r=new URLSearchParams;return s&&r.append("months",s.toString()),t&&r.append("profile",t),L(`/usage/monthly?${r}`)},refresh:async()=>{if(!(await fetch(`${Ye}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>L("/usage/status"),insights:s=>{const t=new URLSearchParams;return s?.startDate&&t.append("since",b(s.startDate)),s?.endDate&&t.append("until",b(s.endDate)),s?.profile&&t.append("profile",s.profile),L(`/usage/insights?${t}`)}};async function L(s){const r=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!r.ok){const l=await r.json().catch(()=>({error:"Unknown error"}));throw new Error(l.error||r.statusText)}const n=await r.json();return n.data||n}function Qe(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function Ve(s){return P({queryKey:["usage","trends",s],queryFn:()=>T.trends(s),staleTime:60*1e3})}function Ze(s){return P({queryKey:["usage","hourly",s],queryFn:()=>T.hourly(s),staleTime:60*1e3})}function Xe(s){return P({queryKey:["usage","models",s],queryFn:()=>T.models(s),staleTime:60*1e3})}function Je(){const s=Be();return f.useCallback(async()=>{await T.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function es(){return P({queryKey:["usage","status"],queryFn:()=>T.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function ss(s){return P({queryKey:["usage","sessions",s],queryFn:()=>T.sessions(s),staleTime:60*1e3})}function ts(){const[s,t]=f.useState({from:$(new Date,30),to:new Date}),[r,n]=f.useState(!1),[l,i]=f.useState(null),[x,a]=f.useState(null),[o,d]=f.useState("daily"),u=Je(),m=f.useCallback(async()=>{n(!0);try{await u()}finally{n(!1)}},[u]),j=f.useMemo(()=>({startDate:s?.from,endDate:s?.to}),[s?.from,s?.to]),{data:w,isLoading:v}=Qe(j),{data:C,isLoading:S}=Ve(j),{data:B,isLoading:A}=Ze(j),{data:U,isLoading:q}=Xe(j),{data:_,isLoading:O}=ss({...j,limit:3}),{data:K}=es(),de=f.useCallback(()=>{const F=new Date;t({from:$(F,1),to:F}),d("hourly")},[]),xe=f.useCallback(F=>{t(F),d("daily")},[]),ue=f.useMemo(()=>K?.lastFetch?Y(new Date(K.lastFetch),{addSuffix:!0}):null,[K?.lastFetch]),me=f.useCallback((F,fe)=>{const E=fe.currentTarget.getBoundingClientRect();a({x:E.left+E.width/2,y:E.top+E.height/2}),i(F)},[]),he=f.useCallback(()=>{i(null),a(null)},[]);return{dateRange:s,isRefreshing:r,viewMode:o,selectedModel:l,popoverPosition:x,summary:w,trends:C,hourlyData:B,models:U,sessions:_,status:K,isSummaryLoading:v,isTrendsLoading:S,isHourlyLoading:A,isModelsLoading:q,isSessionsLoading:O,isLoading:v||S||q||O,handleRefresh:m,handleTodayClick:de,handleDateRangeChange:xe,handleModelClick:me,handlePopoverClose:he,lastUpdatedText:ue}}function as({value:s,onChange:t,presets:r=[{label:"Last 7 days",range:{from:$(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:$(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:$(new Date,90),to:new Date}}],className:n}){const[l,i]=pe.useState(!1),x=a=>!s||!s.from||!s.to||!a.from||!a.to?!1:k(s.from,"yyyy-MM-dd")===k(a.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(a.to,"yyyy-MM-dd");return e.jsxs("div",{className:c("flex flex-wrap items-center gap-2",n),children:[r.map(a=>e.jsx(H,{variant:x(a.range)?"default":"outline",size:"sm",onClick:()=>t(a.range),children:a.label},a.label)),e.jsxs(se,{open:l,onOpenChange:i,children:[e.jsx(ge,{asChild:!0,children:e.jsxs(H,{id:"date",variant:"outline",className:c("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),s?.from?s.to?e.jsxs(e.Fragment,{children:[k(s.from,"LLL dd, y")," - ",k(s.to,"LLL dd, y")]}):k(s.from,"LLL dd, y"):e.jsx("span",{children:"Pick a date"})]})}),e.jsx(te,{className:"w-auto p-0",align:"end",children:e.jsx(je,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function rs({dateRange:s,onDateRangeChange:t,onTodayClick:r,onRefresh:n,isRefreshing:l,lastUpdatedText:i,viewMode:x}){const{t:a}=ee();return e.jsxs("div",{className:"flex flex-col gap-3 shrink-0 xl:flex-row xl:items-center xl:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-semibold",children:a("analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a("analytics.subtitle")})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(H,{variant:x==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:r,children:"24H"}),e.jsx(as,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:$(new Date,7),to:new Date}},{label:"30D",range:{from:$(new Date,30),to:new Date}},{label:a("analytics.month"),range:{from:Ae(new Date),to:new Date}},{label:a("analytics.allTime"),range:{from:void 0,to:new Date}}]}),i&&e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:a("analytics.updated",{value:i})}),e.jsx(H,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:l,children:e.jsx(De,{className:`w-3.5 h-3.5 ${l?"animate-spin":""}`})})]})]})}function ns({data:s,isLoading:t,granularity:r="daily",className:n}){const{privacyMode:l}=M(),i=f.useMemo(()=>!s||s.length===0?[]:(r==="hourly"?s:[...s].reverse()).map(o=>{const d="hour"in o?o.hour:o.date;return{...o,dateFormatted:ls(d,r),costRounded:Number(o.cost.toFixed(4))}}),[s,r]);if(t)return e.jsx(h,{className:c("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:c("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:r==="hourly"?"No usage data for today":"No usage data available"})});const x=({x:a,y:o,payload:d,isRight:u})=>{const m=u?`$${d.value}`:X(Number(d.value));return e.jsx("text",{x:a,y:o,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:c("fill-muted-foreground",l&&"blur-[4px]"),children:m})};return e.jsx("div",{className:c("w-full h-full",n),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Ue,{data:i,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:"tokenGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#0080FF",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#0080FF",stopOpacity:.1})]}),e.jsxs("linearGradient",{id:"costGradient",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"#00C49F",stopOpacity:.8}),e.jsx("stop",{offset:"95%",stopColor:"#00C49F",stopOpacity:.1})]})]}),e.jsx(qe,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Ie,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:a=>e.jsx(x,{...a,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:a=>e.jsx(x,{...a,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(ce,{content:({active:a,payload:o,label:d})=>{if(!a||!o||!o.length)return null;const u=o[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-3 shadow-lg",children:[e.jsx("p",{className:"font-medium mb-2",children:d}),o.map((m,j)=>e.jsxs("p",{className:c("text-sm",l&&N),style:{color:m.color},children:[m.name,":"," ",m.name==="Tokens"?X(Number(m.value)||0):`$${m.value}`]},j)),"requests"in u&&e.jsxs("p",{className:c("text-sm text-muted-foreground mt-1",l&&N),children:["Requests: ",u.requests]})]})}}),e.jsx(Z,{yAxisId:"left",type:"monotone",dataKey:"tokens",stroke:"#0080FF",strokeWidth:2,fillOpacity:1,fill:"url(#tokenGradient)",name:"Tokens"}),e.jsx(Z,{yAxisId:"right",type:"monotone",dataKey:"costRounded",stroke:"#00C49F",strokeWidth:2,fillOpacity:1,fill:"url(#costGradient)",name:"Cost"})]})})})}function ls(s,t){if(t==="hourly"){const[n,l]=s.split(" ");if(n&&l){const i=new Date(`${n}T${l}:00Z`);return k(i,"HH:mm")}return s}const r=new Date(s);return t==="monthly"?k(r,"MMM yyyy"):k(r,"MMM dd")}function X(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function is({data:s,isLoading:t,className:r}){const{privacyMode:n}=M(),l=f.useMemo(()=>!s||s.length===0?[]:s.map(a=>({name:a.model,value:a.tokens,cost:a.cost,percentage:a.percentage,fill:ae(a.model)})),[s]);if(t)return e.jsx(h,{className:c("h-full min-h-[100px] w-full",r)});if(!s||s.length===0)return e.jsx("div",{className:c("h-full min-h-[100px] flex items-center justify-center",r),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const i=({active:a,payload:o})=>{if(!a||!o)return null;const d=o;if(!d.length)return null;const u=d[0].payload;return e.jsxs("div",{className:"rounded-lg border bg-background p-2 shadow-lg text-xs",children:[e.jsx("p",{className:"font-medium mb-1",children:u.name}),e.jsxs("p",{className:c("text-muted-foreground",n&&N),children:[os(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:c("text-muted-foreground",n&&N),children:["$",u.cost.toFixed(4)]})]})},x=a=>a.percentage>5?`${a.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:c("w-full h-full min-h-[100px]",r),children:e.jsx(oe,{width:"100%",height:"100%",children:e.jsxs(Oe,{children:[e.jsx(Ke,{data:l,cx:"50%",cy:"50%",labelLine:!1,label:x,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:l.map((a,o)=>e.jsx(Ee,{fill:a.fill,strokeWidth:1},`cell-${o}`))}),e.jsx(ce,{content:i})]})})})}function os(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function cs(s){if(!s)return"";const r=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return r[r.length-1]||""}function ds({data:s,isLoading:t,className:r}){const{privacyMode:n}=M(),l=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,x=s.total,a=i.reduce((w,v)=>w+(v.inputTokens+v.outputTokens),0),o=Math.round(a/i.length),u=i.reduce((w,v)=>w+v.cost,0)/i.length,m=i[0],j=m?Y(new Date(m.lastActivity),{addSuffix:!0}):"N/A";return{totalSessions:x,avgTokens:o,avgCost:u,lastActive:j,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsx(h,{className:"h-5 w-32"})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}):l?e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsxs(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0 flex flex-col gap-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-blue-600 dark:text-blue-400",children:[e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:l.totalSessions})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Total Sessions"})]}),e.jsxs("div",{className:"p-2 rounded-md bg-muted/50 border text-center",children:[e.jsxs("div",{className:"flex items-center justify-center gap-1.5 text-green-600 dark:text-green-400",children:[e.jsx(ie,{className:"w-4 h-4"}),e.jsxs("span",{className:c("text-xl font-bold",n&&N),children:["$",l.avgCost.toFixed(2)]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground uppercase tracking-wider mt-0.5",children:"Avg Cost/Session"})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium mb-1",children:[e.jsx($e,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:l.recentSessions.map(i=>e.jsxs("div",{className:"flex items-center justify-between text-xs p-1.5 rounded bg-muted/30 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex flex-col min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"font-medium truncate",title:i.projectPath,children:cs(i.projectPath)}),(i.target??"claude")!=="claude"&&e.jsx("span",{className:"shrink-0 px-1 py-0 text-[9px] font-medium rounded bg-purple-100 text-purple-700 dark:bg-purple-900/30 dark:text-purple-300 uppercase",children:i.target})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Y(new Date(i.lastActivity),{addSuffix:!0})})]}),e.jsxs("div",{className:c("text-right shrink-0 ml-2",n&&N),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[xs(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",r),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Q,{className:"w-4 h-4"}),"Session Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"No session data available"})})]})}function xs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toString()}function us({className:s,isLoading:t}){const{data:r,isLoading:n}=ye(),{data:l,isLoading:i,error:x}=Ne(r?.running);if(t||n||r?.running&&i)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx(h,{className:"h-4 w-[100px]"}),e.jsx(h,{className:"h-16 w-full"})]})})]});if(!r?.running)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4 text-muted-foreground"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"secondary",className:"text-[10px] h-5",children:"Offline"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 flex items-center justify-center",children:e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"Start a CLIProxy session (gemini, codex, agy) to collect stats."})})]});if(x)return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(I,{variant:"destructive",className:"text-[10px] h-5",children:"Error"})]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1",children:e.jsx("p",{className:"text-xs text-destructive",children:x.message})})]});const o=l?.totalRequests??0,d=l?.quotaExceededCount??0,u=o-d,m=o>0?Math.round(u/o*100):100,j=l?.tokens?.total??0,w=Object.entries(l?.requestsByModel??{}).sort((C,S)=>S[1]-C[1]).slice(0,4),v=w.length>0?w[0][1]:1;return e.jsxs(p,{className:c("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(y,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(I,{variant:"outline",className:"text-[10px] h-5 text-green-600 border-green-200 bg-green-50 dark:bg-green-900/10 dark:border-green-800",children:[e.jsx(ie,{className:"h-3 w-3 mr-0.5"}),"Running"]})]})}),e.jsx(g,{className:"p-0 flex-1 min-h-0",children:e.jsx(we,{className:"h-full",children:e.jsxs("div",{className:"p-3 space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsxs("div",{className:"relative",children:[e.jsxs("svg",{className:"w-10 h-10 -rotate-90",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",className:"text-muted/30"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeDasharray:`${m*.88} 88`,strokeLinecap:"round",className:m>=90?"text-green-500":"text-amber-500"})]}),e.jsxs("span",{className:"absolute inset-0 flex items-center justify-center text-[8px] font-bold",children:[m,"%"]})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(o)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:d>0?`${d} failed`:"All success"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 p-2 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"p-1.5 rounded-md bg-purple-100 dark:bg-purple-900/20",children:e.jsx(Te,{className:"h-4 w-4 text-purple-600"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-bold leading-none",children:J(j)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:"Total tokens"})]})]})]}),w.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-medium text-muted-foreground",children:[e.jsx(Fe,{className:"h-3 w-3"}),"Models Used"]}),e.jsx("div",{className:"space-y-1",children:w.map(([C,S])=>{const B=Math.round(S/v*100),A=ms(C);return e.jsxs("div",{className:"group",children:[e.jsxs("div",{className:"flex items-center justify-between text-[10px] mb-0.5",children:[e.jsx("span",{className:"truncate font-medium",title:C,children:A}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:S})]}),e.jsx("div",{className:"h-1 bg-muted/50 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-accent/70 rounded-full transition-all",style:{width:`${B}%`}})})]},C)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ms(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function hs(s){return s>=1e9?`${(s/1e9).toFixed(1)}B`:s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(0)}K`:s.toString()}function fs({models:s,isLoading:t,onModelClick:r,privacyMode:n}){return e.jsxs(p,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-4",children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4"}),"Cost by Model"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 overflow-y-auto",children:t?e.jsx(h,{className:"h-full w-full"}):e.jsxs("div",{className:"space-y-0.5",children:[[...s||[]].sort((l,i)=>i.cost-l.cost).map(l=>e.jsxs("button",{className:"group flex items-center text-xs w-full hover:bg-muted/50 rounded px-2 py-1.5 transition-colors cursor-pointer gap-3",onClick:i=>r(l,i),title:"Click for details",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0 w-[180px] shrink-0",children:[e.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:ae(l.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:l.model})]}),e.jsx(ps,{model:l}),e.jsx("span",{className:c("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&N),children:hs(l.tokens)}),e.jsxs("span",{className:c("font-mono font-medium w-16 text-right shrink-0",n&&N),children:["$",l.cost.toFixed(2)]}),e.jsx(Re,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},l.model)),e.jsx(gs,{})]})})]})}function ps({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},r=n=>s.cost>0?n/s.cost*100:0;return e.jsx("div",{className:"flex-1 flex items-center gap-1 min-w-0",children:e.jsxs("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden flex",children:[e.jsx("div",{className:"h-full",style:{backgroundColor:t.input,width:`${r(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${r(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${r(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${r(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function gs(){const s=[{color:"#335c67",label:"Input"},{color:"#fff3b0",label:"Output",hasBorder:!0},{color:"#e09f3e",label:"Cache Write"},{color:"#9e2a2b",label:"Cache Read"}];return e.jsx("div",{className:"flex items-center gap-3 pt-2 px-2 text-[10px] text-muted-foreground border-t mt-2",children:s.map(({color:t,label:r,hasBorder:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:c("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),r]},r))})}function js({viewMode:s,trends:t,hourlyData:r,models:n,sessions:l,isTrendsLoading:i,isHourlyLoading:x,isModelsLoading:a,isSessionsLoading:o,isSummaryLoading:d,onModelClick:u}){const{privacyMode:m}=M();return e.jsxs("div",{className:"min-h-0 grid gap-4 lg:grid-rows-[minmax(260px,1.2fr)_minmax(220px,0.9fr)]",children:[e.jsxs(p,{className:"flex flex-col h-full min-h-[220px] lg:min-h-[240px] overflow-hidden gap-0 py-0 shadow-sm",children:[e.jsx(y,{className:"px-3 py-2 shrink-0",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{className:"w-4 h-4"}),s==="hourly"?"Last 24 Hours":"Usage Trends"]})}),e.jsx(g,{className:"px-3 pb-3 pt-0 flex-1 min-h-0",children:e.jsx(ns,{data:s==="hourly"?r||[]:t||[],isLoading:s==="hourly"?x:i,granularity:s==="hourly"?"hourly":"daily"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-10 gap-4 h-auto min-h-[220px] lg:h-full lg:min-h-[220px] lg:grid-rows-[minmax(0,1fr)] lg:[&>*]:min-h-0",children:[e.jsx(fs,{models:n,isLoading:a,onModelClick:u,privacyMode:m}),e.jsxs(p,{className:"flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm lg:col-span-2",children:[e.jsx(y,{className:"px-3 py-2",children:e.jsxs(D,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Pe,{className:"w-4 h-4"}),"Model Usage"]})}),e.jsx(g,{className:"px-2 pb-2 pt-0 flex-1 min-h-0 flex items-center justify-center",children:e.jsx(is,{data:n||[],isLoading:a,className:"h-full w-full"})})]}),e.jsx(ds,{data:l,isLoading:o,className:"lg:col-span-2"}),e.jsx(us,{isLoading:d,className:"lg:col-span-2"})]})]})}function $s(){return e.jsxs("div",{className:"space-y-4 h-full overflow-hidden",children:[e.jsxs(p,{className:"flex flex-col min-h-[300px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-32"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsx(h,{className:"h-full w-full"})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{className:"p-4 pt-2",children:e.jsx("div",{className:"space-y-3",children:[1,2,3,4,5].map(s=>e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"w-2.5 h-2.5 rounded-full"}),e.jsx(h,{className:"h-3 w-24"})]}),e.jsx(h,{className:"h-3 w-16"})]},s))})})]}),e.jsxs(p,{className:"flex flex-col min-h-[250px]",children:[e.jsx(y,{className:"p-4 pb-2",children:e.jsx(h,{className:"h-4 w-28"})}),e.jsx(g,{className:"p-4 pt-0 flex-1",children:e.jsxs("div",{className:"flex w-full h-full items-center",children:[e.jsx("div",{className:"flex-1 flex justify-center",children:e.jsx(h,{className:"h-[180px] w-[180px] rounded-full"})}),e.jsx("div",{className:"w-[140px] shrink-0 pl-2 space-y-2",children:[1,2,3,4].map(s=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(h,{className:"w-2 h-2 rounded-full"}),e.jsx(h,{className:"h-3 w-20"})]},s))})]})})]})]})]})}function Ts(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:r,handleTodayClick:n,handleRefresh:l,isRefreshing:i,lastUpdatedText:x,viewMode:a,summary:o,isSummaryLoading:d,trends:u,hourlyData:m,models:j,sessions:w,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:S,isSessionsLoading:B,handleModelClick:A,selectedModel:U,popoverPosition:q,handlePopoverClose:_}=ts();return e.jsxs("div",{className:"grid h-full min-h-0 grid-rows-[auto_auto_minmax(0,1fr)] gap-4 overflow-y-auto px-4 py-4",children:[e.jsx(rs,{dateRange:t,onDateRangeChange:r,onTodayClick:n,onRefresh:l,isRefreshing:i,lastUpdatedText:x,viewMode:a}),e.jsx(Ge,{data:o,isLoading:d}),e.jsx(js,{viewMode:a,trends:u,hourlyData:m,models:j,sessions:w,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:S,isSessionsLoading:B,isSummaryLoading:d,onModelClick:A}),e.jsxs(se,{open:!!U,onOpenChange:O=>!O&&_(),children:[e.jsx(be,{asChild:!0,children:e.jsx("div",{ref:s,className:"fixed pointer-events-none",style:{left:q?.x??0,top:q?.y??0,width:1,height:1}})}),e.jsx(te,{className:"w-80 p-3",side:"top",align:"center",children:U&&e.jsx(We,{model:U})})]})]})}export{Ts as AnalyticsPage,$s as AnalyticsSkeleton};
|