@kaitranntt/ccs 7.69.1-dev.1 → 7.69.1-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/ui/assets/accounts-DN0lP-yj.js +1 -0
  2. package/dist/ui/assets/{alert-dialog-QyEXocpn.js → alert-dialog-BA39vaYL.js} +1 -1
  3. package/dist/ui/assets/api-D2cjf1H4.js +4 -0
  4. package/dist/ui/assets/{auth-section-BszF77uT.js → auth-section-BNX8_9MJ.js} +1 -1
  5. package/dist/ui/assets/{backups-section-D6RgaOx1.js → backups-section-Bt0FA5zl.js} +1 -1
  6. package/dist/ui/assets/channels-FaDUjf3Y.js +1 -0
  7. package/dist/ui/assets/{checkbox-Dzwkj_Pg.js → checkbox-DHF-UBrH.js} +1 -1
  8. package/dist/ui/assets/claude-extension-D-skBToQ.js +1 -0
  9. package/dist/ui/assets/cliproxy-CD7z-_q8.js +3 -0
  10. package/dist/ui/assets/cliproxy-ai-providers-QSOOqh8F.js +15 -0
  11. package/dist/ui/assets/cliproxy-control-panel-D9dLU28p.js +1 -0
  12. package/dist/ui/assets/codex-CHO5_hku.js +27 -0
  13. package/dist/ui/assets/confirm-dialog-BICDz_zm.js +1 -0
  14. package/dist/ui/assets/copilot-BnQrRCuJ.js +3 -0
  15. package/dist/ui/assets/{cursor-BrcDgu6X.js → cursor-CXopLKfC.js} +1 -1
  16. package/dist/ui/assets/droid-CLFg9ELE.js +2 -0
  17. package/dist/ui/assets/{globalenv-section-DoX37DqB.js → globalenv-section-NPjCcYBN.js} +1 -1
  18. package/dist/ui/assets/{health-D_gdcxnc.js → health-B_3JpCrY.js} +1 -1
  19. package/dist/ui/assets/index-B5Egq7qY.js +1 -0
  20. package/dist/ui/assets/index-BY2j-o67.js +1 -0
  21. package/dist/ui/assets/{index-CTGpqIx6.js → index-BcUkpsGj.js} +1 -1
  22. package/dist/ui/assets/{index-DoVPk3vW.js → index-BgGHTjTd.js} +1 -1
  23. package/dist/ui/assets/index-DNmWbKbN.js +72 -0
  24. package/dist/ui/assets/index-DZddoGfE.js +1 -0
  25. package/dist/ui/assets/logs-Bb1OVYeK.js +1 -0
  26. package/dist/ui/assets/{masked-input-C2H-Ax0Z.js → masked-input-b4-lEKNq.js} +1 -1
  27. package/dist/ui/assets/proxy-status-widget-s89zaj3X.js +1 -0
  28. package/dist/ui/assets/{raw-json-settings-editor-panel-WxTn7-hS.js → raw-json-settings-editor-panel-Dr_BNQwQ.js} +1 -1
  29. package/dist/ui/assets/{searchable-select-1zOULoec.js → searchable-select-FJPe_YWv.js} +1 -1
  30. package/dist/ui/assets/{separator-BCfZ54mZ.js → separator-DJ0ku_ak.js} +1 -1
  31. package/dist/ui/assets/{shared-DlTbnc9n.js → shared-DyQlJnbj.js} +1 -1
  32. package/dist/ui/assets/{table-Bx2cnkWN.js → table-6Yg65ZZH.js} +1 -1
  33. package/dist/ui/assets/{updates-SiZKOnUD.js → updates-DSCXb6Au.js} +1 -1
  34. package/dist/ui/index.html +1 -1
  35. package/lib/mcp/ccs-browser-server.cjs +119 -27
  36. package/package.json +1 -1
  37. package/dist/ui/assets/accounts-D9eEaNx9.js +0 -1
  38. package/dist/ui/assets/api-7vQe0xOg.js +0 -4
  39. package/dist/ui/assets/channels-B1vgnNJX.js +0 -1
  40. package/dist/ui/assets/claude-extension-CKO4bJ22.js +0 -1
  41. package/dist/ui/assets/cliproxy-ai-providers-CmbFYVoR.js +0 -15
  42. package/dist/ui/assets/cliproxy-control-panel-M8ZfUq3C.js +0 -1
  43. package/dist/ui/assets/cliproxy-kHd-oC5W.js +0 -3
  44. package/dist/ui/assets/codex-BJ0RdMuh.js +0 -27
  45. package/dist/ui/assets/confirm-dialog-BlSaX2gK.js +0 -1
  46. package/dist/ui/assets/copilot-NJKZQXQ_.js +0 -3
  47. package/dist/ui/assets/droid-B9u9ZB-a.js +0 -2
  48. package/dist/ui/assets/index-BNU4Hhe_.js +0 -1
  49. package/dist/ui/assets/index-DFEMq3KP.js +0 -1
  50. package/dist/ui/assets/index-DOn6k1jF.js +0 -72
  51. package/dist/ui/assets/index-h08p9xL5.js +0 -1
  52. package/dist/ui/assets/logs-DtH4YMt4.js +0 -1
  53. package/dist/ui/assets/proxy-status-widget-BOrsn86w.js +0 -1
@@ -1,27 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{r as b}from"./react-vendor-CNOkPC89.js";import{t as W}from"./notifications-B2HqRBj7.js";import{C as D,j as M,k as I,B as y,b as F,d as w,aF as B,r as _,s as E,t as P,v as O,w as v,I as C,n as xe,bb as J,bc as Te,c as _e,bi as Ge,bj as fe,bk as Ye,Q as Be,R as He,U as re,V as te,bd as je}from"./index-DOn6k1jF.js";import{aa as Qe,aR as Je,as as Z,L as X,n as Ze,aS as es,aT as ss,aB as rs,w as ts,a7 as ns,aU as as,aV as ls,aW as os,ah as de,p as ge,$ as is,m as cs,o as ds,_ as us,S as ms,aM as ve,aX as xs,x as hs,I as ps,T as fs,N as js}from"./icons-KVCk4_U8.js";import{S as Q}from"./separator-BCfZ54mZ.js";import{a as gs,u as be,b as we}from"./tanstack-CrmUhA7Z.js";import"./code-highlight-BRUf_pqB.js";import{T as vs,a as bs,b as Ne,c as ne,d as ws,e as ae}from"./table-Bx2cnkWN.js";import{R as Ns}from"./raw-json-settings-editor-panel-WxTn7-hS.js";import"./utils-CzKF5WmX.js";import"./form-utils-Bcoyqxpq.js";function H({title:s,icon:r,badge:t,description:a,disabledReason:n,children:l}){return e.jsxs(D,{children:[e.jsxs(M,{className:"pb-2",children:[e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[r,s,t?e.jsx(y,{variant:"outline",className:"text-[10px] font-normal",children:t}):null]}),a?e.jsx("p",{className:"text-xs text-muted-foreground",children:a}):null]}),e.jsxs(F,{className:"space-y-3",children:[n?e.jsx("p",{className:"text-xs text-amber-600",children:n}):null,l]})]})}function Cs({catalog:s,state:r,disabled:t=!1,disabledReason:a,onToggle:n}){const l=new Set(s.map(o=>o.name)),i=Object.entries(r).filter(([o])=>!l.has(o)).sort(([o],[d])=>o.localeCompare(d));return e.jsxs(H,{title:"Features",badge:"features",icon:e.jsx(Qe,{className:"h-4 w-4"}),description:"Toggle the supported Codex feature flags CCS can safely manage.",disabledReason:a,children:[e.jsx("div",{className:"space-y-2",children:s.map(o=>{const d=r[o.name]??null;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium",children:o.label}),e.jsx(y,{variant:"outline",className:"font-mono text-[10px]",children:o.name})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o.description})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d!==null?e.jsx(w,{variant:"outline",size:"sm",onClick:()=>n(o.name,null),disabled:t,children:"Use default"}):null,e.jsx(B,{checked:d===!0,onCheckedChange:c=>n(o.name,c),disabled:t})]})]},o.name)})}),i.length>0?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Existing config-only flags"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"These feature keys already exist in your `config.toml`, so CCS can surface them without claiming full catalog coverage."})]}),i.map(([o,d])=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-dashed px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"text-sm font-medium",children:o}),e.jsx(y,{variant:"secondary",className:"text-[10px]",children:"existing"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:d===null?"Stored in a non-boolean form. Use raw TOML if you need to edit it.":"Discovered from the current file instead of CCS's built-in catalog."})]}),d===null?e.jsx(y,{variant:"outline",children:"Raw only"}):e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{variant:"outline",size:"sm",onClick:()=>n(o,null),disabled:t,children:"Use default"}),e.jsx(B,{checked:d===!0,onCheckedChange:c=>n(o,c),disabled:t})]})]},o))]}):null]})}const ys={name:"",transport:"stdio",command:null,args:[],url:null,enabled:!0,required:!1,startupTimeoutSec:null,toolTimeoutSec:null,enabledTools:[],disabledTools:[]};function le(s){return s.join(", ")}function oe(s){return s.split(",").map(r=>r.trim()).filter(Boolean)}function Ss({initialDraft:s,isNew:r,disabled:t,saving:a,canDelete:n,onSave:l,onDelete:i}){const[o,d]=b.useState(s);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(C,{value:o.name,onChange:c=>d(u=>({...u,name:c.target.value})),placeholder:"playwright",disabled:t||!r}),e.jsxs(_,{value:o.transport,onValueChange:c=>d(u=>({...u,transport:c})),disabled:t,children:[e.jsx(E,{children:e.jsx(P,{})}),e.jsxs(O,{children:[e.jsx(v,{value:"stdio",children:"stdio"}),e.jsx(v,{value:"streamable-http",children:"streamable-http"})]})]}),o.transport==="stdio"?e.jsxs(e.Fragment,{children:[e.jsx(C,{value:o.command??"",onChange:c=>d(u=>({...u,command:c.target.value||null})),placeholder:"npx",disabled:t}),e.jsx(C,{value:le(o.args),onChange:c=>d(u=>({...u,args:oe(c.target.value)})),placeholder:"@playwright/mcp@latest, --flag",disabled:t})]}):e.jsx(C,{className:"sm:col-span-2",value:o.url??"",onChange:c=>d(u=>({...u,url:c.target.value||null})),placeholder:"https://example.test/mcp",disabled:t}),e.jsx(C,{type:"number",min:1,value:o.startupTimeoutSec??"",onChange:c=>d(u=>({...u,startupTimeoutSec:c.target.value?Number(c.target.value):null})),placeholder:"Startup timeout (sec)",disabled:t}),e.jsx(C,{type:"number",min:1,value:o.toolTimeoutSec??"",onChange:c=>d(u=>({...u,toolTimeoutSec:c.target.value?Number(c.target.value):null})),placeholder:"Tool timeout (sec)",disabled:t}),e.jsx(C,{value:le(o.enabledTools),onChange:c=>d(u=>({...u,enabledTools:oe(c.target.value)})),placeholder:"enabled_tools",disabled:t}),e.jsx(C,{value:le(o.disabledTools),onChange:c=>d(u=>({...u,disabledTools:oe(c.target.value)})),placeholder:"disabled_tools",disabled:t})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"flex items-center justify-between rounded-md border px-3 py-2 text-sm",children:["Enabled",e.jsx(B,{checked:o.enabled,onCheckedChange:c=>d(u=>({...u,enabled:c})),disabled:t})]}),e.jsxs("label",{className:"flex items-center justify-between rounded-md border px-3 py-2 text-sm",children:["Required",e.jsx(B,{checked:o.required,onCheckedChange:c=>d(u=>({...u,required:c})),disabled:t})]})]}),e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsxs(w,{variant:"outline",onClick:i,disabled:t||a||!n,children:[e.jsx(Z,{className:"mr-2 h-4 w-4"}),"Delete"]}),e.jsxs(w,{onClick:()=>l(o.name,{transport:o.transport,command:o.command,args:o.args,url:o.url,enabled:o.enabled,required:o.required,startupTimeoutSec:o.startupTimeoutSec,toolTimeoutSec:o.toolTimeoutSec,enabledTools:o.enabledTools,disabledTools:o.disabledTools}),disabled:t||a||o.name.trim().length===0,children:[a?e.jsx(X,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save MCP server"]})]})]})}function ks({entries:s,disabled:r=!1,disabledReason:t,saving:a=!1,onSave:n,onDelete:l}){const[i,o]=b.useState("new"),d=b.useMemo(()=>s.find(h=>h.name===i)??null,[s,i]),c=d??ys,u=JSON.stringify(c);return e.jsxs(H,{title:"MCP servers",badge:"mcp_servers",icon:e.jsx(Je,{className:"h-4 w-4"}),description:"Manage the safe MCP transport fields. Keep auth headers and bearer tokens in raw TOML.",disabledReason:t,children:[e.jsxs(_,{value:i,onValueChange:o,disabled:r,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Select MCP server"})}),e.jsxs(O,{children:[e.jsx(v,{value:"new",children:"Create new MCP server"}),s.map(h=>e.jsx(v,{value:h.name,children:h.name},h.name))]})]}),e.jsx(Ss,{initialDraft:c,isNew:i==="new",disabled:r,saving:a,canDelete:d!==null,onDelete:async()=>{d&&(await l(d.name),o("new"))},onSave:async(h,j)=>{await n(h,j),o(h)}},u)]})}const Ts={name:"",displayName:null,baseUrl:null,envKey:null,wireApi:"responses",requiresOpenaiAuth:!1,supportsWebsockets:!1},_s={name:"cliproxy",displayName:"CLIProxy Codex",baseUrl:"http://127.0.0.1:8317/api/provider/codex",envKey:"CLIPROXY_API_KEY",wireApi:"responses",requiresOpenaiAuth:!1,supportsWebsockets:!1};function Es({initialDraft:s,isNew:r,disabled:t,saving:a,canDelete:n,onSave:l,onDelete:i}){const[o,d]=b.useState(s);return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md border border-dashed px-3 py-2 text-xs text-muted-foreground",children:[e.jsxs("p",{children:["Quick start: apply the CLIProxy Codex preset here, then set"," ",e.jsx("strong",{children:"Default provider"})," to ",e.jsx("code",{children:"cliproxy"})," in Top-level settings."]}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>d(_s),disabled:t,children:"Use CLIProxy Codex preset"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(C,{value:o.name,onChange:c=>d(u=>({...u,name:c.target.value})),placeholder:"Provider id",disabled:t||!r}),e.jsx(C,{value:o.displayName??"",onChange:c=>d(u=>({...u,displayName:c.target.value||null})),placeholder:"Display name",disabled:t}),e.jsx(C,{value:o.baseUrl??"",onChange:c=>d(u=>({...u,baseUrl:c.target.value||null})),placeholder:"http://127.0.0.1:8317/api/provider/codex",disabled:t}),e.jsx(C,{value:o.envKey??"",onChange:c=>d(u=>({...u,envKey:c.target.value||null})),placeholder:"CLIPROXY_API_KEY",disabled:t})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs(_,{value:o.wireApi??"responses",onValueChange:c=>d(u=>({...u,wireApi:c})),disabled:t,children:[e.jsx(E,{children:e.jsx(P,{})}),e.jsx(O,{children:e.jsx(v,{value:"responses",children:"responses"})})]}),e.jsxs("label",{className:"flex items-center justify-between rounded-md border px-3 py-2 text-sm",children:["Requires OpenAI auth",e.jsx(B,{checked:o.requiresOpenaiAuth,onCheckedChange:c=>d(u=>({...u,requiresOpenaiAuth:c})),disabled:t})]}),e.jsxs("label",{className:"flex items-center justify-between rounded-md border px-3 py-2 text-sm",children:["Supports websockets",e.jsx(B,{checked:o.supportsWebsockets,onCheckedChange:c=>d(u=>({...u,supportsWebsockets:c})),disabled:t})]})]}),e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsxs(w,{variant:"outline",onClick:i,disabled:t||a||!n,children:[e.jsx(Z,{className:"mr-2 h-4 w-4"}),"Delete"]}),e.jsxs(w,{onClick:()=>l(o.name,{displayName:o.displayName,baseUrl:o.baseUrl,envKey:o.envKey,wireApi:o.wireApi,requiresOpenaiAuth:o.requiresOpenaiAuth,supportsWebsockets:o.supportsWebsockets}),disabled:t||a||o.name.trim().length===0,children:[a?e.jsx(X,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save provider"]})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["If you want plain native ",e.jsx("code",{children:"codex"})," to default to CLIProxy, save a provider named"," ",e.jsx("code",{children:"cliproxy"})," with ",e.jsx("code",{children:"CLIPROXY_API_KEY"})," here, then pick"," ",e.jsx("code",{children:"cliproxy"})," in the ",e.jsx("strong",{children:"Default provider"})," control above."]})]})}function Ps({entries:s,disabled:r=!1,disabledReason:t,saving:a=!1,onSave:n,onDelete:l}){const[i,o]=b.useState("new"),d=b.useMemo(()=>s.find(h=>h.name===i)??null,[s,i]),c=d??Ts,u=JSON.stringify(c);return e.jsxs(H,{title:"Model providers",badge:"model_providers",icon:e.jsx(Ze,{className:"h-4 w-4"}),description:"Edit the common provider fields CCS can support safely. Keep secret migration and inline bearer tokens in raw TOML.",disabledReason:t,children:[e.jsxs(_,{value:i,onValueChange:o,disabled:r,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Select provider"})}),e.jsxs(O,{children:[e.jsx(v,{value:"new",children:"Create new provider"}),s.map(h=>e.jsx(v,{value:h.name,children:h.name},h.name))]})]}),e.jsx(Es,{initialDraft:c,isNew:i==="new",disabled:r,saving:a,canDelete:d!==null,onDelete:async()=>{d&&(await l(d.name),o("new"))},onSave:async(h,j)=>{await n(h,j),o(h)}},u)]})}function Os({initialName:s,initialModel:r,initialProvider:t,initialEffort:a,providerNames:n,activeProfile:l,selectedEntryName:i,disabled:o,saving:d,onSave:c,onDelete:u,onSetActive:h}){const[j,x]=b.useState(s),[g,A]=b.useState(r),[U,m]=b.useState(t),[f,T]=b.useState(a);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(C,{value:j,onChange:N=>x(N.target.value),placeholder:"deep-review",disabled:o||i!==null}),e.jsx(C,{value:g??"",onChange:N=>A(N.target.value||null),placeholder:"gpt-5.4",disabled:o}),e.jsxs(_,{value:U??"__unset__",onValueChange:N=>m(N==="__unset__"?null:N),disabled:o,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Use global provider"})}),e.jsxs(O,{children:[e.jsx(v,{value:"__unset__",children:"Use global provider"}),n.map(N=>e.jsx(v,{value:N,children:N},N))]})]}),e.jsxs(_,{value:f??"__unset__",onValueChange:N=>T(N==="__unset__"?null:N),disabled:o,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Use global effort"})}),e.jsxs(O,{children:[e.jsx(v,{value:"__unset__",children:"Use global effort"}),["minimal","low","medium","high","xhigh"].map(N=>e.jsx(v,{value:N,children:N},N))]})]})]}),e.jsxs("div",{className:"flex justify-between gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{variant:"outline",onClick:u,disabled:o||d||!i,children:[e.jsx(Z,{className:"mr-2 h-4 w-4"}),"Delete"]}),e.jsx(w,{variant:"outline",onClick:h,disabled:o||d||!i||i===l,children:"Set active"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(w,{variant:"outline",onClick:()=>c(j,{model:g,modelProvider:U,modelReasoningEffort:f},!1),disabled:o||d||j.trim().length===0,children:[d?e.jsx(X,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save profile"]}),e.jsxs(w,{onClick:()=>c(j,{model:g,modelProvider:U,modelReasoningEffort:f},!0),disabled:o||d||j.trim().length===0,children:[d?e.jsx(X,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save + activate"]})]})]})]})}function Ls({activeProfile:s,entries:r,providerNames:t,disabled:a=!1,disabledReason:n,saving:l=!1,onSave:i,onDelete:o,onSetActive:d}){const[c,u]=b.useState("new"),h=b.useMemo(()=>r.find(x=>x.name===c)??null,[r,c]),j=JSON.stringify(h??{name:"",values:{}});return e.jsxs(H,{title:"Profiles",badge:"profiles",icon:e.jsx(es,{className:"h-4 w-4"}),description:"Create reusable Codex overlays and set the active default profile.",disabledReason:n,children:[e.jsxs(_,{value:c,onValueChange:u,disabled:a,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Select profile"})}),e.jsxs(O,{children:[e.jsx(v,{value:"new",children:"Create new profile"}),r.map(x=>e.jsxs(v,{value:x.name,children:[x.name,x.name===s?" (active)":""]},x.name))]})]}),e.jsx(Os,{initialName:h?.name??"",initialModel:h?.values.model??null,initialProvider:h?.values.modelProvider??null,initialEffort:h?.values.modelReasoningEffort??null,providerNames:t,activeProfile:s,selectedEntryName:h?.name??null,disabled:a,saving:l,onDelete:async()=>{h&&(await o(h.name),u("new"))},onSetActive:async()=>{h&&await d(h.name)},onSave:async(x,g,A)=>{await i(x,g,A),u(x)}},j)]})}function As({workspacePath:s,disabled:r,saving:t,onSave:a}){const[n,l]=b.useState(s),[i,o]=b.useState("trusted");return e.jsxs("div",{className:"grid gap-2 sm:grid-cols-[1fr_160px_auto]",children:[e.jsx(C,{value:n,onChange:d=>l(d.target.value),placeholder:"~/repo or /absolute/path",disabled:r}),e.jsxs(_,{value:i,onValueChange:o,disabled:r,children:[e.jsx(E,{children:e.jsx(P,{})}),e.jsxs(O,{children:[e.jsx(v,{value:"trusted",children:"trusted"}),e.jsx(v,{value:"untrusted",children:"untrusted"})]})]}),e.jsxs(w,{onClick:()=>a(n,i),disabled:r||t,children:[t?e.jsx(X,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save trust"]})]})}function Rs({workspacePath:s,entries:r,disabled:t=!1,disabledReason:a,saving:n=!1,onSave:l}){return e.jsxs(H,{title:"Project trust",badge:"projects",icon:e.jsx(ss,{className:"h-4 w-4"}),description:"Trust current workspaces or remove stale trust entries without opening raw TOML.",disabledReason:a,children:[e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Paths must be absolute or start with ",e.jsx("code",{children:"~/"}),". Relative paths are rejected so CCS does not trust the wrong folder."]}),e.jsx(As,{workspacePath:s,disabled:t,saving:n,onSave:l},s),e.jsx(w,{variant:"outline",className:"w-full justify-start",onClick:()=>l(s,"trusted"),disabled:t||n,children:"Trust current workspace"}),e.jsx("div",{className:"space-y-2",children:r.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:"No explicit project trust entries saved."}):r.map(i=>e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border px-3 py-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate text-sm font-medium",children:i.path}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["trust_level = ",i.trustLevel]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>l(i.path,i.trustLevel==="trusted"?"untrusted":"trusted"),disabled:t||n,children:"Toggle"}),e.jsx(w,{variant:"ghost",size:"icon",onClick:()=>l(i.path,null),disabled:t||n,children:e.jsx(Z,{className:"h-4 w-4"})})]})]},i.path))})]})}const L="__unset__",Ds=105e4,Ms=272e3,Ce=8e5,ye=7e5,Is=new Intl.NumberFormat("en-US");function z(s){return s??L}function $(s,r){return r&&!s.includes(r)?[r,...s]:s}function ie(s){return Is.format(s)}function Fs(s){return s?.trim().toLowerCase().startsWith("gpt-5.4")??!1}function Us(s,r){const t={};return r.model!==s.model&&(t.model=r.model),r.modelReasoningEffort!==s.modelReasoningEffort&&(t.modelReasoningEffort=r.modelReasoningEffort),r.modelContextWindow!==s.modelContextWindow&&(t.modelContextWindow=r.modelContextWindow),r.modelAutoCompactTokenLimit!==s.modelAutoCompactTokenLimit&&(t.modelAutoCompactTokenLimit=r.modelAutoCompactTokenLimit),r.modelProvider!==s.modelProvider&&(t.modelProvider=r.modelProvider),r.approvalPolicy!==s.approvalPolicy&&(t.approvalPolicy=r.approvalPolicy),r.sandboxMode!==s.sandboxMode&&(t.sandboxMode=r.sandboxMode),r.webSearch!==s.webSearch&&(t.webSearch=r.webSearch),r.toolOutputTokenLimit!==s.toolOutputTokenLimit&&(t.toolOutputTokenLimit=r.toolOutputTokenLimit),r.personality!==s.personality&&(t.personality=r.personality),t}function Ws({initialValues:s,providerNames:r,disabled:t,saving:a,onSave:n}){const[l,i]=b.useState(s),o=$(["minimal","low","medium","high","xhigh"],l.modelReasoningEffort),d=$(r,l.modelProvider),c=$(["on-request","never","untrusted"],l.approvalPolicy),u=$(["read-only","workspace-write","danger-full-access"],l.sandboxMode),h=$(["cached","live","disabled"],l.webSearch),j=$(["none","friendly","pragmatic"],l.personality),x=Us(s,l),g=Object.keys(x).length>0,A=Fs(l.model),U=m=>{const f=m.trim();return f.length>0?Number(f):null};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Model"}),e.jsx(C,{value:l.model??"",onChange:m=>i(f=>({...f,model:m.target.value||null})),placeholder:"gpt-5.4",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Reasoning effort"}),e.jsxs(_,{value:z(l.modelReasoningEffort),onValueChange:m=>i(f=>({...f,modelReasoningEffort:m===L?null:m})),disabled:t,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Use default"})}),e.jsxs(O,{children:[e.jsx(v,{value:L,children:"Use default"}),o.map(m=>e.jsx(v,{value:m,children:m},m))]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Default provider"}),e.jsxs(_,{value:z(l.modelProvider),onValueChange:m=>i(f=>({...f,modelProvider:m===L?null:m})),disabled:t,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Use Codex default"})}),e.jsxs(O,{children:[e.jsx(v,{value:L,children:"Use Codex default"}),d.map(m=>e.jsx(v,{value:m,children:m},m))]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Approval policy"}),e.jsxs(_,{value:z(l.approvalPolicy),onValueChange:m=>i(f=>({...f,approvalPolicy:m===L?null:m})),disabled:t,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Use default"})}),e.jsxs(O,{children:[e.jsx(v,{value:L,children:"Use default"}),c.map(m=>e.jsx(v,{value:m,children:m},m))]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Sandbox mode"}),e.jsxs(_,{value:z(l.sandboxMode),onValueChange:m=>i(f=>({...f,sandboxMode:m===L?null:m})),disabled:t,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Use default"})}),e.jsxs(O,{children:[e.jsx(v,{value:L,children:"Use default"}),u.map(m=>e.jsx(v,{value:m,children:m},m))]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Web search"}),e.jsxs(_,{value:z(l.webSearch),onValueChange:m=>i(f=>({...f,webSearch:m===L?null:m})),disabled:t,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Use default"})}),e.jsxs(O,{children:[e.jsx(v,{value:L,children:"Use default"}),h.map(m=>e.jsx(v,{value:m,children:m},m))]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Tool output token limit"}),e.jsx(C,{type:"number",min:1,value:l.toolOutputTokenLimit??"",onChange:m=>i(f=>({...f,toolOutputTokenLimit:m.target.value?Number(m.target.value):null})),placeholder:"25000",disabled:t})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Personality"}),e.jsxs(_,{value:z(l.personality),onValueChange:m=>i(f=>({...f,personality:m===L?null:m})),disabled:t,children:[e.jsx(E,{children:e.jsx(P,{placeholder:"Use default"})}),e.jsxs(O,{children:[e.jsx(v,{value:L,children:"Use default"}),j.map(m=>e.jsx(v,{value:m,children:m},m))]})]})]})]}),e.jsxs("div",{className:"space-y-4 rounded-xl border border-amber-500/30 bg-amber-500/5 p-4 shadow-sm dark:bg-amber-400/5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ts,{className:"h-4 w-4 text-amber-600 dark:text-amber-300"}),e.jsx("p",{className:"text-sm font-semibold",children:"Long context override"}),e.jsx(y,{variant:"outline",className:"border-amber-500/40 bg-background/80 text-[10px] uppercase tracking-[0.16em] text-amber-700 dark:text-amber-300",children:"Manual opt-in only"}),e.jsx(y,{variant:"secondary",className:"text-[10px] uppercase tracking-[0.16em] text-muted-foreground",children:A?"GPT-5.4 selected":"GPT-5.4 reference"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Draft values only. Nothing applies until Save."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(w,{type:"button",variant:"outline",size:"sm",disabled:t,onClick:()=>i(m=>({...m,modelContextWindow:Ce,modelAutoCompactTokenLimit:ye})),children:"Fill cautious pair"}),e.jsx(w,{type:"button",variant:"outline",size:"sm",disabled:t,onClick:()=>i(m=>({...m,modelContextWindow:Ds})),children:"Set official max window"}),e.jsx(w,{type:"button",variant:"ghost",size:"sm",disabled:t,onClick:()=>i(m=>({...m,modelContextWindow:null,modelAutoCompactTokenLimit:null})),children:"Clear"})]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-lg border bg-background/85 px-3 py-3 shadow-sm shadow-black/5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:"Official max"}),e.jsx("p",{className:"mt-1 font-mono text-base font-semibold text-foreground",children:"1.05M / 1M"}),e.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"GPT-5.4 context cap"})]}),e.jsxs("div",{className:"rounded-lg border bg-background/85 px-3 py-3 shadow-sm shadow-black/5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:"Standard window"}),e.jsx("p",{className:"mt-1 font-mono text-base font-semibold text-foreground",children:ie(Ms)}),e.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"Normal usage window"})]}),e.jsxs("div",{className:"rounded-lg border bg-background/85 px-3 py-3 shadow-sm shadow-black/5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:"Above 272K"}),e.jsx("p",{className:"mt-1 font-mono text-base font-semibold text-foreground",children:"Counts 2x"}),e.jsx("p",{className:"mt-1 text-[11px] text-muted-foreground",children:"Usage-limit cost above 272K"})]})]}),e.jsxs("div",{className:"space-y-3 rounded-lg border bg-background/75 px-3 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wide text-muted-foreground",children:"One cautious pair"}),e.jsxs("div",{className:"rounded-full border bg-background px-2.5 py-1 font-mono text-[11px] font-medium",children:["Context ",ie(Ce)]}),e.jsxs("div",{className:"rounded-full border bg-background px-2.5 py-1 font-mono text-[11px] font-medium",children:["Auto-compact ",ie(ye)]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(y,{variant:"outline",className:"border-border/70 bg-background/80 text-[10px] uppercase tracking-[0.14em] text-muted-foreground",children:"Not official"}),e.jsx(y,{variant:"outline",className:"border-border/70 bg-background/80 text-[10px] uppercase tracking-[0.14em] text-muted-foreground",children:"Draft only"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:"Quick-fill only. Review before saving."}),!A&&l.model?e.jsxs("span",{children:[e.jsx("code",{children:l.model})," should be checked separately."]}):null]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Model context window"}),e.jsx(C,{"aria-label":"Model context window",type:"number",min:1,value:l.modelContextWindow??"",onChange:m=>i(f=>({...f,modelContextWindow:U(m.target.value)})),placeholder:"Unset",disabled:t}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Writes ",e.jsx("code",{children:"model_context_window"}),". Leave unset to keep Codex defaults."]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Auto-compact token limit"}),e.jsx(C,{"aria-label":"Auto-compact token limit",type:"number",min:1,value:l.modelAutoCompactTokenLimit??"",onChange:m=>i(f=>({...f,modelAutoCompactTokenLimit:U(m.target.value)})),placeholder:"Unset",disabled:t}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Writes ",e.jsx("code",{children:"model_auto_compact_token_limit"}),". Leave unset to keep model defaults."]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.14em]",children:"Docs"}),e.jsx("a",{href:"https://developers.openai.com/api/docs/models/gpt-5.4",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"GPT-5.4 model page"}),e.jsx("a",{href:"https://openai.com/index/introducing-gpt-5-4/",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Release notes"}),e.jsx("a",{href:"https://developers.openai.com/codex/config-reference",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Config reference"})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(w,{onClick:()=>n(x),disabled:t||a||!g,children:[a?e.jsx(X,{className:"mr-2 h-4 w-4 animate-spin"}):null,"Save top-level settings"]})})]})}function Ks({values:s,providerNames:r,disabled:t=!1,disabledReason:a,saving:n=!1,onSave:l}){return e.jsx(H,{title:"Top-level controls",badge:"config.toml",icon:e.jsx(rs,{className:"h-4 w-4"}),description:"Structured controls for the stable top-level Codex settings users touch most often. Unsupported upstream shapes stay untouched and should be edited in raw TOML.",disabledReason:a,children:e.jsx(Ws,{initialValues:s,providerNames:r,disabled:t,saving:n,onSave:l},JSON.stringify(s))})}function qs({workspacePath:s,activeProfile:r,topLevelSettings:t,projectTrustEntries:a,profileEntries:n,modelProviderEntries:l,mcpServerEntries:i,featureCatalog:o,featureState:d,disabled:c,disabledReason:u,saving:h,onPatch:j}){return e.jsx(xe,{className:"h-full",children:e.jsxs("div",{className:"space-y-6 pr-1 pb-6",children:[e.jsxs("div",{className:"group relative overflow-hidden rounded-xl border border-border/80 bg-background/50 p-5 shadow-sm transition-all hover:bg-background hover:shadow-md dark:border-border/60",children:[e.jsx("div",{className:"absolute inset-x-0 -top-px h-px bg-gradient-to-r from-transparent via-foreground/15 to-transparent transition-opacity group-hover:via-foreground/30"}),e.jsxs("div",{className:"flex flex-col gap-6 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg border border-primary/20 bg-primary/10 text-primary transition-colors group-hover:border-primary/30",children:e.jsx(ns,{className:"h-4 w-4"})}),e.jsx("div",{children:e.jsx("h2",{className:"text-base font-semibold tracking-tight text-foreground",children:"Structured controls boundary"})})]}),e.jsxs("ul",{className:"grid gap-3 sm:grid-cols-2 text-sm text-muted-foreground",children:[e.jsxs("li",{className:"flex items-start gap-2.5",children:[e.jsx(as,{className:"h-4 w-4 shrink-0 text-muted-foreground/60 mt-0.5"}),e.jsxs("span",{className:"leading-relaxed",children:["Writes exclusively to user-layer"," ",e.jsx("code",{className:"text-[11px] bg-muted/70 px-1.5 py-0.5 rounded border border-border/50",children:"config.toml"})]})]}),e.jsxs("li",{className:"flex items-start gap-2.5",children:[e.jsx(ls,{className:"h-4 w-4 shrink-0 text-muted-foreground/60 mt-0.5"}),e.jsx("span",{className:"leading-relaxed",children:"Does not reflect repo trust layers or CLI overrides"})]})]})]}),e.jsx("div",{className:"shrink-0 lg:w-[280px]",children:e.jsx("div",{className:"relative overflow-hidden rounded-lg border border-amber-500/20 bg-amber-500/5 p-4 transition-colors group-hover:border-amber-500/30 group-hover:bg-amber-500/10 dark:border-amber-400/10 dark:bg-amber-400/5",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(os,{className:"mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-400"}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-bold text-amber-700 dark:text-amber-300 uppercase tracking-wider",children:"Formatting Note"}),e.jsx("p",{className:"text-[13px] leading-relaxed text-amber-800/80 dark:text-amber-200/70",children:"Saves normalize TOML formatting and strip comments. Switch to the raw editor if exact layout matters."})]})]})})})]})]}),e.jsx(Ks,{values:t,providerNames:l.map(x=>x.name),disabled:c,disabledReason:u,saving:h,onSave:x=>j({kind:"top-level",values:x},"Saved top-level Codex settings.")}),e.jsx(Rs,{workspacePath:s,entries:a,disabled:c,disabledReason:u,saving:h,onSave:(x,g)=>j({kind:"project-trust",path:x,trustLevel:g},g?"Saved project trust entry.":"Removed project trust entry.")}),e.jsx(Ls,{activeProfile:r,entries:n,providerNames:l.map(x=>x.name),disabled:c,disabledReason:u,saving:h,onSave:(x,g,A)=>j({kind:"profile",action:"upsert",name:x,values:g,setAsActive:A},"Saved profile."),onDelete:x=>j({kind:"profile",action:"delete",name:x},"Deleted profile."),onSetActive:x=>j({kind:"profile",action:"set-active",name:x},"Set active profile.")}),e.jsx(Ps,{entries:l,disabled:c,disabledReason:u,saving:h,onSave:(x,g)=>j({kind:"model-provider",action:"upsert",name:x,values:g},"Saved model provider."),onDelete:x=>j({kind:"model-provider",action:"delete",name:x},"Deleted model provider.")}),e.jsx(ks,{entries:i,disabled:c,disabledReason:u,saving:h,onSave:(x,g)=>j({kind:"mcp-server",action:"upsert",name:x,values:g},"Saved MCP server."),onDelete:x=>j({kind:"mcp-server",action:"delete",name:x},"Deleted MCP server.")}),e.jsx(Cs,{catalog:o,state:d,disabled:c,disabledReason:u,onToggle:(x,g)=>j({kind:"feature",feature:x,enabled:g},"Saved feature toggle.")})]})})}const Ee=`model_provider = "cliproxy"
2
-
3
- [model_providers.cliproxy]
4
- base_url = "http://127.0.0.1:8317/api/provider/codex"
5
- env_key = "CLIPROXY_API_KEY"
6
- wire_api = "responses"`,Pe=[{name:"multi_agent",label:"Multi-agent",description:"Enable subagent collaboration tools."},{name:"unified_exec",label:"Unified exec",description:"Use the PTY-backed unified exec tool."},{name:"shell_snapshot",label:"Shell snapshot",description:"Reuse shell environment snapshots."},{name:"apply_patch_freeform",label:"Apply patch",description:"Enable freeform apply_patch edits."},{name:"js_repl",label:"JS REPL",description:"Enable the Node-backed JavaScript REPL."},{name:"runtime_metrics",label:"Runtime metrics",description:"Collect Codex runtime metrics."},{name:"prevent_idle_sleep",label:"Prevent idle sleep",description:"Keep the machine awake while active."},{name:"fast_mode",label:"Fast mode",description:"Allow the fast service tier path."},{name:"apps",label:"Apps",description:"Enable ChatGPT Apps and connectors support."},{name:"smart_approvals",label:"Smart approvals",description:"Route eligible approvals through the guardian flow."}];function q(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)?s:null}function k(s){return typeof s=="string"&&s.trim().length>0?s.trim():null}function Y(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function ce(s){return Array.isArray(s)?s.filter(r=>typeof r=="string").map(r=>r.trim()):[]}function Oe(s){return{model:k(s?.model),modelReasoningEffort:k(s?.model_reasoning_effort),modelContextWindow:Y(s?.model_context_window),modelAutoCompactTokenLimit:Y(s?.model_auto_compact_token_limit),modelProvider:k(s?.model_provider),approvalPolicy:k(s?.approval_policy),sandboxMode:k(s?.sandbox_mode),webSearch:k(s?.web_search),toolOutputTokenLimit:Y(s?.tool_output_token_limit),personality:k(s?.personality)}}function Vs(s){const r=q(s?.projects);return r?Object.entries(r).map(([t,a])=>{const n=k(q(a)?.trust_level);return n?{path:t,trustLevel:n}:null}).filter(t=>t!==null).sort((t,a)=>t.path.localeCompare(a.path)):[]}function Xs(s){const r=q(s?.profiles);return r?Object.entries(r).map(([t,a])=>({name:t,values:Oe(q(a))})).sort((t,a)=>t.name.localeCompare(a.name)):[]}function zs(s){const r=q(s?.model_providers);return r?Object.entries(r).map(([t,a])=>{const n=q(a);return n?{name:t,displayName:k(n.name),baseUrl:k(n.base_url),envKey:k(n.env_key),wireApi:k(n.wire_api),requiresOpenaiAuth:n.requires_openai_auth===!0,supportsWebsockets:n.supports_websockets===!0}:null}).filter(t=>t!==null).sort((t,a)=>t.name.localeCompare(a.name)):[]}function $s(s){const r=q(s?.mcp_servers);return r?Object.entries(r).map(([t,a])=>{const n=q(a);if(!n)return null;const l=k(n.command)?"stdio":"streamable-http",i=Y(n.startup_timeout_ms);return{name:t,transport:l,command:k(n.command),args:ce(n.args),url:k(n.url),enabled:n.enabled!==!1,required:n.required===!0,startupTimeoutSec:Y(n.startup_timeout_sec)??(i!==null?i/1e3:null),toolTimeoutSec:Y(n.tool_timeout_sec),enabledTools:ce(n.enabled_tools),disabledTools:ce(n.disabled_tools)}}).filter(t=>t!==null).sort((t,a)=>t.name.localeCompare(a.name)):[]}function Gs(s){const r=q(s?.features),t={};for(const a of Pe){const n=r?.[a.name];t[a.name]=typeof n=="boolean"?n:null}if(r)for(const[a,n]of Object.entries(r))a in t||(t[a]=typeof n=="boolean"?n:null);return t}const Ys=[{id:"codex-config-basic",label:"Codex Config Basics",url:"https://developers.openai.com/codex/config-basic",description:"Official user-layer setup, config location, and baseline configuration behavior."},{id:"codex-config-advanced",label:"Codex Config Advanced",url:"https://developers.openai.com/codex/config-advanced",description:"Layering, trust, profiles, and advanced config behavior."},{id:"codex-config-reference",label:"Codex Config Reference",url:"https://developers.openai.com/codex/config-reference",description:"Canonical upstream config surface for providers, MCP, features, and trust."},{id:"codex-releases",label:"Codex GitHub Releases",url:"https://github.com/openai/codex/releases",description:"Track upstream release notes and fast-moving CLI changes."}],Bs=[{provider:"openai",label:"OpenAI Responses API",apiFormat:"Responses API",url:"https://platform.openai.com/docs/api-reference/responses"}];function Hs(s){const r=/https?:\/\/[^\s)]+/g,t=[];let a=0,n;for(;(n=r.exec(s))!==null;){const[l]=n,i=n.index;i>a&&t.push(s.slice(a,i)),t.push(e.jsx("a",{href:l,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:l},`${l}-${i}`)),a=i+l.length}return a<s.length&&t.push(s.slice(a)),t.length>0?t:[s]}function Qs({diagnostics:s}){const r=s.docsReference??{notes:[],links:[],providerDocs:[],providerValues:[],settingsHierarchy:[]},t=r.links.length>0?r.links:Ys,a=r.providerDocs.length>0?r.providerDocs:Bs;return e.jsx(xe,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(de,{className:"h-4 w-4"}),"CCS bridge recipe"]})}),e.jsxs(F,{className:"space-y-3 text-sm text-muted-foreground",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Built-in:"})," Use ",e.jsx("code",{children:"ccsxp"})," for the CCS provider shortcut."]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Native:"})," Configure the recipe below to use CLIProxy directly with"," ",e.jsx("code",{children:"codex"}),"."]})]}),e.jsx("pre",{className:"overflow-x-auto rounded-md border bg-muted/20 p-3 text-xs text-foreground",children:Ee}),e.jsxs("ol",{className:"ml-4 list-decimal space-y-1.5 [&>li]:pl-1",children:[e.jsxs("li",{children:["Save the ",e.jsx("code",{children:"cliproxy"})," provider in your user config."]}),e.jsxs("li",{children:["Set top-level ",e.jsx("code",{children:"model_provider"})," to ",e.jsx("code",{children:"cliproxy"}),"."]}),e.jsxs("li",{children:["Export ",e.jsx("code",{children:"CLIPROXY_API_KEY"})," before launching native Codex."]})]})]})]}),e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(de,{className:"h-4 w-4"}),"Upstream notes"]})}),e.jsxs(F,{className:"space-y-2 text-sm",children:[r.notes.length>0&&e.jsx("ul",{className:"ml-4 list-disc space-y-1.5 text-muted-foreground [&>li]:pl-1",children:r.notes.map((n,l)=>e.jsx("li",{children:Hs(n)},`${l}-${n}`))}),e.jsx(Q,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Codex docs"}),e.jsx("div",{className:"space-y-1.5",children:t.map(n=>e.jsxs("a",{href:n.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:n.label}),e.jsx(ge,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:n.description}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:n.url})]},n.id))})]}),e.jsx(Q,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"Provider / bridge reference"}),e.jsx("div",{className:"space-y-1.5",children:a.map(n=>e.jsxs("a",{href:n.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:n.label}),e.jsx(ge,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["provider: ",n.provider," | format: ",n.apiFormat]}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:n.url})]},`${n.provider}-${n.url}`))})]}),r.providerValues.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Provider values: ",r.providerValues.join(", ")]})]}),r.settingsHierarchy.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Settings hierarchy: ",r.settingsHierarchy.join(" -> ")]})]})]})]})})}function Js(s,r){let t=s.slice(0,r).split(/\r\n|\n|\r/g);return[t.length,t.pop().length+1]}function Zs(s,r,t){let a=s.split(/\r\n|\n|\r/g),n="",l=(Math.log10(r+1)|0)+1;for(let i=r-1;i<=r+1;i++){let o=a[i-1];o&&(n+=i.toString().padEnd(l," "),n+=": ",n+=o,n+=`
7
- `,i===r&&(n+=" ".repeat(l+t+2),n+=`^
8
- `))}return n}class p extends Error{line;column;codeblock;constructor(r,t){const[a,n]=Js(t.toml,t.ptr),l=Zs(t.toml,a,n);super(`Invalid TOML document: ${r}
9
-
10
- ${l}`,t),this.line=a,this.column=n,this.codeblock=l}}function er(s,r){let t=0;for(;s[r-++t]==="\\";);return--t&&t%2}function ue(s,r=0,t=s.length){let a=s.indexOf(`
11
- `,r);return s[a-1]==="\r"&&a--,a<=t?a:-1}function ee(s,r){for(let t=r;t<s.length;t++){let a=s[t];if(a===`
12
- `)return t;if(a==="\r"&&s[t+1]===`
13
- `)return t+1;if(a<" "&&a!==" "||a==="")throw new p("control characters are not allowed in comments",{toml:s,ptr:r})}return s.length}function K(s,r,t,a){let n;for(;;){for(;(n=s[r])===" "||n===" "||!t&&(n===`
14
- `||n==="\r"&&s[r+1]===`
15
- `);)r++;if(a||n!=="#")break;r=ee(s,r)}return r}function sr(s,r,t,a,n=!1){if(!a)return r=ue(s,r),r<0?s.length:r;for(let l=r;l<s.length;l++){let i=s[l];if(i==="#")l=ue(s,l);else{if(i===t)return l+1;if(i===a||n&&(i===`
16
- `||i==="\r"&&s[l+1]===`
17
- `))return l}}throw new p("cannot find end of structure",{toml:s,ptr:r})}function Le(s,r){let t=s[r],a=t===s[r+1]&&s[r+1]===s[r+2]?s.slice(r,r+3):t;r+=a.length-1;do r=s.indexOf(a,++r);while(r>-1&&t!=="'"&&er(s,r));return r>-1&&(r+=a.length,a.length>1&&(s[r]===t&&r++,s[r]===t&&r++)),r}let rr=/^(\d{4}-\d{2}-\d{2})?[T ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|[-+]\d{2}:\d{2})?$/i;class G extends Date{#s=!1;#r=!1;#e=null;constructor(r){let t=!0,a=!0,n="Z";if(typeof r=="string"){let l=r.match(rr);l?(l[1]||(t=!1,r=`0000-01-01T${r}`),a=!!l[2],a&&r[10]===" "&&(r=r.replace(" ","T")),l[2]&&+l[2]>23?r="":(n=l[3]||null,r=r.toUpperCase(),!n&&a&&(r+="Z"))):r=""}super(r),isNaN(this.getTime())||(this.#s=t,this.#r=a,this.#e=n)}isDateTime(){return this.#s&&this.#r}isLocal(){return!this.#s||!this.#r||!this.#e}isDate(){return this.#s&&!this.#r}isTime(){return this.#r&&!this.#s}isValid(){return this.#s||this.#r}toISOString(){let r=super.toISOString();if(this.isDate())return r.slice(0,10);if(this.isTime())return r.slice(11,23);if(this.#e===null)return r.slice(0,-1);if(this.#e==="Z")return r;let t=+this.#e.slice(1,3)*60+ +this.#e.slice(4,6);return t=this.#e[0]==="-"?t:-t,new Date(this.getTime()-t*6e4).toISOString().slice(0,-1)+this.#e}static wrapAsOffsetDateTime(r,t="Z"){let a=new G(r);return a.#e=t,a}static wrapAsLocalDateTime(r){let t=new G(r);return t.#e=null,t}static wrapAsLocalDate(r){let t=new G(r);return t.#r=!1,t.#e=null,t}static wrapAsLocalTime(r){let t=new G(r);return t.#s=!1,t.#e=null,t}}let tr=/^((0x[0-9a-fA-F](_?[0-9a-fA-F])*)|(([+-]|0[ob])?\d(_?\d)*))$/,nr=/^[+-]?\d(_?\d)*(\.\d(_?\d)*)?([eE][+-]?\d(_?\d)*)?$/,ar=/^[+-]?0[0-9_]/,lr=/^[0-9a-f]{2,8}$/i,Se={b:"\b",t:" ",n:`
18
- `,f:"\f",r:"\r",e:"\x1B",'"':'"',"\\":"\\"};function Ae(s,r=0,t=s.length){let a=s[r]==="'",n=s[r++]===s[r]&&s[r]===s[r+1];n&&(t-=2,s[r+=2]==="\r"&&r++,s[r]===`
19
- `&&r++);let l=0,i,o="",d=r;for(;r<t-1;){let c=s[r++];if(c===`
20
- `||c==="\r"&&s[r]===`
21
- `){if(!n)throw new p("newlines are not allowed in strings",{toml:s,ptr:r-1})}else if(c<" "&&c!==" "||c==="")throw new p("control characters are not allowed in strings",{toml:s,ptr:r-1});if(i){if(i=!1,c==="x"||c==="u"||c==="U"){let u=s.slice(r,r+=c==="x"?2:c==="u"?4:8);if(!lr.test(u))throw new p("invalid unicode escape",{toml:s,ptr:l});try{o+=String.fromCodePoint(parseInt(u,16))}catch{throw new p("invalid unicode escape",{toml:s,ptr:l})}}else if(n&&(c===`
22
- `||c===" "||c===" "||c==="\r")){if(r=K(s,r-1,!0),s[r]!==`
23
- `&&s[r]!=="\r")throw new p("invalid escape: only line-ending whitespace may be escaped",{toml:s,ptr:l});r=K(s,r)}else if(c in Se)o+=Se[c];else throw new p("unrecognized escape sequence",{toml:s,ptr:l});d=r}else!a&&c==="\\"&&(l=r-1,i=!0,o+=s.slice(d,l))}return o+s.slice(d,t-1)}function or(s,r,t,a){if(s==="true")return!0;if(s==="false")return!1;if(s==="-inf")return-1/0;if(s==="inf"||s==="+inf")return 1/0;if(s==="nan"||s==="+nan"||s==="-nan")return NaN;if(s==="-0")return a?0n:0;let n=tr.test(s);if(n||nr.test(s)){if(ar.test(s))throw new p("leading zeroes are not allowed",{toml:r,ptr:t});s=s.replace(/_/g,"");let i=+s;if(isNaN(i))throw new p("invalid number",{toml:r,ptr:t});if(n){if((n=!Number.isSafeInteger(i))&&!a)throw new p("integer value cannot be represented losslessly",{toml:r,ptr:t});(n||a===!0)&&(i=BigInt(s))}return i}const l=new G(s);if(!l.isValid())throw new p("invalid value",{toml:r,ptr:t});return l}function ir(s,r,t){let a=s.slice(r,t),n=a.indexOf("#");return n>-1&&(ee(s,n),a=a.slice(0,n)),[a.trimEnd(),n]}function he(s,r,t,a,n){if(a===0)throw new p("document contains excessively nested structures. aborting.",{toml:s,ptr:r});let l=s[r];if(l==="["||l==="{"){let[d,c]=l==="["?ur(s,r,a,n):dr(s,r,a,n);if(t){if(c=K(s,c),s[c]===",")c++;else if(s[c]!==t)throw new p("expected comma or end of structure",{toml:s,ptr:c})}return[d,c]}let i;if(l==='"'||l==="'"){i=Le(s,r);let d=Ae(s,r,i);if(t){if(i=K(s,i),s[i]&&s[i]!==","&&s[i]!==t&&s[i]!==`
24
- `&&s[i]!=="\r")throw new p("unexpected character encountered",{toml:s,ptr:i});i+=+(s[i]===",")}return[d,i]}i=sr(s,r,",",t);let o=ir(s,r,i-+(s[i-1]===","));if(!o[0])throw new p("incomplete key-value declaration: no value specified",{toml:s,ptr:r});return t&&o[1]>-1&&(i=K(s,r+o[1]),i+=+(s[i]===",")),[or(o[0],s,r,n),i]}let cr=/^[a-zA-Z0-9-_]+[ \t]*$/;function me(s,r,t="="){let a=r-1,n=[],l=s.indexOf(t,r);if(l<0)throw new p("incomplete key-value: cannot find end of key",{toml:s,ptr:r});do{let i=s[r=++a];if(i!==" "&&i!==" ")if(i==='"'||i==="'"){if(i===s[r+1]&&i===s[r+2])throw new p("multiline strings are not allowed in keys",{toml:s,ptr:r});let o=Le(s,r);if(o<0)throw new p("unfinished string encountered",{toml:s,ptr:r});a=s.indexOf(".",o);let d=s.slice(o,a<0||a>l?l:a),c=ue(d);if(c>-1)throw new p("newlines are not allowed in keys",{toml:s,ptr:r+a+c});if(d.trimStart())throw new p("found extra tokens after the string part",{toml:s,ptr:o});if(l<o&&(l=s.indexOf(t,o),l<0))throw new p("incomplete key-value: cannot find end of key",{toml:s,ptr:r});n.push(Ae(s,r,o))}else{a=s.indexOf(".",r);let o=s.slice(r,a<0||a>l?l:a);if(!cr.test(o))throw new p("only letter, numbers, dashes and underscores are allowed in keys",{toml:s,ptr:r});n.push(o.trimEnd())}}while(a+1&&a<l);return[n,K(s,l+1,!0,!0)]}function dr(s,r,t,a){let n={},l=new Set,i;for(r++;(i=s[r++])!=="}"&&i;){if(i===",")throw new p("expected value, found comma",{toml:s,ptr:r-1});if(i==="#")r=ee(s,r);else if(i!==" "&&i!==" "&&i!==`
25
- `&&i!=="\r"){let o,d=n,c=!1,[u,h]=me(s,r-1);for(let g=0;g<u.length;g++){if(g&&(d=c?d[o]:d[o]={}),o=u[g],(c=Object.hasOwn(d,o))&&(typeof d[o]!="object"||l.has(d[o])))throw new p("trying to redefine an already defined value",{toml:s,ptr:r});!c&&o==="__proto__"&&Object.defineProperty(d,o,{enumerable:!0,configurable:!0,writable:!0})}if(c)throw new p("trying to redefine an already defined value",{toml:s,ptr:r});let[j,x]=he(s,h,"}",t-1,a);l.add(j),d[o]=j,r=x}}if(!i)throw new p("unfinished table encountered",{toml:s,ptr:r});return[n,r]}function ur(s,r,t,a){let n=[],l;for(r++;(l=s[r++])!=="]"&&l;){if(l===",")throw new p("expected value, found comma",{toml:s,ptr:r-1});if(l==="#")r=ee(s,r);else if(l!==" "&&l!==" "&&l!==`
26
- `&&l!=="\r"){let i=he(s,r-1,"]",t-1,a);n.push(i[0]),r=i[1]}}if(!l)throw new p("unfinished array encountered",{toml:s,ptr:r});return[n,r]}function ke(s,r,t,a){let n=r,l=t,i,o=!1,d;for(let c=0;c<s.length;c++){if(c){if(n=o?n[i]:n[i]={},l=(d=l[i]).c,a===0&&(d.t===1||d.t===2))return null;if(d.t===2){let u=n.length-1;n=n[u],l=l[u].c}}if(i=s[c],(o=Object.hasOwn(n,i))&&l[i]?.t===0&&l[i]?.d)return null;o||(i==="__proto__"&&(Object.defineProperty(n,i,{enumerable:!0,configurable:!0,writable:!0}),Object.defineProperty(l,i,{enumerable:!0,configurable:!0,writable:!0})),l[i]={t:c<s.length-1&&a===2?3:a,d:!1,i:0,c:{}})}if(d=l[i],d.t!==a&&!(a===1&&d.t===3)||(a===2&&(d.d||(d.d=!0,n[i]=[]),n[i].push(n={}),d.c[d.i++]=d={t:1,d:!1,i:0,c:{}}),d.d))return null;if(d.d=!0,a===1)n=o?n[i]:n[i]={};else if(a===0&&o)return null;return[i,n,d.c]}function mr(s,{maxDepth:r=1e3,integersAsBigInt:t}={}){let a={},n={},l=a,i=n;for(let o=K(s,0);o<s.length;){if(s[o]==="["){let d=s[++o]==="[",c=me(s,o+=+d,"]");if(d){if(s[c[1]-1]!=="]")throw new p("expected end of table declaration",{toml:s,ptr:c[1]-1});c[1]++}let u=ke(c[0],a,n,d?2:1);if(!u)throw new p("trying to redefine an already defined table or value",{toml:s,ptr:o});i=u[2],l=u[1],o=c[1]}else{let d=me(s,o),c=ke(d[0],l,i,0);if(!c)throw new p("trying to redefine an already defined table or value",{toml:s,ptr:o});let u=he(s,d[1],void 0,r,t);c[1][c[0]]=u[0],o=u[1]}if(o=K(s,o,!0),s[o]&&s[o]!==`
27
- `&&s[o]!=="\r")throw new p("each key-value declaration must be followed by an end-of-line",{toml:s,ptr:o});o=K(s,o)}return a}function xr(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function hr(s){if(!s.trim())return{};const t=mr(s);if(!xr(t))throw new Error("TOML root must be a table.");return t}function Re(s){try{return{config:hr(s),parseError:null}}catch(r){return{config:null,parseError:r.message}}}async function pr(){const s=await fetch(J("/codex/diagnostics"));if(!s.ok)throw new Error("Failed to fetch Codex diagnostics");return s.json()}async function fr(){const s=await fetch(J("/codex/config/raw"));if(!s.ok)throw new Error("Failed to fetch Codex raw config");return s.json()}async function jr(s){const r=await fetch(J("/codex/config/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(r.status===409)throw new Te("Codex raw config changed externally");if(!r.ok){const t=await r.json().catch(()=>null);throw new Error(t?.error||"Failed to save Codex raw config")}return r.json()}async function gr(s){const r=await fetch(J("/codex/config/patch"),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(r.status===409)throw new Te("Codex config changed externally");if(!r.ok){const t=await r.json().catch(()=>null);throw new Error(t?.error||"Failed to patch Codex config")}return r.json()}function vr(){const s=gs(),r=be({queryKey:["codex-diagnostics"],queryFn:pr,refetchInterval:1e4}),t=be({queryKey:["codex-raw-config"],queryFn:fr}),a=we({mutationFn:jr,onSuccess:(l,i)=>{s.setQueryData(["codex-raw-config"],o=>{const d=o?.path??"$CODEX_HOME/config.toml",c=o?.resolvedPath??d,u=Re(i.rawText);return{path:d,resolvedPath:c,exists:!0,mtime:l.mtime,rawText:i.rawText,config:u.config,parseError:u.parseError,readError:null}}),s.invalidateQueries({queryKey:["codex-diagnostics"]})}}),n=we({mutationFn:gr,onSuccess:l=>{s.setQueryData(["codex-raw-config"],l),s.invalidateQueries({queryKey:["codex-diagnostics"]})}});return b.useMemo(()=>({diagnostics:r.data,diagnosticsLoading:r.isLoading,diagnosticsError:r.error,refetchDiagnostics:r.refetch,rawConfig:t.data,rawConfigLoading:t.isLoading,rawConfigError:t.error,refetchRawConfig:t.refetch,saveRawConfig:a.mutate,saveRawConfigAsync:a.mutateAsync,isSavingRawConfig:a.isPending,patchConfig:n.mutate,patchConfigAsync:n.mutateAsync,isPatchingConfig:n.isPending}),[r.data,r.isLoading,r.error,r.refetch,t.data,t.isLoading,t.error,t.refetch,a.mutate,a.mutateAsync,a.isPending,n.mutate,n.mutateAsync,n.isPending])}const br=[{label:"Start Default",command:"ccs",description:"Launch Claude with default profile"},{label:"GLM Profile",command:"ccs glm",description:"Switch to GLM model"},{label:"Health Check",command:"ccs doctor",description:"Run system diagnostics"},{label:"Delegate Task",command:'ccs glm -p "your task"',description:"Delegate to GLM profile"}];function wr({snippets:s=br}){const[r,t]=b.useState(null),a=async(n,l)=>{await navigator.clipboard.writeText(n),t(l),setTimeout(()=>t(null),2e3)};return e.jsxs(D,{children:[e.jsx(M,{className:"pb-3",children:e.jsxs(I,{className:"text-lg flex items-center gap-2",children:[e.jsx(is,{className:"w-5 h-5 text-muted-foreground"}),"Quick Commands"]})}),e.jsx(F,{children:e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:s.map((n,l)=>e.jsxs("div",{className:_e("group flex items-center justify-between gap-2 px-3 py-2","rounded-lg border bg-muted/30 hover:bg-muted/50 transition-colors"),children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:n.label}),e.jsx("code",{className:"text-sm font-mono font-medium truncate block",children:n.command})]}),e.jsx(w,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0 opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>a(n.command,l),title:n.description,children:r===l?e.jsx(cs,{className:"h-4 w-4 text-green-600"}):e.jsx(ds,{className:"h-4 w-4"})})]},l))})})]})}function Nr(s){return!s||!Number.isFinite(s)?"N/A":new Date(s).toLocaleString()}function Cr(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 S({label:s,value:r,mono:t=!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:_e("text-right break-all",t&&"font-mono text-xs"),children:r})]})}function yr({diagnostics:s}){const r=s.config.activeProfile?`codex --profile ${s.config.activeProfile}`:"codex",t=s.binary.supportsConfigOverrides;return e.jsx(xe,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(us,{className:"h-4 w-4"}),"How Codex works in CCS"]})}),e.jsx(F,{className:"text-sm text-muted-foreground",children:e.jsxs("ul",{className:"ml-4 list-disc space-y-1.5 [&>li]:pl-1",children:[e.jsx("li",{children:"Codex is a first-class, runtime-only target in CCS v1."}),e.jsxs("li",{children:[e.jsx("strong",{children:"Native config:"})," ",e.jsx("code",{children:"ccs-codex"})," and ",e.jsx("code",{children:"ccsx"})," launch native Codex using your saved defaults."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Transient overrides:"})," ",e.jsx("code",{children:"ccsxp"})," (or"," ",e.jsx("code",{children:"ccs codex --target codex"}),") uses the CCS provider shortcut."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"CLIProxy default:"})," To make plain ",e.jsx("code",{children:"codex"})," use CLIProxy, set ",e.jsx("code",{children:'model_provider = "cliproxy"'})," and add the recipe below."]}),e.jsx("li",{children:"API profiles continue to default to Claude or Droid."})]})})]}),e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(ms,{className:"h-4 w-4"}),"Runtime install"]})}),e.jsxs(F,{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:"Status"}),e.jsx(y,{variant:s.binary.installed?"default":"secondary",children:s.binary.installed?"Detected":"Not found"})]}),e.jsx(S,{label:"Detection source",value:s.binary.source,mono:!0}),e.jsx(S,{label:"Binary path",value:s.binary.path||"Not found",mono:!0}),e.jsx(S,{label:"Install directory",value:s.binary.installDir||"N/A",mono:!0}),e.jsx(S,{label:"Version",value:s.binary.version||"Unknown",mono:!0}),e.jsx(S,{label:"Native aliases",value:"ccs-codex, ccsx",mono:!0}),e.jsx(S,{label:"CCS provider shortcut",value:"ccsxp",mono:!0}),e.jsxs("div",{className:"flex items-center justify-between rounded-md border px-3 py-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"--config override support"}),e.jsx(y,{variant:s.binary.supportsConfigOverrides?"default":"secondary",children:s.binary.supportsConfigOverrides?"Available":"Missing"})]})]})]}),e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(ve,{className:"h-4 w-4"}),"CLIProxy-backed native Codex"]})}),e.jsx(F,{className:"space-y-3 text-sm text-muted-foreground",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{children:e.jsx("strong",{children:"Two supported paths:"})}),e.jsxs("ul",{className:"ml-4 list-disc space-y-1 [&>li]:pl-1",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Built-in:"})," Use ",e.jsx("code",{children:"ccsxp"})," for the CCS provider shortcut."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Native:"})," Configure the recipe below to use CLIProxy directly with ",e.jsx("code",{children:"codex"}),"."]})]})]}),e.jsxs("div",{className:"rounded-md border bg-muted/20 p-3",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Saved native Codex recipe"}),e.jsx("pre",{className:"mt-2 overflow-x-auto rounded-md bg-background p-3 text-xs text-foreground",children:Ee})]}),e.jsxs("ol",{className:"ml-4 list-decimal space-y-1.5 [&>li]:pl-1",children:[e.jsxs("li",{children:["Save a provider named ",e.jsx("code",{children:"cliproxy"})," with the base URL and env key above."]}),e.jsxs("li",{children:["In ",e.jsx("strong",{children:"Top-level settings"}),", set ",e.jsx("strong",{children:"Default provider"})," to"," ",e.jsx("code",{children:"cliproxy"}),"."]}),e.jsxs("li",{children:["Export ",e.jsx("code",{children:"CLIPROXY_API_KEY"})," in your shell before launching native Codex."]})]})]}):e.jsxs("p",{children:["This Codex build can still use the native path, but CCS-backed Codex routing via"," ",e.jsx("code",{children:"ccsxp"})," or ",e.jsx("code",{children:"ccs codex --target codex"})," stays unavailable until the detected Codex binary exposes ",e.jsx("code",{children:"--config"})," overrides."]})})]}),e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(xs,{className:"h-4 w-4"}),"Config file"]})}),e.jsx(F,{className:"space-y-3",children: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:"User config"}),s.file.exists?e.jsx(hs,{className:"h-4 w-4 text-green-600"}):e.jsx(ps,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(S,{label:"Path",value:s.file.path,mono:!0}),e.jsx(S,{label:"Resolved",value:s.file.resolvedPath,mono:!0}),e.jsx(S,{label:"Size",value:Cr(s.file.sizeBytes)}),e.jsx(S,{label:"Last modified",value:Nr(s.file.mtimeMs)}),s.file.parseError&&e.jsxs("p",{className:"text-xs text-amber-600",children:["TOML warning: ",s.file.parseError]}),s.file.readError&&e.jsxs("p",{className:"text-xs text-destructive",children:["Read warning: ",s.file.readError]})]})})]}),e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(de,{className:"h-4 w-4"}),"Current user-layer summary"]})}),e.jsxs(F,{className:"space-y-3",children:[e.jsx(S,{label:"Model",value:s.config.model||"Not set",mono:!0}),e.jsx(S,{label:"Model provider",value:s.config.modelProvider||"Not set",mono:!0}),e.jsx(S,{label:"Active profile",value:s.config.activeProfile||"Not set",mono:!0}),e.jsx(S,{label:"Approval policy",value:s.config.approvalPolicy||"Not set",mono:!0}),e.jsx(S,{label:"Sandbox mode",value:s.config.sandboxMode||"Not set",mono:!0}),e.jsx(S,{label:"Web search",value:s.config.webSearch||"Not set",mono:!0}),e.jsx(Q,{}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-xs",children:[e.jsxs(y,{variant:"outline",className:"justify-center",children:["providers: ",s.config.modelProviderCount]}),e.jsxs(y,{variant:"outline",className:"justify-center",children:["profiles: ",s.config.profileCount]}),e.jsxs(y,{variant:"outline",className:"justify-center",children:["enabled features: ",s.config.enabledFeatures.length]}),e.jsxs(y,{variant:"outline",className:"justify-center",children:["MCP servers: ",s.config.mcpServerCount]})]}),s.config.topLevelKeys.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs uppercase tracking-wide text-muted-foreground",children:"User-layer keys present"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.config.topLevelKeys.map(a=>e.jsx(y,{variant:"secondary",className:"font-mono text-[10px]",children:a},a))})]})]})]}),e.jsx(wr,{snippets:[{label:"Native short alias",command:"ccsx",description:"Launch the short native Codex runtime alias."},{label:"CCS Codex shortcut",command:'ccsxp "your prompt"',description:t?"Run the built-in CCS Codex provider on native Codex.":"Requires a Codex build that exposes --config overrides."},{label:"Explicit provider route",command:'ccs codex --target codex "your prompt"',description:t?"Use the explicit built-in Codex provider route.":"Requires a Codex build that exposes --config overrides."},{label:s.config.activeProfile?"Inspect active profile":"Open native Codex",command:r,description:s.config.activeProfile?"Inspect the active named profile directly in native Codex.":"Open native Codex without forcing a named profile overlay."}]}),e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(ve,{className:"h-4 w-4"}),"Runtime vs provider"]})}),e.jsxs(F,{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col rounded-md border p-3 text-sm",children:[e.jsx("p",{className:"font-medium text-foreground",children:"Native Codex runtime"}),e.jsxs("ul",{className:"mt-2 flex-grow list-disc space-y-1.5 pl-4 text-muted-foreground [&>li]:pl-1",children:[e.jsx("li",{children:e.jsx("code",{children:"ccs-codex"})}),e.jsx("li",{children:e.jsx("code",{children:"ccsx"})}),e.jsx("li",{children:e.jsx("code",{children:"--target codex"})})]}),e.jsx(y,{variant:"secondary",className:"mt-4 w-fit justify-center font-normal",children:"Honors saved native user config"})]}),e.jsxs("div",{className:"flex flex-col rounded-md border p-3 text-sm",children:[e.jsx("p",{className:"font-medium text-foreground",children:"CCS Codex provider / bridge"}),t?e.jsxs(e.Fragment,{children:[e.jsxs("ul",{className:"mt-2 flex-grow list-disc space-y-1.5 pl-4 text-muted-foreground [&>li]:pl-1",children:[e.jsx("li",{children:e.jsx("code",{children:"ccsxp"})}),e.jsx("li",{children:e.jsx("code",{children:"ccs codex --target codex"})})]}),e.jsx(y,{variant:"secondary",className:"mt-4 w-fit justify-center font-normal",children:"Uses transient overrides"})]}):e.jsxs("p",{className:"mt-2 text-muted-foreground",children:["Unavailable (Codex build lacks ",e.jsx("code",{children:"--config"})," support)."]})]})]})]}),e.jsxs(D,{children:[e.jsx(M,{className:"pb-2",children:e.jsx(I,{className:"text-base",children:"Supported flows"})}),e.jsx(F,{children:e.jsxs(vs,{children:[e.jsx(bs,{children:e.jsxs(Ne,{children:[e.jsx(ne,{children:"Flow"}),e.jsx(ne,{children:"Status"}),e.jsx(ne,{children:"Notes"})]})}),e.jsx(ws,{children:s.supportMatrix.map(a=>e.jsxs(Ne,{children:[e.jsx(ae,{className:"font-mono text-xs",children:a.label}),e.jsx(ae,{children:e.jsx(y,{variant:a.supported?"default":"secondary",children:a.supported?"Yes":"No"})}),e.jsx(ae,{className:"text-xs text-muted-foreground",children:a.notes})]},a.id))})]})})]}),s.warnings.length>0&&e.jsxs(D,{className:"border-amber-200 bg-amber-50/50 dark:bg-amber-950/20",children:[e.jsx(M,{className:"pb-2",children:e.jsxs(I,{className:"flex items-center gap-2 text-base",children:[e.jsx(fs,{className:"h-4 w-4 text-amber-600"}),"Warnings"]})}),e.jsx(F,{className:"space-y-1.5",children:s.warnings.map(a=>e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-300",children:["- ",a]},a))})]})]})})}function Ir(){const{diagnostics:s,diagnosticsLoading:r,diagnosticsError:t,refetchDiagnostics:a,rawConfig:n,rawConfigLoading:l,rawConfigError:i,refetchRawConfig:o,saveRawConfigAsync:d,isSavingRawConfig:c,patchConfigAsync:u,isPatchingConfig:h}=vr(),[j,x]=b.useState(null),g=n?.rawText??"",A=j??g,U=j!==null&&j!==g,m=Re(A),f=m.parseError?{valid:!1,error:m.parseError}:{valid:!0},T=n?.config??null,N=l||!n||U||n?.parseError!==null||n?.readError!==null,De=i?"Structured controls unavailable: failed to load the current config.toml.":n?.readError?`Structured controls unavailable: ${n.readError}`:U?f.valid?"Save or discard raw TOML edits before using structured controls.":"Fix or discard raw TOML edits before using structured controls.":n?.parseError?`Structured controls disabled: ${n.parseError}`:null,Me=b.useMemo(()=>Oe(T),[T]),Ie=b.useMemo(()=>Vs(T),[T]),Fe=b.useMemo(()=>Xs(T),[T]),Ue=b.useMemo(()=>zs(T),[T]),We=b.useMemo(()=>$s(T),[T]),Ke=b.useMemo(()=>Gs(T),[T]),qe=R=>{if(R===g){x(null);return}x(R)},Ve=async()=>{try{if((await Promise.all([a(),o()])).some(V=>!V||V.status==="error"||V.isError||V.error)){W.error("Failed to refresh Codex snapshot. Raw edits were kept.");return}x(null)}catch(R){W.error(R.message||"Failed to refresh Codex snapshot.")}},Xe=async()=>{if(!f.valid){W.error("Fix TOML before saving.");return}try{await d({rawText:A,expectedMtime:n?.exists?n.mtime:void 0}),x(null),W.success("Saved Codex config.toml."),await a()}catch(R){je(R)?W.error("config.toml changed externally. Refresh and retry."):W.error(R.message||"Failed to save Codex config.toml.")}},ze=async(R,pe)=>{try{await u({...R,expectedMtime:n?.exists?n.mtime:void 0}),x(null),W.success(pe)}catch(V){je(V)?W.error("config.toml changed externally. Refresh and retry."):W.error(V.message||"Failed to update Codex config.")}},se="mt-0 h-full border-0 p-0 data-[state=inactive]:hidden",$e=()=>r?e.jsxs("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:[e.jsx(X,{className:"mr-2 h-5 w-5 animate-spin"}),"Loading Codex diagnostics..."]}):t||!s?e.jsx("div",{className:"flex h-full items-center justify-center px-6 text-center text-destructive",children:"Failed to load Codex diagnostics."}):e.jsxs(Be,{defaultValue:"overview",className:"flex h-full flex-col",children:[e.jsx("div",{className:"shrink-0 px-4 pt-4",children:e.jsxs(He,{className:"grid w-full grid-cols-3",children:[e.jsx(re,{value:"overview",children:"Overview"}),e.jsx(re,{value:"controls",children:"Control Center"}),e.jsx(re,{value:"docs",children:"Docs"})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden px-4 pb-4 pt-3",children:[e.jsx(te,{value:"overview",className:se,children:e.jsx(yr,{diagnostics:s})}),e.jsx(te,{value:"controls",className:se,children:e.jsx(qs,{workspacePath:s.workspacePath,activeProfile:s.config.activeProfile,topLevelSettings:Me,projectTrustEntries:Ie,profileEntries:Fe,modelProviderEntries:Ue,mcpServerEntries:We,featureCatalog:Pe,featureState:Ke,disabled:N,disabledReason:De,saving:h,onPatch:ze})}),e.jsx(te,{value:"docs",className:se,children:e.jsx(Qs,{diagnostics:s})})]})]});return e.jsx("div",{className:"h-full min-h-0 overflow-hidden",children:e.jsxs(Ge,{direction:"horizontal",className:"h-full",children:[e.jsx(fe,{defaultSize:45,minSize:35,children:e.jsx("div",{className:"h-full border-r bg-muted/20",children:$e()})}),e.jsx(Ye,{className:"group flex w-2 cursor-col-resize items-center justify-center bg-border transition-colors hover:bg-primary/20",children:e.jsx(js,{className:"h-3 w-3 text-muted-foreground group-hover:text-primary"})}),e.jsx(fe,{defaultSize:55,minSize:35,children:e.jsx(Ns,{title:"Codex config.toml",pathLabel:n?.path||s?.file.path||"$CODEX_HOME/config.toml",loading:l,parseWarning:f.valid?n?.parseError:f.error,readWarning:n?.readError,value:A,dirty:U,readOnly:!!n?.readError,saving:c,saveDisabled:!U||c||l||!f.valid||!!n?.readError,onChange:R=>{qe(R)},onSave:Xe,onRefresh:Ve,onDiscard:()=>x(null),language:"toml",loadingLabel:"Loading config.toml...",parseWarningLabel:"TOML warning",ownershipNotice:e.jsxs("div",{className:"rounded-md border border-amber-200 bg-amber-50/60 px-3 py-2 text-sm text-amber-900 dark:bg-amber-950/20 dark:text-amber-300",children:[e.jsx("p",{className:"font-medium",children:"This file is upstream-owned by Codex CLI."}),e.jsxs("p",{children:["CCS does not keep ",e.jsx("code",{children:"~/.codex/config.toml"})," in sync for you."]}),e.jsxs("p",{children:["CCS-backed Codex launches may apply transient ",e.jsx("code",{children:"-c"})," overrides and",e.jsx("code",{children:" CCS_CODEX_API_KEY"}),"; those effective values may not appear here."]})]})})})]})})}export{Ir as CodexPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-Zb8sVEtn.js";import{A as c,a as d,b as g,c as x,d as h,e as j,f as A,g as D}from"./alert-dialog-QyEXocpn.js";function f({open:i,onConfirm:l,onCancel:r,title:s,description:t,confirmText:a="Confirm",variant:o="default"}){return e.jsx(c,{open:i,onOpenChange:n=>!n&&r(),children:e.jsxs(d,{children:[e.jsxs(g,{children:[e.jsx(x,{children:s}),e.jsx(h,{children:t})]}),e.jsxs(j,{children:[e.jsx(A,{onClick:r,children:"Cancel"}),e.jsx(D,{onClick:l,className:o==="destructive"?"bg-red-600 hover:bg-red-700 text-white":"",children:a})]})]})})}export{f as C};
@@ -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};