@kaitranntt/ccs 7.51.0-dev.1 → 7.51.0-dev.10

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 (159) hide show
  1. package/README.md +16 -0
  2. package/dist/api/services/profile-writer.d.ts.map +1 -1
  3. package/dist/api/services/profile-writer.js +33 -0
  4. package/dist/api/services/profile-writer.js.map +1 -1
  5. package/dist/auth/profile-continuity-inheritance.d.ts +20 -0
  6. package/dist/auth/profile-continuity-inheritance.d.ts.map +1 -0
  7. package/dist/auth/profile-continuity-inheritance.js +139 -0
  8. package/dist/auth/profile-continuity-inheritance.js.map +1 -0
  9. package/dist/ccs.js +39 -3
  10. package/dist/ccs.js.map +1 -1
  11. package/dist/cliproxy/catalog-cache.d.ts.map +1 -1
  12. package/dist/cliproxy/catalog-cache.js +10 -3
  13. package/dist/cliproxy/catalog-cache.js.map +1 -1
  14. package/dist/cliproxy/composite-validator.d.ts.map +1 -1
  15. package/dist/cliproxy/composite-validator.js +9 -0
  16. package/dist/cliproxy/composite-validator.js.map +1 -1
  17. package/dist/cliproxy/config/env-builder.d.ts.map +1 -1
  18. package/dist/cliproxy/config/env-builder.js +69 -8
  19. package/dist/cliproxy/config/env-builder.js.map +1 -1
  20. package/dist/cliproxy/config/generator.d.ts +3 -1
  21. package/dist/cliproxy/config/generator.d.ts.map +1 -1
  22. package/dist/cliproxy/config/generator.js +17 -6
  23. package/dist/cliproxy/config/generator.js.map +1 -1
  24. package/dist/cliproxy/executor/env-resolver.d.ts +2 -0
  25. package/dist/cliproxy/executor/env-resolver.d.ts.map +1 -1
  26. package/dist/cliproxy/executor/env-resolver.js +2 -1
  27. package/dist/cliproxy/executor/env-resolver.js.map +1 -1
  28. package/dist/cliproxy/executor/index.d.ts.map +1 -1
  29. package/dist/cliproxy/executor/index.js +15 -0
  30. package/dist/cliproxy/executor/index.js.map +1 -1
  31. package/dist/cliproxy/model-catalog.d.ts.map +1 -1
  32. package/dist/cliproxy/model-catalog.js +3 -39
  33. package/dist/cliproxy/model-catalog.js.map +1 -1
  34. package/dist/cliproxy/model-config.d.ts.map +1 -1
  35. package/dist/cliproxy/model-config.js +12 -11
  36. package/dist/cliproxy/model-config.js.map +1 -1
  37. package/dist/cliproxy/model-id-normalizer.d.ts +30 -2
  38. package/dist/cliproxy/model-id-normalizer.d.ts.map +1 -1
  39. package/dist/cliproxy/model-id-normalizer.js +88 -7
  40. package/dist/cliproxy/model-id-normalizer.js.map +1 -1
  41. package/dist/cliproxy/services/variant-service.d.ts.map +1 -1
  42. package/dist/cliproxy/services/variant-service.js +12 -0
  43. package/dist/cliproxy/services/variant-service.js.map +1 -1
  44. package/dist/cliproxy/services/variant-settings.d.ts.map +1 -1
  45. package/dist/cliproxy/services/variant-settings.js +5 -3
  46. package/dist/cliproxy/services/variant-settings.js.map +1 -1
  47. package/dist/cliproxy/stats-fetcher.d.ts +41 -0
  48. package/dist/cliproxy/stats-fetcher.d.ts.map +1 -1
  49. package/dist/cliproxy/stats-fetcher.js +32 -1
  50. package/dist/cliproxy/stats-fetcher.js.map +1 -1
  51. package/dist/cliproxy/tool-sanitization-proxy.d.ts.map +1 -1
  52. package/dist/cliproxy/tool-sanitization-proxy.js +6 -0
  53. package/dist/cliproxy/tool-sanitization-proxy.js.map +1 -1
  54. package/dist/cliproxy/types.d.ts +2 -0
  55. package/dist/cliproxy/types.d.ts.map +1 -1
  56. package/dist/commands/config-command.js +2 -2
  57. package/dist/commands/config-command.js.map +1 -1
  58. package/dist/commands/help-command.d.ts.map +1 -1
  59. package/dist/commands/help-command.js +4 -0
  60. package/dist/commands/help-command.js.map +1 -1
  61. package/dist/config/unified-config-loader.d.ts +5 -0
  62. package/dist/config/unified-config-loader.d.ts.map +1 -1
  63. package/dist/config/unified-config-loader.js +62 -1
  64. package/dist/config/unified-config-loader.js.map +1 -1
  65. package/dist/config/unified-config-types.d.ts +10 -0
  66. package/dist/config/unified-config-types.d.ts.map +1 -1
  67. package/dist/config/unified-config-types.js.map +1 -1
  68. package/dist/copilot/copilot-executor.d.ts +2 -2
  69. package/dist/copilot/copilot-executor.d.ts.map +1 -1
  70. package/dist/copilot/copilot-executor.js +4 -3
  71. package/dist/copilot/copilot-executor.js.map +1 -1
  72. package/dist/types/config.d.ts +2 -0
  73. package/dist/types/config.d.ts.map +1 -1
  74. package/dist/types/config.js.map +1 -1
  75. package/dist/ui/assets/accounts-C0a1t7jn.js +1 -0
  76. package/dist/ui/assets/{alert-dialog-B_Bdo2ou.js → alert-dialog-CdeUwye7.js} +1 -1
  77. package/dist/ui/assets/api-C9zwFFut.js +1 -0
  78. package/dist/ui/assets/auth-section-DN4BD8GL.js +1 -0
  79. package/dist/ui/assets/backups-section-CybLESWH.js +1 -0
  80. package/dist/ui/assets/{checkbox-D19h9xqD.js → checkbox-vEe6qcYo.js} +1 -1
  81. package/dist/ui/assets/cliproxy-BqfDDSqL.js +3 -0
  82. package/dist/ui/assets/cliproxy-control-panel-Bge72LT-.js +1 -0
  83. package/dist/ui/assets/{confirm-dialog-7-N-o1DD.js → confirm-dialog-OyJIM_hE.js} +1 -1
  84. package/dist/ui/assets/copilot-CkAJrz8o.js +3 -0
  85. package/dist/ui/assets/cursor-C9LZa_BA.js +1 -0
  86. package/dist/ui/assets/droid-QWGtb0RV.js +2 -0
  87. package/dist/ui/assets/globalenv-section-DOFqIs-8.js +1 -0
  88. package/dist/ui/assets/health-C3ElQ1Lv.js +1 -0
  89. package/dist/ui/assets/{icons-DrewC9c3.js → icons-kPbuhVdj.js} +1 -1
  90. package/dist/ui/assets/index-3GEclgP5.js +1 -0
  91. package/dist/ui/assets/index-BAKFUe-l.js +1 -0
  92. package/dist/ui/assets/index-Bz6l7LGz.js +47 -0
  93. package/dist/ui/assets/index-CMCDJeIA.js +1 -0
  94. package/dist/ui/assets/index-eLGkeVzr.js +1 -0
  95. package/dist/ui/assets/proxy-status-widget-srJDTpWy.js +1 -0
  96. package/dist/ui/assets/{radix-ui-C1Gpgz6I.js → radix-ui-BR1vy4kf.js} +3 -3
  97. package/dist/ui/assets/{separator-51ocJFnp.js → separator-CmlWHN0k.js} +1 -1
  98. package/dist/ui/assets/shared-COklsZr3.js +8 -0
  99. package/dist/ui/assets/{switch-B3t2TDvW.js → switch-Cv3ybiIH.js} +1 -1
  100. package/dist/ui/assets/{tanstack-DDJIhNJd.js → tanstack-e99Cjjy2.js} +1 -1
  101. package/dist/ui/assets/updates-CGOjPqS1.js +1 -0
  102. package/dist/ui/index.html +4 -4
  103. package/dist/web-server/index.d.ts.map +1 -1
  104. package/dist/web-server/index.js +2 -0
  105. package/dist/web-server/index.js.map +1 -1
  106. package/dist/web-server/model-pricing.d.ts.map +1 -1
  107. package/dist/web-server/model-pricing.js +50 -1
  108. package/dist/web-server/model-pricing.js.map +1 -1
  109. package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
  110. package/dist/web-server/routes/cliproxy-stats-routes.js +27 -3
  111. package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
  112. package/dist/web-server/routes/profile-routes.d.ts.map +1 -1
  113. package/dist/web-server/routes/profile-routes.js +7 -2
  114. package/dist/web-server/routes/profile-routes.js.map +1 -1
  115. package/dist/web-server/routes/route-helpers.d.ts.map +1 -1
  116. package/dist/web-server/routes/route-helpers.js +55 -0
  117. package/dist/web-server/routes/route-helpers.js.map +1 -1
  118. package/dist/web-server/routes/settings-routes.d.ts.map +1 -1
  119. package/dist/web-server/routes/settings-routes.js +137 -28
  120. package/dist/web-server/routes/settings-routes.js.map +1 -1
  121. package/dist/web-server/usage/aggregator.d.ts +9 -0
  122. package/dist/web-server/usage/aggregator.d.ts.map +1 -1
  123. package/dist/web-server/usage/aggregator.js +63 -7
  124. package/dist/web-server/usage/aggregator.js.map +1 -1
  125. package/dist/web-server/usage/cliproxy-usage-syncer.d.ts +34 -0
  126. package/dist/web-server/usage/cliproxy-usage-syncer.d.ts.map +1 -0
  127. package/dist/web-server/usage/cliproxy-usage-syncer.js +155 -0
  128. package/dist/web-server/usage/cliproxy-usage-syncer.js.map +1 -0
  129. package/dist/web-server/usage/cliproxy-usage-transformer.d.ts +26 -0
  130. package/dist/web-server/usage/cliproxy-usage-transformer.d.ts.map +1 -0
  131. package/dist/web-server/usage/cliproxy-usage-transformer.js +141 -0
  132. package/dist/web-server/usage/cliproxy-usage-transformer.js.map +1 -0
  133. package/dist/web-server/usage/disk-cache.d.ts.map +1 -1
  134. package/dist/web-server/usage/disk-cache.js +2 -1
  135. package/dist/web-server/usage/disk-cache.js.map +1 -1
  136. package/dist/web-server/usage/handlers.d.ts +1 -1
  137. package/dist/web-server/usage/handlers.d.ts.map +1 -1
  138. package/dist/web-server/usage/handlers.js +8 -3
  139. package/dist/web-server/usage/handlers.js.map +1 -1
  140. package/package.json +1 -1
  141. package/dist/ui/assets/accounts-p8Gb9myI.js +0 -1
  142. package/dist/ui/assets/api-Bw82I4NV.js +0 -1
  143. package/dist/ui/assets/auth-section-CswwM0bu.js +0 -1
  144. package/dist/ui/assets/backups-section-6slvPh7p.js +0 -1
  145. package/dist/ui/assets/cliproxy-BxWh_a8E.js +0 -3
  146. package/dist/ui/assets/cliproxy-control-panel-BEaTM1tV.js +0 -1
  147. package/dist/ui/assets/copilot-C2ADI_mS.js +0 -3
  148. package/dist/ui/assets/cursor-BzUnxDMC.js +0 -1
  149. package/dist/ui/assets/droid-BOC3J2_I.js +0 -2
  150. package/dist/ui/assets/globalenv-section-Caco9nNS.js +0 -1
  151. package/dist/ui/assets/health-Cn_YNAry.js +0 -1
  152. package/dist/ui/assets/index-0LBl1v7D.js +0 -1
  153. package/dist/ui/assets/index-B_ON5mBa.js +0 -1
  154. package/dist/ui/assets/index-CVKOwyBR.js +0 -1
  155. package/dist/ui/assets/index-CnAQ8t2b.js +0 -1
  156. package/dist/ui/assets/index-DNFjYwGe.js +0 -47
  157. package/dist/ui/assets/proxy-status-widget-B31OXK00.js +0 -1
  158. package/dist/ui/assets/shared-k-J_KXcM.js +0 -8
  159. package/dist/ui/assets/updates-CYChhYqV.js +0 -1
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-C1Gpgz6I.js";import{r as p}from"./react-vendor-CNOkPC89.js";import{t as o}from"./notifications-B2HqRBj7.js";import{aV as v,aW as Ye,B as D,b as f,c as ie,m as E,O as Ze,Q as $e,R as W,U as ee,L as P,I as se,aY as We,a5 as es,a6 as ss,a7 as ts,a8 as as,a9 as ns,an as rs,q as is,r as os,s as ls,t as cs,al as ds,am as us,v as be,aX as ms}from"./index-DNFjYwGe.js";import{a as hs,u as q,b as _}from"./tanstack-DDJIhNJd.js";import{D as Ae}from"./default-ports-1QQSffYX.js";import{S as Ce}from"./switch-B3t2TDvW.js";import{S as xs}from"./separator-51ocJFnp.js";import{R as Se,T as fs,az as ps,K as G,a5 as gs,ay as ke,ax as js,L as M,t as ws,ai as vs,a1 as ys,Z as te,al as Ns,r as bs,s as Cs}from"./icons-DrewC9c3.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";async function Ss(){const s=await fetch(v("/cursor/status"));if(!s.ok)throw new Error("Failed to fetch cursor status");return s.json()}async function ks(){const s=await fetch(v("/cursor/settings"));if(!s.ok)throw new Error("Failed to fetch cursor config");return s.json()}async function As(){const s=await fetch(v("/cursor/models"));if(!s.ok)throw new Error("Failed to fetch cursor models");return s.json()}async function Ds(){const s=await fetch(v("/cursor/settings/raw"));if(!s.ok)throw new Error("Failed to fetch cursor raw settings");return s.json()}async function _s(s){const a=await fetch(v("/cursor/settings"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!a.ok)throw new Error("Failed to update cursor config");return a.json()}async function Ms(s){const a=await fetch(v("/cursor/settings/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(a.status===409)throw new Ye("Cursor raw settings changed externally");if(!a.ok)throw new Error("Failed to save cursor raw settings");return a.json()}async function Ps(){const s=await fetch(v("/cursor/auth/auto-detect"),{method:"POST"});if(!s.ok){const a=await s.json().catch(()=>({error:"Auto-detect failed"}));throw new Error(a.error||"Auto-detect failed")}return s.json()}async function Ts(s){const a=await fetch(v("/cursor/auth/import"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!a.ok){const d=await a.json().catch(()=>({error:"Manual import failed"}));throw new Error(d.error||"Manual import failed")}return a.json()}async function Fs(){const s=await fetch(v("/cursor/daemon/start"),{method:"POST"});if(!s.ok)throw new Error("Failed to start cursor daemon");return s.json()}async function Rs(){const s=await fetch(v("/cursor/daemon/stop"),{method:"POST"});if(!s.ok)throw new Error("Failed to stop cursor daemon");return s.json()}function Os(){const s=hs(),a=q({queryKey:["cursor-status"],queryFn:Ss,refetchInterval:5e3}),d=q({queryKey:["cursor-config"],queryFn:ks}),u=q({queryKey:["cursor-models"],queryFn:As}),m=q({queryKey:["cursor-raw-settings"],queryFn:Ds}),l=()=>{s.invalidateQueries({queryKey:["cursor-status"]}),s.invalidateQueries({queryKey:["cursor-config"]}),s.invalidateQueries({queryKey:["cursor-models"]}),s.invalidateQueries({queryKey:["cursor-raw-settings"]})},n=_({mutationFn:_s,onSuccess:l}),c=_({mutationFn:Ms,onSuccess:l}),h=_({mutationFn:Ps,onSuccess:l}),i=_({mutationFn:Ts,onSuccess:l}),y=_({mutationFn:Fs,onSuccess:l}),C=_({mutationFn:Rs,onSuccess:l});return p.useMemo(()=>({status:a.data,statusLoading:a.isLoading,statusError:a.error,refetchStatus:a.refetch,config:d.data,configLoading:d.isLoading,models:u.data?.models??[],currentModel:u.data?.current??null,modelsLoading:u.isLoading,rawSettings:m.data,rawSettingsLoading:m.isLoading,refetchRawSettings:m.refetch,updateConfig:n.mutate,updateConfigAsync:n.mutateAsync,isUpdatingConfig:n.isPending,saveRawSettings:c.mutate,saveRawSettingsAsync:c.mutateAsync,isSavingRawSettings:c.isPending,autoDetectAuth:h.mutate,autoDetectAuthAsync:h.mutateAsync,isAutoDetectingAuth:h.isPending,autoDetectAuthResult:h.data,importManualAuth:i.mutate,importManualAuthAsync:i.mutateAsync,isImportingManualAuth:i.isPending,manualAuthResult:i.data,startDaemon:y.mutate,startDaemonAsync:y.mutateAsync,isStartingDaemon:y.isPending,stopDaemon:C.mutate,stopDaemonAsync:C.mutateAsync,isStoppingDaemon:C.isPending}),[a.data,a.isLoading,a.error,a.refetch,d.data,d.isLoading,u.data,u.isLoading,m.data,m.isLoading,m.refetch,n.mutate,n.mutateAsync,n.isPending,c.mutate,c.mutateAsync,c.isPending,h.mutate,h.mutateAsync,h.isPending,h.data,i.mutate,i.mutateAsync,i.isPending,i.data,y.mutate,y.mutateAsync,y.isPending,C.mutate,C.mutateAsync,C.isPending])}function ae(s){return{port:String(s?.port??Ae),auto_start:s?.auto_start??!1,ghost_mode:s?.ghost_mode??!0,model:s?.model?.trim()||"gpt-5.3-codex",opus_model:s?.opus_model?.trim()||"",sonnet_model:s?.sonnet_model?.trim()||"",haiku_model:s?.haiku_model?.trim()||""}}function N(s,a,d){return s.find(m=>a.some(l=>l.test(m.id)))?.id??d}function ne(s){return s.toLowerCase().replace(/[^a-z0-9]/g,"")}function b(s,a,d){const u=new Set(a.map(ne)),m=s.find(n=>u.has(ne(n.id)));if(m)return m.id;const l=s.find(n=>u.has(ne(n.name)));return l?l.id:d}function Is(s){try{const a=JSON.parse(s||"{}");return!a||typeof a!="object"||Array.isArray(a)?{isValid:!1,error:"Raw settings must be a JSON object"}:{isValid:!0,settings:a}}catch(a){return{isValid:!1,error:a.message||"Invalid JSON"}}}function U({label:s,description:a,value:d,models:u,disabled:m,allowDefaultFallback:l=!1,onChange:n}){const c=d||(l?"__default":""),h=u.find(i=>i.id===d);return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{children:[e.jsx(P,{className:"text-xs font-medium",children:s}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:a})]}),e.jsxs(is,{value:c,onValueChange:i=>{if(l&&i==="__default"){n("");return}n(i)},disabled:m,children:[e.jsx(os,{className:"h-9",children:e.jsx(ls,{placeholder:"Select model",children:c&&e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"truncate font-mono text-xs",children:l&&c==="__default"?"Use Default Model":h?.name||c}),h?.provider&&e.jsx(D,{variant:"outline",className:"text-[9px] h-4 px-1 capitalize",children:h.provider})]})})}),e.jsx(cs,{className:"max-h-[300px]",children:e.jsxs(ds,{children:[e.jsxs(us,{className:"text-xs text-muted-foreground",children:["Available Models (",u.length,")"]}),l&&e.jsx(be,{value:"__default",children:"Use Default Model"}),u.map(i=>e.jsx(be,{value:i.id,children:e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"truncate text-xs font-mono",children:i.name||i.id}),e.jsx(D,{variant:"outline",className:"text-[9px] h-4 px-1 capitalize",children:i.provider})]})},i.id))]})})]})]})}function re({icon:s,label:a,ok:d,detail:u}){return e.jsxs("div",{className:"flex items-center gap-3 rounded-lg bg-muted/50 px-3 py-2",children:[e.jsx(s,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsx("p",{className:"text-sm",children:a})}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[d?e.jsx(bs,{className:"h-4 w-4 text-green-500"}):e.jsx(Cs,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:ie("text-xs",d?"text-green-500":"text-muted-foreground"),title:u,children:u})]})]})}function Xs(){const{status:s,statusLoading:a,refetchStatus:d,config:u,updateConfigAsync:m,isUpdatingConfig:l,models:n,modelsLoading:c,currentModel:h,rawSettings:i,rawSettingsLoading:y,refetchRawSettings:C,saveRawSettingsAsync:De,isSavingRawSettings:oe,autoDetectAuthAsync:_e,isAutoDetectingAuth:le,importManualAuthAsync:Me,isImportingManualAuth:ce,startDaemonAsync:Pe,isStartingDaemon:Te,stopDaemonAsync:Fe,isStoppingDaemon:de}=Os(),[A,ue]=p.useState(()=>ae()),[g,me]=p.useState(!1),[he,Re]=p.useState("{}"),[T,z]=p.useState(!1),[Oe,O]=p.useState(!1),[B,xe]=p.useState(""),[J,fe]=p.useState(""),S=ae(u),pe=g?A.port:S.port,K=g?A.auto_start:S.auto_start,Q=g?A.ghost_mode:S.ghost_mode,j=g?A.model:S.model,H=g?A.opus_model:S.opus_model,V=g?A.sonnet_model:S.sonnet_model,X=g?A.haiku_model:S.haiku_model,Y=T?he:JSON.stringify(i?.settings??{},null,2),ge=!!i,F=p.useMemo(()=>Is(Y),[Y]),je=F.isValid,we=g||T,Ie=!T||ge&&je,I=p.useMemo(()=>{const t=new Set,r=[...n].sort((k,$)=>k.name.localeCompare($.name)),x=r.filter(k=>t.has(k.id)?!1:(t.add(k.id),!0));return j&&!r.some(k=>k.id===j)?[{id:j,name:j,provider:"custom"},...x]:x},[n,j]),w=t=>{ue(r=>t(g?r:S)),me(!0)},Le=!!(s?.enabled&&s?.authenticated&&!s?.token_expired),Ee=p.useMemo(()=>s?.enabled?e.jsx(D,{children:"Enabled"}):e.jsx(D,{variant:"secondary",children:"Disabled"}),[s?.enabled]),qe=async({suppressSuccessToast:t=!1}={})=>{const r=Number(pe);if(!Number.isInteger(r)||r<1||r>65535)return o.error("Port must be an integer between 1 and 65535"),!1;if(!j.trim())return o.error("Default model is required"),!1;try{return await m({port:r,auto_start:K,ghost_mode:Q,model:j,opus_model:H||void 0,sonnet_model:V||void 0,haiku_model:X||void 0}),me(!1),ue(ae({port:r,auto_start:K,ghost_mode:Q,model:j,opus_model:H||void 0,sonnet_model:V||void 0,haiku_model:X||void 0})),t||o.success("Cursor config and model mapping saved"),!0}catch(x){return o.error(x.message||"Failed to save config"),!1}},Z=t=>{if(c){o.error("Models are still loading. Please wait before applying a preset.");return}if(n.length===0){o.error("No models available yet. Start the daemon and refresh first.");return}const r=j||h||n[0]?.id||"gpt-5.3-codex",x=b(n,["gpt-5.3-codex","gpt53codex","GPT-5.3 Codex"],N(n,[/gpt[-.]?5.*codex/i],r)),k=b(n,["gpt-5.1-codex-max","gpt51codexmax","GPT-5.1 Codex Max"],N(n,[/gpt[-.]?5.*codex.*max/i],x)),$=b(n,["gpt-5-fast","gpt5fast","GPT-5 Fast"],N(n,[/gpt[-.]?5.*fast/i],x)),He=b(n,["gpt-5-mini","gpt5mini","GPT-5 Mini"],N(n,[/gpt[-.]?5.*mini/i],$)),ye=b(n,["claude-4.6-opus","claude46opus","Claude 4.6 Opus"],N(n,[/claude[-.]?4\.?6.*opus/i,/claude.*opus/i],x)),Ne=b(n,["claude-4.5-sonnet","claude45sonnet","Claude 4.5 Sonnet"],N(n,[/claude[-.]?4\.?5.*sonnet/i,/claude.*sonnet/i],x)),Ve=b(n,["claude-4.5-haiku","claude45haiku","Claude 4.5 Haiku"],N(n,[/claude[-.]?4\.?5.*haiku/i,/haiku/i],Ne)),L=b(n,["gemini-3-pro","gemini3pro","Gemini 3 Pro"],N(n,[/gemini[-.]?3.*pro/i],x)),Xe=b(n,["gemini-3-flash","gemini3flash","Gemini 3 Flash"],N(n,[/gemini[-.]?3.*flash/i,/gemini[-.]?2\.?5.*flash/i],L));if(t==="codex53"){w(R=>({...R,model:x,opus_model:k,sonnet_model:x,haiku_model:He})),o.success("Applied GPT-5.3 Codex preset");return}if(t==="claude46"){w(R=>({...R,model:ye,opus_model:ye,sonnet_model:Ne,haiku_model:Ve})),o.success("Applied Claude 4.6 preset");return}w(R=>({...R,model:L,opus_model:L,sonnet_model:L,haiku_model:Xe})),o.success("Applied Gemini 3 preset")},ve=async t=>{try{await m({enabled:t}),o.success(t?"Cursor integration enabled":"Cursor integration disabled")}catch(r){o.error(r.message||"Failed to update integration state")}},Ge=async()=>{try{await _e(),o.success("Cursor credentials imported")}catch(t){o.error(t.message||"Auto-detect failed")}},Ue=async()=>{if(!B.trim()||!J.trim()){o.error("Token and machine ID are required");return}try{await Me({accessToken:B.trim(),machineId:J.trim()}),o.success("Cursor credentials imported"),O(!1),xe(""),fe("")}catch(t){o.error(t.message||"Manual import failed")}},ze=async()=>{try{const t=await Pe();if(!t.success){o.error(t.error||"Failed to start daemon");return}o.success(`Daemon started${t.pid?` (PID: ${t.pid})`:""}`)}catch(t){o.error(t.message||"Failed to start daemon")}},Be=async()=>{try{const t=await Fe();if(!t.success){o.error(t.error||"Failed to stop daemon");return}o.success("Daemon stopped")}catch(t){o.error(t.message||"Failed to stop daemon")}},Je=async({suppressSuccessToast:t=!1}={})=>{if(!ge)return o.error("Raw settings are still loading. Please wait and try again."),!1;if(!F.isValid||!F.settings)return o.error(F.error||"Invalid JSON"),!1;try{return await De({settings:F.settings,expectedMtime:i?.mtime}),z(!1),t||o.success("Raw settings saved"),!0}catch(r){return ms(r)?o.error("Raw settings changed externally. Refresh and retry."):o.error(r.message||"Failed to save raw settings"),!1}},Ke=async()=>{if(!we)return;const t=g,r=T;t&&!await qe({suppressSuccessToast:r})||r&&!await Je({suppressSuccessToast:t})||t&&r&&o.success("Cursor configuration saved")},Qe=()=>{z(!1),d(),C()};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"h-[calc(100vh-100px)] flex",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("img",{src:"/assets/sidebar/cursor.svg",alt:"",className:"w-5 h-5 object-contain shrink-0"}),e.jsx("h1",{className:"font-semibold",children:"Cursor"}),e.jsx(D,{variant:"outline",className:"h-5 border-amber-500/60 bg-amber-500/10 px-1.5 text-[10px] font-semibold uppercase tracking-wide text-amber-800 dark:text-amber-300",children:"Beta"}),Ee]}),e.jsx(f,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>d(),disabled:a,children:e.jsx(Se,{className:ie("w-4 h-4",a&&"animate-spin")})})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Dedicated Cursor integration controls"})]}),e.jsx(E,{className:"flex-1",children: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(fs,{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:"Unofficial API - Use at Your Own Risk"})]}),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:"Reverse-engineered integration may break anytime"}),e.jsx("li",{children:"Abuse or excessive usage may risk account restrictions"}),e.jsx("li",{children:"No warranty, no responsibility from CCS"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(re,{icon:ps,label:"Integration",ok:!!s?.enabled,detail:s?.enabled?"Enabled":"Disabled"}),e.jsx(re,{icon:G,label:"Authentication",ok:!!(s?.authenticated&&!s?.token_expired),detail:s?.authenticated?s?.token_expired?"Expired":s.auth_method??"Connected":"Not connected"}),e.jsx(re,{icon:gs,label:"Daemon",ok:!!s?.daemon_running,detail:s?.daemon_running?"Running":"Stopped"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"Actions"}),s?.enabled?e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",onClick:()=>ve(!1),disabled:l,children:[e.jsx(ke,{className:"w-3.5 h-3.5 mr-1.5"}),"Disable Integration"]}):e.jsxs(f,{size:"sm",className:"w-full",onClick:()=>ve(!0),disabled:l,children:[e.jsx(js,{className:"w-3.5 h-3.5 mr-1.5"}),"Enable Integration"]}),e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",onClick:Ge,disabled:le,children:[le?e.jsx(M,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}):e.jsx(G,{className:"w-3.5 h-3.5 mr-1.5"}),"Auto-detect Auth"]}),e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",onClick:()=>O(!0),children:[e.jsx(G,{className:"w-3.5 h-3.5 mr-1.5"}),"Manual Auth Import"]}),s?.daemon_running?e.jsxs(f,{variant:"outline",size:"sm",className:"w-full",onClick:Be,disabled:de,children:[de?e.jsx(M,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}):e.jsx(ke,{className:"w-3.5 h-3.5 mr-1.5"}),"Stop Daemon"]}):e.jsxs(f,{size:"sm",className:"w-full",onClick:ze,disabled:!Le,children:[Te?e.jsx(M,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}):e.jsx(ws,{className:"w-3.5 h-3.5 mr-1.5"}),"Start Daemon"]})]})]})}),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:"Port"}),e.jsx("span",{children:s?.port??u?.port??Ae})]})})]}),e.jsx("div",{className:"flex-1 flex flex-col min-w-0 bg-background overflow-hidden",children:e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[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:"Cursor Configuration"}),i&&e.jsx(D,{variant:"outline",className:"text-xs",children:"cursor.settings.json"})]}),i&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-0.5",children:["Last modified:"," ",i.exists?new Date(i.mtime).toLocaleString():"Never saved"]})]})}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:"ghost",size:"sm",onClick:Qe,disabled:a||y,children:e.jsx(Se,{className:ie("w-4 h-4",(a||y)&&"animate-spin")})}),e.jsx(f,{size:"sm",onClick:Ke,disabled:l||oe||!we||!Ie,children:l||oe?e.jsxs(e.Fragment,{children:[e.jsx(M,{className:"w-4 h-4 mr-1 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(vs,{className:"w-4 h-4 mr-1"}),"Save"]})})]})]}),e.jsxs("div",{className:"flex-1 min-h-0 flex divide-x overflow-hidden",children:[e.jsx("div",{className:"w-[540px] shrink-0 flex flex-col min-h-0 overflow-hidden bg-muted/5",children:e.jsxs(Ze,{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(W,{value:"config",className:"flex-1",children:"Model Config"}),e.jsx(W,{value:"settings",className:"flex-1",children:"Settings"}),e.jsx(W,{value:"info",className:"flex-1",children:"Info"})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:[e.jsx(ee,{value:"config",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(E,{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(ys,{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:"flex flex-wrap gap-2",children:[e.jsxs(f,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>Z("codex53"),disabled:c||n.length===0,title:"OpenAI-only mapping: GPT-5.3 Codex / Codex Max / GPT-5 Mini",children:[e.jsx(te,{className:"w-3 h-3"}),"GPT-5.3 Codex"]}),e.jsxs(f,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>Z("claude46"),disabled:c||n.length===0,title:"Claude-first mapping: Opus 4.6 / Sonnet 4.5 / Haiku 4.5",children:[e.jsx(te,{className:"w-3 h-3"}),"Claude 4.6"]}),e.jsxs(f,{variant:"outline",size:"sm",className:"text-xs h-7 gap-1",onClick:()=>Z("gemini3"),disabled:c||n.length===0,title:"Gemini-first mapping: Gemini 3 Pro + Gemini 3 Flash",children:[e.jsx(te,{className:"w-3 h-3"}),"Gemini 3 Pro"]})]})]}),e.jsx(xs,{}),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:"space-y-4",children:[e.jsx(U,{label:"Default Model",description:"Used when no specific tier is requested.",value:j,models:I,disabled:c,onChange:t=>{w(r=>({...r,model:t}))}}),e.jsx(U,{label:"Opus (Most capable)",description:"Complex reasoning and highest quality responses.",value:H,models:I,disabled:c,allowDefaultFallback:!0,onChange:t=>{w(r=>({...r,opus_model:t}))}}),e.jsx(U,{label:"Sonnet (Balanced)",description:"General coding and day-to-day chat workloads.",value:V,models:I,disabled:c,allowDefaultFallback:!0,onChange:t=>{w(r=>({...r,sonnet_model:t}))}}),e.jsx(U,{label:"Haiku (Fast)",description:"Low-latency and lightweight request paths.",value:X,models:I,disabled:c,allowDefaultFallback:!0,onChange:t=>{w(r=>({...r,haiku_model:t}))}})]})]})]})})}),e.jsx(ee,{value:"settings",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(E,{className:"flex-1",children:e.jsx("div",{className:"p-4 space-y-6",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-sm font-medium",children:"Runtime Settings"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"cursor-port",className:"text-xs",children:"Port"}),e.jsx(se,{id:"cursor-port",type:"number",min:1,max:65535,className:"max-w-[150px] h-8",value:pe,onChange:t=>{w(r=>({...r,port:t.target.value}))}})]}),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(P,{htmlFor:"cursor-auto-start",className:"text-xs",children:"Auto-start Daemon"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Start Cursor daemon automatically when integration is used."})]}),e.jsx(Ce,{id:"cursor-auto-start",checked:K,onCheckedChange:t=>{w(r=>({...r,auto_start:t}))}})]}),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(P,{htmlFor:"cursor-ghost-mode",className:"text-xs",children:"Ghost Mode"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Request `x-ghost-mode` to reduce telemetry."})]}),e.jsx(Ce,{id:"cursor-ghost-mode",checked:Q,onCheckedChange:t=>{w(r=>({...r,ghost_mode:t}))}})]})]})})})}),e.jsx(ee,{value:"info",className:"flex-1 mt-0 border-0 p-0 data-[state=inactive]:hidden flex flex-col overflow-hidden",children:e.jsx(E,{className:"flex-1",children:e.jsxs("div",{className:"p-4 space-y-6",children:[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:"Cursor IDE"})]}),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.jsx("code",{className:"bg-muted px-1.5 py-0.5 rounded text-xs break-all",children:i?.path??"~/.ccs/cursor.settings.json"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Model mapping writes `ANTHROPIC_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_HAIKU_MODEL` in `cursor.settings.json`."})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Available Models"}),c?e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(M,{className:"w-4 h-4 animate-spin"}),"Loading models..."]}):n.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No model metadata available yet. Start daemon and refresh."}):e.jsx("div",{className:"space-y-2",children:n.map(t=>e.jsxs("div",{className:"rounded-lg border px-3 py-2 flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:t.id}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.name," • ",t.provider]})]}),t.id===h&&e.jsx(D,{children:"Default"})]},t.id))})]})]})})})]})]})}),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(Ns,{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(We,{rawJsonContent:Y,isRawJsonValid:je,rawJsonEdits:T?he:null,rawSettingsEnv:i?.settings?.env,onChange:t=>{z(!0),Re(t)}})]})]})]})})]}),e.jsx(es,{open:Oe,onOpenChange:O,children:e.jsxs(ss,{children:[e.jsxs(ts,{children:[e.jsx(as,{children:"Manual Cursor Auth Import"}),e.jsx(ns,{children:"Provide Cursor access token and machine ID if auto-detect is unavailable."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"cursor-manual-token",children:"Access Token"}),e.jsx(se,{id:"cursor-manual-token",value:B,onChange:t=>xe(t.target.value),placeholder:"Paste Cursor access token"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(P,{htmlFor:"cursor-manual-machine-id",children:"Machine ID"}),e.jsx(se,{id:"cursor-manual-machine-id",value:J,onChange:t=>fe(t.target.value),placeholder:"32-char hex (UUID without hyphens)"})]})]}),e.jsxs(rs,{children:[e.jsx(f,{variant:"outline",onClick:()=>O(!1),children:"Cancel"}),e.jsxs(f,{onClick:Ue,disabled:ce,children:[ce?e.jsx(M,{className:"w-4 h-4 mr-2 animate-spin"}):e.jsx(G,{className:"w-4 h-4 mr-2"}),"Import"]})]})]})})]})}export{Xs as CursorPage};
@@ -1,2 +0,0 @@
1
- import{j as e}from"./radix-ui-C1Gpgz6I.js";import{r as F}from"./react-vendor-CNOkPC89.js";import{t as g}from"./notifications-B2HqRBj7.js";import{aV as ee,aW as we,B as S,b as V,c as le,aZ as ke,C as b,i as v,j as y,a as N,q as H,r as Q,s as W,t as G,v as k,I as ce,a_ as Se,a$ as ae,b0 as Ce,O as Ee,Q as Te,R as z,U as $,m as _,aX as Ae}from"./index-DNFjYwGe.js";import{a as Re,u as ie,b as Oe}from"./tanstack-DDJIhNJd.js";import{aA as De,L as X,ai as _e,m as Be,R as Me,aB as Fe,aC as Ke,v as Le,S as Pe,aD as Ie,r as Ue,s as Ve,T as ze,a5 as $e,az as Je,n as oe}from"./icons-DrewC9c3.js";import{S as B}from"./separator-51ocJFnp.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function Ye(s){try{const t=JSON.parse(s);return!t||typeof t!="object"||Array.isArray(t)?{settings:null,parseError:"JSON root must be an object."}:{settings:t,parseError:null}}catch(t){return{settings:null,parseError:t.message}}}async function qe(){const s=await fetch(ee("/droid/diagnostics"));if(!s.ok)throw new Error("Failed to fetch Droid diagnostics");return s.json()}async function He(){const s=await fetch(ee("/droid/settings/raw"));if(!s.ok)throw new Error("Failed to fetch Droid raw settings");return s.json()}async function Qe(s){const t=await fetch(ee("/droid/settings/raw"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(t.status===409)throw new we("Droid raw settings changed externally");if(!t.ok){const r=await t.json().catch(()=>null);throw new Error(r?.error||"Failed to save Droid raw settings")}return t.json()}function We(){const s=Re(),t=ie({queryKey:["droid-diagnostics"],queryFn:qe,refetchInterval:1e4}),r=ie({queryKey:["droid-raw-settings"],queryFn:He}),l=Oe({mutationFn:Qe,onSuccess:(i,c)=>{s.setQueryData(["droid-raw-settings"],n=>{const a=n?.path??"~/.factory/settings.json",u=n?.resolvedPath??a,m=Ye(c.rawText);return{path:a,resolvedPath:u,exists:!0,mtime:i.mtime,rawText:c.rawText,settings:m.settings,parseError:m.parseError}}),s.invalidateQueries({queryKey:["droid-diagnostics"]})}});return F.useMemo(()=>({diagnostics:t.data,diagnosticsLoading:t.isLoading,diagnosticsError:t.error,refetchDiagnostics:t.refetch,rawSettings:r.data,rawSettingsLoading:r.isLoading,rawSettingsError:r.error,refetchRawSettings:r.refetch,saveRawSettings:l.mutate,saveRawSettingsAsync:l.mutateAsync,isSavingRawSettings:l.isPending}),[t.data,t.isLoading,t.error,t.refetch,r.data,r.isLoading,r.error,r.refetch,l.mutate,l.mutateAsync,l.isPending])}function Ge({title:s,pathLabel:t,loading:r,parseWarning:l,value:i,dirty:c,saving:n,saveDisabled:a,onChange:u,onSave:m,onRefresh:T}){const[A,C]=F.useState(!1),D=async()=>{i&&(await navigator.clipboard.writeText(i),C(!0),g.success("Settings copied to clipboard"),window.setTimeout(()=>C(!1),1500))};return e.jsxs("div",{className:"h-full flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b bg-background flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("h2",{className:"font-semibold flex items-center gap-2",children:[e.jsx(De,{className:"h-4 w-4 text-primary"}),s,c&&e.jsx(S,{variant:"secondary",className:"text-[10px]",children:"Unsaved"})]}),e.jsx("p",{className:"text-xs text-muted-foreground font-mono truncate",children:t})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(V,{size:"sm",onClick:m,disabled:a,children:[n?e.jsx(X,{className:"h-4 w-4 mr-1 animate-spin"}):e.jsx(_e,{className:"h-4 w-4 mr-1"}),"Save"]}),e.jsxs(V,{variant:"outline",size:"sm",onClick:D,disabled:!i,children:[e.jsx(Be,{className:"h-4 w-4 mr-1"}),A?"Copied":"Copy"]}),e.jsx(V,{variant:"outline",size:"sm",onClick:T,children:e.jsx(Me,{className:le("h-4 w-4",r?"animate-spin":"")})})]})]}),e.jsx("div",{className:"flex-1 overflow-auto",children:r?e.jsxs("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:[e.jsx(X,{className:"h-5 w-5 animate-spin mr-2"}),"Loading settings.json..."]}):e.jsxs("div",{className:"h-full flex flex-col",children:[l&&e.jsxs("div",{className:"mx-4 mt-4 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-sm text-amber-800 dark:bg-amber-950/20 dark:text-amber-300",children:["Parse warning: ",l]}),e.jsx("div",{className:"flex-1 p-4 pt-3",children:e.jsx("div",{className:"h-full rounded-md border overflow-hidden bg-background",children:e.jsx(ke,{value:i,onChange:u,language:"json",minHeight:"100%"})})})]})})]})}const Xe=["customModels","custom_models"],Ze={low:4e3,medium:12e3,high:3e4,max:5e4,xhigh:64e3},es=["low","medium","high","max","xhigh"];function p(s){return typeof s=="object"&&s!==null&&!Array.isArray(s)}function j(s){return typeof s=="string"&&s.trim()?s.trim():null}function K(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function Z(s){if(!s)return"unknown";const t=s.toLowerCase();return t==="anthropic"?"anthropic":t==="openai"?"openai":t==="generic-chat-completion-api"?"generic-chat-completion-api":"unknown"}function ss(s,t,r){return`${s}:${t}:${encodeURIComponent(String(r))}`}function ts(s){const t=s.indexOf(":"),r=s.indexOf(":",t+1);if(t<=0||r<=t+1)return null;const l=s.slice(0,t),i=s.slice(t+1,r),c=s.slice(r+1);if(l!=="customModels"&&l!=="custom_models"||i!=="array"&&i!=="object")return null;const n=decodeURIComponent(c);if(i==="array"){const a=Number.parseInt(n,10);return!Number.isInteger(a)||a<0?null:{rootKey:l,locationType:i,locationKey:a}}return{rootKey:l,locationType:i,locationKey:n}}function rs(s){return!s||s<=0?null:s<=4e3?"low":s<=12e3?"medium":s<=3e4?"high":s<=5e4?"max":"xhigh"}function ns(s){return Object.prototype.hasOwnProperty.call(s,"extraArgs")?"extraArgs":Object.prototype.hasOwnProperty.call(s,"extra_args")?"extra_args":"extraArgs"}function de(s){return JSON.parse(JSON.stringify(s))}function as(s){const t=[];for(const r of Xe){const l=s[r];if(Array.isArray(l)){l.forEach((i,c)=>{p(i)&&t.push({rootKey:r,locationType:"array",locationKey:c,entry:i})});continue}if(p(l))for(const[i,c]of Object.entries(l))p(c)&&t.push({rootKey:r,locationType:"object",locationKey:i,entry:c})}return t}function ue(s,t){const r=ts(t);if(!r)return null;const l=s[r.rootKey];if(r.locationType==="array"){if(!Array.isArray(l))return null;const n=l[r.locationKey];if(!p(n))return null;const a=j(n.provider);return{entry:n,providerKind:Z(a)}}if(!p(l))return null;const i=l[r.locationKey];if(!p(i))return null;const c=j(i.provider);return{entry:i,providerKind:Z(c)}}function is(s,t){const r=t.extraArgs??t.extra_args,l=p(r)?r:null;if(!l)return{effort:null,anthropicBudgetTokens:null};const i=j(l.reasoning_effort)??j(l.reasoningEffort),c=p(l.reasoning)?l.reasoning:null,n=c?j(c.effort):null,a=p(l.thinking)?l.thinking:null,u=a?j(a.type):null,m=a?K(a.budget_tokens)??K(a.budgetTokens):null;return s==="openai"?{effort:n??i,anthropicBudgetTokens:null}:s==="anthropic"?u==="enabled"?{effort:rs(m)??"high",anthropicBudgetTokens:m}:{effort:n??i,anthropicBudgetTokens:m}:{effort:i??n,anthropicBudgetTokens:null}}function os(s){if(!s)return null;const t=s.trim().toLowerCase();return!t||t==="default"||t==="unset"||t==="off"||t==="none"||t==="disabled"?null:t}function me(s){const t=ns(s),r=s[t],l=p(r)?{...r}:{};return{extraArgsKey:t,extraArgs:l}}function xe(s,t,r){if(Object.keys(r).length===0){delete s[t];return}s[t]=r}function ls(s){return as(s).map(({rootKey:t,locationType:r,locationKey:l,entry:i})=>{const c=j(i.displayName)??j(i.model_display_name)??"Unnamed model",n=j(i.model)??"",a=j(i.provider)??"unknown",u=Z(a),m=is(u,i);return{id:ss(t,r,l),rootKey:t,locationType:r,locationKey:l,displayName:c,model:n,provider:a,providerKind:u,effort:m.effort,anthropicBudgetTokens:m.anthropicBudgetTokens}})}function cs(s,t,r){const l=de(s),i=ue(l,t);if(!i)return null;const c=os(r),{extraArgsKey:n,extraArgs:a}=me(i.entry);if(i.providerKind==="openai")if(delete a.reasoning_effort,delete a.reasoningEffort,!c)delete a.reasoning;else{const u=p(a.reasoning)?a.reasoning:{};a.reasoning={...u,effort:c}}else if(i.providerKind==="anthropic")if(delete a.reasoning_effort,delete a.reasoningEffort,delete a.reasoning,!c)delete a.thinking;else{const u=p(a.thinking)?{...a.thinking}:{},m=K(u.budget_tokens)??K(u.budgetTokens);delete u.budgetTokens,a.thinking={...u,type:"enabled",budget_tokens:m??Ze[c]??3e4}}else delete a.reasoning,delete a.reasoningEffort,c?a.reasoning_effort=c:delete a.reasoning_effort;return xe(i.entry,n,a),l}function ds(s,t,r){const l=de(s),i=ue(l,t);if(!i||i.providerKind!=="anthropic")return null;const{extraArgsKey:c,extraArgs:n}=me(i.entry),a=p(n.thinking)?{...n.thinking}:{};if(a.type="enabled",r===null)delete a.budget_tokens,delete a.budgetTokens;else{const u=Math.max(1024,Math.floor(r));a.budget_tokens=u,delete a.budgetTokens}return n.thinking=a,xe(i.entry,c,n),l}const J="__unset__";function us(s){return s.providerKind==="openai"?"Writes: extraArgs.reasoning.effort":s.providerKind==="anthropic"?"Writes: extraArgs.thinking.{type,budget_tokens}":"Writes: extraArgs.reasoning_effort"}function ms({models:s,disabled:t,disabledReason:r,onEffortChange:l,onAnthropicBudgetChange:i}){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(Fe,{className:"h-4 w-4"}),"BYOK Reasoning / Thinking",e.jsx(S,{variant:"outline",className:"text-[10px] font-normal",children:"customModels"})]})}),e.jsxs(N,{className:"space-y-3",children:[r&&e.jsx("p",{className:"text-xs text-amber-600",children:r}),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(c=>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:c.displayName}),e.jsx("p",{className:"text-[11px] font-mono text-muted-foreground truncate",children:c.model||"(missing model id)"})]}),e.jsx(S,{variant:"outline",className:"font-mono text-[10px] shrink-0",children:c.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:c.effort??J,onValueChange:n=>l(c.id,n===J?null:n),disabled:t,children:[e.jsx(Q,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:"Use provider default"})}),e.jsxs(G,{children:[e.jsx(k,{value:J,children:"Use provider default"}),es.map(n=>e.jsx(k,{value:n,children:n},n))]})]})]}),c.providerKind==="anthropic"&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-[11px] font-medium",children:"Thinking Budget Tokens"}),e.jsx(ce,{type:"number",min:1024,step:1024,value:c.anthropicBudgetTokens??"",placeholder:"auto",className:"h-8 text-xs",disabled:t,onChange:n=>{const a=n.target.value.trim();if(!a){i(c.id,null);return}const u=Number.parseInt(a,10);Number.isFinite(u)&&i(c.id,Math.max(1024,u))}})]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:us(c)})]},c.id))})]})]})}const O="__unset__",xs=[{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"}]}],fs=[{key:"todoEnabled",label:"Todo Enabled"},{key:"todoAutoRefresh",label:"Todo Auto Refresh"},{key:"autoCompactEnabled",label:"Auto Compact Enabled"},{key:"soundEnabled",label:"Sound Enabled"}],hs=[{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 ps(s){return s===!0?"true":s===!1?"false":O}function gs(s){return s==="true"?!0:s==="false"?!1:null}function js({values:s,disabled:t,disabledReason:r,onEnumSettingChange:l,onBooleanSettingChange:i,onNumberSettingChange:c}){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(Ke,{className:"h-4 w-4"}),"Quick Settings",e.jsx(S,{variant:"outline",className:"text-[10px] font-normal",children:"settings.json"})]})}),e.jsxs(N,{className:"space-y-4",children:[r&&e.jsx("p",{className:"text-xs text-amber-600",children:r}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[xs.map(n=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:n.label}),e.jsxs(H,{value:s[n.key]??O,onValueChange:a=>l(n.key,a===O?null:a),disabled:t,children:[e.jsx(Q,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:"Use default"})}),e.jsxs(G,{children:[e.jsx(k,{value:O,children:"Use default"}),n.options.map(a=>e.jsx(k,{value:a.value,children:a.label},a.value))]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:n.description})]},n.key)),hs.map(n=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:n.label}),e.jsx(ce,{type:"number",min:n.min,step:n.step,value:s[n.key]??"",onChange:a=>{const u=a.target.value.trim();if(!u){c(n.key,null);return}const m=Number.parseInt(u,10);Number.isFinite(m)&&c(n.key,Math.max(n.min,m))},className:"h-8 text-xs",disabled:t})]},n.key)),fs.map(n=>e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:n.label}),e.jsxs(H,{value:ps(s[n.key]),onValueChange:a=>i(n.key,gs(a)),disabled:t,children:[e.jsx(Q,{className:"h-8 text-xs",children:e.jsx(W,{placeholder:"Use default"})}),e.jsxs(G,{children:[e.jsx(k,{value:O,children:"Use default"}),e.jsx(k,{value:"true",children:"true"}),e.jsx(k,{value:"false",children:"false"})]})]})]},n.key))]})]})]})}const bs=[{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."}],vs=[{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 ys(s){const t=/https?:\/\/[^\s)]+/g,r=[];let l=0,i;for(;(i=t.exec(s))!==null;){const[c]=i,n=i.index;n>l&&r.push(s.slice(l,n)),r.push(e.jsx("a",{href:c,target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:c},`${c}-${n}`)),l=n+c.length}return l<s.length&&r.push(s.slice(l)),r.length>0?r:[s]}function Ns(s){return!s||!Number.isFinite(s)?"N/A":new Date(s).toLocaleString()}function ws(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 ks(s){try{const t=JSON.parse(s);return!t||typeof t!="object"||Array.isArray(t)?{valid:!1,error:"JSON root must be an object."}:{valid:!0,value:t}}catch(t){return{valid:!1,error:t.message}}}function Y(s){return typeof s=="string"?s:null}function q(s){return typeof s=="number"&&Number.isFinite(s)?s:null}function M(s){return typeof s=="boolean"?s:null}function f({label:s,value:t,mono:r=!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:le("text-right break-all",r&&"font-mono text-xs"),children:t})]})}function Ms(){const{diagnostics:s,diagnosticsLoading:t,diagnosticsError:r,refetchDiagnostics:l,rawSettings:i,rawSettingsLoading:c,refetchRawSettings:n,saveRawSettingsAsync:a,isSavingRawSettings:u}=We(),[m,T]=F.useState(null),A=i?.rawText??"{}",C=m??A,D=m!==null&&m!==A,d=ks(C),L=d.valid?{valid:!0}:{valid:!1,error:d.error},se=x=>{if(x===A){T(null);return}T(x)},P=x=>{se(JSON.stringify(x,null,2)+`
2
- `)},I=(x,w)=>{if(!d.valid){g.error("Fix JSON syntax before using quick settings controls.");return}const E={...d.value};w==null?delete E[x]:E[x]=w,P(E)},fe=d.valid?{reasoningEffort:Y(d.value.reasoningEffort),autonomyLevel:Y(d.value.autonomyLevel),diffMode:Y(d.value.diffMode),maxTurns:q(d.value.maxTurns),maxToolCalls:q(d.value.maxToolCalls),autoCompactThreshold:q(d.value.autoCompactThreshold),todoEnabled:M(d.value.todoEnabled),todoAutoRefresh:M(d.value.todoAutoRefresh),autoCompactEnabled:M(d.value.autoCompactEnabled),soundEnabled:M(d.value.soundEnabled)}:{reasoningEffort:null,autonomyLevel:null,diffMode:null,maxTurns:null,maxToolCalls:null,autoCompactThreshold:null,todoEnabled:null,todoAutoRefresh:null,autoCompactEnabled:null,soundEnabled:null},he=d.valid?ls(d.value):[],pe=async()=>{await Promise.all([l(),n()])},ge=async()=>{if(!L.valid){g.error(`Invalid JSON: ${L.error}`);return}try{await a({rawText:C,expectedMtime:i?.exists?i.mtime:void 0}),T(null),g.success("Droid settings saved")}catch(x){Ae(x)?g.error("Droid settings changed externally. Refresh and retry."):g.error(x.message||"Failed to save Droid settings")}},te=s?.byok.customModels??[],re=F.useMemo(()=>Object.entries(s?.byok.providerBreakdown??{}).sort((x,w)=>w[1]-x[1]),[s?.byok.providerBreakdown]),je=()=>{if(t)return e.jsxs("div",{className:"flex h-full items-center justify-center text-muted-foreground",children:[e.jsx(X,{className:"h-5 w-5 animate-spin mr-2"}),"Loading Droid diagnostics..."]});if(r||!s)return e.jsx("div",{className:"flex h-full items-center justify-center text-destructive px-6 text-center",children:"Failed to load Droid diagnostics."});const x=s.docsReference??{notes:[],links:[],providerDocs:[],providerValues:[],settingsHierarchy:[]},w=x.notes??[],E=x.links??[],ne=x.providerDocs??[],be=E.length>0?E:bs,ve=ne.length>0?ne:vs,ye=x.providerValues??[],Ne=x.settingsHierarchy??[],U="mt-0 h-full border-0 p-0 data-[state=inactive]:hidden";return e.jsxs(Ee,{defaultValue:"byok",className:"h-full flex flex-col",children:[e.jsx("div",{className:"px-4 pt-4 shrink-0",children:e.jsxs(Te,{className:"grid w-full grid-cols-3",children:[e.jsx(z,{value:"overview",children:"Overview"}),e.jsx(z,{value:"byok",children:"BYOK"}),e.jsx(z,{value:"docs",children:"Docs"})]})}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-hidden px-4 pb-4 pt-3",children:[e.jsx($,{value:"overview",className:U,children:e.jsx(_,{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(Pe,{className:"h-4 w-4"}),"Runtime & Installation"]})}),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:"Status"}),e.jsx(S,{variant:s.binary.installed?"default":"secondary",children:s.binary.installed?"Detected":"Not Found"})]}),e.jsx(f,{label:"Detection source",value:s.binary.source,mono:!0}),e.jsx(f,{label:"Binary path",value:s.binary.path||"Not detected",mono:!0}),e.jsx(f,{label:"Install directory",value:s.binary.installDir||"N/A",mono:!0}),e.jsx(f,{label:"Version",value:s.binary.version||"Unknown",mono:!0}),e.jsx(f,{label:"Override (CCS_DROID_PATH)",value:s.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(Ie,{className:"h-4 w-4"}),"Config Files"]})}),e.jsx(N,{className:"space-y-3",children:[s.files.settings,s.files.legacyConfig].map(o=>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:o.label}),o.exists?e.jsx(Ue,{className:"h-4 w-4 text-green-600"}):e.jsx(Ve,{className:"h-4 w-4 text-muted-foreground"})]}),e.jsx(f,{label:"Path",value:o.path,mono:!0}),e.jsx(f,{label:"Resolved",value:o.resolvedPath,mono:!0}),e.jsx(f,{label:"Size",value:ws(o.sizeBytes)}),e.jsx(f,{label:"Last modified",value:Ns(o.mtimeMs)}),o.parseError&&e.jsxs("p",{className:"text-xs text-amber-600",children:["Parse warning: ",o.parseError]}),o.readError&&e.jsxs("p",{className:"text-xs text-destructive",children:["Read warning: ",o.readError]})]},o.label))})]}),s.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(ze,{className:"h-4 w-4 text-amber-600"}),"Warnings"]})}),e.jsx(N,{className:"space-y-1.5",children:s.warnings.map(o=>e.jsxs("p",{className:"text-sm text-amber-800 dark:text-amber-300",children:["- ",o]},o))})]})]})})}),e.jsx($,{value:"byok",className:U,children:e.jsx(_,{className:"h-full",children:e.jsxs("div",{className:"space-y-4 pr-1",children:[e.jsx(js,{values:fe,disabled:c||!d.valid,disabledReason:d.valid?null:`Quick settings disabled: ${d.error}`,onEnumSettingChange:(o,h)=>{I(o,h)},onBooleanSettingChange:(o,h)=>{I(o,h)},onNumberSettingChange:(o,h)=>{I(o,h)}}),e.jsx(ms,{models:he,disabled:c||!d.valid,disabledReason:d.valid?null:`BYOK reasoning controls disabled: ${d.error}`,onEffortChange:(o,h)=>{if(!d.valid){g.error("Fix JSON syntax before updating BYOK reasoning settings.");return}const R=cs(d.value,o,h);if(!R){g.error("Unable to update selected BYOK model reasoning setting.");return}P(R)},onAnthropicBudgetChange:(o,h)=>{if(!d.valid){g.error("Fix JSON syntax before updating thinking budget.");return}const R=ds(d.value,o,h);if(!R){g.error("Thinking budget is only available for Anthropic BYOK models.");return}P(R)}}),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 Summary"]})}),e.jsxs(N,{className:"space-y-2",children:[e.jsx(f,{label:"Active model selector",value:s.byok.activeModelSelector||"Not set",mono:!0}),e.jsx(f,{label:"Custom models",value:String(s.byok.customModelCount)}),e.jsx(f,{label:"CCS-managed",value:String(s.byok.ccsManagedCount)}),e.jsx(f,{label:"User-managed",value:String(s.byok.userManagedCount)}),e.jsx(f,{label:"Malformed entries",value:String(s.byok.invalidModelEntryCount)}),e.jsx(B,{}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Providers"}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[re.length===0&&e.jsx(S,{variant:"secondary",className:"font-mono",children:"none"}),re.map(([o,h])=>e.jsxs(S,{variant:"outline",className:"font-mono text-xs",children:[o,": ",h]},o))]})]})]})]}),e.jsxs(b,{children:[e.jsx(v,{className:"pb-2",children:e.jsx(y,{className:"text-base",children:"Custom Models"})}),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:"Name / Model"}),e.jsx("span",{children:"Provider"}),e.jsx("span",{children:"Base URL"})]}),e.jsx(_,{className:"h-52",children:e.jsxs("div",{className:"divide-y",children:[te.length===0&&e.jsx("div",{className:"px-3 py-4 text-xs text-muted-foreground",children:"No custom models"}),te.map(o=>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:o.displayName}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:o.model})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",children:o.provider}),e.jsx("p",{className:"text-muted-foreground",children:o.apiKeyPreview||"no-key"})]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",title:o.baseUrl,children:o.host||o.baseUrl}),e.jsx("p",{className:"text-muted-foreground font-mono truncate",children:o.baseUrl})]})]},`${o.displayName}-${o.model}-${o.baseUrl}`))]})})]})})]})]})})}),e.jsx($,{value:"docs",className:U,children:e.jsx(_,{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(Je,{className:"h-4 w-4"}),"Docs-Aligned Notes"]})}),e.jsxs(N,{className:"space-y-2 text-sm",children:[w.map((o,h)=>e.jsxs("p",{className:"text-muted-foreground",children:["- ",ys(o)]},`${h}-${o}`)),e.jsx(B,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Factory Docs"}),e.jsx("div",{className:"space-y-1.5",children:be.map(o=>e.jsxs("a",{href:o.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:o.label}),e.jsx(oe,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsx("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:o.description}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:o.url})]},o.id))})]}),e.jsx(B,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Provider Fact-Check Docs"}),e.jsx("div",{className:"space-y-1.5",children:ve.map(o=>e.jsxs("a",{href:o.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:o.label}),e.jsx(oe,{className:"h-3.5 w-3.5 text-muted-foreground"})]}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-muted-foreground",children:["provider: ",o.provider," | format: ",o.apiFormat]}),e.jsx("p",{className:"mt-1 break-all font-mono text-[11px] text-muted-foreground/90 underline underline-offset-2",children:o.url})]},`${o.provider}-${o.url}`))})]}),e.jsx(B,{}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Provider values: ",ye.join(", ")]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Settings hierarchy: ",Ne.join(" -> ")]})]})]})})})})]})]})};return e.jsx("div",{className:"h-[calc(100vh-100px)] overflow-hidden",children:e.jsxs(Se,{direction:"horizontal",className:"h-full",children:[e.jsx(ae,{defaultSize:45,minSize:35,children:e.jsx("div",{className:"h-full border-r bg-muted/20",children:je()})}),e.jsx(Ce,{className:"w-2 bg-border hover:bg-primary/20 transition-colors cursor-col-resize flex items-center justify-center group",children:e.jsx(Le,{className:"w-3 h-3 text-muted-foreground group-hover:text-primary"})}),e.jsx(ae,{defaultSize:55,minSize:35,children:e.jsx(Ge,{title:"Droid BYOK Settings",pathLabel:i?.path||"~/.factory/settings.json",loading:c,parseWarning:i?.parseError,value:C,dirty:D,saving:u,saveDisabled:!D||u||c||!L.valid,onChange:x=>{se(x)},onSave:ge,onRefresh:pe})})]})})}export{Ms as DroidPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-C1Gpgz6I.js";import{r as c}from"./react-vendor-CNOkPC89.js";import{bb as N,bc as C,bd as w,b4 as y,b6 as G,m as S,b as x,I as p}from"./index-DNFjYwGe.js";import{S as k}from"./switch-B3t2TDvW.js";import{R as j,a2 as A,r as R,ah as L,a0 as V}from"./icons-DrewC9c3.js";import"./tanstack-DDJIhNJd.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function _(){const{state:s}=N(),a=C(),[l,d]=c.useState(""),[m,v]=c.useState(""),u=c.useCallback(async()=>{try{a.setGlobalEnvLoading(!0),a.setGlobalEnvError(null);const t=await fetch("/api/global-env");if(!t.ok)throw new Error("Failed to load Global Env config");const r=await t.json();a.setGlobalEnvConfig(r)}catch(t){a.setGlobalEnvError(t.message)}finally{a.setGlobalEnvLoading(!1)}},[a]),i=c.useCallback(async t=>{const r=s.globalEnvConfig;if(!r)return;const f={...r,...t};a.setGlobalEnvConfig(f);try{a.setGlobalEnvSaving(!0),a.setGlobalEnvError(null);const o=await fetch("/api/global-env",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(f)});if(!o.ok){const n=await o.json();throw new Error(n.error||"Failed to save")}const h=await o.json();a.setGlobalEnvConfig(h.config),a.setGlobalEnvSuccess(!0),setTimeout(()=>a.setGlobalEnvSuccess(!1),1500)}catch(o){a.setGlobalEnvConfig(r),a.setGlobalEnvError(o.message)}finally{a.setGlobalEnvSaving(!1)}},[s.globalEnvConfig,a]),b=c.useCallback(()=>{if(!l.trim()||!s.globalEnvConfig)return;const t={...s.globalEnvConfig.env,[l.trim()]:m};i({env:t}),d(""),v("")},[l,m,s.globalEnvConfig,i]),g=c.useCallback(t=>{if(!s.globalEnvConfig)return;const r={...s.globalEnvConfig.env};delete r[t],i({env:r})},[s.globalEnvConfig,i]);return{config:s.globalEnvConfig,loading:s.globalEnvLoading,saving:s.globalEnvSaving,error:s.globalEnvError,success:s.globalEnvSuccess,newEnvKey:l,setNewEnvKey:d,newEnvValue:m,setNewEnvValue:v,fetchConfig:u,saveConfig:i,addEnvVar:b,removeEnvVar:g}}function F(){const{config:s,loading:a,saving:l,error:d,success:m,newEnvKey:v,setNewEnvKey:u,newEnvValue:i,setNewEnvValue:b,fetchConfig:g,saveConfig:t,addEnvVar:r,removeEnvVar:f}=_(),{fetchRawConfig:o}=w();c.useEffect(()=>{g(),o()},[g,o]);const h=()=>{t({enabled:!s?.enabled})};return a?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..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${d||m?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[d&&e.jsxs(y,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(A,{className:"h-4 w-4"}),e.jsx(G,{children:d})]}),m&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(R,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(S,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Environment variables injected into all non-Claude subscription profiles (gemini, codex, agy, ghcp, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s?.enabled?"Global Env enabled":"Global Env disabled"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s?.enabled?"Env vars will be injected into third-party profiles":"Env vars will not be injected"})]}),e.jsx(k,{checked:s?.enabled??!0,onCheckedChange:h})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Environment Variables"}),s?.env&&Object.keys(s.env).length>0?e.jsx("div",{className:"space-y-2",children:Object.entries(s.env).map(([n,E])=>e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg border bg-background",children:[e.jsx("code",{className:"flex-1 font-mono text-sm truncate",children:n}),e.jsx("span",{className:"text-muted-foreground",children:"="}),e.jsx("code",{className:"font-mono text-sm px-2 py-1 bg-muted rounded",children:E}),e.jsx(x,{variant:"ghost",size:"sm",onClick:()=>f(n),disabled:l,className:"h-8 w-8 p-0 text-destructive hover:text-destructive hover:bg-destructive/10",children:e.jsx(L,{className:"w-4 h-4"})})]},n))}):e.jsx("div",{className:"p-4 rounded-lg border border-dashed text-center text-muted-foreground",children:e.jsx("p",{children:"No environment variables configured"})}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Add New Variable"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{value:v,onChange:n=>u(n.target.value.toUpperCase()),placeholder:"KEY_NAME",className:"flex-1 font-mono text-sm h-9",disabled:l}),e.jsx("span",{className:"flex items-center text-muted-foreground",children:"="}),e.jsx(p,{value:i,onChange:n=>b(n.target.value),placeholder:"value",className:"flex-1 font-mono text-sm h-9",disabled:l}),e.jsxs(x,{size:"sm",onClick:r,disabled:l||!v.trim(),className:"h-9",children:[e.jsx(V,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-3",children:"Quick Add Common Variables"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[[{key:"DISABLE_BUG_COMMAND",value:"1"},{key:"DISABLE_ERROR_REPORTING",value:"1"},{key:"DISABLE_TELEMETRY",value:"1"}].map(({key:n,value:E})=>!s?.env?.[n]&&e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>{u(n),b(E)},className:"text-xs font-mono",children:["+ ",n]},n)),s?.env&&["DISABLE_BUG_COMMAND","DISABLE_ERROR_REPORTING","DISABLE_TELEMETRY"].every(n=>s.env[n])&&e.jsx("span",{className:"text-sm text-muted-foreground",children:"All common variables are configured"})]})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>{g(),o()},disabled:a||l,className:"w-full",children:[e.jsx(j,{className:`w-4 h-4 mr-2 ${a?"animate-spin":""}`}),"Refresh"]})})]})}export{F as default};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-C1Gpgz6I.js";import{c as l,b as p,K as w,M as y,N as k,B as z,S as h}from"./index-DNFjYwGe.js";import{u as M,a as R,b as W}from"./tanstack-DDJIhNJd.js";import{t as g}from"./notifications-B2HqRBj7.js";import{r as j}from"./react-vendor-CNOkPC89.js";import{aL as v,c as E,z as C,m as S,Z as P,g as O,U as $,b as H,aM as I,Y as T,y as F,R as A}from"./icons-DrewC9c3.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";const B={sm:{dimension:80,strokeWidth:6,fontSize:"text-lg",labelSize:"text-[10px]"},md:{dimension:120,strokeWidth:8,fontSize:"text-3xl",labelSize:"text-xs"},lg:{dimension:160,strokeWidth:10,fontSize:"text-4xl",labelSize:"text-sm"}},L={ok:{stroke:"#22C55E",glow:"rgba(34, 197, 94, 0.4)"},warning:{stroke:"#EAB308",glow:"rgba(234, 179, 8, 0.4)"},error:{stroke:"#EF4444",glow:"rgba(239, 68, 68, 0.4)"}};function D({passed:s,total:t,status:r,size:o="md"}){const n=B[o],d=L[r],i=t>0?Math.round(s/t*100):0,a=(n.dimension-n.strokeWidth)/2,c=2*Math.PI*a,f=c-i/100*c,x=n.dimension/2;return e.jsxs("div",{className:"relative inline-flex items-center justify-center",children:[e.jsxs("svg",{width:n.dimension,height:n.dimension,className:"transform -rotate-90",style:{filter:`drop-shadow(0 0 8px ${d.glow})`},children:[e.jsx("circle",{cx:x,cy:x,r:a,fill:"none",stroke:"currentColor",strokeWidth:n.strokeWidth,className:"text-muted/30"}),e.jsx("circle",{cx:x,cy:x,r:a,fill:"none",stroke:d.stroke,strokeWidth:n.strokeWidth,strokeLinecap:"round",strokeDasharray:c,strokeDashoffset:f,className:"transition-all duration-1000 ease-out"}),i>0&&e.jsx("circle",{cx:x+a*Math.cos(i/100*2*Math.PI-Math.PI/2),cy:x+a*Math.sin(i/100*2*Math.PI-Math.PI/2),r:n.strokeWidth/2,fill:d.stroke,className:"animate-pulse",style:{filter:`drop-shadow(0 0 4px ${d.glow})`}})]}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[e.jsx("span",{className:l("font-mono font-bold tracking-tight",n.fontSize),children:i}),e.jsx("span",{className:l("font-mono uppercase tracking-widest text-muted-foreground",n.labelSize),children:"health"})]})]})}function b({label:s,value:t,color:r,bgColor:o}){return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full animate-pulse",o)}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:s}),e.jsx("span",{className:l("font-mono font-bold text-sm",r),children:t})]})}function K({total:s,passed:t,warnings:r,errors:o,info:n}){const d=t/s*100,i=r/s*100,a=o/s*100,c=n/s*100;return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"h-2 rounded-full overflow-hidden bg-muted/50 flex",children:[a>0&&e.jsx("div",{className:"h-full bg-red-500 transition-all duration-500",style:{width:`${a}%`}}),i>0&&e.jsx("div",{className:"h-full bg-yellow-500 transition-all duration-500",style:{width:`${i}%`}}),c>0&&e.jsx("div",{className:"h-full bg-blue-500 transition-all duration-500",style:{width:`${c}%`}}),d>0&&e.jsx("div",{className:"h-full bg-green-500 transition-all duration-500",style:{width:`${d}%`}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wider",children:"Checks"}),e.jsx("span",{className:"font-mono font-bold text-lg",children:s})]}),e.jsxs("div",{className:"flex items-center gap-4 flex-wrap",children:[e.jsx(b,{label:"OK",value:t,color:"text-green-500",bgColor:"bg-green-500"}),e.jsx(b,{label:"WARN",value:r,color:"text-yellow-500",bgColor:"bg-yellow-500"}),e.jsx(b,{label:"ERR",value:o,color:"text-red-500",bgColor:"bg-red-500"}),e.jsx(b,{label:"INFO",value:n,color:"text-blue-500",bgColor:"bg-blue-500"})]})]})]})}function q(){return M({queryKey:["health"],queryFn:async()=>(await fetch("/api/health")).json(),refetchInterval:3e4})}function G(){const s=R();return W({mutationFn:async t=>{const r=await fetch(`/api/health/fix/${t}`,{method:"POST"}),o=await r.json();if(!r.ok)throw new Error(o.message);return o},onSuccess:t=>{s.invalidateQueries({queryKey:["health"]}),g.success(t.message)},onError:t=>{g.error(t.message)}})}const Q={ok:{dot:"bg-green-500",label:"OK",labelColor:"text-green-500"},warning:{dot:"bg-yellow-500",label:"WARN",labelColor:"text-yellow-500"},error:{dot:"bg-red-500",label:"ERR",labelColor:"text-red-500"},info:{dot:"bg-blue-500",label:"INFO",labelColor:"text-blue-500"}};function U({check:s}){const t=G(),r=Q[s.status],[o,n]=j.useState(!1),d=s.details||s.fix,i=a=>{navigator.clipboard.writeText(a),g.success("Copied to clipboard")};return d?e.jsx(w,{open:o,onOpenChange:n,children:e.jsxs("div",{className:l("group rounded-lg border transition-all duration-150",o?"border-border bg-muted/30":"border-transparent hover:border-border/50 hover:bg-muted/50"),children:[e.jsx(y,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),e.jsx(E,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",o&&"rotate-90")})]})}),e.jsx(k,{children:e.jsxs("div",{className:"px-3 pb-3 pt-1 space-y-2 ml-7",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:s.message}),s.details&&e.jsx("pre",{className:"text-xs font-mono text-muted-foreground bg-background/50 rounded p-2 overflow-x-auto border border-border/50",children:s.details}),s.fix&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-2 bg-background/50 rounded px-2 py-1.5 border border-border/50",children:[e.jsx(C,{className:"w-3 h-3 text-muted-foreground shrink-0"}),e.jsx("code",{className:"text-xs font-mono flex-1 truncate",children:s.fix}),e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>s.fix&&i(s.fix),className:"h-5 w-5 p-0",children:e.jsx(S,{className:"w-3 h-3"})})]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",onClick:()=>t.mutate(s.id),disabled:t.isPending,className:"h-7 px-3 text-xs",children:[e.jsx(v,{className:"w-3 h-3 mr-1"}),"Apply Fix"]})]})]})})]})}):e.jsxs("div",{className:l("group flex items-center gap-3 px-3 py-2 rounded-lg","hover:bg-muted/50 transition-colors duration-150","border border-transparent hover:border-border/50"),children:[e.jsxs("div",{className:"relative flex items-center justify-center w-4 h-4",children:[e.jsx("div",{className:l("w-2 h-2 rounded-full",r.dot)}),s.status!=="ok"&&e.jsx("div",{className:l("absolute w-2 h-2 rounded-full animate-ping opacity-75",r.dot)})]}),e.jsx("span",{className:"flex-1 text-sm font-medium truncate",children:s.name}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",r.labelColor),children:["[",r.label,"]"]}),s.fixable&&s.status!=="ok"&&e.jsxs(p,{size:"sm",variant:"ghost",onClick:()=>t.mutate(s.id),disabled:t.isPending,className:"h-6 px-2 text-xs opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(v,{className:"w-3 h-3 mr-1"}),"Fix"]})]})}const Z={Monitor:I,Settings:H,Users:$,Shield:O,Zap:P};function V({group:s,defaultOpen:t=!0}){const[r,o]=j.useState(t),n=Z[s.icon]||I,d=s.checks.filter(m=>m.status==="ok").length,i=s.checks.length,a=s.checks.some(m=>m.status==="error"),c=s.checks.some(m=>m.status==="warning"),f=Math.round(d/i*100),x=a?"text-red-500":c?"text-yellow-500":"text-green-500",u=a?"bg-red-500":c?"bg-yellow-500":"bg-green-500";return e.jsx(w,{open:r,onOpenChange:o,children:e.jsxs("div",{className:l("rounded-lg border transition-all duration-200",a?"border-red-500/30":c?"border-yellow-500/30":"border-border"),children:[e.jsx(y,{asChild:!0,children:e.jsxs("button",{className:l("w-full flex items-center gap-3 p-3 text-left rounded-lg","hover:bg-muted/50 transition-colors duration-150",r&&"rounded-b-none border-b border-border/50"),children:[e.jsx("div",{className:l("p-1.5 rounded-md",a?"bg-red-500/10 text-red-500":c?"bg-yellow-500/10 text-yellow-500":"bg-muted text-muted-foreground"),children:e.jsx(n,{className:"w-4 h-4"})}),e.jsx("span",{className:"flex-1 text-sm font-semibold",children:s.name}),!r&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("div",{className:"w-16 h-1.5 rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:l("h-full transition-all duration-500",u),style:{width:`${f}%`}})})}),e.jsxs("span",{className:l("font-mono text-xs font-semibold",x),children:[d,"/",i]}),e.jsx(T,{className:l("w-4 h-4 text-muted-foreground transition-transform duration-200",r&&"rotate-180")})]})}),e.jsx(k,{children:e.jsx("div",{className:"p-2 space-y-0.5",children:s.checks.map(m=>e.jsx(U,{check:m},m.id))})})]})})}function Y(s){return s.errors>0?"error":s.warnings>0?"warning":"ok"}function J(s){const t=Math.floor((Date.now()-s)/1e3);if(t<5)return"just now";if(t<60)return`${t}s ago`;const r=Math.floor(t/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function X(s){return[...s].sort((t,r)=>{const o=t.checks.filter(a=>a.status==="error").length,n=r.checks.filter(a=>a.status==="error").length,d=t.checks.filter(a=>a.status==="warning").length,i=r.checks.filter(a=>a.status==="warning").length;return o!==n?n-o:i-d})}function _(){return e.jsxs("div",{className:"font-mono text-sm text-muted-foreground flex items-center gap-2",children:[e.jsx("span",{className:"text-green-500",children:"$"}),e.jsx("span",{children:"ccs doctor"})]})}function ee(){return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsx("div",{className:"rounded-xl border bg-gradient-to-br from-background to-muted/20 p-6",children:e.jsxs("div",{className:"flex items-center gap-6",children:[e.jsx(h,{className:"w-[120px] h-[120px] rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(h,{className:"h-5 w-48"}),e.jsx(h,{className:"h-8 w-64"}),e.jsx(h,{className:"h-4 w-32"})]})]})}),e.jsx(h,{className:"h-16 w-full rounded-lg"}),e.jsx("div",{className:"space-y-3",children:[1,2,3,4].map(s=>e.jsx(h,{className:"h-20 rounded-lg"},s))})]})}function ce(){const{data:s,isLoading:t,refetch:r,dataUpdatedAt:o}=q(),n=o,[d,i]=j.useState(0);j.useEffect(()=>{const u=setInterval(()=>i(m=>m+1),1e3);return()=>clearInterval(u)},[]);const a=()=>{navigator.clipboard.writeText("ccs doctor"),g.success("Copied to clipboard")},c=()=>{r(),g.info("Refreshing health checks...")};if(t&&!s)return e.jsx(ee,{});const f=s?Y(s.summary):"ok",x=s?.groups?X(s.groups):[];return e.jsxs("div",{className:"p-6 max-w-6xl mx-auto space-y-6",children:[e.jsxs("div",{className:l("relative overflow-hidden rounded-xl border p-6","bg-gradient-to-br from-background via-background to-muted/30"),children:[e.jsx("div",{className:"absolute inset-0 opacity-[0.02] pointer-events-none",style:{backgroundImage:"repeating-linear-gradient(0deg, transparent, transparent 2px, currentColor 2px, currentColor 3px)"}}),e.jsx("div",{className:"absolute inset-0 opacity-[0.03] pointer-events-none",children:e.jsx("div",{className:"absolute inset-0",style:{backgroundImage:"radial-gradient(circle at 1px 1px, currentColor 1px, transparent 0)",backgroundSize:"24px 24px"}})}),e.jsxs("div",{className:"relative flex flex-col md:flex-row items-start md:items-center gap-6",children:[s&&e.jsx("div",{className:"shrink-0",children:e.jsx(D,{passed:s.summary.passed,total:s.summary.total-s.summary.info,status:f,size:"md"})}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx(_,{}),e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-bold font-mono tracking-tight",children:"System Health"}),s?.version&&e.jsxs(z,{variant:"outline",className:"font-mono text-xs bg-muted/50",children:["build ",s.version]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(F,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"Last scan:"}),e.jsx("span",{className:"font-mono",children:n?J(n):"--"}),e.jsx("span",{className:"text-muted-foreground",children:"|"}),e.jsx("span",{className:"text-muted-foreground",children:"Auto-refresh:"}),e.jsx("span",{className:"font-mono text-green-500",children:"30s"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(p,{variant:"outline",size:"sm",onClick:a,className:"gap-2 font-mono text-xs",children:[e.jsx(C,{className:"w-3 h-3"}),"ccs doctor",e.jsx(S,{className:"w-3 h-3 opacity-50"})]}),e.jsxs(p,{variant:"outline",size:"sm",onClick:c,disabled:t,className:"gap-2",children:[e.jsx(A,{className:l("w-4 h-4",t&&"animate-spin")}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"}),e.jsx("kbd",{className:"hidden md:inline-flex h-5 items-center gap-1 rounded border bg-muted px-1.5 font-mono text-[10px] font-medium text-muted-foreground",children:"R"})]})]})]})]}),s&&e.jsx("div",{className:"rounded-lg border bg-card p-4",children:e.jsx(K,{total:s.summary.total,passed:s.summary.passed,warnings:s.summary.warnings,errors:s.summary.errors,info:s.summary.info})}),x.length>0&&e.jsx("div",{className:"space-y-3",children:x.map((u,m)=>e.jsx(V,{group:u,defaultOpen:m<2||u.checks.some(N=>N.status==="error"||N.status==="warning")},u.id))}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground border-t pt-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{children:["Version ",e.jsx("span",{className:"font-mono",children:s?.version??"--"})]}),e.jsxs("span",{children:["Platform"," ",e.jsx("span",{className:"font-mono",children:typeof navigator<"u"?navigator.platform:"linux"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),e.jsx("span",{children:"Live monitoring active"})]})]})]})}export{ce as HealthPage};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-C1Gpgz6I.js";import{r as f,c as fe}from"./react-vendor-CNOkPC89.js";import{u as M,C as p,a as g,S as h,c as d,P as y,B as O,b as H,d as ee,e as pe,f as se,g as ge,h as te,i as N,j as S,k as je,l as Ne,m as ye,n as we}from"./index-DNFjYwGe.js";import{O as be,aa as ae,ab as z,ac as re,J as ne,a1 as ve,G as ke,ad as Ce,R as $e,z as Q,U as Se,Z as le,q as De,a5 as G,ae as Le,y as Te,c as Fe,af as Re,ag as Me}from"./icons-DrewC9c3.js";import{a as Pe,u as P}from"./tanstack-DDJIhNJd.js";import{K as L,L as Y,f as k,H as Ae}from"./utils-CzKF5WmX.js";import{R as ie,A as Be,C as Ue,X as qe,Y as V,T as oe,a as Z,P as Oe,b as Ie,c as Ke}from"./charts-BBPXh0Ar.js";import"./notifications-B2HqRBj7.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function Ee({data:s,isLoading:t}){const{privacyMode:a}=M();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(o=>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"})]})})},o))});const n=(s?.tokenBreakdown?.cacheCreation?.cost??0)+(s?.tokenBreakdown?.cacheRead?.cost??0),r=s?.totalCost?Math.round(n/s.totalCost*100):0,i=[{title:"Total Tokens",value:s?.totalTokens??0,icon:be,format:o=>R(o),color:"text-blue-600",bgColor:"bg-blue-100 dark:bg-blue-900/20",subtitle:`${R(s?.totalInputTokens??0)} in / ${R(s?.totalOutputTokens??0)} out`},{title:"Total Cost",value:s?.totalCost??0,icon:ae,format:o=>`$${o.toFixed(2)}`,color:"text-green-600",bgColor:"bg-green-100 dark:bg-green-900/20",subtitle:`$${s?.averageCostPerDay?.toFixed(2)??"0.00"}/day avg`},{title:"Cache Tokens",value:s?.totalCacheTokens??0,icon:z,format:o=>R(o),color:"text-cyan-600",bgColor:"bg-cyan-100 dark:bg-cyan-900/20",subtitle:`$${n.toFixed(2)} (${r}% of cost)`},{title:"Input Cost",value:s?.tokenBreakdown?.input?.cost??0,icon:re,format:o=>`$${o.toFixed(2)}`,color:"text-purple-600",bgColor:"bg-purple-100 dark:bg-purple-900/20",subtitle:`${R(s?.tokenBreakdown?.input?.tokens??0)} tokens`},{title:"Output Cost",value:s?.tokenBreakdown?.output?.cost??0,icon:ne,format:o=>`$${o.toFixed(2)}`,color:"text-orange-600",bgColor:"bg-orange-100 dark:bg-orange-900/20",subtitle:`${R(s?.tokenBreakdown?.output?.tokens??0)} tokens`}];return e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-5 gap-4",children:i.map((o,l)=>{const c=o.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:o.title}),e.jsx("p",{className:d("text-xl font-bold truncate",a&&y),children:o.format(o.value)}),o.subtitle&&e.jsx("p",{className:d("text-[10px] text-muted-foreground truncate",a&&y),children:o.subtitle})]}),e.jsx("div",{className:d("p-2 rounded-lg shrink-0",o.bgColor),children:e.jsx(c,{className:d("h-4 w-4",o.color)})})]})})},l)})})}function R(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function Ge({model:s}){const{privacyMode:t}=M(),a=We(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(ve,{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(O,{variant:"secondary",className:"text-[10px] h-5 px-1.5",children:[s.percentage.toFixed(1),"% usage"]}),e.jsxs(O,{variant:a.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:d("text-lg font-bold",t&&y),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:d("text-lg font-bold",t&&y),children:_e(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:d("space-y-1",t&&y),children:[e.jsx(W,{label:"Input",tokens:s.inputTokens,cost:s.costBreakdown.input.cost,color:"#335c67",icon:re}),e.jsx(W,{label:"Output",tokens:s.outputTokens,cost:s.costBreakdown.output.cost,color:"#fff3b0",icon:ne}),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(ke,{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:a.description})]})]})}function W({label:s,tokens:t,cost:a,color:n,icon:r}){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:["$",a.toFixed(3)]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:[e.jsx(r,{className:"h-3 w-3 shrink-0"}),e.jsx("span",{children:He(t)})]})]})]})}function We(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 He(s){return s.toLocaleString()}function _e(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 ze="/api";function b(s){const t=s.getFullYear(),a=String(s.getMonth()+1).padStart(2,"0"),n=String(s.getDate()).padStart(2,"0");return`${t}${a}${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),D(`/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),D(`/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)),D(`/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),D(`/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()),D(`/usage/sessions?${t}`)},monthly:(s,t)=>{const a=new URLSearchParams;return s&&a.append("months",s.toString()),t&&a.append("profile",t),D(`/usage/monthly?${a}`)},refresh:async()=>{if(!(await fetch(`${ze}/usage/refresh`,{method:"POST",headers:{"Content-Type":"application/json"}})).ok)throw new Error("Failed to refresh usage cache")},status:()=>D("/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),D(`/usage/insights?${t}`)}};async function D(s){const a=await fetch(`/api${s}`,{headers:{"Content-Type":"application/json"}});if(!a.ok){const r=await a.json().catch(()=>({error:"Unknown error"}));throw new Error(r.error||a.statusText)}const n=await a.json();return n.data||n}function Ye(s){return P({queryKey:["usage","summary",s],queryFn:()=>T.summary(s),staleTime:60*1e3})}function Qe(s){return P({queryKey:["usage","trends",s],queryFn:()=>T.trends(s),staleTime:60*1e3})}function Ve(s){return P({queryKey:["usage","hourly",s],queryFn:()=>T.hourly(s),staleTime:60*1e3})}function Ze(s){return P({queryKey:["usage","models",s],queryFn:()=>T.models(s),staleTime:60*1e3})}function Xe(){const s=Pe();return f.useCallback(async()=>{await T.refresh(),await s.invalidateQueries({queryKey:["usage"]})},[s])}function Je(){return P({queryKey:["usage","status"],queryFn:()=>T.status(),staleTime:10*1e3,refetchInterval:30*1e3})}function es(s){return P({queryKey:["usage","sessions",s],queryFn:()=>T.sessions(s),staleTime:60*1e3})}function ss(){const[s,t]=f.useState({from:L(new Date,30),to:new Date}),[a,n]=f.useState(!1),[r,i]=f.useState(null),[o,l]=f.useState(null),[c,x]=f.useState("daily"),u=Xe(),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}=Ye(j),{data:C,isLoading:$}=Qe(j),{data:A,isLoading:B}=Ve(j),{data:U,isLoading:q}=Ze(j),{data:_,isLoading:I}=es({...j,limit:3}),{data:K}=Je(),ce=f.useCallback(()=>{const F=new Date;t({from:L(F,1),to:F}),x("hourly")},[]),de=f.useCallback(F=>{t(F),x("daily")},[]),xe=f.useMemo(()=>K?.lastFetch?Y(new Date(K.lastFetch),{addSuffix:!0}):null,[K?.lastFetch]),ue=f.useCallback((F,he)=>{const E=he.currentTarget.getBoundingClientRect();l({x:E.left+E.width/2,y:E.top+E.height/2}),i(F)},[]),me=f.useCallback(()=>{i(null),l(null)},[]);return{dateRange:s,isRefreshing:a,viewMode:c,selectedModel:r,popoverPosition:o,summary:w,trends:C,hourlyData:A,models:U,sessions:_,status:K,isSummaryLoading:v,isTrendsLoading:$,isHourlyLoading:B,isModelsLoading:q,isSessionsLoading:I,isLoading:v||$||q||I,handleRefresh:m,handleTodayClick:ce,handleDateRangeChange:de,handleModelClick:ue,handlePopoverClose:me,lastUpdatedText:xe}}function ts({value:s,onChange:t,presets:a=[{label:"Last 7 days",range:{from:L(new Date,7),to:new Date}},{label:"Last 30 days",range:{from:L(new Date,30),to:new Date}},{label:"Last 90 days",range:{from:L(new Date,90),to:new Date}}],className:n}){const[r,i]=fe.useState(!1),o=l=>!s||!s.from||!s.to||!l.from||!l.to?!1:k(s.from,"yyyy-MM-dd")===k(l.from,"yyyy-MM-dd")&&k(s.to,"yyyy-MM-dd")===k(l.to,"yyyy-MM-dd");return e.jsxs("div",{className:d("flex flex-wrap items-center gap-2",n),children:[a.map(l=>e.jsx(H,{variant:o(l.range)?"default":"outline",size:"sm",onClick:()=>t(l.range),children:l.label},l.label)),e.jsxs(ee,{open:r,onOpenChange:i,children:[e.jsx(pe,{asChild:!0,children:e.jsxs(H,{id:"date",variant:"outline",className:d("w-auto min-w-[200px] sm:min-w-[240px] justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(Ce,{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(se,{className:"w-auto p-0",align:"end",children:e.jsx(ge,{initialFocus:!0,mode:"range",defaultMonth:s?.from,selected:s,onSelect:t,numberOfMonths:2})})]})]})}function as({dateRange:s,onDateRangeChange:t,onTodayClick:a,onRefresh:n,isRefreshing:r,lastUpdatedText:i,viewMode:o}){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:"Analytics"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Track usage & insights"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 xl:justify-end",children:[e.jsx(H,{variant:o==="hourly"?"default":"outline",size:"sm",className:"h-8",onClick:a,children:"24H"}),e.jsx(ts,{className:"flex-wrap",value:s,onChange:t,presets:[{label:"7D",range:{from:L(new Date,7),to:new Date}},{label:"30D",range:{from:L(new Date,30),to:new Date}},{label:"Month",range:{from:Ae(new Date),to:new Date}},{label:"All Time",range:{from:void 0,to:new Date}}]}),i&&e.jsxs("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:["Updated ",i]}),e.jsx(H,{variant:"outline",size:"sm",className:"gap-2 h-8",onClick:n,disabled:r,children:e.jsx($e,{className:`w-3.5 h-3.5 ${r?"animate-spin":""}`})})]})]})}function rs({data:s,isLoading:t,granularity:a="daily",className:n}){const{privacyMode:r}=M(),i=f.useMemo(()=>!s||s.length===0?[]:(a==="hourly"?s:[...s].reverse()).map(c=>{const x="hour"in c?c.hour:c.date;return{...c,dateFormatted:ns(x,a),costRounded:Number(c.cost.toFixed(4))}}),[s,a]);if(t)return e.jsx(h,{className:d("h-full w-full",n)});if(!s||s.length===0)return e.jsx("div",{className:d("h-full flex items-center justify-center",n),children:e.jsx("p",{className:"text-muted-foreground",children:a==="hourly"?"No usage data for today":"No usage data available"})});const o=({x:l,y:c,payload:x,isRight:u})=>{const m=u?`$${x.value}`:X(Number(x.value));return e.jsx("text",{x:l,y:c,dy:4,textAnchor:u?"start":"end",fontSize:12,fill:"currentColor",className:d("fill-muted-foreground",r&&"blur-[4px]"),children:m})};return e.jsx("div",{className:d("w-full h-full",n),children:e.jsx(ie,{width:"100%",height:"100%",children:e.jsxs(Be,{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(Ue,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(qe,{dataKey:"dateFormatted",tick:{fontSize:12},tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"left",orientation:"left",tick:l=>e.jsx(o,{...l,isRight:!1}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(V,{yAxisId:"right",orientation:"right",tick:l=>e.jsx(o,{...l,isRight:!0}),tickLine:!1,axisLine:{className:"stroke-muted"}}),e.jsx(oe,{content:({active:l,payload:c,label:x})=>{if(!l||!c||!c.length)return null;const u=c[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:x}),c.map((m,j)=>e.jsxs("p",{className:d("text-sm",r&&y),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:d("text-sm text-muted-foreground mt-1",r&&y),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 ns(s,t){if(t==="hourly"){const[n,r]=s.split(" ");if(n&&r){const i=new Date(`${n}T${r}:00Z`);return k(i,"HH:mm")}return s}const a=new Date(s);return t==="monthly"?k(a,"MMM yyyy"):k(a,"MMM dd")}function X(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function ls({data:s,isLoading:t,className:a}){const{privacyMode:n}=M(),r=f.useMemo(()=>!s||s.length===0?[]:s.map(l=>({name:l.model,value:l.tokens,cost:l.cost,percentage:l.percentage,fill:te(l.model)})),[s]);if(t)return e.jsx(h,{className:d("h-full min-h-[100px] w-full",a)});if(!s||s.length===0)return e.jsx("div",{className:d("h-full min-h-[100px] flex items-center justify-center",a),children:e.jsx("p",{className:"text-muted-foreground",children:"No model data available"})});const i=({active:l,payload:c})=>{if(!l||!c)return null;const x=c;if(!x.length)return null;const u=x[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:d("text-muted-foreground",n&&y),children:[is(u.value)," (",u.percentage.toFixed(1),"%)"]}),e.jsxs("p",{className:d("text-muted-foreground",n&&y),children:["$",u.cost.toFixed(4)]})]})},o=l=>l.percentage>5?`${l.percentage.toFixed(1)}%`:"";return e.jsx("div",{className:d("w-full h-full min-h-[100px]",a),children:e.jsx(ie,{width:"100%",height:"100%",children:e.jsxs(Oe,{children:[e.jsx(Ie,{data:r,cx:"50%",cy:"50%",labelLine:!1,label:o,innerRadius:50,outerRadius:70,paddingAngle:2,dataKey:"value",children:r.map((l,c)=>e.jsx(Ke,{fill:l.fill,strokeWidth:1},`cell-${c}`))}),e.jsx(oe,{content:i})]})})})}function is(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function os(s){if(!s)return"";const a=s.replace(/^\/|\/$/g,"").split("/").filter(n=>n.length>0);return a[a.length-1]||""}function cs({data:s,isLoading:t,className:a}){const{privacyMode:n}=M(),r=f.useMemo(()=>{if(!s?.sessions||s.sessions.length===0)return null;const i=s.sessions,o=s.total,l=i.reduce((w,v)=>w+(v.inputTokens+v.outputTokens),0),c=Math.round(l/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:o,avgTokens:c,avgCost:u,lastActive:j,recentSessions:i.slice(0,3)}},[s]);return t?e.jsxs(p,{className:d("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(N,{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"})})]}):r?e.jsxs(p,{className:d("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 shadow-sm",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{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(Se,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xl font-bold",children:r.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(le,{className:"w-4 h-4"}),e.jsxs("span",{className:d("text-xl font-bold",n&&y),children:["$",r.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(De,{className:"w-3 h-3"}),"Recent Activity"]}),e.jsx("div",{className:"space-y-1.5 max-h-full overflow-y-auto pr-1",children:r.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:os(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:d("text-right shrink-0 ml-2",n&&y),children:[e.jsxs("div",{className:"font-mono",children:["$",i.cost.toFixed(2)]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[ds(i.inputTokens+i.outputTokens)," toks"]})]})]},i.sessionId))})]})]})]}):e.jsxs(p,{className:d("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",a),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{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 ds(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 xs({className:s,isLoading:t}){const{data:a,isLoading:n}=je(),{data:r,isLoading:i,error:o}=Ne(a?.running);if(t||n||a?.running&&i)return e.jsxs(p,{className:d("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs(S,{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(!a?.running)return e.jsxs(p,{className:d("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-dashed",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{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(O,{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(o)return e.jsxs(p,{className:d("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0 border-destructive/50",s),children:[e.jsx(N,{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsx(O,{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:o.message})})]});const c=r?.totalRequests??0,x=r?.quotaExceededCount??0,u=c-x,m=c>0?Math.round(u/c*100):100,j=r?.tokens?.total??0,w=Object.entries(r?.requestsByModel??{}).sort((C,$)=>$[1]-C[1]).slice(0,4),v=w.length>0?w[0][1]:1;return e.jsxs(p,{className:d("flex flex-col h-full min-h-0 overflow-hidden gap-0 py-0",s),children:[e.jsx(N,{className:"px-3 py-2 border-b bg-muted/5",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"CLIProxy Stats"]}),e.jsxs(O,{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(le,{className:"h-3 w-3 mr-0.5"}),"Running"]})]})}),e.jsx(g,{className:"p-0 flex-1 min-h-0",children:e.jsx(ye,{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(c)}),e.jsx("div",{className:"text-[9px] text-muted-foreground mt-0.5",children:x>0?`${x} 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(Le,{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(Te,{className:"h-3 w-3"}),"Models Used"]}),e.jsx("div",{className:"space-y-1",children:w.map(([C,$])=>{const A=Math.round($/v*100),B=us(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:B}),e.jsx("span",{className:"text-muted-foreground shrink-0 ml-2",children:$})]}),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:`${A}%`}})})]},C)})})]})]})})})]})}function J(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function us(s){let t=s.replace(/^gemini-claude-/,"").replace(/^gemini-/,"").replace(/^claude-/,"").replace(/^anthropic\./,"").replace(/-thinking$/," Thinking");return t=t.split(/[-_]/).map(a=>a.charAt(0).toUpperCase()+a.slice(1)).join(" "),t.length>20&&(t=t.slice(0,18)+"..."),t}function ms(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 hs({models:s,isLoading:t,onModelClick:a,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(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ae,{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((r,i)=>i.cost-r.cost).map(r=>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=>a(r,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:te(r.model)}}),e.jsx("span",{className:"font-medium truncate group-hover:underline underline-offset-2",children:r.model})]}),e.jsx(fs,{model:r}),e.jsx("span",{className:d("text-[10px] text-muted-foreground w-14 text-right shrink-0",n&&y),children:ms(r.tokens)}),e.jsxs("span",{className:d("font-mono font-medium w-16 text-right shrink-0",n&&y),children:["$",r.cost.toFixed(2)]}),e.jsx(Fe,{className:"w-3 h-3 opacity-0 group-hover:opacity-50 transition-opacity shrink-0"})]},r.model)),e.jsx(ps,{})]})})]})}function fs({model:s}){const t={input:"#335c67",output:"#fff3b0",cacheWrite:"#e09f3e",cacheRead:"#9e2a2b"},a=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:`${a(s.costBreakdown.input.cost)}%`},title:`Input: $${s.costBreakdown.input.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.output,width:`${a(s.costBreakdown.output.cost)}%`},title:`Output: $${s.costBreakdown.output.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheWrite,width:`${a(s.costBreakdown.cacheCreation.cost)}%`},title:`Cache Write: $${s.costBreakdown.cacheCreation.cost.toFixed(2)}`}),e.jsx("div",{className:"h-full",style:{backgroundColor:t.cacheRead,width:`${a(s.costBreakdown.cacheRead.cost)}%`},title:`Cache Read: $${s.costBreakdown.cacheRead.cost.toFixed(2)}`})]})})}function ps(){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:a,hasBorder:n})=>e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("div",{className:d("w-2 h-2 rounded-full",n&&"border border-muted-foreground/30"),style:{backgroundColor:t}}),a]},a))})}function gs({viewMode:s,trends:t,hourlyData:a,models:n,sessions:r,isTrendsLoading:i,isHourlyLoading:o,isModelsLoading:l,isSessionsLoading:c,isSummaryLoading:x,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(N,{className:"px-3 py-2 shrink-0",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Re,{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(rs,{data:s==="hourly"?a||[]:t||[],isLoading:s==="hourly"?o: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(hs,{models:n,isLoading:l,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(N,{className:"px-3 py-2",children:e.jsxs(S,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Me,{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(ls,{data:n||[],isLoading:l,className:"h-full w-full"})})]}),e.jsx(cs,{data:r,isLoading:c,className:"lg:col-span-2"}),e.jsx(xs,{isLoading:x,className:"lg:col-span-2"})]})]})}function Ds(){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(N,{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(N,{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(N,{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 Ls(){const s=f.useRef(null),{dateRange:t,handleDateRangeChange:a,handleTodayClick:n,handleRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:l,summary:c,isSummaryLoading:x,trends:u,hourlyData:m,models:j,sessions:w,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:$,isSessionsLoading:A,handleModelClick:B,selectedModel:U,popoverPosition:q,handlePopoverClose:_}=ss();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(as,{dateRange:t,onDateRangeChange:a,onTodayClick:n,onRefresh:r,isRefreshing:i,lastUpdatedText:o,viewMode:l}),e.jsx(Ee,{data:c,isLoading:x}),e.jsx(gs,{viewMode:l,trends:u,hourlyData:m,models:j,sessions:w,isTrendsLoading:v,isHourlyLoading:C,isModelsLoading:$,isSessionsLoading:A,isSummaryLoading:x,onModelClick:B}),e.jsxs(ee,{open:!!U,onOpenChange:I=>!I&&_(),children:[e.jsx(we,{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(se,{className:"w-80 p-3",side:"top",align:"center",children:U&&e.jsx(Ge,{model:U})})]})]})}export{Ls as AnalyticsPage,Ds as AnalyticsSkeleton};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-C1Gpgz6I.js";import{r as a}from"./react-vendor-CNOkPC89.js";import{bb as Ke,bc as Ge,W as R,I,q as Ye,r as $e,s as He,t as Ue,v as xe,b as $,bd as Oe,be as Ve,bf as ze,b4 as ee,b6 as se,m as qe}from"./index-DNFjYwGe.js";import{S as B}from"./switch-B3t2TDvW.js";import{C as H}from"./default-ports-1QQSffYX.js";import{aR as he,R as te,f as We,r as ge,W as Je,a2 as Xe,aS as Qe,aT as Ze,T as ue,ap as es,n as ss,aU as ts}from"./icons-DrewC9c3.js";import{R as Y,P as rs}from"./proxy-status-widget-B31OXK00.js";import{t as T}from"./notifications-B2HqRBj7.js";import"./tanstack-DDJIhNJd.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";import"./alert-dialog-B_Bdo2ou.js";function as(){const{state:t}=Ke(),r=Ge(),[o,m]=a.useState(null),[h,b]=a.useState(null),[f,u]=a.useState(null),[k,N]=a.useState(null),[y,C]=a.useState(null),P=a.useCallback(async()=>{try{r.setProxyLoading(!0),r.setProxyError(null);const c=await R.cliproxyServer.get();r.setProxyConfig(c)}catch(c){r.setProxyError(c.message)}finally{r.setProxyLoading(!1)}},[r]),w=a.useCallback(async c=>{const d=t.proxyConfig;if(!d)return;const p={remote:{...d.remote,...c.remote},fallback:{...d.fallback,...c.fallback},local:{...d.local,...c.local}};r.setProxyConfig(p),r.setProxyTestResult(null);try{r.setProxySaving(!0),r.setProxyError(null);const i=await R.cliproxyServer.update(c);r.setProxyConfig(i),r.setProxySuccess(!0),setTimeout(()=>r.setProxySuccess(!1),1500)}catch(i){r.setProxyConfig(d),r.setProxyError(i.message)}finally{r.setProxySaving(!1)}},[t.proxyConfig,r]),S=a.useCallback(async c=>{const{host:d,port:p,protocol:i,authToken:A}=c;if(!d){r.setProxyError("Host is required");return}try{r.setProxyTesting(!0),r.setProxyError(null),r.setProxyTestResult(null);const l=p?parseInt(p,10):void 0,E=await R.cliproxyServer.test({host:d,port:l||void 0,protocol:i,authToken:A||void 0});r.setProxyTestResult(E)}catch(l){r.setProxyError(l.message)}finally{r.setProxyTesting(!1)}},[r]);return{config:t.proxyConfig,loading:t.proxyLoading,saving:t.proxySaving,error:t.proxyError,success:t.proxySuccess,testResult:t.proxyTestResult,testing:t.proxyTesting,editedHost:o,setEditedHost:m,editedPort:h,setEditedPort:b,editedAuthToken:f,setEditedAuthToken:u,editedManagementKey:k,setEditedManagementKey:N,editedLocalPort:y,setEditedLocalPort:C,fetchConfig:P,saveConfig:w,testConnection:S}}function os({config:t,saving:r,displayLocalPort:o,setEditedLocalPort:m,onSaveLocalPort:h,onSaveConfig:b}){const f=t.local;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Local Proxy"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Port"}),e.jsx(I,{type:"text",inputMode:"numeric",value:o,onChange:u=>m(u.target.value.replace(/\D/g,"")),onBlur:h,placeholder:`${H}`,className:"font-mono max-w-32",disabled:r})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Start local proxy automatically when needed"})]}),e.jsx(B,{checked:f.auto_start??!0,onCheckedChange:u=>b({local:{...f,auto_start:u}}),disabled:r})]})]})]})}function ns({config:t,saving:r,testing:o,testResult:m,displayHost:h,displayPort:b,displayAuthToken:f,displayManagementKey:u,setEditedHost:k,setEditedPort:N,setEditedAuthToken:y,setEditedManagementKey:C,onSaveHost:P,onSavePort:w,onSaveAuthToken:S,onSaveManagementKey:c,onSaveConfig:d,onTestConnection:p}){const i=t.remote,A=l=>l==="https"?443:H;return e.jsxs("div",{className:"space-y-4 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("h4",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4"}),"Remote Server Configuration"]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Host"}),e.jsx(I,{value:h,onChange:l=>k(l.target.value),onBlur:P,placeholder:"192.168.1.100 or proxy.example.com",className:"font-mono",disabled:r})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm text-muted-foreground",children:["Port"," ",e.jsxs("span",{className:"text-xs opacity-70",children:["(default: ",A(t.remote.protocol||"http"),")"]})]}),e.jsx(I,{type:"text",inputMode:"numeric",value:b,onChange:l=>N(l.target.value.replace(/\D/g,"")),onBlur:w,placeholder:`Leave empty for ${A(t.remote.protocol||"http")}`,className:"font-mono",disabled:r})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Protocol"}),e.jsxs(Ye,{value:t.remote.protocol||"http",onValueChange:l=>d({remote:{...i,protocol:l}}),disabled:r,children:[e.jsx($e,{children:e.jsx(He,{})}),e.jsxs(Ue,{children:[e.jsx(xe,{value:"http",children:"HTTP"}),e.jsx(xe,{value:"https",children:"HTTPS"})]})]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"API Key (optional)"}),e.jsx(I,{type:"password",value:f,onChange:l=>y(l.target.value),onBlur:S,placeholder:"For /v1/* API endpoints",className:"font-mono",disabled:r}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used for API requests to /v1/chat/completions"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Management Key (optional)"}),e.jsx(I,{type:"password",value:u,onChange:l=>C(l.target.value),onBlur:c,placeholder:"For /v0/management/* endpoints",className:"font-mono",disabled:r}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used for dashboard management APIs. Falls back to API Key if not set."})]}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsx($,{onClick:p,disabled:o||!h,variant:"outline",className:"w-full",children:o?e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"w-4 h-4 mr-2 animate-spin"}),"Testing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(We,{className:"w-4 h-4 mr-2"}),"Test Connection"]})}),m&&e.jsx("div",{className:`p-3 rounded-md ${m.reachable?"bg-green-50 border border-green-200 dark:bg-green-900/20 dark:border-green-900/50":"bg-red-50 border border-red-200 dark:bg-red-900/20 dark:border-red-900/50"}`,children:e.jsx("div",{className:"flex items-center gap-2",children:m.reachable?e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"w-4 h-4 text-green-600 dark:text-green-400"}),e.jsxs("span",{className:"text-sm font-medium text-green-700 dark:text-green-300",children:["Connected (",m.latencyMs,"ms)"]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Je,{className:"w-4 h-4 text-red-600 dark:text-red-400"}),e.jsx("span",{className:"text-sm font-medium text-red-700 dark:text-red-300",children:m.error||"Connection failed"})]})})})]})]})}const pe="ccs_debug_mode",ls=["kiro","ghcp"];function is(t){return t.trim().replace(/\s+/g," ").toUpperCase()}function Ns(){const{config:t,loading:r,saving:o,error:m,success:h,testResult:b,testing:f,editedHost:u,setEditedHost:k,editedPort:N,setEditedPort:y,editedAuthToken:C,setEditedAuthToken:P,editedManagementKey:w,setEditedManagementKey:S,editedLocalPort:c,setEditedLocalPort:d,fetchConfig:p,saveConfig:i,testConnection:A}=as(),{fetchRawConfig:l}=Oe(),[E,fe]=a.useState(()=>{try{return localStorage.getItem(pe)==="true"}catch{return!1}}),[ye,U]=a.useState(!1),[be,re]=a.useState(!0),[g,ae]=a.useState(!1),[je,_]=a.useState(!1),[oe,D]=a.useState(""),M=a.useRef(!1),O=is(oe)===Y,ve=s=>{fe(s);try{localStorage.setItem(pe,String(s))}catch{}},V=a.useCallback(async()=>{try{re(!0);const s=await fetch("/api/settings/auth/antigravity-risk");if(!s.ok)throw new Error("Failed to load AGY power user mode");const n=await s.json();U(n.antigravityAckBypass===!0)}catch(s){T.error(s instanceof Error?s.message:"Failed to load AGY power user mode"),U(!1)}finally{re(!1)}},[]),F=a.useCallback(async s=>{if(!(M.current||g||o))try{M.current=!0,ae(!0);const n=await fetch("/api/settings/auth/antigravity-risk",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({antigravityAckBypass:s})}),G=await n.json();if(!n.ok)throw new Error(G.error||"Failed to update AGY power user mode");const Fe=G.antigravityAckBypass===!0,de=await fetch("/api/settings/auth/antigravity-risk",{cache:"no-store"});if(!de.ok)throw new Error("Failed to verify AGY power user mode persistence");const me=(await de.json()).antigravityAckBypass===!0;if(me!==s)throw new Error("AGY power user mode was not persisted. Config may have been modified by another process.");U(me&&Fe),_(!1),D(""),T.success(s?"AGY power user mode enabled.":"AGY power user mode disabled."),await l()}catch(n){T.error(n instanceof Error?n.message:"Failed to update AGY power user mode")}finally{M.current=!1,ae(!1)}},[g,l,o]),ke=a.useCallback(s=>{if(!(M.current||g||o)){if(s){_(!0);return}_(!1),D(""),F(!1)}},[g,F,o]),Ne=a.useCallback(()=>{if(!O){T.error(`Type "${Y}" to continue.`);return}F(!0)},[O,F]),[j,z]=a.useState("plus"),[Ce,Pe]=a.useState(!1),q=Ve(),{data:we}=ze(),ne=we?.running??!1,W=a.useCallback(async()=>{try{const s=await R.cliproxyServer.getBackend();z(s.backend)}catch(s){console.error("[Proxy] Failed to fetch backend:",s)}},[]),J=a.useCallback(async()=>{try{const n=(await R.cliproxy.list()).variants.some(G=>ls.includes(G.provider));Pe(n)}catch(s){console.error("[Proxy] Failed to check variants:",s)}},[]),le=s=>{const n=j;z(s),q.mutate({backend:s},{onError:()=>{z(n)}})};if(a.useEffect(()=>{if(E&&t){const s={...t,remote:{...t.remote,auth_token:t.remote.auth_token?"[REDACTED]":void 0,management_key:t.remote.management_key?"[REDACTED]":void 0}};console.log("[CCS Debug] Debug mode enabled - proxy config:",s)}},[E,t]),a.useEffect(()=>{p(),V(),l(),W(),J()},[p,V,l,W,J]),r||!t)return 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(te,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})});const x=t.remote.enabled??!1,K=!x&&ne,v=t.remote,L=t.fallback,Se=t.remote.host??"",Ae=t.remote.port!==void 0?t.remote.port.toString():"",Ee=t.remote.auth_token??"",Te=t.remote.management_key??"",Ie=(t.local.port??H).toString(),X=u??Se,Q=N??Ae,Z=C??Ee,ie=w??Te,ce=c??Ie,Le=()=>{const s=u??X;s!==t.remote.host&&i({remote:{...v,host:s}}),k(null)},Be=()=>{const s=(N??Q).trim();if(s===""){t.remote.port!==void 0&&i({remote:{...v,port:void 0}}),y(null);return}const n=Number(s);if(!Number.isInteger(n)||n<1||n>65535){T.error("Port must be an integer between 1 and 65535, or empty for default"),y(null);return}n!==t.remote.port&&i({remote:{...v,port:n}}),y(null)},Re=()=>{const s=C??Z;s!==t.remote.auth_token&&i({remote:{...v,auth_token:s}}),P(null)},_e=()=>{const s=w??ie;s!==t.remote.management_key&&i({remote:{...v,management_key:s||void 0}}),S(null)},De=()=>{const s=(c??ce).trim(),n=s===""?H:Number(s);if(!Number.isInteger(n)||n<1||n>65535){T.error("Local port must be an integer between 1 and 65535"),d(null);return}n!==t.local.port&&i({local:{...t.local,port:n}}),d(null)},Me=()=>{A({host:X,port:Q,protocol:t.remote.protocol||"http",authToken:Z})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${m||h?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[m&&e.jsxs(ee,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(Xe,{className:"h-4 w-4"}),e.jsx(se,{children:m})]}),h&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(ge,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(qe,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Configure local or remote ",j==="plus"?"CLIProxy Plus":"CLIProxy"," connection for proxy-based profiles"]}),!x&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Instance Status"}),e.jsx(rs,{})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Connection Mode"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>i({remote:{...v,enabled:!1}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${x?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(Qe,{className:`w-5 h-5 ${x?"text-muted-foreground":"text-primary"}`}),e.jsx("span",{className:"font-medium",children:"Local"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Run ",j==="plus"?"CLIProxy Plus":"CLIProxy"," binary on this machine"]})]}),e.jsxs("button",{onClick:()=>i({remote:{...v,enabled:!0}}),disabled:o,className:`p-4 rounded-lg border-2 text-left transition-all ${x?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx(he,{className:`w-5 h-5 ${x?"text-primary":"text-muted-foreground"}`}),e.jsx("span",{className:"font-medium",children:"Remote"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Connect to a remote ",j==="plus"?"CLIProxy Plus":"CLIProxy"," server"]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(Ze,{className:"w-4 h-4"}),"Backend Binary"]}),!x&&ne&&e.jsxs(ee,{className:"py-2 border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-900/20 [&>svg]:top-2.5",children:[e.jsx(ue,{className:"h-4 w-4 text-amber-600"}),e.jsx(se,{className:"text-amber-700 dark:text-amber-400",children:"Stop the running proxy in Instance Status to switch backend."})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:()=>le("plus"),disabled:q.isPending||K,className:`p-4 rounded-lg border-2 text-left transition-all ${j==="plus"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${K?"opacity-60 cursor-not-allowed":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("span",{className:"font-medium",children:"CLIProxyAPIPlus"}),e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-100 text-green-700 dark:bg-green-900/50 dark:text-green-400",children:"Default"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Full provider support including Kiro and GitHub Copilot"})]}),e.jsxs("button",{onClick:()=>le("original"),disabled:q.isPending||K,className:`p-4 rounded-lg border-2 text-left transition-all ${j==="original"?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"} ${K?"opacity-60 cursor-not-allowed":""}`,children:[e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsx("span",{className:"font-medium",children:"CLIProxyAPI"})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Original binary (Gemini, Codex, Antigravity only)"})]})]}),j==="original"&&Ce&&e.jsxs(ee,{variant:"destructive",className:"py-2",children:[e.jsx(ue,{className:"h-4 w-4"}),e.jsx(se,{children:"Existing Kiro/Copilot variants will not work with CLIProxyAPI. Switch to CLIProxyAPIPlus or remove those variants."})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(es,{className:"w-4 h-4 text-amber-700 dark:text-amber-300"}),"Safety"]}),e.jsxs("div",{className:"space-y-3 rounded-lg border border-amber-400/35 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-950/25",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("p",{className:"font-medium text-sm",children:"Antigravity Power User Mode"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Skip AGY responsibility checklist in Add Account and `ccs agy` flows."})]}),e.jsx(B,{"aria-labelledby":"agy-power-user-mode-label","aria-describedby":"agy-power-user-mode-description",checked:ye,disabled:be||g||o,onCheckedChange:ke})]}),e.jsx("p",{id:"agy-power-user-mode-description",className:"text-xs text-amber-800/90 dark:text-amber-200/90",children:"Use only if you fully understand the OAuth suspension/ban risk pattern (#509). CCS cannot assume responsibility for account loss."}),je&&e.jsxs("div",{className:"space-y-3 rounded-lg border border-rose-500/40 bg-rose-500/[0.08] p-3.5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold tracking-wide text-rose-900 dark:text-rose-200",children:"Final confirmation required"}),e.jsx("p",{className:"text-xs leading-relaxed text-rose-800/95 dark:text-rose-200/90",children:"Enabling this will skip AGY safety checkpoints in both dashboard and CLI. Review issue #509 and type the exact phrase to proceed."})]}),e.jsxs("div",{className:"grid gap-2 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:"Step 1"}),e.jsxs("a",{href:"https://github.com/kaitranntt/ccs/issues/509",target:"_blank",rel:"noreferrer",className:"mt-1 inline-flex items-center gap-1.5 text-xs font-medium text-rose-800 underline decoration-rose-500/60 underline-offset-2 transition-colors hover:text-rose-700 dark:text-rose-200",children:["Read issue #509",e.jsx(ss,{className:"h-3.5 w-3.5"})]})]}),e.jsxs("div",{className:"rounded-md border border-rose-400/30 bg-rose-500/10 p-2.5",children:[e.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-rose-900 dark:text-rose-200",children:"Step 2"}),e.jsxs("p",{className:"mt-1 text-xs text-rose-800/95 dark:text-rose-200/90",children:["Type"," ",e.jsx("code",{className:"rounded bg-background/80 px-1 py-0.5 font-mono",children:Y})," ","to enable."]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{value:oe,onChange:s=>D(s.target.value),placeholder:Y,disabled:g||o,className:"font-mono text-xs","aria-label":"Type I ACCEPT RISK to enable Antigravity power user mode"}),e.jsx("p",{className:"text-[11px] text-rose-800/90 dark:text-rose-200/80",children:"Exact phrase required."})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx($,{variant:"outline",size:"sm",onClick:()=>{_(!1),D("")},disabled:g||o,children:"Cancel"}),e.jsx($,{size:"sm",variant:"destructive",onClick:Ne,disabled:!O||g||o,children:"Enable Power User Mode"})]})]}),e.jsx("span",{id:"agy-power-user-mode-label",className:"sr-only",children:"Toggle AGY power user mode"})]})]}),x&&e.jsx(ns,{config:t,saving:o,testing:f,testResult:b,displayHost:X,displayPort:Q,displayAuthToken:Z,displayManagementKey:ie,setEditedHost:k,setEditedPort:y,setEditedAuthToken:P,setEditedManagementKey:S,onSaveHost:Le,onSavePort:Be,onSaveAuthToken:Re,onSaveManagementKey:_e,onSaveConfig:i,onTestConnection:Me}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Fallback Settings"}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Enable fallback to local"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use local proxy if remote is unreachable"})]}),e.jsx(B,{checked:L.enabled??!0,onCheckedChange:s=>i({fallback:{...L,enabled:s}}),disabled:o||!x})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Auto-start local proxy"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Automatically start local proxy on fallback"})]}),e.jsx(B,{checked:L.auto_start??!1,onCheckedChange:s=>i({fallback:{...L,auto_start:s}}),disabled:o||!x||!L.enabled})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("h3",{className:"text-base font-medium flex items-center gap-2",children:[e.jsx(ts,{className:"w-4 h-4"}),"Advanced"]}),e.jsxs("div",{className:"space-y-3 p-4 rounded-lg border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-sm",children:"Debug Mode"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enable developer diagnostics in browser console"})]}),e.jsx(B,{checked:E,onCheckedChange:ve,disabled:o})]}),E&&e.jsx("p",{className:"text-xs text-amber-600 dark:text-amber-400 pl-0.5",children:"Debug mode enabled. Check browser console for detailed logs."})]})]}),!x&&e.jsx(os,{config:t,saving:o,displayLocalPort:ce,setEditedLocalPort:d,onSaveLocalPort:De,onSaveConfig:i})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs($,{variant:"outline",size:"sm",onClick:()=>{p(),V(),l(),W(),J()},disabled:r||o||g,className:"w-full",children:[e.jsx(te,{className:`w-4 h-4 mr-2 ${r?"animate-spin":""}`}),"Refresh"]})})]})}export{Ns as default};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-C1Gpgz6I.js";import{r as a}from"./react-vendor-CNOkPC89.js";import{b4 as q,b6 as W,b as T,m as Y,L,q as D,r as M,s as K,t as $,v as I,I as F}from"./index-DNFjYwGe.js";import{S as J}from"./switch-B3t2TDvW.js";import{R as z,a2 as X,r as Q,a4 as Z,I as ee,Y as se}from"./icons-DrewC9c3.js";import"./tanstack-DDJIhNJd.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";const B={mode:"auto",tier_defaults:{opus:"high",sonnet:"medium",haiku:"low"},show_warnings:!0},U=1e4;function re(){const[t,f]=a.useState(null),[l,j]=a.useState(!0),[w,v]=a.useState(!1),[E,m]=a.useState(null),[A,p]=a.useState(!1),N=a.useRef(void 0),C=a.useRef(!1),b=a.useCallback(async()=>{const r=new AbortController,d=setTimeout(()=>r.abort(),U);try{j(!0),m(null);const n=await fetch("/api/thinking",{signal:r.signal});if(clearTimeout(d),!n.ok)throw n.headers.get("content-type")?.includes("text/html")?new Error(`Server error (${n.status})`):new Error("Failed to load Thinking config");const c=await n.json();f(c.config||B),N.current=c.lastModified,C.current=!0}catch(n){clearTimeout(d),n.name==="AbortError"?m("Request timeout - please try again"):m(n.message)}finally{j(!1)}return()=>r.abort()},[]),o=a.useCallback(async r=>{if(!C.current||t===null){m("Cannot save settings before they load. Click Refresh and try again.");return}const d=t,n={...d,...r.mode!==void 0?{mode:r.mode}:{},...r.tier_defaults!==void 0?{tier_defaults:r.tier_defaults}:{},...r.show_warnings!==void 0?{show_warnings:r.show_warnings}:{}};r.clear_override||r.override===null?delete n.override:r.override!==void 0&&(n.override=r.override),r.clear_provider_overrides||r.provider_overrides===null?delete n.provider_overrides:r.provider_overrides!==void 0&&(n.provider_overrides=r.provider_overrides),f(n);const c=new AbortController,h=setTimeout(()=>c.abort(),U);try{v(!0),m(null);const x={...n,lastModified:N.current},u=await fetch("/api/thinking",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(x),signal:c.signal});if(clearTimeout(h),!u.ok){if(u.headers.get("content-type")?.includes("text/html"))throw new Error(`Server error (${u.status})`);const i=await u.json();throw u.status===409?new Error("Config changed by another session. Refreshing..."):new Error(i.error||"Failed to save")}const g=await u.json();f(g.config),N.current=g.lastModified,p(!0),setTimeout(()=>p(!1),1500)}catch(x){clearTimeout(h),f(d),x.name==="AbortError"?m("Request timeout - please try again"):(m(x.message),x.message.includes("another session")&&setTimeout(()=>b(),1e3))}finally{v(!1)}},[t,b]),S=a.useCallback(r=>{o({mode:r})},[o]),O=a.useCallback((r,d)=>{const n=t?.tier_defaults||B.tier_defaults;o({tier_defaults:{...n,[r]:d}})},[t,o]),R=a.useCallback(r=>{o({show_warnings:r})},[o]),P=a.useCallback(r=>{if(r===void 0){o({override:null,clear_override:!0});return}o({override:r,clear_override:!1})},[o]),y=a.useCallback((r,d,n)=>{const c=t?.provider_overrides||{},h=c[r]||{};if(n===void 0){const{[d]:x,...u}=h,g=Object.keys(u).length>0?u:void 0,{[r]:s,...i}=c,k=g?{...i,[r]:g}:i;o({provider_overrides:Object.keys(k).length>0?k:null,clear_provider_overrides:Object.keys(k).length===0})}else o({provider_overrides:{...c,[r]:{...h,[d]:n}},clear_provider_overrides:!1})},[t,o]);return{config:t||B,loading:l,saving:w,error:E,success:A,fetchConfig:b,saveConfig:o,setMode:S,setTierDefault:O,setShowWarnings:R,setOverride:P,setProviderOverride:y}}const H=[{value:"minimal",label:"Minimal (512 tokens)"},{value:"low",label:"Low (1K tokens)"},{value:"medium",label:"Medium (8K tokens)"},{value:"high",label:"High (24K tokens)"},{value:"xhigh",label:"Extra High (32K tokens)"},{value:"auto",label:"Auto (dynamic)"}],te=[{value:"__none__",label:"None (use CLI flags only)"},...H,{value:"__custom__",label:"Custom budget (number)"},{value:"off",label:"Off (disable thinking)"}],ie=["agy","gemini","codex"],V=0,G=1e5;function fe(){const{config:t,loading:f,saving:l,error:j,success:w,fetchConfig:v,setMode:E,setTierDefault:m,setShowWarnings:A,setOverride:p,setProviderOverride:N}=re(),[C,b]=a.useState(null),[o,S]=a.useState(""),[O,R]=a.useState([]),[P,y]=a.useState(null),r=a.useMemo(()=>Array.from(new Set([...ie,...Object.keys(t.provider_overrides??{}),...O])),[O,t.provider_overrides]),d=t.override===void 0?"__none__":typeof t.override=="number"||/^\d+$/.test(String(t.override))?"__custom__":String(t.override),n=typeof t.override=="number"||/^\d+$/.test(String(t.override??""))?String(t.override):"",c=P??n,h=Object.keys(t.provider_overrides??{}).length>0,x=C??h;a.useEffect(()=>{v()},[v]);const u=()=>{const s=o.trim().toLowerCase();s&&(r.includes(s)||R(i=>[...i,s]),S(""),b(!0))},g=()=>{const s=c.trim();if(!s){p(void 0);return}const i=Number.parseInt(s,10);Number.isNaN(i)||i<V||i>G||!/^\d+$/.test(s)||p(i)};return f?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(z,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${j||w?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[j&&e.jsx(q,{variant:"destructive",className:"py-2 shadow-lg",children:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(X,{className:"h-4 w-4"}),e.jsx(W,{children:j})]}),e.jsxs(T,{variant:"outline",size:"sm",onClick:v,className:"h-7 px-2 text-xs border-destructive/50 hover:bg-destructive/10",children:[e.jsx(z,{className:"w-3 h-3 mr-1"}),"Retry"]})]})}),w&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(Q,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(Y,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Z,{className:"w-5 h-5 text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure extended thinking/reasoning for supported models."})]}),e.jsxs("div",{className:"flex items-start gap-2 p-3 rounded-lg bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800",children:[e.jsx(ee,{className:"w-4 h-4 text-blue-600 dark:text-blue-400 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm text-blue-700 dark:text-blue-300",children:[e.jsx("p",{className:"font-medium",children:"Supported Providers"}),e.jsxs("ul",{className:"mt-1 space-y-0.5 text-blue-600 dark:text-blue-400",children:[e.jsxs("li",{children:["Thinking budget: ",e.jsx("strong",{children:"agy"}),", ",e.jsx("strong",{children:"gemini"})," (token-based)"]}),e.jsxs("li",{children:["Reasoning effort: ",e.jsx("strong",{children:"codex"})," (suffix or ",e.jsx("code",{children:"--effort"}),": medium/high/xhigh)"]}),e.jsxs("li",{children:["Codex suffixes pin effort (for example ",e.jsx("code",{children:"-high"}),"); unsuffixed models use Thinking mode."]})]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Thinking Mode"}),e.jsx("div",{className:"space-y-2",children:["auto","off","manual"].map(s=>e.jsxs("div",{className:`flex items-center justify-between p-4 rounded-lg cursor-pointer transition-colors ${t.mode===s?"bg-primary/10 border border-primary/30":"bg-muted/50 hover:bg-muted/80"} ${l?"opacity-70 pointer-events-none":""}`,onClick:()=>{l||E(s)},children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium capitalize",children:s}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s==="auto"&&"Automatically set thinking based on model tier",s==="off"&&"Disable extended thinking",s==="manual"&&"Set a persistent override level or use CLI flags per run"]})]}),e.jsx("div",{className:`w-4 h-4 rounded-full border-2 ${t.mode===s?"bg-primary border-primary":"border-muted-foreground/50"}`})]},s))})]}),t.mode==="auto"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Tier Defaults"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Default thinking level for each model tier when in auto mode."}),e.jsx("div",{className:"space-y-3",children:["opus","sonnet","haiku"].map(s=>e.jsxs("div",{className:"flex items-center gap-4 p-3 rounded-lg bg-muted/30",children:[e.jsx(L,{className:"w-20 capitalize font-medium",children:s}),e.jsxs(D,{value:t.tier_defaults[s],onValueChange:i=>m(s,i),disabled:l,children:[e.jsx(M,{className:"flex-1",children:e.jsx(K,{})}),e.jsx($,{children:H.map(i=>e.jsx(I,{value:i.value,children:i.label},i.value))})]})]},s))})]}),t.mode==="manual"&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Persistent Override"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Applied to all sessions. CLI flags still take priority."}),e.jsxs(D,{value:d,onValueChange:s=>{if(s==="__none__"){p(void 0);return}if(s==="__custom__"){c||y("8192");return}y(null),p(s)},disabled:l,children:[e.jsx(M,{children:e.jsx(K,{})}),e.jsx($,{children:te.map(s=>e.jsx(I,{value:s.value,children:s.label},s.value))})]}),d==="__custom__"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{type:"number",min:V,max:G,value:c,onChange:s=>y(s.target.value),onBlur:g,disabled:l,placeholder:"Enter custom budget"}),e.jsx(T,{type:"button",size:"sm",variant:"outline",onClick:g,disabled:l,children:"Apply"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Range: ",V," to ",G]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("button",{type:"button",className:"flex items-center gap-2 text-base font-medium w-full text-left",onClick:()=>b(s=>!(s??h)),disabled:l,children:[e.jsx(se,{className:`w-4 h-4 transition-transform ${x?"rotate-0":"-rotate-90"}`}),"Provider Overrides (",Object.keys(t.provider_overrides??{}).length,")"]}),x&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Override tier defaults for specific providers. Add custom provider keys as needed."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{value:o,onChange:s=>S(s.target.value),disabled:l,placeholder:"Add provider key (e.g. qwen)"}),e.jsx(T,{type:"button",size:"sm",variant:"outline",onClick:u,disabled:l,children:"Add"})]}),r.map(s=>e.jsxs("div",{className:"space-y-2 p-3 rounded-lg bg-muted/30",children:[e.jsx(L,{className:"capitalize font-medium text-sm",children:s}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:["opus","sonnet","haiku"].map(i=>{const k=t.provider_overrides?.[s]?.[i]||"__default__";return e.jsxs("div",{className:"space-y-1",children:[e.jsx(L,{className:"text-xs text-muted-foreground capitalize",children:i}),e.jsxs(D,{value:k,onValueChange:_=>N(s,i,_==="__default__"?void 0:_),disabled:l,children:[e.jsx(M,{className:"h-8 text-xs",children:e.jsx(K,{})}),e.jsxs($,{children:[e.jsx(I,{value:"__default__",children:"Default"}),H.map(_=>e.jsx(I,{value:_.value,children:_.label},_.value))]})]})]},i)})})]},s))]})]}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Show Warnings"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Display warnings when thinking values are clamped or adjusted"})]}),e.jsx(J,{checked:t.show_warnings??!0,onCheckedChange:A,disabled:l})]}),e.jsxs("div",{className:"p-4 rounded-lg border bg-muted/30",children:[e.jsx("h4",{className:"text-sm font-medium mb-2",children:"CLI & Env Override"}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-2",children:["Override per session with flags or"," ",e.jsx("code",{className:"px-1.5 py-0.5 rounded bg-muted",children:"CCS_THINKING"})," env var. Priority: flag > env > config."]}),e.jsxs("div",{className:"space-y-1 text-sm font-mono text-muted-foreground",children:[e.jsx("p",{children:"ccs gemini --thinking high"}),e.jsx("p",{children:"ccs codex --effort xhigh"}),e.jsx("p",{children:'CCS_THINKING=high ccs codex "debug this"'}),e.jsx("p",{children:"ccs config thinking --mode auto"})]})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(T,{variant:"outline",size:"sm",onClick:v,disabled:f||l,className:"w-full",children:[e.jsx(z,{className:`w-4 h-4 mr-2 ${f?"animate-spin":""}`}),"Refresh"]})})]})}export{fe as default};
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-C1Gpgz6I.js";import{r as i}from"./react-vendor-CNOkPC89.js";import{bb as P,bc as $,I as F,bd as U,b4 as _,b6 as z,m as B,b as O}from"./index-DNFjYwGe.js";import{S as K}from"./switch-B3t2TDvW.js";import{z as Y,k as q,_ as D,Y as J,n as Q,R as y,a2 as V,r as X,aQ as Z}from"./icons-DrewC9c3.js";import"./tanstack-DDJIhNJd.js";import"./notifications-B2HqRBj7.js";import"./utils-CzKF5WmX.js";import"./form-utils-Cn_Uld6y.js";import"./code-highlight-BRUf_pqB.js";function ee(){const{state:s}=P(),a=$(),[d,l]=i.useState(""),[o,m]=i.useState(""),[f,h]=i.useState(!1),[j,u]=i.useState(!1),S=i.useCallback(async()=>{try{a.setWebSearchLoading(!0),a.setWebSearchError(null);const t=await fetch("/api/websearch");if(!t.ok)throw new Error("Failed to load WebSearch config");const r=await t.json();a.setWebSearchConfig(r)}catch(t){a.setWebSearchError(t.message)}finally{a.setWebSearchLoading(!1)}},[a]),v=i.useCallback(async()=>{try{a.setWebSearchStatusLoading(!0);const t=await fetch("/api/websearch/status");if(!t.ok)throw new Error("Failed to load status");const r=await t.json();a.setWebSearchStatus(r)}catch{}finally{a.setWebSearchStatusLoading(!1)}},[a]),g=i.useCallback(async t=>{const r=s.webSearchConfig;if(!r)return;const w={...r,...t};a.setWebSearchConfig(w);try{a.setWebSearchSaving(!0),a.setWebSearchError(null);const n=await fetch("/api/websearch",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(w)});if(!n.ok){const k=await n.json();throw new Error(k.error||"Failed to save")}const C=await n.json();a.setWebSearchConfig(C.websearch),a.setWebSearchSuccess(!0),setTimeout(()=>a.setWebSearchSuccess(!1),1500)}catch(n){a.setWebSearchConfig(r),a.setWebSearchError(n.message)}finally{a.setWebSearchSaving(!1)}},[s.webSearchConfig,a]);i.useEffect(()=>{s.webSearchConfig&&(l(s.webSearchConfig.providers?.gemini?.model??"gemini-2.5-flash"),m(s.webSearchConfig.providers?.opencode?.model??"opencode/grok-code"))},[s.webSearchConfig]);const x=i.useCallback(async()=>{const t=s.webSearchConfig?.providers?.gemini?.model??"gemini-2.5-flash";if(d!==t){const r=s.webSearchConfig?.providers||{};await g({providers:{...r,gemini:{...r.gemini,model:d}}}),h(!0),setTimeout(()=>h(!1),2e3)}},[d,s.webSearchConfig,g]),p=i.useCallback(async()=>{const t=s.webSearchConfig?.providers?.opencode?.model??"opencode/grok-code";if(o!==t){const r=s.webSearchConfig?.providers||{};await g({providers:{...r,opencode:{...r.opencode,model:o}}}),u(!0),setTimeout(()=>u(!1),2e3)}},[o,s.webSearchConfig,g]);return{config:s.webSearchConfig,status:s.webSearchStatus,loading:s.webSearchLoading,statusLoading:s.webSearchStatusLoading,saving:s.webSearchSaving,error:s.webSearchError,success:s.webSearchSuccess,geminiModelInput:d,setGeminiModelInput:l,opencodeModelInput:o,setOpencodeModelInput:m,geminiModelSaved:f,opencodeModelSaved:j,fetchConfig:S,fetchStatus:v,saveConfig:g,saveGeminiModel:x,saveOpencodeModel:p}}function A({name:s,label:a,badge:d,badgeColor:l,enabled:o,installed:m,statusLoading:f,saving:h,onToggle:j,modelInput:u,setModelInput:S,onModelBlur:v,modelSaved:g,modelPlaceholder:x,showHint:p,setShowHint:t,installCmd:r,docsUrl:w,hintColor:n}){const C=l==="green"?"bg-green-500/10 text-green-600":l==="blue"?"bg-blue-500/10 text-blue-600":"bg-purple-500/10 text-purple-600",k=n==="amber"?"bg-amber-50 dark:bg-amber-900/20 text-amber-700 dark:text-amber-300":n==="blue"?"bg-blue-50 dark:bg-blue-900/20 text-blue-700 dark:text-blue-300":"bg-purple-50 dark:bg-purple-900/20 text-purple-700 dark:text-purple-300",E=n==="amber"?"bg-amber-100 dark:bg-amber-900/40":n==="blue"?"bg-blue-100 dark:bg-blue-900/40":"bg-purple-100 dark:bg-purple-900/40",I=n==="amber"?"text-amber-600 dark:text-amber-400":n==="blue"?"text-blue-600 dark:text-blue-400":"text-purple-600 dark:text-purple-400",M=s==="opencode"?"OpenCode":s.charAt(0).toUpperCase()+s.slice(1);return e.jsxs("div",{className:`rounded-lg border transition-colors ${o?"border-primary border-l-4":"border-border"}`,children:[e.jsxs("div",{className:"flex items-center justify-between p-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Y,{className:`w-5 h-5 ${o?"text-primary":"text-muted-foreground"}`}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("p",{className:"font-mono font-medium",children:s}),e.jsx("span",{className:`text-xs px-1.5 py-0.5 rounded font-medium ${C}`,children:d}),m?e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-green-500/10 text-green-600 font-medium",children:"installed"}):e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-600 font-medium",children:"not installed"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:a})]})]}),e.jsx(K,{checked:o,onCheckedChange:j,disabled:h||!m})]}),o&&u!==void 0&&S&&v&&e.jsx("div",{className:"px-4 pb-4 pt-0",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground whitespace-nowrap",children:"Model:"}),e.jsx(F,{value:u,onChange:W=>S(W.target.value),onBlur:v,placeholder:x,className:"h-8 text-sm font-mono",disabled:h}),g&&e.jsxs("span",{className:"flex items-center gap-1 text-green-600 dark:text-green-400 text-xs animate-in fade-in duration-200",children:[e.jsx(q,{className:"w-3.5 h-3.5"}),"Saved"]})]})}),!m&&!f&&e.jsxs("div",{className:"px-4 pb-4 pt-0 border-t border-border/50",children:[e.jsxs("button",{onClick:()=>t(!p),className:`flex items-center gap-2 text-sm hover:underline w-full py-2 ${I}`,children:[p?e.jsx(D,{className:"w-4 h-4"}):e.jsx(J,{className:"w-4 h-4"}),"How to install ",M," CLI"]}),p&&e.jsxs("div",{className:`mt-2 p-3 rounded-md text-sm ${k}`,children:[e.jsxs("p",{className:"mb-2",children:["Install globally"," ",d==="GROK_API_KEY"?"(requires xAI API key)":"(FREE tier available)",":"]}),e.jsx("code",{className:`text-sm px-2 py-1 rounded font-mono block mb-2 ${E}`,children:r}),e.jsxs("a",{href:w,target:"_blank",rel:"noopener noreferrer",className:"hover:underline inline-flex items-center gap-1",children:[e.jsx(Q,{className:"w-3 h-3"}),"View documentation"]})]})]})]})}function me(){const{config:s,status:a,loading:d,statusLoading:l,saving:o,error:m,success:f,geminiModelInput:h,setGeminiModelInput:j,opencodeModelInput:u,setOpencodeModelInput:S,geminiModelSaved:v,opencodeModelSaved:g,fetchConfig:x,fetchStatus:p,saveConfig:t,saveGeminiModel:r,saveOpencodeModel:w}=ee(),{fetchRawConfig:n}=U(),[C,k]=i.useState(!1),[E,I]=i.useState(!1),[M,W]=i.useState(!1);i.useEffect(()=>{x(),p(),n()},[x,p,n]);const N=s?.providers?.gemini?.enabled??!1,G=s?.providers?.grok?.enabled??!1,L=s?.providers?.opencode?.enabled??!1,H=()=>{const c=s?.providers||{},b=c.gemini?.enabled??!1;t({enabled:!b||G||L,providers:{...c,gemini:{...c.gemini,enabled:!b}}})},R=()=>{const c=s?.providers||{},b=c.grok?.enabled??!1;t({enabled:N||!b||L,providers:{...c,grok:{...c.grok,enabled:!b}}})},T=()=>{const c=s?.providers||{},b=c.opencode?.enabled??!1;t({enabled:N||G||!b,providers:{...c,opencode:{...c.opencode,enabled:!b}}})};return d?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(y,{className:"w-5 h-5 animate-spin"}),e.jsx("span",{children:"Loading..."})]})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`absolute left-5 right-5 top-20 z-10 transition-all duration-200 ease-out ${m||f?"opacity-100 translate-y-0":"opacity-0 -translate-y-2 pointer-events-none"}`,children:[m&&e.jsxs(_,{variant:"destructive",className:"py-2 shadow-lg",children:[e.jsx(V,{className:"h-4 w-4"}),e.jsx(z,{children:m})]}),f&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md border border-green-200 bg-green-50 text-green-700 shadow-lg dark:border-green-900/50 dark:bg-green-900/90 dark:text-green-300",children:[e.jsx(X,{className:"h-4 w-4 shrink-0"}),e.jsx("span",{className:"text-sm font-medium",children:"Saved"})]})]}),e.jsx(B,{className:"flex-1",children:e.jsxs("div",{className:"p-5 space-y-6",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"CLI-based web search for third-party profiles (gemini, codex, agy, etc.)"}),e.jsxs("div",{className:"flex items-center justify-between p-4 rounded-lg bg-muted/50",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:N?"WebSearch enabled":"WebSearch disabled"}),l?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Checking status..."}):a?.readiness?e.jsx("p",{className:"text-sm text-muted-foreground",children:a.readiness.message}):null]}),e.jsx(O,{variant:"ghost",size:"sm",onClick:p,disabled:l,children:e.jsx(y,{className:`w-4 h-4 ${l?"animate-spin":""}`})})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-base font-medium",children:"Providers"}),!a?.geminiCli&&!a?.opencodeCli&&!a?.grokCli&&!l&&e.jsxs("div",{className:"flex flex-col items-center justify-center p-8 border-2 border-dashed rounded-lg text-center bg-muted/30",children:[e.jsx(Z,{className:"w-12 h-12 text-muted-foreground mb-3 opacity-30"}),e.jsx("p",{className:"font-medium text-foreground mb-1",children:"No providers configured"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Install CLI tools to enable web search providers"}),e.jsxs(O,{variant:"outline",size:"sm",onClick:p,children:[e.jsx(y,{className:"w-4 h-4 mr-2"}),"Check for providers"]})]}),e.jsx(A,{name:"gemini",label:"Google Gemini CLI (1000 req/day free)",badge:"FREE",badgeColor:"green",enabled:N,installed:a?.geminiCli?.installed??!1,statusLoading:l,saving:o,onToggle:H,modelInput:h,setModelInput:j,onModelBlur:r,modelSaved:v,modelPlaceholder:"gemini-2.5-flash",showHint:C,setShowHint:k,installCmd:"npm install -g @google/gemini-cli",docsUrl:"https://github.com/google-gemini/gemini-cli",hintColor:"amber"}),e.jsx(A,{name:"opencode",label:"OpenCode (web search via Zen)",badge:"FREE",badgeColor:"green",enabled:L,installed:a?.opencodeCli?.installed??!1,statusLoading:l,saving:o,onToggle:T,modelInput:u,setModelInput:S,onModelBlur:w,modelSaved:g,modelPlaceholder:"opencode/grok-code",showHint:E,setShowHint:I,installCmd:"curl -fsSL https://opencode.ai/install | bash",docsUrl:"https://github.com/sst/opencode",hintColor:"purple"}),e.jsx(A,{name:"grok",label:"xAI Grok CLI (web + X search)",badge:"GROK_API_KEY",badgeColor:"blue",enabled:G,installed:a?.grokCli?.installed??!1,statusLoading:l,saving:o,onToggle:R,showHint:M,setShowHint:W,installCmd:"npm install -g @vibe-kit/grok-cli",docsUrl:"https://github.com/superagent-ai/grok-cli",hintColor:"blue"})]})]})}),e.jsx("div",{className:"p-4 border-t bg-background",children:e.jsxs(O,{variant:"outline",size:"sm",onClick:()=>{x(),n()},disabled:d||o,className:"w-full",children:[e.jsx(y,{className:`w-4 h-4 mr-2 ${d?"animate-spin":""}`}),"Refresh"]})})]})}export{me as default};