@yansigit/opencodex 2.36.1-dev.20260829.48 → 2.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/gui/dist/assets/{ApiKeys-LOOFiZfv.js → ApiKeys-CsmNyf4I.js} +1 -1
- package/gui/dist/assets/{Claude-BwKzpXe3.js → Claude-B4sHsGTD.js} +1 -1
- package/gui/dist/assets/{CodexSet-B5qi9KeE.js → CodexSet-BuAQ4YQn.js} +1 -1
- package/gui/dist/assets/{FileIntegrationPage-B0sUef6W.js → FileIntegrationPage-BC65sEaS.js} +1 -1
- package/gui/dist/assets/{Grok-bsb4n-f4.js → Grok-DNJWlISf.js} +1 -1
- package/gui/dist/assets/{Integrations-CSMwFDvM.js → Integrations-vGJshFZK.js} +2 -2
- package/gui/dist/assets/{IntegrationsOverview-CTORdKJA.js → IntegrationsOverview-DYMkDFHE.js} +1 -1
- package/gui/dist/assets/{Logs-BWYbfELf.js → Logs-Coc7_RPP.js} +1 -1
- package/gui/dist/assets/{Models-CexEtdT1.js → Models-CKVT8Meb.js} +1 -1
- package/gui/dist/assets/{NumberStepper-BapSFQnW.js → NumberStepper-Dug4wR8n.js} +1 -1
- package/gui/dist/assets/{Providers-BwUFeAgA.js → Providers-DyaCHRWL.js} +1 -1
- package/gui/dist/assets/{RestoreDialog-CD8piq90.js → RestoreDialog-BpuvVU2w.js} +1 -1
- package/gui/dist/assets/{Startup-BgX731C2.js → Startup-DAUQqNEN.js} +1 -1
- package/gui/dist/assets/{Storage-Bgq7HphP.js → Storage-DfP95SlJ.js} +1 -1
- package/gui/dist/assets/{Subagents-ChxItbeF.js → Subagents-CMNsZLfk.js} +1 -1
- package/gui/dist/assets/{Usage-BkylzP50.js → Usage-ESFRfBMO.js} +1 -1
- package/gui/dist/assets/{codex-stale-banner-D4gvSWnO.js → codex-stale-banner-W4FhikN7.js} +1 -1
- package/gui/dist/assets/{data-surface-BtO3lwam.js → data-surface-B8PX8rjm.js} +1 -1
- package/gui/dist/assets/{data-surface-pCXChiBf.js → data-surface-CETFXqiA.js} +1 -1
- package/gui/dist/assets/{index-CNopOid3.js → index-DHQHBRhb.js} +3 -3
- package/gui/dist/assets/{model-display-CiUpg8T9.js → model-display-OBTJhQwT.js} +1 -1
- package/gui/dist/assets/{provider-payload-b2jlS-On.js → provider-payload-CJRJUn7w.js} +1 -1
- package/gui/dist/assets/{section-tabs-BP7gEPK6.js → section-tabs-B8sLMiz6.js} +1 -1
- package/gui/dist/assets/shared-DI18-uF7.js +69 -0
- package/gui/dist/index.html +2 -2
- package/package.json +3 -1
- package/src/adapters/base.ts +26 -0
- package/src/adapters/cursor/catalog.ts +541 -0
- package/src/adapters/cursor/cursor-errors.ts +15 -0
- package/src/adapters/cursor/discovery.ts +34 -41
- package/src/adapters/cursor/envelope-echo.ts +128 -0
- package/src/adapters/cursor/request-builder.ts +19 -12
- package/src/adapters/cursor/tool-definitions.ts +2 -1
- package/src/adapters/cursor/tool-result-normalize.ts +23 -31
- package/src/adapters/cursor.ts +21 -2
- package/src/adapters/exec-tool-result-normalize.ts +99 -0
- package/src/adapters/google-antigravity-replay.ts +71 -2
- package/src/adapters/google.ts +19 -4
- package/src/adapters/kiro-constants.ts +12 -0
- package/src/adapters/kiro.ts +128 -11
- package/src/adapters/openai-chat.ts +16 -2
- package/src/adapters/openai-responses.ts +15 -2
- package/src/adapters/tool-catalog-nudge.ts +2 -1
- package/src/adapters/xai-web-search.ts +10 -14
- package/src/claude/outbound.ts +14 -3
- package/src/cli/access.ts +46 -3
- package/src/cli/account-api.ts +93 -16
- package/src/cli/account-extended.ts +262 -36
- package/src/cli/account-main.ts +12 -12
- package/src/cli/account.ts +40 -10
- package/src/cli/agent.ts +8 -1
- package/src/cli/capabilities-command.ts +94 -0
- package/src/cli/capabilities.ts +535 -0
- package/src/cli/claude-desktop.ts +31 -11
- package/src/cli/dispatch.ts +195 -27
- package/src/cli/doctor.ts +100 -1
- package/src/cli/help.ts +11 -2
- package/src/cli/index.ts +19 -3
- package/src/cli/inspect.ts +230 -0
- package/src/cli/observe.ts +11 -3
- package/src/cli/registry.ts +34 -2
- package/src/cli/runtime-api.ts +51 -7
- package/src/cli/status.ts +16 -0
- package/src/cli/storage.ts +234 -0
- package/src/cli/system-command.ts +16 -0
- package/src/cli/usage-report.ts +52 -2
- package/src/cli/version-skew.ts +46 -0
- package/src/codex/account-label.ts +21 -0
- package/src/codex/catalog/provider-fetch.ts +4 -0
- package/src/codex/transition-state.ts +12 -3
- package/src/compatibility/openai-responses.ts +9 -1
- package/src/generated/compatibility-version.json +94 -58
- package/src/integrations/ownership-policy.ts +24 -5
- package/src/integrations/ownership.ts +36 -2
- package/src/integrations/state.ts +40 -7
- package/src/integrations/writer.ts +21 -3
- package/src/lib/admin-secrets.ts +24 -0
- package/src/lib/errors.ts +25 -1
- package/src/lib/service-secrets.ts +15 -0
- package/src/oauth/store.ts +16 -6
- package/src/providers/label.ts +34 -1
- package/src/responses/turn-termination.ts +107 -0
- package/src/server/management/logs-usage-routes.ts +5 -27
- package/src/server/management/route-registry.ts +317 -0
- package/src/server/proxy-liveness.ts +27 -4
- package/src/server/request-log.ts +37 -17
- package/src/server/responses/core.ts +80 -4
- package/src/server/responses/policy-fallback.ts +1 -1
- package/src/service.ts +34 -0
- package/src/storage/policy-job.ts +14 -4
- package/src/storage/policy.ts +79 -33
- package/src/usage/log.ts +32 -6
- package/src/usage/summary.ts +22 -34
- package/gui/dist/assets/shared-BdYGV-yJ.js +0 -69
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,h as t}from"./shared-
|
|
1
|
+
import{_ as e,h as t}from"./shared-DI18-uF7.js";import{Q as n,at as r,ht as i,it as a}from"./index-DHQHBRhb.js";var o=e(t(),1),s={"gpt-5.6-sol":i,"gpt-5.6-terra":n,"gpt-5.6-luna":r,"gpt-daybreak-blue-latest":i,"daybreak-blue-latest":i,"daybreak-red-latest":a},c={width:14,height:14,flexShrink:0,verticalAlign:`text-bottom`};function l(e){return e.slice(e.lastIndexOf(`/`)+1)}function u(e){return s[e]??s[l(e)]??null}function d(e){let t=u(e);return t?(0,o.createElement)(`span`,{className:`model-label`},(0,o.createElement)(t,{style:c,"aria-hidden":!0}),e):e}export{d as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,c as t,h as n,m as r,s as i}from"./shared-BdYGV-yJ.js";import{I as a,M as o,N as s,P as c,Q as l,U as u,X as d,Y as f,_ as p,_t as m,ct as h,dt as g,it as _,lt as v,ot as y,rt as b,u as x,v as S,xt as C,yt as w}from"./index-CNopOid3.js";import{n as T,t as E}from"./NumberStepper-BapSFQnW.js";import{n as D,t as O}from"./intl-formatters-CTcuZoAe.js";var k=e(n(),1),A=e=>({step:e?`oauth-waiting`:`pick`,id:``,error:``,authUrl:``,manualCode:``,manualCodeState:`idle`,statusNotice:``,statusTone:`ok`,flowId:null});function j(e,t){switch(t.type){case`set-step`:return{...e,step:t.step};case`set-id`:return{...e,id:t.id};case`set-error`:return{...e,error:t.error};case`set-auth-url`:return{...e,authUrl:t.authUrl};case`set-manual-code`:return{...e,manualCode:t.manualCode};case`set-manual-code-state`:return{...e,manualCodeState:t.manualCodeState};case`set-status-notice`:return{...e,statusNotice:t.statusNotice,statusTone:t.statusTone??e.statusTone};case`set-flow-id`:return{...e,flowId:t.flowId};case`clear-manual-code`:return{...e,manualCode:``,manualCodeState:`idle`,statusNotice:``,statusTone:`ok`};case`reset-oauth-start`:return{...e,error:``,statusNotice:``,statusTone:`ok`,flowId:null};case`oauth-code-submitted`:return{...e,error:``,manualCode:``,manualCodeState:`waiting`,statusTone:`ok`,statusNotice:``};default:return e}}var M=r();function N({id:e,error:n,onIdChange:r,onStartOAuth:i,onClose:a}){let o=t();return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{style:{marginBottom:4},children:o(`codexAuth.addTitle`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:o(`codexAuth.addPickDesc`)}),(0,M.jsx)(`label`,{className:`field-label`,htmlFor:`codex-account-id-input`,children:o(`codexAuth.addIdLabel`)}),(0,M.jsx)(`input`,{id:`codex-account-id-input`,className:`input`,placeholder:o(`codexAuth.addIdPlaceholder`),value:e,onChange:e=>r(e.target.value),style:{marginBottom:12}}),(0,M.jsx)(`button`,{type:`button`,className:`list-row`,onClick:i,style:{marginBottom:8},children:(0,M.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,M.jsx)(l,{width:20}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`title`,children:o(`codexAuth.oauthLogin`)}),(0,M.jsx)(`div`,{className:`sub`,children:o(`codexAuth.oauthDesc`)})]})]})}),n&&(0,M.jsx)(`div`,{className:`notice notice-err`,style:{marginTop:8},children:n}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:a,style:{width:`100%`},children:o(`codexAuth.cancel`)})]})}function P(e){if(!e)return null;let t=e.trim();return t?t.length<=4?`account-…`:`account-…${t.slice(-4)}`:null}function F(e){return P(e)??`account-…`}function I(e){return e===`healthy`?`ok`:e===`cooldown`?`muted`:e===`reauth_required`||e===`warning`?`warn`:`muted`}function L(e){let t=I(e);return t===`ok`?`badge badge-green`:t===`warn`?`badge badge-amber`:`badge badge-muted`}function R(e){return e===`reauth_required`}function ee(e){return!!e?.needsReauth||R(e?.health?.status)}function z(e){return e===`cooldown`}function B(e){return e===`warning`||e===`reauth_required`}function V(e){if(!e||e.status===`healthy`)return null;if(e.status===`cooldown`)return e.reason===`rate_limit`?`pws.healthLabel.rateLimited`:`pws.healthLabel.quotaLimited`;if(e.status===`reauth_required`)return e.reason===`refresh_failed`?`pws.healthLabel.refreshFailed`:`pws.healthLabel.reauthRequired`;switch(e.reason){case`refresh_conflict`:return`pws.healthLabel.credentialConflict`;case`metadata_mismatch`:return`pws.healthLabel.metadataMismatch`;case`stale_credentials`:return`pws.healthLabel.refreshFailed`;default:return`pws.healthLabel.reauthRequired`}}function te(e,t){let n=V(t);return n?e(n):null}function H(e,t,n,r){if(!r||r.status===`healthy`)return null;let i=n===`__main__`?e(`codexAuth.mainAccount`):F(n);if(r.status===`cooldown`){let n=r.until?new Date(r.until).toLocaleString():``;return e(r.reason===`rate_limit`?`pws.healthSummary.rateLimited`:`pws.healthSummary.quotaLimited`,{provider:t,account:i,until:n})}return r.status===`reauth_required`?e(`pws.healthSummary.reauthRequired`,{provider:t,account:i}):r.reason===`refresh_conflict`?e(`pws.healthSummary.credentialConflict`,{provider:t,account:i}):r.reason===`metadata_mismatch`?e(`pws.healthSummary.metadataMismatch`,{provider:t,account:i}):e(`pws.healthSummary.staleCredentials`,{provider:t,account:i})}async function U(e){let t=navigator.clipboard?.writeText?.bind(navigator.clipboard);if(t)try{return await t(e),!0}catch{}return W(e)}function W(e){if(typeof document>`u`||typeof document.execCommand!=`function`)return!1;let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.setAttribute(`aria-hidden`,`true`),t.style.position=`fixed`,t.style.top=`0`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.remove()}}function G(e,t){return e(t?t===`copied`?`pws.doctorCopied`:`pws.doctorCopyUnavailable`:`pws.copyDoctor`)}var ne=2500;function re(){let[e,t]=(0,k.useState)(null),n=(0,k.useRef)(null),r=(0,k.useRef)(0),i=(0,k.useCallback)(()=>{n.current&&=(clearTimeout(n.current),null)},[]);return(0,k.useEffect)(()=>i,[i]),{outcomeFor:(0,k.useCallback)(t=>e&&Object.is(e.scope,t)?e.outcome:null,[e]),copy:(0,k.useCallback)((e,a)=>{let o=++r.current;U(e).then(e=>{r.current===o&&(i(),t({scope:a,outcome:e?`copied`:`unavailable`}),n.current=setTimeout(()=>{n.current=null,r.current===o&&t(null)},ne))})},[i])}}function K({url:e}){let n=t(),{outcomeFor:r,copy:i}=re();if(!e)return null;let a=r(e),o=n(a===`copied`?`prov.linkCopied`:a===`unavailable`?`prov.linkCopyUnavailable`:`prov.copyLink`);return(0,M.jsxs)(`div`,{className:`login-url-block`,children:[(0,M.jsx)(`code`,{className:`login-url-block-text`,children:e}),(0,M.jsxs)(`div`,{className:`login-url-block-actions`,children:[(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>i(e,e),children:[(0,M.jsx)(b,{style:{width:13,height:13},"aria-hidden":`true`}),(0,M.jsx)(`span`,{"aria-live":`polite`,children:o})]}),(0,M.jsxs)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`login-url-block-open`,children:[(0,M.jsx)(d,{style:{width:13,height:13},"aria-hidden":`true`}),` `,n(`prov.didntOpen`)]})]})]})}function ie({hint:e,paste:n}){let r=t(),i=re(),a=e.deviceCode??``,o=e.url??``;if(!a&&!o&&!e.instructions&&!n)return null;let s=i.outcomeFor(a),c=r(s===`copied`?`prov.codeCopied`:s===`unavailable`?`prov.linkCopyUnavailable`:`prov.copyCode`);return(0,M.jsxs)(`div`,{className:`login-hint`,children:[a&&(0,M.jsxs)(`div`,{className:`login-hint-device pwi-device-code-wrap`,children:[(0,M.jsx)(`span`,{className:`text-label`,children:r(`prov.deviceCode`)}),(0,M.jsx)(`code`,{className:`login-hint-device-code pwi-device-code`,children:a}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>i.copy(a,a),children:(0,M.jsx)(`span`,{"aria-live":`polite`,children:c})})]}),(0,M.jsx)(K,{url:o}),e.instructions&&(0,M.jsx)(`div`,{className:`muted text-label`,children:e.instructions}),n&&(0,M.jsxs)(`div`,{className:`login-hint-paste`,children:[(0,M.jsx)(`div`,{className:`muted text-label`,children:r(`prov.pasteRedirectHint`)}),(0,M.jsxs)(`div`,{className:`login-hint-paste-row`,children:[(0,M.jsx)(`input`,{type:`text`,autoComplete:`off`,spellCheck:!1,value:n.value,onChange:e=>n.onChange(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),n.onSubmit())},placeholder:r(`prov.pasteRedirect`),"aria-label":r(`prov.pasteRedirect`),disabled:n.busy,className:`input text-label login-hint-paste-input`}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:n.busy||n.disabled===!0||!n.value.trim(),onClick:n.onSubmit,children:n.busy?n.submittingLabel??r(`prov.pasteSubmitting`):r(`prov.pasteSubmit`)})]}),n.message&&(0,M.jsx)(`div`,{className:`text-label`,"aria-live":`polite`,style:{color:n.ok?`var(--accent-hover)`:`var(--amber)`},children:n.message})]})]})}function ae({reauthAccountId:e,authUrl:n,manualCode:r,manualCodeBusy:i,manualCodeWaiting:a,statusNotice:o,statusTone:s,flowId:c,error:l,onManualCodeChange:u,onSubmitManualCode:d,onClose:f}){let p=t();return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{style:{marginBottom:4},children:p(e?`codexAuth.reauthenticate`:`codexAuth.oauthLogin`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:p(`codexAuth.oauthWaiting`)}),(0,M.jsx)(ie,{hint:{url:n},paste:{value:r,busy:i,disabled:i||a||!r.trim()||!c,submittingLabel:p(`codexAuth.oauthSubmittingCode`),message:``,ok:!0,onChange:u,onSubmit:d}}),o&&(0,M.jsx)(`div`,{className:s===`warn`?`notice-warn`:`notice notice-ok`,role:`status`,"aria-live":`polite`,style:{marginTop:12},children:o}),l&&(0,M.jsx)(`div`,{className:`notice notice-err`,style:{marginTop:12},children:l}),(0,M.jsx)(`div`,{style:{textAlign:`center`,padding:`24px 0`},children:(0,M.jsx)(`span`,{className:`spin`,style:{width:24,height:24}})}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:f,style:{width:`100%`},children:p(`codexAuth.cancel`)})]})}var q=`ocx.oauth.openBrowser`;function J(){try{let e=window.localStorage.getItem(q);return e===`0`?!1:e===`1`||void 0}catch{return}}function oe(){let e=J();return e===void 0?{}:{openBrowser:e}}function Y(e){try{window.localStorage.setItem(q,e?`1`:`0`)}catch{}}function se(e){if(typeof e!=`object`||!e||Array.isArray(e))return{catalogRefreshPending:!1};let t=Object.getOwnPropertyDescriptor(e,`catalogRefreshPending`);return{catalogRefreshPending:t!==void 0&&`value`in t&&t.value===!0}}function ce({apiBase:e,reauthAccountId:t,ui:n,dispatch:r,t:i}){let a=(0,k.useRef)(!0),c=(0,k.useRef)(0),l=(0,k.useRef)(!1),u=(0,k.useRef)(null),d=(0,k.useRef)(null),f=(0,k.useRef)(null),m=(0,k.useRef)(null),h=(0,k.useRef)(n.manualCodeState),g=(0,k.useRef)(null),_=(0,k.useRef)(null),v=(0,k.useRef)(()=>{}),y=(0,k.useRef)(()=>{}),b=n.manualCodeState===`submitting`,x=n.manualCodeState===`waiting`;(0,k.useEffect)(()=>{h.current=n.manualCodeState},[n.manualCodeState]),(0,k.useEffect)(()=>{m.current=n.flowId},[n.flowId]);let S=(0,k.useCallback)(()=>{u.current&&=(u.current(),null),d.current&&=(clearTimeout(d.current),null),f.current?.abort(),f.current=null,l.current=!1},[]),C=(0,k.useCallback)(()=>{r({type:`clear-manual-code`}),c.current=0},[r]),w=(0,k.useCallback)(async()=>{C();let t=m.current;m.current=null,r({type:`set-flow-id`,flowId:null}),r({type:`set-auth-url`,authUrl:``}),S(),g.current?.abort(),g.current=null,t&&await fetch(`${e}/api/codex-auth/login/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({flowId:t})}).catch(()=>{})},[e,C,r,S]);(0,k.useEffect)(()=>(a.current=!0,()=>{C(),a.current=!1,_.current=null,g.current?.abort(),g.current=null;let t=m.current;m.current=null,r({type:`set-flow-id`,flowId:null}),S(),t&&fetch(`${e}/api/codex-auth/login/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({flowId:t})}).catch(()=>{})}),[e,C,r,S]);let T=(0,k.useCallback)((e,t)=>{v.current=e,y.current=t},[]),E=(0,k.useCallback)(()=>{n.step===`oauth-waiting`&&w(),y.current()},[n.step,w]),D=(0,k.useCallback)(async n=>{C(),m.current=null,r({type:`set-flow-id`,flowId:null});let _=new AbortController;g.current?.abort(),g.current=_,r({type:`reset-oauth-start`}),c.current=0;try{let g=t??n?.trim()??``,b=()=>fetch(`${e}/api/codex-auth/login`,{signal:_.signal,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...oe(),...t?{id:t,reauth:!0}:g?{id:g}:{}})}),x=await b();if(!a.current)return;if(x.status===409){if(await fetch(`${e}/api/codex-auth/login/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`}),!a.current||_.signal.aborted)return;if(x=await b(),x.status===409){r({type:`set-error`,error:i(`codexAuth.oauthAlreadyInProgress`)});return}}let T=await s(x,i(`modal.networkError`));if(!a.current||!T)return;if(T.url){m.current=T.flowId??null,r({type:`set-flow-id`,flowId:T.flowId??null}),r({type:`set-auth-url`,authUrl:T.url}),r({type:`set-step`,step:`oauth-waiting`}),S();let n=T.flowId??``,s=t?`&reauth=1`:``,_=n?`${e}/api/codex-auth/login-status?flowId=${encodeURIComponent(n)}${g?`&accountId=${encodeURIComponent(g)}`:``}${s}`:`${e}/api/codex-auth/login-status`,b=new AbortController;f.current=b,u.current=p(async()=>{if(l.current||b.signal.aborted)return;l.current=!0;let e=AbortSignal.any([b.signal,AbortSignal.timeout(1e4)]);try{let n=await fetch(_,{signal:e}),s=await o(n);if(!a.current||b.signal.aborted)return;if(!s){c.current+=1,c.current>=3&&r({type:`set-status-notice`,statusNotice:i(`codexAuth.oauthStatusRetrying`),statusTone:`warn`});return}if(c.current=0,h.current===`waiting`?r({type:`set-status-notice`,statusNotice:i(`codexAuth.oauthCodeSubmitted`),statusTone:`ok`}):r({type:`set-status-notice`,statusNotice:``,statusTone:`ok`}),s.status===`done`){if(S(),C(),m.current=null,r({type:`set-flow-id`,flowId:null}),!a.current)return;v.current(se(s)),y.current()}else(s.status===`error`||s.status===`expired`)&&(S(),C(),m.current=null,r({type:`set-flow-id`,flowId:null}),a.current&&(t||r({type:`set-step`,step:`pick`}),r({type:`set-error`,error:s.error??i(`codexAuth.loginFailed`)})))}catch(e){if(!a.current||b.signal.aborted||e instanceof Error&&e.name===`AbortError`)return;c.current+=1,c.current>=3&&r({type:`set-status-notice`,statusNotice:i(`codexAuth.oauthStatusRetrying`),statusTone:`warn`})}finally{l.current=!1}},2e3),d.current=setTimeout(()=>{u.current&&(C(),w(),a.current&&(t||r({type:`set-step`,step:`pick`}),r({type:`set-error`,error:i(`modal.loginTimeout`)})))},3e5)}T.error&&!T.url&&r({type:`set-error`,error:T.error})}catch(e){a.current&&!(e instanceof Error&&e.name===`AbortError`)&&r({type:`set-error`,error:e instanceof Error?e.message:String(e)})}},[e,w,C,r,t,S,i]);return(0,k.useEffect)(()=>{if(!t){_.current=null;return}_.current!==t&&(_.current=t,D())},[t,D]),{manualCodeBusy:b,manualCodeWaiting:x,bindCallbacks:T,closeModal:E,startOAuth:D,submitManualCode:(0,k.useCallback)(async()=>{let t=m.current,o=n.manualCode.trim();if(!(!t||!o||b||x)){r({type:`set-manual-code-state`,manualCodeState:`submitting`}),r({type:`set-status-notice`,statusNotice:``,statusTone:`ok`});try{let n=await fetch(`${e}/api/codex-auth/login/code`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({flowId:t,input:o})});if(!a.current)return;if(!n.ok){r({type:`set-error`,error:i(`prov.pasteFail`,{error:(await n.json().catch(()=>({}))).error??n.statusText})}),r({type:`set-manual-code-state`,manualCodeState:`idle`});return}r({type:`oauth-code-submitted`}),r({type:`set-status-notice`,statusNotice:i(`codexAuth.oauthCodeSubmitted`),statusTone:`ok`}),c.current=0}catch{a.current&&(r({type:`set-error`,error:i(`modal.networkError`)}),r({type:`set-manual-code-state`,manualCodeState:`idle`}))}}},[e,r,b,x,i,n.manualCode])}}function le({apiBase:e,onClose:n,onAdded:r,reauthAccountId:i}){let a=t(),[o,s]=(0,k.useReducer)(j,i,A),c=(0,k.useRef)(null),l=(0,k.useRef)(null),{manualCodeBusy:u,manualCodeWaiting:d,bindCallbacks:f,closeModal:p,startOAuth:m,submitManualCode:h}=ce({apiBase:e,reauthAccountId:i,ui:o,dispatch:s,t:a});(0,k.useEffect)(()=>{f(r,n)},[f,r,n]),(0,k.useEffect)(()=>{c.current=document.activeElement;let e=l.current;e&&!e.open&&e.showModal();let t=e?.querySelector(`input:not([disabled]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])`);return t&&t.focus(),()=>{c.current?.focus()}},[]);let g=(0,k.useCallback)(e=>{e.preventDefault(),p()},[p]),_=a(i?`codexAuth.reauthenticate`:`codexAuth.addTitle`);return(0,M.jsx)(`dialog`,{ref:l,"aria-label":_,className:`modal-overlay`,onCancel:g,children:(0,M.jsxs)(`div`,{className:`modal-card`,style:{maxWidth:440},children:[o.step===`pick`&&(0,M.jsx)(N,{id:o.id,error:o.error,onIdChange:e=>s({type:`set-id`,id:e}),onStartOAuth:()=>{m(o.id)},onClose:p}),o.step===`oauth-waiting`&&(0,M.jsx)(ae,{reauthAccountId:i,authUrl:o.authUrl,manualCode:o.manualCode,manualCodeBusy:u,manualCodeWaiting:d,statusNotice:o.statusNotice,statusTone:o.statusTone,flowId:o.flowId,error:o.error,onManualCodeChange:e=>s({type:`set-manual-code`,manualCode:e}),onSubmitManualCode:()=>{h()},onClose:p})]})})}var ue=[2,1,0,-1,-2],X=new Map([[2,`accountPool.priorityFirst`],[1,`accountPool.priorityEarlier`],[0,`accountPool.priorityNormal`],[-1,`accountPool.priorityLater`],[-2,`accountPool.priorityLast`]]);function Z(e){return typeof e==`number`&&Number.isInteger(e)&&e>=-100&&e<=100?e:0}function de(e){let t=Z(e);return t>0?`+${t}`:String(t)}function fe(e){return X.has(e)}function Q(e){return X.get(e)??null}function pe(e,t){let n=Z(t);return e(`accountPool.priorityOption`,{name:e(Q(n)??`accountPool.priorityCustom`),value:de(n)})}var me=1e4;function he(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0&&e<=100?e:80}function $(e){let t=e.trim();if(!/^\d+$/.test(t))return null;let n=Number(t);return n>=1&&n<=100?n:null}function ge(e,t){return e>0?0:Number.isInteger(t)&&t>=1&&t<=100?t:80}function _e(e,t,n,r){return n===r?e||t?`defer`:`apply`:`ignore`}function ve(e){return e&&typeof e==`object`&&e&&`autoSwitchThreshold`in e?e.autoSwitchThreshold:e}function ye(e,t,n){if(e<=0){let t=ge(e,n);return{threshold:t,lastEnabled:t}}return{threshold:0,lastEnabled:$(t)??ge(0,n)}}async function be(e,t,n=(e,t)=>fetch(e,t),r=me){if(!Number.isInteger(t)||t<0||t>100)return!1;try{return(await n(`${e}/api/codex-auth/auto-switch`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({threshold:t}),signal:AbortSignal.timeout(r)})).ok}catch{return!1}}var xe=3e4,Se=new Map;function Ce(e,t=!0){let n=Se.get(e),[r,i]=(0,k.useState)(()=>n?.accounts??[]),a=C(x(e,`codex`),[e],async t=>{let n=await fetch(`${e}/api/usage?range=30d&surface=codex`,{signal:t});if(!n.ok)throw Error(`account usage load failed`);return n.json()},{enabled:t}),[o,s]=(0,k.useState)(()=>n?.activeId??null),[c,l]=(0,k.useState)(()=>n==null?`loading`:`ready`),[u,d]=(0,k.useState)(null),[f,m]=(0,k.useState)(null),[h,g]=(0,k.useState)(null),[_,v]=(0,k.useState)(!1),[y,b]=(0,k.useState)(null),[w,T]=(0,k.useState)(0),[E,D]=(0,k.useState)(()=>n!=null),[O,A]=(0,k.useState)(0),j=(0,k.useRef)(null);j.current===null&&(j.current=new Set);let M=(0,k.useRef)(null),N=(0,k.useRef)(0),P=(0,k.useRef)(null),F=(0,k.useRef)(null);F.current===null&&(F.current=new Set);let I=(0,k.useRef)(null),L=(0,k.useRef)(null),R=(0,k.useRef)(!!n?.accounts.length),z=(0,k.useRef)(n!=null),B=(0,k.useRef)(null),V=(0,k.useRef)(null),te=(0,k.useCallback)(e=>(F.current.add(e),()=>{F.current.delete(e)}),[]),H=(0,k.useCallback)(()=>ve(I.current?.value),[]),U=(0,k.useCallback)(()=>I.current?.value,[]),W=(0,k.useCallback)(async(t=!1)=>{let n=++N.current,r=S(2e4);T(e=>e+1);try{let a=[...F.current],o=new Map;for(let e of a)o.set(e,e.beginActiveRead());!t&&!z.current&&l(`loading`);let c=null,u,d=(async()=>{try{let a=await fetch(`${e}/api/codex-auth/accounts${t?`?refresh=1`:``}`,{signal:r.signal});if(!a.ok)throw Error(`account load failed`);let o=await a.json();return N.current===n&&(c=(o.accounts??[]).map(e=>{let t=e.isMain?`main`:e.logLabel;return{...e,...t?{logLabel:t}:{},priority:Z(e.priority)}}),i(c),R.current=c.length>0,z.current=!0,l(`ready`)),!0}catch{return!1}})(),f=(async()=>{try{let t=await fetch(`${e}/api/codex-auth/active`,{signal:r.signal});if(!t.ok)throw Error(`active account load failed`);let i=await t.json();if(N.current===n){let e=i.activeCodexAccountId??null,t=P.current;t&&e!==t.id||(P.current=null,u=e,s(e)),I.current={value:i},b(typeof i.pinnedAccountId==`string`?i.pinnedAccountId:null);for(let e of a)e.acceptActiveRead(i,o.get(e))}return!0}catch{if(N.current===n)for(let e of a)e.rejectActiveRead();return!1}})(),[p,m]=await Promise.all([d,f]);if(N.current!==n)return!1;if(p){l(`ready`),z.current=!0;let t=Se.get(e);return Se.set(e,{accounts:c??t?.accounts??[],activeId:u===void 0?t?.activeId??null:u}),m}return z.current||l(`error`),!1}finally{r.clear(),T(e=>Math.max(0,e-1)),D(!0)}},[e]);(0,k.useEffect)(()=>{t&&M.current!==e&&(M.current=e,Promise.resolve().then(()=>{W()}))},[e,t,W]);let G=r.some(e=>e.hasCredential&&!e.quota);(0,k.useEffect)(()=>{if(!t||!G||O>0)return;let e=[350,900,2e3].map(e=>window.setTimeout(()=>{W(!1)},e));return()=>{for(let t of e)window.clearTimeout(t)}},[t,G,O,W]),(0,k.useEffect)(()=>{if(!(!t||O>0))return p(()=>{W()},xe)},[t,W,O]);let ne=(0,k.useCallback)(()=>{let e={};return j.current.add(e),A(j.current.size),e},[]),re=(0,k.useCallback)(e=>{j.current.delete(e)&&A(j.current.size)},[]),K=(0,k.useCallback)(async t=>{if(L.current||V.current)return{ok:!1,reason:`busy`};L.current=t??`__main__`,d(t??`__main__`);try{let n=await fetch(`${e}/api/codex-auth/active`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:t})});if(!n.ok)throw Error(`account switch failed`);let r=(await n.json().catch(()=>({}))).activeCodexAccountId??t;return P.current={id:r??null},s(r??null),b(r??`__main__`),W(),{ok:!0,activeId:r??null}}catch{return{ok:!1,reason:`request`}}finally{L.current=null,d(null)}},[e,W]),ie=(0,k.useCallback)(async(t,n)=>{try{return(await fetch(`${e}/api/codex-auth/accounts/alias`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t,alias:n.trim()})})).ok?(await W(),{ok:!0}):{ok:!1,reason:`request`}}catch{return{ok:!1,reason:`request`}}},[e,W]),ae=(0,k.useCallback)(async(t,n)=>{if(B.current)return{ok:!1,reason:`busy`};B.current={accountId:t},m(t);try{let r=await fetch(`${e}/api/codex-auth/accounts/pause`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t,paused:n})});if(!r.ok)return{ok:!1,reason:`request`};let a=await r.json().catch(()=>({})),o=a&&typeof a==`object`?a:{};if(i(e=>e.map(e=>e.id===t||t===`__main__`&&e.isMain?{...e,paused:n}:e)),Object.prototype.hasOwnProperty.call(o,`activeCodexAccountId`)){let e=o.activeCodexAccountId??null;P.current={id:e},s(e)}return n&&b(e=>e===t?null:e),W(),{ok:!0}}catch{return{ok:!1,reason:`request`}}finally{B.current=null,m(null)}},[e,W]),q=(0,k.useCallback)(async(t,n)=>{if(V.current||L.current)return{ok:!1,reason:`busy`};V.current={accountId:t},g(t);try{let r=await fetch(`${e}/api/codex-auth/accounts/priority`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t,priority:n})});if(!r.ok)return{ok:!1,reason:`request`};let a=await r.json().catch(()=>({})),o=Z((a&&typeof a==`object`?a:{}).priority??n);return i(e=>e.map(e=>e.id===t||t===`__main__`&&e.isMain?{...e,priority:o}:e)),b(null),P.current=null,W(),{ok:!0}}catch{return{ok:!1,reason:`request`}}finally{V.current=null,g(null)}},[e,W]),J=(0,k.useCallback)(async()=>{if(B.current)return{ok:!1,reason:`busy`};B.current=`bulk`,v(!0);try{let t=await fetch(`${e}/api/codex-auth/accounts/pause-exhausted`,{method:`PUT`});if(!t.ok)return{ok:!1,reason:`request`};let n=await t.json().catch(()=>({})),r=n&&typeof n==`object`?n:{},a=new Set(r.pausedAccountIds??[]);if(i(e=>e.map(e=>a.has(e.id)||a.has(`__main__`)&&e.isMain?{...e,paused:!0}:e)),Object.prototype.hasOwnProperty.call(r,`activeCodexAccountId`)){let e=r.activeCodexAccountId??null;P.current={id:e},s(e)}return b(e=>e!==null&&a.has(e)?null:e),W(),{ok:!0,pausedCount:r.pausedCount??a.size}}catch{return{ok:!1,reason:`request`}}finally{B.current=null,v(!1)}},[e,W]),oe=(0,k.useCallback)(async t=>{try{let n=await fetch(`${e}/api/codex-auth/accounts?id=${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok)return{ok:!1,reason:`request`};let r=se(await n.json().catch(()=>({})));return await W(),{ok:!0,...r}}catch{return{ok:!1,reason:`request`}}},[e,W]),Y=(0,k.useCallback)(async()=>await W()?{ok:!0}:{ok:!1,reason:`reload`},[W]),ce=o&&o!==`__main__`?r.find(e=>e.id===o):null,le=r.find(e=>e.isMain),ue=ce??le,X=!ue?.paused&&ee(ue);return{accounts:(0,k.useMemo)(()=>{let e=new Map((a.data?.accounts??[]).map(e=>[e.accountLogLabel,e]));return r.map(t=>{let n=t.isMain?`main`:t.logLabel,r=n?e.get(n):void 0;return r?{...t,usage30d:r}:t})},[r,a.data]),activeId:o,loadState:c,refreshing:w>0,initialLoading:!E,switchingId:u,pauseUpdatingId:f,priorityUpdatingId:h,pausingExhausted:_,activeNeedsReauth:X,activePinnedId:y,load:W,switchAccount:K,setAccountPaused:ae,setAccountPriority:q,pauseExhaustedAccounts:J,saveAlias:ie,removeAccount:oe,syncAfterAccountAdded:Y,pauseRefresh:ne,resumeRefresh:re,subscribeLoadObserver:te,readLastThreshold:H,readLastActive:U}}var we={quota:{on:`codexAuth.autoSwitchQuotaDesc`,off:`codexAuth.autoSwitchQuotaOffDesc`},"round-robin":{on:`codexAuth.autoSwitchRoundRobinDesc`,off:`codexAuth.autoSwitchRoundRobinDesc`},"fill-first":{on:`codexAuth.autoSwitchFillFirstDesc`,off:`codexAuth.autoSwitchFillFirstOffDesc`}};function Te({threshold:e,draft:n,strategy:r=`quota`,hydrated:i=!0,saving:a,loadError:o,feedback:s,onDraftChange:c,onEditingChange:l,onCommit:u,onCancel:d,onToggle:f,onRetry:p}){let m=t(),h=(0,k.useRef)(!1),g=e>0,_=we[r][g?`on`:`off`],v=a||!i,y=a?m(`common.saving`):s?.message??``,b=a?`pending`:s?.tone,x=y?`codex-auto-switch-desc codex-auto-switch-feedback`:`codex-auto-switch-desc`;return(0,M.jsxs)(`div`,{className:`card card-row codex-auto-switch-card`,style:{marginTop:16},"aria-busy":a||!i&&!o||void 0,children:[(0,M.jsxs)(`div`,{className:`codex-auto-switch-copy`,children:[(0,M.jsx)(`strong`,{children:m(`codexAuth.autoSwitch`)}),(0,M.jsx)(`div`,{id:`codex-auto-switch-desc`,className:`card-sub`,role:o?`alert`:void 0,children:o?m(`codexAuth.autoSwitchLoadFailed`):m(_,{threshold:e})}),(0,M.jsx)(`div`,{className:`card-sub`,children:m(`codexAuth.failureRecoveryNote`)}),(0,M.jsx)(`div`,{className:`card-sub`,children:m(`codexAuth.cacheWarning`)})]}),(0,M.jsxs)(`div`,{className:`codex-auto-switch-controls`,onBlur:e=>{if(!e.currentTarget.contains(e.relatedTarget)){if(l(!1),h.current){h.current=!1;return}g&&!v&&u()}},children:[o&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:p,children:m(`pws.retryAccounts`)}),g&&(0,M.jsxs)(`label`,{className:`codex-auto-switch-threshold`,children:[(0,M.jsx)(`span`,{className:`field-label`,children:m(`codexAuth.autoSwitchThreshold`)}),(0,M.jsxs)(`span`,{className:`codex-auto-switch-input-wrap`,children:[(0,M.jsx)(`input`,{className:`input mono codex-auto-switch-input`,type:`number`,min:1,max:100,step:1,inputMode:`numeric`,value:n,readOnly:v,"aria-disabled":v,"aria-label":m(`codexAuth.autoSwitchThresholdAria`),"aria-describedby":x,onChange:e=>c(e.target.value),onFocus:()=>{v||l(!0)},onKeyDown:e=>{e.nativeEvent.isComposing||v||(e.key===`Enter`?(e.preventDefault(),u()):e.key===`Escape`&&(e.preventDefault(),d()))}}),(0,M.jsx)(`span`,{className:`codex-auto-switch-unit`,"aria-hidden":`true`,children:`%`}),(0,M.jsx)(E,{disabled:v,incrementLabel:m(`codexAuth.autoSwitchThresholdInc`),decrementLabel:m(`codexAuth.autoSwitchThresholdDec`),onIncrement:()=>{l(!0),c(T(n,1,1,100))},onDecrement:()=>{l(!0),c(T(n,-1,1,100))}})]})]}),(0,M.jsx)(`span`,{className:`codex-auto-switch-toggle-slot`,children:(0,M.jsx)(`button`,{type:`button`,className:`toggle ${g?`on`:``}`,onPointerDownCapture:()=>{h.current=!0},onPointerUp:()=>{h.current=!1},onPointerCancel:()=>{h.current=!1},onClick:()=>{h.current=!1,f()},disabled:v,"aria-pressed":g,"aria-label":m(`codexAuth.autoSwitch`),"aria-describedby":x,title:m(`codexAuth.autoSwitch`),children:(0,M.jsx)(`span`,{className:`toggle-knob`})})})]}),y&&(0,M.jsx)(`div`,{id:`codex-auto-switch-feedback`,className:`codex-auto-switch-feedback${b===`err`?` is-error`:``}`,role:b===`err`?`alert`:`status`,"aria-atomic":`true`,children:y})]})}var Ee=[`quota`,`round-robin`,`fill-first`],De=`quota`,Oe=new Set(Ee);function ke(e){return typeof e==`string`&&Oe.has(e)?e:De}function Ae(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=100?e:1}function je(e){let t=e.trim();if(!/^\d+$/.test(t))return null;let n=Number(t);return n>=1&&n<=100?n:null}async function Me(e,t,n=(e,t)=>fetch(e,t)){if(t.strategy===void 0&&t.stickyLimit===void 0)return{ok:!1};try{let r=await n(`${e}/api/codex-auth/pool-strategy`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t.strategy===void 0?{}:{strategy:t.strategy},...t.stickyLimit===void 0?{}:{stickyLimit:t.stickyLimit}})});if(!r.ok)return{ok:!1};let i=await r.json();return{ok:!0,strategy:ke(i.accountPoolStrategy??t.strategy),stickyLimit:Ae(i.accountPoolStickyLimit??t.stickyLimit)}}catch{return{ok:!1}}}var Ne={quota:`accountPool.strategyQuota`,"round-robin":`accountPool.strategyRoundRobin`,"fill-first":`accountPool.strategyFillFirst`},Pe={quota:`accountPool.strategyHintQuota`,"round-robin":`accountPool.strategyHintRoundRobin`,"fill-first":`accountPool.strategyHintFillFirst`};function Fe({strategy:e,stickyDraft:n,disabled:r=!1,strategySelectId:i=`account-pool-strategy`,stickyInputId:o=`account-pool-sticky-limit`,onStrategyChange:s,onStickyDraftChange:c,onStickyCommit:l}){let u=t(),d=Ee.map(e=>({value:e,label:u(Ne[e])}));return(0,M.jsxs)(`div`,{className:`account-pool-strategy-controls`,children:[(0,M.jsxs)(`div`,{className:`setting-row`,children:[(0,M.jsxs)(`div`,{className:`setting-label`,children:[(0,M.jsx)(`span`,{className:`title`,id:`${i}-label`,children:u(`accountPool.strategy`)}),(0,M.jsx)(`span`,{className:`desc`,children:u(`accountPool.strategyDesc`)}),(0,M.jsx)(`span`,{className:`desc`,children:u(Pe[e])}),(0,M.jsx)(`span`,{className:`desc`,children:u(`accountPool.unboundDefinition`)})]}),(0,M.jsx)(`div`,{className:`setting-controls`,children:(0,M.jsx)(a,{id:i,value:e,options:d,disabled:r,label:u(`accountPool.strategy`),onChange:e=>s(e)})})]}),e===`round-robin`&&(0,M.jsxs)(`div`,{className:`setting-row`,children:[(0,M.jsxs)(`label`,{className:`setting-label`,htmlFor:o,children:[(0,M.jsx)(`span`,{className:`title`,children:u(`accountPool.stickyLimit`)}),(0,M.jsx)(`span`,{className:`desc`,children:u(`accountPool.stickyLimitHelp`)})]}),(0,M.jsx)(`div`,{className:`setting-controls`,children:(0,M.jsxs)(`span`,{className:`codex-auto-switch-input-wrap`,children:[(0,M.jsx)(`input`,{id:o,className:`input mono codex-auto-switch-input`,type:`number`,min:1,max:100,step:1,inputMode:`numeric`,value:n,disabled:r,"aria-label":u(`accountPool.stickyLimitAria`),onChange:e=>c(e.target.value),onBlur:()=>l(),onKeyDown:e=>{e.nativeEvent.isComposing||r||e.key===`Enter`&&(e.preventDefault(),l())}}),(0,M.jsx)(E,{disabled:r,incrementLabel:u(`accountPool.stickyLimitInc`),decrementLabel:u(`accountPool.stickyLimitDec`),onIncrement:()=>{let e=T(n,1,1,100);c(e),l(e)},onDecrement:()=>{let e=T(n,-1,1,100);c(e),l(e)}})]})})]})]})}function Ie(e){if(!e||typeof e!=`object`)return null;let t=e;return!(`accountPoolStrategy`in t)&&!(`accountPoolStickyLimit`in t)?null:{strategy:ke(t.accountPoolStrategy),stickyLimit:Ae(t.accountPoolStickyLimit)}}function Le({apiBase:e,subscribeLoadObserver:n,readLastActive:r,onStrategyResolved:i}){let a=t(),[o,s]=(0,k.useState)(De),[c,l]=(0,k.useState)(1),[u,d]=(0,k.useState)(`1`),[f,p]=(0,k.useState)(!1),m=(0,k.useRef)(!1),[h,g]=(0,k.useState)(!1),_=(0,k.useRef)(!1),v=(0,k.useRef)(!1),y=(0,k.useRef)(0),[b,x]=(0,k.useState)(!1),[S,C]=(0,k.useState)(null),w=(0,k.useCallback)(e=>{let t=ke(e.accountPoolStrategy),n=Ae(e.accountPoolStickyLimit);s(t),i?.(t),l(n),d(String(n)),m.current=!0,p(!0),x(!1),C(null)},[i]),T=(0,k.useCallback)(e=>{let t=Ie(e);t&&w({accountPoolStrategy:t.strategy,accountPoolStickyLimit:t.stickyLimit})},[w]),E=(0,k.useCallback)(async()=>{try{let t=await fetch(`${e}/api/codex-auth/active`);if(!t.ok)throw Error(`load`);let n=await t.json();if(_.current){v.current=!0;return}w(n)}catch{_.current||x(!0)}},[e,w]),D=(0,k.useCallback)(()=>{v.current&&(v.current=!1,queueMicrotask(()=>{if(_.current){v.current=!0;return}E()}))},[E]);(0,k.useEffect)(()=>{if(!n)return;let e=n({beginActiveRead:()=>y.current,acceptActiveRead:(e,t)=>{if(t===y.current){if(_.current){v.current=!0;return}T(e)}},rejectActiveRead:()=>{m.current||x(!0)}});return!_.current&&r&&T(r()),e},[n,T,r]),(0,k.useEffect)(()=>{!r||n||_.current||T(r())},[r,T,n]),(0,k.useEffect)(()=>{n||E()},[E,n]);let O=(0,k.useCallback)(async t=>{if(_.current)return;let n=o,r=c;t.strategy!==void 0&&(s(t.strategy),i?.(t.strategy)),t.stickyLimit!==void 0&&(l(t.stickyLimit),d(String(t.stickyLimit))),_.current=!0,g(!0),C(null),y.current+=1;let u=await Me(e,t);y.current+=1,u.ok?(s(u.strategy),i?.(u.strategy),l(u.stickyLimit),d(String(u.stickyLimit)),m.current=!0,p(!0)):(C(a(`accountPool.strategyUpdateFailed`)),s(n),i?.(n),l(r),d(String(r))),_.current=!1,g(!1),D()},[e,i,D,c,o,a]),A=h||b||!f;return(0,M.jsxs)(`div`,{className:`card account-pool-strategy-card`,"aria-busy":h||!f&&!b,children:[b&&(0,M.jsx)(`div`,{className:`card-sub`,role:`alert`,children:a(`accountPool.strategyLoadFailed`)}),b&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm account-pool-strategy-card__retry`,onClick:()=>{E()},children:a(`common.retry`)}),!b&&(0,M.jsx)(Fe,{strategy:o,stickyDraft:u,disabled:A,strategySelectId:`codex-pool-strategy`,stickyInputId:`codex-pool-sticky-limit`,onStrategyChange:e=>{A||e===o||O({strategy:e})},onStickyDraftChange:d,onStickyCommit:e=>{if(A)return;let t=je(e??u);if(t===null){d(String(c)),C(a(`accountPool.stickyLimitInvalid`));return}if(t===c){d(String(t));return}O({stickyLimit:t})}}),S&&(0,M.jsx)(`div`,{role:`alert`,className:`card-sub account-pool-strategy-card__error`,children:S})]})}function Re({t:e,open:t,onToggle:n,children:r}){return(0,M.jsxs)(`section`,{className:`codex-auth-advanced`,children:[(0,M.jsxs)(`button`,{type:`button`,className:`codex-auth-advanced__toggle`,"aria-expanded":t,"aria-controls":`codex-auth-advanced-boxes`,onClick:n,children:[(0,M.jsx)(`span`,{children:e(`codexAuth.advancedSettings`)}),(0,M.jsx)(f,{width:12,height:12,"aria-hidden":`true`,className:t?`codex-auth-advanced__chevron is-open`:`codex-auth-advanced__chevron`})]}),t&&(0,M.jsx)(`div`,{id:`codex-auth-advanced-boxes`,className:`codex-auth-advanced__boxes`,children:r})]})}function ze(e,t){let[n,r]=(0,k.useState)(80),[i,a]=(0,k.useState)(`80`),[o,s]=(0,k.useState)(!1),[c,l]=(0,k.useState)(!1),[u,d]=(0,k.useState)(!1),[f,p]=(0,k.useState)(null),m=(0,k.useRef)(80),h=(0,k.useRef)(!1),g=(0,k.useRef)(80),_=(0,k.useRef)(!1),v=(0,k.useRef)(!1),y=(0,k.useRef)(!1),b=(0,k.useRef)(0),x=(0,k.useRef)(null),S=(0,k.useRef)(null),C=(0,k.useCallback)(e=>{m.current=e,h.current=!0,s(!0),r(e),e>0&&(g.current=e),a(String(e>0?e:g.current))},[]),w=(0,k.useCallback)(e=>{if(_.current||v.current){x.current=e;return}x.current=null,C(e)},[C]),T=(0,k.useCallback)(()=>{let e=x.current;return e!==null&&(x.current=null,C(e),!0)},[C]),E=(0,k.useCallback)(()=>{S.current!==null&&(window.clearTimeout(S.current),S.current=null),p(null)},[]),D=(0,k.useCallback)((e,t)=>{S.current!==null&&window.clearTimeout(S.current),p({tone:t?`err`:`ok`,message:e}),S.current=window.setTimeout(()=>{p(null),S.current=null},5e3)},[]);(0,k.useEffect)(()=>()=>{S.current!==null&&window.clearTimeout(S.current)},[]);let O=(0,k.useCallback)(()=>(h.current||l(!1),b.current),[]),A=(0,k.useCallback)((e,t)=>{l(!1);let n=ve(e),r=_e(_.current,v.current,t,b.current);r===`defer`?x.current=he(n):r===`apply`&&w(he(n))},[w]),j=(0,k.useCallback)(e=>{h.current||_.current||v.current||(l(!1),C(he(ve(e))))},[C]),M=(0,k.useCallback)(()=>{h.current||l(!0)},[]),N=(0,k.useCallback)(async(n,r,i=!0)=>{if(v.current)return!1;v.current=!0,_.current=!1,E(),d(!0),b.current+=1;try{let a=await be(e,n);return b.current+=1,a?(x.current=null,C(n),i&&D(t.updated,!1)):(T()||C(r),D(t.updateFailed,!0)),a}finally{v.current=!1,d(!1)}},[e,C,E,t.updateFailed,t.updated,T,D]),P=(0,k.useCallback)(()=>{_.current=!1;let e=m.current;T()||a(String(e>0?e:g.current)),D(t.invalid,!0)},[t.invalid,T,D]),F=(0,k.useCallback)(()=>{_.current=!1,y.current=!0,E();let e=m.current;T()||a(String(e>0?e:g.current))},[E,T]),I=(0,k.useCallback)(async()=>{if(y.current)return y.current=!1,!0;if(!h.current||v.current)return!1;let e=m.current;_.current=!1;let t=$(i);return t===null?(P(),!1):t===e?(T()||a(String(t)),!0):N(t,e)},[i,T,P,N]),L=(0,k.useCallback)(async()=>{if(!h.current||v.current)return!1;let e=m.current;_.current=!1;let t=ye(e,i,g.current),n=await N(t.threshold,e);return n?(g.current=t.lastEnabled,t.threshold===0&&a(String(t.lastEnabled)),n):!1},[i,N]);return{threshold:n,draft:i,hydrated:o,saving:u,loadError:c,feedback:f,beginServerRead:O,acceptServerRead:A,hydrateServerValue:j,rejectServerRead:M,setDraft:(0,k.useCallback)(e=>{h.current&&(_.current=!0,y.current=!1,E(),a(e))},[E]),setEditing:(0,k.useCallback)(e=>{_.current=e},[]),commit:I,cancel:F,toggle:L,retry:(0,k.useCallback)(()=>{l(!1),E()},[E])}}function Be({value:e,disabled:n=!1,selectId:r,onChange:i}){let o=t(),s=Z(e),c=o(`accountPool.priorityHint`),l=`${r}-hint`,u=ue.map(e=>({value:String(e),label:pe(o,e)})),d=fe(s)?u:[{value:String(s),label:pe(o,s)},...u];return(0,M.jsxs)(`div`,{className:`codex-account-priority`,children:[(0,M.jsx)(`label`,{className:`codex-account-priority-label`,htmlFor:r,children:o(`accountPool.priority`)}),(0,M.jsx)(a,{id:r,value:String(s),options:d,disabled:n,label:o(`accountPool.priorityAria`),describedBy:l,title:c,onChange:e=>i(Z(Number.parseInt(e,10)))}),(0,M.jsx)(`span`,{id:l,className:`sr-only`,children:c})]})}function Ve({value:e}){let n=t(),r=Z(e);return r===0?null:(0,M.jsx)(`span`,{className:`badge badge-muted`,children:pe(n,r)})}function He(e){let t=e?.trim().toLowerCase();return t===`go`||t===`free`}function Ue(e,t){if(!e)return null;let n=e.shortPercent===void 0&&e.shortResetAt===void 0?e:{...e,fiveHourPercent:e.fiveHourPercent??e.shortPercent,fiveHourResetAt:e.fiveHourResetAt??e.shortResetAt};return He(t)?{...n.monthlyPercent===void 0?{}:{monthlyPercent:n.monthlyPercent},...n.monthlyResetAt===void 0?{}:{monthlyResetAt:n.monthlyResetAt},...n.creditsUsd===void 0?{}:{creditsUsd:n.creditsUsd},...n.resetCredits===void 0?{}:{resetCredits:n.resetCredits},updatedAt:n.updatedAt}:n}function We(e){return e===`5h`?0:e===`First-party models`?2:e===`API usage`?3:e===`Total subscription credits`?4.5:5}function Ge(e,t){switch(e){case`First-party models`:return t(`quota.cursorFirstParty`);case`API usage`:return t(`quota.cursorApiUsage`);case`Total subscription credits`:return t(`quota.totalSubscriptionCredits`);default:return e}}function Ke(e,t,n){let r=Ue(e,t);if(!r)return[];let i=[],a=r.fiveHourPercent??r.shortPercent,o=r.fiveHourResetAt??r.shortResetAt;typeof a==`number`&&i.push({rank:0,row:{windowKey:`fiveHour`,label:n(`codexAuth.fiveHour`),limitLabel:n(`quota.fiveHourLimit`),percent:a,resetAt:o}}),typeof r.weeklyPercent==`number`&&i.push({rank:1,row:{windowKey:`weekly`,label:n(`codexAuth.weekly`),limitLabel:n(`quota.weeklyLimit`),percent:r.weeklyPercent,resetAt:r.weeklyResetAt}}),typeof r.monthlyPercent==`number`&&i.push({rank:4,row:{windowKey:`monthly`,label:n(`codexAuth.monthly`),limitLabel:n(`quota.monthlyLimit`),percent:r.monthlyPercent,resetAt:r.monthlyResetAt}});for(let e of r.customWindows??[]){let t=Ge(e.label,n);i.push({rank:We(e.label),row:{customLabel:e.label,label:t,limitLabel:t,percent:e.percent,resetAt:e.resetAt}})}if(r.creditsUsd&&typeof r.creditsUsd.percent==`number`&&!r.customWindows?.some(e=>/credits?/i.test(e.label))){let e=Ge(`Total subscription credits`,n);i.push({rank:We(`Total subscription credits`),row:{customLabel:`Total subscription credits`,label:e,limitLabel:e,percent:r.creditsUsd.percent,resetAt:r.creditsUsd.expiresAt}})}return i.sort((e,t)=>e.rank-t.rank).map(e=>e.row)}function qe(e){if(!e)return-1;let t=[e.fiveHourPercent??e.shortPercent,e.weeklyPercent,e.monthlyPercent].filter(e=>typeof e==`number`);for(let n of e.customWindows??[])typeof n.percent==`number`&&t.push(n.percent);return typeof e.creditsUsd?.percent==`number`&&t.push(e.creditsUsd.percent),t.length?Math.max(...t):-1}function Je(e){switch(e){case`en`:return`en-GB`;case`de`:return`de-DE`;case`fr`:return`fr-FR`;case`ko`:return`ko-KR`;case`zh`:return`zh-CN`;case`zh-TW`:return`zh-TW`;case`ru`:return`ru-RU`;case`ja`:return`ja-JP`;case`tr`:return`tr-TR`;default:return e}}function Ye(e){return e>=99.5}function Xe(e,t){return t>0&&e>=t}function Ze(e,t){return Xe(e,t)||Ye(e)?`bar-warn`:`bar-green`}function Qe(e){let t=Math.max(0,Math.min(100,e));return t<=0?0:Math.max(4,Math.round(t))}function $e(e){return{"--bar-scale":String(Qe(e)/100)}}function et({quota:e,plan:t,threshold:n,t:r,className:a,layout:o=`compact`,pending:s=!1,incompleteWindowKeys:c,incompleteCustomWindowLabels:l}){let{locale:u}=i(),d=Ke(e,t,r);return d.length===0?s?o===`stacked`?(0,M.jsxs)(`div`,{className:`quota-stacked quota-stacked--pending${a?` ${a}`:``}`,"aria-busy":`true`,role:`status`,children:[Array.from({length:2},(e,t)=>(0,M.jsxs)(`div`,{className:`quota-stacked-row quota-stacked-row--skeleton`,"aria-hidden":`true`,children:[(0,M.jsxs)(`div`,{className:`quota-stacked-head`,children:[(0,M.jsx)(`span`,{className:`quota-skel quota-skel--label`,style:{width:72}}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--time`,style:{width:64}})]}),(0,M.jsxs)(`div`,{className:`quota-stacked-bar-row`,children:[(0,M.jsx)(`span`,{className:`quota-skel quota-skel--bar`,style:{height:6,flex:1}}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--val`,style:{width:36}})]})]},t)),(0,M.jsx)(`span`,{className:`sr-only`,children:r(`common.loading`)})]}):(0,M.jsxs)(`div`,{className:`codex-account-quota-slot quota-compact quota-compact--pending${a?` ${a}`:``}`,"aria-busy":`true`,role:`status`,children:[(0,M.jsxs)(`div`,{className:`quota-row quota-row--skeleton`,"aria-hidden":`true`,children:[(0,M.jsx)(`span`,{className:`quota-skel quota-skel--label`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--reset`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--day`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--time`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--bar`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--val`})]}),(0,M.jsx)(`span`,{className:`sr-only`,children:r(`common.loading`)})]}):null:o===`stacked`?(0,M.jsx)(`div`,{className:`quota-stacked${a?` ${a}`:``}`,children:d.map(e=>(0,M.jsx)(nt,{row:e,threshold:n,t:r,locale:u,incomplete:e.windowKey?c?.has(e.windowKey)===!0:e.customLabel!==void 0&&l?.has(e.customLabel)===!0},e.limitLabel))}):(0,M.jsx)(`div`,{className:`codex-account-quota-slot quota-compact${a?` ${a}`:``}`,children:d.map(e=>(0,M.jsx)(tt,{label:e.label,percent:e.percent,resetAt:e.resetAt,threshold:n,t:r,locale:u},e.label))})}function tt({label:e,percent:t,resetAt:n,threshold:r,t:i,locale:a}){let o=Ye(t),s=Xe(t,r),c=Ze(t,r),l=it(n,i,a),d=l.day||l.time?`${i(`codexAuth.resets`)} ${l.day} ${l.time}`.replace(/\s+/g,` `).trim():void 0,f=l.day!==``||l.time!==``;return(0,M.jsxs)(`div`,{className:`quota-row${s?` quota-row--warn`:``}${o?` quota-row--exhausted`:``}`,children:[(0,M.jsx)(`span`,{className:`quota-label`,title:d,children:e}),(0,M.jsx)(`span`,{className:`quota-reset-label`,children:f?i(`codexAuth.resets`):``}),(0,M.jsx)(`span`,{className:`quota-reset-day`,children:l.day}),(0,M.jsx)(`span`,{className:`quota-reset-time`,children:l.time}),(0,M.jsx)(`div`,{className:`bar`,title:d,children:(0,M.jsx)(`div`,{className:`bar-fill ${c}`,style:$e(t)})}),(0,M.jsxs)(`span`,{className:`quota-val${s?` quota-val--warn`:``}`,title:o?i(`quota.limitReached`):d,"aria-label":d,children:[s&&(0,M.jsx)(u,{width:12,height:12,"aria-hidden":`true`}),Math.round(t),`%`,o?` · ${i(`quota.limitReached`)}`:``]})]})}function nt({row:e,threshold:t,t:n,locale:r,incomplete:i}){let a=Ye(e.percent),o=Xe(e.percent,t),s=Ze(e.percent,t),c=at(e.resetAt,n,r);return(0,M.jsxs)(`div`,{className:`quota-stacked-row${o?` quota-stacked-row--warn`:``}${a?` quota-stacked-row--exhausted`:``}`,children:[(0,M.jsxs)(`div`,{className:`quota-stacked-head`,children:[(0,M.jsxs)(`span`,{className:`quota-stacked-limit-group`,children:[(0,M.jsx)(`span`,{className:`quota-stacked-limit`,children:e.limitLabel}),i&&(0,M.jsx)(`span`,{className:`quota-window-partial`,role:`note`,"aria-label":n(`pws.capacity.windowPartialA11y`,{window:e.limitLabel}),title:n(`pws.capacity.windowPartialA11y`,{window:e.limitLabel}),children:n(`pws.capacity.windowPartial`)})]}),(0,M.jsx)(`span`,{className:`quota-stacked-reset muted`,children:c})]}),(0,M.jsxs)(`div`,{className:`quota-stacked-bar-row`,children:[(0,M.jsx)(`div`,{className:`bar quota-stacked-bar`,children:(0,M.jsx)(`div`,{className:`bar-fill ${s}`,style:$e(e.percent)})}),(0,M.jsx)(`span`,{className:`quota-stacked-used${o?` quota-stacked-used--warn`:``}`,children:n(`quota.usedPercent`,{pct:Math.round(e.percent)})})]}),a&&(0,M.jsxs)(`div`,{className:`quota-stacked-limit-reached`,role:`status`,children:[(0,M.jsx)(u,{width:12,height:12,"aria-hidden":`true`}),n(`quota.limitReached`)]})]})}function rt(e){if(typeof e!=`number`||!Number.isFinite(e))return null;let t=e<1e10?e*1e3:e,n=new Date(t);return Number.isFinite(n.getTime())?{date:n,ms:t}:null}function it(e,t,n){let r=rt(e);if(!r)return{day:``,time:``};let{date:i}=r,a=new Date,o=Je(n),s=new Intl.DateTimeFormat(o,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(i);return i.getFullYear()===a.getFullYear()&&i.getMonth()===a.getMonth()&&i.getDate()===a.getDate()?{day:t(`codexAuth.today`),time:s}:{day:new Intl.DateTimeFormat(o,{day:`numeric`,month:`short`}).format(i),time:s}}function at(e,t,n=`en`,r=Date.now()){let i=rt(e);if(!i)return``;let{date:a,ms:o}=i,s=Je(n),c=new Intl.DateTimeFormat(s,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(a),l=new Date(r),u=new Date(l.getFullYear(),l.getMonth(),l.getDate()).getTime(),d=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),f=Math.round((d-u)/864e5);if(f===1)return t(`quota.resetsTomorrow`,{time:c});let p=a.getFullYear()!==l.getFullYear(),m=new Intl.DateTimeFormat(s,{day:`numeric`,month:`short`,...p?{year:`numeric`}:{}}).format(a);if(o<=r)return t(`quota.resetsAt`,{date:m,time:c,when:`${m}, ${c}`});let h=Math.round((o-r)/6e4);if(h<60)return t(`quota.resetsRelativeMinutes`,{n:Math.max(1,h)});let g=Math.round(h/60);return g<12&&f===0?t(`quota.resetsRelativeHours`,{n:Math.max(1,g)}):f===0?t(`quota.resetsToday`,{time:c}):t(`quota.resetsAt`,{date:m,time:c,when:`${m}, ${c}`})}function ot(e,t){return O(e,t)}function st(e,t){return D(e,t)}function ct(e){return Math.max(0,Math.ceil((new Date(e).getTime()-Date.now())/864e5))}function lt({index:e,grantedAt:t,expiresAt:n,isNext:r,locale:i,t:a}){let o=ct(n),s=o<=7;return(0,M.jsxs)(`div`,{className:`credit-item${r?` credit-next`:``}`,children:[(0,M.jsxs)(`div`,{className:`credit-item-head`,children:[(0,M.jsx)(m,{width:13}),(0,M.jsx)(`span`,{className:`credit-item-label`,children:r?a(`codexAuth.creditNext`):a(`codexAuth.creditLabel`,{n:String(e+1)})}),r&&(0,M.jsx)(`span`,{className:`badge badge-amber text-micro`,style:{padding:`1px 6px`},children:a(`codexAuth.creditNextBadge`)})]}),(0,M.jsxs)(`div`,{className:`credit-item-dates`,children:[(0,M.jsx)(`span`,{children:a(`codexAuth.creditGranted`,{date:ot(t,i)})}),(0,M.jsx)(`span`,{className:s?`credit-urgent`:``,children:a(`codexAuth.creditExpires`,{date:st(n,i),days:String(o)})})]})]})}function ut({account:e,onClick:t,t:n}){let r=e.quota?.resetCredits;return e.quota==null?(0,M.jsxs)(`span`,{className:`badge badge-muted codex-ticket-badge-slot`,"aria-hidden":`true`,children:[(0,M.jsx)(m,{width:12}),`0`]}):r===void 0?null:(0,M.jsxs)(`button`,{type:`button`,className:`badge ${typeof r==`number`&&r>0?`badge-amber`:`badge-muted`} badge-clickable`,onClick:e=>{e.stopPropagation(),t()},"aria-label":n(`codexAuth.resetCreditsAria`,{count:String(r)}),children:[(0,M.jsx)(m,{width:12}),r]})}function dt({t:e,paused:t,saving:n}){let r=e(`codexAuth.pause`),i=e(`codexAuth.resume`),a=e(`common.saving`),o=n?a:t?i:r,s=Math.max(r.length,i.length,a.length);return(0,M.jsx)(`span`,{className:`codex-auth-pause-label`,style:{minWidth:`${s}ch`},children:o})}function ft({pool:e,activeId:n,accountModeState:r,switchActionLabel:i,threshold:a,onOpenReset:o,onSwitch:s,onTogglePause:c,pauseUpdatingId:l,pauseBusy:u,onPriorityChange:d,priorityUpdatingId:f,switchingId:p,pinnedId:m=null,onReauth:g,onEditAlias:_,onRemove:v,onCopyDoctor:b,doctorCopyOutcomeFor:x}){let S=t(),C=e=>!e.paused&&n===e.id;return(0,M.jsx)(M.Fragment,{children:e.map(e=>{let t=e.health?.status,n=!!e.needsReauth||R(t),T=z(t),E=te(S,e.health),D=H(S,`codex`,e.id,e.health);return(0,M.jsxs)(`div`,{className:`card ${C(e)?`card-active`:``}`,style:{marginBottom:8},children:[(0,M.jsxs)(`div`,{className:`card-head`,children:[(0,M.jsx)(`span`,{className:`dot ${n?`dot-amber`:C(e)?`dot-blue`:`dot-muted`}`}),(0,M.jsx)(`strong`,{children:e.alias??e.email}),(0,M.jsxs)(`span`,{className:`card-badges`,children:[e.plan&&(0,M.jsx)(`span`,{className:`badge badge-green`,children:e.plan}),e.paused&&(0,M.jsx)(`span`,{className:`badge badge-muted`,title:S(`codexAuth.pausedHint`),children:S(`codexAuth.paused`)}),(0,M.jsx)(Ve,{value:e.priority}),e.id===m&&!e.paused&&(0,M.jsx)(`span`,{className:`badge badge-muted`,children:S(`codexAuth.pinned`)}),(0,M.jsx)(ut,{t:S,account:e,onClick:()=>o(e)}),E&&(0,M.jsx)(`span`,{className:L(t),children:E}),n&&!E&&(0,M.jsx)(`span`,{className:`badge badge-amber`,children:S(`codexAuth.needsReauth`)}),C(e)&&!n&&!T&&(0,M.jsx)(`span`,{className:`badge badge-primary`,children:S(r===`direct`?`codexAuth.poolPrepared`:`codexAuth.nextSession`)})]}),!e.paused&&(!C(e)||m!==e.id)&&!n&&!T&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-account-switch`,onClick:()=>s(e),children:i}),n&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>g(e.id),children:S(`codexAuth.reauthenticate`)}),b&&B(t)&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-auth-action-btn`,onClick:()=>b(e.id),children:(0,M.jsx)(`span`,{"aria-live":`polite`,children:G(S,x?.(e.id))})}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost codex-auth-action-btn`,onClick:()=>c(e),disabled:u,title:e.paused?S(`codexAuth.pausedHint`):void 0,"aria-label":e.paused?`${S(`codexAuth.resume`)}. ${S(`codexAuth.pausedHint`)}`:S(`codexAuth.pause`),children:[e.paused?(0,M.jsx)(h,{width:14}):(0,M.jsx)(y,{width:14}),(0,M.jsx)(dt,{t:S,paused:e.paused,saving:l===e.id})]}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void _(e),children:S(`prov.editAlias`)}),(0,M.jsx)(`button`,{type:`button`,className:`btn-icon btn-icon-danger card-right`,"aria-label":`${S(`common.remove`)} — ${e.email}`,title:`${S(`common.remove`)} — ${e.email}`,onClick:t=>{t.stopPropagation(),v(e.id)},children:(0,M.jsx)(w,{width:14})})]}),(0,M.jsxs)(`div`,{className:`codex-account-identity`,children:[(0,M.jsxs)(`div`,{className:`codex-account-identity-copy`,children:[e.email,e.plan?` · ${e.plan}`:``,` · `,S(`prov.accountId`),`: `,F(e.id)]}),(0,M.jsx)(Be,{value:e.priority,selectId:`codex-account-priority-${e.id}`,disabled:f!==null||p!==null,onChange:t=>d(e,t)})]}),D&&(0,M.jsx)(`div`,{className:`card-sub faint`,children:D}),T&&(0,M.jsx)(`div`,{className:`card-sub faint`,children:S(`pws.healthCooldownHint`)}),n?(0,M.jsx)(`div`,{className:`card-sub faint`,children:S(`codexAuth.tokenExpired`)}):!T&&(0,M.jsx)(et,{quota:e.quota,plan:e.plan,threshold:a,t:S,pending:e.quota==null})]},e.id)})})}function pt({onReauth:e}){let n=t();return(0,M.jsxs)(`div`,{className:`notice-warn`,style:{marginBottom:12,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:12,flexWrap:`wrap`},children:[(0,M.jsxs)(`span`,{children:[(0,M.jsx)(u,{width:14}),` `,n(`codexAuth.tokenExpired`)]}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:e,children:n(`codexAuth.reauthenticate`)})]})}function mt({confirm:e,mainEmail:n,accountModeState:r,switchingId:i,orderBusy:a=!1,onCancel:o,onConfirm:s}){let c=t(),l=(0,k.useRef)(null);(0,k.useEffect)(()=>{let e=l.current;e&&!e.open&&e.showModal()},[]);let d=(0,k.useCallback)(e=>{e.preventDefault(),o()},[o]);return(0,M.jsxs)(`dialog`,{ref:l,className:`modal-overlay`,"aria-labelledby":`codex-switch-title`,onCancel:d,children:[(0,M.jsx)(`button`,{type:`button`,className:`modal-backdrop-dismiss`,"aria-label":c(`common.close`),tabIndex:-1,onClick:o}),(0,M.jsxs)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),role:`document`,children:[(0,M.jsx)(`h3`,{id:`codex-switch-title`,children:r===`direct`?c(`codexAuth.preparePoolTitle`):e.id===`__main__`?c(`codexAuth.switchBack`):c(`codexAuth.switchTitle`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:r===`direct`?c(`codexAuth.preparePoolDesc`):e.id===`__main__`?c(`codexAuth.switchBackDesc`):c(`codexAuth.switchDesc`)}),(0,M.jsxs)(`div`,{className:`card`,style:{margin:`12px 0`},children:[(0,M.jsx)(`strong`,{children:e.id===`__main__`?n||c(`codexAuth.codexApp`):e.email}),e.plan&&(0,M.jsx)(`span`,{className:`badge badge-green`,style:{marginLeft:8},children:e.plan})]}),e.id!==`__main__`&&(0,M.jsxs)(`div`,{className:`notice-warn`,children:[(0,M.jsx)(u,{width:14}),` `,c(`codexAuth.cacheWarning`)]}),(0,M.jsxs)(`div`,{className:`modal-actions`,children:[(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:o,children:c(`codexAuth.cancel`)}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:!!i||a,onClick:s,children:c(i?`pws.accountSwitching`:r===`direct`?`codexAuth.prepareForPool`:`codexAuth.setAsNext`)})]})]})]})}function ht({resetPopup:e,resetConfirm:t,creditDetails:n,creditDetailsLoading:r,redeeming:a,onClose:o,onShowConfirm:s,onCancelConfirm:c,onRedeem:l}){let{locale:d,t:f}=i(),p=(0,k.useRef)(null);(0,k.useEffect)(()=>{let e=p.current;e&&!e.open&&e.showModal()},[]);let h=(0,k.useCallback)(e=>{e.preventDefault(),o()},[o]);return(0,M.jsxs)(`dialog`,{ref:p,className:`modal-overlay`,"aria-labelledby":`codex-reset-title`,onCancel:h,children:[(0,M.jsx)(`button`,{type:`button`,className:`modal-backdrop-dismiss`,"aria-label":f(`common.close`),tabIndex:-1,onClick:o}),(0,M.jsx)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),role:`document`,children:t?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{style:{textAlign:`center`,padding:`12px 0`},children:[(0,M.jsx)(`div`,{className:`confirm-icon`,children:(0,M.jsx)(u,{width:22})}),(0,M.jsx)(`h3`,{id:`codex-reset-title`,children:f(`codexAuth.confirmResetTitle`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:f(`codexAuth.confirmResetDesc`,{count:String(e.quota?.resetCredits??0)})}),n&&n[0]&&(0,M.jsx)(`p`,{className:`faint text-label`,children:f(`codexAuth.confirmWhichCredit`,{date:ot(n[0].granted_at,d)})}),(0,M.jsx)(`p`,{className:`faint text-label`,children:f(`codexAuth.irreversible`)})]}),(0,M.jsxs)(`div`,{className:`modal-actions`,children:[(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:c,children:f(`codexAuth.cancel`)}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:l,disabled:a,children:f(a?`codexAuth.redeeming`:`codexAuth.useCredit`)})]})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`h3`,{id:`codex-reset-title`,children:[(0,M.jsx)(m,{width:16}),` `,f(`codexAuth.resetCreditsTitle`)]}),(0,M.jsxs)(`div`,{className:`card-sub`,children:[e.email,e.plan?` · ${e.plan}`:``]}),(0,M.jsx)(`div`,{style:{margin:`16px 0`},children:(e.quota?.resetCredits??0)>0?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`p`,{style:{marginBottom:12},children:f(`codexAuth.resetCreditsAvailable`,{count:String(e.quota?.resetCredits??0)})}),r&&(0,M.jsx)(`p`,{className:`faint text-label`,children:f(`common.loading`)}),n&&n.length>0&&(0,M.jsx)(`div`,{className:`credit-list`,children:n.map((e,t)=>(0,M.jsx)(lt,{index:t,grantedAt:e.granted_at,expiresAt:e.expires_at,isNext:t===0,locale:d,t:f},`${e.granted_at}:${e.expires_at}`))}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary`,style:{marginTop:12,width:`100%`},onClick:s,disabled:a,children:f(`codexAuth.useOneCredit`)}),(0,M.jsx)(`p`,{className:`card-sub text-caption`,style:{marginTop:8,textAlign:`center`},children:f(`codexAuth.fifoNote`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`p`,{className:`faint`,children:f(`codexAuth.noResetCredits`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:f(`codexAuth.earnCreditsHint`)})]})})]})})]})}function gt({t:e,main:t,isMainActive:n,accountModeState:r,threshold:i,switchActionLabel:a,onSwitch:o,onTogglePause:s,pauseUpdatingId:c,pauseBusy:l,onPriorityChange:u,priorityUpdatingId:d,switchingId:f,pinnedId:p=null,onOpenReset:m,onCopyDoctor:g,doctorCopyOutcomeFor:v}){let b=e(`codexAuth.codexApp`),x=t?.id??`__main__`,S={id:`__main__`,email:t?.email||b,plan:t?.plan,isMain:!0,paused:t?.paused??!1,priority:t?.priority??0,hasCredential:!0,quota:t?.quota??null},C=!!t?.needsReauth||R(t?.health?.status),w=z(t?.health?.status),T=te(e,t?.health),E=t?H(e,`codex`,x,t.health):null;return(0,M.jsxs)(`div`,{className:`card ${n?`card-active`:``}`,style:{marginBottom:12},children:[(0,M.jsxs)(`div`,{className:`card-head`,children:[(0,M.jsx)(`span`,{className:`dot ${C?`dot-amber`:`dot-green`}`}),(0,M.jsx)(`strong`,{children:e(`codexAuth.mainAccount`)}),(0,M.jsxs)(`span`,{className:`card-badges`,children:[t&&(0,M.jsx)(ut,{t:e,account:{...t,id:`__main__`},onClick:()=>m({...t,id:`__main__`})}),t?.paused&&(0,M.jsx)(`span`,{className:`badge badge-muted`,title:e(`codexAuth.pausedHint`),children:e(`codexAuth.paused`)}),(0,M.jsx)(Ve,{value:S.priority}),p===`__main__`&&!t?.paused&&(0,M.jsx)(`span`,{className:`badge badge-muted`,children:e(`codexAuth.pinned`)}),T&&(0,M.jsx)(`span`,{className:L(t?.health?.status),children:T}),C&&!T&&(0,M.jsx)(`span`,{className:`badge badge-amber`,children:e(`codexAuth.needsReauth`)}),!t?.paused&&(0,M.jsx)(`span`,{className:`badge ${n?`badge-primary`:`badge-muted`}`,children:e(n?r===`direct`?`codexAuth.poolPrepared`:`codexAuth.nextSession`:`codexAuth.current`)})]}),!t?.paused&&(!n||p!==`__main__`)&&!C&&!w&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-account-switch`,onClick:()=>o(S),children:a}),g&&B(t?.health?.status)&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-auth-action-btn`,onClick:()=>g(x),children:(0,M.jsx)(`span`,{"aria-live":`polite`,children:G(e,v?.(x))})}),t&&(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost codex-auth-action-btn`,onClick:()=>s(S),disabled:l,title:t.paused?e(`codexAuth.pausedHint`):void 0,"aria-label":t.paused?`${e(`codexAuth.resume`)}. ${e(`codexAuth.pausedHint`)}`:e(`codexAuth.pause`),children:[t.paused?(0,M.jsx)(h,{width:14}):(0,M.jsx)(y,{width:14}),(0,M.jsx)(dt,{t:e,paused:!!t.paused,saving:c===`__main__`})]}),(0,M.jsxs)(`span`,{className:`card-right`,children:[(0,M.jsx)(_,{width:14}),` `,e(`codexAuth.appLogin`)]})]}),(0,M.jsxs)(`div`,{className:`codex-account-identity`,children:[(0,M.jsxs)(`div`,{className:`codex-account-identity-copy`,children:[t?.email||e(`codexAuth.appLogin`),t?.plan?` · ${t.plan}`:``]}),t&&(0,M.jsx)(Be,{value:S.priority,selectId:`codex-account-priority-${S.id}`,disabled:d!==null||f!==null,onChange:e=>u(S,e)})]}),E&&(0,M.jsx)(`div`,{className:`card-sub faint`,children:E}),w&&(0,M.jsx)(`div`,{className:`card-sub faint`,children:e(`pws.healthCooldownHint`)}),C?(0,M.jsx)(`div`,{className:`card-sub faint`,children:e(`codexAuth.mainTokenExpired`)}):!w&&(0,M.jsx)(et,{quota:t?.quota??null,plan:t?.plan,threshold:i,t:e,pending:t!=null&&t.quota==null})]})}function _t({t:e,embedded:t,refreshingQuota:n,pausingExhausted:r,pauseBusy:i,actionFeedback:a,actionFeedbackTone:o,onRefresh:s,onPauseExhausted:c,sparkVisible:l,sparkBusy:u,onToggleSpark:d}){return(0,M.jsxs)(`div`,{className:t?`row`:`page-head codex-auth-page-head`,style:t?{justifyContent:`flex-end`,marginBottom:8}:void 0,children:[!t&&(0,M.jsx)(`h2`,{className:`page-title`,children:e(`nav.codexAuth`)}),(0,M.jsxs)(`div`,{className:t?`row`:`codex-auth-page-head__actions`,children:[(0,M.jsx)(`span`,{className:`codex-auth-page-head__feedback${o===`ok`?` is-ok`:``}${o===`warn`?` is-warn`:``}${o===`err`?` is-err`:``}`,role:`status`,"aria-live":`polite`,children:a??``}),l!==void 0&&d&&(0,M.jsxs)(`span`,{className:`codex-auth-spark-toggle`,children:[(0,M.jsx)(`span`,{className:`codex-auth-spark-toggle__label`,children:e(`codexAuth.sparkQuota`)}),(0,M.jsx)(`button`,{type:`button`,className:`toggle ${l?`on`:``}`,onClick:d,disabled:!!u,"aria-pressed":l,"aria-label":e(`codexAuth.sparkQuota`),title:e(`codexAuth.sparkQuotaHint`),children:(0,M.jsx)(`span`,{className:`toggle-knob`})})]}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost codex-auth-action-btn`,onClick:c,disabled:n||r||!!i,children:[(0,M.jsx)(y,{width:14}),` `,e(r?`codexAuth.pausingExhausted`:`codexAuth.pauseExhausted`)]}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost codex-auth-action-btn`,onClick:s,disabled:n||r||!!i,children:[(0,M.jsx)(g,{width:14}),` `,e(n?`codexAuth.refreshingQuota`:`codexAuth.refreshQuota`)]})]})]})}function vt({t:e,loadState:t,accountsCount:n,onRetry:r}){return t===`loading`&&n===0?(0,M.jsxs)(`div`,{className:`codex-auth-load-skeleton`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,M.jsxs)(`div`,{className:`card codex-auth-load-skeleton__main`,style:{marginBottom:12},"aria-hidden":`true`,children:[(0,M.jsxs)(`div`,{className:`card-head`,children:[(0,M.jsx)(`span`,{className:`dot dot-muted`}),(0,M.jsx)(`strong`,{children:e(`codexAuth.mainAccount`)}),(0,M.jsxs)(`span`,{className:`card-badges`,children:[(0,M.jsxs)(`span`,{className:`badge badge-muted codex-ticket-badge-slot`,"aria-hidden":`true`,children:[(0,M.jsx)(m,{width:12}),`0`]}),(0,M.jsx)(`span`,{className:`badge badge-primary`,children:e(`codexAuth.nextSession`)})]}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,tabIndex:-1,disabled:!0,children:[(0,M.jsx)(y,{width:14}),` `,e(`codexAuth.pause`)]}),(0,M.jsxs)(`span`,{className:`card-right`,children:[(0,M.jsx)(_,{width:14}),` `,e(`codexAuth.appLogin`)]})]}),(0,M.jsxs)(`div`,{className:`card-sub`,children:[(0,M.jsx)(`span`,{className:`codex-auth-load-skeleton__strut`,children:e(`codexAuth.appLogin`)}),(0,M.jsx)(`span`,{className:`codex-auth-load-skeleton__line codex-auth-load-skeleton__line--sub`})]}),(0,M.jsx)(et,{quota:null,threshold:0,t:e,pending:!0})]}),(0,M.jsxs)(`div`,{className:`section-sep`,"aria-hidden":`true`,children:[(0,M.jsx)(`span`,{className:`section-label`,children:e(`codexAuth.accountPool`)}),(0,M.jsx)(`div`,{className:`sep-line`}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,tabIndex:-1,disabled:!0,children:[(0,M.jsx)(v,{width:14}),` `,e(`codexAuth.add`)]})]}),(0,M.jsx)(`div`,{className:`empty codex-auth-pool-empty codex-auth-load-skeleton__empty`,"aria-hidden":`true`,children:(0,M.jsx)(`div`,{className:`title`,children:e(`codexAuth.noPool`)})}),(0,M.jsx)(`span`,{className:`sr-only`,children:e(`pws.accountsLoading`)})]}):t===`error`?(0,M.jsxs)(`div`,{className:`pwi-auth-state pwi-auth-state--error`,role:`alert`,children:[(0,M.jsx)(`span`,{children:e(`codexAuth.loadFailed`)}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:r,children:e(`pws.retryAccounts`)})]}):null}function yt(e,t){return t===void 0?e(`codexAuth.resetSuccessGeneric`):e(`codexAuth.resetSuccess`,{remaining:String(t)})}async function bt(e,t,n,r){try{let i=await fetch(`${e}/api/codex-auth/reset-credits/consume`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:t})}),a=await o(i);return a?a.code===`reset`||a.code===`already_redeemed`?(await r(!0),{ok:!0,close:!0,toast:yt(n,typeof a.remaining==`number`&&Number.isFinite(a.remaining)?Math.max(0,a.remaining):void 0)}):{ok:!1,close:!0,toast:n(a.code===`nothing_to_reset`?`codexAuth.resetNothingToReset`:a.code===`no_credit`?`codexAuth.resetNoCredit`:`codexAuth.resetError`)}:{ok:!1,toast:n(`codexAuth.resetError`)}}catch{return{ok:!1,toast:n(`codexAuth.resetError`)}}}var xt=`ocx doctor`;function St({apiBase:e,accountModeState:n=null,banner:r=null,embedded:i=!1,onActiveNeedsReauthChange:a,controller:s,advancedExtras:l=null}){let u=t(),d=ze(e,{updated:u(`codexAuth.autoSwitchUpdated`),updateFailed:u(`codexAuth.autoSwitchUpdateFailed`),invalid:u(`codexAuth.autoSwitchThresholdInvalid`)}),[f,p]=(0,k.useState)(null),{beginServerRead:m,acceptServerRead:h,rejectServerRead:g,hydrateServerValue:_}=d,y=Ce(e,!s),b=s??y,{accounts:x,activeId:S,loadState:C,switchingId:w,pauseUpdatingId:T,priorityUpdatingId:E,pausingExhausted:D,activePinnedId:O,load:A}=b,[j,N]=(0,k.useState)(null),[P,F]=(0,k.useState)(!1),[I,L]=(0,k.useState)(!1),[R,z]=(0,k.useState)(null),[B,V]=(0,k.useState)(null),[te,H]=(0,k.useState)(null),U=(0,k.useRef)(null),[W,G]=(0,k.useState)(!1),[ne,K]=(0,k.useState)(void 0),[ie,ae]=(0,k.useState)(!1),[q,J]=(0,k.useState)(null),[oe,Y]=(0,k.useState)(!1),[se,ce]=(0,k.useState)(!1),[ue,X]=(0,k.useState)(null),[Z,de]=(0,k.useState)(!1),fe=re(),Q=(0,k.useCallback)((e,t=`ok`)=>{U.current&&clearTimeout(U.current),V(e),H(t),U.current=setTimeout(()=>{V(null),H(null),U.current=null},5e3)},[]);(0,k.useEffect)(()=>()=>{U.current&&clearTimeout(U.current)},[]);let pe=(0,k.useCallback)(e=>{fe.copy(xt,e)},[fe]),{subscribeLoadObserver:me,readLastThreshold:he}=b;(0,k.useEffect)(()=>me({beginActiveRead:m,acceptActiveRead:h,rejectActiveRead:g}),[me,m,h,g]),(0,k.useEffect)(()=>{let e=he();e!==void 0&&_(e)},[he,_]),(0,k.useEffect)(()=>{if(!P)return;let e=b.pauseRefresh();return()=>b.resumeRefresh(e)},[b,P]);let $=S&&S!==`__main__`?x.find(e=>e.id===S):null,ge=!$?.paused&&ee($);(0,k.useEffect)(()=>{a?.(ge)},[ge,a]);let _e=(0,k.useCallback)(e=>{z(e),F(!0)},[]),ve=(0,k.useCallback)(()=>{F(!1),z(null)},[]),ye=(0,k.useCallback)(e=>{b.syncAfterAccountAdded(),Q(u(e.catalogRefreshPending?`codexAuth.catalogRefreshPending`:`codexAuth.accountAdded`),e.catalogRefreshPending?`warn`:`ok`),ve()},[ve,b,Q,u]),be=async e=>{let t=await b.switchAccount(e);if(!t.ok){if(t.reason===`busy`)return;Q(u(`codexAuth.switchFailed`),`err`);return}N(null);let r=t.activeId,i=r&&r!==`__main__`?x.find(e=>e.id===r)?.email??u(`pws.accountOrdinal`,{count:`1`}):u(`codexAuth.mainAccount`);Q(u(n===`direct`?`codexAuth.poolPreparedToast`:`codexAuth.switched`,{email:i}))},xe=async e=>{let t=window.prompt(u(`prov.aliasPrompt`),e.alias??``);if(t===null)return;let n=await b.saveAlias(e.id,t);Q(u(n.ok?`prov.aliasSaved`:`prov.aliasSaveFailed`),n.ok?`ok`:`err`)},Se=async e=>{let t=!e.paused,n=await b.setAccountPaused(e.id,t);!n.ok&&n.reason===`busy`||(N(t=>t?.id===e.id?null:t),Q(u(n.ok?t?`codexAuth.pauseSucceeded`:`codexAuth.resumeSucceeded`:t?`codexAuth.pauseFailed`:`codexAuth.resumeFailed`,{email:e.alias??e.email}),n.ok?`ok`:`err`))},we=async(e,t)=>{if(t===e.priority)return;let n=await b.setAccountPriority(e.id,t);!n.ok&&n.reason===`busy`||Q(u(n.ok?`accountPool.priorityUpdated`:`accountPool.priorityUpdateFailed`,{email:e.alias??e.email}),n.ok?`ok`:`err`)},Ee=async e=>{let t=x.find(t=>t.id===e)?.email??u(`pws.accountOrdinal`,{count:`1`});if(!window.confirm(u(`codexAuth.removeConfirm`,{id:t})))return;let n=await b.removeAccount(e);n.ok?n.catalogRefreshPending&&Q(u(`codexAuth.catalogRefreshPending`),`warn`):Q(u(`codexAuth.removeFailed`),`err`)},De=async()=>{G(!0);try{let e=await A(!0);Q(u(e?`codexAuth.quotaRefreshed`:`codexAuth.quotaRefreshFailed`),e?`ok`:`err`)}finally{G(!1)}};(0,k.useEffect)(()=>{let t=new AbortController;return fetch(`${e}/api/settings`,{signal:t.signal}).then(e=>e.ok?e.json():null).then(e=>{t.signal.aborted||typeof e?.showCodexSparkQuota!=`boolean`||K(e.showCodexSparkQuota)}).catch(()=>{}),()=>{t.abort()}},[e]);let Oe=async()=>{if(ie||ne===void 0)return;let t=!ne;ae(!0),K(t);try{let n=await fetch(`${e}/api/settings`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({showCodexSparkQuota:t})});if(!n.ok)throw Error(`save`);let r=await n.json(),i=typeof r.showCodexSparkQuota==`boolean`?r.showCodexSparkQuota:t;K(i),Q(u(i?`codexAuth.sparkQuotaShown`:`codexAuth.sparkQuotaHidden`),`ok`),await A(!0)}catch{K(!t),Q(u(`codexAuth.sparkQuotaFailed`),`err`)}finally{ae(!1)}},ke=async()=>{let e=await b.pauseExhaustedAccounts();!e.ok&&e.reason===`busy`||Q(e.ok?e.pausedCount>0?u(`codexAuth.pauseExhaustedSucceeded`,{count:String(e.pausedCount)}):u(`codexAuth.pauseExhaustedNone`):u(`codexAuth.pauseExhaustedFailed`),e.ok?`ok`:`err`)},Ae=async t=>{J(t),Y(!1),X(null),de(!0);try{let n=await fetch(`${e}/api/codex-auth/reset-credits?accountId=${encodeURIComponent(t.id)}`),r=await o(n);if(r){let e=(r.credits??[]).sort((e,t)=>new Date(e.granted_at).getTime()-new Date(t.granted_at).getTime());X(e)}}catch{}finally{de(!1)}},je=async t=>{ce(!0);try{let n=await bt(e,t,u,A);n.close&&(J(null),Y(!1)),n.toast&&Q(n.toast,n.ok?`ok`:`err`)}finally{ce(!1)}},Me=x.find(e=>e.isMain),Ne=x.filter(e=>!e.isMain),Pe=!Me?.paused&&(!S||S===`__main__`),Fe=u(n===`direct`?`codexAuth.prepareForPool`:`codexAuth.setAsNext`),Ie=T!==null||D,Be=d.threshold??0,Ve=!i;return(0,M.jsxs)(`div`,{children:[(0,M.jsx)(_t,{t:u,embedded:i,refreshingQuota:W,actionFeedback:B,actionFeedbackTone:te,pausingExhausted:D,pauseBusy:Ie,onRefresh:()=>{De()},onPauseExhausted:()=>{ke()},sparkVisible:ne,sparkBusy:ie,onToggleSpark:()=>{Oe()}}),r,(0,M.jsx)(vt,{t:u,loadState:C,accountsCount:x.length,onRetry:()=>{A()}}),(C!==`loading`||x.length!==0)&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(gt,{t:u,main:Me,isMainActive:Pe,accountModeState:n,threshold:Be,switchActionLabel:Fe,onSwitch:N,onTogglePause:Se,pauseUpdatingId:T,pauseBusy:Ie,onPriorityChange:(e,t)=>{we(e,t)},priorityUpdatingId:E,switchingId:w,pinnedId:O,onOpenReset:Ae,onCopyDoctor:Ve?pe:void 0,doctorCopyOutcomeFor:Ve?fe.outcomeFor:void 0}),(0,M.jsxs)(`div`,{className:`section-sep`,children:[(0,M.jsx)(`span`,{className:`section-label`,children:u(`codexAuth.accountPool`)}),(0,M.jsx)(`div`,{className:`sep-line`}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,onClick:()=>F(!0),children:[(0,M.jsx)(v,{width:14}),` `,u(`codexAuth.add`)]})]}),ge&&$&&(0,M.jsx)(pt,{onReauth:()=>_e($.id)}),Ne.length===0&&(0,M.jsx)(c,{title:u(`codexAuth.noPool`)}),(0,M.jsx)(ft,{pool:Ne,activeId:S,accountModeState:n,switchActionLabel:Fe,threshold:Be,onOpenReset:Ae,onSwitch:N,onTogglePause:Se,pauseUpdatingId:T,pauseBusy:Ie,onPriorityChange:(e,t)=>{we(e,t)},priorityUpdatingId:E,switchingId:w,pinnedId:O,onReauth:_e,onEditAlias:xe,onRemove:Ee,onCopyDoctor:Ve?pe:void 0,doctorCopyOutcomeFor:Ve?fe.outcomeFor:void 0})]}),(0,M.jsx)(Le,{apiBase:e,subscribeLoadObserver:b.subscribeLoadObserver,readLastActive:b.readLastActive,onStrategyResolved:p}),(0,M.jsxs)(Re,{t:u,open:I,onToggle:()=>L(e=>!e),children:[f!==null&&(0,M.jsx)(Te,{threshold:d.threshold,draft:d.draft,strategy:f,hydrated:d.hydrated,saving:d.saving,loadError:d.loadError,feedback:d.feedback,onDraftChange:d.setDraft,onEditingChange:d.setEditing,onCommit:d.commit,onCancel:d.cancel,onToggle:d.toggle,onRetry:()=>{d.retry(),A()}}),l]}),j&&(0,M.jsx)(mt,{confirm:j,mainEmail:Me?.email,accountModeState:n,switchingId:w,orderBusy:E!==null,onCancel:()=>N(null),onConfirm:()=>{be(j.id===`__main__`?`__main__`:j.id)}}),q&&(0,M.jsx)(ht,{resetPopup:q,resetConfirm:oe,creditDetails:ue,creditDetailsLoading:Z,redeeming:se,onClose:()=>{J(null),Y(!1),X(null)},onShowConfirm:()=>Y(!0),onCancelConfirm:()=>Y(!1),onRedeem:()=>{je(q.id)}}),P&&(0,M.jsx)(le,{apiBase:e,reauthAccountId:R??void 0,onClose:ve,onAdded:ye})]})}var Ct=`https://chatgpt.com/backend-api/codex`;function wt(e){try{let t=new URL(e.trim());if(t.username||t.password||t.search||t.hash)return;let n=t.pathname.replace(/\/+$/,``);return`${t.origin}${n}`}catch{return}}function Tt(e){return[`openai`,...Object.entries(e).filter(([,e])=>e.authMode===`forward`).map(([e])=>e).filter(e=>e!==`openai`).sort((e,t)=>e.localeCompare(t))]}function Et(e){return e?e.adapter!==`openai-responses`||e.authMode!==`forward`||typeof e.baseUrl!=`string`||wt(e.baseUrl)!==Ct?`invalid`:e.disabled===!0?`disabled`:`ready`:`absent`}function Dt(e){return e.id===`openai`}function Ot(e){return e.id===`openai`?e.codexAccountMode===`direct`?`prov.openaiDirectDesc`:`prov.openaiPoolDesc`:null}function kt(e){let t={adapter:e.adapter.trim(),baseUrl:e.baseUrl.trim()};return e.responsesPath?.trim()&&(t.responsesPath=e.responsesPath.trim()),(e.authMode===`key`||e.authMode===`forward`)&&(t.authMode=e.authMode),e.authMode===`key`&&e.apiKey.trim()&&(t.apiKey=e.apiKey.trim()),e.adapter.trim()===`anthropic`&&e.authMode===`key`&&e.apiKeyTransport===`bearer`&&(t.apiKeyTransport=`bearer`),e.defaultModel.trim()&&(t.defaultModel=e.defaultModel.trim()),e.allowPrivateNetwork&&(t.allowPrivateNetwork=!0),t}function At(e,t){return Dt(e)?jt(e):{name:t.name.trim(),provider:kt(t)}}function jt(e){if(!e.provider)throw Error(`Missing canonical provider seed for ${e.id}`);return{name:e.id,provider:structuredClone(e.provider)}}var Mt=class extends Error{i18nKey;constructor(e){super(e),this.name=`OpenAiEnableError`,this.i18nKey=e}};async function Nt(e,t,n=fetch){if(t===`disabled`){if((await n(`${e}/api/providers?name=openai`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({disabled:!1})})).ok)return;throw new Mt(`codexAuth.enableOpenaiFailed`)}let r=await n(`${e}/api/provider-presets`);if(!r.ok)throw new Mt(`codexAuth.openaiPresetLoadFailed`);let i=(await r.json()).providers?.find(e=>e.id===`openai`);if(!i?.provider)throw new Mt(`codexAuth.openaiPresetUnavailable`);if(!(await n(`${e}/api/providers`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(jt(i))})).ok)throw new Mt(`codexAuth.enableOpenaiFailed`)}export{te as C,R as D,z as E,F as O,ee as S,L as T,le as _,Nt as a,Y as b,St as c,Fe as d,De as f,Ce as g,je as h,Ot as i,et as l,ke as m,At as n,Dt as o,Ae as p,Tt as r,Et as s,Mt as t,qe as u,oe as v,H as w,ie as x,J as y};
|
|
1
|
+
import{_ as e,c as t,h as n,m as r,s as i}from"./shared-DI18-uF7.js";import{I as a,M as o,N as s,P as c,Q as l,U as u,X as d,Y as f,_ as p,_t as m,ct as h,dt as g,it as _,lt as v,ot as y,rt as b,u as x,v as S,xt as C,yt as w}from"./index-DHQHBRhb.js";import{n as T,t as E}from"./NumberStepper-Dug4wR8n.js";import{n as D,t as O}from"./intl-formatters-CTcuZoAe.js";var k=e(n(),1),A=e=>({step:e?`oauth-waiting`:`pick`,id:``,error:``,authUrl:``,manualCode:``,manualCodeState:`idle`,statusNotice:``,statusTone:`ok`,flowId:null});function j(e,t){switch(t.type){case`set-step`:return{...e,step:t.step};case`set-id`:return{...e,id:t.id};case`set-error`:return{...e,error:t.error};case`set-auth-url`:return{...e,authUrl:t.authUrl};case`set-manual-code`:return{...e,manualCode:t.manualCode};case`set-manual-code-state`:return{...e,manualCodeState:t.manualCodeState};case`set-status-notice`:return{...e,statusNotice:t.statusNotice,statusTone:t.statusTone??e.statusTone};case`set-flow-id`:return{...e,flowId:t.flowId};case`clear-manual-code`:return{...e,manualCode:``,manualCodeState:`idle`,statusNotice:``,statusTone:`ok`};case`reset-oauth-start`:return{...e,error:``,statusNotice:``,statusTone:`ok`,flowId:null};case`oauth-code-submitted`:return{...e,error:``,manualCode:``,manualCodeState:`waiting`,statusTone:`ok`,statusNotice:``};default:return e}}var M=r();function N({id:e,error:n,onIdChange:r,onStartOAuth:i,onClose:a}){let o=t();return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{style:{marginBottom:4},children:o(`codexAuth.addTitle`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:o(`codexAuth.addPickDesc`)}),(0,M.jsx)(`label`,{className:`field-label`,htmlFor:`codex-account-id-input`,children:o(`codexAuth.addIdLabel`)}),(0,M.jsx)(`input`,{id:`codex-account-id-input`,className:`input`,placeholder:o(`codexAuth.addIdPlaceholder`),value:e,onChange:e=>r(e.target.value),style:{marginBottom:12}}),(0,M.jsx)(`button`,{type:`button`,className:`list-row`,onClick:i,style:{marginBottom:8},children:(0,M.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:10},children:[(0,M.jsx)(l,{width:20}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`div`,{className:`title`,children:o(`codexAuth.oauthLogin`)}),(0,M.jsx)(`div`,{className:`sub`,children:o(`codexAuth.oauthDesc`)})]})]})}),n&&(0,M.jsx)(`div`,{className:`notice notice-err`,style:{marginTop:8},children:n}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:a,style:{width:`100%`},children:o(`codexAuth.cancel`)})]})}function P(e){if(!e)return null;let t=e.trim();return t?t.length<=4?`account-…`:`account-…${t.slice(-4)}`:null}function F(e){return P(e)??`account-…`}function I(e){return e===`healthy`?`ok`:e===`cooldown`?`muted`:e===`reauth_required`||e===`warning`?`warn`:`muted`}function L(e){let t=I(e);return t===`ok`?`badge badge-green`:t===`warn`?`badge badge-amber`:`badge badge-muted`}function R(e){return e===`reauth_required`}function ee(e){return!!e?.needsReauth||R(e?.health?.status)}function z(e){return e===`cooldown`}function B(e){return e===`warning`||e===`reauth_required`}function V(e){if(!e||e.status===`healthy`)return null;if(e.status===`cooldown`)return e.reason===`rate_limit`?`pws.healthLabel.rateLimited`:`pws.healthLabel.quotaLimited`;if(e.status===`reauth_required`)return e.reason===`refresh_failed`?`pws.healthLabel.refreshFailed`:`pws.healthLabel.reauthRequired`;switch(e.reason){case`refresh_conflict`:return`pws.healthLabel.credentialConflict`;case`metadata_mismatch`:return`pws.healthLabel.metadataMismatch`;case`stale_credentials`:return`pws.healthLabel.refreshFailed`;default:return`pws.healthLabel.reauthRequired`}}function te(e,t){let n=V(t);return n?e(n):null}function H(e,t,n,r){if(!r||r.status===`healthy`)return null;let i=n===`__main__`?e(`codexAuth.mainAccount`):F(n);if(r.status===`cooldown`){let n=r.until?new Date(r.until).toLocaleString():``;return e(r.reason===`rate_limit`?`pws.healthSummary.rateLimited`:`pws.healthSummary.quotaLimited`,{provider:t,account:i,until:n})}return r.status===`reauth_required`?e(`pws.healthSummary.reauthRequired`,{provider:t,account:i}):r.reason===`refresh_conflict`?e(`pws.healthSummary.credentialConflict`,{provider:t,account:i}):r.reason===`metadata_mismatch`?e(`pws.healthSummary.metadataMismatch`,{provider:t,account:i}):e(`pws.healthSummary.staleCredentials`,{provider:t,account:i})}async function U(e){let t=navigator.clipboard?.writeText?.bind(navigator.clipboard);if(t)try{return await t(e),!0}catch{}return W(e)}function W(e){if(typeof document>`u`||typeof document.execCommand!=`function`)return!1;let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.setAttribute(`aria-hidden`,`true`),t.style.position=`fixed`,t.style.top=`0`,t.style.opacity=`0`,document.body.appendChild(t);try{return t.select(),document.execCommand(`copy`)}catch{return!1}finally{t.remove()}}function G(e,t){return e(t?t===`copied`?`pws.doctorCopied`:`pws.doctorCopyUnavailable`:`pws.copyDoctor`)}var ne=2500;function re(){let[e,t]=(0,k.useState)(null),n=(0,k.useRef)(null),r=(0,k.useRef)(0),i=(0,k.useCallback)(()=>{n.current&&=(clearTimeout(n.current),null)},[]);return(0,k.useEffect)(()=>i,[i]),{outcomeFor:(0,k.useCallback)(t=>e&&Object.is(e.scope,t)?e.outcome:null,[e]),copy:(0,k.useCallback)((e,a)=>{let o=++r.current;U(e).then(e=>{r.current===o&&(i(),t({scope:a,outcome:e?`copied`:`unavailable`}),n.current=setTimeout(()=>{n.current=null,r.current===o&&t(null)},ne))})},[i])}}function K({url:e}){let n=t(),{outcomeFor:r,copy:i}=re();if(!e)return null;let a=r(e),o=n(a===`copied`?`prov.linkCopied`:a===`unavailable`?`prov.linkCopyUnavailable`:`prov.copyLink`);return(0,M.jsxs)(`div`,{className:`login-url-block`,children:[(0,M.jsx)(`code`,{className:`login-url-block-text`,children:e}),(0,M.jsxs)(`div`,{className:`login-url-block-actions`,children:[(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>i(e,e),children:[(0,M.jsx)(b,{style:{width:13,height:13},"aria-hidden":`true`}),(0,M.jsx)(`span`,{"aria-live":`polite`,children:o})]}),(0,M.jsxs)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`login-url-block-open`,children:[(0,M.jsx)(d,{style:{width:13,height:13},"aria-hidden":`true`}),` `,n(`prov.didntOpen`)]})]})]})}function ie({hint:e,paste:n}){let r=t(),i=re(),a=e.deviceCode??``,o=e.url??``;if(!a&&!o&&!e.instructions&&!n)return null;let s=i.outcomeFor(a),c=r(s===`copied`?`prov.codeCopied`:s===`unavailable`?`prov.linkCopyUnavailable`:`prov.copyCode`);return(0,M.jsxs)(`div`,{className:`login-hint`,children:[a&&(0,M.jsxs)(`div`,{className:`login-hint-device pwi-device-code-wrap`,children:[(0,M.jsx)(`span`,{className:`text-label`,children:r(`prov.deviceCode`)}),(0,M.jsx)(`code`,{className:`login-hint-device-code pwi-device-code`,children:a}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>i.copy(a,a),children:(0,M.jsx)(`span`,{"aria-live":`polite`,children:c})})]}),(0,M.jsx)(K,{url:o}),e.instructions&&(0,M.jsx)(`div`,{className:`muted text-label`,children:e.instructions}),n&&(0,M.jsxs)(`div`,{className:`login-hint-paste`,children:[(0,M.jsx)(`div`,{className:`muted text-label`,children:r(`prov.pasteRedirectHint`)}),(0,M.jsxs)(`div`,{className:`login-hint-paste-row`,children:[(0,M.jsx)(`input`,{type:`text`,autoComplete:`off`,spellCheck:!1,value:n.value,onChange:e=>n.onChange(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),n.onSubmit())},placeholder:r(`prov.pasteRedirect`),"aria-label":r(`prov.pasteRedirect`),disabled:n.busy,className:`input text-label login-hint-paste-input`}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:n.busy||n.disabled===!0||!n.value.trim(),onClick:n.onSubmit,children:n.busy?n.submittingLabel??r(`prov.pasteSubmitting`):r(`prov.pasteSubmit`)})]}),n.message&&(0,M.jsx)(`div`,{className:`text-label`,"aria-live":`polite`,style:{color:n.ok?`var(--accent-hover)`:`var(--amber)`},children:n.message})]})]})}function ae({reauthAccountId:e,authUrl:n,manualCode:r,manualCodeBusy:i,manualCodeWaiting:a,statusNotice:o,statusTone:s,flowId:c,error:l,onManualCodeChange:u,onSubmitManualCode:d,onClose:f}){let p=t();return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`h3`,{style:{marginBottom:4},children:p(e?`codexAuth.reauthenticate`:`codexAuth.oauthLogin`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:p(`codexAuth.oauthWaiting`)}),(0,M.jsx)(ie,{hint:{url:n},paste:{value:r,busy:i,disabled:i||a||!r.trim()||!c,submittingLabel:p(`codexAuth.oauthSubmittingCode`),message:``,ok:!0,onChange:u,onSubmit:d}}),o&&(0,M.jsx)(`div`,{className:s===`warn`?`notice-warn`:`notice notice-ok`,role:`status`,"aria-live":`polite`,style:{marginTop:12},children:o}),l&&(0,M.jsx)(`div`,{className:`notice notice-err`,style:{marginTop:12},children:l}),(0,M.jsx)(`div`,{style:{textAlign:`center`,padding:`24px 0`},children:(0,M.jsx)(`span`,{className:`spin`,style:{width:24,height:24}})}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:f,style:{width:`100%`},children:p(`codexAuth.cancel`)})]})}var q=`ocx.oauth.openBrowser`;function J(){try{let e=window.localStorage.getItem(q);return e===`0`?!1:e===`1`||void 0}catch{return}}function oe(){let e=J();return e===void 0?{}:{openBrowser:e}}function Y(e){try{window.localStorage.setItem(q,e?`1`:`0`)}catch{}}function se(e){if(typeof e!=`object`||!e||Array.isArray(e))return{catalogRefreshPending:!1};let t=Object.getOwnPropertyDescriptor(e,`catalogRefreshPending`);return{catalogRefreshPending:t!==void 0&&`value`in t&&t.value===!0}}function ce({apiBase:e,reauthAccountId:t,ui:n,dispatch:r,t:i}){let a=(0,k.useRef)(!0),c=(0,k.useRef)(0),l=(0,k.useRef)(!1),u=(0,k.useRef)(null),d=(0,k.useRef)(null),f=(0,k.useRef)(null),m=(0,k.useRef)(null),h=(0,k.useRef)(n.manualCodeState),g=(0,k.useRef)(null),_=(0,k.useRef)(null),v=(0,k.useRef)(()=>{}),y=(0,k.useRef)(()=>{}),b=n.manualCodeState===`submitting`,x=n.manualCodeState===`waiting`;(0,k.useEffect)(()=>{h.current=n.manualCodeState},[n.manualCodeState]),(0,k.useEffect)(()=>{m.current=n.flowId},[n.flowId]);let S=(0,k.useCallback)(()=>{u.current&&=(u.current(),null),d.current&&=(clearTimeout(d.current),null),f.current?.abort(),f.current=null,l.current=!1},[]),C=(0,k.useCallback)(()=>{r({type:`clear-manual-code`}),c.current=0},[r]),w=(0,k.useCallback)(async()=>{C();let t=m.current;m.current=null,r({type:`set-flow-id`,flowId:null}),r({type:`set-auth-url`,authUrl:``}),S(),g.current?.abort(),g.current=null,t&&await fetch(`${e}/api/codex-auth/login/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({flowId:t})}).catch(()=>{})},[e,C,r,S]);(0,k.useEffect)(()=>(a.current=!0,()=>{C(),a.current=!1,_.current=null,g.current?.abort(),g.current=null;let t=m.current;m.current=null,r({type:`set-flow-id`,flowId:null}),S(),t&&fetch(`${e}/api/codex-auth/login/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({flowId:t})}).catch(()=>{})}),[e,C,r,S]);let T=(0,k.useCallback)((e,t)=>{v.current=e,y.current=t},[]),E=(0,k.useCallback)(()=>{n.step===`oauth-waiting`&&w(),y.current()},[n.step,w]),D=(0,k.useCallback)(async n=>{C(),m.current=null,r({type:`set-flow-id`,flowId:null});let _=new AbortController;g.current?.abort(),g.current=_,r({type:`reset-oauth-start`}),c.current=0;try{let g=t??n?.trim()??``,b=()=>fetch(`${e}/api/codex-auth/login`,{signal:_.signal,method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...oe(),...t?{id:t,reauth:!0}:g?{id:g}:{}})}),x=await b();if(!a.current)return;if(x.status===409){if(await fetch(`${e}/api/codex-auth/login/cancel`,{method:`POST`,headers:{"Content-Type":`application/json`},body:`{}`}),!a.current||_.signal.aborted)return;if(x=await b(),x.status===409){r({type:`set-error`,error:i(`codexAuth.oauthAlreadyInProgress`)});return}}let T=await s(x,i(`modal.networkError`));if(!a.current||!T)return;if(T.url){m.current=T.flowId??null,r({type:`set-flow-id`,flowId:T.flowId??null}),r({type:`set-auth-url`,authUrl:T.url}),r({type:`set-step`,step:`oauth-waiting`}),S();let n=T.flowId??``,s=t?`&reauth=1`:``,_=n?`${e}/api/codex-auth/login-status?flowId=${encodeURIComponent(n)}${g?`&accountId=${encodeURIComponent(g)}`:``}${s}`:`${e}/api/codex-auth/login-status`,b=new AbortController;f.current=b,u.current=p(async()=>{if(l.current||b.signal.aborted)return;l.current=!0;let e=AbortSignal.any([b.signal,AbortSignal.timeout(1e4)]);try{let n=await fetch(_,{signal:e}),s=await o(n);if(!a.current||b.signal.aborted)return;if(!s){c.current+=1,c.current>=3&&r({type:`set-status-notice`,statusNotice:i(`codexAuth.oauthStatusRetrying`),statusTone:`warn`});return}if(c.current=0,h.current===`waiting`?r({type:`set-status-notice`,statusNotice:i(`codexAuth.oauthCodeSubmitted`),statusTone:`ok`}):r({type:`set-status-notice`,statusNotice:``,statusTone:`ok`}),s.status===`done`){if(S(),C(),m.current=null,r({type:`set-flow-id`,flowId:null}),!a.current)return;v.current(se(s)),y.current()}else(s.status===`error`||s.status===`expired`)&&(S(),C(),m.current=null,r({type:`set-flow-id`,flowId:null}),a.current&&(t||r({type:`set-step`,step:`pick`}),r({type:`set-error`,error:s.error??i(`codexAuth.loginFailed`)})))}catch(e){if(!a.current||b.signal.aborted||e instanceof Error&&e.name===`AbortError`)return;c.current+=1,c.current>=3&&r({type:`set-status-notice`,statusNotice:i(`codexAuth.oauthStatusRetrying`),statusTone:`warn`})}finally{l.current=!1}},2e3),d.current=setTimeout(()=>{u.current&&(C(),w(),a.current&&(t||r({type:`set-step`,step:`pick`}),r({type:`set-error`,error:i(`modal.loginTimeout`)})))},3e5)}T.error&&!T.url&&r({type:`set-error`,error:T.error})}catch(e){a.current&&!(e instanceof Error&&e.name===`AbortError`)&&r({type:`set-error`,error:e instanceof Error?e.message:String(e)})}},[e,w,C,r,t,S,i]);return(0,k.useEffect)(()=>{if(!t){_.current=null;return}_.current!==t&&(_.current=t,D())},[t,D]),{manualCodeBusy:b,manualCodeWaiting:x,bindCallbacks:T,closeModal:E,startOAuth:D,submitManualCode:(0,k.useCallback)(async()=>{let t=m.current,o=n.manualCode.trim();if(!(!t||!o||b||x)){r({type:`set-manual-code-state`,manualCodeState:`submitting`}),r({type:`set-status-notice`,statusNotice:``,statusTone:`ok`});try{let n=await fetch(`${e}/api/codex-auth/login/code`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({flowId:t,input:o})});if(!a.current)return;if(!n.ok){r({type:`set-error`,error:i(`prov.pasteFail`,{error:(await n.json().catch(()=>({}))).error??n.statusText})}),r({type:`set-manual-code-state`,manualCodeState:`idle`});return}r({type:`oauth-code-submitted`}),r({type:`set-status-notice`,statusNotice:i(`codexAuth.oauthCodeSubmitted`),statusTone:`ok`}),c.current=0}catch{a.current&&(r({type:`set-error`,error:i(`modal.networkError`)}),r({type:`set-manual-code-state`,manualCodeState:`idle`}))}}},[e,r,b,x,i,n.manualCode])}}function le({apiBase:e,onClose:n,onAdded:r,reauthAccountId:i}){let a=t(),[o,s]=(0,k.useReducer)(j,i,A),c=(0,k.useRef)(null),l=(0,k.useRef)(null),{manualCodeBusy:u,manualCodeWaiting:d,bindCallbacks:f,closeModal:p,startOAuth:m,submitManualCode:h}=ce({apiBase:e,reauthAccountId:i,ui:o,dispatch:s,t:a});(0,k.useEffect)(()=>{f(r,n)},[f,r,n]),(0,k.useEffect)(()=>{c.current=document.activeElement;let e=l.current;e&&!e.open&&e.showModal();let t=e?.querySelector(`input:not([disabled]), button:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex='-1'])`);return t&&t.focus(),()=>{c.current?.focus()}},[]);let g=(0,k.useCallback)(e=>{e.preventDefault(),p()},[p]),_=a(i?`codexAuth.reauthenticate`:`codexAuth.addTitle`);return(0,M.jsx)(`dialog`,{ref:l,"aria-label":_,className:`modal-overlay`,onCancel:g,children:(0,M.jsxs)(`div`,{className:`modal-card`,style:{maxWidth:440},children:[o.step===`pick`&&(0,M.jsx)(N,{id:o.id,error:o.error,onIdChange:e=>s({type:`set-id`,id:e}),onStartOAuth:()=>{m(o.id)},onClose:p}),o.step===`oauth-waiting`&&(0,M.jsx)(ae,{reauthAccountId:i,authUrl:o.authUrl,manualCode:o.manualCode,manualCodeBusy:u,manualCodeWaiting:d,statusNotice:o.statusNotice,statusTone:o.statusTone,flowId:o.flowId,error:o.error,onManualCodeChange:e=>s({type:`set-manual-code`,manualCode:e}),onSubmitManualCode:()=>{h()},onClose:p})]})})}var ue=[2,1,0,-1,-2],X=new Map([[2,`accountPool.priorityFirst`],[1,`accountPool.priorityEarlier`],[0,`accountPool.priorityNormal`],[-1,`accountPool.priorityLater`],[-2,`accountPool.priorityLast`]]);function Z(e){return typeof e==`number`&&Number.isInteger(e)&&e>=-100&&e<=100?e:0}function de(e){let t=Z(e);return t>0?`+${t}`:String(t)}function fe(e){return X.has(e)}function Q(e){return X.get(e)??null}function pe(e,t){let n=Z(t);return e(`accountPool.priorityOption`,{name:e(Q(n)??`accountPool.priorityCustom`),value:de(n)})}var me=1e4;function he(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0&&e<=100?e:80}function $(e){let t=e.trim();if(!/^\d+$/.test(t))return null;let n=Number(t);return n>=1&&n<=100?n:null}function ge(e,t){return e>0?0:Number.isInteger(t)&&t>=1&&t<=100?t:80}function _e(e,t,n,r){return n===r?e||t?`defer`:`apply`:`ignore`}function ve(e){return e&&typeof e==`object`&&e&&`autoSwitchThreshold`in e?e.autoSwitchThreshold:e}function ye(e,t,n){if(e<=0){let t=ge(e,n);return{threshold:t,lastEnabled:t}}return{threshold:0,lastEnabled:$(t)??ge(0,n)}}async function be(e,t,n=(e,t)=>fetch(e,t),r=me){if(!Number.isInteger(t)||t<0||t>100)return!1;try{return(await n(`${e}/api/codex-auth/auto-switch`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({threshold:t}),signal:AbortSignal.timeout(r)})).ok}catch{return!1}}var xe=3e4,Se=new Map;function Ce(e,t=!0){let n=Se.get(e),[r,i]=(0,k.useState)(()=>n?.accounts??[]),a=C(x(e,`codex`),[e],async t=>{let n=await fetch(`${e}/api/usage?range=30d&surface=codex`,{signal:t});if(!n.ok)throw Error(`account usage load failed`);return n.json()},{enabled:t}),[o,s]=(0,k.useState)(()=>n?.activeId??null),[c,l]=(0,k.useState)(()=>n==null?`loading`:`ready`),[u,d]=(0,k.useState)(null),[f,m]=(0,k.useState)(null),[h,g]=(0,k.useState)(null),[_,v]=(0,k.useState)(!1),[y,b]=(0,k.useState)(null),[w,T]=(0,k.useState)(0),[E,D]=(0,k.useState)(()=>n!=null),[O,A]=(0,k.useState)(0),j=(0,k.useRef)(null);j.current===null&&(j.current=new Set);let M=(0,k.useRef)(null),N=(0,k.useRef)(0),P=(0,k.useRef)(null),F=(0,k.useRef)(null);F.current===null&&(F.current=new Set);let I=(0,k.useRef)(null),L=(0,k.useRef)(null),R=(0,k.useRef)(!!n?.accounts.length),z=(0,k.useRef)(n!=null),B=(0,k.useRef)(null),V=(0,k.useRef)(null),te=(0,k.useCallback)(e=>(F.current.add(e),()=>{F.current.delete(e)}),[]),H=(0,k.useCallback)(()=>ve(I.current?.value),[]),U=(0,k.useCallback)(()=>I.current?.value,[]),W=(0,k.useCallback)(async(t=!1)=>{let n=++N.current,r=S(2e4);T(e=>e+1);try{let a=[...F.current],o=new Map;for(let e of a)o.set(e,e.beginActiveRead());!t&&!z.current&&l(`loading`);let c=null,u,d=(async()=>{try{let a=await fetch(`${e}/api/codex-auth/accounts${t?`?refresh=1`:``}`,{signal:r.signal});if(!a.ok)throw Error(`account load failed`);let o=await a.json();return N.current===n&&(c=(o.accounts??[]).map(e=>{let t=e.isMain?`main`:e.logLabel;return{...e,...t?{logLabel:t}:{},priority:Z(e.priority)}}),i(c),R.current=c.length>0,z.current=!0,l(`ready`)),!0}catch{return!1}})(),f=(async()=>{try{let t=await fetch(`${e}/api/codex-auth/active`,{signal:r.signal});if(!t.ok)throw Error(`active account load failed`);let i=await t.json();if(N.current===n){let e=i.activeCodexAccountId??null,t=P.current;t&&e!==t.id||(P.current=null,u=e,s(e)),I.current={value:i},b(typeof i.pinnedAccountId==`string`?i.pinnedAccountId:null);for(let e of a)e.acceptActiveRead(i,o.get(e))}return!0}catch{if(N.current===n)for(let e of a)e.rejectActiveRead();return!1}})(),[p,m]=await Promise.all([d,f]);if(N.current!==n)return!1;if(p){l(`ready`),z.current=!0;let t=Se.get(e);return Se.set(e,{accounts:c??t?.accounts??[],activeId:u===void 0?t?.activeId??null:u}),m}return z.current||l(`error`),!1}finally{r.clear(),T(e=>Math.max(0,e-1)),D(!0)}},[e]);(0,k.useEffect)(()=>{t&&M.current!==e&&(M.current=e,Promise.resolve().then(()=>{W()}))},[e,t,W]);let G=r.some(e=>e.hasCredential&&!e.quota);(0,k.useEffect)(()=>{if(!t||!G||O>0)return;let e=[350,900,2e3].map(e=>window.setTimeout(()=>{W(!1)},e));return()=>{for(let t of e)window.clearTimeout(t)}},[t,G,O,W]),(0,k.useEffect)(()=>{if(!(!t||O>0))return p(()=>{W()},xe)},[t,W,O]);let ne=(0,k.useCallback)(()=>{let e={};return j.current.add(e),A(j.current.size),e},[]),re=(0,k.useCallback)(e=>{j.current.delete(e)&&A(j.current.size)},[]),K=(0,k.useCallback)(async t=>{if(L.current||V.current)return{ok:!1,reason:`busy`};L.current=t??`__main__`,d(t??`__main__`);try{let n=await fetch(`${e}/api/codex-auth/active`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:t})});if(!n.ok)throw Error(`account switch failed`);let r=(await n.json().catch(()=>({}))).activeCodexAccountId??t;return P.current={id:r??null},s(r??null),b(r??`__main__`),W(),{ok:!0,activeId:r??null}}catch{return{ok:!1,reason:`request`}}finally{L.current=null,d(null)}},[e,W]),ie=(0,k.useCallback)(async(t,n)=>{try{return(await fetch(`${e}/api/codex-auth/accounts/alias`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t,alias:n.trim()})})).ok?(await W(),{ok:!0}):{ok:!1,reason:`request`}}catch{return{ok:!1,reason:`request`}}},[e,W]),ae=(0,k.useCallback)(async(t,n)=>{if(B.current)return{ok:!1,reason:`busy`};B.current={accountId:t},m(t);try{let r=await fetch(`${e}/api/codex-auth/accounts/pause`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t,paused:n})});if(!r.ok)return{ok:!1,reason:`request`};let a=await r.json().catch(()=>({})),o=a&&typeof a==`object`?a:{};if(i(e=>e.map(e=>e.id===t||t===`__main__`&&e.isMain?{...e,paused:n}:e)),Object.prototype.hasOwnProperty.call(o,`activeCodexAccountId`)){let e=o.activeCodexAccountId??null;P.current={id:e},s(e)}return n&&b(e=>e===t?null:e),W(),{ok:!0}}catch{return{ok:!1,reason:`request`}}finally{B.current=null,m(null)}},[e,W]),q=(0,k.useCallback)(async(t,n)=>{if(V.current||L.current)return{ok:!1,reason:`busy`};V.current={accountId:t},g(t);try{let r=await fetch(`${e}/api/codex-auth/accounts/priority`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t,priority:n})});if(!r.ok)return{ok:!1,reason:`request`};let a=await r.json().catch(()=>({})),o=Z((a&&typeof a==`object`?a:{}).priority??n);return i(e=>e.map(e=>e.id===t||t===`__main__`&&e.isMain?{...e,priority:o}:e)),b(null),P.current=null,W(),{ok:!0}}catch{return{ok:!1,reason:`request`}}finally{V.current=null,g(null)}},[e,W]),J=(0,k.useCallback)(async()=>{if(B.current)return{ok:!1,reason:`busy`};B.current=`bulk`,v(!0);try{let t=await fetch(`${e}/api/codex-auth/accounts/pause-exhausted`,{method:`PUT`});if(!t.ok)return{ok:!1,reason:`request`};let n=await t.json().catch(()=>({})),r=n&&typeof n==`object`?n:{},a=new Set(r.pausedAccountIds??[]);if(i(e=>e.map(e=>a.has(e.id)||a.has(`__main__`)&&e.isMain?{...e,paused:!0}:e)),Object.prototype.hasOwnProperty.call(r,`activeCodexAccountId`)){let e=r.activeCodexAccountId??null;P.current={id:e},s(e)}return b(e=>e!==null&&a.has(e)?null:e),W(),{ok:!0,pausedCount:r.pausedCount??a.size}}catch{return{ok:!1,reason:`request`}}finally{B.current=null,v(!1)}},[e,W]),oe=(0,k.useCallback)(async t=>{try{let n=await fetch(`${e}/api/codex-auth/accounts?id=${encodeURIComponent(t)}`,{method:`DELETE`});if(!n.ok)return{ok:!1,reason:`request`};let r=se(await n.json().catch(()=>({})));return await W(),{ok:!0,...r}}catch{return{ok:!1,reason:`request`}}},[e,W]),Y=(0,k.useCallback)(async()=>await W()?{ok:!0}:{ok:!1,reason:`reload`},[W]),ce=o&&o!==`__main__`?r.find(e=>e.id===o):null,le=r.find(e=>e.isMain),ue=ce??le,X=!ue?.paused&&ee(ue);return{accounts:(0,k.useMemo)(()=>{let e=new Map((a.data?.accounts??[]).map(e=>[e.accountLogLabel,e]));return r.map(t=>{let n=t.isMain?`main`:t.logLabel,r=n?e.get(n):void 0;return r?{...t,usage30d:r}:t})},[r,a.data]),activeId:o,loadState:c,refreshing:w>0,initialLoading:!E,switchingId:u,pauseUpdatingId:f,priorityUpdatingId:h,pausingExhausted:_,activeNeedsReauth:X,activePinnedId:y,load:W,switchAccount:K,setAccountPaused:ae,setAccountPriority:q,pauseExhaustedAccounts:J,saveAlias:ie,removeAccount:oe,syncAfterAccountAdded:Y,pauseRefresh:ne,resumeRefresh:re,subscribeLoadObserver:te,readLastThreshold:H,readLastActive:U}}var we={quota:{on:`codexAuth.autoSwitchQuotaDesc`,off:`codexAuth.autoSwitchQuotaOffDesc`},"round-robin":{on:`codexAuth.autoSwitchRoundRobinDesc`,off:`codexAuth.autoSwitchRoundRobinDesc`},"fill-first":{on:`codexAuth.autoSwitchFillFirstDesc`,off:`codexAuth.autoSwitchFillFirstOffDesc`}};function Te({threshold:e,draft:n,strategy:r=`quota`,hydrated:i=!0,saving:a,loadError:o,feedback:s,onDraftChange:c,onEditingChange:l,onCommit:u,onCancel:d,onToggle:f,onRetry:p}){let m=t(),h=(0,k.useRef)(!1),g=e>0,_=we[r][g?`on`:`off`],v=a||!i,y=a?m(`common.saving`):s?.message??``,b=a?`pending`:s?.tone,x=y?`codex-auto-switch-desc codex-auto-switch-feedback`:`codex-auto-switch-desc`;return(0,M.jsxs)(`div`,{className:`card card-row codex-auto-switch-card`,style:{marginTop:16},"aria-busy":a||!i&&!o||void 0,children:[(0,M.jsxs)(`div`,{className:`codex-auto-switch-copy`,children:[(0,M.jsx)(`strong`,{children:m(`codexAuth.autoSwitch`)}),(0,M.jsx)(`div`,{id:`codex-auto-switch-desc`,className:`card-sub`,role:o?`alert`:void 0,children:o?m(`codexAuth.autoSwitchLoadFailed`):m(_,{threshold:e})}),(0,M.jsx)(`div`,{className:`card-sub`,children:m(`codexAuth.failureRecoveryNote`)}),(0,M.jsx)(`div`,{className:`card-sub`,children:m(`codexAuth.cacheWarning`)})]}),(0,M.jsxs)(`div`,{className:`codex-auto-switch-controls`,onBlur:e=>{if(!e.currentTarget.contains(e.relatedTarget)){if(l(!1),h.current){h.current=!1;return}g&&!v&&u()}},children:[o&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:p,children:m(`pws.retryAccounts`)}),g&&(0,M.jsxs)(`label`,{className:`codex-auto-switch-threshold`,children:[(0,M.jsx)(`span`,{className:`field-label`,children:m(`codexAuth.autoSwitchThreshold`)}),(0,M.jsxs)(`span`,{className:`codex-auto-switch-input-wrap`,children:[(0,M.jsx)(`input`,{className:`input mono codex-auto-switch-input`,type:`number`,min:1,max:100,step:1,inputMode:`numeric`,value:n,readOnly:v,"aria-disabled":v,"aria-label":m(`codexAuth.autoSwitchThresholdAria`),"aria-describedby":x,onChange:e=>c(e.target.value),onFocus:()=>{v||l(!0)},onKeyDown:e=>{e.nativeEvent.isComposing||v||(e.key===`Enter`?(e.preventDefault(),u()):e.key===`Escape`&&(e.preventDefault(),d()))}}),(0,M.jsx)(`span`,{className:`codex-auto-switch-unit`,"aria-hidden":`true`,children:`%`}),(0,M.jsx)(E,{disabled:v,incrementLabel:m(`codexAuth.autoSwitchThresholdInc`),decrementLabel:m(`codexAuth.autoSwitchThresholdDec`),onIncrement:()=>{l(!0),c(T(n,1,1,100))},onDecrement:()=>{l(!0),c(T(n,-1,1,100))}})]})]}),(0,M.jsx)(`span`,{className:`codex-auto-switch-toggle-slot`,children:(0,M.jsx)(`button`,{type:`button`,className:`toggle ${g?`on`:``}`,onPointerDownCapture:()=>{h.current=!0},onPointerUp:()=>{h.current=!1},onPointerCancel:()=>{h.current=!1},onClick:()=>{h.current=!1,f()},disabled:v,"aria-pressed":g,"aria-label":m(`codexAuth.autoSwitch`),"aria-describedby":x,title:m(`codexAuth.autoSwitch`),children:(0,M.jsx)(`span`,{className:`toggle-knob`})})})]}),y&&(0,M.jsx)(`div`,{id:`codex-auto-switch-feedback`,className:`codex-auto-switch-feedback${b===`err`?` is-error`:``}`,role:b===`err`?`alert`:`status`,"aria-atomic":`true`,children:y})]})}var Ee=[`quota`,`round-robin`,`fill-first`],De=`quota`,Oe=new Set(Ee);function ke(e){return typeof e==`string`&&Oe.has(e)?e:De}function Ae(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1&&e<=100?e:1}function je(e){let t=e.trim();if(!/^\d+$/.test(t))return null;let n=Number(t);return n>=1&&n<=100?n:null}async function Me(e,t,n=(e,t)=>fetch(e,t)){if(t.strategy===void 0&&t.stickyLimit===void 0)return{ok:!1};try{let r=await n(`${e}/api/codex-auth/pool-strategy`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({...t.strategy===void 0?{}:{strategy:t.strategy},...t.stickyLimit===void 0?{}:{stickyLimit:t.stickyLimit}})});if(!r.ok)return{ok:!1};let i=await r.json();return{ok:!0,strategy:ke(i.accountPoolStrategy??t.strategy),stickyLimit:Ae(i.accountPoolStickyLimit??t.stickyLimit)}}catch{return{ok:!1}}}var Ne={quota:`accountPool.strategyQuota`,"round-robin":`accountPool.strategyRoundRobin`,"fill-first":`accountPool.strategyFillFirst`},Pe={quota:`accountPool.strategyHintQuota`,"round-robin":`accountPool.strategyHintRoundRobin`,"fill-first":`accountPool.strategyHintFillFirst`};function Fe({strategy:e,stickyDraft:n,disabled:r=!1,strategySelectId:i=`account-pool-strategy`,stickyInputId:o=`account-pool-sticky-limit`,onStrategyChange:s,onStickyDraftChange:c,onStickyCommit:l}){let u=t(),d=Ee.map(e=>({value:e,label:u(Ne[e])}));return(0,M.jsxs)(`div`,{className:`account-pool-strategy-controls`,children:[(0,M.jsxs)(`div`,{className:`setting-row`,children:[(0,M.jsxs)(`div`,{className:`setting-label`,children:[(0,M.jsx)(`span`,{className:`title`,id:`${i}-label`,children:u(`accountPool.strategy`)}),(0,M.jsx)(`span`,{className:`desc`,children:u(`accountPool.strategyDesc`)}),(0,M.jsx)(`span`,{className:`desc`,children:u(Pe[e])}),(0,M.jsx)(`span`,{className:`desc`,children:u(`accountPool.unboundDefinition`)})]}),(0,M.jsx)(`div`,{className:`setting-controls`,children:(0,M.jsx)(a,{id:i,value:e,options:d,disabled:r,label:u(`accountPool.strategy`),onChange:e=>s(e)})})]}),e===`round-robin`&&(0,M.jsxs)(`div`,{className:`setting-row`,children:[(0,M.jsxs)(`label`,{className:`setting-label`,htmlFor:o,children:[(0,M.jsx)(`span`,{className:`title`,children:u(`accountPool.stickyLimit`)}),(0,M.jsx)(`span`,{className:`desc`,children:u(`accountPool.stickyLimitHelp`)})]}),(0,M.jsx)(`div`,{className:`setting-controls`,children:(0,M.jsxs)(`span`,{className:`codex-auto-switch-input-wrap`,children:[(0,M.jsx)(`input`,{id:o,className:`input mono codex-auto-switch-input`,type:`number`,min:1,max:100,step:1,inputMode:`numeric`,value:n,disabled:r,"aria-label":u(`accountPool.stickyLimitAria`),onChange:e=>c(e.target.value),onBlur:()=>l(),onKeyDown:e=>{e.nativeEvent.isComposing||r||e.key===`Enter`&&(e.preventDefault(),l())}}),(0,M.jsx)(E,{disabled:r,incrementLabel:u(`accountPool.stickyLimitInc`),decrementLabel:u(`accountPool.stickyLimitDec`),onIncrement:()=>{let e=T(n,1,1,100);c(e),l(e)},onDecrement:()=>{let e=T(n,-1,1,100);c(e),l(e)}})]})})]})]})}function Ie(e){if(!e||typeof e!=`object`)return null;let t=e;return!(`accountPoolStrategy`in t)&&!(`accountPoolStickyLimit`in t)?null:{strategy:ke(t.accountPoolStrategy),stickyLimit:Ae(t.accountPoolStickyLimit)}}function Le({apiBase:e,subscribeLoadObserver:n,readLastActive:r,onStrategyResolved:i}){let a=t(),[o,s]=(0,k.useState)(De),[c,l]=(0,k.useState)(1),[u,d]=(0,k.useState)(`1`),[f,p]=(0,k.useState)(!1),m=(0,k.useRef)(!1),[h,g]=(0,k.useState)(!1),_=(0,k.useRef)(!1),v=(0,k.useRef)(!1),y=(0,k.useRef)(0),[b,x]=(0,k.useState)(!1),[S,C]=(0,k.useState)(null),w=(0,k.useCallback)(e=>{let t=ke(e.accountPoolStrategy),n=Ae(e.accountPoolStickyLimit);s(t),i?.(t),l(n),d(String(n)),m.current=!0,p(!0),x(!1),C(null)},[i]),T=(0,k.useCallback)(e=>{let t=Ie(e);t&&w({accountPoolStrategy:t.strategy,accountPoolStickyLimit:t.stickyLimit})},[w]),E=(0,k.useCallback)(async()=>{try{let t=await fetch(`${e}/api/codex-auth/active`);if(!t.ok)throw Error(`load`);let n=await t.json();if(_.current){v.current=!0;return}w(n)}catch{_.current||x(!0)}},[e,w]),D=(0,k.useCallback)(()=>{v.current&&(v.current=!1,queueMicrotask(()=>{if(_.current){v.current=!0;return}E()}))},[E]);(0,k.useEffect)(()=>{if(!n)return;let e=n({beginActiveRead:()=>y.current,acceptActiveRead:(e,t)=>{if(t===y.current){if(_.current){v.current=!0;return}T(e)}},rejectActiveRead:()=>{m.current||x(!0)}});return!_.current&&r&&T(r()),e},[n,T,r]),(0,k.useEffect)(()=>{!r||n||_.current||T(r())},[r,T,n]),(0,k.useEffect)(()=>{n||E()},[E,n]);let O=(0,k.useCallback)(async t=>{if(_.current)return;let n=o,r=c;t.strategy!==void 0&&(s(t.strategy),i?.(t.strategy)),t.stickyLimit!==void 0&&(l(t.stickyLimit),d(String(t.stickyLimit))),_.current=!0,g(!0),C(null),y.current+=1;let u=await Me(e,t);y.current+=1,u.ok?(s(u.strategy),i?.(u.strategy),l(u.stickyLimit),d(String(u.stickyLimit)),m.current=!0,p(!0)):(C(a(`accountPool.strategyUpdateFailed`)),s(n),i?.(n),l(r),d(String(r))),_.current=!1,g(!1),D()},[e,i,D,c,o,a]),A=h||b||!f;return(0,M.jsxs)(`div`,{className:`card account-pool-strategy-card`,"aria-busy":h||!f&&!b,children:[b&&(0,M.jsx)(`div`,{className:`card-sub`,role:`alert`,children:a(`accountPool.strategyLoadFailed`)}),b&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm account-pool-strategy-card__retry`,onClick:()=>{E()},children:a(`common.retry`)}),!b&&(0,M.jsx)(Fe,{strategy:o,stickyDraft:u,disabled:A,strategySelectId:`codex-pool-strategy`,stickyInputId:`codex-pool-sticky-limit`,onStrategyChange:e=>{A||e===o||O({strategy:e})},onStickyDraftChange:d,onStickyCommit:e=>{if(A)return;let t=je(e??u);if(t===null){d(String(c)),C(a(`accountPool.stickyLimitInvalid`));return}if(t===c){d(String(t));return}O({stickyLimit:t})}}),S&&(0,M.jsx)(`div`,{role:`alert`,className:`card-sub account-pool-strategy-card__error`,children:S})]})}function Re({t:e,open:t,onToggle:n,children:r}){return(0,M.jsxs)(`section`,{className:`codex-auth-advanced`,children:[(0,M.jsxs)(`button`,{type:`button`,className:`codex-auth-advanced__toggle`,"aria-expanded":t,"aria-controls":`codex-auth-advanced-boxes`,onClick:n,children:[(0,M.jsx)(`span`,{children:e(`codexAuth.advancedSettings`)}),(0,M.jsx)(f,{width:12,height:12,"aria-hidden":`true`,className:t?`codex-auth-advanced__chevron is-open`:`codex-auth-advanced__chevron`})]}),t&&(0,M.jsx)(`div`,{id:`codex-auth-advanced-boxes`,className:`codex-auth-advanced__boxes`,children:r})]})}function ze(e,t){let[n,r]=(0,k.useState)(80),[i,a]=(0,k.useState)(`80`),[o,s]=(0,k.useState)(!1),[c,l]=(0,k.useState)(!1),[u,d]=(0,k.useState)(!1),[f,p]=(0,k.useState)(null),m=(0,k.useRef)(80),h=(0,k.useRef)(!1),g=(0,k.useRef)(80),_=(0,k.useRef)(!1),v=(0,k.useRef)(!1),y=(0,k.useRef)(!1),b=(0,k.useRef)(0),x=(0,k.useRef)(null),S=(0,k.useRef)(null),C=(0,k.useCallback)(e=>{m.current=e,h.current=!0,s(!0),r(e),e>0&&(g.current=e),a(String(e>0?e:g.current))},[]),w=(0,k.useCallback)(e=>{if(_.current||v.current){x.current=e;return}x.current=null,C(e)},[C]),T=(0,k.useCallback)(()=>{let e=x.current;return e!==null&&(x.current=null,C(e),!0)},[C]),E=(0,k.useCallback)(()=>{S.current!==null&&(window.clearTimeout(S.current),S.current=null),p(null)},[]),D=(0,k.useCallback)((e,t)=>{S.current!==null&&window.clearTimeout(S.current),p({tone:t?`err`:`ok`,message:e}),S.current=window.setTimeout(()=>{p(null),S.current=null},5e3)},[]);(0,k.useEffect)(()=>()=>{S.current!==null&&window.clearTimeout(S.current)},[]);let O=(0,k.useCallback)(()=>(h.current||l(!1),b.current),[]),A=(0,k.useCallback)((e,t)=>{l(!1);let n=ve(e),r=_e(_.current,v.current,t,b.current);r===`defer`?x.current=he(n):r===`apply`&&w(he(n))},[w]),j=(0,k.useCallback)(e=>{h.current||_.current||v.current||(l(!1),C(he(ve(e))))},[C]),M=(0,k.useCallback)(()=>{h.current||l(!0)},[]),N=(0,k.useCallback)(async(n,r,i=!0)=>{if(v.current)return!1;v.current=!0,_.current=!1,E(),d(!0),b.current+=1;try{let a=await be(e,n);return b.current+=1,a?(x.current=null,C(n),i&&D(t.updated,!1)):(T()||C(r),D(t.updateFailed,!0)),a}finally{v.current=!1,d(!1)}},[e,C,E,t.updateFailed,t.updated,T,D]),P=(0,k.useCallback)(()=>{_.current=!1;let e=m.current;T()||a(String(e>0?e:g.current)),D(t.invalid,!0)},[t.invalid,T,D]),F=(0,k.useCallback)(()=>{_.current=!1,y.current=!0,E();let e=m.current;T()||a(String(e>0?e:g.current))},[E,T]),I=(0,k.useCallback)(async()=>{if(y.current)return y.current=!1,!0;if(!h.current||v.current)return!1;let e=m.current;_.current=!1;let t=$(i);return t===null?(P(),!1):t===e?(T()||a(String(t)),!0):N(t,e)},[i,T,P,N]),L=(0,k.useCallback)(async()=>{if(!h.current||v.current)return!1;let e=m.current;_.current=!1;let t=ye(e,i,g.current),n=await N(t.threshold,e);return n?(g.current=t.lastEnabled,t.threshold===0&&a(String(t.lastEnabled)),n):!1},[i,N]);return{threshold:n,draft:i,hydrated:o,saving:u,loadError:c,feedback:f,beginServerRead:O,acceptServerRead:A,hydrateServerValue:j,rejectServerRead:M,setDraft:(0,k.useCallback)(e=>{h.current&&(_.current=!0,y.current=!1,E(),a(e))},[E]),setEditing:(0,k.useCallback)(e=>{_.current=e},[]),commit:I,cancel:F,toggle:L,retry:(0,k.useCallback)(()=>{l(!1),E()},[E])}}function Be({value:e,disabled:n=!1,selectId:r,onChange:i}){let o=t(),s=Z(e),c=o(`accountPool.priorityHint`),l=`${r}-hint`,u=ue.map(e=>({value:String(e),label:pe(o,e)})),d=fe(s)?u:[{value:String(s),label:pe(o,s)},...u];return(0,M.jsxs)(`div`,{className:`codex-account-priority`,children:[(0,M.jsx)(`label`,{className:`codex-account-priority-label`,htmlFor:r,children:o(`accountPool.priority`)}),(0,M.jsx)(a,{id:r,value:String(s),options:d,disabled:n,label:o(`accountPool.priorityAria`),describedBy:l,title:c,onChange:e=>i(Z(Number.parseInt(e,10)))}),(0,M.jsx)(`span`,{id:l,className:`sr-only`,children:c})]})}function Ve({value:e}){let n=t(),r=Z(e);return r===0?null:(0,M.jsx)(`span`,{className:`badge badge-muted`,children:pe(n,r)})}function He(e){let t=e?.trim().toLowerCase();return t===`go`||t===`free`}function Ue(e,t){if(!e)return null;let n=e.shortPercent===void 0&&e.shortResetAt===void 0?e:{...e,fiveHourPercent:e.fiveHourPercent??e.shortPercent,fiveHourResetAt:e.fiveHourResetAt??e.shortResetAt};return He(t)?{...n.monthlyPercent===void 0?{}:{monthlyPercent:n.monthlyPercent},...n.monthlyResetAt===void 0?{}:{monthlyResetAt:n.monthlyResetAt},...n.creditsUsd===void 0?{}:{creditsUsd:n.creditsUsd},...n.resetCredits===void 0?{}:{resetCredits:n.resetCredits},updatedAt:n.updatedAt}:n}function We(e){return e===`5h`?0:e===`First-party models`?2:e===`API usage`?3:e===`Total subscription credits`?4.5:5}function Ge(e,t){switch(e){case`First-party models`:return t(`quota.cursorFirstParty`);case`API usage`:return t(`quota.cursorApiUsage`);case`Total subscription credits`:return t(`quota.totalSubscriptionCredits`);default:return e}}function Ke(e,t,n){let r=Ue(e,t);if(!r)return[];let i=[],a=r.fiveHourPercent??r.shortPercent,o=r.fiveHourResetAt??r.shortResetAt;typeof a==`number`&&i.push({rank:0,row:{windowKey:`fiveHour`,label:n(`codexAuth.fiveHour`),limitLabel:n(`quota.fiveHourLimit`),percent:a,resetAt:o}}),typeof r.weeklyPercent==`number`&&i.push({rank:1,row:{windowKey:`weekly`,label:n(`codexAuth.weekly`),limitLabel:n(`quota.weeklyLimit`),percent:r.weeklyPercent,resetAt:r.weeklyResetAt}}),typeof r.monthlyPercent==`number`&&i.push({rank:4,row:{windowKey:`monthly`,label:n(`codexAuth.monthly`),limitLabel:n(`quota.monthlyLimit`),percent:r.monthlyPercent,resetAt:r.monthlyResetAt}});for(let e of r.customWindows??[]){let t=Ge(e.label,n);i.push({rank:We(e.label),row:{customLabel:e.label,label:t,limitLabel:t,percent:e.percent,resetAt:e.resetAt}})}if(r.creditsUsd&&typeof r.creditsUsd.percent==`number`&&!r.customWindows?.some(e=>/credits?/i.test(e.label))){let e=Ge(`Total subscription credits`,n);i.push({rank:We(`Total subscription credits`),row:{customLabel:`Total subscription credits`,label:e,limitLabel:e,percent:r.creditsUsd.percent,resetAt:r.creditsUsd.expiresAt}})}return i.sort((e,t)=>e.rank-t.rank).map(e=>e.row)}function qe(e){if(!e)return-1;let t=[e.fiveHourPercent??e.shortPercent,e.weeklyPercent,e.monthlyPercent].filter(e=>typeof e==`number`);for(let n of e.customWindows??[])typeof n.percent==`number`&&t.push(n.percent);return typeof e.creditsUsd?.percent==`number`&&t.push(e.creditsUsd.percent),t.length?Math.max(...t):-1}function Je(e){switch(e){case`en`:return`en-GB`;case`de`:return`de-DE`;case`fr`:return`fr-FR`;case`ko`:return`ko-KR`;case`zh`:return`zh-CN`;case`zh-TW`:return`zh-TW`;case`ru`:return`ru-RU`;case`ja`:return`ja-JP`;case`tr`:return`tr-TR`;default:return e}}function Ye(e){return e>=99.5}function Xe(e,t){return t>0&&e>=t}function Ze(e,t){return Xe(e,t)||Ye(e)?`bar-warn`:`bar-green`}function Qe(e){let t=Math.max(0,Math.min(100,e));return t<=0?0:Math.max(4,Math.round(t))}function $e(e){return{"--bar-scale":String(Qe(e)/100)}}function et({quota:e,plan:t,threshold:n,t:r,className:a,layout:o=`compact`,pending:s=!1,incompleteWindowKeys:c,incompleteCustomWindowLabels:l}){let{locale:u}=i(),d=Ke(e,t,r);return d.length===0?s?o===`stacked`?(0,M.jsxs)(`div`,{className:`quota-stacked quota-stacked--pending${a?` ${a}`:``}`,"aria-busy":`true`,role:`status`,children:[Array.from({length:2},(e,t)=>(0,M.jsxs)(`div`,{className:`quota-stacked-row quota-stacked-row--skeleton`,"aria-hidden":`true`,children:[(0,M.jsxs)(`div`,{className:`quota-stacked-head`,children:[(0,M.jsx)(`span`,{className:`quota-skel quota-skel--label`,style:{width:72}}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--time`,style:{width:64}})]}),(0,M.jsxs)(`div`,{className:`quota-stacked-bar-row`,children:[(0,M.jsx)(`span`,{className:`quota-skel quota-skel--bar`,style:{height:6,flex:1}}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--val`,style:{width:36}})]})]},t)),(0,M.jsx)(`span`,{className:`sr-only`,children:r(`common.loading`)})]}):(0,M.jsxs)(`div`,{className:`codex-account-quota-slot quota-compact quota-compact--pending${a?` ${a}`:``}`,"aria-busy":`true`,role:`status`,children:[(0,M.jsxs)(`div`,{className:`quota-row quota-row--skeleton`,"aria-hidden":`true`,children:[(0,M.jsx)(`span`,{className:`quota-skel quota-skel--label`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--reset`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--day`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--time`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--bar`}),(0,M.jsx)(`span`,{className:`quota-skel quota-skel--val`})]}),(0,M.jsx)(`span`,{className:`sr-only`,children:r(`common.loading`)})]}):null:o===`stacked`?(0,M.jsx)(`div`,{className:`quota-stacked${a?` ${a}`:``}`,children:d.map(e=>(0,M.jsx)(nt,{row:e,threshold:n,t:r,locale:u,incomplete:e.windowKey?c?.has(e.windowKey)===!0:e.customLabel!==void 0&&l?.has(e.customLabel)===!0},e.limitLabel))}):(0,M.jsx)(`div`,{className:`codex-account-quota-slot quota-compact${a?` ${a}`:``}`,children:d.map(e=>(0,M.jsx)(tt,{label:e.label,percent:e.percent,resetAt:e.resetAt,threshold:n,t:r,locale:u},e.label))})}function tt({label:e,percent:t,resetAt:n,threshold:r,t:i,locale:a}){let o=Ye(t),s=Xe(t,r),c=Ze(t,r),l=it(n,i,a),d=l.day||l.time?`${i(`codexAuth.resets`)} ${l.day} ${l.time}`.replace(/\s+/g,` `).trim():void 0,f=l.day!==``||l.time!==``;return(0,M.jsxs)(`div`,{className:`quota-row${s?` quota-row--warn`:``}${o?` quota-row--exhausted`:``}`,children:[(0,M.jsx)(`span`,{className:`quota-label`,title:d,children:e}),(0,M.jsx)(`span`,{className:`quota-reset-label`,children:f?i(`codexAuth.resets`):``}),(0,M.jsx)(`span`,{className:`quota-reset-day`,children:l.day}),(0,M.jsx)(`span`,{className:`quota-reset-time`,children:l.time}),(0,M.jsx)(`div`,{className:`bar`,title:d,children:(0,M.jsx)(`div`,{className:`bar-fill ${c}`,style:$e(t)})}),(0,M.jsxs)(`span`,{className:`quota-val${s?` quota-val--warn`:``}`,title:o?i(`quota.limitReached`):d,"aria-label":d,children:[s&&(0,M.jsx)(u,{width:12,height:12,"aria-hidden":`true`}),Math.round(t),`%`,o?` · ${i(`quota.limitReached`)}`:``]})]})}function nt({row:e,threshold:t,t:n,locale:r,incomplete:i}){let a=Ye(e.percent),o=Xe(e.percent,t),s=Ze(e.percent,t),c=at(e.resetAt,n,r);return(0,M.jsxs)(`div`,{className:`quota-stacked-row${o?` quota-stacked-row--warn`:``}${a?` quota-stacked-row--exhausted`:``}`,children:[(0,M.jsxs)(`div`,{className:`quota-stacked-head`,children:[(0,M.jsxs)(`span`,{className:`quota-stacked-limit-group`,children:[(0,M.jsx)(`span`,{className:`quota-stacked-limit`,children:e.limitLabel}),i&&(0,M.jsx)(`span`,{className:`quota-window-partial`,role:`note`,"aria-label":n(`pws.capacity.windowPartialA11y`,{window:e.limitLabel}),title:n(`pws.capacity.windowPartialA11y`,{window:e.limitLabel}),children:n(`pws.capacity.windowPartial`)})]}),(0,M.jsx)(`span`,{className:`quota-stacked-reset muted`,children:c})]}),(0,M.jsxs)(`div`,{className:`quota-stacked-bar-row`,children:[(0,M.jsx)(`div`,{className:`bar quota-stacked-bar`,children:(0,M.jsx)(`div`,{className:`bar-fill ${s}`,style:$e(e.percent)})}),(0,M.jsx)(`span`,{className:`quota-stacked-used${o?` quota-stacked-used--warn`:``}`,children:n(`quota.usedPercent`,{pct:Math.round(e.percent)})})]}),a&&(0,M.jsxs)(`div`,{className:`quota-stacked-limit-reached`,role:`status`,children:[(0,M.jsx)(u,{width:12,height:12,"aria-hidden":`true`}),n(`quota.limitReached`)]})]})}function rt(e){if(typeof e!=`number`||!Number.isFinite(e))return null;let t=e<1e10?e*1e3:e,n=new Date(t);return Number.isFinite(n.getTime())?{date:n,ms:t}:null}function it(e,t,n){let r=rt(e);if(!r)return{day:``,time:``};let{date:i}=r,a=new Date,o=Je(n),s=new Intl.DateTimeFormat(o,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(i);return i.getFullYear()===a.getFullYear()&&i.getMonth()===a.getMonth()&&i.getDate()===a.getDate()?{day:t(`codexAuth.today`),time:s}:{day:new Intl.DateTimeFormat(o,{day:`numeric`,month:`short`}).format(i),time:s}}function at(e,t,n=`en`,r=Date.now()){let i=rt(e);if(!i)return``;let{date:a,ms:o}=i,s=Je(n),c=new Intl.DateTimeFormat(s,{hour:`2-digit`,minute:`2-digit`,hour12:!1}).format(a),l=new Date(r),u=new Date(l.getFullYear(),l.getMonth(),l.getDate()).getTime(),d=new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime(),f=Math.round((d-u)/864e5);if(f===1)return t(`quota.resetsTomorrow`,{time:c});let p=a.getFullYear()!==l.getFullYear(),m=new Intl.DateTimeFormat(s,{day:`numeric`,month:`short`,...p?{year:`numeric`}:{}}).format(a);if(o<=r)return t(`quota.resetsAt`,{date:m,time:c,when:`${m}, ${c}`});let h=Math.round((o-r)/6e4);if(h<60)return t(`quota.resetsRelativeMinutes`,{n:Math.max(1,h)});let g=Math.round(h/60);return g<12&&f===0?t(`quota.resetsRelativeHours`,{n:Math.max(1,g)}):f===0?t(`quota.resetsToday`,{time:c}):t(`quota.resetsAt`,{date:m,time:c,when:`${m}, ${c}`})}function ot(e,t){return O(e,t)}function st(e,t){return D(e,t)}function ct(e){return Math.max(0,Math.ceil((new Date(e).getTime()-Date.now())/864e5))}function lt({index:e,grantedAt:t,expiresAt:n,isNext:r,locale:i,t:a}){let o=ct(n),s=o<=7;return(0,M.jsxs)(`div`,{className:`credit-item${r?` credit-next`:``}`,children:[(0,M.jsxs)(`div`,{className:`credit-item-head`,children:[(0,M.jsx)(m,{width:13}),(0,M.jsx)(`span`,{className:`credit-item-label`,children:r?a(`codexAuth.creditNext`):a(`codexAuth.creditLabel`,{n:String(e+1)})}),r&&(0,M.jsx)(`span`,{className:`badge badge-amber text-micro`,style:{padding:`1px 6px`},children:a(`codexAuth.creditNextBadge`)})]}),(0,M.jsxs)(`div`,{className:`credit-item-dates`,children:[(0,M.jsx)(`span`,{children:a(`codexAuth.creditGranted`,{date:ot(t,i)})}),(0,M.jsx)(`span`,{className:s?`credit-urgent`:``,children:a(`codexAuth.creditExpires`,{date:st(n,i),days:String(o)})})]})]})}function ut({account:e,onClick:t,t:n}){let r=e.quota?.resetCredits;return e.quota==null?(0,M.jsxs)(`span`,{className:`badge badge-muted codex-ticket-badge-slot`,"aria-hidden":`true`,children:[(0,M.jsx)(m,{width:12}),`0`]}):r===void 0?null:(0,M.jsxs)(`button`,{type:`button`,className:`badge ${typeof r==`number`&&r>0?`badge-amber`:`badge-muted`} badge-clickable`,onClick:e=>{e.stopPropagation(),t()},"aria-label":n(`codexAuth.resetCreditsAria`,{count:String(r)}),children:[(0,M.jsx)(m,{width:12}),r]})}function dt({t:e,paused:t,saving:n}){let r=e(`codexAuth.pause`),i=e(`codexAuth.resume`),a=e(`common.saving`),o=n?a:t?i:r,s=Math.max(r.length,i.length,a.length);return(0,M.jsx)(`span`,{className:`codex-auth-pause-label`,style:{minWidth:`${s}ch`},children:o})}function ft({pool:e,activeId:n,accountModeState:r,switchActionLabel:i,threshold:a,onOpenReset:o,onSwitch:s,onTogglePause:c,pauseUpdatingId:l,pauseBusy:u,onPriorityChange:d,priorityUpdatingId:f,switchingId:p,pinnedId:m=null,onReauth:g,onEditAlias:_,onRemove:v,onCopyDoctor:b,doctorCopyOutcomeFor:x}){let S=t(),C=e=>!e.paused&&n===e.id;return(0,M.jsx)(M.Fragment,{children:e.map(e=>{let t=e.health?.status,n=!!e.needsReauth||R(t),T=z(t),E=te(S,e.health),D=H(S,`codex`,e.id,e.health);return(0,M.jsxs)(`div`,{className:`card ${C(e)?`card-active`:``}`,style:{marginBottom:8},children:[(0,M.jsxs)(`div`,{className:`card-head`,children:[(0,M.jsx)(`span`,{className:`dot ${n?`dot-amber`:C(e)?`dot-blue`:`dot-muted`}`}),(0,M.jsx)(`strong`,{children:e.alias??e.email}),(0,M.jsxs)(`span`,{className:`card-badges`,children:[e.plan&&(0,M.jsx)(`span`,{className:`badge badge-green`,children:e.plan}),e.paused&&(0,M.jsx)(`span`,{className:`badge badge-muted`,title:S(`codexAuth.pausedHint`),children:S(`codexAuth.paused`)}),(0,M.jsx)(Ve,{value:e.priority}),e.id===m&&!e.paused&&(0,M.jsx)(`span`,{className:`badge badge-muted`,children:S(`codexAuth.pinned`)}),(0,M.jsx)(ut,{t:S,account:e,onClick:()=>o(e)}),E&&(0,M.jsx)(`span`,{className:L(t),children:E}),n&&!E&&(0,M.jsx)(`span`,{className:`badge badge-amber`,children:S(`codexAuth.needsReauth`)}),C(e)&&!n&&!T&&(0,M.jsx)(`span`,{className:`badge badge-primary`,children:S(r===`direct`?`codexAuth.poolPrepared`:`codexAuth.nextSession`)})]}),!e.paused&&(!C(e)||m!==e.id)&&!n&&!T&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-account-switch`,onClick:()=>s(e),children:i}),n&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>g(e.id),children:S(`codexAuth.reauthenticate`)}),b&&B(t)&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-auth-action-btn`,onClick:()=>b(e.id),children:(0,M.jsx)(`span`,{"aria-live":`polite`,children:G(S,x?.(e.id))})}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost codex-auth-action-btn`,onClick:()=>c(e),disabled:u,title:e.paused?S(`codexAuth.pausedHint`):void 0,"aria-label":e.paused?`${S(`codexAuth.resume`)}. ${S(`codexAuth.pausedHint`)}`:S(`codexAuth.pause`),children:[e.paused?(0,M.jsx)(h,{width:14}):(0,M.jsx)(y,{width:14}),(0,M.jsx)(dt,{t:S,paused:e.paused,saving:l===e.id})]}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void _(e),children:S(`prov.editAlias`)}),(0,M.jsx)(`button`,{type:`button`,className:`btn-icon btn-icon-danger card-right`,"aria-label":`${S(`common.remove`)} — ${e.email}`,title:`${S(`common.remove`)} — ${e.email}`,onClick:t=>{t.stopPropagation(),v(e.id)},children:(0,M.jsx)(w,{width:14})})]}),(0,M.jsxs)(`div`,{className:`codex-account-identity`,children:[(0,M.jsxs)(`div`,{className:`codex-account-identity-copy`,children:[e.email,e.plan?` · ${e.plan}`:``,` · `,S(`prov.accountId`),`: `,F(e.id)]}),(0,M.jsx)(Be,{value:e.priority,selectId:`codex-account-priority-${e.id}`,disabled:f!==null||p!==null,onChange:t=>d(e,t)})]}),D&&(0,M.jsx)(`div`,{className:`card-sub faint`,children:D}),T&&(0,M.jsx)(`div`,{className:`card-sub faint`,children:S(`pws.healthCooldownHint`)}),n?(0,M.jsx)(`div`,{className:`card-sub faint`,children:S(`codexAuth.tokenExpired`)}):!T&&(0,M.jsx)(et,{quota:e.quota,plan:e.plan,threshold:a,t:S,pending:e.quota==null})]},e.id)})})}function pt({onReauth:e}){let n=t();return(0,M.jsxs)(`div`,{className:`notice-warn`,style:{marginBottom:12,display:`flex`,alignItems:`center`,justifyContent:`space-between`,gap:12,flexWrap:`wrap`},children:[(0,M.jsxs)(`span`,{children:[(0,M.jsx)(u,{width:14}),` `,n(`codexAuth.tokenExpired`)]}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:e,children:n(`codexAuth.reauthenticate`)})]})}function mt({confirm:e,mainEmail:n,accountModeState:r,switchingId:i,orderBusy:a=!1,onCancel:o,onConfirm:s}){let c=t(),l=(0,k.useRef)(null);(0,k.useEffect)(()=>{let e=l.current;e&&!e.open&&e.showModal()},[]);let d=(0,k.useCallback)(e=>{e.preventDefault(),o()},[o]);return(0,M.jsxs)(`dialog`,{ref:l,className:`modal-overlay`,"aria-labelledby":`codex-switch-title`,onCancel:d,children:[(0,M.jsx)(`button`,{type:`button`,className:`modal-backdrop-dismiss`,"aria-label":c(`common.close`),tabIndex:-1,onClick:o}),(0,M.jsxs)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),role:`document`,children:[(0,M.jsx)(`h3`,{id:`codex-switch-title`,children:r===`direct`?c(`codexAuth.preparePoolTitle`):e.id===`__main__`?c(`codexAuth.switchBack`):c(`codexAuth.switchTitle`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:r===`direct`?c(`codexAuth.preparePoolDesc`):e.id===`__main__`?c(`codexAuth.switchBackDesc`):c(`codexAuth.switchDesc`)}),(0,M.jsxs)(`div`,{className:`card`,style:{margin:`12px 0`},children:[(0,M.jsx)(`strong`,{children:e.id===`__main__`?n||c(`codexAuth.codexApp`):e.email}),e.plan&&(0,M.jsx)(`span`,{className:`badge badge-green`,style:{marginLeft:8},children:e.plan})]}),e.id!==`__main__`&&(0,M.jsxs)(`div`,{className:`notice-warn`,children:[(0,M.jsx)(u,{width:14}),` `,c(`codexAuth.cacheWarning`)]}),(0,M.jsxs)(`div`,{className:`modal-actions`,children:[(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:o,children:c(`codexAuth.cancel`)}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:!!i||a,onClick:s,children:c(i?`pws.accountSwitching`:r===`direct`?`codexAuth.prepareForPool`:`codexAuth.setAsNext`)})]})]})]})}function ht({resetPopup:e,resetConfirm:t,creditDetails:n,creditDetailsLoading:r,redeeming:a,onClose:o,onShowConfirm:s,onCancelConfirm:c,onRedeem:l}){let{locale:d,t:f}=i(),p=(0,k.useRef)(null);(0,k.useEffect)(()=>{let e=p.current;e&&!e.open&&e.showModal()},[]);let h=(0,k.useCallback)(e=>{e.preventDefault(),o()},[o]);return(0,M.jsxs)(`dialog`,{ref:p,className:`modal-overlay`,"aria-labelledby":`codex-reset-title`,onCancel:h,children:[(0,M.jsx)(`button`,{type:`button`,className:`modal-backdrop-dismiss`,"aria-label":f(`common.close`),tabIndex:-1,onClick:o}),(0,M.jsx)(`div`,{className:`modal-card`,onClick:e=>e.stopPropagation(),role:`document`,children:t?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{style:{textAlign:`center`,padding:`12px 0`},children:[(0,M.jsx)(`div`,{className:`confirm-icon`,children:(0,M.jsx)(u,{width:22})}),(0,M.jsx)(`h3`,{id:`codex-reset-title`,children:f(`codexAuth.confirmResetTitle`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:f(`codexAuth.confirmResetDesc`,{count:String(e.quota?.resetCredits??0)})}),n&&n[0]&&(0,M.jsx)(`p`,{className:`faint text-label`,children:f(`codexAuth.confirmWhichCredit`,{date:ot(n[0].granted_at,d)})}),(0,M.jsx)(`p`,{className:`faint text-label`,children:f(`codexAuth.irreversible`)})]}),(0,M.jsxs)(`div`,{className:`modal-actions`,children:[(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:c,children:f(`codexAuth.cancel`)}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:l,disabled:a,children:f(a?`codexAuth.redeeming`:`codexAuth.useCredit`)})]})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`h3`,{id:`codex-reset-title`,children:[(0,M.jsx)(m,{width:16}),` `,f(`codexAuth.resetCreditsTitle`)]}),(0,M.jsxs)(`div`,{className:`card-sub`,children:[e.email,e.plan?` · ${e.plan}`:``]}),(0,M.jsx)(`div`,{style:{margin:`16px 0`},children:(e.quota?.resetCredits??0)>0?(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`p`,{style:{marginBottom:12},children:f(`codexAuth.resetCreditsAvailable`,{count:String(e.quota?.resetCredits??0)})}),r&&(0,M.jsx)(`p`,{className:`faint text-label`,children:f(`common.loading`)}),n&&n.length>0&&(0,M.jsx)(`div`,{className:`credit-list`,children:n.map((e,t)=>(0,M.jsx)(lt,{index:t,grantedAt:e.granted_at,expiresAt:e.expires_at,isNext:t===0,locale:d,t:f},`${e.granted_at}:${e.expires_at}`))}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-primary`,style:{marginTop:12,width:`100%`},onClick:s,disabled:a,children:f(`codexAuth.useOneCredit`)}),(0,M.jsx)(`p`,{className:`card-sub text-caption`,style:{marginTop:8,textAlign:`center`},children:f(`codexAuth.fifoNote`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`p`,{className:`faint`,children:f(`codexAuth.noResetCredits`)}),(0,M.jsx)(`p`,{className:`modal-desc`,children:f(`codexAuth.earnCreditsHint`)})]})})]})})]})}function gt({t:e,main:t,isMainActive:n,accountModeState:r,threshold:i,switchActionLabel:a,onSwitch:o,onTogglePause:s,pauseUpdatingId:c,pauseBusy:l,onPriorityChange:u,priorityUpdatingId:d,switchingId:f,pinnedId:p=null,onOpenReset:m,onCopyDoctor:g,doctorCopyOutcomeFor:v}){let b=e(`codexAuth.codexApp`),x=t?.id??`__main__`,S={id:`__main__`,email:t?.email||b,plan:t?.plan,isMain:!0,paused:t?.paused??!1,priority:t?.priority??0,hasCredential:!0,quota:t?.quota??null},C=!!t?.needsReauth||R(t?.health?.status),w=z(t?.health?.status),T=te(e,t?.health),E=t?H(e,`codex`,x,t.health):null;return(0,M.jsxs)(`div`,{className:`card ${n?`card-active`:``}`,style:{marginBottom:12},children:[(0,M.jsxs)(`div`,{className:`card-head`,children:[(0,M.jsx)(`span`,{className:`dot ${C?`dot-amber`:`dot-green`}`}),(0,M.jsx)(`strong`,{children:e(`codexAuth.mainAccount`)}),(0,M.jsxs)(`span`,{className:`card-badges`,children:[t&&(0,M.jsx)(ut,{t:e,account:{...t,id:`__main__`},onClick:()=>m({...t,id:`__main__`})}),t?.paused&&(0,M.jsx)(`span`,{className:`badge badge-muted`,title:e(`codexAuth.pausedHint`),children:e(`codexAuth.paused`)}),(0,M.jsx)(Ve,{value:S.priority}),p===`__main__`&&!t?.paused&&(0,M.jsx)(`span`,{className:`badge badge-muted`,children:e(`codexAuth.pinned`)}),T&&(0,M.jsx)(`span`,{className:L(t?.health?.status),children:T}),C&&!T&&(0,M.jsx)(`span`,{className:`badge badge-amber`,children:e(`codexAuth.needsReauth`)}),!t?.paused&&(0,M.jsx)(`span`,{className:`badge ${n?`badge-primary`:`badge-muted`}`,children:e(n?r===`direct`?`codexAuth.poolPrepared`:`codexAuth.nextSession`:`codexAuth.current`)})]}),!t?.paused&&(!n||p!==`__main__`)&&!C&&!w&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-account-switch`,onClick:()=>o(S),children:a}),g&&B(t?.health?.status)&&(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm codex-auth-action-btn`,onClick:()=>g(x),children:(0,M.jsx)(`span`,{"aria-live":`polite`,children:G(e,v?.(x))})}),t&&(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost codex-auth-action-btn`,onClick:()=>s(S),disabled:l,title:t.paused?e(`codexAuth.pausedHint`):void 0,"aria-label":t.paused?`${e(`codexAuth.resume`)}. ${e(`codexAuth.pausedHint`)}`:e(`codexAuth.pause`),children:[t.paused?(0,M.jsx)(h,{width:14}):(0,M.jsx)(y,{width:14}),(0,M.jsx)(dt,{t:e,paused:!!t.paused,saving:c===`__main__`})]}),(0,M.jsxs)(`span`,{className:`card-right`,children:[(0,M.jsx)(_,{width:14}),` `,e(`codexAuth.appLogin`)]})]}),(0,M.jsxs)(`div`,{className:`codex-account-identity`,children:[(0,M.jsxs)(`div`,{className:`codex-account-identity-copy`,children:[t?.email||e(`codexAuth.appLogin`),t?.plan?` · ${t.plan}`:``]}),t&&(0,M.jsx)(Be,{value:S.priority,selectId:`codex-account-priority-${S.id}`,disabled:d!==null||f!==null,onChange:e=>u(S,e)})]}),E&&(0,M.jsx)(`div`,{className:`card-sub faint`,children:E}),w&&(0,M.jsx)(`div`,{className:`card-sub faint`,children:e(`pws.healthCooldownHint`)}),C?(0,M.jsx)(`div`,{className:`card-sub faint`,children:e(`codexAuth.mainTokenExpired`)}):!w&&(0,M.jsx)(et,{quota:t?.quota??null,plan:t?.plan,threshold:i,t:e,pending:t!=null&&t.quota==null})]})}function _t({t:e,embedded:t,refreshingQuota:n,pausingExhausted:r,pauseBusy:i,actionFeedback:a,actionFeedbackTone:o,onRefresh:s,onPauseExhausted:c,sparkVisible:l,sparkBusy:u,onToggleSpark:d}){return(0,M.jsxs)(`div`,{className:t?`row`:`page-head codex-auth-page-head`,style:t?{justifyContent:`flex-end`,marginBottom:8}:void 0,children:[!t&&(0,M.jsx)(`h2`,{className:`page-title`,children:e(`nav.codexAuth`)}),(0,M.jsxs)(`div`,{className:t?`row`:`codex-auth-page-head__actions`,children:[(0,M.jsx)(`span`,{className:`codex-auth-page-head__feedback${o===`ok`?` is-ok`:``}${o===`warn`?` is-warn`:``}${o===`err`?` is-err`:``}`,role:`status`,"aria-live":`polite`,children:a??``}),l!==void 0&&d&&(0,M.jsxs)(`span`,{className:`codex-auth-spark-toggle`,children:[(0,M.jsx)(`span`,{className:`codex-auth-spark-toggle__label`,children:e(`codexAuth.sparkQuota`)}),(0,M.jsx)(`button`,{type:`button`,className:`toggle ${l?`on`:``}`,onClick:d,disabled:!!u,"aria-pressed":l,"aria-label":e(`codexAuth.sparkQuota`),title:e(`codexAuth.sparkQuotaHint`),children:(0,M.jsx)(`span`,{className:`toggle-knob`})})]}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost codex-auth-action-btn`,onClick:c,disabled:n||r||!!i,children:[(0,M.jsx)(y,{width:14}),` `,e(r?`codexAuth.pausingExhausted`:`codexAuth.pauseExhausted`)]}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost codex-auth-action-btn`,onClick:s,disabled:n||r||!!i,children:[(0,M.jsx)(g,{width:14}),` `,e(n?`codexAuth.refreshingQuota`:`codexAuth.refreshQuota`)]})]})]})}function vt({t:e,loadState:t,accountsCount:n,onRetry:r}){return t===`loading`&&n===0?(0,M.jsxs)(`div`,{className:`codex-auth-load-skeleton`,role:`status`,"aria-live":`polite`,"aria-busy":`true`,children:[(0,M.jsxs)(`div`,{className:`card codex-auth-load-skeleton__main`,style:{marginBottom:12},"aria-hidden":`true`,children:[(0,M.jsxs)(`div`,{className:`card-head`,children:[(0,M.jsx)(`span`,{className:`dot dot-muted`}),(0,M.jsx)(`strong`,{children:e(`codexAuth.mainAccount`)}),(0,M.jsxs)(`span`,{className:`card-badges`,children:[(0,M.jsxs)(`span`,{className:`badge badge-muted codex-ticket-badge-slot`,"aria-hidden":`true`,children:[(0,M.jsx)(m,{width:12}),`0`]}),(0,M.jsx)(`span`,{className:`badge badge-primary`,children:e(`codexAuth.nextSession`)})]}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,tabIndex:-1,disabled:!0,children:[(0,M.jsx)(y,{width:14}),` `,e(`codexAuth.pause`)]}),(0,M.jsxs)(`span`,{className:`card-right`,children:[(0,M.jsx)(_,{width:14}),` `,e(`codexAuth.appLogin`)]})]}),(0,M.jsxs)(`div`,{className:`card-sub`,children:[(0,M.jsx)(`span`,{className:`codex-auth-load-skeleton__strut`,children:e(`codexAuth.appLogin`)}),(0,M.jsx)(`span`,{className:`codex-auth-load-skeleton__line codex-auth-load-skeleton__line--sub`})]}),(0,M.jsx)(et,{quota:null,threshold:0,t:e,pending:!0})]}),(0,M.jsxs)(`div`,{className:`section-sep`,"aria-hidden":`true`,children:[(0,M.jsx)(`span`,{className:`section-label`,children:e(`codexAuth.accountPool`)}),(0,M.jsx)(`div`,{className:`sep-line`}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,tabIndex:-1,disabled:!0,children:[(0,M.jsx)(v,{width:14}),` `,e(`codexAuth.add`)]})]}),(0,M.jsx)(`div`,{className:`empty codex-auth-pool-empty codex-auth-load-skeleton__empty`,"aria-hidden":`true`,children:(0,M.jsx)(`div`,{className:`title`,children:e(`codexAuth.noPool`)})}),(0,M.jsx)(`span`,{className:`sr-only`,children:e(`pws.accountsLoading`)})]}):t===`error`?(0,M.jsxs)(`div`,{className:`pwi-auth-state pwi-auth-state--error`,role:`alert`,children:[(0,M.jsx)(`span`,{children:e(`codexAuth.loadFailed`)}),(0,M.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:r,children:e(`pws.retryAccounts`)})]}):null}function yt(e,t){return t===void 0?e(`codexAuth.resetSuccessGeneric`):e(`codexAuth.resetSuccess`,{remaining:String(t)})}async function bt(e,t,n,r){try{let i=await fetch(`${e}/api/codex-auth/reset-credits/consume`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({accountId:t})}),a=await o(i);return a?a.code===`reset`||a.code===`already_redeemed`?(await r(!0),{ok:!0,close:!0,toast:yt(n,typeof a.remaining==`number`&&Number.isFinite(a.remaining)?Math.max(0,a.remaining):void 0)}):{ok:!1,close:!0,toast:n(a.code===`nothing_to_reset`?`codexAuth.resetNothingToReset`:a.code===`no_credit`?`codexAuth.resetNoCredit`:`codexAuth.resetError`)}:{ok:!1,toast:n(`codexAuth.resetError`)}}catch{return{ok:!1,toast:n(`codexAuth.resetError`)}}}var xt=`ocx doctor`;function St({apiBase:e,accountModeState:n=null,banner:r=null,embedded:i=!1,onActiveNeedsReauthChange:a,controller:s,advancedExtras:l=null}){let u=t(),d=ze(e,{updated:u(`codexAuth.autoSwitchUpdated`),updateFailed:u(`codexAuth.autoSwitchUpdateFailed`),invalid:u(`codexAuth.autoSwitchThresholdInvalid`)}),[f,p]=(0,k.useState)(null),{beginServerRead:m,acceptServerRead:h,rejectServerRead:g,hydrateServerValue:_}=d,y=Ce(e,!s),b=s??y,{accounts:x,activeId:S,loadState:C,switchingId:w,pauseUpdatingId:T,priorityUpdatingId:E,pausingExhausted:D,activePinnedId:O,load:A}=b,[j,N]=(0,k.useState)(null),[P,F]=(0,k.useState)(!1),[I,L]=(0,k.useState)(!1),[R,z]=(0,k.useState)(null),[B,V]=(0,k.useState)(null),[te,H]=(0,k.useState)(null),U=(0,k.useRef)(null),[W,G]=(0,k.useState)(!1),[ne,K]=(0,k.useState)(void 0),[ie,ae]=(0,k.useState)(!1),[q,J]=(0,k.useState)(null),[oe,Y]=(0,k.useState)(!1),[se,ce]=(0,k.useState)(!1),[ue,X]=(0,k.useState)(null),[Z,de]=(0,k.useState)(!1),fe=re(),Q=(0,k.useCallback)((e,t=`ok`)=>{U.current&&clearTimeout(U.current),V(e),H(t),U.current=setTimeout(()=>{V(null),H(null),U.current=null},5e3)},[]);(0,k.useEffect)(()=>()=>{U.current&&clearTimeout(U.current)},[]);let pe=(0,k.useCallback)(e=>{fe.copy(xt,e)},[fe]),{subscribeLoadObserver:me,readLastThreshold:he}=b;(0,k.useEffect)(()=>me({beginActiveRead:m,acceptActiveRead:h,rejectActiveRead:g}),[me,m,h,g]),(0,k.useEffect)(()=>{let e=he();e!==void 0&&_(e)},[he,_]),(0,k.useEffect)(()=>{if(!P)return;let e=b.pauseRefresh();return()=>b.resumeRefresh(e)},[b,P]);let $=S&&S!==`__main__`?x.find(e=>e.id===S):null,ge=!$?.paused&&ee($);(0,k.useEffect)(()=>{a?.(ge)},[ge,a]);let _e=(0,k.useCallback)(e=>{z(e),F(!0)},[]),ve=(0,k.useCallback)(()=>{F(!1),z(null)},[]),ye=(0,k.useCallback)(e=>{b.syncAfterAccountAdded(),Q(u(e.catalogRefreshPending?`codexAuth.catalogRefreshPending`:`codexAuth.accountAdded`),e.catalogRefreshPending?`warn`:`ok`),ve()},[ve,b,Q,u]),be=async e=>{let t=await b.switchAccount(e);if(!t.ok){if(t.reason===`busy`)return;Q(u(`codexAuth.switchFailed`),`err`);return}N(null);let r=t.activeId,i=r&&r!==`__main__`?x.find(e=>e.id===r)?.email??u(`pws.accountOrdinal`,{count:`1`}):u(`codexAuth.mainAccount`);Q(u(n===`direct`?`codexAuth.poolPreparedToast`:`codexAuth.switched`,{email:i}))},xe=async e=>{let t=window.prompt(u(`prov.aliasPrompt`),e.alias??``);if(t===null)return;let n=await b.saveAlias(e.id,t);Q(u(n.ok?`prov.aliasSaved`:`prov.aliasSaveFailed`),n.ok?`ok`:`err`)},Se=async e=>{let t=!e.paused,n=await b.setAccountPaused(e.id,t);!n.ok&&n.reason===`busy`||(N(t=>t?.id===e.id?null:t),Q(u(n.ok?t?`codexAuth.pauseSucceeded`:`codexAuth.resumeSucceeded`:t?`codexAuth.pauseFailed`:`codexAuth.resumeFailed`,{email:e.alias??e.email}),n.ok?`ok`:`err`))},we=async(e,t)=>{if(t===e.priority)return;let n=await b.setAccountPriority(e.id,t);!n.ok&&n.reason===`busy`||Q(u(n.ok?`accountPool.priorityUpdated`:`accountPool.priorityUpdateFailed`,{email:e.alias??e.email}),n.ok?`ok`:`err`)},Ee=async e=>{let t=x.find(t=>t.id===e)?.email??u(`pws.accountOrdinal`,{count:`1`});if(!window.confirm(u(`codexAuth.removeConfirm`,{id:t})))return;let n=await b.removeAccount(e);n.ok?n.catalogRefreshPending&&Q(u(`codexAuth.catalogRefreshPending`),`warn`):Q(u(`codexAuth.removeFailed`),`err`)},De=async()=>{G(!0);try{let e=await A(!0);Q(u(e?`codexAuth.quotaRefreshed`:`codexAuth.quotaRefreshFailed`),e?`ok`:`err`)}finally{G(!1)}};(0,k.useEffect)(()=>{let t=new AbortController;return fetch(`${e}/api/settings`,{signal:t.signal}).then(e=>e.ok?e.json():null).then(e=>{t.signal.aborted||typeof e?.showCodexSparkQuota!=`boolean`||K(e.showCodexSparkQuota)}).catch(()=>{}),()=>{t.abort()}},[e]);let Oe=async()=>{if(ie||ne===void 0)return;let t=!ne;ae(!0),K(t);try{let n=await fetch(`${e}/api/settings`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({showCodexSparkQuota:t})});if(!n.ok)throw Error(`save`);let r=await n.json(),i=typeof r.showCodexSparkQuota==`boolean`?r.showCodexSparkQuota:t;K(i),Q(u(i?`codexAuth.sparkQuotaShown`:`codexAuth.sparkQuotaHidden`),`ok`),await A(!0)}catch{K(!t),Q(u(`codexAuth.sparkQuotaFailed`),`err`)}finally{ae(!1)}},ke=async()=>{let e=await b.pauseExhaustedAccounts();!e.ok&&e.reason===`busy`||Q(e.ok?e.pausedCount>0?u(`codexAuth.pauseExhaustedSucceeded`,{count:String(e.pausedCount)}):u(`codexAuth.pauseExhaustedNone`):u(`codexAuth.pauseExhaustedFailed`),e.ok?`ok`:`err`)},Ae=async t=>{J(t),Y(!1),X(null),de(!0);try{let n=await fetch(`${e}/api/codex-auth/reset-credits?accountId=${encodeURIComponent(t.id)}`),r=await o(n);if(r){let e=(r.credits??[]).sort((e,t)=>new Date(e.granted_at).getTime()-new Date(t.granted_at).getTime());X(e)}}catch{}finally{de(!1)}},je=async t=>{ce(!0);try{let n=await bt(e,t,u,A);n.close&&(J(null),Y(!1)),n.toast&&Q(n.toast,n.ok?`ok`:`err`)}finally{ce(!1)}},Me=x.find(e=>e.isMain),Ne=x.filter(e=>!e.isMain),Pe=!Me?.paused&&(!S||S===`__main__`),Fe=u(n===`direct`?`codexAuth.prepareForPool`:`codexAuth.setAsNext`),Ie=T!==null||D,Be=d.threshold??0,Ve=!i;return(0,M.jsxs)(`div`,{children:[(0,M.jsx)(_t,{t:u,embedded:i,refreshingQuota:W,actionFeedback:B,actionFeedbackTone:te,pausingExhausted:D,pauseBusy:Ie,onRefresh:()=>{De()},onPauseExhausted:()=>{ke()},sparkVisible:ne,sparkBusy:ie,onToggleSpark:()=>{Oe()}}),r,(0,M.jsx)(vt,{t:u,loadState:C,accountsCount:x.length,onRetry:()=>{A()}}),(C!==`loading`||x.length!==0)&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(gt,{t:u,main:Me,isMainActive:Pe,accountModeState:n,threshold:Be,switchActionLabel:Fe,onSwitch:N,onTogglePause:Se,pauseUpdatingId:T,pauseBusy:Ie,onPriorityChange:(e,t)=>{we(e,t)},priorityUpdatingId:E,switchingId:w,pinnedId:O,onOpenReset:Ae,onCopyDoctor:Ve?pe:void 0,doctorCopyOutcomeFor:Ve?fe.outcomeFor:void 0}),(0,M.jsxs)(`div`,{className:`section-sep`,children:[(0,M.jsx)(`span`,{className:`section-label`,children:u(`codexAuth.accountPool`)}),(0,M.jsx)(`div`,{className:`sep-line`}),(0,M.jsxs)(`button`,{type:`button`,className:`btn btn-sm btn-ghost`,onClick:()=>F(!0),children:[(0,M.jsx)(v,{width:14}),` `,u(`codexAuth.add`)]})]}),ge&&$&&(0,M.jsx)(pt,{onReauth:()=>_e($.id)}),Ne.length===0&&(0,M.jsx)(c,{title:u(`codexAuth.noPool`)}),(0,M.jsx)(ft,{pool:Ne,activeId:S,accountModeState:n,switchActionLabel:Fe,threshold:Be,onOpenReset:Ae,onSwitch:N,onTogglePause:Se,pauseUpdatingId:T,pauseBusy:Ie,onPriorityChange:(e,t)=>{we(e,t)},priorityUpdatingId:E,switchingId:w,pinnedId:O,onReauth:_e,onEditAlias:xe,onRemove:Ee,onCopyDoctor:Ve?pe:void 0,doctorCopyOutcomeFor:Ve?fe.outcomeFor:void 0})]}),(0,M.jsx)(Le,{apiBase:e,subscribeLoadObserver:b.subscribeLoadObserver,readLastActive:b.readLastActive,onStrategyResolved:p}),(0,M.jsxs)(Re,{t:u,open:I,onToggle:()=>L(e=>!e),children:[f!==null&&(0,M.jsx)(Te,{threshold:d.threshold,draft:d.draft,strategy:f,hydrated:d.hydrated,saving:d.saving,loadError:d.loadError,feedback:d.feedback,onDraftChange:d.setDraft,onEditingChange:d.setEditing,onCommit:d.commit,onCancel:d.cancel,onToggle:d.toggle,onRetry:()=>{d.retry(),A()}}),l]}),j&&(0,M.jsx)(mt,{confirm:j,mainEmail:Me?.email,accountModeState:n,switchingId:w,orderBusy:E!==null,onCancel:()=>N(null),onConfirm:()=>{be(j.id===`__main__`?`__main__`:j.id)}}),q&&(0,M.jsx)(ht,{resetPopup:q,resetConfirm:oe,creditDetails:ue,creditDetailsLoading:Z,redeeming:se,onClose:()=>{J(null),Y(!1),X(null)},onShowConfirm:()=>Y(!0),onCancelConfirm:()=>Y(!1),onRedeem:()=>{je(q.id)}}),P&&(0,M.jsx)(le,{apiBase:e,reauthAccountId:R??void 0,onClose:ve,onAdded:ye})]})}var Ct=`https://chatgpt.com/backend-api/codex`;function wt(e){try{let t=new URL(e.trim());if(t.username||t.password||t.search||t.hash)return;let n=t.pathname.replace(/\/+$/,``);return`${t.origin}${n}`}catch{return}}function Tt(e){return[`openai`,...Object.entries(e).filter(([,e])=>e.authMode===`forward`).map(([e])=>e).filter(e=>e!==`openai`).sort((e,t)=>e.localeCompare(t))]}function Et(e){return e?e.adapter!==`openai-responses`||e.authMode!==`forward`||typeof e.baseUrl!=`string`||wt(e.baseUrl)!==Ct?`invalid`:e.disabled===!0?`disabled`:`ready`:`absent`}function Dt(e){return e.id===`openai`}function Ot(e){return e.id===`openai`?e.codexAccountMode===`direct`?`prov.openaiDirectDesc`:`prov.openaiPoolDesc`:null}function kt(e){let t={adapter:e.adapter.trim(),baseUrl:e.baseUrl.trim()};return e.responsesPath?.trim()&&(t.responsesPath=e.responsesPath.trim()),(e.authMode===`key`||e.authMode===`forward`)&&(t.authMode=e.authMode),e.authMode===`key`&&e.apiKey.trim()&&(t.apiKey=e.apiKey.trim()),e.adapter.trim()===`anthropic`&&e.authMode===`key`&&e.apiKeyTransport===`bearer`&&(t.apiKeyTransport=`bearer`),e.defaultModel.trim()&&(t.defaultModel=e.defaultModel.trim()),e.allowPrivateNetwork&&(t.allowPrivateNetwork=!0),t}function At(e,t){return Dt(e)?jt(e):{name:t.name.trim(),provider:kt(t)}}function jt(e){if(!e.provider)throw Error(`Missing canonical provider seed for ${e.id}`);return{name:e.id,provider:structuredClone(e.provider)}}var Mt=class extends Error{i18nKey;constructor(e){super(e),this.name=`OpenAiEnableError`,this.i18nKey=e}};async function Nt(e,t,n=fetch){if(t===`disabled`){if((await n(`${e}/api/providers?name=openai`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({disabled:!1})})).ok)return;throw new Mt(`codexAuth.enableOpenaiFailed`)}let r=await n(`${e}/api/provider-presets`);if(!r.ok)throw new Mt(`codexAuth.openaiPresetLoadFailed`);let i=(await r.json()).providers?.find(e=>e.id===`openai`);if(!i?.provider)throw new Mt(`codexAuth.openaiPresetUnavailable`);if(!(await n(`${e}/api/providers`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(jt(i))})).ok)throw new Mt(`codexAuth.enableOpenaiFailed`)}export{te as C,R as D,z as E,F as O,ee as S,L as T,le as _,Nt as a,Y as b,St as c,Fe as d,De as f,Ce as g,je as h,Ot as i,et as l,ke as m,At as n,Dt as o,Ae as p,Tt as r,Et as s,Mt as t,qe as u,oe as v,H as w,ie as x,J as y};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,h as t,m as n}from"./shared-
|
|
1
|
+
import{_ as e,h as t,m as n}from"./shared-DI18-uF7.js";var r=e(t(),1),i=`section`;function a(e,t){return[e,i,t].join(`-`)}function o(e){return[e,i,``].join(`-`)}var s=1200,c=n();function l({scope:e,items:t,ariaLabel:n}){let[i,l]=(0,r.useState)(t[0]?.id??``),u=(0,r.useRef)(null),d=(0,r.useRef)(null),f=(0,r.useCallback)(()=>{u.current=null,d.current!==null&&(clearTimeout(d.current),d.current=null)},[]),p=(0,r.useCallback)(()=>{f();let n=null,r=1/0;for(let i of t){let t=document.getElementById(a(e,i.id));if(!t)continue;let o=Math.abs(t.getBoundingClientRect().top-72);o<r&&(r=o,n=i.id)}n&&l(n)},[f,t,e]);(0,r.useEffect)(()=>()=>f(),[f]),(0,r.useEffect)(()=>{if(typeof IntersectionObserver>`u`)return;let n=t.map(t=>document.getElementById(a(e,t.id))).filter(e=>e!==null);if(n.length===0)return;let r=new IntersectionObserver(t=>{let n=u.current;if(n){let r=document.getElementById(a(e,n));t.some(e=>e.isIntersecting&&e.target===r)&&(f(),l(n));return}let r=t.filter(e=>e.isIntersecting).sort((e,t)=>e.boundingClientRect.top-t.boundingClientRect.top)[0];if(!r)return;let i=r.target.id.slice(o(e).length);l(e=>e===i?e:i)},{rootMargin:`-72px 0px -60% 0px`,threshold:0});for(let e of n)r.observe(e);return()=>r.disconnect()},[f,t,e]);let m=t=>{let n=document.getElementById(a(e,t));n&&(u.current=t,d.current!==null&&clearTimeout(d.current),d.current=setTimeout(p,s),l(t),n.scrollIntoView({behavior:`smooth`,block:`start`}))};return(0,c.jsx)(`nav`,{className:`page-tabs section-tabs`,"aria-label":n,children:t.map(e=>(0,c.jsxs)(`button`,{type:`button`,"aria-current":i===e.id?`location`:void 0,className:`page-tab${i===e.id?` page-tab--active`:``}`,onClick:()=>m(e.id),children:[e.label,e.meta?(0,c.jsx)(`span`,{className:`section-tab-meta`,children:e.meta}):null]},e.id))})}export{a as n,l as t};
|