@kaitranntt/ccs 8.8.1-dev.1 → 8.8.1-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 (112) hide show
  1. package/README.md +5 -4
  2. package/dist/api/services/profile-lifecycle-validation.d.ts.map +1 -1
  3. package/dist/api/services/profile-lifecycle-validation.js +3 -8
  4. package/dist/api/services/profile-lifecycle-validation.js.map +1 -1
  5. package/dist/cliproxy/accounts/registry.d.ts.map +1 -1
  6. package/dist/cliproxy/accounts/registry.js +14 -16
  7. package/dist/cliproxy/accounts/registry.js.map +1 -1
  8. package/dist/cliproxy/ai-providers/model-id-normalizer.d.ts +1 -1
  9. package/dist/cliproxy/ai-providers/model-id-normalizer.d.ts.map +1 -1
  10. package/dist/cliproxy/config/generator.d.ts.map +1 -1
  11. package/dist/cliproxy/config/generator.js +22 -2
  12. package/dist/cliproxy/config/generator.js.map +1 -1
  13. package/dist/cliproxy/model-catalog.d.ts.map +1 -1
  14. package/dist/cliproxy/model-catalog.js +17 -0
  15. package/dist/cliproxy/model-catalog.js.map +1 -1
  16. package/dist/cliproxy/quota/quota-fetcher-claude.d.ts.map +1 -1
  17. package/dist/cliproxy/quota/quota-fetcher-claude.js +11 -1
  18. package/dist/cliproxy/quota/quota-fetcher-claude.js.map +1 -1
  19. package/dist/cliproxy/routing/retry-settings.d.ts +18 -0
  20. package/dist/cliproxy/routing/retry-settings.d.ts.map +1 -0
  21. package/dist/cliproxy/routing/retry-settings.js +185 -0
  22. package/dist/cliproxy/routing/retry-settings.js.map +1 -0
  23. package/dist/cliproxy/routing/routing-strategy-http.d.ts +3 -0
  24. package/dist/cliproxy/routing/routing-strategy-http.d.ts.map +1 -1
  25. package/dist/cliproxy/routing/routing-strategy-http.js +13 -3
  26. package/dist/cliproxy/routing/routing-strategy-http.js.map +1 -1
  27. package/dist/cliproxy/session-tracker.d.ts.map +1 -1
  28. package/dist/cliproxy/session-tracker.js +4 -18
  29. package/dist/cliproxy/session-tracker.js.map +1 -1
  30. package/dist/commands/cliproxy/quota-subcommand/sections/claude.d.ts.map +1 -1
  31. package/dist/commands/cliproxy/quota-subcommand/sections/claude.js +2 -1
  32. package/dist/commands/cliproxy/quota-subcommand/sections/claude.js.map +1 -1
  33. package/dist/commands/setup-command.js +1 -1
  34. package/dist/commands/setup-command.js.map +1 -1
  35. package/dist/commands/version-command.js +1 -1
  36. package/dist/commands/version-command.js.map +1 -1
  37. package/dist/config/schemas/cliproxy.d.ts +23 -0
  38. package/dist/config/schemas/cliproxy.d.ts.map +1 -1
  39. package/dist/config/schemas/cliproxy.js +13 -1
  40. package/dist/config/schemas/cliproxy.js.map +1 -1
  41. package/dist/shared/extended-context-utils.d.ts +1 -1
  42. package/dist/shared/extended-context-utils.d.ts.map +1 -1
  43. package/dist/shared/extended-context-utils.js +1 -0
  44. package/dist/shared/extended-context-utils.js.map +1 -1
  45. package/dist/ui/assets/{Trans-BTOdiwQc.js → Trans-dQ5QXCeL.js} +1 -1
  46. package/dist/ui/assets/{accounts-CVV5qf-s.js → accounts-DMMNI7g4.js} +1 -1
  47. package/dist/ui/assets/{alert-dialog-dwnTAMrx.js → alert-dialog-BIWuuEiP.js} +1 -1
  48. package/dist/ui/assets/{api-DMlBRB1d.js → api-BKTghVxS.js} +1 -1
  49. package/dist/ui/assets/{auth-section-D-8VFxj-.js → auth-section-BKDcPs0P.js} +1 -1
  50. package/dist/ui/assets/{backups-section-BMoPVfss.js → backups-section-DB1N4X1P.js} +1 -1
  51. package/dist/ui/assets/{channels-01330zzz.js → channels-dhk_rRcA.js} +1 -1
  52. package/dist/ui/assets/{checkbox-D90euwtT.js → checkbox-h1pwW_6m.js} +1 -1
  53. package/dist/ui/assets/{claude-extension-YrcmNoqS.js → claude-extension-WLOGl6eK.js} +1 -1
  54. package/dist/ui/assets/cliproxy-CE_mZIGU.js +4 -0
  55. package/dist/ui/assets/{cliproxy-ai-providers-hIp8fhPI.js → cliproxy-ai-providers-DVkAmHVF.js} +5 -5
  56. package/dist/ui/assets/{cliproxy-control-panel-DZULkDd2.js → cliproxy-control-panel-D25OT5u5.js} +1 -1
  57. package/dist/ui/assets/{codex-CPrRO-lX.js → codex-Bqc25al7.js} +1 -1
  58. package/dist/ui/assets/{confirm-dialog-D3AQRal2.js → confirm-dialog-BnAIV9ZB.js} +1 -1
  59. package/dist/ui/assets/{copilot-wVeMPslf.js → copilot-BdjZjuRs.js} +2 -2
  60. package/dist/ui/assets/{cursor-CNtEFxNr.js → cursor-DTbIQ-d7.js} +1 -1
  61. package/dist/ui/assets/{droid-Dux87vgL.js → droid-DAjrpAjP.js} +1 -1
  62. package/dist/ui/assets/{globalenv-section-DQaZlUu9.js → globalenv-section-BzirfKtN.js} +1 -1
  63. package/dist/ui/assets/{health-gz6ld9tF.js → health-CDCop1Et.js} +1 -1
  64. package/dist/ui/assets/index-B4yjQknk.js +56 -0
  65. package/dist/ui/assets/{index-BqCWQTXC.js → index-BF4hYrQf.js} +1 -1
  66. package/dist/ui/assets/{index-B4YzYZ3N.js → index-BhGdNER3.js} +1 -1
  67. package/dist/ui/assets/{index-D4ZnFjI-.js → index-DMGiMF5C.js} +1 -1
  68. package/dist/ui/assets/{index-4qh8YPnm.js → index-Dkee4NQG.js} +1 -1
  69. package/dist/ui/assets/{index-D33IsBj2.js → index-bC8F80OC.js} +1 -1
  70. package/dist/ui/assets/{index-Bv5KphSU.js → index-vdkPayvk.js} +1 -1
  71. package/dist/ui/assets/{logs-DIoXbk6b.js → logs-Bb1BaiFq.js} +1 -1
  72. package/dist/ui/assets/{masked-input-D6AHQpvJ.js → masked-input-DxWhb6sQ.js} +1 -1
  73. package/dist/ui/assets/proxy-status-widget-Dj_46CdP.js +1 -0
  74. package/dist/ui/assets/{raw-json-settings-editor-panel-kUoKhfLK.js → raw-json-settings-editor-panel-BeZJbsnO.js} +1 -1
  75. package/dist/ui/assets/{searchable-select-DO8VBumf.js → searchable-select-CcXdAHJm.js} +1 -1
  76. package/dist/ui/assets/{separator-BMAKvIfO.js → separator-O1g2RdCE.js} +1 -1
  77. package/dist/ui/assets/{shared-BMHgpQ9x.js → shared-Ct6UqE0N.js} +1 -1
  78. package/dist/ui/assets/{table-UWsBM0x-.js → table-D4ZJKsoh.js} +1 -1
  79. package/dist/ui/assets/{updates-BMeAtdI6.js → updates-jnNBispr.js} +1 -1
  80. package/dist/ui/assets/{use-accounts-r2G8nswz.js → use-accounts-DXwh5f2t.js} +1 -1
  81. package/dist/ui/index.html +2 -2
  82. package/dist/utils/shell-executor.d.ts +1 -1
  83. package/dist/utils/shell-executor.d.ts.map +1 -1
  84. package/dist/utils/shell-executor.js +5 -8
  85. package/dist/utils/shell-executor.js.map +1 -1
  86. package/dist/utils/sync-lock-retry.d.ts +9 -0
  87. package/dist/utils/sync-lock-retry.d.ts.map +1 -0
  88. package/dist/utils/sync-lock-retry.js +107 -0
  89. package/dist/utils/sync-lock-retry.js.map +1 -0
  90. package/dist/web-server/model-pricing.d.ts.map +1 -1
  91. package/dist/web-server/model-pricing.js +22 -0
  92. package/dist/web-server/model-pricing.js.map +1 -1
  93. package/dist/web-server/routes/cliproxy-routing-routes.d.ts.map +1 -1
  94. package/dist/web-server/routes/cliproxy-routing-routes.js +28 -0
  95. package/dist/web-server/routes/cliproxy-routing-routes.js.map +1 -1
  96. package/dist/web-server/routes/settings-routes.d.ts.map +1 -1
  97. package/dist/web-server/routes/settings-routes.js +1 -0
  98. package/dist/web-server/routes/settings-routes.js.map +1 -1
  99. package/lib/ccs +1 -1
  100. package/lib/ccs.ps1 +1 -1
  101. package/package.json +2 -2
  102. package/scripts/ci-parity-gate.sh +3 -30
  103. package/scripts/completion/ccs.bash +1 -1
  104. package/scripts/completion/ccs.fish +1 -1
  105. package/scripts/completion/ccs.ps1 +1 -1
  106. package/scripts/completion/ccs.zsh +1 -1
  107. package/scripts/hardening-inventory.js +37 -4
  108. package/scripts/maintainability-metrics.js +2 -8
  109. package/scripts/runtime-source-classifier.js +12 -0
  110. package/dist/ui/assets/cliproxy-BKbuNYOB.js +0 -4
  111. package/dist/ui/assets/index-B80fcKqU.js +0 -56
  112. package/dist/ui/assets/proxy-status-widget-BgrDqD-_.js +0 -1
@@ -1 +0,0 @@
1
- import{j as e}from"./radix-ui-nu4wz29m.js";import{r as x}from"./react-vendor-Bjx91N7w.js";import{a as le,c as f,B as N,e as q,bC as we,aZ as Ce,bG as ke,bH as Re,bI as Ae,bJ as Ge,bK as Te,bL as Pe,bM as We,bN as Ve,bO as De,T as Oe,O as _e,R as Ee,j as Ie,k as Ue,l as $e,m as Le,n as Fe,o as Me,p as qe,q as Be,_ as ze}from"./index-B80fcKqU.js";import{A as He,a as Ke,b as Qe,c as Ye,d as Je,e as Xe,f as Ze,g as et}from"./alert-dialog-dwnTAMrx.js";import{u as he,a as tt,b as st,h as nt}from"./tanstack-bhJxV1h8.js";import{t as se}from"./notifications-B4_o8bcr.js";import{bg as ge,R as M,u as rt,t as at,v as it,A as ot,bh as lt,bi as dt,bj as ct,X as ut,e as xt,bk as gt,bl as mt,U as pt,w as ft,n as ht,x as bt,aG as yt,T as ne,aQ as jt}from"./icons-DSLG1YsC.js";import{T as me}from"./Trans-BTOdiwQc.js";async function vt(){const t=await fetch("/api/cliproxy/sync/status");if(!t.ok){let a="Failed to fetch sync status";try{const s=await t.json();a=s.error||s.message||a}catch{}throw new Error(a)}return t.json()}async function Nt(){const t=new AbortController,a=setTimeout(()=>t.abort(),3e4);try{const s=await fetch("/api/cliproxy/sync",{method:"POST",headers:{"Content-Type":"application/json"},signal:t.signal});if(!s.ok){let r="Sync failed";try{const i=await s.json();r=i.error||i.message||r}catch{}throw new Error(r)}return s.json()}catch(s){throw s instanceof Error&&s.name==="AbortError"?new Error("Sync request timed out after 30 seconds"):s}finally{clearTimeout(a)}}function St(){return he({queryKey:["cliproxy-sync-status"],queryFn:vt,refetchInterval:3e4,retry:1,staleTime:1e4})}function wt(){const t=tt(),{t:a}=le();return st({mutationFn:Nt,onSuccess:s=>{t.invalidateQueries({queryKey:["cliproxy-sync-status"]}),t.invalidateQueries({queryKey:["cliproxy-sync-preview"]}),s.syncedCount===0?se.info(a("toasts.noProfilesToSync")):se.success(`Synced ${s.syncedCount} profile${s.syncedCount===1?"":"s"} to CLIProxy`)},onError:s=>{se.error(a("toasts.syncFailed",{error:s.message}))}})}function pe(t){const a=t.trim().replace(/^v/,""),[s,r="0"]=a.split("-",2),[i=0,u=0,c=0]=s.split(".").map(P=>Number.parseInt(P,10)||0),T=/^\d+$/.test(r)&&Number.parseInt(r,10)||0;return{major:i,minor:u,patch:c,forkRelease:T}}function Q(t,a){return t>a?1:t<a?-1:0}function oe(t,a){const s=pe(t),r=pe(a);return Q(s.major,r.major)||Q(s.minor,r.minor)||Q(s.patch,r.patch)||Q(s.forkRelease,r.forkRelease)}function re(t,a){return oe(t,a)>0}function ae(t,a,s){return oe(t,a)>=0&&oe(t,s)<=0}const ie={"round-robin":{title:"Round Robin",description:"Spread requests across matching accounts for even usage."},"fill-first":{title:"Fill First",description:"Drain one healthy account first and keep backups untouched until needed."}};function fe({className:t,compact:a=!1,state:s,sessionAffinityState:r,isLoading:i,isSaving:u,error:c,onApply:T,onApplyAffinity:P}){const{t:n}=le(),w=s?.strategy??"round-robin",g=s?.poolRouting?.enabled??!1,_=s?.poolRouting?.maxRetryCredentials,W=s?.poolRouting?.manageable??!0,j=!W,E=s?.poolRouting?.message??n("routingGuidance.poolRoutingLocalOnly"),v=r?.enabled??!1,m=r?.ttl??"1h",p=r?.manageable??!0,[h,B]=x.useState(w),[A,V]=x.useState(v),[S,D]=x.useState(m),[b,J]=x.useState(!1),X=s?.source==="live"?"Live CLIProxy":"Saved startup default",I=i||u||!s||h===w,U=b?"Hide details":"Show details",G=i||u||!!c||!p,O=n(p?A?"routingGuidance.disableSessionAffinity":"routingGuidance.enableSessionAffinity":"routingGuidance.sessionAffinityUnavailable"),C=x.useRef(null),$=x.useRef(!1);x.useEffect(()=>{B(w)},[w]),x.useEffect(()=>{V(v),D(m)},[v,m]),x.useEffect(()=>{if(u||!C.current)return;const l=C.current;l.enabled===v&&l.ttl===m||(V(v),D(m)),C.current=null},[u,v,m]);const H=()=>{if(!p)return;const l=!A,d=S.trim()||"1h";C.current={enabled:l,ttl:d},V(l),P({enabled:l,ttl:d})},k=()=>{if(!p||c)return;if($.current){$.current=!1;return}const l=S.trim()||"1h";l!==m&&(C.current={enabled:A,ttl:l},P({enabled:A,ttl:l}))};if(a){const l=d=>{B(d),d!==w&&T(d)};return e.jsxs("div",{className:f("group/routing mt-1 space-y-2 -mx-1 rounded-lg p-1",t),children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg transition-colors hover:bg-primary/5",children:[e.jsxs("div",{className:"flex items-center gap-2 px-1 text-xs font-medium text-foreground",children:[e.jsxs("div",{className:"relative flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-background border border-border/60 text-muted-foreground shadow-sm overflow-hidden transition-all duration-300 group-hover/routing:border-primary/40 group-hover/routing:text-primary group-hover/routing:shadow-[0_0_12px_rgba(59,130,246,0.15)] dark:group-hover/routing:shadow-[0_0_12px_rgba(59,130,246,0.1)]",children:[e.jsx("div",{className:"absolute inset-0 bg-primary/10 translate-y-full group-hover/routing:translate-y-0 transition-transform duration-300 ease-out"}),e.jsx(ge,{className:"relative z-10 h-3.5 w-3.5 transition-transform duration-300 group-hover/routing:scale-110"})]}),e.jsx("span",{className:"tracking-tight transition-colors duration-300 group-hover/routing:text-primary group-hover/routing:font-semibold",children:"Routing"}),u&&e.jsx(M,{className:"ml-1 h-3 w-3 shrink-0 animate-spin text-primary"})]}),e.jsxs("div",{className:"relative grid grid-cols-2 p-0.5 gap-0.5 rounded-lg border border-border/60 bg-muted/30 shadow-[inset_0_1px_2px_rgba(0,0,0,0.05)] dark:shadow-[inset_0_1px_3px_rgba(0,0,0,0.2)] transition-colors duration-300 group-hover/routing:border-primary/20 group-hover/routing:bg-primary/5",children:[e.jsx("div",{className:f("absolute inset-y-0.5 left-0.5 w-[calc(50%-0.1875rem)] rounded bg-background shadow-[0_1px_3px_rgba(0,0,0,0.1),0_1px_2px_rgba(0,0,0,0.06)] ring-1 ring-black/5 dark:ring-white/10 transition-all duration-300",h==="fill-first"?"translate-x-[calc(100%+0.125rem)]":"translate-x-0","group-hover/routing:shadow-[0_0_8px_rgba(59,130,246,0.15)] dark:group-hover/routing:shadow-[0_0_8px_rgba(59,130,246,0.1)] group-hover/routing:ring-primary/30"),style:{transitionTimingFunction:"cubic-bezier(0.175, 0.885, 0.32, 1.275)"}}),Object.entries(ie).map(([d,y])=>{const z=h===d;return e.jsx("button",{type:"button",className:f("relative z-10 flex items-center justify-center rounded px-2.5 py-0.5 text-[10px] font-medium whitespace-nowrap transition-colors duration-200",z?"text-foreground group-hover/routing:text-primary":"text-muted-foreground/70 hover:text-foreground/90 group-hover/routing:text-muted-foreground/90"),onClick:()=>l(d),disabled:i||u||!!c,title:y.description,children:y.title},d)})]})]}),g&&W?e.jsx("div",{role:"status",className:"rounded-lg border border-amber-500/40 bg-amber-500/10 px-2 py-1.5 text-[10px] leading-4 text-amber-700 dark:text-amber-300",children:n("routingGuidance.poolRoutingApplyWarning")}):null,e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-lg border border-border/60 bg-muted/20 px-2 py-1.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:n("routingGuidance.poolRouting")}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:j?E:n(g?"routingGuidance.drainOrderHint":"routingGuidance.poolRoutingOffHint")})]}),e.jsx(N,{variant:j?"outline":g?"secondary":"outline",title:j?E:n(g?"routingGuidance.poolRoutingManaged":"routingGuidance.poolRoutingOffHint"),children:j?n("routingGuidance.localOnly"):g?`${n("routingGuidance.poolRoutingOn")} · ${n("routingGuidance.poolMaxRetry",{count:_??0})}`:n("routingGuidance.poolRoutingOff")})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-lg border border-border/60 bg-muted/20 px-2 py-1.5",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[10px] font-medium text-foreground",children:n("routingGuidance.sessionAffinity")}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:p?n("routingGuidance.ttlBadge",{ttl:m}):n("routingGuidance.localOnlySetting")})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[p?e.jsx("input",{"aria-label":"Session affinity TTL",className:"h-6 w-14 rounded border border-border/70 bg-background px-2 text-[10px] text-foreground",value:S,onChange:d=>D(d.target.value),onBlur:k,disabled:G}):null,e.jsx("button",{type:"button","aria-label":O,className:f("rounded border px-2 py-1 text-[10px] font-medium transition-colors",p?"border-border/70 bg-background text-foreground hover:border-primary/40 hover:text-primary":"border-border/60 bg-muted/40 text-muted-foreground"),onMouseDown:()=>{$.current=!0},onClick:H,disabled:G,title:r?.message,children:n(p?A?"routingGuidance.sessionAffinityOn":"routingGuidance.sessionAffinityOff":"routingGuidance.sessionAffinityUnavailable")})]})]}),r?.message?e.jsx("div",{className:"rounded-lg border border-border/60 bg-muted/20 px-2 py-1.5 text-[10px] text-muted-foreground",children:r.message}):null]})}return e.jsx("section",{className:f("rounded-xl border border-border/70 bg-background",t),children:e.jsxs("div",{className:"grid gap-3 px-4 py-3 xl:grid-cols-[minmax(0,1fr)_auto] xl:items-start",children:[e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"inline-flex h-7 w-7 items-center justify-center rounded-lg bg-muted text-primary",children:e.jsx(ge,{className:"h-4 w-4"})}),e.jsx("div",{className:"text-sm font-medium",children:n("routingGuidance.routingStrategy")}),e.jsx(N,{variant:"secondary",children:w}),s?e.jsx(N,{variant:"outline",children:X}):null,s?e.jsx(N,{variant:"outline",children:s.target}):null,s?e.jsxs(N,{variant:j?"outline":g?"secondary":"outline",title:j?E:n(g?"routingGuidance.poolRoutingManaged":"routingGuidance.poolRoutingOffHint"),children:[n("routingGuidance.poolRouting"),":"," ",n(j?"routingGuidance.localOnly":g?"routingGuidance.poolRoutingOn":"routingGuidance.poolRoutingOff"),!j&&g&&_!==void 0?` · ${n("routingGuidance.poolMaxRetry",{count:_})}`:""]}):null]}),e.jsx("p",{className:"max-w-3xl text-xs leading-5 text-muted-foreground",children:"Proxy-wide account rotation. CCS keeps round-robin as the default until you explicitly change it."}),e.jsx("p",{className:"max-w-3xl text-[11px] leading-5 text-muted-foreground",children:n("routingGuidance.drainOrderHint")})]}),e.jsxs("div",{className:"flex flex-col gap-2 xl:items-end",children:[e.jsx("div",{className:"inline-flex flex-wrap rounded-lg border border-border/70 bg-muted/35 p-1",children:Object.entries(ie).map(([l,d])=>{const y=h===l;return e.jsx("button",{type:"button",className:f("rounded-md px-3 py-1.5 text-sm font-medium transition-colors",y?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),onClick:()=>B(l),disabled:i||u||!!c,children:d.title},l)})}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(q,{type:"button",variant:"ghost",size:"sm",className:"h-8 px-2 text-xs text-muted-foreground",onClick:()=>J(l=>!l),children:[b?e.jsx(rt,{className:"mr-1 h-3.5 w-3.5"}):e.jsx(at,{className:"mr-1 h-3.5 w-3.5"}),U]}),e.jsx(q,{size:"sm",onClick:()=>T(h),disabled:I||!!c,children:u?"Saving...":`Use ${h}`})]}),g&&W?e.jsx("p",{role:"status",className:"max-w-xs text-[11px] leading-4 text-amber-700 dark:text-amber-400 xl:text-right",children:n("routingGuidance.poolRoutingApplyWarning")}):null]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1 text-[11px] text-muted-foreground xl:col-span-2",children:[e.jsx("span",{children:n("routingGuidance.roundRobin")}),e.jsx("span",{className:"hidden text-border sm:inline",children:"•"}),e.jsx("span",{children:n("routingGuidance.fillFirst")})]}),e.jsxs("div",{className:"grid gap-3 rounded-lg border border-border/70 bg-muted/20 px-3 py-3 xl:col-span-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm font-medium",children:n("routingGuidance.sessionAffinity")}),e.jsx(N,{variant:"secondary",children:n(A?"routingGuidance.sessionAffinityOn":"routingGuidance.sessionAffinityOff")}),r?.ttl?e.jsx(N,{variant:"outline",children:n("routingGuidance.ttlBadge",{ttl:m})}):null,p?null:e.jsx(N,{variant:"outline",children:n("routingGuidance.localOnly")})]}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:n("routingGuidance.sessionAffinityDescription")}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{"aria-label":"Session affinity TTL",className:"h-9 w-24 rounded-md border border-border/70 bg-background px-3 text-sm text-foreground",value:S,onChange:l=>D(l.target.value),onBlur:k,disabled:G}),e.jsx(q,{type:"button",variant:"outline",onMouseDown:()=>{$.current=!0},onClick:H,disabled:G,"aria-label":O,children:O})]}),r?.message?e.jsx("div",{className:"rounded-lg border border-border/70 bg-background/70 px-3 py-2 text-xs text-muted-foreground",children:r.message}):null]}),c?e.jsx("div",{className:"rounded-lg border border-destructive/25 bg-destructive/5 px-3 py-2 text-sm xl:col-span-2",children:c.message}):null,!c&&s?.message?e.jsx("div",{className:"rounded-lg border border-border/70 bg-muted/35 px-3 py-2 text-xs text-muted-foreground xl:col-span-2",children:s.message}):null,b?e.jsxs("div",{className:"grid gap-4 border-t border-border/60 pt-3 md:grid-cols-2 xl:col-span-2",children:[Object.entries(ie).map(([l,d])=>{const y=w===l;return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm font-medium",children:d.title}),y?e.jsx(N,{variant:"secondary",children:"Current"}):null]}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:d.description})]},l)}),e.jsxs("div",{className:"space-y-1 md:col-span-2",children:[e.jsx("div",{className:"text-sm font-medium",children:n("routingGuidance.sessionRecognitionTitle")}),e.jsx("p",{className:"text-xs leading-5 text-muted-foreground",children:n("routingGuidance.sessionRecognitionDescription")})]})]}):null]})})}function Ct(t){if(!t)return"";const a=new Date(t).getTime(),r=Date.now()-a,i=Math.floor(r/(1e3*60*60)),u=Math.floor(r%(1e3*60*60)/(1e3*60));return i>0?`${i}h ${u}m`:`${u}m`}function kt(t,a){if(!t)return"";const s=Date.now()-t,r=Math.floor(s/(1e3*60)),i=Math.floor(s/(1e3*60*60));return r<1?a("proxyStatusWidget.justNow"):r<60?a("proxyStatusWidget.minutesAgo",{count:r}):a("proxyStatusWidget.hoursAgo",{count:i})}function Y({icon:t,tooltip:a,onClick:s,disabled:r,isPending:i,className:u,variant:c="ghost"}){return e.jsxs(Me,{children:[e.jsx(qe,{asChild:!0,children:e.jsx(q,{variant:c==="destructive-ghost"?"ghost":c,size:"sm",className:f("h-7 w-7 p-0",c==="destructive-ghost"&&"hover:bg-destructive/10 hover:text-destructive hover:border-destructive/30",u),onClick:s,disabled:r,children:i?e.jsx(M,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(t,{className:"w-3.5 h-3.5"})})}),e.jsx(Be,{side:"bottom",className:"text-xs",children:a})]})}function Ot(){const{t}=le(),{data:a,isLoading:s}=we(),{data:r}=Ce(),{data:i,isLoading:u}=ke(),{data:c,isLoading:T,error:P}=Re(),n=Ae(),{data:w,isLoading:g,error:_}=Ge(),W=Te(),j=n.isPending||W.isPending,E=P instanceof Error?P:null,v=Pe(),m=We(),p=Ve(),h=De(),{data:B}=St(),{mutate:A,isPending:V}=wt(),[S,D]=x.useState(!1),[b,J]=x.useState(""),[X,I]=x.useState(!1),[U,G]=x.useState(null),[O,C]=x.useState(null),{data:$}=he({queryKey:["cliproxy-server-config"],queryFn:()=>ze.cliproxyServer.get(),staleTime:3e4}),H=nt({mutationKey:["update-backend"]})>0,k=$?.remote,l=k?.enabled&&k?.host,d=w??(_ instanceof Error?{source:"unsupported",target:c?.target??(l?"remote":"local"),reachable:!1,manageable:!1,message:_.message}:void 0),y=a?.running??!1,z=v.isPending||m.isPending||p.isPending||h.isPending||H||V,be=r?.hasUpdate??!1,L=r?.isStable===!1,de=r?.currentVersion,K=B?.configured??!1,ye=t(K?"proxyStatusWidget.syncReady":"proxyStatusWidget.noConfig"),Z=L?r?.maxStableVersion||i?.latestStable:r?.latestVersion,ce=i?.maxStableVersion||r?.maxStableVersion||"6.6.80",F=i?.faultyRange,je=F&&`${F.min.replace(/-\d+$/,"")}-${F.max.replace(/-\d+$/,"")}`,ee=(o,R)=>{G(o),C(R),I(!0)},ue=async o=>{if(!o)return;const R=re(o,ce);if(F!==void 0&&ae(o,F.min,F.max)){ee(o,"faulty");return}if(R){ee(o,"experimental");return}try{const xe=await h.mutateAsync({version:o});xe.requiresConfirmation&&ee(o,xe.isFaulty?"faulty":"experimental")}catch{}},ve=()=>{U&&h.mutate({version:U,force:!0}),I(!1),G(null),C(null)},Ne=()=>{I(!1),G(null),C(null)},Se=l?(()=>{const o=k.protocol||"http",R=k.port||(o==="https"?443:80);return o==="https"&&R===443||o==="http"&&R===80?k.host:`${k.host}:${R}`})():null;return l?e.jsxs("div",{className:f("rounded-lg border p-3 transition-colors","border-blue-500/30 bg-blue-500/5"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(it,{className:"w-4 h-4 text-blue-500"}),e.jsx("span",{className:"text-sm font-medium",children:t("proxyStatusWidget.remoteProxy")}),e.jsx(N,{variant:"secondary",className:"text-[10px] h-4 px-1.5 bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400",children:t("proxyStatusWidget.active")})]}),e.jsx(ot,{className:"w-3 h-3 text-blue-600"})]}),e.jsxs("div",{className:"mt-2 text-xs text-muted-foreground",children:[e.jsx("div",{className:"flex items-center gap-1 mb-1",children:e.jsx("span",{className:"font-mono",children:Se})}),e.jsx("p",{className:"text-[10px] text-muted-foreground/70 leading-tight",children:t("proxyStatusWidget.trafficAutoRouted")})]}),e.jsx(fe,{compact:!0,className:"mt-3",state:c,sessionAffinityState:d,isLoading:T||g,isSaving:j,error:E,onApply:o=>n.mutate(o),onApplyAffinity:o=>W.mutate(o)},`remote:${c?.strategy??"round-robin"}:${d?.enabled??"na"}:${d?.ttl??"na"}:${d?.manageable??"na"}`)]}):e.jsx(Oe,{delayDuration:300,children:e.jsxs("div",{className:f("rounded-lg border p-3 transition-colors",y?"border-green-500/30 bg-green-500/5":"border-muted bg-muted/30"),children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:f("w-2 h-2 rounded-full",y?"bg-green-500 animate-pulse":"bg-muted-foreground/30")}),e.jsx("span",{className:"text-sm font-medium",children:r?.backendLabel??"CLIProxy"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[s?e.jsx(M,{className:"w-3 h-3 animate-spin text-muted-foreground"}):y?e.jsxs(e.Fragment,{children:[e.jsx(Y,{icon:V?M:lt,tooltip:t("proxyStatusWidget.tooltipSync"),onClick:()=>A(),disabled:!K||z,isPending:V}),e.jsx(Y,{icon:dt,tooltip:t("proxyStatusWidget.tooltipRestart"),onClick:()=>p.mutate(),disabled:z,isPending:p.isPending}),e.jsx(Y,{icon:ct,tooltip:t("proxyStatusWidget.tooltipStop"),onClick:()=>m.mutate(),disabled:z,isPending:m.isPending,variant:"destructive-ghost"})]}):null,e.jsx(Y,{icon:S?ut:xt,tooltip:t(S?"proxyStatusWidget.tooltipClose":"proxyStatusWidget.tooltipVersionSettings"),onClick:()=>D(!S),className:S?"bg-muted":void 0})]})]}),de&&e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsxs("span",{className:f("text-xs font-mono text-muted-foreground",L&&"text-amber-600 dark:text-amber-400"),children:["v",de]}),(be||L)&&Z&&e.jsxs(N,{variant:"secondary",className:f("text-[10px] h-4 px-1.5 gap-0.5 cursor-pointer transition-colors",L?"bg-amber-100 text-amber-700 hover:bg-amber-200 dark:bg-amber-900/30 dark:text-amber-400 dark:hover:bg-amber-900/50":"bg-green-100 text-green-700 hover:bg-green-200 dark:bg-green-900/30 dark:text-green-400 dark:hover:bg-green-900/50"),onClick:()=>void ue(Z),title:t(L?"proxyStatusWidget.clickToDowngrade":"proxyStatusWidget.clickToUpdate"),children:[L?e.jsx(gt,{className:"w-2.5 h-2.5"}):e.jsx(mt,{className:"w-2.5 h-2.5"}),Z]})]}),y&&a&&e.jsxs("div",{className:"mt-2 flex items-center gap-4 text-xs text-muted-foreground",children:[e.jsx("span",{className:"flex items-center gap-1",children:t("proxyStatusWidget.port",{port:a.port})}),a.sessionCount!==void 0&&a.sessionCount>0&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(pt,{className:"w-3 h-3"}),t("proxyStatusWidget.sessionCount",{count:a.sessionCount})]}),a.startedAt&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(ft,{className:"w-3 h-3"}),Ct(a.startedAt)]})]}),e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-xs",children:[K?e.jsx(ht,{className:"w-3 h-3 text-green-600 dark:text-green-400"}):e.jsx(bt,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:f("text-xs",K?"text-green-600 dark:text-green-400":"text-muted-foreground"),children:ye})]}),e.jsx(fe,{compact:!0,className:"mt-3",state:c,sessionAffinityState:d,isLoading:T||g,isSaving:j,error:E,onApply:o=>n.mutate(o),onApplyAffinity:o=>W.mutate(o)},`local:${c?.strategy??"round-robin"}:${d?.enabled??"na"}:${d?.ttl??"na"}:${d?.manageable??"na"}`),e.jsx(_e,{open:S,onOpenChange:D,children:e.jsxs(Ee,{className:"mt-3 pt-3 border-t border-muted",children:[e.jsx("h4",{className:"text-xs font-medium text-muted-foreground mb-3",children:t("proxyStatusWidget.versionManagement")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Ie,{value:b,onValueChange:J,disabled:u,children:[e.jsx(Ue,{className:"h-8 text-xs flex-1",children:e.jsx($e,{placeholder:t("proxyStatusWidget.selectVersionPlaceholder")})}),e.jsx(Le,{children:i?.versions.slice(0,20).map(o=>{const R=i?.maxStableVersion&&re(o,i.maxStableVersion),te=i?.faultyRange&&ae(o,i.faultyRange.min,i.faultyRange.max);return e.jsx(Fe,{value:o,className:"text-xs",children:e.jsxs("span",{className:"flex items-center gap-2",children:["v",o,o===i.latestStable&&e.jsx("span",{className:"text-green-600 dark:text-green-400",children:t("proxyStatusWidget.stable")}),(te||R)&&e.jsx("span",{className:"text-amber-600 dark:text-amber-400",children:"⚠"})]})},o)})})]}),e.jsxs(q,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1.5 px-3",onClick:()=>void ue(b),disabled:h.isPending||!b,children:[h.isPending?e.jsx(M,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(yt,{className:"w-3.5 h-3.5"}),t("proxyStatusWidget.install")]})]}),b&&i?.maxStableVersion&&re(b,i.maxStableVersion)&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-amber-600 dark:text-amber-400",children:[e.jsx(ne,{className:"w-3.5 h-3.5 flex-shrink-0"}),e.jsx("span",{children:t("proxyStatusWidget.versionsAboveUnstable",{version:i.maxStableVersion})})]}),b&&i?.faultyRange&&ae(b,i.faultyRange.min,i.faultyRange.max)&&e.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-amber-600 dark:text-amber-400",children:[e.jsx(ne,{className:"w-3.5 h-3.5 flex-shrink-0"}),e.jsx("span",{children:t("proxyStatusWidget.versionsKnownIssues",{version:b})})]}),r?.checkedAt&&e.jsx("div",{className:"mt-2 text-[10px] text-muted-foreground/60",children:t("proxyStatusWidget.lastChecked",{time:kt(r.checkedAt,t)})})]})}),!y&&e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t("proxyStatusWidget.notRunning")}),e.jsxs(q,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1",onClick:()=>v.mutate(),disabled:v.isPending,children:[v.isPending?e.jsx(M,{className:"w-3 h-3 animate-spin"}):e.jsx(jt,{className:"w-3 h-3"}),t("proxyStatusWidget.start")]})]}),e.jsx(He,{open:X,onOpenChange:I,children:e.jsxs(Ke,{children:[e.jsxs(Qe,{children:[e.jsxs(Ye,{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"w-5 h-5 text-amber-500"}),t(O==="faulty"?"proxyStatusWidget.installFaultyTitle":"proxyStatusWidget.installUnstableTitle")]}),e.jsxs(Je,{className:"space-y-2",children:[O==="faulty"?e.jsx("p",{children:e.jsx(me,{i18nKey:"proxyStatusWidget.installFaultyDesc",values:{version:U??"",range:je||""},components:{strong:e.jsx("strong",{})}})}):e.jsx("p",{children:e.jsx(me,{i18nKey:"proxyStatusWidget.installUnstableDesc",values:{version:U??"",maxStable:ce},components:{strong:e.jsx("strong",{})}})}),e.jsx("p",{className:"text-amber-600 dark:text-amber-400",children:t(O==="faulty"?"proxyStatusWidget.installFaultyWarning":"proxyStatusWidget.installUnstableWarning")}),e.jsx("p",{children:t("proxyStatusWidget.installUnstableConfirm")})]})]}),e.jsxs(Xe,{children:[e.jsx(Ze,{onClick:Ne,children:t("proxyStatusWidget.cancel")}),e.jsx(et,{onClick:ve,className:"bg-amber-500 hover:bg-amber-600 text-white",children:t("proxyStatusWidget.installAnyway")})]})]})})]})})}export{Ot as P};