cartethyia 2.6.4 → 2.6.5

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 (68) hide show
  1. package/dist/dashboard/assets/{BannedPage-rvAOt5Ad.js → BannedPage-B7OjIxCp.js} +1 -1
  2. package/dist/dashboard/assets/BannedPage-B7OjIxCp.js.gz +0 -0
  3. package/dist/dashboard/assets/{CliToolDetailPage-ZoKZDsob.js → CliToolDetailPage-Bt-6y24w.js} +1 -1
  4. package/dist/dashboard/assets/CliToolDetailPage-Bt-6y24w.js.gz +0 -0
  5. package/dist/dashboard/assets/{CliToolsPage-1_a6Tw8Y.js → CliToolsPage-C6LunsuE.js} +1 -1
  6. package/dist/dashboard/assets/CliToolsPage-C6LunsuE.js.gz +0 -0
  7. package/dist/dashboard/assets/{CombosPage-Czo7GLxL.js → CombosPage-CgyfN2Yy.js} +1 -1
  8. package/dist/dashboard/assets/CombosPage-CgyfN2Yy.js.gz +0 -0
  9. package/dist/dashboard/assets/{ConsoleLogPage-BrlBFGtF.js → ConsoleLogPage-BHWU7y6j.js} +1 -1
  10. package/dist/dashboard/assets/ConsoleLogPage-BHWU7y6j.js.gz +0 -0
  11. package/dist/dashboard/assets/{CustomizationPage-COvQuDTc.js → CustomizationPage-xIjU736m.js} +1 -1
  12. package/dist/dashboard/assets/CustomizationPage-xIjU736m.js.gz +0 -0
  13. package/dist/dashboard/assets/{HealthEventsModal-gTD1Qv_d.js → HealthEventsModal-DeT1zkYG.js} +1 -1
  14. package/dist/dashboard/assets/HealthEventsModal-DeT1zkYG.js.gz +0 -0
  15. package/dist/dashboard/assets/{LoginPage-BlGbMdYo.js → LoginPage-ChVqIAam.js} +1 -1
  16. package/dist/dashboard/assets/LoginPage-ChVqIAam.js.gz +0 -0
  17. package/dist/dashboard/assets/{OverviewPage-BhUFw9Qp.js → OverviewPage-BD4GkRtS.js} +1 -1
  18. package/dist/dashboard/assets/OverviewPage-BD4GkRtS.js.gz +0 -0
  19. package/dist/dashboard/assets/{ProviderDetailPage-CrBfX_gj.js → ProviderDetailPage-BJXwqpKj.js} +1 -1
  20. package/dist/dashboard/assets/ProviderDetailPage-BJXwqpKj.js.gz +0 -0
  21. package/dist/dashboard/assets/{ProvidersPage-CZ7sCKxk.js → ProvidersPage-Ck64riM5.js} +1 -1
  22. package/dist/dashboard/assets/ProvidersPage-Ck64riM5.js.gz +0 -0
  23. package/dist/dashboard/assets/{ProxyPage-PnJWpC9C.js → ProxyPage-Br_Leqq0.js} +1 -1
  24. package/dist/dashboard/assets/ProxyPage-Br_Leqq0.js.gz +0 -0
  25. package/dist/dashboard/assets/{QuotaPage-CrGTXWjQ.js → QuotaPage-D2gyhfa8.js} +1 -1
  26. package/dist/dashboard/assets/QuotaPage-D2gyhfa8.js.gz +0 -0
  27. package/dist/dashboard/assets/{SettingsPage-DXjUbFh_.js → SettingsPage-1dbYb8cM.js} +1 -1
  28. package/dist/dashboard/assets/SettingsPage-1dbYb8cM.js.gz +0 -0
  29. package/dist/dashboard/assets/{SetupPage-DCFo3R5_.js → SetupPage-DUTFy9wH.js} +1 -1
  30. package/dist/dashboard/assets/SetupPage-DUTFy9wH.js.gz +0 -0
  31. package/dist/dashboard/assets/{SortableList-lFdVPMo_.js → SortableList-BZEhfDpZ.js} +1 -1
  32. package/dist/dashboard/assets/SortableList-BZEhfDpZ.js.gz +0 -0
  33. package/dist/dashboard/assets/{StudioPage-DPbSWHny.js → StudioPage-GBDtsJjh.js} +1 -1
  34. package/dist/dashboard/assets/StudioPage-GBDtsJjh.js.gz +0 -0
  35. package/dist/dashboard/assets/{UsagePage-B-CTPrqB.js → UsagePage-CxidMvxq.js} +1 -1
  36. package/dist/dashboard/assets/UsagePage-CxidMvxq.js.gz +0 -0
  37. package/dist/dashboard/assets/{entry-BcfdW4C_.js → entry-BrksMru8.js} +3 -3
  38. package/dist/dashboard/assets/entry-BrksMru8.js.gz +0 -0
  39. package/dist/dashboard/assets/{index-_rbyCXD2.js → index-DU61iviS.js} +2 -2
  40. package/dist/dashboard/assets/index-DU61iviS.js.gz +0 -0
  41. package/dist/dashboard/assets/{select-BTEzH1iH.js → select-Ciq_KFQ1.js} +1 -1
  42. package/dist/dashboard/assets/select-Ciq_KFQ1.js.gz +0 -0
  43. package/dist/dashboard/index.html +1 -1
  44. package/dist/dashboard/index.html.gz +0 -0
  45. package/dist/dashboard/precompressed-assets.json +21 -21
  46. package/package.json +1 -1
  47. package/src/main.ts +6 -0
  48. package/dist/dashboard/assets/BannedPage-rvAOt5Ad.js.gz +0 -0
  49. package/dist/dashboard/assets/CliToolDetailPage-ZoKZDsob.js.gz +0 -0
  50. package/dist/dashboard/assets/CliToolsPage-1_a6Tw8Y.js.gz +0 -0
  51. package/dist/dashboard/assets/CombosPage-Czo7GLxL.js.gz +0 -0
  52. package/dist/dashboard/assets/ConsoleLogPage-BrlBFGtF.js.gz +0 -0
  53. package/dist/dashboard/assets/CustomizationPage-COvQuDTc.js.gz +0 -0
  54. package/dist/dashboard/assets/HealthEventsModal-gTD1Qv_d.js.gz +0 -0
  55. package/dist/dashboard/assets/LoginPage-BlGbMdYo.js.gz +0 -0
  56. package/dist/dashboard/assets/OverviewPage-BhUFw9Qp.js.gz +0 -0
  57. package/dist/dashboard/assets/ProviderDetailPage-CrBfX_gj.js.gz +0 -0
  58. package/dist/dashboard/assets/ProvidersPage-CZ7sCKxk.js.gz +0 -0
  59. package/dist/dashboard/assets/ProxyPage-PnJWpC9C.js.gz +0 -0
  60. package/dist/dashboard/assets/QuotaPage-CrGTXWjQ.js.gz +0 -0
  61. package/dist/dashboard/assets/SettingsPage-DXjUbFh_.js.gz +0 -0
  62. package/dist/dashboard/assets/SetupPage-DCFo3R5_.js.gz +0 -0
  63. package/dist/dashboard/assets/SortableList-lFdVPMo_.js.gz +0 -0
  64. package/dist/dashboard/assets/StudioPage-DPbSWHny.js.gz +0 -0
  65. package/dist/dashboard/assets/UsagePage-B-CTPrqB.js.gz +0 -0
  66. package/dist/dashboard/assets/entry-BcfdW4C_.js.gz +0 -0
  67. package/dist/dashboard/assets/index-_rbyCXD2.js.gz +0 -0
  68. package/dist/dashboard/assets/select-BTEzH1iH.js.gz +0 -0
@@ -1,4 +1,4 @@
1
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{T as a,c as o,s,t as c,v as l,w as u,x as d}from"./numbers-Dulqgys5.js";import{t as f}from"./eye-off-Bk5g2luF.js";import{t as p}from"./eye-C_hawfH4.js";import{t as m}from"./gauge-BbIMy7MB.js";import{n as h,r as g,t as _}from"./state-DhZBfWgx.js";import{t as v}from"./dialog-Iec_ywbD.js";import{t as y}from"./pencil-768ysRAr.js";import{t as ee}from"./plus-DIdX_g-x.js";import{t as b}from"./power-off-Yjw9GMJh.js";import{t as x}from"./rotate-ccw-CufcqITi.js";import{t as S}from"./shield-check-DVS0Foqh.js";import{t as C}from"./trash-Cppn5c3R.js";import{C as w,T,c as E,v as D,y as O}from"./assert-DU6qrMA_.js";import{a as k,i as A,l as j,o as M,t as N}from"./query-keys-UETqfytp.js";import{t as P}from"./useMutation-EDFRkn1i.js";import{it as te,z as ne}from"./entry-BcfdW4C_.js";import{n as re,r as ie,t as ae}from"./card-BOPBuBzD.js";import{n as oe}from"./download-dRFo5_Wu.js";import{t as F}from"./badge-Bkz_-RrM.js";import{n as I}from"./input-WlyHWeG2.js";import{t as se}from"./select-BTEzH1iH.js";import{t as L}from"./switch-yD7D99Lg.js";import{t as ce}from"./stack-B1w5BM0u.js";import{n as le}from"./inline-DToMICwl.js";import{r as R,t as ue}from"./layout-DaJ5baJr.js";import{i as de,n as fe}from"./privacy-mode-GM8bej85.js";import{n as z}from"./live-ta6GMb-8.js";var pe=e(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),me=e(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),he=1e6,B=1e8,ge=5e6,_e=`sin1`,ve=[{label:`Asia Pacific`,regions:[{id:`sin1`,label:`Singapore`},{id:`hkg1`,label:`Hong Kong`},{id:`icn1`,label:`Seoul`},{id:`hnd1`,label:`Tokyo`},{id:`kix1`,label:`Osaka`},{id:`bom1`,label:`Mumbai`},{id:`syd1`,label:`Sydney`}]},{label:`Europe`,regions:[{id:`fra1`,label:`Frankfurt`},{id:`cdg1`,label:`Paris`},{id:`lhr1`,label:`London`},{id:`arn1`,label:`Stockholm`},{id:`dub1`,label:`Dublin`}]},{label:`North America`,regions:[{id:`iad1`,label:`Washington, D.C.`},{id:`sfo1`,label:`San Francisco`},{id:`pdx1`,label:`Portland`},{id:`cle1`,label:`Cleveland`},{id:`yul1`,label:`Montréal`}]},{label:`Other`,regions:[{id:`gru1`,label:`São Paulo`},{id:`cpt1`,label:`Cape Town`},{id:`dxb1`,label:`Dubai`}]}];function ye(){return w({queryKey:N.network.pools,queryFn:e=>M(`/network/pools`,{signal:D(e)}).then(E),staleTime:A.staleTime,gcTime:A.gcTime})}function be(){let e=T();return P({mutationFn:e=>M(`/network/pools`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Proxy pool created`)},onError:e=>{s.error(`Could not create the proxy pool.`,j(e))}})}function xe(){let e=T();return P({mutationFn:e=>M(`/network/pools/relay/deploy`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Se(){return P({mutationFn:e=>M(`/network/pools/test-batch`,{method:`POST`,body:JSON.stringify({targets:e})})})}function Ce(){let e=T();return P({mutationFn:({poolId:e,request:t})=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify(t)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Proxy updated`)},onError:e=>{s.error(`Could not update the proxy pool.`,j(e))}})}function we(e){return w({queryKey:[...N.network.pools,e,`health-events`],queryFn:t=>M(`/network/pools/${encodeURIComponent(e??``)}/health-events`,{signal:D(t)}),enabled:!!e,...A,refetchInterval:k.status})}function Te(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/recover`,{method:`POST`,body:`{}`}),onSuccess:async(t,n)=>{await Promise.all([e.invalidateQueries({queryKey:N.network.pools}),e.invalidateQueries({queryKey:[...N.network.pools,n,`health-events`]})]),s.success(`Proxy pool recovered`)},onError:e=>{s.error(`Could not recover the proxy pool.`,j(e))}})}function Ee(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`DELETE`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Proxy pool deleted`)},onError:e=>{s.error(`Could not delete the proxy pool.`,j(e))}})}function De(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/provider-probe`,{method:`POST`,body:JSON.stringify({providerId:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Oe(){return P({mutationFn:({providerId:e,targets:t})=>M(`/network/pools/test-batch/provider`,{method:`POST`,body:JSON.stringify({providerId:e,targets:t})})})}function ke(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/health-check`,{method:`POST`,body:`{}`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Health check complete`)},onError:e=>{s.error(`Health check failed.`,j(e))}})}function Ae(){let e=T();return P({mutationFn:({poolId:e,bytes:t})=>M(`/network/pools/${encodeURIComponent(e)}/speed-test`,{method:`POST`,body:JSON.stringify({bytes:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function je(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/cooldowns/clear`,{method:`POST`,body:JSON.stringify(t?{providerId:t}:{})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Provider cooldowns cleared`)},onError:e=>{s.error(`Could not clear provider cooldowns.`,j(e))}})}var V=t(n(),1),H=r(),U={cloudflare:{label:`Cloudflare Workers`,tokenLabel:`Cloudflare API token`,needsAccount:!0,host:`*.workers.dev`,hasRegion:!1},vercel:{label:`Vercel`,tokenLabel:`Vercel API token`,needsAccount:!1,host:`*.vercel.app`,hasRegion:!0},deno:{label:`Deno Deploy`,tokenLabel:`Deno Deploy token`,needsAccount:!1,host:`*.deno.dev`,hasRegion:!1}},Me=ve.flatMap(e=>e.regions.map(t=>({value:t.id,label:`${e.label} — ${t.label}`})));function Ne({onClose:e}){let t=xe(),[n,r]=(0,V.useState)(`cloudflare`),[i,a]=(0,V.useState)(_e),[c,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(``),[p,m]=(0,V.useState)(``),[h,g]=(0,V.useState)(null),_=U[n],y=c.trim().length>0&&(!_.needsAccount||d.trim().length>0);return(0,H.jsx)(v,{open:!0,onClose:e,title:`Deploy Relay`,description:`Run outbound traffic through a hosted relay (Cloudflare, Vercel, Deno).`,size:`md`,children:(0,H.jsxs)(ce,{gap:`12px`,children:[(0,H.jsxs)(`p`,{className:`text-badge text-text-tertiary m-0 flex gap-3`,children:[(0,H.jsx)(te,{size:13,className:`shrink-0 mt-0.5`}),(0,H.jsxs)(`span`,{children:[`Deploys a small relay worker to your own `,_.label,` account and registers its URL (`,(0,H.jsx)(`code`,{children:_.host}),`) as an active HTTP pool. Your API token is used only for the deploy and is never stored.`]})]}),(0,H.jsx)(se,{label:`Relay host`,id:`relay-target`,value:n,onValueChange:e=>r(e),options:O.map(e=>({value:e,label:U[e].label}))}),(0,H.jsx)(I,{label:_.tokenLabel,id:`relay-token`,type:`password`,value:c,placeholder:`Paste a deploy token`,onChange:e=>u(e.target.value)}),_.needsAccount?(0,H.jsx)(I,{label:`Account ID`,id:`relay-account`,value:d,placeholder:`Cloudflare account id`,onChange:e=>f(e.target.value)}):null,(0,H.jsx)(I,{label:`Project name (optional)`,id:`relay-project`,value:p,placeholder:`e.g. cartethyia-relay`,onChange:e=>m(e.target.value)}),_.hasRegion?(0,H.jsx)(se,{label:`Deploy region`,id:`relay-region`,value:i,onValueChange:e=>a(e),options:Me}):null,_.hasRegion?(0,H.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Sets the region on the Vercel project, which is what decides the country outbound traffic leaves from. A region sent on the deployment alone is accepted but does not move the Function.`}):null,(0,H.jsxs)(`div`,{className:`flex items-center gap-5`,children:[(0,H.jsx)(o,{variant:`primary`,size:`sm`,onClick:()=>{y&&t.mutate({target:n,token:c.trim(),..._.needsAccount&&d.trim()?{accountId:d.trim()}:{},...p.trim()?{projectName:p.trim()}:{},..._.hasRegion?{region:i}:{}},{onSuccess:e=>{g(e.relayUrl),u(``),s.success(`Relay deployed to ${e.relayUrl} and registered as a pool.`)},onError:e=>s.error(j(e,`Relay deploy failed.`))})},disabled:!y||t.isPending,children:t.isPending?`Deploying…`:`Deploy relay`}),h?(0,H.jsxs)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Registered pool at `,(0,H.jsx)(`code`,{children:h})]}):null]}),t.isError?(0,H.jsxs)(`p`,{className:`text-badge text-red m-0 flex gap-3`,children:[(0,H.jsx)(l,{size:13,className:`shrink-0 mt-0.5`}),(0,H.jsx)(`span`,{children:j(t.error,`Relay deploy failed.`)})]}):null]})})}function Pe(e,t){if(e!==void 0)return e.endpoint===``||e.endpoint===(t??``)?e.result:void 0}function Fe(e,t,n){switch(t){case`name`:return(e.label||e.endpoint).toLowerCase();case`family`:return e.family===void 0||e.family===null||e.family===``?null:e.family.toLowerCase();case`address`:return e.egressIp??null;case`load`:return n??null}}function Ie(e,t,n,r){let i=n===`asc`?1:-1;return[...e].sort((e,n)=>{let a=Fe(e,t,r(e)),o=Fe(n,t,r(n));return a===null&&o===null?0:a===null?1:o===null?-1:typeof a==`number`&&typeof o==`number`?(a-o)*i:String(a).localeCompare(String(o))*i})}function W(e,t){let n=e.filter(e=>e.status===`active`),r=n.reduce((e,t)=>e+t.maxInflight,0),i=t===void 0?n.reduce((e,t)=>e+(t.inflight??0),0):n.reduce((e,n)=>e+(t.get(n.id)??0),0),a=0,o=0;for(let e of n)(t===void 0?e.inflight??0:t.get(e.id)??0)>=e.maxInflight?o+=1:a+=1;let s=null,c=Date.now(),l=e=>{if(!e)return;let t=Date.parse(e);if(Number.isNaN(t))return;let n=t-c;n<=0||(s===null||n<s)&&(s=n)};for(let t of e){l(t.cooldownUntil);for(let e of t.providerCooldowns??[])l(e.until)}let u=n.filter(e=>e.lastLatencyMs!==void 0&&Number.isFinite(e.lastLatencyMs)),d=u.length===0?null:Math.round(u.reduce((e,t)=>e+(t.lastLatencyMs??0),0)/u.length);return{totalPools:e.length,active:n.length,cooldown:e.filter(e=>e.status===`cooldown`).length,totalMaxConcurrency:r,usedInflight:i,availableCapacity:Math.max(0,r-i),routablePools:a,saturatedPools:o,soonestCooldownMs:s,avgLatencyMs:d,measuredPools:u.length}}var G=[`http`,`https`,`socks5`];function K(e){return/^[a-z][a-z0-9+.-]*:\/\//i.test(e.trim())}function Le(e,t){let n=e.trim();return t===null||K(n)?n:`${t}://${n}`}function q(e){return e.find(e=>e.trim()!==``)}function J(e){let t=e.trim().toLowerCase();return t.startsWith(`https://`)?`https`:t.startsWith(`socks5://`)||t.startsWith(`socks://`)?`socks5`:`http`}var Re=1024**3;function ze(e){let t=e.trim();if(t===``)return null;let n=Number(t);return!Number.isFinite(n)||n<=0?null:Math.max(1,Math.round(n*Re))}function Y(e,t,n){let r=new Map;if(t.trim().toLowerCase()===``||n<=0)return r;let i=Math.floor(e/n),a=e-i*n;for(let e=0;e<n;e+=1){let t=e===n-1?a:0;r.set(e,i+t)}return r}var Be=4,Ve=`cartethyia_proxy_test_payload`,He=`cartethyia_proxy_check_results`,Ue=[{value:`url`,label:`Test URL`},{value:`opencode`,label:`Test OpenCode`}],We=`opencode`,Ge=4,Ke=`Mysterious Proxy`;function X(e){return e.avgLatencyMs===null?`no measurement yet`:`avg across ${e.measuredPools} enabled ${e.measuredPools===1?`pool`:`pools`}`}function qe(e){let t=e.endpoint||``,n=t.includes(`://`)?t:`${e.kind}://${t}`,r={"https:":`443`,"http:":`80`,"socks5:":`1080`,"socks:":`1080`};try{let e=new URL(n),t=e.port||r[e.protocol]||``,i=`${e.hostname}${t?`:${t}`:``}`;return{name:i,endpoint:`${e.protocol}//${i}${e.pathname===`/`?``:e.pathname}${e.search}`}}catch{return{name:e.label||t,endpoint:t}}}function Z(e){return e.label||qe(e).name||e.id}var Q=1024**3;function Je(e){if(e.lastSpeedtestStatus===void 0||e.lastSpeedtestAt===void 0)return;let t=e.lastSpeedtestDurationMs??0,n=e.lastSpeedtestBytes??0,r=t>0?n/(t/1e3):void 0;return{poolId:e.id,status:e.lastSpeedtestStatus,bytes:n,durationMs:t,...r===void 0?{}:{bytesPerSecond:r,megabitsPerSecond:r*8/1e6},...e.lastSpeedtestError?{errorMessage:e.lastSpeedtestError}:{},measuredAt:e.lastSpeedtestAt}}function Ye(e,t){if(!e)return t;if(!t)return e;let n=e.measuredAt?new Date(e.measuredAt).getTime():0;return(t.measuredAt?new Date(t.measuredAt).getTime():0)>=n?t:e}var Xe=[{value:String(he),label:`1 MB`},{value:String(ge),label:`5 MB`},{value:`50000000`,label:`50 MB`},{value:String(B),label:`100 MB`}];function Ze({pool:e,onClose:t,actionsRef:n}){let r=Ce(),i=Oe(),a=ke(),[l,f]=(0,V.useState)(e.label??``),[p,m]=(0,V.useState)(e.family??``),[h,g]=(0,V.useState)(e.endpoint??``),[_,v]=(0,V.useState)(String(e.maxInflight??10)),[y,ee]=(0,V.useState)(String(e.weight??100)),[b,x]=(0,V.useState)(e.quotaBytes?String(Math.round(e.quotaBytes/Q*1e3)/1e3):``),[S,C]=(0,V.useState)(null),[w,T]=(0,V.useState)(!1),E=h.trim()===e.endpoint,D=async()=>{T(!0),C(null);try{if(E){let t=await a.mutateAsync(e.id),n=t.status===`healthy`||t.status===`reachable`;C({ok:n,message:t.status===`healthy`?`Connected in ${t.latencyMs??0}ms`:t.errorMessage??`Connection failed`});return}let t=[{kind:e.kind,endpoint:h.trim(),...e.family===null||e.family===void 0?{}:{family:e.family}}],[n]=await i.mutateAsync({providerId:We,targets:t}),r=n?.result;if(!r){C({ok:!1,message:`Probe returned no result`});return}let o=r.status===`allowed`||r.status===`throttled`;C({ok:o,message:r.reason??(r.status===`allowed`?`Reachable${r.latencyMs===void 0?``:` in ${r.latencyMs}ms`}`:r.status===`throttled`?`Reachable; rate limit spent`:`Probe could not complete`)})}catch(e){C({ok:!1,message:j(e,`Connection failed`)})}finally{T(!1)}},O=ze(b),k=async()=>{await r.mutateAsync({poolId:e.id,request:{...l.trim()===e.label?{}:{label:l.trim()||void 0},...p.trim()===(e.family??``)?{}:{family:p.trim()||null},...h.trim()!==e.endpoint&&h.trim()!==``?{endpoint:h.trim()}:{},...Number(_)===e.maxInflight?{}:{maxInflight:Number(_)},...Number(y)===e.weight?{}:{weight:Number(y)},...O===(e.quotaBytes??null)?{}:{quotaBytes:O}}}),s.success(`Proxy updated`),t()};return(0,V.useEffect)(()=>{n?.((0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(o,{variant:`secondary`,size:`sm`,onClick:t,children:`Cancel`}),(0,H.jsx)(o,{variant:`primary`,size:`sm`,disabled:r.isPending||!h.trim(),onClick:()=>void k(),children:`Save`})]}))}),(0,H.jsxs)(ce,{gap:`12px`,children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Name`,value:l,onChange:e=>f(e.target.value)})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Family`,value:p,placeholder:`e.g. residential-id`,onChange:e=>m(e.target.value)})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Endpoint`,value:h,onChange:e=>g(e.target.value),className:`font-mono tabular-nums`})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-5`,children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Max concurrent`,type:`number`,min:1,value:_,onChange:e=>v(e.target.value)})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Weight`,type:`number`,min:1,value:y,onChange:e=>ee(e.target.value)})})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(I,{label:`Bandwidth quota (GB, blank = unmetered)`,type:`number`,min:.001,step:`0.1`,value:b,onChange:e=>x(e.target.value)}),(0,H.jsx)(`div`,{className:`text-micro text-text-tertiary mt-2`,children:O===null?`No quota — the bar shows a running total only.`:`Bar turns orange at 80% and red once ${c(O)} is exceeded.`})]}),S&&(0,H.jsx)(`div`,{className:`rounded-inset px-6 py-4 text-badge font-semibold ${S.ok?`bg-green-soft text-green`:`bg-red-soft text-red`}`,children:S.message}),(0,H.jsx)(`div`,{children:(0,H.jsx)(o,{variant:`secondary`,size:`sm`,disabled:w,icon:w?(0,H.jsx)(d,{size:13,className:`animate-spin`}):(0,H.jsx)(u,{size:13}),onClick:()=>void D(),children:w?`Testing…`:`Test connection`})})]})}function Qe({endpoint:e,chip:t,onChipChange:n}){return(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,role:`group`,"aria-label":`Scheme for the first endpoint`,children:[(0,H.jsx)(`span`,{className:`text-badge text-text-secondary`,children:`Scheme`}),G.map(r=>{let i=t===r;return(0,H.jsxs)(o,{type:`button`,variant:i?`primary`:`secondary`,size:`sm`,disabled:e===void 0,"aria-pressed":i,"data-scheme":r,onClick:()=>n(i?null:r),className:`font-mono`,children:[r,`://`]},r)}),t!==null&&(0,H.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[`→ `,Le(e??``,t)]})]})}function $e({onClose:e,actionsRef:t,onProbeResult:n,onHealthResult:r}){let i=be(),a=Se(),c=Oe(),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(``),[p,m]=(0,V.useState)(``),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)([]),[y,ee]=(0,V.useState)({}),[b,x]=(0,V.useState)({}),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(null),E=l.split(`
1
+ import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{T as a,c as o,s,t as c,v as l,w as u,x as d}from"./numbers-Dulqgys5.js";import{t as f}from"./eye-off-Bk5g2luF.js";import{t as p}from"./eye-C_hawfH4.js";import{t as m}from"./gauge-BbIMy7MB.js";import{n as h,r as g,t as _}from"./state-DhZBfWgx.js";import{t as v}from"./dialog-Iec_ywbD.js";import{t as y}from"./pencil-768ysRAr.js";import{t as ee}from"./plus-DIdX_g-x.js";import{t as b}from"./power-off-Yjw9GMJh.js";import{t as x}from"./rotate-ccw-CufcqITi.js";import{t as S}from"./shield-check-DVS0Foqh.js";import{t as C}from"./trash-Cppn5c3R.js";import{C as w,T,c as E,v as D,y as O}from"./assert-DU6qrMA_.js";import{a as k,i as A,l as j,o as M,t as N}from"./query-keys-UETqfytp.js";import{t as P}from"./useMutation-EDFRkn1i.js";import{it as te,z as ne}from"./entry-BrksMru8.js";import{n as re,r as ie,t as ae}from"./card-BOPBuBzD.js";import{n as oe}from"./download-dRFo5_Wu.js";import{t as F}from"./badge-Bkz_-RrM.js";import{n as I}from"./input-WlyHWeG2.js";import{t as se}from"./select-Ciq_KFQ1.js";import{t as L}from"./switch-yD7D99Lg.js";import{t as ce}from"./stack-B1w5BM0u.js";import{n as le}from"./inline-DToMICwl.js";import{r as R,t as ue}from"./layout-DaJ5baJr.js";import{i as de,n as fe}from"./privacy-mode-GM8bej85.js";import{n as z}from"./live-ta6GMb-8.js";var pe=e(`cloud`,[[`path`,{d:`M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9Z`,key:`p7xjir`}]]),me=e(`power`,[[`path`,{d:`M12 2v10`,key:`mnfbl`}],[`path`,{d:`M18.4 6.6a9 9 0 1 1-12.77.04`,key:`obofu9`}]]),he=1e6,B=1e8,ge=5e6,_e=`sin1`,ve=[{label:`Asia Pacific`,regions:[{id:`sin1`,label:`Singapore`},{id:`hkg1`,label:`Hong Kong`},{id:`icn1`,label:`Seoul`},{id:`hnd1`,label:`Tokyo`},{id:`kix1`,label:`Osaka`},{id:`bom1`,label:`Mumbai`},{id:`syd1`,label:`Sydney`}]},{label:`Europe`,regions:[{id:`fra1`,label:`Frankfurt`},{id:`cdg1`,label:`Paris`},{id:`lhr1`,label:`London`},{id:`arn1`,label:`Stockholm`},{id:`dub1`,label:`Dublin`}]},{label:`North America`,regions:[{id:`iad1`,label:`Washington, D.C.`},{id:`sfo1`,label:`San Francisco`},{id:`pdx1`,label:`Portland`},{id:`cle1`,label:`Cleveland`},{id:`yul1`,label:`Montréal`}]},{label:`Other`,regions:[{id:`gru1`,label:`São Paulo`},{id:`cpt1`,label:`Cape Town`},{id:`dxb1`,label:`Dubai`}]}];function ye(){return w({queryKey:N.network.pools,queryFn:e=>M(`/network/pools`,{signal:D(e)}).then(E),staleTime:A.staleTime,gcTime:A.gcTime})}function be(){let e=T();return P({mutationFn:e=>M(`/network/pools`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Proxy pool created`)},onError:e=>{s.error(`Could not create the proxy pool.`,j(e))}})}function xe(){let e=T();return P({mutationFn:e=>M(`/network/pools/relay/deploy`,{method:`POST`,body:JSON.stringify(e)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Se(){return P({mutationFn:e=>M(`/network/pools/test-batch`,{method:`POST`,body:JSON.stringify({targets:e})})})}function Ce(){let e=T();return P({mutationFn:({poolId:e,request:t})=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`PATCH`,body:JSON.stringify(t)}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Proxy updated`)},onError:e=>{s.error(`Could not update the proxy pool.`,j(e))}})}function we(e){return w({queryKey:[...N.network.pools,e,`health-events`],queryFn:t=>M(`/network/pools/${encodeURIComponent(e??``)}/health-events`,{signal:D(t)}),enabled:!!e,...A,refetchInterval:k.status})}function Te(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/recover`,{method:`POST`,body:`{}`}),onSuccess:async(t,n)=>{await Promise.all([e.invalidateQueries({queryKey:N.network.pools}),e.invalidateQueries({queryKey:[...N.network.pools,n,`health-events`]})]),s.success(`Proxy pool recovered`)},onError:e=>{s.error(`Could not recover the proxy pool.`,j(e))}})}function Ee(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}`,{method:`DELETE`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Proxy pool deleted`)},onError:e=>{s.error(`Could not delete the proxy pool.`,j(e))}})}function De(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/provider-probe`,{method:`POST`,body:JSON.stringify({providerId:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function Oe(){return P({mutationFn:({providerId:e,targets:t})=>M(`/network/pools/test-batch/provider`,{method:`POST`,body:JSON.stringify({providerId:e,targets:t})})})}function ke(){let e=T();return P({mutationFn:e=>M(`/network/pools/${encodeURIComponent(e)}/health-check`,{method:`POST`,body:`{}`}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Health check complete`)},onError:e=>{s.error(`Health check failed.`,j(e))}})}function Ae(){let e=T();return P({mutationFn:({poolId:e,bytes:t})=>M(`/network/pools/${encodeURIComponent(e)}/speed-test`,{method:`POST`,body:JSON.stringify({bytes:t})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools})}})}function je(){let e=T();return P({mutationFn:({poolId:e,providerId:t})=>M(`/network/pools/${encodeURIComponent(e)}/cooldowns/clear`,{method:`POST`,body:JSON.stringify(t?{providerId:t}:{})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:N.network.pools}),s.success(`Provider cooldowns cleared`)},onError:e=>{s.error(`Could not clear provider cooldowns.`,j(e))}})}var V=t(n(),1),H=r(),U={cloudflare:{label:`Cloudflare Workers`,tokenLabel:`Cloudflare API token`,needsAccount:!0,host:`*.workers.dev`,hasRegion:!1},vercel:{label:`Vercel`,tokenLabel:`Vercel API token`,needsAccount:!1,host:`*.vercel.app`,hasRegion:!0},deno:{label:`Deno Deploy`,tokenLabel:`Deno Deploy token`,needsAccount:!1,host:`*.deno.dev`,hasRegion:!1}},Me=ve.flatMap(e=>e.regions.map(t=>({value:t.id,label:`${e.label} — ${t.label}`})));function Ne({onClose:e}){let t=xe(),[n,r]=(0,V.useState)(`cloudflare`),[i,a]=(0,V.useState)(_e),[c,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(``),[p,m]=(0,V.useState)(``),[h,g]=(0,V.useState)(null),_=U[n],y=c.trim().length>0&&(!_.needsAccount||d.trim().length>0);return(0,H.jsx)(v,{open:!0,onClose:e,title:`Deploy Relay`,description:`Run outbound traffic through a hosted relay (Cloudflare, Vercel, Deno).`,size:`md`,children:(0,H.jsxs)(ce,{gap:`12px`,children:[(0,H.jsxs)(`p`,{className:`text-badge text-text-tertiary m-0 flex gap-3`,children:[(0,H.jsx)(te,{size:13,className:`shrink-0 mt-0.5`}),(0,H.jsxs)(`span`,{children:[`Deploys a small relay worker to your own `,_.label,` account and registers its URL (`,(0,H.jsx)(`code`,{children:_.host}),`) as an active HTTP pool. Your API token is used only for the deploy and is never stored.`]})]}),(0,H.jsx)(se,{label:`Relay host`,id:`relay-target`,value:n,onValueChange:e=>r(e),options:O.map(e=>({value:e,label:U[e].label}))}),(0,H.jsx)(I,{label:_.tokenLabel,id:`relay-token`,type:`password`,value:c,placeholder:`Paste a deploy token`,onChange:e=>u(e.target.value)}),_.needsAccount?(0,H.jsx)(I,{label:`Account ID`,id:`relay-account`,value:d,placeholder:`Cloudflare account id`,onChange:e=>f(e.target.value)}):null,(0,H.jsx)(I,{label:`Project name (optional)`,id:`relay-project`,value:p,placeholder:`e.g. cartethyia-relay`,onChange:e=>m(e.target.value)}),_.hasRegion?(0,H.jsx)(se,{label:`Deploy region`,id:`relay-region`,value:i,onValueChange:e=>a(e),options:Me}):null,_.hasRegion?(0,H.jsx)(`p`,{className:`text-badge text-text-tertiary m-0`,children:`Sets the region on the Vercel project, which is what decides the country outbound traffic leaves from. A region sent on the deployment alone is accepted but does not move the Function.`}):null,(0,H.jsxs)(`div`,{className:`flex items-center gap-5`,children:[(0,H.jsx)(o,{variant:`primary`,size:`sm`,onClick:()=>{y&&t.mutate({target:n,token:c.trim(),..._.needsAccount&&d.trim()?{accountId:d.trim()}:{},...p.trim()?{projectName:p.trim()}:{},..._.hasRegion?{region:i}:{}},{onSuccess:e=>{g(e.relayUrl),u(``),s.success(`Relay deployed to ${e.relayUrl} and registered as a pool.`)},onError:e=>s.error(j(e,`Relay deploy failed.`))})},disabled:!y||t.isPending,children:t.isPending?`Deploying…`:`Deploy relay`}),h?(0,H.jsxs)(`span`,{className:`mt-1 text-badge text-text-tertiary`,children:[`Registered pool at `,(0,H.jsx)(`code`,{children:h})]}):null]}),t.isError?(0,H.jsxs)(`p`,{className:`text-badge text-red m-0 flex gap-3`,children:[(0,H.jsx)(l,{size:13,className:`shrink-0 mt-0.5`}),(0,H.jsx)(`span`,{children:j(t.error,`Relay deploy failed.`)})]}):null]})})}function Pe(e,t){if(e!==void 0)return e.endpoint===``||e.endpoint===(t??``)?e.result:void 0}function Fe(e,t,n){switch(t){case`name`:return(e.label||e.endpoint).toLowerCase();case`family`:return e.family===void 0||e.family===null||e.family===``?null:e.family.toLowerCase();case`address`:return e.egressIp??null;case`load`:return n??null}}function Ie(e,t,n,r){let i=n===`asc`?1:-1;return[...e].sort((e,n)=>{let a=Fe(e,t,r(e)),o=Fe(n,t,r(n));return a===null&&o===null?0:a===null?1:o===null?-1:typeof a==`number`&&typeof o==`number`?(a-o)*i:String(a).localeCompare(String(o))*i})}function W(e,t){let n=e.filter(e=>e.status===`active`),r=n.reduce((e,t)=>e+t.maxInflight,0),i=t===void 0?n.reduce((e,t)=>e+(t.inflight??0),0):n.reduce((e,n)=>e+(t.get(n.id)??0),0),a=0,o=0;for(let e of n)(t===void 0?e.inflight??0:t.get(e.id)??0)>=e.maxInflight?o+=1:a+=1;let s=null,c=Date.now(),l=e=>{if(!e)return;let t=Date.parse(e);if(Number.isNaN(t))return;let n=t-c;n<=0||(s===null||n<s)&&(s=n)};for(let t of e){l(t.cooldownUntil);for(let e of t.providerCooldowns??[])l(e.until)}let u=n.filter(e=>e.lastLatencyMs!==void 0&&Number.isFinite(e.lastLatencyMs)),d=u.length===0?null:Math.round(u.reduce((e,t)=>e+(t.lastLatencyMs??0),0)/u.length);return{totalPools:e.length,active:n.length,cooldown:e.filter(e=>e.status===`cooldown`).length,totalMaxConcurrency:r,usedInflight:i,availableCapacity:Math.max(0,r-i),routablePools:a,saturatedPools:o,soonestCooldownMs:s,avgLatencyMs:d,measuredPools:u.length}}var G=[`http`,`https`,`socks5`];function K(e){return/^[a-z][a-z0-9+.-]*:\/\//i.test(e.trim())}function Le(e,t){let n=e.trim();return t===null||K(n)?n:`${t}://${n}`}function q(e){return e.find(e=>e.trim()!==``)}function J(e){let t=e.trim().toLowerCase();return t.startsWith(`https://`)?`https`:t.startsWith(`socks5://`)||t.startsWith(`socks://`)?`socks5`:`http`}var Re=1024**3;function ze(e){let t=e.trim();if(t===``)return null;let n=Number(t);return!Number.isFinite(n)||n<=0?null:Math.max(1,Math.round(n*Re))}function Y(e,t,n){let r=new Map;if(t.trim().toLowerCase()===``||n<=0)return r;let i=Math.floor(e/n),a=e-i*n;for(let e=0;e<n;e+=1){let t=e===n-1?a:0;r.set(e,i+t)}return r}var Be=4,Ve=`cartethyia_proxy_test_payload`,He=`cartethyia_proxy_check_results`,Ue=[{value:`url`,label:`Test URL`},{value:`opencode`,label:`Test OpenCode`}],We=`opencode`,Ge=4,Ke=`Mysterious Proxy`;function X(e){return e.avgLatencyMs===null?`no measurement yet`:`avg across ${e.measuredPools} enabled ${e.measuredPools===1?`pool`:`pools`}`}function qe(e){let t=e.endpoint||``,n=t.includes(`://`)?t:`${e.kind}://${t}`,r={"https:":`443`,"http:":`80`,"socks5:":`1080`,"socks:":`1080`};try{let e=new URL(n),t=e.port||r[e.protocol]||``,i=`${e.hostname}${t?`:${t}`:``}`;return{name:i,endpoint:`${e.protocol}//${i}${e.pathname===`/`?``:e.pathname}${e.search}`}}catch{return{name:e.label||t,endpoint:t}}}function Z(e){return e.label||qe(e).name||e.id}var Q=1024**3;function Je(e){if(e.lastSpeedtestStatus===void 0||e.lastSpeedtestAt===void 0)return;let t=e.lastSpeedtestDurationMs??0,n=e.lastSpeedtestBytes??0,r=t>0?n/(t/1e3):void 0;return{poolId:e.id,status:e.lastSpeedtestStatus,bytes:n,durationMs:t,...r===void 0?{}:{bytesPerSecond:r,megabitsPerSecond:r*8/1e6},...e.lastSpeedtestError?{errorMessage:e.lastSpeedtestError}:{},measuredAt:e.lastSpeedtestAt}}function Ye(e,t){if(!e)return t;if(!t)return e;let n=e.measuredAt?new Date(e.measuredAt).getTime():0;return(t.measuredAt?new Date(t.measuredAt).getTime():0)>=n?t:e}var Xe=[{value:String(he),label:`1 MB`},{value:String(ge),label:`5 MB`},{value:`50000000`,label:`50 MB`},{value:String(B),label:`100 MB`}];function Ze({pool:e,onClose:t,actionsRef:n}){let r=Ce(),i=Oe(),a=ke(),[l,f]=(0,V.useState)(e.label??``),[p,m]=(0,V.useState)(e.family??``),[h,g]=(0,V.useState)(e.endpoint??``),[_,v]=(0,V.useState)(String(e.maxInflight??10)),[y,ee]=(0,V.useState)(String(e.weight??100)),[b,x]=(0,V.useState)(e.quotaBytes?String(Math.round(e.quotaBytes/Q*1e3)/1e3):``),[S,C]=(0,V.useState)(null),[w,T]=(0,V.useState)(!1),E=h.trim()===e.endpoint,D=async()=>{T(!0),C(null);try{if(E){let t=await a.mutateAsync(e.id),n=t.status===`healthy`||t.status===`reachable`;C({ok:n,message:t.status===`healthy`?`Connected in ${t.latencyMs??0}ms`:t.errorMessage??`Connection failed`});return}let t=[{kind:e.kind,endpoint:h.trim(),...e.family===null||e.family===void 0?{}:{family:e.family}}],[n]=await i.mutateAsync({providerId:We,targets:t}),r=n?.result;if(!r){C({ok:!1,message:`Probe returned no result`});return}let o=r.status===`allowed`||r.status===`throttled`;C({ok:o,message:r.reason??(r.status===`allowed`?`Reachable${r.latencyMs===void 0?``:` in ${r.latencyMs}ms`}`:r.status===`throttled`?`Reachable; rate limit spent`:`Probe could not complete`)})}catch(e){C({ok:!1,message:j(e,`Connection failed`)})}finally{T(!1)}},O=ze(b),k=async()=>{await r.mutateAsync({poolId:e.id,request:{...l.trim()===e.label?{}:{label:l.trim()||void 0},...p.trim()===(e.family??``)?{}:{family:p.trim()||null},...h.trim()!==e.endpoint&&h.trim()!==``?{endpoint:h.trim()}:{},...Number(_)===e.maxInflight?{}:{maxInflight:Number(_)},...Number(y)===e.weight?{}:{weight:Number(y)},...O===(e.quotaBytes??null)?{}:{quotaBytes:O}}}),s.success(`Proxy updated`),t()};return(0,V.useEffect)(()=>{n?.((0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(o,{variant:`secondary`,size:`sm`,onClick:t,children:`Cancel`}),(0,H.jsx)(o,{variant:`primary`,size:`sm`,disabled:r.isPending||!h.trim(),onClick:()=>void k(),children:`Save`})]}))}),(0,H.jsxs)(ce,{gap:`12px`,children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Name`,value:l,onChange:e=>f(e.target.value)})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Family`,value:p,placeholder:`e.g. residential-id`,onChange:e=>m(e.target.value)})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Endpoint`,value:h,onChange:e=>g(e.target.value),className:`font-mono tabular-nums`})}),(0,H.jsxs)(`div`,{className:`grid grid-cols-2 gap-5`,children:[(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Max concurrent`,type:`number`,min:1,value:_,onChange:e=>v(e.target.value)})}),(0,H.jsx)(`div`,{children:(0,H.jsx)(I,{label:`Weight`,type:`number`,min:1,value:y,onChange:e=>ee(e.target.value)})})]}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(I,{label:`Bandwidth quota (GB, blank = unmetered)`,type:`number`,min:.001,step:`0.1`,value:b,onChange:e=>x(e.target.value)}),(0,H.jsx)(`div`,{className:`text-micro text-text-tertiary mt-2`,children:O===null?`No quota — the bar shows a running total only.`:`Bar turns orange at 80% and red once ${c(O)} is exceeded.`})]}),S&&(0,H.jsx)(`div`,{className:`rounded-inset px-6 py-4 text-badge font-semibold ${S.ok?`bg-green-soft text-green`:`bg-red-soft text-red`}`,children:S.message}),(0,H.jsx)(`div`,{children:(0,H.jsx)(o,{variant:`secondary`,size:`sm`,disabled:w,icon:w?(0,H.jsx)(d,{size:13,className:`animate-spin`}):(0,H.jsx)(u,{size:13}),onClick:()=>void D(),children:w?`Testing…`:`Test connection`})})]})}function Qe({endpoint:e,chip:t,onChipChange:n}){return(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,role:`group`,"aria-label":`Scheme for the first endpoint`,children:[(0,H.jsx)(`span`,{className:`text-badge text-text-secondary`,children:`Scheme`}),G.map(r=>{let i=t===r;return(0,H.jsxs)(o,{type:`button`,variant:i?`primary`:`secondary`,size:`sm`,disabled:e===void 0,"aria-pressed":i,"data-scheme":r,onClick:()=>n(i?null:r),className:`font-mono`,children:[r,`://`]},r)}),t!==null&&(0,H.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[`→ `,Le(e??``,t)]})]})}function $e({onClose:e,actionsRef:t,onProbeResult:n,onHealthResult:r}){let i=be(),a=Se(),c=Oe(),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(``),[p,m]=(0,V.useState)(``),[h,g]=(0,V.useState)(null),[_,v]=(0,V.useState)([]),[y,ee]=(0,V.useState)({}),[b,x]=(0,V.useState)({}),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(null),E=l.split(`
2
2
  `).map(e=>e.trim()).filter(Boolean),D=q(E),O=(0,V.useMemo)(()=>w===null||D===void 0?E:E.map((e,t)=>e===D&&t===0?Le(e,w):e),[E,w,D]),k=E.length>100,A=ze(p),M=(0,V.useMemo)(()=>O.map(e=>({kind:J(e),endpoint:e})),[O]),N=async()=>{try{let e=await navigator.clipboard.readText();e&&u(t=>t?`${t}\n${e}`:e)}catch{s.error(`Paste failed`,`Clipboard access denied`)}},P=async()=>{if(M.length!==0){v([`Testing ${M.length} proxy target(s)…`]);try{let e=await a.mutateAsync(M),t=e.map(e=>{let t=e.result.status===`healthy`||e.result.status===`reachable`,n=e.result.latencyMs===void 0?``:` · ${e.result.latencyMs}ms`,r=e.result.egressIp?` · ${e.result.egressIp}`:``,i=t?``:` · ${e.result.errorMessage??e.result.status}`;return`${t?`OK `:`FAIL`} ${e.endpoint}${n}${r}${i}`}),n=e.filter(e=>e.result.status===`healthy`||e.result.status===`reachable`).length;x(t=>{let n={...t};for(let t of e)n[t.endpoint]=t.result;return n}),v([`${n}/${e.length} reachable`,...t]),n===e.length?s.success(`All ${e.length} proxies reachable`):s.error(`${e.length-n} of ${e.length} proxies failed`)}catch(e){v([`Test failed: ${j(e,`batch probe failed`)}`]),s.error(`Test failed`,j(e,`batch probe failed`))}}},te=async()=>{if(M.length!==0){v([`Testing ${M.length} proxy target(s) against OpenCode…`]);try{let e=await c.mutateAsync({providerId:We,targets:M}),t=e.map(e=>{let{status:t,latencyMs:n,reason:r}=e.result,i=n===void 0?``:` · ${n}ms`,a=r===void 0?``:` · ${r}`;return`${t===`allowed`?`OK `:t===`blocked`?`BLOCK`:`FAIL`} ${e.endpoint}${i}${a}`});ee(t=>{let n={...t};for(let t of e)n[t.endpoint]=t.result;return n});let n=e.filter(e=>e.result.status===`allowed`).length,r=e.filter(e=>e.result.status===`blocked`).length;v([`${n}/${e.length} allowed · ${r} blocked`,...t]),r===0&&n===e.length?s.success(`OpenCode accepted all ${e.length} proxies`):s.error(`OpenCode: ${n} allowed · ${r} blocked`)}catch(e){v([`Test failed: ${j(e,`provider probe failed`)}`]),s.error(`Test failed`,j(e,`provider probe failed`))}}};return(0,V.useEffect)(()=>{t?.((0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(o,{variant:`secondary`,type:`button`,onClick:e,children:`Cancel`}),(0,H.jsx)(o,{variant:`primary`,type:`submit`,form:`add-proxy-form`,disabled:S||E.length===0,children:S?`Adding…`:`Add ${E.length} Prox${E.length===1?`y`:`ies`}`})]}))},[t,S,E.length,e]),(0,H.jsxs)(`form`,{id:`add-proxy-form`,onSubmit:async t=>{if(t.preventDefault(),E.length!==0){g(null),C(!0);try{let t=A===null?new Map:Y(A,d,O.length),a=Array(E.length),o=0,c=async()=>{for(;o<E.length;){let e=o++,s=O[e];try{let o=await i.mutateAsync({kind:J(s),endpoint:s,...t.has(e)?{quotaBytes:t.get(e)}:{},...d.trim()===``?{}:{family:d.trim()}}),c=y[s],l=b[s];o?.id&&(l!==void 0&&r?.(o.id,l),c!==void 0&&n?.(o.id,c)),a[e]={ok:!0}}catch(t){a[e]={ok:!1,error:j(t,`Proxy pool creation failed`)}}}};await Promise.all(Array.from({length:Math.min(Be,E.length)},()=>c()));let l=[],f=0;for(let[e,t]of a.entries())t.ok?f++:l.length<3&&l.push(`${E[e].slice(0,48)}…: ${t.error}`);let p=E.length-f,m=a.find(e=>!e.ok)?.error;f>0&&s.success(`Added ${f} proxy pool(s)`,p?`${p} failed: ${m??`see the import details`}`:void 0),p>0&&f===0&&s.error(`Failed to create pool`,m??`See the import details`),p>0&&g(l.join(`
3
3
  `)),f>0&&(u(``),e())}finally{C(!1)}}},className:`flex flex-col gap-4`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`label`,{htmlFor:`proxy-endpoints`,className:`text-caption font-semibold text-text-primary`,children:`Proxy endpoints`}),(0,H.jsx)(o,{variant:`secondary`,size:`sm`,type:`button`,onClick:N,children:`Paste`})]}),(0,H.jsx)(`textarea`,{id:`proxy-endpoints`,value:l,onChange:e=>u(e.target.value),placeholder:`http://proxy.example:8080
4
4
  https://proxy.example:8443
@@ -1 +1 @@
1
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{O as a,c as o,s,v as c,x as l}from"./numbers-Dulqgys5.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as u}from"./eye-off-Bk5g2luF.js";import{i as d,n as f,r as p,t as m}from"./state-DhZBfWgx.js";import{t as h}from"./dialog-Iec_ywbD.js";import{t as g}from"./refresh-cw-BqJFk4sU.js";import{t as _}from"./rotate-ccw-CufcqITi.js";import{t as v}from"./trash-Cppn5c3R.js";import{t as y}from"./zap-C4EeVW4q.js";import{l as b}from"./query-keys-UETqfytp.js";import{z as x}from"./entry-BcfdW4C_.js";import{n as S,t as te}from"./card-BOPBuBzD.js";import{t as C}from"./badge-Bkz_-RrM.js";import{t as w}from"./select-BTEzH1iH.js";import{t as T}from"./ProviderIcon-CmfzxpVM.js";import{t as E}from"./switch-yD7D99Lg.js";import{t as D}from"./stack-B1w5BM0u.js";import{n as O}from"./inline-DToMICwl.js";import{t as k}from"./layout-DaJ5baJr.js";import{a as A,i as ne,n as j,o as M,r as N,s as P,t as F}from"./quota-DZGyp0N5.js";import{a as I,c as L,d as R,f as z,i as B,l as V,n as H,o as U,p as W,r as G,s as K,t as re,u as q}from"./HealthEventsModal-gTD1Qv_d.js";var J=e(`calendar-check`,[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`m9 15 2 2 4-4`,key:`1grp1n`}]]),ie=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),Y=e(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),X=t(n(),1),Z=r();function Q(e){return!!(e.quota?.windows.length&&e.quota.windows.every(e=>e.remainingPercent!==null&&e.remainingPercent<=0))}function $(e){let t=e.quota?.windows.map(e=>e.resetsAt?new Date(e.resetsAt).getTime():1/0)??[];return Math.min(...t,1/0)}function ae({account:e,onClose:t}){let n=B(e.id,!0),r=q(e.id),i=n.data?.credits??[],a=e=>e?new Date(e).toLocaleString():`—`,c=e=>e?new Date(e).toLocaleString():`—`,l=e=>{if(!e)return``;let t=new Date(e).getTime()-Date.now();if(!Number.isFinite(t))return``;if(t<=0)return`expired`;let n=Math.floor(t/864e5);if(n>=1)return`in ${n}d`;let r=Math.floor(t/36e5);return r>=1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))}m`};return(0,Z.jsx)(h,{open:!0,onClose:t,size:`lg`,title:`Saved Rate-Limit Resets — ${e.name}`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border bg-surface-2 px-8 py-6`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(y,{size:14,className:`text-status-success`}),(0,Z.jsx)(`span`,{className:`text-body font-semibold`,children:`Available resets`})]}),(0,Z.jsx)(`p`,{className:`mt-2 text-text-tertiary text-badge leading-normal`,children:`Each credit lifts a spent rate-limit window before its natural reset.`})]}),(0,Z.jsxs)(C,{tone:n.data&&n.data.availableCount>0?`ok`:`disabled`,dot:!0,children:[n.data?.availableCount??0,` reset`,(n.data?.availableCount??0)===1?``:`s`]})]}),n.isPending?(0,Z.jsx)(p,{compact:!0,label:`Reading saved resets…`}):n.isError?(0,Z.jsx)(f,{compact:!0,message:`Failed to read saved resets`,onRetry:()=>void n.refetch()}):i.length===0?(0,Z.jsx)(m,{compact:!0,title:`No saved resets`,message:`This account has no saved rate-limit reset credits right now.`,icon:(0,Z.jsx)(y,{size:20})}):(0,Z.jsx)(`div`,{className:`max-h-170 overflow-y-auto rounded-control border border-inner-border`,children:(0,Z.jsx)(k,{headers:[`Status`,`Title`,`Granted`,`Expires`,``],children:i.map(e=>{let t=(e.status??`available`)===`available`,n=l(e.expiresAt);return(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`whitespace-nowrap align-middle`,children:(0,Z.jsx)(C,{tone:t?`ok`:e.status===`expired`?`disabled`:`warn`,children:e.status??`available`})}),(0,Z.jsx)(`td`,{className:`text-caption font-medium whitespace-nowrap align-middle text-text-primary`,children:e.title??`Rate-limit reset`}),(0,Z.jsx)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:a(e.grantedAt)}),(0,Z.jsxs)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:[c(e.expiresAt),n&&(0,Z.jsxs)(`span`,{className:`ml-3 text-text-tertiary`,children:[`(`,n,`)`]})]}),(0,Z.jsx)(`td`,{className:`whitespace-nowrap text-right align-middle`,children:(0,Z.jsx)(o,{size:`sm`,variant:t?`primary`:`secondary`,disabled:!t||r.isPending,onClick:()=>r.mutate({creditId:e.id},{onSuccess:e=>{e.ok?s.success(e.message??`Rate limit reset applied`):s.error(e.message??`Rate limit reset failed`)},onError:e=>{s.error(b(e,`Unable to redeem rate-limit reset`))}}),children:`Use`})})]},e.id)})})}),(0,Z.jsx)(O,{justify:`flex-end`,gap:`0px`,children:(0,Z.jsx)(o,{variant:`secondary`,size:`sm`,onClick:t,children:`Close`})})]})})}function oe({accounts:e}){let t=(0,X.useMemo)(()=>{let t=new Map;for(let n of e){if(!H(n.provider))continue;let e=t.get(n.provider);e?e.count+=1:t.set(n.provider,{id:n.provider,label:n.providerName||n.provider,count:1})}return[...t.values()]},[e]),[n,r]=(0,X.useState)(``),i=(t.find(e=>e.id===n)??t[0])?.id??``,a=z(i),c=i.length===0||a.isPending||t.length===0;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2.5`,"aria-label":`Daily growth actions`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 w-67.5`,children:(0,Z.jsx)(w,{"aria-label":`Provider for the daily growth pass`,value:i,onValueChange:r,className:`w-full h-16`,options:t.length>0?t.map(e=>({value:e.id,label:`${e.label} · ${e.count}`})):[{value:``,label:`No buddy providers`}]})}),(0,Z.jsx)(o,{variant:`secondary`,size:`sm`,title:`Send the activity report, then claim the daily check-in, for every account of this provider`,"aria-label":`Run the daily growth pass for this provider`,disabled:c,className:`shrink-0`,icon:a.isPending?(0,Z.jsx)(l,{size:13,className:`animate-spin`}):(0,Z.jsx)(J,{size:13}),onClick:()=>a.mutate(void 0,{onSuccess:e=>{let t=e.data.filter(e=>!e.report.ok).length;t===0?s.success(e.message):s.error(`${e.message} — ${t} report${t===1?``:`s`} failed`)},onError:e=>s.error(b(e,`Unable to run the daily growth pass`))}),children:`Daily growth`})]})}function se({account:e,onToggle:t,onDelete:n,onShowHealth:r,onShowResets:a}){let u=K(e.id),d=R(e.id),f=H(e.provider),p=G(e.provider),m=B(e.id,p),h=e.quota,[g,x]=(0,X.useState)(0),S=h?.windows??[],C=M(S,g),w=C.pageCount;(0,X.useEffect)(()=>{x(e=>Math.min(e,Math.max(0,w-1)))},[w]);let D=u.isPending||d.isPending,O=m.data?.availableCount??0,[k,I]=(0,X.useState)(null),[L,z]=(0,X.useState)(!1),V=e.checkin?.attemptedToday??!1,U=`${k?k.state===`claimed`?`Checked in${k.credit===null?``:` +${k.credit}`}${k.streakDays===null?``:` · ${k.streakDays}d streak`}`:k.state===`already_claimed`?`Check-in attempted · already claimed`:k.state===`not_eligible`?`Check-in attempted · not eligible`:k.state===`event_ended`?`Check-in attempted · event ended`:`Check-in attempted · unavailable`:V?`Check-in attempted today`:`Check-in due`}${L?` · Reported today`:``}`,W=S.reduce((e,t)=>{let n=t.limit;if(typeof n!=`number`||!Number.isFinite(n))return e;let r=typeof t.remaining==`number`&&Number.isFinite(t.remaining)?t.remaining:typeof t.used==`number`&&Number.isFinite(t.used)?n-t.used:typeof t.remainingPercent==`number`&&Number.isFinite(t.remainingPercent)?n*t.remainingPercent/100:null;return r===null?e:e+Math.max(0,r)},0),re=(u.error?b(u.error,`Unable to refresh this account`):null)??h?.refreshError??h?.error??e.health?.sanitizedMessage,q=A(re),Y=q===`Quota tracking is not supported for this provider`?null:q,Q=F(e.credentialHint,e.name),$=e.health?.status??`unknown`;return(0,Z.jsxs)(te,{className:`flex h-full flex-col overflow-hidden`,"aria-busy":D,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5 px-7 py-4`,children:[(0,Z.jsx)(T,{icon:e.providerIcon,name:e.providerName,size:32}),(0,Z.jsxs)(`div`,{className:`flex-[1_1_160px]`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4`,children:[(0,Z.jsx)(`div`,{className:`truncate text-caption font-bold text-text-primary text-body`,children:e.providerName}),h?.plan&&(0,Z.jsx)(`span`,{className:`shrink-0 rounded-chip bg-accent-soft px-4 py-1 text-micro font-semibold text-accent`,children:h.plan})]}),(0,Z.jsx)(`div`,{className:`truncate text-badge text-text-secondary`,children:Q.primary}),Q.secondary!==null&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:Q.secondary}),h&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:j(h.lastSuccessAt??h.fetchedAt)}),p&&(0,Z.jsx)(`div`,{className:`truncate text-micro flex items-center gap-2 text-text-tertiary`,title:`Saved rate-limit reset credits available on this account`,children:m.isPending?`Checking saved resets…`:O>0?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(y,{size:10,className:`text-status-success shrink-0`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{className:`reset-credit-live`,children:[O,` rate-limit reset`,O===1?``:`s`,` available`]})]}):`No rate-limit resets available`}),f&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{title:`Daily growth state: manual pass result, else the sweep ledger for today`,className:`truncate text-micro text-text-tertiary`,children:d.isPending?`Running growth pass…`:U}),S.some(e=>typeof e.limit==`number`&&Number.isFinite(e.limit))&&(0,Z.jsxs)(`div`,{className:`truncate text-micro text-text-tertiary`,children:[`Total credits: `,W.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.75 gap-3 ml-auto`,children:[p&&(0,Z.jsx)(o,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:m.isPending?`Checking saved rate-limit resets…`:O>0?`Saved rate-limit resets (${O} available)`:`Saved rate-limit resets`,"aria-label":`Open saved rate-limit resets for ${e.name}`,disabled:D,onClick:()=>a(e),children:(0,Z.jsx)(y,{size:14})}),f&&(0,Z.jsx)(o,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:`Daily growth pass (check-in + activity report) — ${U}`,"aria-label":`Run daily growth pass for ${e.name}`,disabled:D,onClick:()=>d.mutate(void 0,{onSuccess:e=>{let t=e.checkin.data;t&&I({state:t.state,credit:t.credit,streakDays:t.streakDays}),e.report.ok&&z(!0),e.ok?s.success(e.message):s.error(e.message)},onError:e=>{s.error(b(e,`Unable to run daily growth pass`))}}),children:d.isPending?(0,Z.jsx)(l,{size:14,className:`animate-spin`}):(0,Z.jsx)(J,{size:14})}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,title:$===`active`?`Health & Error Log`:`${$} — Inspect account health details`,"aria-label":$===`active`?`Health log for ${e.name}`:`Account is ${$} — inspect health details for ${e.name}`,disabled:D,onClick:()=>r(e),icon:(0,Z.jsx)(i,{size:12})}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,title:`Refresh quota`,"aria-label":`Refresh ${e.name} quota`,disabled:D,onClick:()=>u.mutate(),icon:u.isPending?(0,Z.jsx)(l,{size:12,className:`animate-spin`}):(0,Z.jsx)(_,{size:12})}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,title:`Delete account`,"aria-label":`Delete ${e.name}`,onClick:()=>n(e),className:`text-red`,icon:(0,Z.jsx)(v,{size:12})}),(0,Z.jsx)(E,{checked:e.active,disabled:u.isPending,onChange:n=>t(e,n),label:``,id:`switch-${e.id}`})]})]}),Y&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-4 border-t border-inner-border px-8 py-5 text-center text-badge text-red`,role:`alert`,children:[(0,Z.jsx)(c,{size:13,className:`shrink-0`}),(0,Z.jsx)(`span`,{children:Y})]}),h?.windows.length?(0,Z.jsxs)(`div`,{className:`quota-window-list flex flex-1 flex-col gap-4 border-t border-inner-border px-7 py-4.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-section-label text-micro font-bold tracking-label text-text-tertiary`,children:`QUOTA WINDOWS`}),C.items.map((e,t)=>{let n=e.remainingPercent??null,r=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null,i=typeof e.used==`number`&&Number.isFinite(e.used)?e.used:r!==null&&e.usedPercent!==null&&e.usedPercent!==void 0?r*e.usedPercent/100:null,a=P(n),o=n===null?0:Math.max(0,Math.min(100,n)),s=e=>e.toLocaleString(void 0,{maximumFractionDigits:2}),c=e=>{let t=Math.round(e*10)/10;return t>0&&t<.1?`<0.1`:t.toLocaleString(void 0,{maximumFractionDigits:1})},l=N(e.label);return(0,Z.jsxs)(`div`,{className:`quota-window-row grid grid-cols-quota-window min-w-0 items-center gap-x-6 gap-y-2 max-small:grid-cols-[minmax(0,1fr)_auto] max-small:gap-x-4 max-small:gap-y-2.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-heading min-w-0 max-small:col-start-1`,children:(0,Z.jsx)(`span`,{className:`text-badge font-semibold text-text-primary`,children:l})}),(0,Z.jsx)(`div`,{className:`quota-bar-track quota-window-bar min-w-0 w-full h-5 rounded-tiny bg-inner-border overflow-hidden max-small:col-span-full max-small:row-start-2`,role:`progressbar`,"aria-label":`${l} remaining quota`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n===null?void 0:o,"aria-valuetext":n===null?`Quota only`:`${c(n)}% remaining`,children:(0,Z.jsx)(`div`,{className:`quota-bar-fill h-full rounded-tiny transition-[width] duration-(--dur-macro) ease-spring`,style:{width:`${o}%`,background:a.bar}})}),(0,Z.jsx)(`span`,{className:`quota-window-remaining whitespace-nowrap text-badge font-bold tabular-nums max-small:col-start-2 max-small:row-start-1`,style:{color:a.text},children:n===null?`—`:`${c(n)}%`}),(0,Z.jsxs)(`div`,{className:`quota-window-details col-span-full flex min-w-0 items-center justify-end gap-6 text-micro text-text-tertiary max-small:row-start-3 max-small:flex-wrap max-small:justify-between max-small:gap-4`,children:[(0,Z.jsx)(`span`,{className:`quota-window-usage mr-auto tabular-nums max-small:min-w-0`,children:i!==null&&r!==null?`${s(i)} / ${s(r)} Credits`:`Quota only`}),e.resetsAt&&(0,Z.jsx)(`span`,{className:`quota-window-reset whitespace-nowrap tabular-nums text-right max-small:ml-auto`,children:ne(e.resetsAt,e.recurring)})]})]},`${e.kind??e.label}:${e.resetsAt??`none`}:${t}`)}),C.pageCount>1&&(0,Z.jsxs)(`nav`,{"aria-label":`Quota windows for ${e.name}`,className:`quota-window-pagination mt-auto flex items-center justify-between gap-4 border-t border-inner-border pt-4 max-small:flex-wrap`,children:[(0,Z.jsxs)(`span`,{"aria-live":`polite`,className:`text-micro text-text-tertiary`,children:[`Showing `,C.startIndex+1,`–`,C.startIndex+C.items.length,` of `,S.length]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,"aria-label":`Previous quota windows for ${e.name}`,disabled:C.page===0,icon:(0,Z.jsx)(ie,{size:13}),onClick:()=>x(C.page-1),className:`h-14 px-4 py-0`,children:`Previous`}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,"aria-label":`Next quota windows for ${e.name}`,disabled:C.page>=C.pageCount-1,icon:(0,Z.jsx)(ee,{size:13}),onClick:()=>x(C.page+1),className:`h-14 px-4 py-0`,children:`Next`})]})]})]}):Y?null:(0,Z.jsx)(`div`,{className:`border-t border-inner-border px-7 py-9 text-center text-badge text-text-tertiary`,children:D||e.pending?`Fetching quota…`:`No quota data`})]})}function ce(){let[e,t]=(0,X.useState)(`all`),[n,r]=(0,X.useState)(`all`),[i,c]=(0,X.useState)(!1),{data:l,isLoading:ee,isError:f,error:p,isFetching:h,dataUpdatedAt:_,refetch:v}=U(),y=(0,X.useMemo)(()=>[...l?.providers??[]].sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`})),[l?.providers]),b=(0,X.useMemo)(()=>l?.accounts??[],[l?.accounts]),C=l?.refreshing??0,T=L(),[E,O]=(0,X.useState)(null),k=W(),A=V(),ne=I(),[j,M]=(0,X.useState)(null);(0,X.useEffect)(()=>{T.isPending||O(null)},[T.isPending]);let[N,P]=(0,X.useState)(null),[F,R]=(0,X.useState)(null),z=(0,X.useMemo)(()=>{let t=b.filter(t=>{if(e!==`all`&&t.provider!==e)return!1;let r=!!t.quota?.windows.length;return n===`untracked`?!r:!(!r||n===`active`&&!t.active||n===`disabled`&&t.active)}),r=(e,t)=>e.providerName.localeCompare(t.providerName,void 0,{sensitivity:`base`})||e.name.localeCompare(t.name,void 0,{sensitivity:`base`});return[...t].sort(i?(e,t)=>$(e)-$(t)||r(e,t):r)},[n,b,i,e]),B=async(e,t)=>{try{await k.mutateAsync({id:e.id,active:t}),s.success(`${e.name} ${t?`enabled`:`disabled`}`)}catch(e){s.error(e instanceof Error?e.message:`Unable to update account`)}},H=async()=>{let e=b.filter(e=>e.active&&Q(e));await A.mutateAsync({ids:e.map(e=>e.id),active:!1}),s.success(`Disabled ${e.length} empty accounts`)},G=async()=>{let e=b.filter(e=>!e.active&&e.quota?.windows.some(e=>e.remainingPercent!==null&&e.remainingPercent>0));await A.mutateAsync({ids:e.map(e=>e.id),active:!0}),s.success(`Enabled ${e.length} available accounts`)},K=async e=>{await ne.mutateAsync(e.id),s.success(`${e.name} deleted`)},q=_>0?new Date(_).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):`Not updated`,J=b.filter(Q).length;return(0,Z.jsxs)(D,{gap:`16px`,className:`dashboard-page min-h-0 flex-1`,children:[(0,Z.jsx)(te,{children:(0,Z.jsxs)(S,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-4`,children:[(0,Z.jsx)(w,{"aria-label":`Filter quota by provider`,value:e,onValueChange:t,className:`w-full h-16 max-small:w-80`,options:[{value:`all`,label:`All Providers`},...y.map(e=>({value:e.id,label:e.name}))]}),(0,Z.jsx)(w,{"aria-label":`Filter quota by account`,value:n,onValueChange:r,className:`w-full h-16 max-small:w-67.5`,options:[{value:`all`,label:`With quota`},{value:`active`,label:`Active`},{value:`disabled`,label:`Disabled`},{value:`untracked`,label:`No quota`}]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,Z.jsx)(o,{variant:i?`secondary`:`ghost`,size:`sm`,onClick:()=>c(e=>!e),"aria-pressed":i,icon:(0,Z.jsx)(Y,{size:13}),children:`Expiring first`}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,className:`text-red`,disabled:J===0||h,onClick:()=>void H(),icon:(0,Z.jsx)(u,{size:13}),children:`Turn off Empty`}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,className:`text-green`,disabled:h,onClick:()=>void G(),icon:(0,Z.jsx)(a,{size:13}),children:`Turn on Available`})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4 border-t border-inner-border pt-5`,children:[(0,Z.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[z.length,` shown`,J>0?` · ${J} empty`:``]}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-5 gap-y-3 text-badge text-text-tertiary`,children:[C>0?`Refreshing ${C} account${C===1?``:`s`}…`:`Auto-refresh 60s · ${q}`,(0,Z.jsx)(oe,{accounts:b}),(0,Z.jsx)(o,{variant:`secondary`,size:`sm`,title:`Queue quota refresh`,"aria-label":`Queue quota refresh`,disabled:h||T.isPending||b.length===0,icon:(0,Z.jsx)(g,{size:13,className:T.isPending?`animate-spin`:void 0}),onClick:()=>T.mutate({accountIds:b.map(e=>e.id),onProgress:(e,t)=>O({done:e,total:t})},{onSuccess:e=>{s.success(e.failed===0?`Refreshed ${e.succeeded} quota${e.succeeded===1?``:`s`}`:`Refreshed ${e.succeeded}, ${e.failed} failed`)},onError:e=>s.error(e instanceof Error?e.message:`Unable to refresh quota`)}),children:E&&E.total>0?`Refresh ${E.done}/${E.total}`:`Refresh`})]})]})]})}),(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6`,children:ee?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`loading`,title:`Loading quota data`,description:`Reading provider account limits…`}):f?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`error`,title:`Unable to load quota data`,description:p instanceof Error?p.message:`Check the console session and retry.`,action:(0,Z.jsx)(o,{variant:`secondary`,onClick:()=>void v(),children:`Retry`})}):z.length===0?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-12 border border-dashed border-transparent rounded-card bg-transparent text-center`,children:(0,Z.jsx)(m,{title:`No account quota data`,message:`Nothing is reporting a quota window yet. Add a provider account and its limits will appear here.`})}):(0,Z.jsx)(`div`,{className:`quota-account-grid scroll-region min-h-0 flex-1 gap-6 [align-content:start]`,children:z.map(e=>(0,Z.jsx)(se,{account:e,onToggle:(e,t)=>void B(e,t),onDelete:e=>M(e),onShowHealth:e=>P(e),onShowResets:e=>R(e)},e.id))})}),N&&(0,Z.jsx)(re,{summary:{providerId:N.provider,accountId:N.id,title:N.name,status:N.health?.status??`unknown`,errorCategory:N.health?.lastErrorCategory??void 0,errorMessage:N.health?.sanitizedMessage??void 0,emptyMessage:`Status transitions, rate limits, quota refreshes, check-ins, and auto-recoveries will appear here.`},onClose:()=>P(null)}),F&&(0,Z.jsx)(ae,{account:F,onClose:()=>R(null)}),(0,Z.jsx)(x,{open:j!==null,onClose:()=>M(null),onConfirm:async()=>{j&&await K(j)},title:`Delete account?`,message:`Delete "${j?.name}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}export{ce as default};
1
+ import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i}from"./terminal-0_IjPWTk.js";import{O as a,c as o,s,v as c,x as l}from"./numbers-Dulqgys5.js";import{t as ee}from"./chevron-right-BXIy5l3h.js";import{t as u}from"./eye-off-Bk5g2luF.js";import{i as d,n as f,r as p,t as m}from"./state-DhZBfWgx.js";import{t as h}from"./dialog-Iec_ywbD.js";import{t as g}from"./refresh-cw-BqJFk4sU.js";import{t as _}from"./rotate-ccw-CufcqITi.js";import{t as v}from"./trash-Cppn5c3R.js";import{t as y}from"./zap-C4EeVW4q.js";import{l as b}from"./query-keys-UETqfytp.js";import{z as x}from"./entry-BrksMru8.js";import{n as S,t as te}from"./card-BOPBuBzD.js";import{t as C}from"./badge-Bkz_-RrM.js";import{t as w}from"./select-Ciq_KFQ1.js";import{t as T}from"./ProviderIcon-CmfzxpVM.js";import{t as E}from"./switch-yD7D99Lg.js";import{t as D}from"./stack-B1w5BM0u.js";import{n as O}from"./inline-DToMICwl.js";import{t as k}from"./layout-DaJ5baJr.js";import{a as A,i as ne,n as j,o as M,r as N,s as P,t as F}from"./quota-DZGyp0N5.js";import{a as I,c as L,d as R,f as z,i as B,l as V,n as H,o as U,p as W,r as G,s as K,t as re,u as q}from"./HealthEventsModal-DeT1zkYG.js";var J=e(`calendar-check`,[[`path`,{d:`M8 2v3`,key:`1ioesn`}],[`path`,{d:`M16 2v3`,key:`otl347`}],[`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`,key:`h1oib`}],[`path`,{d:`M3 9h18`,key:`1pudct`}],[`path`,{d:`m9 15 2 2 4-4`,key:`1grp1n`}]]),ie=e(`chevron-left`,[[`path`,{d:`m15 18-6-6 6-6`,key:`1wnfg3`}]]),Y=e(`clock-3`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6h4`,key:`135r8i`}]]),X=t(n(),1),Z=r();function Q(e){return!!(e.quota?.windows.length&&e.quota.windows.every(e=>e.remainingPercent!==null&&e.remainingPercent<=0))}function $(e){let t=e.quota?.windows.map(e=>e.resetsAt?new Date(e.resetsAt).getTime():1/0)??[];return Math.min(...t,1/0)}function ae({account:e,onClose:t}){let n=B(e.id,!0),r=q(e.id),i=n.data?.credits??[],a=e=>e?new Date(e).toLocaleString():`—`,c=e=>e?new Date(e).toLocaleString():`—`,l=e=>{if(!e)return``;let t=new Date(e).getTime()-Date.now();if(!Number.isFinite(t))return``;if(t<=0)return`expired`;let n=Math.floor(t/864e5);if(n>=1)return`in ${n}d`;let r=Math.floor(t/36e5);return r>=1?`in ${r}h`:`in ${Math.max(1,Math.floor(t/6e4))}m`};return(0,Z.jsx)(h,{open:!0,onClose:t,size:`lg`,title:`Saved Rate-Limit Resets — ${e.name}`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border bg-surface-2 px-8 py-6`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Z.jsx)(y,{size:14,className:`text-status-success`}),(0,Z.jsx)(`span`,{className:`text-body font-semibold`,children:`Available resets`})]}),(0,Z.jsx)(`p`,{className:`mt-2 text-text-tertiary text-badge leading-normal`,children:`Each credit lifts a spent rate-limit window before its natural reset.`})]}),(0,Z.jsxs)(C,{tone:n.data&&n.data.availableCount>0?`ok`:`disabled`,dot:!0,children:[n.data?.availableCount??0,` reset`,(n.data?.availableCount??0)===1?``:`s`]})]}),n.isPending?(0,Z.jsx)(p,{compact:!0,label:`Reading saved resets…`}):n.isError?(0,Z.jsx)(f,{compact:!0,message:`Failed to read saved resets`,onRetry:()=>void n.refetch()}):i.length===0?(0,Z.jsx)(m,{compact:!0,title:`No saved resets`,message:`This account has no saved rate-limit reset credits right now.`,icon:(0,Z.jsx)(y,{size:20})}):(0,Z.jsx)(`div`,{className:`max-h-170 overflow-y-auto rounded-control border border-inner-border`,children:(0,Z.jsx)(k,{headers:[`Status`,`Title`,`Granted`,`Expires`,``],children:i.map(e=>{let t=(e.status??`available`)===`available`,n=l(e.expiresAt);return(0,Z.jsxs)(`tr`,{children:[(0,Z.jsx)(`td`,{className:`whitespace-nowrap align-middle`,children:(0,Z.jsx)(C,{tone:t?`ok`:e.status===`expired`?`disabled`:`warn`,children:e.status??`available`})}),(0,Z.jsx)(`td`,{className:`text-caption font-medium whitespace-nowrap align-middle text-text-primary`,children:e.title??`Rate-limit reset`}),(0,Z.jsx)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:a(e.grantedAt)}),(0,Z.jsxs)(`td`,{className:`text-badge whitespace-nowrap tabular-nums align-middle text-text-secondary`,children:[c(e.expiresAt),n&&(0,Z.jsxs)(`span`,{className:`ml-3 text-text-tertiary`,children:[`(`,n,`)`]})]}),(0,Z.jsx)(`td`,{className:`whitespace-nowrap text-right align-middle`,children:(0,Z.jsx)(o,{size:`sm`,variant:t?`primary`:`secondary`,disabled:!t||r.isPending,onClick:()=>r.mutate({creditId:e.id},{onSuccess:e=>{e.ok?s.success(e.message??`Rate limit reset applied`):s.error(e.message??`Rate limit reset failed`)},onError:e=>{s.error(b(e,`Unable to redeem rate-limit reset`))}}),children:`Use`})})]},e.id)})})}),(0,Z.jsx)(O,{justify:`flex-end`,gap:`0px`,children:(0,Z.jsx)(o,{variant:`secondary`,size:`sm`,onClick:t,children:`Close`})})]})})}function oe({accounts:e}){let t=(0,X.useMemo)(()=>{let t=new Map;for(let n of e){if(!H(n.provider))continue;let e=t.get(n.provider);e?e.count+=1:t.set(n.provider,{id:n.provider,label:n.providerName||n.provider,count:1})}return[...t.values()]},[e]),[n,r]=(0,X.useState)(``),i=(t.find(e=>e.id===n)??t[0])?.id??``,a=z(i),c=i.length===0||a.isPending||t.length===0;return(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2.5`,"aria-label":`Daily growth actions`,children:[(0,Z.jsx)(`div`,{className:`min-w-0 w-67.5`,children:(0,Z.jsx)(w,{"aria-label":`Provider for the daily growth pass`,value:i,onValueChange:r,className:`w-full h-16`,options:t.length>0?t.map(e=>({value:e.id,label:`${e.label} · ${e.count}`})):[{value:``,label:`No buddy providers`}]})}),(0,Z.jsx)(o,{variant:`secondary`,size:`sm`,title:`Send the activity report, then claim the daily check-in, for every account of this provider`,"aria-label":`Run the daily growth pass for this provider`,disabled:c,className:`shrink-0`,icon:a.isPending?(0,Z.jsx)(l,{size:13,className:`animate-spin`}):(0,Z.jsx)(J,{size:13}),onClick:()=>a.mutate(void 0,{onSuccess:e=>{let t=e.data.filter(e=>!e.report.ok).length;t===0?s.success(e.message):s.error(`${e.message} — ${t} report${t===1?``:`s`} failed`)},onError:e=>s.error(b(e,`Unable to run the daily growth pass`))}),children:`Daily growth`})]})}function se({account:e,onToggle:t,onDelete:n,onShowHealth:r,onShowResets:a}){let u=K(e.id),d=R(e.id),f=H(e.provider),p=G(e.provider),m=B(e.id,p),h=e.quota,[g,x]=(0,X.useState)(0),S=h?.windows??[],C=M(S,g),w=C.pageCount;(0,X.useEffect)(()=>{x(e=>Math.min(e,Math.max(0,w-1)))},[w]);let D=u.isPending||d.isPending,O=m.data?.availableCount??0,[k,I]=(0,X.useState)(null),[L,z]=(0,X.useState)(!1),V=e.checkin?.attemptedToday??!1,U=`${k?k.state===`claimed`?`Checked in${k.credit===null?``:` +${k.credit}`}${k.streakDays===null?``:` · ${k.streakDays}d streak`}`:k.state===`already_claimed`?`Check-in attempted · already claimed`:k.state===`not_eligible`?`Check-in attempted · not eligible`:k.state===`event_ended`?`Check-in attempted · event ended`:`Check-in attempted · unavailable`:V?`Check-in attempted today`:`Check-in due`}${L?` · Reported today`:``}`,W=S.reduce((e,t)=>{let n=t.limit;if(typeof n!=`number`||!Number.isFinite(n))return e;let r=typeof t.remaining==`number`&&Number.isFinite(t.remaining)?t.remaining:typeof t.used==`number`&&Number.isFinite(t.used)?n-t.used:typeof t.remainingPercent==`number`&&Number.isFinite(t.remainingPercent)?n*t.remainingPercent/100:null;return r===null?e:e+Math.max(0,r)},0),re=(u.error?b(u.error,`Unable to refresh this account`):null)??h?.refreshError??h?.error??e.health?.sanitizedMessage,q=A(re),Y=q===`Quota tracking is not supported for this provider`?null:q,Q=F(e.credentialHint,e.name),$=e.health?.status??`unknown`;return(0,Z.jsxs)(te,{className:`flex h-full flex-col overflow-hidden`,"aria-busy":D,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-5 px-7 py-4`,children:[(0,Z.jsx)(T,{icon:e.providerIcon,name:e.providerName,size:32}),(0,Z.jsxs)(`div`,{className:`flex-[1_1_160px]`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 items-center gap-4`,children:[(0,Z.jsx)(`div`,{className:`truncate text-caption font-bold text-text-primary text-body`,children:e.providerName}),h?.plan&&(0,Z.jsx)(`span`,{className:`shrink-0 rounded-chip bg-accent-soft px-4 py-1 text-micro font-semibold text-accent`,children:h.plan})]}),(0,Z.jsx)(`div`,{className:`truncate text-badge text-text-secondary`,children:Q.primary}),Q.secondary!==null&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:Q.secondary}),h&&(0,Z.jsx)(`div`,{className:`truncate text-micro text-text-tertiary`,children:j(h.lastSuccessAt??h.fetchedAt)}),p&&(0,Z.jsx)(`div`,{className:`truncate text-micro flex items-center gap-2 text-text-tertiary`,title:`Saved rate-limit reset credits available on this account`,children:m.isPending?`Checking saved resets…`:O>0?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(y,{size:10,className:`text-status-success shrink-0`,"aria-hidden":`true`}),(0,Z.jsxs)(`span`,{className:`reset-credit-live`,children:[O,` rate-limit reset`,O===1?``:`s`,` available`]})]}):`No rate-limit resets available`}),f&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{title:`Daily growth state: manual pass result, else the sweep ledger for today`,className:`truncate text-micro text-text-tertiary`,children:d.isPending?`Running growth pass…`:U}),S.some(e=>typeof e.limit==`number`&&Number.isFinite(e.limit))&&(0,Z.jsxs)(`div`,{className:`truncate text-micro text-text-tertiary`,children:[`Total credits: `,W.toLocaleString(void 0,{maximumFractionDigits:2})]})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.75 gap-3 ml-auto`,children:[p&&(0,Z.jsx)(o,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:m.isPending?`Checking saved rate-limit resets…`:O>0?`Saved rate-limit resets (${O} available)`:`Saved rate-limit resets`,"aria-label":`Open saved rate-limit resets for ${e.name}`,disabled:D,onClick:()=>a(e),children:(0,Z.jsx)(y,{size:14})}),f&&(0,Z.jsx)(o,{variant:`ghost`,size:`icon`,className:`w-16 h-16 p-0`,title:`Daily growth pass (check-in + activity report) — ${U}`,"aria-label":`Run daily growth pass for ${e.name}`,disabled:D,onClick:()=>d.mutate(void 0,{onSuccess:e=>{let t=e.checkin.data;t&&I({state:t.state,credit:t.credit,streakDays:t.streakDays}),e.report.ok&&z(!0),e.ok?s.success(e.message):s.error(e.message)},onError:e=>{s.error(b(e,`Unable to run daily growth pass`))}}),children:d.isPending?(0,Z.jsx)(l,{size:14,className:`animate-spin`}):(0,Z.jsx)(J,{size:14})}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,title:$===`active`?`Health & Error Log`:`${$} — Inspect account health details`,"aria-label":$===`active`?`Health log for ${e.name}`:`Account is ${$} — inspect health details for ${e.name}`,disabled:D,onClick:()=>r(e),icon:(0,Z.jsx)(i,{size:12})}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,title:`Refresh quota`,"aria-label":`Refresh ${e.name} quota`,disabled:D,onClick:()=>u.mutate(),icon:u.isPending?(0,Z.jsx)(l,{size:12,className:`animate-spin`}):(0,Z.jsx)(_,{size:12})}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,title:`Delete account`,"aria-label":`Delete ${e.name}`,onClick:()=>n(e),className:`text-red`,icon:(0,Z.jsx)(v,{size:12})}),(0,Z.jsx)(E,{checked:e.active,disabled:u.isPending,onChange:n=>t(e,n),label:``,id:`switch-${e.id}`})]})]}),Y&&(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-4 border-t border-inner-border px-8 py-5 text-center text-badge text-red`,role:`alert`,children:[(0,Z.jsx)(c,{size:13,className:`shrink-0`}),(0,Z.jsx)(`span`,{children:Y})]}),h?.windows.length?(0,Z.jsxs)(`div`,{className:`quota-window-list flex flex-1 flex-col gap-4 border-t border-inner-border px-7 py-4.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-section-label text-micro font-bold tracking-label text-text-tertiary`,children:`QUOTA WINDOWS`}),C.items.map((e,t)=>{let n=e.remainingPercent??null,r=typeof e.limit==`number`&&Number.isFinite(e.limit)?e.limit:null,i=typeof e.used==`number`&&Number.isFinite(e.used)?e.used:r!==null&&e.usedPercent!==null&&e.usedPercent!==void 0?r*e.usedPercent/100:null,a=P(n),o=n===null?0:Math.max(0,Math.min(100,n)),s=e=>e.toLocaleString(void 0,{maximumFractionDigits:2}),c=e=>{let t=Math.round(e*10)/10;return t>0&&t<.1?`<0.1`:t.toLocaleString(void 0,{maximumFractionDigits:1})},l=N(e.label);return(0,Z.jsxs)(`div`,{className:`quota-window-row grid grid-cols-quota-window min-w-0 items-center gap-x-6 gap-y-2 max-small:grid-cols-[minmax(0,1fr)_auto] max-small:gap-x-4 max-small:gap-y-2.5`,children:[(0,Z.jsx)(`div`,{className:`quota-window-heading min-w-0 max-small:col-start-1`,children:(0,Z.jsx)(`span`,{className:`text-badge font-semibold text-text-primary`,children:l})}),(0,Z.jsx)(`div`,{className:`quota-bar-track quota-window-bar min-w-0 w-full h-5 rounded-tiny bg-inner-border overflow-hidden max-small:col-span-full max-small:row-start-2`,role:`progressbar`,"aria-label":`${l} remaining quota`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":n===null?void 0:o,"aria-valuetext":n===null?`Quota only`:`${c(n)}% remaining`,children:(0,Z.jsx)(`div`,{className:`quota-bar-fill h-full rounded-tiny transition-[width] duration-(--dur-macro) ease-spring`,style:{width:`${o}%`,background:a.bar}})}),(0,Z.jsx)(`span`,{className:`quota-window-remaining whitespace-nowrap text-badge font-bold tabular-nums max-small:col-start-2 max-small:row-start-1`,style:{color:a.text},children:n===null?`—`:`${c(n)}%`}),(0,Z.jsxs)(`div`,{className:`quota-window-details col-span-full flex min-w-0 items-center justify-end gap-6 text-micro text-text-tertiary max-small:row-start-3 max-small:flex-wrap max-small:justify-between max-small:gap-4`,children:[(0,Z.jsx)(`span`,{className:`quota-window-usage mr-auto tabular-nums max-small:min-w-0`,children:i!==null&&r!==null?`${s(i)} / ${s(r)} Credits`:`Quota only`}),e.resetsAt&&(0,Z.jsx)(`span`,{className:`quota-window-reset whitespace-nowrap tabular-nums text-right max-small:ml-auto`,children:ne(e.resetsAt,e.recurring)})]})]},`${e.kind??e.label}:${e.resetsAt??`none`}:${t}`)}),C.pageCount>1&&(0,Z.jsxs)(`nav`,{"aria-label":`Quota windows for ${e.name}`,className:`quota-window-pagination mt-auto flex items-center justify-between gap-4 border-t border-inner-border pt-4 max-small:flex-wrap`,children:[(0,Z.jsxs)(`span`,{"aria-live":`polite`,className:`text-micro text-text-tertiary`,children:[`Showing `,C.startIndex+1,`–`,C.startIndex+C.items.length,` of `,S.length]}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,"aria-label":`Previous quota windows for ${e.name}`,disabled:C.page===0,icon:(0,Z.jsx)(ie,{size:13}),onClick:()=>x(C.page-1),className:`h-14 px-4 py-0`,children:`Previous`}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,"aria-label":`Next quota windows for ${e.name}`,disabled:C.page>=C.pageCount-1,icon:(0,Z.jsx)(ee,{size:13}),onClick:()=>x(C.page+1),className:`h-14 px-4 py-0`,children:`Next`})]})]})]}):Y?null:(0,Z.jsx)(`div`,{className:`border-t border-inner-border px-7 py-9 text-center text-badge text-text-tertiary`,children:D||e.pending?`Fetching quota…`:`No quota data`})]})}function ce(){let[e,t]=(0,X.useState)(`all`),[n,r]=(0,X.useState)(`all`),[i,c]=(0,X.useState)(!1),{data:l,isLoading:ee,isError:f,error:p,isFetching:h,dataUpdatedAt:_,refetch:v}=U(),y=(0,X.useMemo)(()=>[...l?.providers??[]].sort((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:`base`})),[l?.providers]),b=(0,X.useMemo)(()=>l?.accounts??[],[l?.accounts]),C=l?.refreshing??0,T=L(),[E,O]=(0,X.useState)(null),k=W(),A=V(),ne=I(),[j,M]=(0,X.useState)(null);(0,X.useEffect)(()=>{T.isPending||O(null)},[T.isPending]);let[N,P]=(0,X.useState)(null),[F,R]=(0,X.useState)(null),z=(0,X.useMemo)(()=>{let t=b.filter(t=>{if(e!==`all`&&t.provider!==e)return!1;let r=!!t.quota?.windows.length;return n===`untracked`?!r:!(!r||n===`active`&&!t.active||n===`disabled`&&t.active)}),r=(e,t)=>e.providerName.localeCompare(t.providerName,void 0,{sensitivity:`base`})||e.name.localeCompare(t.name,void 0,{sensitivity:`base`});return[...t].sort(i?(e,t)=>$(e)-$(t)||r(e,t):r)},[n,b,i,e]),B=async(e,t)=>{try{await k.mutateAsync({id:e.id,active:t}),s.success(`${e.name} ${t?`enabled`:`disabled`}`)}catch(e){s.error(e instanceof Error?e.message:`Unable to update account`)}},H=async()=>{let e=b.filter(e=>e.active&&Q(e));await A.mutateAsync({ids:e.map(e=>e.id),active:!1}),s.success(`Disabled ${e.length} empty accounts`)},G=async()=>{let e=b.filter(e=>!e.active&&e.quota?.windows.some(e=>e.remainingPercent!==null&&e.remainingPercent>0));await A.mutateAsync({ids:e.map(e=>e.id),active:!0}),s.success(`Enabled ${e.length} available accounts`)},K=async e=>{await ne.mutateAsync(e.id),s.success(`${e.name} deleted`)},q=_>0?new Date(_).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):`Not updated`,J=b.filter(Q).length;return(0,Z.jsxs)(D,{gap:`16px`,className:`dashboard-page min-h-0 flex-1`,children:[(0,Z.jsx)(te,{children:(0,Z.jsxs)(S,{className:`flex flex-col gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-5`,children:[(0,Z.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-4`,children:[(0,Z.jsx)(w,{"aria-label":`Filter quota by provider`,value:e,onValueChange:t,className:`w-full h-16 max-small:w-80`,options:[{value:`all`,label:`All Providers`},...y.map(e=>({value:e.id,label:e.name}))]}),(0,Z.jsx)(w,{"aria-label":`Filter quota by account`,value:n,onValueChange:r,className:`w-full h-16 max-small:w-67.5`,options:[{value:`all`,label:`With quota`},{value:`active`,label:`Active`},{value:`disabled`,label:`Disabled`},{value:`untracked`,label:`No quota`}]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4`,children:[(0,Z.jsx)(o,{variant:i?`secondary`:`ghost`,size:`sm`,onClick:()=>c(e=>!e),"aria-pressed":i,icon:(0,Z.jsx)(Y,{size:13}),children:`Expiring first`}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,className:`text-red`,disabled:J===0||h,onClick:()=>void H(),icon:(0,Z.jsx)(u,{size:13}),children:`Turn off Empty`}),(0,Z.jsx)(o,{variant:`ghost`,size:`sm`,className:`text-green`,disabled:h,onClick:()=>void G(),icon:(0,Z.jsx)(a,{size:13}),children:`Turn on Available`})]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4 border-t border-inner-border pt-5`,children:[(0,Z.jsxs)(`span`,{className:`text-badge text-text-tertiary`,children:[z.length,` shown`,J>0?` · ${J} empty`:``]}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-5 gap-y-3 text-badge text-text-tertiary`,children:[C>0?`Refreshing ${C} account${C===1?``:`s`}…`:`Auto-refresh 60s · ${q}`,(0,Z.jsx)(oe,{accounts:b}),(0,Z.jsx)(o,{variant:`secondary`,size:`sm`,title:`Queue quota refresh`,"aria-label":`Queue quota refresh`,disabled:h||T.isPending||b.length===0,icon:(0,Z.jsx)(g,{size:13,className:T.isPending?`animate-spin`:void 0}),onClick:()=>T.mutate({accountIds:b.map(e=>e.id),onProgress:(e,t)=>O({done:e,total:t})},{onSuccess:e=>{s.success(e.failed===0?`Refreshed ${e.succeeded} quota${e.succeeded===1?``:`s`}`:`Refreshed ${e.succeeded}, ${e.failed} failed`)},onError:e=>s.error(e instanceof Error?e.message:`Unable to refresh quota`)}),children:E&&E.total>0?`Refresh ${E.done}/${E.total}`:`Refresh`})]})]})]})}),(0,Z.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6`,children:ee?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`loading`,title:`Loading quota data`,description:`Reading provider account limits…`}):f?(0,Z.jsx)(d,{className:`min-h-0 flex flex-1 flex-col items-center justify-center`,kind:`error`,title:`Unable to load quota data`,description:p instanceof Error?p.message:`Check the console session and retry.`,action:(0,Z.jsx)(o,{variant:`secondary`,onClick:()=>void v(),children:`Retry`})}):z.length===0?(0,Z.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-12 border border-dashed border-transparent rounded-card bg-transparent text-center`,children:(0,Z.jsx)(m,{title:`No account quota data`,message:`Nothing is reporting a quota window yet. Add a provider account and its limits will appear here.`})}):(0,Z.jsx)(`div`,{className:`quota-account-grid scroll-region min-h-0 flex-1 gap-6 [align-content:start]`,children:z.map(e=>(0,Z.jsx)(se,{account:e,onToggle:(e,t)=>void B(e,t),onDelete:e=>M(e),onShowHealth:e=>P(e),onShowResets:e=>R(e)},e.id))})}),N&&(0,Z.jsx)(re,{summary:{providerId:N.provider,accountId:N.id,title:N.name,status:N.health?.status??`unknown`,errorCategory:N.health?.lastErrorCategory??void 0,errorMessage:N.health?.sanitizedMessage??void 0,emptyMessage:`Status transitions, rate limits, quota refreshes, check-ins, and auto-recoveries will appear here.`},onClose:()=>P(null)}),F&&(0,Z.jsx)(ae,{account:F,onClose:()=>R(null)}),(0,Z.jsx)(x,{open:j!==null,onClose:()=>M(null),onConfirm:async()=>{j&&await K(j)},title:`Delete account?`,message:`Delete "${j?.name}"? This cannot be undone.`,confirmLabel:`Delete`,danger:!0})]})}export{ce as default};
@@ -1 +1 @@
1
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i,r as a}from"./terminal-0_IjPWTk.js";import{T as o,c as s,i as c,s as l,t as u}from"./numbers-Dulqgys5.js";import{t as d}from"./database-Dz9N3zGd.js";import{t as f}from"./eye-C_hawfH4.js";import{n as p,r as m}from"./state-DhZBfWgx.js";import{t as h}from"./layers-2-glBbjl.js";import{t as ee}from"./dialog-Iec_ywbD.js";import{n as g,r as te,t as _}from"./settings--3hxSyry.js";import{t as v}from"./trash-Cppn5c3R.js";import{t as y}from"./zap-C4EeVW4q.js";import{C as b,T as x,v as S}from"./assert-DU6qrMA_.js";import{a as C,i as w,l as T,o as E,s as D,t as O}from"./query-keys-UETqfytp.js";import{t as k}from"./useMutation-EDFRkn1i.js";import{it as A}from"./entry-BcfdW4C_.js";import{n as j,r as M,t as N}from"./card-BOPBuBzD.js";import{n as ne,t as re}from"./download-dRFo5_Wu.js";import{n as P}from"./input-WlyHWeG2.js";import{t as F}from"./select-BTEzH1iH.js";import{t as ie}from"./switch-yD7D99Lg.js";import{t as I}from"./stack-B1w5BM0u.js";import{t as L}from"./banner-C-7y3VKV.js";import{t as ae}from"./backup-file-gdKIlg8U.js";var oe=e(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),se=e(`file-braces`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]]),ce=e(`file-clock`,[[`path`,{d:`M16 22h2a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v2.85`,key:`ryk6xj`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M8 14v2.2l1.6 1`,key:`6m4bie`}],[`circle`,{cx:`8`,cy:`16`,r:`6`,key:`10v15b`}]]),R=e(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),z=e(`hard-drive`,[[`path`,{d:`M10 16h.01`,key:`1bzywj`}],[`path`,{d:`M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`18tbho`}],[`path`,{d:`M21.946 12.013H2.054`,key:`zqlbp7`}],[`path`,{d:`M6 16h.01`,key:`1pmjb7`}]]),le=e(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),B=t(n(),1);function ue(){return k({mutationFn:async({password:e,sections:t,compressed:n,onProgress:r})=>{let i=new URLSearchParams({password:e});t!==void 0&&t.length>0&&i.set(`sections`,t),n===!0&&i.set(`compressed`,`1`);let a=`/backup/export?${i.toString()}`;if(n!==!0)return E(a);let o=await E(a),s=atob(o.bytes),c=Uint8Array.from(s,e=>e.charCodeAt(0));return r?.({loaded:c.byteLength,total:c.byteLength}),c}})}function de(){let e=x();return k({mutationFn:({password:e,scopes:t})=>E(`/backup/delete-all`,{method:`POST`,body:JSON.stringify({password:e,scopes:t})}),onSuccess:async()=>{await e.invalidateQueries()}})}function fe(){let e=x();return k({mutationFn:({password:e,backup:t,tables:n,onProgress:r})=>D(`/backup/import`,JSON.stringify({password:e,backup:t,...n===void 0||n.length===0?{}:{tables:[...n]}}),r),onSuccess:async()=>{await e.invalidateQueries()}})}function pe(){return k({mutationFn:({backup:e})=>E(`/backup/inspect`,{method:`POST`,body:JSON.stringify({backup:e})})})}var V=r();function me({title:e,description:t}){return(0,V.jsxs)(`div`,{className:`mb-6 min-w-0`,children:[(0,V.jsx)(`h3`,{className:`text-body-lg font-bold text-text-primary`,children:e}),(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-secondary`,children:t})]})}function H({icon:e,label:t,description:n,checked:r,onChange:i}){return(0,V.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:r,onChange:i}),(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(e,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,V.jsx)(`strong`,{children:t}),(0,V.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:n})]})]})}function he(e){return e===`providers`?A:e===`proxies`?a:h}function ge({report:e}){let t=Object.entries(e.imported).filter(([,e])=>e>0);return(0,V.jsxs)(I,{gap:`8px`,children:[t.length>0?(0,V.jsxs)(`p`,{className:`text-caption`,children:[`Imported:`,` `,t.map(([e,t])=>`${t} ${e}`).join(`, `)]}):null,e.remapped.length>0?(0,V.jsxs)(`p`,{className:`text-caption text-text-secondary`,children:[`Remapped provider ids: `,e.remapped.join(`, `)]}):null,e.skipped.length>0?(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`p`,{className:`text-caption text-yellow`,children:[`Skipped (`,e.skipped.length,`) — nothing was guessed:`]}),(0,V.jsx)(`ul`,{className:`text-caption text-text-tertiary mt-2 ml-8`,children:e.skipped.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}):null,e.warnings.length>0?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`Warnings:`}),(0,V.jsx)(`ul`,{className:`text-caption text-text-tertiary mt-2 ml-8`,children:e.warnings.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}):null]})}function _e({warnings:e}){return e.length===0?null:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,live:`status`,children:[(0,V.jsxs)(`strong`,{children:[`Restore completed with `,e.length,` warning`,e.length===1?``:`s`]}),(0,V.jsx)(`ul`,{className:`mt-2 ml-8`,children:e.map((e,t)=>(0,V.jsxs)(`li`,{children:[e.table?`${e.table}${e.column?`.${e.column}`:``}: `:``,e.reason]},`${e.table??`backup`}:${e.column??`general`}:${t}`))})]})}function U(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function ve(e,t){if(e===null)return t;let n=Math.max((Date.now()-e.startedAt)/1e3,.1),r=U(e.loaded/n);return`${e.total===null?U(e.loaded):`${U(e.loaded)} / ${U(e.total)}`} · ${r}/s`}function W(){let[e,t]=(0,B.useState)(``),[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(!0),[c,u]=(0,B.useState)(!1),[f,p]=(0,B.useState)(!0),[m,h]=(0,B.useState)(null),[g,te]=(0,B.useState)(null),[_,y]=(0,B.useState)(null),[b,x]=(0,B.useState)(null),[S,C]=(0,B.useState)(null),[w,E]=(0,B.useState)(null),[D,O]=(0,B.useState)(new Set),[k,A]=(0,B.useState)(null),[j,M]=(0,B.useState)(null),[N,F]=(0,B.useState)(new Set),[oe,se]=(0,B.useState)(null),R=(0,B.useRef)(null),z=ue(),U=fe(),W=de(),ye=pe(),be=e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},G=()=>{r(null),t(``)},xe=()=>{D.size!==0&&(t(``),r(`delete`))},Se=async()=>{if(e.length===0)return;let t=await W.mutateAsync({password:e,scopes:[...D]});O(new Set),G(),l.success(`Selected configuration deleted.`,Object.entries(t.deleted).map(([e,t])=>`${e}: ${t}`).join(` · `))},K=()=>{let t=[...i?[`config`]:[],...c?[`telemetry`]:[]].join(`,`);if(t.length===0){l.error(`Select at least one backup section.`);return}z.mutate({password:e,sections:t,compressed:f,onProgress:e=>h(t=>({...e,startedAt:t?.startedAt??Date.now()}))},{onSuccess:e=>{let t=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`);e instanceof Uint8Array?re(`cartethyia_backup_${t}.json.gz`,e,`application/gzip`):ne(`cartethyia_backup_${t}.json`,JSON.stringify(e,null,2),`application/json`),G(),l.success(`Backup downloaded.`)},onError:e=>l.error(T(e,`Backup export failed.`))})},q=async e=>{te(null),y(null),x(null),C(null),E(null),se(null),M(null),F(new Set),A(e);try{let t=await ae(e),n=await ye.mutateAsync({backup:t});M(n),F(new Set(n.rows.filter(e=>e.supported).map(e=>e.table)))}catch(e){A(null),l.error(`Could not read that backup`,T(e,`The file is not a readable backup.`))}},Ce=e=>{F(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},J=()=>{M(null),A(null),se(null)},we=()=>{k!==null&&N.size!==0&&(t(``),x(null),r(`restore`))},Te=async()=>{let t=k;if(t!==null){x(null);try{let n=await ae(t),r=await U.mutateAsync({password:e,backup:n,tables:[...N],onProgress:e=>h(t=>({...e,startedAt:t?.startedAt??Date.now()}))});te(r.restored),y(r.warnings),C(r.report??null),E(r.format),G(),A(null),M(null),l.success(r.warnings.length===0?`Restore complete.`:`Restore completed with warnings.`,r.warnings.length===0?null:`${r.warnings.length} item(s) need attention. See the restore report below.`)}catch(e){let t=T(e,`Backup restore failed.`);x(t),l.error(`Backup restore failed`,t)}}},Ee=g===null?[]:Object.entries(g);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-8 w-full min-w-0 max-medium:grid-cols-1`,children:[(0,V.jsxs)(`section`,{"aria-label":`Backup`,className:`min-w-0`,children:[(0,V.jsx)(me,{title:`Export and restore`,description:`Download a JSON snapshot, or restore one you already trust.`}),(0,V.jsxs)(I,{gap:`14px`,children:[(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-2 gap-5 min-w-0 border-0 m-0 p-0 max-medium:grid-cols-1`,children:[(0,V.jsx)(`legend`,{className:`mb-4 text-text-secondary text-caption font-semibold`,children:`Include in the download`}),(0,V.jsx)(H,{icon:d,label:`Account, proxy & settings`,description:`Credentials, API-key hashes, routing, and settings`,checked:i,onChange:()=>a(!i)}),(0,V.jsx)(H,{icon:ce,label:`Telemetry history`,description:`Status, tokens, cost, latency — never prompt bodies`,checked:c,onChange:()=>u(!c)})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border px-6 py-5`,children:[(0,V.jsxs)(`span`,{children:[(0,V.jsx)(`strong`,{className:`block text-body`,children:`Highly Compress Backup`}),(0,V.jsx)(`small`,{className:`text-caption text-text-tertiary`,children:`Makes the download smaller.`})]}),(0,V.jsx)(ie,{checked:f,onChange:p,"aria-label":`Highly Compress Backup`})]}),(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:`The file contains provider credentials. Treat it like the database. Prompt and response bodies, health-event history, and console sessions are left out.`}),(0,V.jsxs)(`div`,{className:`mt-auto flex justify-end gap-4`,children:[(0,V.jsx)(s,{variant:`primary`,size:`sm`,onClick:()=>{t(``),r(`download`)},disabled:!i&&!c,icon:(0,V.jsx)(o,{size:13}),children:`Download backup`}),(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:()=>R.current?.click(),icon:(0,V.jsx)(le,{size:13}),children:`Restore from file`}),(0,V.jsx)(`input`,{ref:R,type:`file`,accept:`application/json,.json,.gz,application/gzip`,className:`sr-only`,onChange:e=>{let t=e.target.files?.[0];t&&q(t),e.target.value=``}})]}),w===null?null:(0,V.jsxs)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:[`Detected format:`,` `,w===`nine_router`?`router export`:`Cartethyia backup`]}),g===null?null:(0,V.jsxs)(L,{tone:`success`,surface:`raised`,live:`status`,children:[(0,V.jsx)(`strong`,{children:`Restore complete`}),Ee.length>0?(0,V.jsx)(`ul`,{children:Ee.map(([e,t])=>(0,V.jsxs)(`li`,{children:[e,`: `,t]},e))}):(0,V.jsx)(`p`,{children:`No rows were imported.`})]}),_===null?null:(0,V.jsx)(_e,{warnings:_}),S===null?null:(0,V.jsx)(ge,{report:S})]})]}),(0,V.jsxs)(`section`,{"aria-label":`Delete data`,className:`min-w-0`,children:[(0,V.jsx)(me,{title:`Delete data`,description:`Removes the scopes you check. Console users, sessions, and audit history stay.`}),(0,V.jsxs)(I,{gap:`12px`,children:[(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-5 min-w-0 border-0 m-0 p-0`,children:[(0,V.jsx)(`legend`,{className:`mb-4 text-text-secondary text-caption font-semibold`,children:`Delete`}),[[`providers`,`Providers`,`Accounts, credentials, tenant models, routing, and account health`],[`proxies`,`Proxies`,`Network pools, pool settings, and pool health`],[`configuration`,`All configuration`,`Providers, proxies, aliases, combos, API keys, CLI tools, and settings`]].map(([e,t,n])=>(0,V.jsx)(H,{icon:he(e),label:t,description:n,checked:D.has(e),onChange:()=>be(e)},e))]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end gap-4 flex-wrap`,children:(0,V.jsx)(s,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),disabled:D.size===0,onClick:xe,children:`Delete selected`})})]})]})]}),(0,V.jsx)(ee,{open:j!==null,onClose:J,title:`Restore from backup`,description:`Choose which parts of this file to restore, then confirm with your console password.`,size:`md`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:J,children:`Cancel`}),(0,V.jsx)(s,{variant:`primary`,size:`sm`,disabled:N.size===0,onClick:we,children:`Restore now`})]}),children:(0,V.jsx)(I,{gap:`12px`,children:j===null?null:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`text-caption text-text-tertiary`,children:j.format===`nine_router`?`Router export — it is converted at restore time, so every table it produces is restored.`:`${j.total} rows · exported ${j.exportedAt||`unknown date`}`}),j.rows.length>0?(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-4 min-w-0 border-0 m-0 p-0`,children:[(0,V.jsx)(`legend`,{className:`mb-3 text-text-secondary text-caption font-semibold`,children:`Restore these tables`}),(0,V.jsxs)(`div`,{className:`flex justify-end gap-4`,children:[(0,V.jsx)(`button`,{type:`button`,className:`text-badge text-accent hover:underline`,onClick:()=>F(new Set(j.rows.filter(e=>e.supported).map(e=>e.table))),children:`Select all`}),(0,V.jsx)(`button`,{type:`button`,className:`text-badge text-text-secondary hover:underline`,onClick:()=>F(new Set),children:`Select none`})]}),j.rows.map(e=>(0,V.jsxs)(`label`,{className:`flex items-start gap-4 px-5 py-4 border border-inner-border rounded-control bg-surface-2 text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:N.has(e.table),disabled:!e.supported,onChange:()=>Ce(e.table)}),(0,V.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,V.jsx)(`strong`,{className:`text-text-primary`,children:e.table}),(0,V.jsxs)(`small`,{className:`text-text-tertiary text-badge`,children:[e.count,` rows · `,e.section,e.supported?``:` · not in the current schema, will be skipped`]})]})]},`${e.section}:${e.table}`))]}):null,oe===null?null:(0,V.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:oe})]})})}),(0,V.jsx)(ee,{open:n!==null,onClose:G,title:n===`delete`?`Confirm deletion`:n===`restore`?`Restore backup`:`Download backup`,description:`The console password is checked again before this runs.`,size:`sm`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:G,children:`Cancel`}),(0,V.jsx)(s,{variant:n===`delete`?`danger`:`primary`,size:`sm`,loading:z.isPending||U.isPending||W.isPending,disabled:e.length===0||z.isPending||U.isPending||W.isPending,onClick:()=>{h(null),n===`download`?K():n===`restore`?Te():Se()},children:z.isPending?ve(m,`Downloading…`):U.isPending?ve(m,`Uploading…`):W.isPending?`Working…`:n===`delete`?`Delete permanently`:n===`restore`?`Restore`:`Download`})]}),children:(0,V.jsxs)(I,{gap:`10px`,children:[n===`restore`&&b!==null?(0,V.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:b}):null,(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:n===`delete`?`This cannot be undone. The password is verified again before anything is removed.`:n===`restore`?`Restore replaces the tenant configuration in this file. Continue only if the file is trusted.`:`The export is plain JSON and contains provider credentials.`}),(0,V.jsx)(P,{label:`Console password`,type:`password`,value:e,onChange:e=>t(e.target.value),autoComplete:`current-password`,"data-autofocus":!0})]})})]})}function ye(){return b({queryKey:O.settings.diskUsage,queryFn:e=>E(`/data-management/usage`,{signal:S(e)}),...w,staleTime:C.status})}function be(){let e=x();return k({mutationFn:e=>E(`/data-management/reclaim`,{method:`POST`,body:JSON.stringify({action:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:O.settings.diskUsage})}})}function G(){return k({mutationFn:()=>E(`/data-management/flush`,{method:`POST`})})}function xe(){let e=x();return k({mutationFn:()=>E(`/data-management/purge`,{method:`POST`,body:JSON.stringify({target:`health_events`})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:O.settings.diskUsage})}})}function Se(){let e=ye(),t=be(),n=G(),r=xe(),[a,o]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1);if(e.isPending)return(0,V.jsx)(m,{label:`Measuring disk usage…`});if(e.isError||!e.data)return(0,V.jsx)(p,{message:T(e.error,`Failed to measure disk usage`),onRetry:()=>void e.refetch()});let h=e.data,ee=e=>{e!==null&&(o(null),t.mutate(e,{onSuccess:e=>{if(e.deletedFiles===0){l.success(`Nothing to reclaim.`);return}l.success(`Reclaimed ${u(e.reclaimedBytes)} across ${c(e.deletedFiles)} file${e.deletedFiles===1?``:`s`}.`)},onError:e=>l.error(T(e,`Reclaim failed.`))}))},g=h.healthEventCount;return(0,V.jsxs)(I,{gap:`14px`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-4 flex-wrap`,children:[(0,V.jsxs)(`span`,{className:`text-caption text-text-tertiary`,children:[u(h.totalBytes),` on disk across`,` `,c(h.buckets.reduce((e,t)=>e+t.files,0)),` files`]}),(0,V.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(z,{size:14}),onClick:()=>void e.refetch(),disabled:e.isFetching,children:e.isFetching?`Measuring…`:`Refresh`})]}),(0,V.jsxs)(`div`,{className:`settings-bucket-grid`,children:[h.buckets.map(e=>{let n=q(e);return(0,V.jsx)(J,{bucket:e,busy:t.isPending,confirming:n!==null&&a===n,onAsk:()=>o(n),onCancel:()=>o(null),onConfirm:()=>ee(n)},e.id)}),(0,V.jsx)(K,{icon:i,title:`Health & Error Log`,note:g===void 0?`Purging is not offered in this deployment's console composition.`:`${c(g)} recorded transition${g===1?``:`s`} across accounts and pools. Purge clears only this audit trail — account statuses and cooldowns stay as they are, and this cannot be undone.`,testId:`health_events`,children:g===void 0?null:d?(0,V.jsx)(`span`,{className:`flex flex-col gap-3`,children:(0,V.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:()=>f(!1),disabled:r.isPending,children:`Cancel`}),(0,V.jsx)(s,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),disabled:r.isPending,onClick:()=>r.mutate(void 0,{onSuccess:e=>{f(!1),l.success(e.deleted===0?`Health & error log was already empty.`:`Purged ${c(e.deleted)} health event${e.deleted===1?``:`s`}.`)},onError:e=>l.error(T(e,`Purge failed.`))}),children:`Delete`})]})}):(0,V.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),disabled:r.isPending||g===0,onClick:()=>f(!0),children:`Purge`})}),(0,V.jsx)(K,{icon:R,title:`Flush pending writes`,note:`Write queued telemetry, usage, and health events now instead of waiting for the interval. Nothing is deleted.`,testId:`flush`,children:(0,V.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(y,{size:14}),disabled:n.isPending,onClick:()=>n.mutate(void 0,{onSuccess:()=>l.success(`Buffers flushed.`),onError:e=>l.error(T(e,`Flush failed.`))}),children:n.isPending?`Flushing…`:`Flush`})})]}),t.isError?(0,V.jsx)(L,{tone:`danger`,surface:`raised`,live:`status`,children:T(t.error,`Reclaim failed.`)}):null]})}function K({icon:e,title:t,note:n,children:r,testId:i}){return(0,V.jsxs)(`div`,{"data-panel":i,className:`flex flex-col rounded-control border border-inner-border px-6 py-5 min-w-0`,children:[(0,V.jsxs)(`span`,{className:`flex items-start gap-4`,children:[(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(e,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block text-caption text-text-tertiary`,children:t}),(0,V.jsx)(`span`,{className:`mt-1 block text-caption text-text-tertiary`,children:n})]})]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end pt-5`,children:r})]})}function q(e){return e.id===`payload_frames`?`payload_frames`:e.id===`telemetry_events`?`telemetry_retention`:null}function Ce(e){return e.id===`payload_frames`?se:ce}function J({bucket:e,busy:t,confirming:n,onAsk:r,onCancel:i,onConfirm:a}){let o=q(e),l=e.reclaimableBytes!==null,d=e.reclaimableBytes??0,f=e.reclaimableFiles??0,p=l&&d===0,m=Ce(e);return(0,V.jsxs)(`div`,{"data-bucket":e.id,className:`flex flex-col rounded-control border border-inner-border px-6 py-5 min-w-0`,children:[(0,V.jsxs)(`span`,{className:`flex items-start gap-4`,children:[(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(m,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block text-caption text-text-tertiary`,children:e.label}),(0,V.jsx)(`span`,{className:`mt-1 block text-lead font-semibold text-text-primary`,children:u(e.bytes)}),(0,V.jsxs)(`span`,{className:`block text-caption text-text-tertiary`,children:[c(e.files),` file`,e.files===1?``:`s`,` · `,e.note]})]})]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end pt-5`,children:o===null?(0,V.jsx)(`p`,{className:`text-caption text-text-tertiary`,children:`Kept — no other copy.`}):n?(0,V.jsxs)(`span`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`span`,{className:`text-caption text-text-secondary`,children:l?`Delete ${c(f)} file${f===1?``:`s`}, ${u(d)}?`:`Delete raw event files past the retention window?`}),(0,V.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:i,disabled:t,children:`Cancel`}),(0,V.jsx)(s,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),onClick:a,disabled:t,children:`Delete`})]})]}):(0,V.jsxs)(`span`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,V.jsx)(`span`,{className:`text-caption text-text-tertiary`,children:l?p?`Clean`:`${u(d)} free`:`Expired events only`}),(0,V.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),onClick:r,disabled:t||p,children:`Reclaim`})]})})]})}function we(){return k({mutationFn:e=>E(`/auth/change-password`,{method:`POST`,body:JSON.stringify(e)})})}var Te=[5,15,30,60,120,300,600],Ee=[5,15,30,60,180,720,1440],De=[1,5,10,25,50,100];function Oe({name:e}){let t={size:16};return e===`privacy`?(0,V.jsx)(f,{...t}):e===`operations`?(0,V.jsx)(y,{...t}):e===`data`?(0,V.jsx)(oe,{...t}):e===`data-management`?(0,V.jsx)(d,{...t}):(0,V.jsx)(te,{...t})}function Y(e,t,n){return(t===null||e.includes(t)?[...e]:[...e,t].sort((e,t)=>e-t)).map(e=>({value:String(e),label:n(e)}))}var ke=[{id:`security`,title:`Security`,description:`Change the password used to sign in to this console.`},{id:`privacy`,title:`Privacy`,description:`What request telemetry stores, and how client addresses are shown.`},{id:`backup`,title:`Backup`,description:`Export or restore this tenant's configuration and history.`},{id:`operations`,title:`Operations`,description:`Routing, admission, request handling, and response shaping for this tenant.`},{id:`data-management`,title:`Data Management`,description:`See what the gateway keeps on disk, reclaim space, and flush queued writes.`}];function X(e){if(e%1440==0){let t=e/1440;return`${t} day${t===1?``:`s`}`}if(e%60==0){let t=e/60;return`${t} hour${t===1?``:`s`}`}return`${e} min`}function Z(e){return`Deployment default (${e})`}function Ae(e){return`${Math.round(e/1048576)} MB`}function Q({label:e,hint:t,labelFor:n,control:r}){return(0,V.jsxs)(`div`,{className:`settings-row`,children:[(0,V.jsxs)(`div`,{className:`settings-row-text`,children:[n?(0,V.jsx)(`label`,{className:`settings-row-label`,htmlFor:n,children:e}):(0,V.jsx)(`span`,{className:`settings-row-label`,children:e}),t?(0,V.jsx)(`p`,{className:`settings-row-hint`,children:t}):null]}),(0,V.jsx)(`div`,{className:`settings-row-control`,children:r})]})}function $({title:e}){return(0,V.jsx)(`p`,{className:`settings-group-head`,children:e})}function je({id:e,title:t,description:n,children:r}){return(0,V.jsxs)(N,{id:e,"aria-label":t,className:`min-w-0`,children:[(0,V.jsx)(M,{title:t,subtitle:n,icon:(0,V.jsx)(Oe,{name:e})}),(0,V.jsx)(j,{className:`flex flex-col gap-0`,children:r})]})}function Me(){let e=_(),t=g(),n=e.data;return e.isPending?(0,V.jsx)(m,{label:`Loading privacy settings…`}):e.isError||!n?(0,V.jsx)(p,{message:T(e.error,`Failed to load runtime settings`),onRetry:()=>void e.refetch()}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Telemetry payloads`,labelFor:`privacy-payloads`,hint:`Request metadata is always kept. Bodies stay off until you turn them on, and anything captured is redacted and deleted when the Request detail window in Operations runs out.`,control:(0,V.jsx)(F,{"aria-label":`Telemetry payloads`,id:`privacy-payloads`,value:n.telemetryPayloads,onValueChange:e=>t.mutate({telemetryPayloads:e===`full`||e===`metadata`?e:`none`},{onSuccess:()=>l.success(`Payload capture updated`),onError:e=>l.error(T(e,`Could not update payload capture.`))}),options:[{value:`none`,label:`Off — no payload capture`},{value:`metadata`,label:`Metadata — method and headers only`},{value:`full`,label:`Full — redacted bodies`}]})}),n.telemetryPayloads===`full`?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Capture depth`,labelFor:`privacy-payload-depth`,hint:`Size cap for each captured body.`,control:(0,V.jsx)(F,{"aria-label":`Capture depth`,id:`privacy-payload-depth`,value:n.telemetryPayloadDepth,onValueChange:e=>t.mutate({telemetryPayloadDepth:e===`moderate`||e===`maximum`?e:`minimum`},{onSuccess:()=>l.success(`Capture depth updated`),onError:e=>l.error(T(e,`Could not update capture depth.`))}),options:[{value:`minimum`,label:`Minimum — 1 MiB cap`},{value:`moderate`,label:`Moderate — 8 MiB cap`},{value:`maximum`,label:`Maximum — 16 MiB cap`}]})}),n.telemetryPayloadDepth===`minimum`?null:(0,V.jsx)(`div`,{className:`settings-row-banner`,children:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,className:`text-text-secondary`,children:[(0,V.jsx)(`strong`,{children:`High CPU and memory while this is on.`}),` Use it to debug, then switch back to Metadata or Minimum.`]})})]}):null,(0,V.jsx)(Q,{label:`Client IP display`,labelFor:`privacy-ip`,hint:`Raw addresses stay stored and are still written to telemetry. This only changes how they are shown in the console.`,control:(0,V.jsx)(F,{"aria-label":`Client IP display`,id:`privacy-ip`,value:n.privacyMode,onValueChange:e=>t.mutate({privacyMode:e===`full`?`full`:`masked`},{onSuccess:()=>l.success(`IP display updated`),onError:e=>l.error(T(e,`Could not update IP display.`))}),options:[{value:`masked`,label:`Masked — recommended`},{value:`full`,label:`Show full IP`}]})})]})}function Ne(){let e=_(),t=g(),n=e.data;if(e.isPending)return(0,V.jsx)(m,{label:`Loading operational settings…`});if(e.isError||!n)return(0,V.jsx)(p,{message:T(e.error,`Failed to load runtime settings`),onRetry:()=>void e.refetch()});let r=(e,n)=>{t.mutate(e,{onSuccess:()=>l.success(n),onError:e=>l.error(T(e,`Could not update settings.`))})};return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{title:`Routing`}),(0,V.jsx)(Q,{label:`Ignore cooldowns`,labelFor:`ignore-cooldowns`,hint:`Route to accounts that are cooling down, including ones already parked. Off by default: a cooling account stays out of the rotation until it resets. On dials it anyway, which is what the warning below is about.`,control:(0,V.jsx)(F,{"aria-label":`Ignore cooldowns`,id:`ignore-cooldowns`,value:n.forceDisableCooldown?`on`:`off`,onValueChange:e=>{let t=e===`on`;r({forceDisableCooldown:t},t?`Cooldowns are ignored.`:`Cooldowns are enforced again.`)},options:[{value:`off`,label:`Off — default`},{value:`on`,label:`On`}]})}),n.forceDisableCooldown?(0,V.jsx)(`div`,{className:`settings-row-banner`,children:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,live:`status`,children:[(0,V.jsx)(`strong`,{children:`This may cause admission failure.`}),` A cooled-down account was parked because the upstream refused it, so dialing it anyway reproduces that refusal on every attempt — and if every candidate is cooling, the request fails instead of waiting for a reset. The cooldown is still recorded and still recovered by the sweep, so turning this back off needs no cleanup. Per-model cooldowns are still enforced.`]})}):null,(0,V.jsx)($,{title:`Admission`}),(0,V.jsx)(Q,{label:`Tenant concurrency limit`,labelFor:`tenant-concurrency-limit`,hint:`Ceiling on requests in flight across every key in this tenant at once. Empty means no tenant-wide ceiling — each key is then bounded only by its own limit.`,control:(0,V.jsx)(P,{id:`tenant-concurrency-limit`,"aria-label":`Tenant concurrency limit`,type:`number`,min:`1`,step:`1`,inputMode:`numeric`,placeholder:`No ceiling`,value:n.tenantConcurrencyLimit?.toString()??``,onChange:e=>{let t=e.target.value.trim();if(t===``){r({tenantConcurrencyLimit:null},`Tenant ceiling removed.`);return}let n=Number(t);!Number.isInteger(n)||n<1||r({tenantConcurrencyLimit:n},`Tenant concurrency limit updated.`)}})}),(0,V.jsx)(Q,{label:`Concurrency tolerance`,labelFor:`concurrency-tolerance`,hint:`Slack added above a key's own concurrency limit. The effective ceiling is the key's limit plus this, so a run landing a few over is not refused at the number it was told.`,control:(0,V.jsx)(P,{id:`concurrency-tolerance`,"aria-label":`Concurrency tolerance`,type:`number`,min:`0`,max:`1024`,step:`1`,inputMode:`numeric`,placeholder:`None`,value:n.concurrencyTolerance?.toString()??``,onChange:e=>{let t=e.target.value.trim();if(t===``){r({concurrencyTolerance:null},`Tolerance removed.`);return}let n=Number(t);!Number.isInteger(n)||n<0||n>1024||r({concurrencyTolerance:n},`Concurrency tolerance updated.`)}})}),(0,V.jsx)($,{title:`Request handling`}),(0,V.jsx)(Q,{label:`Upstream timeout`,labelFor:`upstream-timeout`,hint:`5–600 seconds, ${n.defaults.upstreamTimeoutSeconds}s when unset. Applied when the request is dispatched, so it can only shorten a deadline that has already started.`,control:(0,V.jsx)(F,{"aria-label":`Upstream timeout`,id:`upstream-timeout`,value:n.upstreamTimeoutSeconds?.toString()??``,placeholder:Z(`${n.defaults.upstreamTimeoutSeconds} seconds`),onValueChange:e=>r({upstreamTimeoutSeconds:e===``?null:Number(e)},`Upstream timeout updated.`),options:[...Y(Te,n.upstreamTimeoutSeconds,e=>`${e} seconds`),{value:``,label:Z(`${n.defaults.upstreamTimeoutSeconds} seconds`)}]})}),(0,V.jsx)(Q,{label:`Request detail window`,labelFor:`telemetry-window-minutes`,hint:`1–1440 minutes, ${X(n.defaults.telemetryWindowMinutes)} when unset. Controls how long captured payload frames are kept — the same number Data Management reports as what payload frames expire after. Raw request events follow the ${n.defaults.telemetryRetentionDays}-day server retention instead.`,control:(0,V.jsx)(F,{"aria-label":`Request detail window`,id:`telemetry-window-minutes`,value:n.telemetryWindowMinutes?.toString()??``,placeholder:Z(X(n.defaults.telemetryWindowMinutes)),onValueChange:e=>r({telemetryWindowMinutes:e===``?null:Number(e)},`Detail window updated.`),options:[...Y(Ee,n.telemetryWindowMinutes,X),{value:``,label:Z(X(n.defaults.telemetryWindowMinutes))}]})}),(0,V.jsx)(Q,{label:`Max attachment size`,labelFor:`image-clamp-max-bytes`,hint:`Per image, ${Ae(n.defaults.imageClampMaxBytes)} when unset. An oversized attachment is refused before send rather than after the upstream rejects it — a block too large poisons every retry and every replayed turn. Raising this asserts your upstreams accept more; lowering it is the safer direction. Applies to the Messages and Gemini wires.`,control:(0,V.jsx)(F,{"aria-label":`Max attachment size`,id:`image-clamp-max-bytes`,value:n.imageClampMaxBytes===null?``:String(Math.round(n.imageClampMaxBytes/1048576)),placeholder:Z(Ae(n.defaults.imageClampMaxBytes)),onValueChange:e=>r({imageClampMaxBytes:e===``?null:Number(e)*1024*1024},`Attachment size limit updated.`),options:[...Y(De,n.imageClampMaxBytes===null?null:Math.round(n.imageClampMaxBytes/1048576),e=>`${e} MB`),{value:``,label:Z(Ae(n.defaults.imageClampMaxBytes))}]})}),(0,V.jsx)($,{title:`Response shaping`}),(0,V.jsx)(Q,{label:`Thinking normalization`,labelFor:`thinking-normalization`,hint:`Rewrite a provider's native thinking config into the canonical shape on turns where the user is not the final reader. Off by default: the upstream's own config is passed through untouched.`,control:(0,V.jsx)(F,{"aria-label":`Thinking normalization`,id:`thinking-normalization`,value:n.thinkingNormalizationEnabled?`on`:`off`,onValueChange:e=>{let t=e===`on`;r({thinkingNormalizationEnabled:t},t?`Thinking config will be normalized.`:`Upstream thinking config is left as sent.`)},options:[{value:`off`,label:`Off — default`},{value:`on`,label:`On`}]})}),(0,V.jsx)(Q,{label:`Reasoning summary`,labelFor:`responses-reasoning-summary`,hint:`Verbosity of the reasoning summary on the Responses wire, forced even when a request carries no reasoning block. Applies when the routed model is Responses and the client called a Chat surface.`,control:(0,V.jsx)(F,{"aria-label":`Reasoning summary`,id:`responses-reasoning-summary`,value:n.responsesReasoningSummary,onValueChange:e=>r({responsesReasoningSummary:e===`concise`||e===`detailed`?e:`auto`},`Reasoning summary updated.`),options:[{value:`auto`,label:`Auto — follow the request`},{value:`concise`,label:`Concise`},{value:`detailed`,label:`Detailed — default`}]})})]})}function Pe(){let e=we(),[t,n]=(0,B.useState)(``),[r,i]=(0,B.useState)(``),[a,o]=(0,B.useState)(``),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(!1);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Current password`,labelFor:`current-password`,hint:`This is the password for this console, not for any upstream provider. Provider credentials live on each provider in Providers.`,control:(0,V.jsx)(P,{id:`current-password`,"aria-label":`Current password`,type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:`current-password`})}),(0,V.jsx)(Q,{label:`New password`,labelFor:`new-password`,hint:`Minimum 8 characters. A passphrase is easier to remember and harder to guess.`,control:(0,V.jsx)(P,{id:`new-password`,"aria-label":`New password`,type:`password`,value:r,onChange:e=>i(e.target.value),autoComplete:`new-password`})}),(0,V.jsx)(Q,{label:`Confirm new password`,labelFor:`confirm-password`,control:(0,V.jsx)(P,{id:`confirm-password`,"aria-label":`Confirm new password`,type:`password`,value:a,onChange:e=>o(e.target.value),autoComplete:`new-password`})}),c?(0,V.jsx)(`p`,{role:`alert`,className:`settings-feedback`,"data-tone":`err`,children:c}):null,u?(0,V.jsx)(`p`,{role:`status`,className:`settings-feedback`,"data-tone":`ok`,children:`Password updated.`}):null,(0,V.jsx)(`div`,{className:`settings-actions`,children:(0,V.jsx)(s,{variant:`primary`,size:`sm`,onClick:()=>{if(d(!1),r.length<8){l(`New password must be at least 8 characters.`);return}if(r!==a){l(`New password and confirmation do not match.`);return}l(null),e.mutate({currentPassword:t,newPassword:r},{onSuccess:()=>{d(!0),n(``),i(``),o(``)},onError:e=>l(T(e,`Password change failed.`))})},disabled:e.isPending||!t||!r||!a,children:e.isPending?`Updating…`:`Update password`})})]})}var Fe={security:(0,V.jsx)(Pe,{}),privacy:(0,V.jsx)(Me,{}),operations:(0,V.jsx)(Ne,{}),backup:(0,V.jsx)(W,{}),"data-management":(0,V.jsx)(Se,{})},Ie=[`security`,`privacy`];function Le(){return(0,V.jsxs)(`div`,{className:`settings-page`,children:[(0,V.jsx)(`div`,{className:`settings-grid`,children:Ie.map(e=>{let t=ke.find(t=>t.id===e);return t?(0,V.jsx)(je,{id:t.id,title:t.title,description:t.description,children:Fe[t.id]},e):null})}),ke.filter(e=>!Ie.includes(e.id)).map(e=>(0,V.jsx)(je,{id:e.id,title:e.title,description:e.description,children:Fe[e.id]},e.id))]})}export{Y as boundedOptions,Le as default};
1
+ import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{i,r as a}from"./terminal-0_IjPWTk.js";import{T as o,c as s,i as c,s as l,t as u}from"./numbers-Dulqgys5.js";import{t as d}from"./database-Dz9N3zGd.js";import{t as f}from"./eye-C_hawfH4.js";import{n as p,r as m}from"./state-DhZBfWgx.js";import{t as h}from"./layers-2-glBbjl.js";import{t as ee}from"./dialog-Iec_ywbD.js";import{n as g,r as te,t as _}from"./settings--3hxSyry.js";import{t as v}from"./trash-Cppn5c3R.js";import{t as y}from"./zap-C4EeVW4q.js";import{C as b,T as x,v as S}from"./assert-DU6qrMA_.js";import{a as C,i as w,l as T,o as E,s as D,t as O}from"./query-keys-UETqfytp.js";import{t as k}from"./useMutation-EDFRkn1i.js";import{it as A}from"./entry-BrksMru8.js";import{n as j,r as M,t as N}from"./card-BOPBuBzD.js";import{n as ne,t as re}from"./download-dRFo5_Wu.js";import{n as P}from"./input-WlyHWeG2.js";import{t as F}from"./select-Ciq_KFQ1.js";import{t as ie}from"./switch-yD7D99Lg.js";import{t as I}from"./stack-B1w5BM0u.js";import{t as L}from"./banner-C-7y3VKV.js";import{t as ae}from"./backup-file-gdKIlg8U.js";var oe=e(`archive`,[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]),se=e(`file-braces`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]]),ce=e(`file-clock`,[[`path`,{d:`M16 22h2a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v2.85`,key:`ryk6xj`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M8 14v2.2l1.6 1`,key:`6m4bie`}],[`circle`,{cx:`8`,cy:`16`,r:`6`,key:`10v15b`}]]),R=e(`hard-drive-download`,[[`path`,{d:`M12 2v8`,key:`1q4o3n`}],[`path`,{d:`m16 6-4 4-4-4`,key:`6wukr`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,key:`w68u3i`}],[`path`,{d:`M6 18h.01`,key:`uhywen`}],[`path`,{d:`M10 18h.01`,key:`h775k`}]]),z=e(`hard-drive`,[[`path`,{d:`M10 16h.01`,key:`1bzywj`}],[`path`,{d:`M2.212 11.577a2 2 0 0 0-.212.896V18a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-5.527a2 2 0 0 0-.212-.896L18.55 5.11A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`18tbho`}],[`path`,{d:`M21.946 12.013H2.054`,key:`zqlbp7`}],[`path`,{d:`M6 16h.01`,key:`1pmjb7`}]]),le=e(`upload`,[[`path`,{d:`M12 3v12`,key:`1x0j5s`}],[`path`,{d:`m17 8-5-5-5 5`,key:`7q97r8`}],[`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`,key:`ih7n3h`}]]),B=t(n(),1);function ue(){return k({mutationFn:async({password:e,sections:t,compressed:n,onProgress:r})=>{let i=new URLSearchParams({password:e});t!==void 0&&t.length>0&&i.set(`sections`,t),n===!0&&i.set(`compressed`,`1`);let a=`/backup/export?${i.toString()}`;if(n!==!0)return E(a);let o=await E(a),s=atob(o.bytes),c=Uint8Array.from(s,e=>e.charCodeAt(0));return r?.({loaded:c.byteLength,total:c.byteLength}),c}})}function de(){let e=x();return k({mutationFn:({password:e,scopes:t})=>E(`/backup/delete-all`,{method:`POST`,body:JSON.stringify({password:e,scopes:t})}),onSuccess:async()=>{await e.invalidateQueries()}})}function fe(){let e=x();return k({mutationFn:({password:e,backup:t,tables:n,onProgress:r})=>D(`/backup/import`,JSON.stringify({password:e,backup:t,...n===void 0||n.length===0?{}:{tables:[...n]}}),r),onSuccess:async()=>{await e.invalidateQueries()}})}function pe(){return k({mutationFn:({backup:e})=>E(`/backup/inspect`,{method:`POST`,body:JSON.stringify({backup:e})})})}var V=r();function me({title:e,description:t}){return(0,V.jsxs)(`div`,{className:`mb-6 min-w-0`,children:[(0,V.jsx)(`h3`,{className:`text-body-lg font-bold text-text-primary`,children:e}),(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-secondary`,children:t})]})}function H({icon:e,label:t,description:n,checked:r,onChange:i}){return(0,V.jsxs)(`label`,{className:`flex items-start gap-5 min-h-21 px-6 py-5 border border-inner-border rounded-control bg-surface-2 text-text-primary text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:r,onChange:i}),(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(e,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,V.jsx)(`strong`,{children:t}),(0,V.jsx)(`small`,{className:`text-text-tertiary text-badge`,children:n})]})]})}function he(e){return e===`providers`?A:e===`proxies`?a:h}function ge({report:e}){let t=Object.entries(e.imported).filter(([,e])=>e>0);return(0,V.jsxs)(I,{gap:`8px`,children:[t.length>0?(0,V.jsxs)(`p`,{className:`text-caption`,children:[`Imported:`,` `,t.map(([e,t])=>`${t} ${e}`).join(`, `)]}):null,e.remapped.length>0?(0,V.jsxs)(`p`,{className:`text-caption text-text-secondary`,children:[`Remapped provider ids: `,e.remapped.join(`, `)]}):null,e.skipped.length>0?(0,V.jsxs)(`div`,{children:[(0,V.jsxs)(`p`,{className:`text-caption text-yellow`,children:[`Skipped (`,e.skipped.length,`) — nothing was guessed:`]}),(0,V.jsx)(`ul`,{className:`text-caption text-text-tertiary mt-2 ml-8`,children:e.skipped.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}):null,e.warnings.length>0?(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`p`,{className:`text-caption text-text-secondary`,children:`Warnings:`}),(0,V.jsx)(`ul`,{className:`text-caption text-text-tertiary mt-2 ml-8`,children:e.warnings.map(e=>(0,V.jsx)(`li`,{children:e},e))})]}):null]})}function _e({warnings:e}){return e.length===0?null:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,live:`status`,children:[(0,V.jsxs)(`strong`,{children:[`Restore completed with `,e.length,` warning`,e.length===1?``:`s`]}),(0,V.jsx)(`ul`,{className:`mt-2 ml-8`,children:e.map((e,t)=>(0,V.jsxs)(`li`,{children:[e.table?`${e.table}${e.column?`.${e.column}`:``}: `:``,e.reason]},`${e.table??`backup`}:${e.column??`general`}:${t}`))})]})}function U(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function ve(e,t){if(e===null)return t;let n=Math.max((Date.now()-e.startedAt)/1e3,.1),r=U(e.loaded/n);return`${e.total===null?U(e.loaded):`${U(e.loaded)} / ${U(e.total)}`} · ${r}/s`}function W(){let[e,t]=(0,B.useState)(``),[n,r]=(0,B.useState)(null),[i,a]=(0,B.useState)(!0),[c,u]=(0,B.useState)(!1),[f,p]=(0,B.useState)(!0),[m,h]=(0,B.useState)(null),[g,te]=(0,B.useState)(null),[_,y]=(0,B.useState)(null),[b,x]=(0,B.useState)(null),[S,C]=(0,B.useState)(null),[w,E]=(0,B.useState)(null),[D,O]=(0,B.useState)(new Set),[k,A]=(0,B.useState)(null),[j,M]=(0,B.useState)(null),[N,F]=(0,B.useState)(new Set),[oe,se]=(0,B.useState)(null),R=(0,B.useRef)(null),z=ue(),U=fe(),W=de(),ye=pe(),be=e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},G=()=>{r(null),t(``)},xe=()=>{D.size!==0&&(t(``),r(`delete`))},Se=async()=>{if(e.length===0)return;let t=await W.mutateAsync({password:e,scopes:[...D]});O(new Set),G(),l.success(`Selected configuration deleted.`,Object.entries(t.deleted).map(([e,t])=>`${e}: ${t}`).join(` · `))},K=()=>{let t=[...i?[`config`]:[],...c?[`telemetry`]:[]].join(`,`);if(t.length===0){l.error(`Select at least one backup section.`);return}z.mutate({password:e,sections:t,compressed:f,onProgress:e=>h(t=>({...e,startedAt:t?.startedAt??Date.now()}))},{onSuccess:e=>{let t=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`);e instanceof Uint8Array?re(`cartethyia_backup_${t}.json.gz`,e,`application/gzip`):ne(`cartethyia_backup_${t}.json`,JSON.stringify(e,null,2),`application/json`),G(),l.success(`Backup downloaded.`)},onError:e=>l.error(T(e,`Backup export failed.`))})},q=async e=>{te(null),y(null),x(null),C(null),E(null),se(null),M(null),F(new Set),A(e);try{let t=await ae(e),n=await ye.mutateAsync({backup:t});M(n),F(new Set(n.rows.filter(e=>e.supported).map(e=>e.table)))}catch(e){A(null),l.error(`Could not read that backup`,T(e,`The file is not a readable backup.`))}},Ce=e=>{F(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},J=()=>{M(null),A(null),se(null)},we=()=>{k!==null&&N.size!==0&&(t(``),x(null),r(`restore`))},Te=async()=>{let t=k;if(t!==null){x(null);try{let n=await ae(t),r=await U.mutateAsync({password:e,backup:n,tables:[...N],onProgress:e=>h(t=>({...e,startedAt:t?.startedAt??Date.now()}))});te(r.restored),y(r.warnings),C(r.report??null),E(r.format),G(),A(null),M(null),l.success(r.warnings.length===0?`Restore complete.`:`Restore completed with warnings.`,r.warnings.length===0?null:`${r.warnings.length} item(s) need attention. See the restore report below.`)}catch(e){let t=T(e,`Backup restore failed.`);x(t),l.error(`Backup restore failed`,t)}}},Ee=g===null?[]:Object.entries(g);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`grid grid-cols-2 gap-8 w-full min-w-0 max-medium:grid-cols-1`,children:[(0,V.jsxs)(`section`,{"aria-label":`Backup`,className:`min-w-0`,children:[(0,V.jsx)(me,{title:`Export and restore`,description:`Download a JSON snapshot, or restore one you already trust.`}),(0,V.jsxs)(I,{gap:`14px`,children:[(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-2 gap-5 min-w-0 border-0 m-0 p-0 max-medium:grid-cols-1`,children:[(0,V.jsx)(`legend`,{className:`mb-4 text-text-secondary text-caption font-semibold`,children:`Include in the download`}),(0,V.jsx)(H,{icon:d,label:`Account, proxy & settings`,description:`Credentials, API-key hashes, routing, and settings`,checked:i,onChange:()=>a(!i)}),(0,V.jsx)(H,{icon:ce,label:`Telemetry history`,description:`Status, tokens, cost, latency — never prompt bodies`,checked:c,onChange:()=>u(!c)})]}),(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-6 rounded-control border border-inner-border px-6 py-5`,children:[(0,V.jsxs)(`span`,{children:[(0,V.jsx)(`strong`,{className:`block text-body`,children:`Highly Compress Backup`}),(0,V.jsx)(`small`,{className:`text-caption text-text-tertiary`,children:`Makes the download smaller.`})]}),(0,V.jsx)(ie,{checked:f,onChange:p,"aria-label":`Highly Compress Backup`})]}),(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:`The file contains provider credentials. Treat it like the database. Prompt and response bodies, health-event history, and console sessions are left out.`}),(0,V.jsxs)(`div`,{className:`mt-auto flex justify-end gap-4`,children:[(0,V.jsx)(s,{variant:`primary`,size:`sm`,onClick:()=>{t(``),r(`download`)},disabled:!i&&!c,icon:(0,V.jsx)(o,{size:13}),children:`Download backup`}),(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:()=>R.current?.click(),icon:(0,V.jsx)(le,{size:13}),children:`Restore from file`}),(0,V.jsx)(`input`,{ref:R,type:`file`,accept:`application/json,.json,.gz,application/gzip`,className:`sr-only`,onChange:e=>{let t=e.target.files?.[0];t&&q(t),e.target.value=``}})]}),w===null?null:(0,V.jsxs)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:[`Detected format:`,` `,w===`nine_router`?`router export`:`Cartethyia backup`]}),g===null?null:(0,V.jsxs)(L,{tone:`success`,surface:`raised`,live:`status`,children:[(0,V.jsx)(`strong`,{children:`Restore complete`}),Ee.length>0?(0,V.jsx)(`ul`,{children:Ee.map(([e,t])=>(0,V.jsxs)(`li`,{children:[e,`: `,t]},e))}):(0,V.jsx)(`p`,{children:`No rows were imported.`})]}),_===null?null:(0,V.jsx)(_e,{warnings:_}),S===null?null:(0,V.jsx)(ge,{report:S})]})]}),(0,V.jsxs)(`section`,{"aria-label":`Delete data`,className:`min-w-0`,children:[(0,V.jsx)(me,{title:`Delete data`,description:`Removes the scopes you check. Console users, sessions, and audit history stay.`}),(0,V.jsxs)(I,{gap:`12px`,children:[(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-5 min-w-0 border-0 m-0 p-0`,children:[(0,V.jsx)(`legend`,{className:`mb-4 text-text-secondary text-caption font-semibold`,children:`Delete`}),[[`providers`,`Providers`,`Accounts, credentials, tenant models, routing, and account health`],[`proxies`,`Proxies`,`Network pools, pool settings, and pool health`],[`configuration`,`All configuration`,`Providers, proxies, aliases, combos, API keys, CLI tools, and settings`]].map(([e,t,n])=>(0,V.jsx)(H,{icon:he(e),label:t,description:n,checked:D.has(e),onChange:()=>be(e)},e))]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end gap-4 flex-wrap`,children:(0,V.jsx)(s,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),disabled:D.size===0,onClick:xe,children:`Delete selected`})})]})]})]}),(0,V.jsx)(ee,{open:j!==null,onClose:J,title:`Restore from backup`,description:`Choose which parts of this file to restore, then confirm with your console password.`,size:`md`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:J,children:`Cancel`}),(0,V.jsx)(s,{variant:`primary`,size:`sm`,disabled:N.size===0,onClick:we,children:`Restore now`})]}),children:(0,V.jsx)(I,{gap:`12px`,children:j===null?null:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`p`,{className:`text-caption text-text-tertiary`,children:j.format===`nine_router`?`Router export — it is converted at restore time, so every table it produces is restored.`:`${j.total} rows · exported ${j.exportedAt||`unknown date`}`}),j.rows.length>0?(0,V.jsxs)(`fieldset`,{className:`grid grid-cols-1 gap-4 min-w-0 border-0 m-0 p-0`,children:[(0,V.jsx)(`legend`,{className:`mb-3 text-text-secondary text-caption font-semibold`,children:`Restore these tables`}),(0,V.jsxs)(`div`,{className:`flex justify-end gap-4`,children:[(0,V.jsx)(`button`,{type:`button`,className:`text-badge text-accent hover:underline`,onClick:()=>F(new Set(j.rows.filter(e=>e.supported).map(e=>e.table))),children:`Select all`}),(0,V.jsx)(`button`,{type:`button`,className:`text-badge text-text-secondary hover:underline`,onClick:()=>F(new Set),children:`Select none`})]}),j.rows.map(e=>(0,V.jsxs)(`label`,{className:`flex items-start gap-4 px-5 py-4 border border-inner-border rounded-control bg-surface-2 text-caption leading-snug cursor-pointer hover:border-border-strong hover:bg-hover has-checked:border-accent has-checked:bg-accent-soft`,children:[(0,V.jsx)(`input`,{type:`checkbox`,checked:N.has(e.table),disabled:!e.supported,onChange:()=>Ce(e.table)}),(0,V.jsxs)(`span`,{className:`flex flex-col gap-1 min-w-0`,children:[(0,V.jsx)(`strong`,{className:`text-text-primary`,children:e.table}),(0,V.jsxs)(`small`,{className:`text-text-tertiary text-badge`,children:[e.count,` rows · `,e.section,e.supported?``:` · not in the current schema, will be skipped`]})]})]},`${e.section}:${e.table}`))]}):null,oe===null?null:(0,V.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:oe})]})})}),(0,V.jsx)(ee,{open:n!==null,onClose:G,title:n===`delete`?`Confirm deletion`:n===`restore`?`Restore backup`:`Download backup`,description:`The console password is checked again before this runs.`,size:`sm`,footer:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:G,children:`Cancel`}),(0,V.jsx)(s,{variant:n===`delete`?`danger`:`primary`,size:`sm`,loading:z.isPending||U.isPending||W.isPending,disabled:e.length===0||z.isPending||U.isPending||W.isPending,onClick:()=>{h(null),n===`download`?K():n===`restore`?Te():Se()},children:z.isPending?ve(m,`Downloading…`):U.isPending?ve(m,`Uploading…`):W.isPending?`Working…`:n===`delete`?`Delete permanently`:n===`restore`?`Restore`:`Download`})]}),children:(0,V.jsxs)(I,{gap:`10px`,children:[n===`restore`&&b!==null?(0,V.jsx)(`p`,{role:`alert`,className:`text-caption text-red`,children:b}):null,(0,V.jsx)(`p`,{className:`mt-1 text-caption text-text-tertiary`,children:n===`delete`?`This cannot be undone. The password is verified again before anything is removed.`:n===`restore`?`Restore replaces the tenant configuration in this file. Continue only if the file is trusted.`:`The export is plain JSON and contains provider credentials.`}),(0,V.jsx)(P,{label:`Console password`,type:`password`,value:e,onChange:e=>t(e.target.value),autoComplete:`current-password`,"data-autofocus":!0})]})})]})}function ye(){return b({queryKey:O.settings.diskUsage,queryFn:e=>E(`/data-management/usage`,{signal:S(e)}),...w,staleTime:C.status})}function be(){let e=x();return k({mutationFn:e=>E(`/data-management/reclaim`,{method:`POST`,body:JSON.stringify({action:e})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:O.settings.diskUsage})}})}function G(){return k({mutationFn:()=>E(`/data-management/flush`,{method:`POST`})})}function xe(){let e=x();return k({mutationFn:()=>E(`/data-management/purge`,{method:`POST`,body:JSON.stringify({target:`health_events`})}),onSuccess:async()=>{await e.invalidateQueries({queryKey:O.settings.diskUsage})}})}function Se(){let e=ye(),t=be(),n=G(),r=xe(),[a,o]=(0,B.useState)(null),[d,f]=(0,B.useState)(!1);if(e.isPending)return(0,V.jsx)(m,{label:`Measuring disk usage…`});if(e.isError||!e.data)return(0,V.jsx)(p,{message:T(e.error,`Failed to measure disk usage`),onRetry:()=>void e.refetch()});let h=e.data,ee=e=>{e!==null&&(o(null),t.mutate(e,{onSuccess:e=>{if(e.deletedFiles===0){l.success(`Nothing to reclaim.`);return}l.success(`Reclaimed ${u(e.reclaimedBytes)} across ${c(e.deletedFiles)} file${e.deletedFiles===1?``:`s`}.`)},onError:e=>l.error(T(e,`Reclaim failed.`))}))},g=h.healthEventCount;return(0,V.jsxs)(I,{gap:`14px`,children:[(0,V.jsxs)(`div`,{className:`flex items-center justify-between gap-4 flex-wrap`,children:[(0,V.jsxs)(`span`,{className:`text-caption text-text-tertiary`,children:[u(h.totalBytes),` on disk across`,` `,c(h.buckets.reduce((e,t)=>e+t.files,0)),` files`]}),(0,V.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(z,{size:14}),onClick:()=>void e.refetch(),disabled:e.isFetching,children:e.isFetching?`Measuring…`:`Refresh`})]}),(0,V.jsxs)(`div`,{className:`settings-bucket-grid`,children:[h.buckets.map(e=>{let n=q(e);return(0,V.jsx)(J,{bucket:e,busy:t.isPending,confirming:n!==null&&a===n,onAsk:()=>o(n),onCancel:()=>o(null),onConfirm:()=>ee(n)},e.id)}),(0,V.jsx)(K,{icon:i,title:`Health & Error Log`,note:g===void 0?`Purging is not offered in this deployment's console composition.`:`${c(g)} recorded transition${g===1?``:`s`} across accounts and pools. Purge clears only this audit trail — account statuses and cooldowns stay as they are, and this cannot be undone.`,testId:`health_events`,children:g===void 0?null:d?(0,V.jsx)(`span`,{className:`flex flex-col gap-3`,children:(0,V.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:()=>f(!1),disabled:r.isPending,children:`Cancel`}),(0,V.jsx)(s,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),disabled:r.isPending,onClick:()=>r.mutate(void 0,{onSuccess:e=>{f(!1),l.success(e.deleted===0?`Health & error log was already empty.`:`Purged ${c(e.deleted)} health event${e.deleted===1?``:`s`}.`)},onError:e=>l.error(T(e,`Purge failed.`))}),children:`Delete`})]})}):(0,V.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),disabled:r.isPending||g===0,onClick:()=>f(!0),children:`Purge`})}),(0,V.jsx)(K,{icon:R,title:`Flush pending writes`,note:`Write queued telemetry, usage, and health events now instead of waiting for the interval. Nothing is deleted.`,testId:`flush`,children:(0,V.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(y,{size:14}),disabled:n.isPending,onClick:()=>n.mutate(void 0,{onSuccess:()=>l.success(`Buffers flushed.`),onError:e=>l.error(T(e,`Flush failed.`))}),children:n.isPending?`Flushing…`:`Flush`})})]}),t.isError?(0,V.jsx)(L,{tone:`danger`,surface:`raised`,live:`status`,children:T(t.error,`Reclaim failed.`)}):null]})}function K({icon:e,title:t,note:n,children:r,testId:i}){return(0,V.jsxs)(`div`,{"data-panel":i,className:`flex flex-col rounded-control border border-inner-border px-6 py-5 min-w-0`,children:[(0,V.jsxs)(`span`,{className:`flex items-start gap-4`,children:[(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(e,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block text-caption text-text-tertiary`,children:t}),(0,V.jsx)(`span`,{className:`mt-1 block text-caption text-text-tertiary`,children:n})]})]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end pt-5`,children:r})]})}function q(e){return e.id===`payload_frames`?`payload_frames`:e.id===`telemetry_events`?`telemetry_retention`:null}function Ce(e){return e.id===`payload_frames`?se:ce}function J({bucket:e,busy:t,confirming:n,onAsk:r,onCancel:i,onConfirm:a}){let o=q(e),l=e.reclaimableBytes!==null,d=e.reclaimableBytes??0,f=e.reclaimableFiles??0,p=l&&d===0,m=Ce(e);return(0,V.jsxs)(`div`,{"data-bucket":e.id,className:`flex flex-col rounded-control border border-inner-border px-6 py-5 min-w-0`,children:[(0,V.jsxs)(`span`,{className:`flex items-start gap-4`,children:[(0,V.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-control bg-surface-1 text-text-secondary`,children:(0,V.jsx)(m,{size:15,"aria-hidden":`true`})}),(0,V.jsxs)(`span`,{className:`min-w-0`,children:[(0,V.jsx)(`span`,{className:`block text-caption text-text-tertiary`,children:e.label}),(0,V.jsx)(`span`,{className:`mt-1 block text-lead font-semibold text-text-primary`,children:u(e.bytes)}),(0,V.jsxs)(`span`,{className:`block text-caption text-text-tertiary`,children:[c(e.files),` file`,e.files===1?``:`s`,` · `,e.note]})]})]}),(0,V.jsx)(`div`,{className:`mt-auto flex justify-end pt-5`,children:o===null?(0,V.jsx)(`p`,{className:`text-caption text-text-tertiary`,children:`Kept — no other copy.`}):n?(0,V.jsxs)(`span`,{className:`flex flex-col gap-3`,children:[(0,V.jsx)(`span`,{className:`text-caption text-text-secondary`,children:l?`Delete ${c(f)} file${f===1?``:`s`}, ${u(d)}?`:`Delete raw event files past the retention window?`}),(0,V.jsxs)(`span`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(s,{variant:`secondary`,size:`sm`,onClick:i,disabled:t,children:`Cancel`}),(0,V.jsx)(s,{variant:`danger`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),onClick:a,disabled:t,children:`Delete`})]})]}):(0,V.jsxs)(`span`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,V.jsx)(`span`,{className:`text-caption text-text-tertiary`,children:l?p?`Clean`:`${u(d)} free`:`Expired events only`}),(0,V.jsx)(s,{variant:`secondary`,size:`sm`,icon:(0,V.jsx)(v,{size:14}),onClick:r,disabled:t||p,children:`Reclaim`})]})})]})}function we(){return k({mutationFn:e=>E(`/auth/change-password`,{method:`POST`,body:JSON.stringify(e)})})}var Te=[5,15,30,60,120,300,600],Ee=[5,15,30,60,180,720,1440],De=[1,5,10,25,50,100];function Oe({name:e}){let t={size:16};return e===`privacy`?(0,V.jsx)(f,{...t}):e===`operations`?(0,V.jsx)(y,{...t}):e===`data`?(0,V.jsx)(oe,{...t}):e===`data-management`?(0,V.jsx)(d,{...t}):(0,V.jsx)(te,{...t})}function Y(e,t,n){return(t===null||e.includes(t)?[...e]:[...e,t].sort((e,t)=>e-t)).map(e=>({value:String(e),label:n(e)}))}var ke=[{id:`security`,title:`Security`,description:`Change the password used to sign in to this console.`},{id:`privacy`,title:`Privacy`,description:`What request telemetry stores, and how client addresses are shown.`},{id:`backup`,title:`Backup`,description:`Export or restore this tenant's configuration and history.`},{id:`operations`,title:`Operations`,description:`Routing, admission, request handling, and response shaping for this tenant.`},{id:`data-management`,title:`Data Management`,description:`See what the gateway keeps on disk, reclaim space, and flush queued writes.`}];function X(e){if(e%1440==0){let t=e/1440;return`${t} day${t===1?``:`s`}`}if(e%60==0){let t=e/60;return`${t} hour${t===1?``:`s`}`}return`${e} min`}function Z(e){return`Deployment default (${e})`}function Ae(e){return`${Math.round(e/1048576)} MB`}function Q({label:e,hint:t,labelFor:n,control:r}){return(0,V.jsxs)(`div`,{className:`settings-row`,children:[(0,V.jsxs)(`div`,{className:`settings-row-text`,children:[n?(0,V.jsx)(`label`,{className:`settings-row-label`,htmlFor:n,children:e}):(0,V.jsx)(`span`,{className:`settings-row-label`,children:e}),t?(0,V.jsx)(`p`,{className:`settings-row-hint`,children:t}):null]}),(0,V.jsx)(`div`,{className:`settings-row-control`,children:r})]})}function $({title:e}){return(0,V.jsx)(`p`,{className:`settings-group-head`,children:e})}function je({id:e,title:t,description:n,children:r}){return(0,V.jsxs)(N,{id:e,"aria-label":t,className:`min-w-0`,children:[(0,V.jsx)(M,{title:t,subtitle:n,icon:(0,V.jsx)(Oe,{name:e})}),(0,V.jsx)(j,{className:`flex flex-col gap-0`,children:r})]})}function Me(){let e=_(),t=g(),n=e.data;return e.isPending?(0,V.jsx)(m,{label:`Loading privacy settings…`}):e.isError||!n?(0,V.jsx)(p,{message:T(e.error,`Failed to load runtime settings`),onRetry:()=>void e.refetch()}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Telemetry payloads`,labelFor:`privacy-payloads`,hint:`Request metadata is always kept. Bodies stay off until you turn them on, and anything captured is redacted and deleted when the Request detail window in Operations runs out.`,control:(0,V.jsx)(F,{"aria-label":`Telemetry payloads`,id:`privacy-payloads`,value:n.telemetryPayloads,onValueChange:e=>t.mutate({telemetryPayloads:e===`full`||e===`metadata`?e:`none`},{onSuccess:()=>l.success(`Payload capture updated`),onError:e=>l.error(T(e,`Could not update payload capture.`))}),options:[{value:`none`,label:`Off — no payload capture`},{value:`metadata`,label:`Metadata — method and headers only`},{value:`full`,label:`Full — redacted bodies`}]})}),n.telemetryPayloads===`full`?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Capture depth`,labelFor:`privacy-payload-depth`,hint:`Size cap for each captured body.`,control:(0,V.jsx)(F,{"aria-label":`Capture depth`,id:`privacy-payload-depth`,value:n.telemetryPayloadDepth,onValueChange:e=>t.mutate({telemetryPayloadDepth:e===`moderate`||e===`maximum`?e:`minimum`},{onSuccess:()=>l.success(`Capture depth updated`),onError:e=>l.error(T(e,`Could not update capture depth.`))}),options:[{value:`minimum`,label:`Minimum — 1 MiB cap`},{value:`moderate`,label:`Moderate — 8 MiB cap`},{value:`maximum`,label:`Maximum — 16 MiB cap`}]})}),n.telemetryPayloadDepth===`minimum`?null:(0,V.jsx)(`div`,{className:`settings-row-banner`,children:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,className:`text-text-secondary`,children:[(0,V.jsx)(`strong`,{children:`High CPU and memory while this is on.`}),` Use it to debug, then switch back to Metadata or Minimum.`]})})]}):null,(0,V.jsx)(Q,{label:`Client IP display`,labelFor:`privacy-ip`,hint:`Raw addresses stay stored and are still written to telemetry. This only changes how they are shown in the console.`,control:(0,V.jsx)(F,{"aria-label":`Client IP display`,id:`privacy-ip`,value:n.privacyMode,onValueChange:e=>t.mutate({privacyMode:e===`full`?`full`:`masked`},{onSuccess:()=>l.success(`IP display updated`),onError:e=>l.error(T(e,`Could not update IP display.`))}),options:[{value:`masked`,label:`Masked — recommended`},{value:`full`,label:`Show full IP`}]})})]})}function Ne(){let e=_(),t=g(),n=e.data;if(e.isPending)return(0,V.jsx)(m,{label:`Loading operational settings…`});if(e.isError||!n)return(0,V.jsx)(p,{message:T(e.error,`Failed to load runtime settings`),onRetry:()=>void e.refetch()});let r=(e,n)=>{t.mutate(e,{onSuccess:()=>l.success(n),onError:e=>l.error(T(e,`Could not update settings.`))})};return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)($,{title:`Routing`}),(0,V.jsx)(Q,{label:`Ignore cooldowns`,labelFor:`ignore-cooldowns`,hint:`Route to accounts that are cooling down, including ones already parked. Off by default: a cooling account stays out of the rotation until it resets. On dials it anyway, which is what the warning below is about.`,control:(0,V.jsx)(F,{"aria-label":`Ignore cooldowns`,id:`ignore-cooldowns`,value:n.forceDisableCooldown?`on`:`off`,onValueChange:e=>{let t=e===`on`;r({forceDisableCooldown:t},t?`Cooldowns are ignored.`:`Cooldowns are enforced again.`)},options:[{value:`off`,label:`Off — default`},{value:`on`,label:`On`}]})}),n.forceDisableCooldown?(0,V.jsx)(`div`,{className:`settings-row-banner`,children:(0,V.jsxs)(L,{tone:`warning`,surface:`raised`,live:`status`,children:[(0,V.jsx)(`strong`,{children:`This may cause admission failure.`}),` A cooled-down account was parked because the upstream refused it, so dialing it anyway reproduces that refusal on every attempt — and if every candidate is cooling, the request fails instead of waiting for a reset. The cooldown is still recorded and still recovered by the sweep, so turning this back off needs no cleanup. Per-model cooldowns are still enforced.`]})}):null,(0,V.jsx)($,{title:`Admission`}),(0,V.jsx)(Q,{label:`Tenant concurrency limit`,labelFor:`tenant-concurrency-limit`,hint:`Ceiling on requests in flight across every key in this tenant at once. Empty means no tenant-wide ceiling — each key is then bounded only by its own limit.`,control:(0,V.jsx)(P,{id:`tenant-concurrency-limit`,"aria-label":`Tenant concurrency limit`,type:`number`,min:`1`,step:`1`,inputMode:`numeric`,placeholder:`No ceiling`,value:n.tenantConcurrencyLimit?.toString()??``,onChange:e=>{let t=e.target.value.trim();if(t===``){r({tenantConcurrencyLimit:null},`Tenant ceiling removed.`);return}let n=Number(t);!Number.isInteger(n)||n<1||r({tenantConcurrencyLimit:n},`Tenant concurrency limit updated.`)}})}),(0,V.jsx)(Q,{label:`Concurrency tolerance`,labelFor:`concurrency-tolerance`,hint:`Slack added above a key's own concurrency limit. The effective ceiling is the key's limit plus this, so a run landing a few over is not refused at the number it was told.`,control:(0,V.jsx)(P,{id:`concurrency-tolerance`,"aria-label":`Concurrency tolerance`,type:`number`,min:`0`,max:`1024`,step:`1`,inputMode:`numeric`,placeholder:`None`,value:n.concurrencyTolerance?.toString()??``,onChange:e=>{let t=e.target.value.trim();if(t===``){r({concurrencyTolerance:null},`Tolerance removed.`);return}let n=Number(t);!Number.isInteger(n)||n<0||n>1024||r({concurrencyTolerance:n},`Concurrency tolerance updated.`)}})}),(0,V.jsx)($,{title:`Request handling`}),(0,V.jsx)(Q,{label:`Upstream timeout`,labelFor:`upstream-timeout`,hint:`5–600 seconds, ${n.defaults.upstreamTimeoutSeconds}s when unset. Applied when the request is dispatched, so it can only shorten a deadline that has already started.`,control:(0,V.jsx)(F,{"aria-label":`Upstream timeout`,id:`upstream-timeout`,value:n.upstreamTimeoutSeconds?.toString()??``,placeholder:Z(`${n.defaults.upstreamTimeoutSeconds} seconds`),onValueChange:e=>r({upstreamTimeoutSeconds:e===``?null:Number(e)},`Upstream timeout updated.`),options:[...Y(Te,n.upstreamTimeoutSeconds,e=>`${e} seconds`),{value:``,label:Z(`${n.defaults.upstreamTimeoutSeconds} seconds`)}]})}),(0,V.jsx)(Q,{label:`Request detail window`,labelFor:`telemetry-window-minutes`,hint:`1–1440 minutes, ${X(n.defaults.telemetryWindowMinutes)} when unset. Controls how long captured payload frames are kept — the same number Data Management reports as what payload frames expire after. Raw request events follow the ${n.defaults.telemetryRetentionDays}-day server retention instead.`,control:(0,V.jsx)(F,{"aria-label":`Request detail window`,id:`telemetry-window-minutes`,value:n.telemetryWindowMinutes?.toString()??``,placeholder:Z(X(n.defaults.telemetryWindowMinutes)),onValueChange:e=>r({telemetryWindowMinutes:e===``?null:Number(e)},`Detail window updated.`),options:[...Y(Ee,n.telemetryWindowMinutes,X),{value:``,label:Z(X(n.defaults.telemetryWindowMinutes))}]})}),(0,V.jsx)(Q,{label:`Max attachment size`,labelFor:`image-clamp-max-bytes`,hint:`Per image, ${Ae(n.defaults.imageClampMaxBytes)} when unset. An oversized attachment is refused before send rather than after the upstream rejects it — a block too large poisons every retry and every replayed turn. Raising this asserts your upstreams accept more; lowering it is the safer direction. Applies to the Messages and Gemini wires.`,control:(0,V.jsx)(F,{"aria-label":`Max attachment size`,id:`image-clamp-max-bytes`,value:n.imageClampMaxBytes===null?``:String(Math.round(n.imageClampMaxBytes/1048576)),placeholder:Z(Ae(n.defaults.imageClampMaxBytes)),onValueChange:e=>r({imageClampMaxBytes:e===``?null:Number(e)*1024*1024},`Attachment size limit updated.`),options:[...Y(De,n.imageClampMaxBytes===null?null:Math.round(n.imageClampMaxBytes/1048576),e=>`${e} MB`),{value:``,label:Z(Ae(n.defaults.imageClampMaxBytes))}]})}),(0,V.jsx)($,{title:`Response shaping`}),(0,V.jsx)(Q,{label:`Thinking normalization`,labelFor:`thinking-normalization`,hint:`Rewrite a provider's native thinking config into the canonical shape on turns where the user is not the final reader. Off by default: the upstream's own config is passed through untouched.`,control:(0,V.jsx)(F,{"aria-label":`Thinking normalization`,id:`thinking-normalization`,value:n.thinkingNormalizationEnabled?`on`:`off`,onValueChange:e=>{let t=e===`on`;r({thinkingNormalizationEnabled:t},t?`Thinking config will be normalized.`:`Upstream thinking config is left as sent.`)},options:[{value:`off`,label:`Off — default`},{value:`on`,label:`On`}]})}),(0,V.jsx)(Q,{label:`Reasoning summary`,labelFor:`responses-reasoning-summary`,hint:`Verbosity of the reasoning summary on the Responses wire, forced even when a request carries no reasoning block. Applies when the routed model is Responses and the client called a Chat surface.`,control:(0,V.jsx)(F,{"aria-label":`Reasoning summary`,id:`responses-reasoning-summary`,value:n.responsesReasoningSummary,onValueChange:e=>r({responsesReasoningSummary:e===`concise`||e===`detailed`?e:`auto`},`Reasoning summary updated.`),options:[{value:`auto`,label:`Auto — follow the request`},{value:`concise`,label:`Concise`},{value:`detailed`,label:`Detailed — default`}]})})]})}function Pe(){let e=we(),[t,n]=(0,B.useState)(``),[r,i]=(0,B.useState)(``),[a,o]=(0,B.useState)(``),[c,l]=(0,B.useState)(null),[u,d]=(0,B.useState)(!1);return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(Q,{label:`Current password`,labelFor:`current-password`,hint:`This is the password for this console, not for any upstream provider. Provider credentials live on each provider in Providers.`,control:(0,V.jsx)(P,{id:`current-password`,"aria-label":`Current password`,type:`password`,value:t,onChange:e=>n(e.target.value),autoComplete:`current-password`})}),(0,V.jsx)(Q,{label:`New password`,labelFor:`new-password`,hint:`Minimum 8 characters. A passphrase is easier to remember and harder to guess.`,control:(0,V.jsx)(P,{id:`new-password`,"aria-label":`New password`,type:`password`,value:r,onChange:e=>i(e.target.value),autoComplete:`new-password`})}),(0,V.jsx)(Q,{label:`Confirm new password`,labelFor:`confirm-password`,control:(0,V.jsx)(P,{id:`confirm-password`,"aria-label":`Confirm new password`,type:`password`,value:a,onChange:e=>o(e.target.value),autoComplete:`new-password`})}),c?(0,V.jsx)(`p`,{role:`alert`,className:`settings-feedback`,"data-tone":`err`,children:c}):null,u?(0,V.jsx)(`p`,{role:`status`,className:`settings-feedback`,"data-tone":`ok`,children:`Password updated.`}):null,(0,V.jsx)(`div`,{className:`settings-actions`,children:(0,V.jsx)(s,{variant:`primary`,size:`sm`,onClick:()=>{if(d(!1),r.length<8){l(`New password must be at least 8 characters.`);return}if(r!==a){l(`New password and confirmation do not match.`);return}l(null),e.mutate({currentPassword:t,newPassword:r},{onSuccess:()=>{d(!0),n(``),i(``),o(``)},onError:e=>l(T(e,`Password change failed.`))})},disabled:e.isPending||!t||!r||!a,children:e.isPending?`Updating…`:`Update password`})})]})}var Fe={security:(0,V.jsx)(Pe,{}),privacy:(0,V.jsx)(Me,{}),operations:(0,V.jsx)(Ne,{}),backup:(0,V.jsx)(W,{}),"data-management":(0,V.jsx)(Se,{})},Ie=[`security`,`privacy`];function Le(){return(0,V.jsxs)(`div`,{className:`settings-page`,children:[(0,V.jsx)(`div`,{className:`settings-grid`,children:Ie.map(e=>{let t=ke.find(t=>t.id===e);return t?(0,V.jsx)(je,{id:t.id,title:t.title,description:t.description,children:Fe[t.id]},e):null})}),ke.filter(e=>!Ie.includes(e.id)).map(e=>(0,V.jsx)(je,{id:e.id,title:e.title,description:e.description,children:Fe[e.id]},e.id))]})}export{Y as boundedOptions,Le as default};
@@ -1 +1 @@
1
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{c as i}from"./numbers-Dulqgys5.js";import{o as a,t as o}from"./query-keys-UETqfytp.js";import{$ as s,L as c,Q as l}from"./entry-BcfdW4C_.js";import{n as u}from"./input-WlyHWeG2.js";import{t as d}from"./layout-DaJ5baJr.js";import{t as f}from"./backup-file-gdKIlg8U.js";var p=e(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),m=t(n(),1),h=r();function g(){let e=s(),[t,n]=(0,m.useState)(null),[r,d]=(0,m.useState)(`admin`),[g,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(``),[w,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(`create`),[A,j]=(0,m.useState)(null),[M,N]=(0,m.useState)(null),P=(0,m.useRef)(null);(0,m.useEffect)(()=>{let t=!0;return a(`/auth/first-boot`).then(r=>{t&&(n(r.requires_setup),r.requires_setup||e(`/login`,{replace:!0}))}).catch(()=>{t&&n(!0)}),()=>{t=!1}},[e]);let F=async n=>{if(n.preventDefault(),t===!1){T(`This console already has an account. Sign in instead.`);return}if(!r.trim()){T(`Administrator username is required.`);return}if(b.length<8){T(`Administrator password must be at least 8 characters.`);return}if(b!==S){T(`Passwords do not match.`);return}D(!0),T(null);try{let t=await a(`/auth/setup`,{method:`POST`,body:JSON.stringify({username:r.trim(),password:b,...g.trim()?{display_name:g.trim()}:{}})});if(t.status!==`success`){T(t.message??`Setup failed. Please try again.`);return}c.removeQueries({queryKey:o.session.current}),e(`/login`,{replace:!0})}catch(e){if(e&&typeof e==`object`&&`message`in e){let t=e.message;if(typeof t==`string`){T(t);return}}T(`An unexpected network error occurred.`)}finally{D(!1)}},I=async t=>{D(!0),T(null);try{if(b.length<8){T(`Administrator password must be at least 8 characters.`);return}if(b!==S){T(`Passwords do not match.`);return}let n=await f(t),i=await a(`/auth/setup/restore`,{method:`POST`,body:JSON.stringify({backup:n,username:r.trim(),password:b,...g.trim()?{display_name:g.trim()}:{}})});if(i.status!==`success`){T(i.message??`Restore failed. Please try again.`);return}c.removeQueries({queryKey:o.session.current}),e(`/login`,{replace:!0})}catch(e){if(e instanceof Error){T(e.message);return}T(`An unexpected network error occurred.`)}finally{D(!1)}},L=e=>{if(j(e),T(null),e===null){N(null);return}f(e).then(async t=>{try{let n=await a(`/auth/setup/inspect`,{method:`POST`,body:JSON.stringify({backup:t})});if(n.status!==`success`){N(null),T(n.message??`Could not read that backup.`);return}N({fileName:e.name,version:n.version??0,exportedAt:n.exportedAt??``,rows:n.rows??[],total:n.total??0,warnings:n.warnings??[]})}catch{N(null)}}).catch(e=>{N(null),T(e instanceof Error?e.message:`That file is not a JSON backup.`)})};return t===!1?(0,h.jsx)(`main`,{className:`auth-viewport`,children:(0,h.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,h.jsxs)(`div`,{className:`auth-header`,children:[(0,h.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,h.jsx)(`h1`,{className:`auth-title`,children:`Account Already Registered`}),(0,h.jsx)(`p`,{className:`auth-desc`,children:`This console already has an administrator account, so setup is closed. Sign in with the account that was created.`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,h.jsx)(v,{message:`Setup is already finished. Creating a second administrator is not possible from here.`}),(0,h.jsx)(l,{to:`/login`,className:`no-underline`,children:(0,h.jsx)(i,{variant:`primary`,type:`button`,className:`w-full h-20`,children:`Go to sign in`})})]})]})}):(0,h.jsx)(`main`,{className:`auth-viewport`,children:(0,h.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,h.jsxs)(`div`,{className:`auth-header`,children:[(0,h.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,h.jsx)(`h1`,{className:`auth-title`,children:`Cartethyia Console Setup`}),O===`create`?(0,h.jsx)(`p`,{className:`auth-desc`,children:`Configure the administrator account for Cartethyia AI Gateway`}):null]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-7`,children:[(0,h.jsx)(i,{type:`button`,variant:O===`create`?`primary`:`secondary`,onClick:()=>k(`create`),children:`New account`}),(0,h.jsx)(i,{type:`button`,variant:O===`restore`?`primary`:`secondary`,onClick:()=>k(`restore`),children:`Restore`})]}),O===`restore`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`text-text-secondary text-caption`,children:`Backup file`}),(0,h.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border-subtle px-3 py-2.5`,children:[(0,h.jsx)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>P.current?.click(),disabled:E||t===null,children:`Choose file…`}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-caption text-text-secondary`,children:A?.name??`No file chosen`})]})]}),(0,h.jsx)(`input`,{ref:P,id:`setup-backup`,type:`file`,accept:`application/json,.json,.gz,application/gzip`,disabled:E,className:`hidden`,onChange:e=>{let t=e.target.files?.[0]??null;L(t),e.target.value=``}}),M?(0,h.jsx)(_,{preview:M}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 text-text-secondary text-caption`,children:`Backups carry settings only — no logins. Create the administrator for this install.`}),(0,h.jsx)(u,{label:`Administrator Username`,id:`restore-username`,value:r,onChange:e=>d(e.target.value),required:!0,autoComplete:`username`}),(0,h.jsx)(u,{label:`Master Password`,hint:`(min. 8 chars)`,id:`restore-password`,type:`password`,required:!0,minLength:8,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`}),(0,h.jsx)(u,{label:`Confirm Password`,id:`restore-confirm`,type:`password`,required:!0,minLength:8,value:S,onChange:e=>C(e.target.value),autoComplete:`new-password`})]}),w?(0,h.jsx)(v,{message:w}):null,(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,h.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>k(`create`),disabled:E,children:`Cancel`}),(0,h.jsx)(i,{type:`button`,variant:`primary`,disabled:E||t===null||A===null,onClick:()=>{A&&I(A)},children:E?`Restoring…`:`Restore this backup`})]})]}):(0,h.jsxs)(`form`,{onSubmit:F,className:`flex flex-col gap-7`,children:[(0,h.jsx)(u,{label:`Administrator Username`,id:`setup-username`,value:r,onChange:e=>d(e.target.value),required:!0,autoComplete:`username`,placeholder:`e.g. admin, risun`}),(0,h.jsx)(u,{label:`Display Name`,hint:`(optional)`,id:`display-name`,value:g,onChange:e=>y(e.target.value),autoComplete:`name`,placeholder:`e.g. Administrator, risun`}),(0,h.jsx)(u,{label:`Master Password`,hint:`(min. 8 chars)`,id:`setup-password`,type:`password`,required:!0,minLength:8,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`}),(0,h.jsx)(u,{label:`Confirm Password`,id:`setup-confirm`,type:`password`,required:!0,minLength:8,value:S,onChange:e=>C(e.target.value),autoComplete:`new-password`}),w?(0,h.jsx)(v,{message:w}):null,(0,h.jsx)(i,{variant:`primary`,type:`submit`,disabled:E||t===null,className:`w-full mt-3 h-20`,icon:(0,h.jsx)(p,{size:15}),children:E?`Initializing…`:`Complete Setup`})]})]})})}function _({preview:e}){let t=e.rows.filter(e=>!e.supported),n=e.rows.filter(e=>e.supported),r=e.exportedAt?e.exportedAt.replace(`T`,` `).slice(0,19):`unknown`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center flex-wrap gap-1.5`,children:[(0,h.jsx)(`span`,{className:`min-w-0 overflow-hidden whitespace-nowrap text-ellipsis text-body font-semibold`,title:e.fileName,children:e.fileName}),(0,h.jsxs)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border border-inner-border rounded-md bg-surface-2 text-text-secondary text-badge tabular-nums`,children:[`v`,e.version]}),t.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:[t.length,` unsupported`]}):null]}),(0,h.jsxs)(`p`,{className:`m-0 text-text-secondary text-caption`,children:[e.total,` rows across `,e.rows.length,` tables · exported `,r]}),t.length>0?(0,h.jsx)(`p`,{className:`m-0 text-caption text-status-warning`,children:t.length===e.rows.length?`None of these tables exist in this build, so nothing can be restored.`:`This build no longer has some of these tables. The rest still restores.`}):null,e.rows.length===0?(0,h.jsx)(`p`,{className:`m-0 text-text-secondary text-caption`,children:`This backup is empty.`}):(0,h.jsx)(`div`,{className:`max-h-110 overflow-auto`,children:(0,h.jsx)(d,{headers:[`Table`,`Section`,`Rows`],dense:!0,children:[...n,...t].map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{children:e.table}),(0,h.jsx)(`td`,{children:e.section}),(0,h.jsx)(`td`,{className:`text-right`,children:e.supported?e.count:(0,h.jsx)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:`unsupported`})})]},`${e.section}/${e.table}`))})})]})}function v({message:e}){return(0,h.jsx)(`div`,{className:`py-5 px-7 rounded-control bg-red-soft text-red text-caption font-medium`,role:`alert`,children:e})}export{g as default};
1
+ import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{c as i}from"./numbers-Dulqgys5.js";import{o as a,t as o}from"./query-keys-UETqfytp.js";import{$ as s,L as c,Q as l}from"./entry-BrksMru8.js";import{n as u}from"./input-WlyHWeG2.js";import{t as d}from"./layout-DaJ5baJr.js";import{t as f}from"./backup-file-gdKIlg8U.js";var p=e(`user-plus`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}],[`line`,{x1:`19`,x2:`19`,y1:`8`,y2:`14`,key:`1bvyxn`}],[`line`,{x1:`22`,x2:`16`,y1:`11`,y2:`11`,key:`1shjgl`}]]),m=t(n(),1),h=r();function g(){let e=s(),[t,n]=(0,m.useState)(null),[r,d]=(0,m.useState)(`admin`),[g,y]=(0,m.useState)(``),[b,x]=(0,m.useState)(``),[S,C]=(0,m.useState)(``),[w,T]=(0,m.useState)(null),[E,D]=(0,m.useState)(!1),[O,k]=(0,m.useState)(`create`),[A,j]=(0,m.useState)(null),[M,N]=(0,m.useState)(null),P=(0,m.useRef)(null);(0,m.useEffect)(()=>{let t=!0;return a(`/auth/first-boot`).then(r=>{t&&(n(r.requires_setup),r.requires_setup||e(`/login`,{replace:!0}))}).catch(()=>{t&&n(!0)}),()=>{t=!1}},[e]);let F=async n=>{if(n.preventDefault(),t===!1){T(`This console already has an account. Sign in instead.`);return}if(!r.trim()){T(`Administrator username is required.`);return}if(b.length<8){T(`Administrator password must be at least 8 characters.`);return}if(b!==S){T(`Passwords do not match.`);return}D(!0),T(null);try{let t=await a(`/auth/setup`,{method:`POST`,body:JSON.stringify({username:r.trim(),password:b,...g.trim()?{display_name:g.trim()}:{}})});if(t.status!==`success`){T(t.message??`Setup failed. Please try again.`);return}c.removeQueries({queryKey:o.session.current}),e(`/login`,{replace:!0})}catch(e){if(e&&typeof e==`object`&&`message`in e){let t=e.message;if(typeof t==`string`){T(t);return}}T(`An unexpected network error occurred.`)}finally{D(!1)}},I=async t=>{D(!0),T(null);try{if(b.length<8){T(`Administrator password must be at least 8 characters.`);return}if(b!==S){T(`Passwords do not match.`);return}let n=await f(t),i=await a(`/auth/setup/restore`,{method:`POST`,body:JSON.stringify({backup:n,username:r.trim(),password:b,...g.trim()?{display_name:g.trim()}:{}})});if(i.status!==`success`){T(i.message??`Restore failed. Please try again.`);return}c.removeQueries({queryKey:o.session.current}),e(`/login`,{replace:!0})}catch(e){if(e instanceof Error){T(e.message);return}T(`An unexpected network error occurred.`)}finally{D(!1)}},L=e=>{if(j(e),T(null),e===null){N(null);return}f(e).then(async t=>{try{let n=await a(`/auth/setup/inspect`,{method:`POST`,body:JSON.stringify({backup:t})});if(n.status!==`success`){N(null),T(n.message??`Could not read that backup.`);return}N({fileName:e.name,version:n.version??0,exportedAt:n.exportedAt??``,rows:n.rows??[],total:n.total??0,warnings:n.warnings??[]})}catch{N(null)}}).catch(e=>{N(null),T(e instanceof Error?e.message:`That file is not a JSON backup.`)})};return t===!1?(0,h.jsx)(`main`,{className:`auth-viewport`,children:(0,h.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,h.jsxs)(`div`,{className:`auth-header`,children:[(0,h.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,h.jsx)(`h1`,{className:`auth-title`,children:`Account Already Registered`}),(0,h.jsx)(`p`,{className:`auth-desc`,children:`This console already has an administrator account, so setup is closed. Sign in with the account that was created.`})]}),(0,h.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,h.jsx)(v,{message:`Setup is already finished. Creating a second administrator is not possible from here.`}),(0,h.jsx)(l,{to:`/login`,className:`no-underline`,children:(0,h.jsx)(i,{variant:`primary`,type:`button`,className:`w-full h-20`,children:`Go to sign in`})})]})]})}):(0,h.jsx)(`main`,{className:`auth-viewport`,children:(0,h.jsxs)(`div`,{className:`card-solid auth-window`,children:[(0,h.jsxs)(`div`,{className:`auth-header`,children:[(0,h.jsx)(`div`,{className:`auth-logo`,"aria-hidden":`true`}),(0,h.jsx)(`h1`,{className:`auth-title`,children:`Cartethyia Console Setup`}),O===`create`?(0,h.jsx)(`p`,{className:`auth-desc`,children:`Configure the administrator account for Cartethyia AI Gateway`}):null]}),(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 mb-7`,children:[(0,h.jsx)(i,{type:`button`,variant:O===`create`?`primary`:`secondary`,onClick:()=>k(`create`),children:`New account`}),(0,h.jsx)(i,{type:`button`,variant:O===`restore`?`primary`:`secondary`,onClick:()=>k(`restore`),children:`Restore`})]}),O===`restore`?(0,h.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,h.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,h.jsx)(`span`,{className:`text-text-secondary text-caption`,children:`Backup file`}),(0,h.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border border-border-subtle px-3 py-2.5`,children:[(0,h.jsx)(i,{type:`button`,variant:`secondary`,size:`sm`,onClick:()=>P.current?.click(),disabled:E||t===null,children:`Choose file…`}),(0,h.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-caption text-text-secondary`,children:A?.name??`No file chosen`})]})]}),(0,h.jsx)(`input`,{ref:P,id:`setup-backup`,type:`file`,accept:`application/json,.json,.gz,application/gzip`,disabled:E,className:`hidden`,onChange:e=>{let t=e.target.files?.[0]??null;L(t),e.target.value=``}}),M?(0,h.jsx)(_,{preview:M}):null,(0,h.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,h.jsx)(`p`,{className:`m-0 text-text-secondary text-caption`,children:`Backups carry settings only — no logins. Create the administrator for this install.`}),(0,h.jsx)(u,{label:`Administrator Username`,id:`restore-username`,value:r,onChange:e=>d(e.target.value),required:!0,autoComplete:`username`}),(0,h.jsx)(u,{label:`Master Password`,hint:`(min. 8 chars)`,id:`restore-password`,type:`password`,required:!0,minLength:8,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`}),(0,h.jsx)(u,{label:`Confirm Password`,id:`restore-confirm`,type:`password`,required:!0,minLength:8,value:S,onChange:e=>C(e.target.value),autoComplete:`new-password`})]}),w?(0,h.jsx)(v,{message:w}):null,(0,h.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,h.jsx)(i,{type:`button`,variant:`secondary`,onClick:()=>k(`create`),disabled:E,children:`Cancel`}),(0,h.jsx)(i,{type:`button`,variant:`primary`,disabled:E||t===null||A===null,onClick:()=>{A&&I(A)},children:E?`Restoring…`:`Restore this backup`})]})]}):(0,h.jsxs)(`form`,{onSubmit:F,className:`flex flex-col gap-7`,children:[(0,h.jsx)(u,{label:`Administrator Username`,id:`setup-username`,value:r,onChange:e=>d(e.target.value),required:!0,autoComplete:`username`,placeholder:`e.g. admin, risun`}),(0,h.jsx)(u,{label:`Display Name`,hint:`(optional)`,id:`display-name`,value:g,onChange:e=>y(e.target.value),autoComplete:`name`,placeholder:`e.g. Administrator, risun`}),(0,h.jsx)(u,{label:`Master Password`,hint:`(min. 8 chars)`,id:`setup-password`,type:`password`,required:!0,minLength:8,value:b,onChange:e=>x(e.target.value),autoComplete:`new-password`}),(0,h.jsx)(u,{label:`Confirm Password`,id:`setup-confirm`,type:`password`,required:!0,minLength:8,value:S,onChange:e=>C(e.target.value),autoComplete:`new-password`}),w?(0,h.jsx)(v,{message:w}):null,(0,h.jsx)(i,{variant:`primary`,type:`submit`,disabled:E||t===null,className:`w-full mt-3 h-20`,icon:(0,h.jsx)(p,{size:15}),children:E?`Initializing…`:`Complete Setup`})]})]})})}function _({preview:e}){let t=e.rows.filter(e=>!e.supported),n=e.rows.filter(e=>e.supported),r=e.exportedAt?e.exportedAt.replace(`T`,` `).slice(0,19):`unknown`;return(0,h.jsxs)(`div`,{className:`flex flex-col gap-2 p-3 border border-inner-border rounded-control bg-surface-2`,children:[(0,h.jsxs)(`div`,{className:`flex items-center flex-wrap gap-1.5`,children:[(0,h.jsx)(`span`,{className:`min-w-0 overflow-hidden whitespace-nowrap text-ellipsis text-body font-semibold`,title:e.fileName,children:e.fileName}),(0,h.jsxs)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border border-inner-border rounded-md bg-surface-2 text-text-secondary text-badge tabular-nums`,children:[`v`,e.version]}),t.length>0?(0,h.jsxs)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:[t.length,` unsupported`]}):null]}),(0,h.jsxs)(`p`,{className:`m-0 text-text-secondary text-caption`,children:[e.total,` rows across `,e.rows.length,` tables · exported `,r]}),t.length>0?(0,h.jsx)(`p`,{className:`m-0 text-caption text-status-warning`,children:t.length===e.rows.length?`None of these tables exist in this build, so nothing can be restored.`:`This build no longer has some of these tables. The rest still restores.`}):null,e.rows.length===0?(0,h.jsx)(`p`,{className:`m-0 text-text-secondary text-caption`,children:`This backup is empty.`}):(0,h.jsx)(`div`,{className:`max-h-110 overflow-auto`,children:(0,h.jsx)(d,{headers:[`Table`,`Section`,`Rows`],dense:!0,children:[...n,...t].map(e=>(0,h.jsxs)(`tr`,{children:[(0,h.jsx)(`td`,{children:e.table}),(0,h.jsx)(`td`,{children:e.section}),(0,h.jsx)(`td`,{className:`text-right`,children:e.supported?e.count:(0,h.jsx)(`span`,{className:`inline-flex items-center flex-none px-3.5 py-px border rounded-md bg-surface-2 text-badge tabular-nums border-warning-line text-status-warning`,children:`unsupported`})})]},`${e.section}/${e.table}`))})})]})}function v({message:e}){return(0,h.jsx)(`div`,{className:`py-5 px-7 rounded-control bg-red-soft text-red text-caption font-medium`,role:`alert`,children:e})}export{g as default};
@@ -1 +1 @@
1
- import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{m as i}from"./numbers-Dulqgys5.js";import{lt as a}from"./entry-BcfdW4C_.js";import{n as o}from"./stack-B1w5BM0u.js";var s=e(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),c=e(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),l=t(n(),1),u=r();function d({items:e,onReorder:t,disabled:n=!1,gap:r=`10px`,renderItem:d,label:f}){let[p,m]=(0,l.useState)(null),[h,g]=(0,l.useState)(null),_=(0,l.useRef)(null),v=()=>{_.current=null,m(null),g(null)},y=(n,r)=>{if(n===r)return;let i=e.map(e=>e.id),a=i.indexOf(n),o=i.indexOf(r);a!==-1&&o!==-1&&(i.splice(o,0,...i.splice(a,1)),t(i))};return(0,u.jsx)(`div`,{role:`list`,"aria-label":f,className:i(`flex flex-col min-w-0`,o(r)??`gap-5`),children:e.map((r,o)=>{let l=p===r.id,f=h===r.id&&p!==null&&p!==r.id,b=r=>{let i=o+r;if(n||i<0||i>=e.length)return;let a=e.map(e=>e.id),[s]=a.splice(o,1);s!==void 0&&(a.splice(i,0,s),t(a))};return(0,u.jsxs)(`div`,{role:`listitem`,className:i(`relative flex items-stretch gap-5 min-w-0 rounded-card transition-opacity duration-150 ease-spring`,l&&`opacity-50`,f&&`before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-accent before:content-['']`),"data-dragging":l?`true`:void 0,"data-drop-target":f?`true`:void 0,onDragOver:e=>{n||_.current===null||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,h!==r.id&&g(r.id))},onDrop:e=>{e.preventDefault();let t=_.current;t!==null&&y(t,r.id),v()},children:[(0,u.jsxs)(`div`,{className:`flex flex-none flex-col items-center gap-1 pt-4 text-text-tertiary select-none`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,u.jsx)(`span`,{className:`font-mono text-badge tabular-nums leading-none`,children:o+1}),(0,u.jsx)(`button`,{type:`button`,draggable:!n,"aria-label":`Drag item at position ${o+1} to reorder`,title:`Drag to reorder`,disabled:n,onDragStart:e=>{_.current=r.id,m(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragEnd:v,className:`grid size-7 cursor-grab place-items-center rounded-control text-text-tertiary hover:bg-hover active:cursor-grabbing disabled:cursor-not-allowed`,children:(0,u.jsx)(c,{size:14})})]}),(0,u.jsxs)(`div`,{className:`flex gap-1`,children:[(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} up`,title:`Move up`,disabled:n||o===0,onClick:()=>b(-1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(s,{size:14})}),(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} down`,title:`Move down`,disabled:n||o===e.length-1,onClick:()=>b(1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(a,{size:14})})]})]}),(0,u.jsx)(`div`,{className:`flex-auto min-w-0`,children:d(r,o)})]},r.id)})})}export{d as t};
1
+ import{n as e,o as t,r as n,t as r}from"./jsx-runtime-CXUMngI_.js";import{m as i}from"./numbers-Dulqgys5.js";import{lt as a}from"./entry-BrksMru8.js";import{n as o}from"./stack-B1w5BM0u.js";var s=e(`chevron-up`,[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]),c=e(`grip-vertical`,[[`circle`,{cx:`9`,cy:`12`,r:`1`,key:`1vctgf`}],[`circle`,{cx:`9`,cy:`5`,r:`1`,key:`hp0tcf`}],[`circle`,{cx:`9`,cy:`19`,r:`1`,key:`fkjjf6`}],[`circle`,{cx:`15`,cy:`12`,r:`1`,key:`1tmaij`}],[`circle`,{cx:`15`,cy:`5`,r:`1`,key:`19l28e`}],[`circle`,{cx:`15`,cy:`19`,r:`1`,key:`f4zoj3`}]]),l=t(n(),1),u=r();function d({items:e,onReorder:t,disabled:n=!1,gap:r=`10px`,renderItem:d,label:f}){let[p,m]=(0,l.useState)(null),[h,g]=(0,l.useState)(null),_=(0,l.useRef)(null),v=()=>{_.current=null,m(null),g(null)},y=(n,r)=>{if(n===r)return;let i=e.map(e=>e.id),a=i.indexOf(n),o=i.indexOf(r);a!==-1&&o!==-1&&(i.splice(o,0,...i.splice(a,1)),t(i))};return(0,u.jsx)(`div`,{role:`list`,"aria-label":f,className:i(`flex flex-col min-w-0`,o(r)??`gap-5`),children:e.map((r,o)=>{let l=p===r.id,f=h===r.id&&p!==null&&p!==r.id,b=r=>{let i=o+r;if(n||i<0||i>=e.length)return;let a=e.map(e=>e.id),[s]=a.splice(o,1);s!==void 0&&(a.splice(i,0,s),t(a))};return(0,u.jsxs)(`div`,{role:`listitem`,className:i(`relative flex items-stretch gap-5 min-w-0 rounded-card transition-opacity duration-150 ease-spring`,l&&`opacity-50`,f&&`before:absolute before:inset-x-0 before:top-0 before:h-0.5 before:bg-accent before:content-['']`),"data-dragging":l?`true`:void 0,"data-drop-target":f?`true`:void 0,onDragOver:e=>{n||_.current===null||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,h!==r.id&&g(r.id))},onDrop:e=>{e.preventDefault();let t=_.current;t!==null&&y(t,r.id),v()},children:[(0,u.jsxs)(`div`,{className:`flex flex-none flex-col items-center gap-1 pt-4 text-text-tertiary select-none`,children:[(0,u.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,u.jsx)(`span`,{className:`font-mono text-badge tabular-nums leading-none`,children:o+1}),(0,u.jsx)(`button`,{type:`button`,draggable:!n,"aria-label":`Drag item at position ${o+1} to reorder`,title:`Drag to reorder`,disabled:n,onDragStart:e=>{_.current=r.id,m(r.id),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,r.id)},onDragEnd:v,className:`grid size-7 cursor-grab place-items-center rounded-control text-text-tertiary hover:bg-hover active:cursor-grabbing disabled:cursor-not-allowed`,children:(0,u.jsx)(c,{size:14})})]}),(0,u.jsxs)(`div`,{className:`flex gap-1`,children:[(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} up`,title:`Move up`,disabled:n||o===0,onClick:()=>b(-1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(s,{size:14})}),(0,u.jsx)(`button`,{type:`button`,"aria-label":`Move item ${o+1} down`,title:`Move down`,disabled:n||o===e.length-1,onClick:()=>b(1),className:`grid size-7 place-items-center rounded-control text-text-tertiary hover:bg-hover disabled:cursor-not-allowed disabled:opacity-40`,children:(0,u.jsx)(a,{size:14})})]})]}),(0,u.jsx)(`div`,{className:`flex-auto min-w-0`,children:d(r,o)})]},r.id)})})}export{d as t};