@bitkyc08/opencodex 2.9.0 → 2.9.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.
|
@@ -64,4 +64,4 @@ v2: spawn_agent を備えたマルチスレッドエージェント。すべて
|
|
|
64
64
|
"max_tokens": 64,
|
|
65
65
|
"messages": [{"role": "user", "content": ${r}}]
|
|
66
66
|
}'`;return(0,z.jsxs)(`section`,{className:`panel api-panel awi-usage-panel`,children:[(0,z.jsx)(`h3`,{className:`panel-title`,children:n(`api.workspace.usageExamples`)}),(0,z.jsxs)(`div`,{className:`awi-usage-panel-body`,children:[(0,z.jsxs)(`div`,{className:`awi-usage-example`,children:[(0,z.jsx)(`h4`,{className:`awi-usage-example-title`,children:n(`api.usageChatTitle`)}),(0,z.jsx)(ju,{text:i})]}),(0,z.jsxs)(`div`,{className:`awi-usage-example`,children:[(0,z.jsx)(`h4`,{className:`awi-usage-example-title`,children:n(`api.usageResponsesTitle`)}),(0,z.jsx)(ju,{text:a})]}),t&&(0,z.jsxs)(`div`,{className:`awi-usage-example`,children:[(0,z.jsx)(`h4`,{className:`awi-usage-example-title`,children:n(`api.usageMessagesTitle`)}),(0,z.jsx)(ju,{text:o})]})]})]})}var Lu=[`opencode`,`pi`],Ru={opencode:`api.clientConfig.clientOpencode`,pi:`api.clientConfig.clientPi`};function zu({apiBase:e,baseUrl:t,hasKeys:n}){let r=q(),[i,a]=(0,_.useState)(`opencode`),[o,s]=(0,_.useState)(0),c=`${i}:${o}`,[l,u]=(0,_.useState)(null),[d,f]=(0,_.useState)(null);(0,_.useEffect)(()=>{let t=new AbortController,n=!1;return(async()=>{try{let a=await fetch(`${e}/api/client-config?client=${encodeURIComponent(i)}`,{signal:t.signal});if(!a.ok)throw Error(await oo(a,r(`api.clientConfig.loadFailed`)));let o=await a.json();if(n)return;u({key:c,data:o,error:null})}catch(e){if(n)return;u({key:c,data:null,error:e instanceof Error&&e.message?e.message:r(`api.clientConfig.loadFailed`)})}})(),()=>{n=!0,t.abort()}},[e,i,c,r]);let p=l!==null&&l.key===c?l:null,m=p===null,h=p?.data??null,g=p?.error??null,v=d!==null&&d.key===c?d.text:``,y=h?`${JSON.stringify(h.config,null,2)}\n`:``,b=(0,_.useCallback)(async()=>{if(h)try{await navigator.clipboard.writeText(y),f({key:c,text:r(`api.clientConfig.copiedAnnounce`)})}catch{f({key:c,text:r(`api.clientConfig.copyFailed`)})}},[h,y,c,r]),x=(0,_.useCallback)(()=>{if(!h)return;let e=URL.createObjectURL(new Blob([y],{type:`application/json`})),t=document.createElement(`a`);t.href=e,t.download=h.filename,t.click(),URL.revokeObjectURL(e),f({key:c,text:r(`api.clientConfig.downloadedAnnounce`,{filename:h.filename,destination:h.destination})})},[h,y,c,r]);return(0,z.jsxs)(`section`,{className:`panel api-panel awi-clientconfig-panel`,children:[(0,z.jsxs)(`div`,{className:`api-panel-head awi-clientconfig-head`,children:[(0,z.jsx)(`h3`,{className:`panel-title`,children:r(`api.clientConfig.title`)}),(0,z.jsxs)(`span`,{className:`awi-clientconfig-actions`,children:[(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,onClick:()=>{b()},disabled:!h,children:r(`api.clientConfig.copy`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-sm`,onClick:x,disabled:!h,children:r(`api.clientConfig.download`)})]})]}),(0,z.jsx)(`div`,{className:`segmented awi-clientconfig-segmented`,role:`radiogroup`,"aria-label":r(`api.clientConfig.clientLabel`),children:Lu.map(e=>(0,z.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":i===e,className:`btn btn-sm${i===e?` btn-primary`:` btn-ghost`}`,onClick:()=>a(e),children:r(Ru[e])},e))}),m?(0,z.jsx)(ls,{label:r(`api.clientConfig.loading`),rows:4,className:`awi-clientconfig-skeleton`}):g!==null||!h?(0,z.jsxs)(`div`,{className:`awi-clientconfig-error`,children:[(0,z.jsx)(`p`,{className:`muted small`,role:`alert`,children:g??r(`api.clientConfig.loadFailed`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>s(e=>e+1),children:r(`common.retry`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`pre`,{className:`api-code api-example-pre awi-clientconfig-json`,tabIndex:0,role:`group`,"aria-label":r(`api.clientConfig.jsonLabel`,{client:r(Ru[i])}),children:y}),(0,z.jsx)(`p`,{className:`muted small awi-clientconfig-count`,children:r(`api.clientConfig.modelCount`,{count:h.modelCount})}),h.modelsWithoutLimits>0&&(0,z.jsx)(`p`,{className:`muted small awi-clientconfig-degraded`,children:r(`api.clientConfig.missingLimits`,{count:h.modelsWithoutLimits,total:h.modelCount})}),!n&&(0,z.jsx)(`p`,{className:`muted small awi-clientconfig-nokey`,children:r(`api.clientConfig.noKeyYet`,{env:h.apiKeyEnv})}),(0,z.jsxs)(`div`,{className:`awi-clientconfig-line`,children:[(0,z.jsx)(`span`,{className:`muted text-label`,children:r(`api.clientConfig.destination`)}),(0,z.jsx)(ju,{text:h.destination})]}),(0,z.jsxs)(`div`,{className:`awi-clientconfig-line`,children:[(0,z.jsx)(`span`,{className:`muted text-label`,children:r(`api.clientConfig.envHint`)}),(0,z.jsx)(ju,{text:h.exportHint})]}),(0,z.jsx)(`p`,{className:`muted small awi-clientconfig-merge`,children:r(`api.clientConfig.mergeWarning`)})]}),(0,z.jsxs)(`div`,{className:`awi-clientconfig-line`,children:[(0,z.jsx)(`span`,{className:`muted text-label`,children:r(`api.baseUrl`)}),(0,z.jsx)(ju,{text:t})]}),(0,z.jsxs)(`details`,{className:`awi-clientconfig-where`,children:[(0,z.jsx)(`summary`,{className:`muted text-label`,children:r(`api.clientConfig.whereDisclosure`)}),(0,z.jsx)(`p`,{className:`muted small`,children:r(`api.clientConfig.whereBody`)})]}),!m&&h!==null&&(0,z.jsx)(`div`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:v})]})}function Bu({keys:e,apiBase:t,attributionSince:n,historyTruncated:r,authMatrix:i,keysLoading:a,keysLoadFailed:o,endpoints:s,claudeCodeEnabled:c,localeTag:l,newName:u,creating:d,newKey:f,copied:p,filteredModels:m,modelsLoading:h,modelsRefreshing:g=!1,modelsLoadFailed:v,modelCount:y,hasModelData:b,modelQuery:x,copiedModelId:S,modelTests:C,canTestModels:w,onNewNameChange:T,onCreate:E,onDismissNewKey:D,onCopyKey:O,onDelete:k,onRename:A,onModelQueryChange:j,onCopyModelId:M,onTestModel:N,onRetryModels:P,sourceLabel:F,protocolLabel:I}){let L=q(),[R,B]=(0,_.useState)(null),[V,H]=(0,_.useState)(!1),[U,W]=(0,_.useState)(!1),[G,ee]=(0,_.useState)(!1),[te,ne]=(0,_.useState)(!1),[K,re]=(0,_.useState)(``),[ie,ae]=(0,_.useState)(!1),[oe,se]=(0,_.useState)(!1),[ce,ue]=(0,_.useState)(!1),de=R?e.find(e=>e.id===R)??null:null,fe=G||ie,pe=()=>{H(!1),W(!1)},me=()=>{B(null),pe(),ne(!1),se(!1),ue(!1)};(0,_.useEffect)(()=>{if(!V)return;let e=window.setTimeout(()=>W(!0),300);return()=>window.clearTimeout(e)},[V]);let he=()=>{de&&H(!0)},_e=async()=>{if(!(!de||!U||G)){ee(!0),ue(!1);try{await k(de.id)?(pe(),B(null)):ue(!0)}finally{ee(!1)}}},ve=()=>{de&&(re(de.name),se(!1),ne(!0))},ye=async()=>{if(!de||ie)return;let e=K.trim();if(!e||e===de.name){ne(!1);return}ae(!0),se(!1);try{await A(de.id,e)?ne(!1):se(!0)}finally{ae(!1)}};return(0,z.jsx)(`div`,{className:`apikeys-workspace-shell`,children:(0,z.jsxs)(`div`,{className:`apikeys-workspace-root`,children:[(0,z.jsxs)(`aside`,{className:`apikeys-workspace-rail`,"aria-label":L(`api.title`),children:[(0,z.jsx)(`div`,{className:`apikeys-workspace-rail-header`,children:(0,z.jsx)(`span`,{className:`apikeys-workspace-rail-title`,children:a?L(`api.activeKeysLoading`):L(`api.activeKeys`,{count:e.length})})}),(0,z.jsxs)(`div`,{className:`apikeys-workspace-rail-list`,children:[(0,z.jsx)(`button`,{type:`button`,className:`apikeys-workspace-rail-row${R===null?` apikeys-workspace-rail-row--selected`:``}`,onClick:me,disabled:fe,"aria-current":R===null?`page`:void 0,children:(0,z.jsx)(`span`,{className:`apikeys-workspace-rail-name`,children:L(`api.workspace.overview`)})}),a?(0,z.jsx)(`span`,{className:`apikeys-workspace-rail-empty`,children:L(`common.loading`)}):e.length===0?(0,z.jsx)(`span`,{className:`apikeys-workspace-rail-empty`,children:L(o?`api.keysLoadFailed`:`api.workspace.noKeysHint`)}):e.map(e=>(0,z.jsxs)(`button`,{type:`button`,className:`apikeys-workspace-rail-row${R===e.id?` apikeys-workspace-rail-row--selected`:``}`,disabled:fe,onClick:()=>{B(e.id),pe(),ne(!1),se(!1),ue(!1)},"aria-current":R===e.id?`page`:void 0,children:[(0,z.jsx)(`span`,{className:`apikeys-workspace-rail-name`,children:e.name}),(0,z.jsx)(`span`,{className:`apikeys-workspace-rail-meta`,children:n?e.usage.ambiguous?L(`api.attribution.railAmbiguous`):`${L(`api.attribution.railRequests`,{count:e.usage.requests7d})} · ${e.usage.lastUsedAt?L(`api.attribution.railLastUsed`,{date:Ou(e.usage.lastUsedAt,l)}):L(`api.attribution.railNeverUsed`)}`:L(`api.attribution.unavailable`)})]},e.id))]})]}),(0,z.jsx)(`section`,{className:`apikeys-workspace-main`,"aria-label":L(`api.workspace.details`),children:de?(0,z.jsxs)(`div`,{className:`awi-detail`,children:[(0,z.jsx)(`div`,{className:`awi-detail-toolbar`,children:(0,z.jsxs)(`button`,{type:`button`,className:`awi-back`,onClick:me,disabled:fe,children:[(0,z.jsx)(ge,{className:`awi-back-chevron`,"aria-hidden":`true`}),L(`modal.back`)]})}),(0,z.jsxs)(`div`,{className:`awi-detail-body`,children:[(0,z.jsxs)(`div`,{className:`awi-detail-head`,children:[(0,z.jsx)(`h2`,{className:`awi-detail-title`,children:de.name}),(0,z.jsx)(`span`,{className:`awi-detail-actions`,children:V?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-danger btn-sm awi-confirm-delete`,onClick:()=>{_e()},disabled:!U||G,children:[(0,z.jsx)(le,{}),` `,L(G?`api.key.deleting`:`api.confirm`)]},`confirm-delete`),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:pe,disabled:G,children:L(`common.cancel`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:ve,disabled:te,children:L(`api.key.rename`)},`rename`),(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-danger btn-sm`,onClick:he,"aria-label":L(`api.deleteAria`),children:[(0,z.jsx)(le,{}),` `,L(`api.workspace.deleteKey`)]},`request-delete`)]})})]}),V&&(0,z.jsx)(`p`,{className:`muted awi-delete-hint`,children:L(`api.workspace.deleteConfirm`)}),ce&&(0,z.jsx)(`p`,{className:`awi-delete-error`,role:`alert`,children:L(`api.deleteFailed`)}),te&&(0,z.jsxs)(`div`,{className:`awi-rename`,children:[(0,z.jsx)(`label`,{className:`awi-rename-label`,htmlFor:`awi-key-name`,children:L(`api.key.name`)}),(0,z.jsx)(`input`,{id:`awi-key-name`,className:`input`,type:`text`,value:K,maxLength:64,disabled:ie,onChange:e=>re(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ye())}}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-sm`,onClick:()=>{ye()},disabled:ie,children:L(ie?`api.key.renaming`:`api.key.saveName`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>ne(!1),disabled:ie,children:L(`common.cancel`)}),oe&&(0,z.jsx)(`p`,{className:`awi-rename-error`,role:`alert`,children:L(`api.key.renameFailed`)})]}),(0,z.jsxs)(`div`,{className:`awi-section`,children:[(0,z.jsx)(`h3`,{className:`awi-section-title`,children:L(`api.workspace.keyDetails`)}),(0,z.jsxs)(`dl`,{className:`awi-kv`,children:[(0,z.jsxs)(`div`,{className:`awi-kv-row`,children:[(0,z.jsx)(`dt`,{children:L(`api.workspace.keyPrefix`)}),(0,z.jsx)(`dd`,{children:(0,z.jsx)(`code`,{children:de.prefix})})]}),(0,z.jsxs)(`div`,{className:`awi-kv-row`,children:[(0,z.jsx)(`dt`,{children:L(`api.colCreated`)}),(0,z.jsx)(`dd`,{children:Ou(de.createdAt,l)})]})]})]}),(0,z.jsxs)(`div`,{className:`awi-section`,children:[(0,z.jsx)(`h3`,{className:`awi-section-title`,children:L(`api.attribution.title`)}),n?de.usage.ambiguous?(0,z.jsx)(`p`,{className:`muted`,children:L(`api.attribution.ambiguous`)}):(0,z.jsxs)(`dl`,{className:`awi-kv`,children:[(0,z.jsxs)(`div`,{className:`awi-kv-row`,children:[(0,z.jsx)(`dt`,{children:L(`api.attribution.requests7d`)}),(0,z.jsx)(`dd`,{children:de.usage.requests7d.toLocaleString(l)})]}),(0,z.jsxs)(`div`,{className:`awi-kv-row`,children:[(0,z.jsx)(`dt`,{children:L(r?`api.attribution.totalRequestsAvailable`:`api.attribution.totalRequests`)}),(0,z.jsx)(`dd`,{children:de.usage.totalRequests.toLocaleString(l)})]}),(0,z.jsxs)(`div`,{className:`awi-kv-row`,children:[(0,z.jsx)(`dt`,{children:L(`api.attribution.lastUsed`)}),(0,z.jsx)(`dd`,{children:de.usage.lastUsedAt?Ou(de.usage.lastUsedAt,l):L(`api.attribution.neverUsed`)})]}),(0,z.jsxs)(`div`,{className:`awi-kv-row`,children:[(0,z.jsx)(`dt`,{children:L(r?`api.attribution.sinceAvailable`:`api.attribution.since`)}),(0,z.jsx)(`dd`,{children:Ou(n,l)})]})]}):(0,z.jsx)(`p`,{className:`muted`,children:L(`api.attribution.unavailableDetail`)})]})]})]}):(0,z.jsxs)(`div`,{className:`awi-overview`,children:[(0,z.jsxs)(`div`,{className:`awi-overview-left`,children:[(0,z.jsx)(Pu,{keys:e,keysLoading:a,keysLoadFailed:o,newName:u,creating:d,newKey:f,copied:p,confirmDelete:null,localeTag:l,showKeyList:!1,onNewNameChange:T,onCreate:E,onDismissNewKey:D,onCopyKey:O,onConfirmDelete:()=>{},onCancelDelete:()=>{},onDelete:()=>{}}),(0,z.jsx)(Nu,{endpoints:s,claudeCodeEnabled:c,authMatrix:i}),(0,z.jsx)(zu,{apiBase:t,baseUrl:s.baseUrl,hasKeys:e.length>0}),(0,z.jsx)(Iu,{endpoints:s,claudeCodeEnabled:c})]}),(0,z.jsx)(`div`,{className:`awi-overview-right`,children:(0,z.jsx)(Fu,{filteredModels:m,modelsLoading:h,modelsRefreshing:g,modelsLoadFailed:v,modelCount:y,hasModelData:b,modelQuery:x,copiedModelId:S,modelTests:C,claudeCodeEnabled:c,onModelQueryChange:j,onCopyModelId:M,onTestModel:N,onRetryModels:P,canTestModels:w,sourceLabel:F,protocolLabel:I})})]})})]})})}var Vu=[],Hu=15e3;function Uu(e){let t=e.replace(/\/$/,``);if(!t)return Eu;try{return new URL(t).host?Du(`${t}/v1/responses`):Eu}catch{return Eu}}function Wu(e){return!e||!Tu(e.authMatrix)||!Array.isArray(e.keys)||e.keys.some(e=>!e||!Cu(e.usage))?null:e}function Gu({apiBase:e}){let{t,locale:n}=Be(),r=Fe.find(e=>e.code===n)?.htmlLang,i=`ocx.apikeys.list.v2:${e}`,a=`ocx.apikeys.models.v1:${e}`,o=`api-keys:${e}`,s=`api-models:${e}`,c=Wu(X(i)),l=X(a),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(``),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)({}),[y,b]=(0,_.useState)(``),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(null),[T,E]=(0,_.useState)(!1),D=(0,_.useRef)(!1),O=(0,_.useCallback)(async n=>{let r=await lt(await fetch(`${e}/api/keys`,{signal:n}));if(!r||!Tu(r.authMatrix))throw Error(t(`api.keysLoadFailed`));let a=r.keys??[];if(a.some(e=>!Cu(e.usage)))throw Error(t(`api.keysLoadFailed`));let o=a,s=Du(r.endpoint??``),c={keys:o,endpoints:{baseUrl:r.baseUrl??s.baseUrl,responses:r.responsesEndpoint??r.endpoint??Eu.responses,chatCompletions:r.chatCompletionsEndpoint??s.chatCompletions,messages:r.messagesEndpoint??s.messages,models:r.modelsEndpoint??s.models},claudeCodeEnabled:r.claudeCodeEnabled!==!1,...r.attributionSince?{attributionSince:r.attributionSince}:{},...r.historyTruncated===!0?{historyTruncated:!0}:{},authMatrix:r.authMatrix};return Z(i,c),c},[e,i,t]),k=(0,_.useCallback)(async n=>{let r=await fetch(`${e}/v1/models`,{signal:n});if(!r.ok)throw Error(t(`api.modelsLoadFailed`));let i=await r.json(),o=Array.isArray(i)?i:typeof i==`object`&&i&&Array.isArray(i.data)?i.data:null;if(!o)throw Error(t(`api.modelsLoadFailed`));let s=o.filter(e=>typeof e==`object`&&!!e&&typeof e.id==`string`).map(e=>xu(e)).sort((e,t)=>Su(e).localeCompare(Su(t)));return Z(a,s),s},[e,a,t]),A=ss(o,[e],O,{isEmpty:e=>e.keys.length===0,initialData:c??void 0}),j=ss(s,[e],k,{isEmpty:e=>e.length===0,initialData:l??void 0}),M=A.state,N=j.state,P=M.data??c,F=N.data??l??Vu,I=P?.keys??[],L=P?.endpoints??Uu(e),R=P?.claudeCodeEnabled??!0,B=P?.attributionSince,V=P?.historyTruncated===!0,H=P?.authMatrix??[],U=A.refresh,W=j.refresh,G=(0,_.useMemo)(()=>{let e=f.trim().toLowerCase();return e?F.filter(t=>Su(t).toLowerCase().includes(e)||t.displayName.toLowerCase().includes(e)||t.provider.toLowerCase().includes(e)):F},[f,F]),ee=async n=>{if(D.current)return!1;D.current=!0,S(!0),d(null);try{let r=n??y,i=await Y(await fetch(`${e}/api/keys`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:r||`default`})}),t(`api.createFailed`));return typeof i?.key!=`string`||i.key.length===0?(d(t(`api.createFailed`)),!1):(w(i.key),b(``),U(),!0)}catch{return d(t(`api.createFailed`)),!1}finally{D.current=!1,S(!1)}},te=async t=>{d(null);let n=Lt(Hu);try{return(await fetch(`${e}/api/keys`,{method:`DELETE`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t}),signal:n.signal})).ok?(U(),!0):!1}catch{return!1}finally{n.clear()}},ne=async(t,n)=>{d(null);let r=Lt(Hu);try{return(await fetch(`${e}/api/keys`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({id:t,name:n}),signal:r.signal})).ok?(U(),!0):!1}catch{return!1}finally{r.clear()}},K=async()=>{if(C){d(null);try{await navigator.clipboard.writeText(C),E(!0),window.setTimeout(()=>E(!1),2e3)}catch{E(!1),d(t(`api.key.copyFailed`))}}},re=async e=>{try{await navigator.clipboard.writeText(e),h(e),window.setTimeout(()=>h(t=>t===e?null:t),2e3)}catch{}},ie=e=>e.native?t(`api.sourceNative`):e.provider===`combo`?t(`api.sourceCombo`):e.custom?t(`api.sourceCustom`):e.provider,ae=e=>t(e===`responses`?`api.protocolResponses`:e===`messages`?`api.protocolMessages`:`api.protocolChatCompletions`),oe=(e,t)=>e===`responses`?{url:L.responses,body:{model:t,input:`ping`,max_output_tokens:1,stream:!1}}:e===`messages`?{url:L.messages,body:{model:t,max_tokens:1,messages:[{role:`user`,content:`ping`}]}}:{url:L.chatCompletions,body:{model:t,messages:[{role:`user`,content:`ping`}],max_tokens:1,stream:!1}},se=(e,t,n)=>v(r=>({...r,[e]:{...r[e],[t]:n}})),ce=async(e,n)=>{if(!C)return;let r=Su(e),i=oe(n,r);se(r,n,{state:`testing`});try{let e=await fetch(i.url,{method:`POST`,headers:{"Content-Type":`application/json`,"x-opencodex-api-key":C},body:JSON.stringify(i.body)});if(!e.ok){se(r,n,{state:`error`,detail:(await e.text()).slice(0,160)||String(e.status)});return}se(r,n,{state:`ok`})}catch(e){se(r,n,{state:`error`,detail:e instanceof Error?e.message:t(`api.testFailed`)})}},le=t(`api.subtitle`).split(`{authHeader}`);return(0,z.jsxs)(`section`,{className:`api-page`,"aria-busy":M.refreshing||N.refreshing||void 0,children:[(0,z.jsx)(`div`,{className:`page-head`,children:(0,z.jsx)(`h2`,{children:t(`api.title`)})}),(0,z.jsxs)(`p`,{className:`page-sub`,children:[le[0],(0,z.jsx)(`code`,{children:`x-opencodex-api-key`}),le[1]]}),u&&(0,z.jsx)(J,{tone:`err`,children:u}),M.showError&&P&&(0,z.jsx)(J,{tone:`err`,children:t(`api.keysLoadFailed`)}),M.showSkeleton&&!P?(0,z.jsx)(ls,{label:t(`api.activeKeysLoading`),rows:4}):M.kind===`failed-cold`&&!P?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(J,{tone:`err`,children:M.error instanceof Error?M.error.message:t(`api.keysLoadFailed`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>U(),children:t(`common.retry`)})]}):(0,z.jsx)(z.Fragment,{children:(0,z.jsx)(Bu,{keys:I,apiBase:e,attributionSince:B,historyTruncated:V,authMatrix:H,keysLoading:!1,keysLoadFailed:M.showError,endpoints:L,claudeCodeEnabled:R,localeTag:r,newName:y,creating:x,newKey:C,copied:T,filteredModels:G,modelsLoading:N.showSkeleton&&!N.data&&!l,modelsRefreshing:N.refreshing&&N.showError&&(N.data!==void 0||l!==null),modelsLoadFailed:N.showError,modelCount:F.length,hasModelData:N.data!==void 0||l!==null,modelQuery:f,copiedModelId:m,modelTests:g,onNewNameChange:b,onCreate:()=>{ee()},onDismissNewKey:()=>w(null),onCopyKey:()=>{K()},onDelete:te,onRename:ne,onModelQueryChange:p,onCopyModelId:e=>{re(e)},onTestModel:(e,t)=>{ce(e,t)},onRetryModels:()=>{W({forceLoading:!0})},canTestModels:C!==null,sourceLabel:ie,protocolLabel:ae})})]})}function Ku(e,t){let n=(e??[]).map(e=>({value:e,label:Io(e)}));return[{value:``,label:t},...n]}function qu(e){let t=e.autoConnectSupported===!0;return{autoConnectSupported:t,systemEnv:t&&e.systemEnv===!0}}var Ju=[`ANTHROPIC_MODEL`,`ANTHROPIC_DEFAULT_OPUS_MODEL`,`ANTHROPIC_DEFAULT_SONNET_MODEL`,`ANTHROPIC_DEFAULT_HAIKU_MODEL`,`ANTHROPIC_DEFAULT_FABLE_MODEL`];function Yu(e){let t=`http://127.0.0.1:${e.port}`,n=e.authMode===`auto`?e.markerMode??`subscription`:e.authMode,r=e.autoContext&&e.maxContextTokens===null,i=Ju.filter(t=>e.effectiveModelEnv[t]).map(t=>`export ${t}=${e.effectiveModelEnv[t]}`);return[`export ANTHROPIC_BASE_URL=${t}`,...n===`proxy`?[`export ANTHROPIC_AUTH_TOKEN=opencodex-proxy`]:[`# no ANTHROPIC_AUTH_TOKEN: your claude.ai login (and connectors) stay active`],`export CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`,...n===`proxy`?['[ -z "${CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST+x}" ] && export CLAUDE_CODE_PROVIDER_MANAGED_BY_HOST=1']:[],...r?[`export CLAUDE_CODE_AUTO_COMPACT_WINDOW=${e.autoCompactWindow??35e4}`]:[],...i,`claude`].join(`
|
|
67
|
-
`)}function Xu(e){return e?e.backend??`auto`:`inherit`}function Zu(e,t){if(t!==`inherit`)return t===`auto`?{...e,backend:void 0}:{...e,backend:t}}function Qu(e,t){return{...e,model:t}}function $u(e){if(!e)return null;let t=(e.model??``).trim();return e.backend?{backend:e.backend,model:t}:t?{backend:null,model:t}:null}function ed({label:e,checked:t,onChange:n,disabled:r=!1,describedBy:i}){return(0,z.jsxs)(`label`,{className:`toggle`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:t,disabled:r,"aria-label":e,"aria-describedby":i,onChange:e=>n(e.target.checked)}),(0,z.jsx)(`span`,{className:`slider`,"aria-hidden":`true`})]})}function td({supported:e,checked:t,onChange:n}){let r=q(),i=e?void 0:`claude-system-env-unsupported`;return(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:r(`claude.systemEnv`)}),e?(0,z.jsx)(`span`,{className:`desc`,children:r(`claude.systemEnvDesc`)}):(0,z.jsx)(`span`,{className:`desc`,id:i,children:(0,z.jsx)(He,{k:`claude.systemEnvUnsupported`,cmd:`ocx claude`})}),e&&t&&(0,z.jsx)(`span`,{className:`desc`,style:{color:`var(--red)`},children:r(`claude.systemEnvWarn`)})]}),(0,z.jsx)(ed,{label:r(`claude.systemEnv`),checked:e&&t,disabled:!e,describedBy:i,onChange:n})]})}function nd({value:e,tierHaikuModel:t,options:n,onChange:r}){let i=q(),a=t??e;return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:i(`claude.smallFastModelAccurateHint`)}),(0,z.jsx)(it,{value:e,options:n,onChange:r,label:i(`claude.smallFastModel`),style:{maxWidth:420}}),a===``&&(0,z.jsx)(`p`,{className:`notice-warn`,role:`status`,style:{marginTop:8},children:i(`claude.smallFastModelNativeWarning`)})]})}function rd(){if(typeof crypto<`u`&&typeof crypto.randomUUID==`function`)try{return crypto.randomUUID()}catch{}let e=new Uint8Array(16);if(typeof crypto<`u`&&typeof crypto.getRandomValues==`function`)crypto.getRandomValues(e);else for(let t=0;t<16;t++)e[t]=Math.floor(Math.random()*256);e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function id(e,t=`en`){if(e>=1e6){let n=e/1e6,r=n.toFixed(1).replace(/\.0$/,``);return Number.isInteger(n)||Number(r)*1e6===e?new Intl.NumberFormat(t,{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:+!Number.isInteger(n)}).format(e):`${Math.round(e/1e3)}k`}return`${Math.round(e/1e3)}k`}function ad(e,t){return e&&[`claude-json-oauth`,`claude-credentials-file`,`macos-keychain`,`exported-env`].includes(e)?t(`claude.authSource.${e}`):t(`claude.authSource.unknown`)}function od({state:e,autoCompactOptions:t,availableModels:n,onStateChange:r}){let i=q();return(0,z.jsxs)(`div`,{className:`card`,style:{overflow:`hidden`},children:[(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.enabledLabel`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.enabledHint`)})]}),(0,z.jsx)(ed,{label:i(`claude.enabledLabel`),checked:e.enabled,onChange:t=>r({...e,enabled:t})})]}),(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.authMode`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.authModeHint`)})]}),(0,z.jsx)(`div`,{className:`setting-controls`,children:(0,z.jsx)(it,{value:e.authMode,options:[{value:`auto`,label:i(`claude.authModeAuto`)},{value:`subscription`,label:i(`claude.authModeSubscription`)},{value:`proxy`,label:i(`claude.authModeProxy`)}],onChange:t=>r({...e,authMode:t}),label:i(`claude.authMode`),style:{minWidth:220},align:`right`,portal:!0})})]}),e.authModeOrigin&&(0,z.jsxs)(`div`,{className:`claude-effective-auth${e.authModeOrigin===`auto-unknown`?` warn`:``}`,role:`status`,children:[(0,z.jsx)(`span`,{className:`claude-effective-auth-label`,children:i(`claude.effectiveMode.label`)}),(0,z.jsxs)(`span`,{children:[e.authModeOrigin===`manual`?i(`claude.effectiveMode.manual`,{mode:e.markerMode===`proxy`?i(`claude.authModeProxy`):i(`claude.authModeSubscription`)}):e.authModeOrigin===`auto-present`?i(`claude.effectiveMode.autoPresent`,{source:ad(e.authFoundBy,i)}):e.authModeOrigin===`auto-absent`?i(`claude.effectiveMode.autoAbsent`):i(`claude.effectiveMode.autoUnknown`),e.admissionKeyActive===!0?` ${i(`claude.effectiveMode.admissionKey`)}`:``]})]}),(0,z.jsx)(td,{supported:e.autoConnectSupported,checked:e.systemEnv,onChange:t=>r({...e,systemEnv:t})}),(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.fastMode`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.fastModeDesc`)})]}),(0,z.jsx)(`div`,{className:`setting-controls`,children:(0,z.jsx)(it,{value:e.fastMode===null?`auto`:e.fastMode?`on`:`off`,options:[{value:`auto`,label:i(`claude.fastAuto`)},{value:`on`,label:i(`claude.fastOn`)},{value:`off`,label:i(`claude.fastOff`)}],onChange:t=>r({...e,fastMode:t===`auto`?null:t===`on`}),label:i(`claude.fastMode`),style:{minWidth:140},align:`right`,portal:!0})})]}),(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.autoContext`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.autoContextDesc`)}),e.maxContextTokens!==null&&(0,z.jsx)(`span`,{className:`desc`,style:{color:`var(--muted)`},children:i(`claude.autoContextInert`)})]}),(0,z.jsx)(ed,{label:i(`claude.autoContext`),checked:e.autoContext,onChange:t=>r({...e,autoContext:t})})]}),e.autoContext&&(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.autoCompactWindow`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.autoCompactWindowDesc`)}),e.autoCompactWindow!==null&&(0,z.jsx)(`span`,{className:`desc`,style:{color:`var(--red)`},children:i(`claude.autoCompactWindowWarn`)})]}),(0,z.jsx)(`div`,{className:`setting-controls`,children:(0,z.jsx)(it,{value:e.autoCompactWindow===null?``:String(e.autoCompactWindow),options:t,onChange:t=>r({...e,autoCompactWindow:t===``?null:Number(t)}),label:i(`claude.autoCompactWindow`),style:{minWidth:130},align:`right`,portal:!0})})]}),(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.injectAgents`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.injectAgentsDesc`)})]}),(0,z.jsx)(ed,{label:i(`claude.injectAgents`),checked:e.injectAgents,onChange:t=>r({...e,injectAgents:t})})]}),[`webSearchSidecar`,`visionSidecar`].map(t=>{let a=e[t],o=t===`webSearchSidecar`?`claude.webSearchSidecar`:`claude.visionSidecar`,s=t===`webSearchSidecar`?`claude.webSearchSidecarHint`:`claude.visionSidecarHint`,c=`claude-sidecar-models-${t}`;return(0,z.jsxs)(`div`,{className:`setting-row`,style:{alignItems:`flex-start`},children:[(0,z.jsxs)(`div`,{className:`setting-label setting-copy`,style:{flex:1},children:[(0,z.jsx)(`span`,{className:`title`,children:i(o)}),(0,z.jsx)(`span`,{className:`desc`,children:i(s)})]}),(0,z.jsxs)(`div`,{className:`setting-controls`,style:{display:`flex`,gap:8},children:[(0,z.jsx)(it,{value:Xu(a),options:[{value:`inherit`,label:i(`claude.useMainSetting`)},{value:`auto`,label:i(`dash.backendAuto`)},{value:`openai`,label:i(`dash.backendOpenAI`)},{value:`anthropic`,label:i(`dash.backendAnthropic`)}],onChange:n=>{r({...e,[t]:Zu(a,n)})},label:i(`dash.sidecarBackend`),portal:!0}),(0,z.jsx)(`input`,{className:`input mono`,value:a?.model??``,onChange:n=>{r({...e,[t]:Qu(a,n.target.value)})},placeholder:i(`claude.sidecarModelPlaceholder`),disabled:!a,list:a?c:void 0,"aria-label":i(`dash.sidecarModel`),style:{minWidth:210},autoComplete:`off`}),a&&(0,z.jsx)(`datalist`,{id:c,children:n.map(e=>(0,z.jsx)(`option`,{value:e},e))})]})]},t)})]})}function sd({manualEnv:e}){let t=q();return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:(0,z.jsx)(He,{k:`claude.quickstartHint`,cmd:`ocx claude`})}),(0,z.jsx)(`pre`,{className:`mono card`,style:{padding:`10px 14px`,overflowX:`auto`,margin:0},children:`ocx claude`}),(0,z.jsxs)(`details`,{style:{margin:`10px 0 0`},children:[(0,z.jsx)(`summary`,{className:`muted text-label`,style:{cursor:`pointer`,padding:`2px 2px`},children:t(`claude.manualEnv`)}),(0,z.jsx)(`pre`,{className:`mono card text-label`,style:{padding:`10px 14px`,overflowX:`auto`,margin:`6px 0 0`},children:e})]})]})}function cd({rows:e,onRowsChange:t}){let n=q();return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:n(`claude.modelMapHint`)}),(0,z.jsx)(`div`,{className:`stack`,style:{gap:8},children:e.map((r,i)=>(0,z.jsxs)(`div`,{className:`row`,style:{gap:8},children:[(0,z.jsx)(`input`,{className:`input mono`,value:r.from,placeholder:n(`claude.mapFrom`),"aria-label":n(`claude.mapFrom`),onChange:n=>t(e.map((e,t)=>t===i?{...e,from:n.target.value}:e)),style:{flex:1}}),(0,z.jsx)(`span`,{className:`muted`,"aria-hidden":!0,children:`→`}),(0,z.jsx)(`input`,{className:`input mono`,value:r.to,placeholder:n(`claude.mapTo`),"aria-label":n(`claude.mapTo`),onChange:n=>t(e.map((e,t)=>t===i?{...e,to:n.target.value}:e)),style:{flex:1}}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>t(e.filter((e,t)=>t!==i)),"aria-label":n(`claude.removeMapping`),style:{color:`var(--red)`},children:(0,z.jsx)(ie,{})})]},r.id))}),(0,z.jsx)(`div`,{style:{marginTop:8},children:(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>t([...e,{id:rd(),from:``,to:``}]),children:[(0,z.jsx)(ae,{}),` `,n(`claude.addMapping`)]})})]})}var ld=`etc`;function ud(e){let t=new Map;for(let n of e){let e=/\(([^)]+)\)\s*$/.exec(n.display_name),r=e?e[1]:ld,i=t.get(r);i?i.push(n):t.set(r,[n])}return Array.from(t)}function dd({aliases:e}){let t=q();return(0,z.jsxs)(`div`,{className:`claude-aliases`,children:[(0,z.jsx)(`p`,{className:`muted text-label claude-aliases-hint`,children:t(`claude.aliasesHint`)}),e.length===0?(0,z.jsx)(`div`,{className:`muted text-label`,children:t(`claude.none`)}):(0,z.jsx)(`div`,{className:`claude-aliases-scroll`,children:ud(e).map(([e,n])=>(0,z.jsxs)(`div`,{className:`claude-aliases-group`,children:[(0,z.jsxs)(`div`,{className:`claude-aliases-group-label`,children:[e===ld?t(`claude.aliasProviderOther`):e,(0,z.jsx)(`span`,{className:`claude-aliases-group-count`,children:n.length})]}),(0,z.jsx)(`div`,{className:`claude-aliases-chips`,children:n.map(e=>(0,z.jsxs)(`span`,{className:`claude-aliases-chip`,children:[(0,z.jsx)(`code`,{className:`claude-aliases-chip-id`,children:e.id}),e.display_name?(0,z.jsx)(`span`,{className:`claude-aliases-chip-name`,children:e.display_name}):null]},e.id))})]},e))})]})}function fd({apiBase:e,active:t=!0}){let n=q(),{locale:r}=Be(),i=Fe.find(e=>e.code===r)?.htmlLang??`en`,a=`ocx.claude-code.v1:${e}`,o=`claude-code:${e}`,s=(0,_.useMemo)(()=>X(a),[a]),[c,l]=(0,_.useState)(()=>s?.state??null),[u,d]=(0,_.useState)(()=>s?.rows??[]),[f,p]=(0,_.useState)(!!s),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(`settings`),x=(0,_.useCallback)(async t=>{let r=await Y(await fetch(`${e}/api/claude-code`,{signal:t}),n(`claude.loadFail`));if(!r)throw Error(n(`claude.loadFail`));let i={...r,authMode:r.authMode===`proxy`||r.authMode===`subscription`?r.authMode:`auto`,...qu(r),fastMode:r.fastMode??null,maxContextTokens:r.maxContextTokens??null,autoContext:r.autoContext!==!1,autoCompactWindow:r.autoCompactWindow??null,injectAgents:r.injectAgents!==!1,effectiveModelEnv:r.effectiveModelEnv??{}},o=Object.entries(r.modelMap??{}).map(([e,t])=>({id:rd(),from:e,to:String(t)})),s={state:i,rows:o};if(t.aborted)throw Error(`Claude Code request aborted`);return l(i),d(o),p(!0),Z(a,s),s},[e,a,n]),S=ss(o,[e],x,{isEmpty:()=>!1,enabled:t,initialData:s??void 0}),C=S.state,w=C.data??s,T=c??w?.state??null,E=f?u:w?.rows??u,D=(0,_.useMemo)(()=>Ku(T?.available,n(`claude.smallFastModelUnsetOption`)),[T?.available,n]),O=(0,_.useMemo)(()=>{let e=[1e5,2e5,25e4,3e5,35e4,4e5,5e5,6e5,75e4,9e5,1e6],t=T?.autoCompactWindow??null,r=t!==null&&!e.includes(t)?[...e,t].sort((e,t)=>e-t):e;return[{value:``,label:n(`claude.autoCompactDefault`)},...r.map(e=>({value:String(e),label:id(e,i)}))]},[T?.autoCompactWindow,n,i]),k=async()=>{if(!T)return;h(``);let t={};for(let e of E)e.from.trim()&&e.to.trim()&&(t[e.from.trim()]=e.to.trim());try{await Y(await fetch(`${e}/api/claude-code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:T.enabled,authMode:T.authMode,systemEnv:T.systemEnv,fastMode:T.fastMode,autoContext:T.autoContext,autoCompactWindow:T.autoCompactWindow,injectAgents:T.injectAgents,smallFastModel:T.smallFastModel,modelMap:t,webSearchSidecar:$u(T.webSearchSidecar),visionSidecar:$u(T.visionSidecar)})}),n(`claude.saveFailed`)),v(!0),h(n(`claude.saved`)),S.refresh()}catch(e){v(!1),h(e instanceof Error&&e.message?e.message:n(`claude.networkError`))}};if(C.kind===`disabled`&&!w)return null;if(C.showSkeleton&&!w)return(0,z.jsx)(ls,{label:n(`claude.loading`),rows:3});if(C.kind===`failed-cold`)return(0,z.jsxs)(`div`,{className:`claudecode-workspace-shell`,children:[(0,z.jsx)(J,{tone:`err`,children:C.error instanceof Error?C.error.message:n(`claude.loadFail`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>S.refresh(),children:n(`common.retry`)})]});if(!T)return null;let A=[{id:`settings`,label:n(`claude.workspace.settings`),body:(0,z.jsx)(od,{state:T,autoCompactOptions:O,availableModels:T.available??[],onStateChange:l})},{id:`quickstart`,label:n(`claude.quickstart`),body:(0,z.jsx)(sd,{manualEnv:Yu(T)})},{id:`smallFast`,label:n(`claude.smallFastModel`),body:(0,z.jsx)(nd,{value:T.smallFastModel,tierHaikuModel:T.tierModels?.haiku,options:D,onChange:e=>l({...T,smallFastModel:e})})},{id:`modelMap`,label:n(`claude.modelMap`),meta:String(E.length),body:(0,z.jsx)(cd,{rows:E,onRowsChange:e=>{p(!0),d(e)}})},{id:`aliases`,label:n(`claude.aliases`),meta:String(T.aliases.length),body:(0,z.jsx)(dd,{aliases:T.aliases})}],j=A.find(e=>e.id===y)??A[0],M=y===`settings`||y===`smallFast`||y===`modelMap`;return(0,z.jsxs)(`div`,{className:`claudecode-workspace-shell`,children:[m&&(0,z.jsx)(J,{tone:g?`ok`:`err`,children:m}),C.showError&&(0,z.jsx)(J,{tone:`err`,children:n(`claude.loadFail`)}),(0,z.jsxs)(`div`,{className:`claudecode-workspace-root`,children:[(0,z.jsx)(`aside`,{className:`claudecode-workspace-rail`,"aria-label":n(`claude.pageTitle`),children:(0,z.jsx)(`div`,{className:`claudecode-workspace-rail-list`,children:A.map(e=>(0,z.jsx)(`button`,{type:`button`,className:`claudecode-workspace-rail-row${y===e.id?` claudecode-workspace-rail-row--selected`:``}`,onClick:()=>b(e.id),"aria-current":y===e.id?`true`:void 0,children:(0,z.jsx)(`span`,{className:`claudecode-workspace-rail-name`,children:e.label})},e.id))})}),(0,z.jsxs)(`section`,{className:`claudecode-workspace-main`,"aria-label":j.label,children:[(0,z.jsxs)(`div`,{className:`ccw-main-head`,children:[(0,z.jsxs)(`h3`,{className:`ccw-main-title`,children:[j.label,j.meta==null?null:(0,z.jsx)(`span`,{className:`count`,children:j.meta})]}),(0,z.jsx)(`div`,{className:`claudecode-workspace-save`,"data-visible":M?`true`:`false`,children:(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:!M,tabIndex:M?0:-1,"aria-hidden":!M,onClick:()=>{k()},children:n(`common.save`)})})]}),(0,z.jsx)(`div`,{className:`ccw-body`,children:j.body})]})]})]})}function pd(e,t,n){let r=t.trim().toLowerCase(),i=(r?e.filter(e=>e.label.toLowerCase().includes(r)||e.route.toLowerCase().includes(r)):e).toSorted((e,t)=>Number(!e.available)-Number(!t.available)),a=i.slice(0,n);return{total:e.length,showSearch:e.length>4,shown:a,hidden:i.length-a.length,noMatch:e.length>0&&i.length===0}}function md(e){return new Set(Object.keys(e))}function hd(e,t){return t!==null&&e===t}function gd(e){return e||(typeof localStorage>`u`?void 0:localStorage)}function _d(e){return{read(t){let n=gd(t);if(!n)return null;try{let t=n.getItem(e);if(t===null)return null;let r=JSON.parse(t);return Array.isArray(r)?new Set(r.filter(e=>typeof e==`string`)):null}catch{return null}},write(t,n){let r=gd(n);if(r)try{r.setItem(e,JSON.stringify([...t]))}catch{}}}}function vd(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}var $=[`opus`,`fable`,`sonnet`,`haiku`],yd=_d(`ocx.claudeDesktop.collapsedFamilies.v2`),bd={opus:`claudeDesktop.family.opus`,fable:`claudeDesktop.family.fable`,sonnet:`claudeDesktop.family.sonnet`,haiku:`claudeDesktop.family.haiku`};function xd(e){return{version:1,assignments:Object.fromEntries(Object.entries(e.assignments).map(([e,t])=>[e,{...t}])),defaults:{...e.defaults},...e.appliedFingerprint===void 0?{}:{appliedFingerprint:e.appliedFingerprint},...e.appliedAt===void 0?{}:{appliedAt:e.appliedAt}}}function Sd(e){let t={...e.profile.assignments};for(let n of e.models){let e=t[n.route]??n.assignment;t[n.route]={family:$.includes(e?.family)?e.family:`opus`,alias:typeof e?.alias==`string`?e.alias:``}}return{version:1,assignments:t,defaults:{opus:e.profile.defaults.opus??null,fable:e.profile.defaults.fable??null,sonnet:e.profile.defaults.sonnet??null,haiku:e.profile.defaults.haiku??null}}}function Cd(e,t){return e&&typeof e==`object`&&`error`in e&&typeof e.error==`string`?e.error:t}function wd(e,t){return e?e>=1048576?t(`claudeDesktop.contextM`,{n:Math.round(e/1048576)}):e>=1e6?t(`claudeDesktop.contextM`,{n:e/1e6}):t(`claudeDesktop.contextK`,{n:Math.round(e/1e3)}):null}function Td(e){return X(e)}function Ed(e){let t=Td(e);return{held:t,data:t?.data??null,profile:t?.profile??null,savedProfile:t?.profile?xd(t.profile):null,destinations:t?.data?Object.fromEntries(t.data.models.map(e=>[e.route,t.profile.assignments[e.route]?.family??`opus`])):{}}}function Dd({apiBase:e,active:t=!0,onPortChange:n}){let{t:r,locale:i}=Be(),a=Fe.find(e=>e.code===i)?.htmlLang,o=`ocx.claude-desktop.v1:${e}`,s=`claude-desktop:${e}`,c=(0,_.useMemo)(()=>Ed(o),[o]),[l,u]=(0,_.useState)(()=>c.profile),[d,f]=(0,_.useState)(()=>c.savedProfile),[p,m]=(0,_.useState)(()=>c.destinations),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)({}),[w,T]=(0,_.useState)({}),[E,D]=(0,_.useState)(()=>yd.read()??new Set($)),[O,k]=(0,_.useState)({}),A=(0,_.useRef)(null),j=(0,_.useCallback)(async t=>{let n=await Y(await fetch(`${e}/api/claude-desktop`,{signal:t}),r(`claudeDesktop.loadFail`));if(!n||!(`profile`in n)||!(`models`in n))throw Error(Cd(n,r(`claudeDesktop.loadFail`)));let i=Sd(n),a={data:n,profile:i};if(t.aborted)throw Error(`Claude Desktop request aborted`);if(u(i),f(xd(i)),m(Object.fromEntries(n.models.map(e=>[e.route,i.assignments[e.route]?.family??`opus`]))),yd.read()===null){let e=Object.fromEntries($.map(e=>[e,0]));for(let t of n.models)e[i.assignments[t.route]?.family??`opus`]+=1;D(md(e))}return Z(o,a),a},[e,o,r,m,u,f]),M=ss(s,[e],j,{isEmpty:()=>!1,enabled:t,initialData:c.held??void 0}),N=M.state,P=N.data??(c.data&&c.profile?{data:c.data,profile:c.profile}:null),F=P?.data??null,I=l??P?.profile??null,L=d??P?.profile??null,R=P?Object.fromEntries(P.data.models.map(e=>[e.route,P.profile.assignments[e.route]?.family??`opus`])):{},B=Object.keys(p).length>0?p:R;(0,_.useEffect)(()=>{if(n){if(typeof F?.port==`number`){n(F.port);return}N.kind===`failed-cold`&&n(null)}},[F?.port,N.kind,n]);let V=(0,_.useMemo)(()=>I!==null&&L!==null&&JSON.stringify(I)!==JSON.stringify(L),[I,L]),H=(0,_.useMemo)(()=>{let e=Object.fromEntries($.map(e=>[e,[]]));if(!F||!I)return e;for(let t of F.models)e[I.assignments[t.route]?.family??`opus`].push(t);return e},[F,I]),U=(0,_.useMemo)(()=>{let e={};for(let t of $){let n=H[t].filter(e=>e.available).map(e=>e.route).sort(),r=I?.defaults[t]??null;e[t]=r&&n.includes(r)?r:n[0]??null}return e},[H,I]),W=`ocx.claude-desktop.status.v1:${e}`,G=`claude-desktop-status:${e}`,ee=X(W),te=ss(G,[e],async t=>{let n=await lt(await fetch(`${e}/api/claude-desktop/status`,{signal:t}));if(!n)throw Error(`Claude Desktop status unavailable`);return Z(W,n),n},{isEmpty:()=>!1,pollMs:5e3,enabled:t,initialData:ee??void 0}),ne=te.state,K=ne.data??ee??null,re=ne.showError,ie=(e,t)=>{!I||I.assignments[e]?.family===t||(u(n=>{if(!n)return n;let r=n.assignments[e];if(!r||r.family===t)return n;let i={...n.assignments,[e]:{...r,family:t}},a={...n.defaults};return a[r.family]===e&&(a[r.family]=Object.keys(i).filter(t=>t!==e&&i[t].family===r.family).sort()[0]??null),a[t]===null&&(a[t]=e),{...n,assignments:i,defaults:a}}),m(n=>({...n,[e]:t})),y(r(`claudeDesktop.moved`,{route:e,family:r(bd[t])})))},ae=e=>{let t=vd(E,e);yd.write(t),D(t)},oe=async t=>{if(!(!I||b)){x(`save`),g(null);try{await Y(await fetch(`${e}/api/claude-desktop`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({profile:I})}),r(`claudeDesktop.saveFailed`)),f(xd(I)),t?(x(`apply`),await Y(await fetch(`${e}/api/claude-desktop/apply`,{method:`POST`}),r(`claudeDesktop.applyFailed`)),g({tone:`ok`,text:r(`claudeDesktop.savedApplied`)}),y(r(`claudeDesktop.savedAppliedAnnounce`))):(g({tone:`ok`,text:r(`claudeDesktop.saved`)}),y(r(`claudeDesktop.savedAnnounce`))),te.refresh()}catch(e){let t=e instanceof Error?e.message:r(`claudeDesktop.updateFailed`);g({tone:`err`,text:t}),y(t)}finally{x(null)}}},se=()=>{if(!I)return;let e=URL.createObjectURL(new Blob([`${JSON.stringify(I,null,2)}\n`],{type:`application/json`})),t=document.createElement(`a`);t.href=e,t.download=`claude-desktop-profile.json`,t.click(),URL.revokeObjectURL(e),y(r(`claudeDesktop.exported`))},ce=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t)try{let e=JSON.parse(await t.text());if(e.version!==1||!e.assignments||!e.defaults)throw Error(r(`claudeDesktop.importExpected`));u(Sd({...F,profile:e})),g({tone:`ok`,text:r(`claudeDesktop.importReady`)}),y(r(`claudeDesktop.importedAnnounce`))}catch(e){let t=e instanceof Error?e.message:r(`claudeDesktop.importInvalid`);g({tone:`err`,text:t}),y(r(`claudeDesktop.importFailed`,{error:t}))}},le=(e,t)=>{e.preventDefault();let n=e.dataTransfer.getData(`text/plain`);n&&ie(n,t)};return N.kind===`disabled`&&!P?null:N.showSkeleton&&!P?(0,z.jsx)(ls,{label:r(`claudeDesktop.loading`),rows:4}):N.kind===`failed-cold`?(0,z.jsxs)(`div`,{className:`claude-desktop-error`,children:[(0,z.jsx)(J,{tone:`err`,children:N.error instanceof Error?N.error.message:r(`claudeDesktop.loadFail`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:()=>M.refresh(),children:r(`claudeDesktop.retry`)})]}):!F||!I?null:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`claude-desktop-toolbar`,children:(0,z.jsxs)(`div`,{className:`claude-profile-tools`,children:[(0,z.jsx)(`input`,{ref:A,type:`file`,accept:`application/json,.json`,hidden:!0,onChange:e=>void ce(e)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>A.current?.click(),children:r(`claudeDesktop.importJson`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:se,children:r(`claudeDesktop.exportJson`)})]})}),(0,z.jsxs)(`div`,{className:`claude-status-bar ${re&&!K?`not-applied`:K?K.activeProfile===!1?`not-applied`:K.stale?`stale`:K.applied?`applied`:`not-applied`:`pending`}`,"aria-busy":!K&&!re||void 0,children:[(0,z.jsx)(`span`,{className:`claude-status-dot`}),(0,z.jsx)(`span`,{children:re&&!K?r(`claudeDesktop.loadFail`):K?K.activeProfile===!1?r(`claudeDesktop.status.notActiveProfile`):K.stale?r(`claudeDesktop.status.stale`):K.applied?r(`claudeDesktop.status.applied`):r(`claudeDesktop.status.notApplied`):r(`claudeDesktop.loading`)}),K?.health.lastRequestAt&&(0,z.jsxs)(`span`,{className:`claude-status-health`,children:[r(`claudeDesktop.health.lastRequest`),`:`,` `,new Date(K.health.lastRequestAt).toLocaleTimeString(a)]}),K&&K.health.requestCount>0&&(0,z.jsx)(`span`,{className:`claude-status-health`,children:r(`claudeDesktop.health.stats`,{count:K.health.requestCount,errors:K.health.errorCount})})]}),(0,z.jsx)(`div`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:v}),h&&(0,z.jsx)(J,{tone:h.tone,children:h.text}),N.showError&&(0,z.jsx)(J,{tone:`err`,children:r(`claudeDesktop.loadFail`)}),re&&K&&(0,z.jsx)(J,{tone:`err`,children:r(`claudeDesktop.loadFail`)}),(0,z.jsxs)(`div`,{className:`claude-profile-bar`,children:[(0,z.jsx)(`span`,{className:`claude-dirty${V?` active`:``}`,children:r(V?`claudeDesktop.unsaved`:`claudeDesktop.upToDate`)}),(0,z.jsxs)(`div`,{className:`claude-save-actions`,children:[(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:!V||b!==null,onClick:()=>void oe(!1),children:r(b===`save`?`claudeDesktop.saving`:`common.save`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:b!==null,onClick:()=>void oe(!0),children:r(b===`apply`?`claudeDesktop.applying`:b===`save`?`claudeDesktop.saving`:`claudeDesktop.saveApply`)})]})]}),F.models.length===0&&(0,z.jsx)(at,{title:r(`claudeDesktop.emptyTitle`),children:r(`claudeDesktop.emptyHint`)}),(0,z.jsx)(`div`,{className:`ocx-group-stack`,"aria-label":r(`claudeDesktop.assignmentsLabel`),children:$.map(e=>{let t=H[e],n=pd(t,S[e]??``,w[e]??6),i=E.has(e),a=U[e];return(0,z.jsxs)(`section`,{className:`ocx-group${i?` collapsed`:``}`,"aria-labelledby":`claude-lane-${e}`,onDragOver:e=>e.preventDefault(),onDrop:t=>le(t,e),children:[(0,z.jsxs)(`header`,{className:`ocx-group-head${i?``:` open`}`,children:[(0,z.jsx)(`h3`,{id:`claude-lane-${e}`,className:`ocx-group-heading`,children:(0,z.jsxs)(`button`,{type:`button`,className:`ocx-group-toggle`,"aria-expanded":!i,"aria-controls":`claude-lane-body-${e}`,onClick:()=>ae(e),children:[(0,z.jsx)(ge,{className:`ocx-chevron`,width:14,height:14,"aria-hidden":`true`,style:{transform:i?`none`:`rotate(90deg)`}}),(0,z.jsx)(`span`,{className:`ocx-group-name`,children:r(bd[e])}),(0,z.jsx)(`span`,{className:`ocx-group-count`,children:r(t.length===1?`claudeDesktop.modelCountOne`:`claudeDesktop.modelCountMany`,{count:t.length})}),a&&(0,z.jsx)(`code`,{className:`claude-lane-default`,title:a,children:a})]})}),t.length>0&&I.defaults[e]===null&&(0,z.jsx)(`span`,{className:`claude-default-needed`,children:r(`claudeDesktop.chooseDefault`)}),a&&a!==I.defaults[e]&&(0,z.jsx)(`span`,{className:`claude-default-needed`,title:a,children:r(`claudeDesktop.temporaryDefault`)})]}),!i&&(0,z.jsxs)(`div`,{id:`claude-lane-body-${e}`,children:[n.showSearch&&(0,z.jsx)(`input`,{className:`input claude-lane-search`,type:`search`,placeholder:r(`models.search`),"aria-label":r(`models.search`),value:S[e]??``,onChange:t=>{let n=t.target.value;C(t=>({...t,[e]:n})),T(t=>({...t,[e]:6}))}}),(0,z.jsxs)(`div`,{className:`claude-lane-models`,children:[t.length===0?(0,z.jsx)(`div`,{className:`claude-lane-empty`,children:r(`claudeDesktop.laneEmpty`)}):n.noMatch?(0,z.jsx)(`div`,{className:`claude-lane-empty`,children:r(`claudeDesktop.laneNoMatch`)}):n.shown.map(t=>{let n=I.assignments[t.route],i=wd(t.contextWindow,r),a=B[t.route]??`opus`,o=O[t.route]??hd(t.route,U[e]);return(0,z.jsxs)(`article`,{className:`claude-model-card${o?` open`:``}`,draggable:t.available,onDragStart:e=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.route)},children:[(0,z.jsxs)(`button`,{type:`button`,className:`claude-model-summary`,"aria-expanded":o,"aria-controls":`claude-model-body-${t.route}`,onClick:()=>k(e=>({...e,[t.route]:!o})),children:[(0,z.jsx)(ge,{className:`ocx-chevron`,width:12,height:12,"aria-hidden":`true`,style:{transform:o?`rotate(90deg)`:`none`}}),(0,z.jsxs)(`span`,{className:`claude-model-names`,children:[(0,z.jsx)(`strong`,{title:t.label,children:t.label}),(0,z.jsx)(`code`,{title:t.route,children:t.route})]}),i&&(0,z.jsx)(`span`,{className:`claude-model-context`,children:i}),!i&&(0,z.jsx)(`span`,{className:`claude-model-context claude-model-context-unknown`,children:r(`claudeDesktop.contextUnknown`)}),t.supports1m===!0&&(0,z.jsx)(`span`,{className:`claude-1m-chip`,children:r(`claudeDesktop.supports1m`)}),t.effortSupported===!1&&(0,z.jsx)(`span`,{className:`claude-effort-badge off`,children:r(`claudeDesktop.effort.displayOnly`)}),t.effortSupported===!0&&(0,z.jsx)(`span`,{className:`claude-effort-badge on`,children:r(`claudeDesktop.effort.supported`)}),I.defaults[e]===t.route&&(0,z.jsx)(`span`,{className:`claude-row-default`,children:r(`claudeDesktop.defaultBadge`)}),(0,z.jsx)(`span`,{className:`badge ${t.available?`badge-green`:`badge-muted`}`,children:t.available?r(`claudeDesktop.available`):r(`claudeDesktop.unavailable`)})]}),o&&(0,z.jsxs)(`div`,{className:`claude-model-body`,id:`claude-model-body-${t.route}`,children:[U[e]===t.route&&I.defaults[e]!==t.route&&(0,z.jsx)(`span`,{className:`claude-effective-default`,children:r(`claudeDesktop.temporaryDefault`)}),(0,z.jsxs)(`div`,{className:`claude-field`,children:[(0,z.jsx)(`span`,{children:r(`claudeDesktop.alias`)}),(0,z.jsx)(`code`,{className:`claude-alias`,title:n.alias,children:n.alias})]}),(0,z.jsxs)(`label`,{className:`claude-default-radio`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`default-${e}`,checked:I.defaults[e]===t.route,disabled:!t.available,onChange:()=>u(n=>n&&{...n,defaults:{...n.defaults,[e]:t.route}})}),r(`claudeDesktop.useAsDefault`,{family:r(bd[e])})]}),(0,z.jsxs)(`div`,{className:`claude-move-row`,children:[(0,z.jsx)(`label`,{htmlFor:`move-${t.route}`,children:r(`claudeDesktop.moveTo`)}),(0,z.jsx)(`select`,{id:`move-${t.route}`,className:`input`,value:a,disabled:!t.available,onChange:e=>m(n=>({...n,[t.route]:e.target.value})),children:$.map(e=>(0,z.jsx)(`option`,{value:e,children:r(bd[e])},e))}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:!t.available||a===e,onClick:()=>ie(t.route,a),children:r(`claudeDesktop.move`)})]})]})]},t.route)}),n.hidden>0&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm claude-lane-more`,onClick:()=>T(t=>({...t,[e]:(t[e]??6)+6})),children:r(`models.showMore`,{n:n.hidden})})]})]})]},e)})})]})}function Od(e){let t=X(`ocx.claude-desktop.v1:${e}`);return typeof t?.data?.port==`number`?t.data.port:null}function kd({apiBase:e}){let[t,n]=(0,_.useState)(`code`),r=q(),i=(0,_.useRef)(null),a=(0,_.useRef)(null),o=Od(e),[s,c]=(0,_.useState)(null),l=s?.base===e?s.port:o,u=s?.base===e,d=(0,_.useCallback)(t=>{c(n=>n?.base===e&&n.port===t?n:{base:e,port:t})},[e]),f=e=>{n(e),window.requestAnimationFrame(()=>{(e===`code`?i:a).current?.focus({preventScroll:!0})})},p=e=>{e.key===`ArrowLeft`||e.key===`ArrowRight`?(e.preventDefault(),f(t===`code`?`desktop`:`code`)):e.key===`Home`?(e.preventDefault(),f(`code`)):e.key===`End`&&(e.preventDefault(),f(`desktop`))};return(0,z.jsxs)(`section`,{className:`claude-page`,children:[(0,z.jsxs)(`div`,{className:`claude-page-intro`,children:[(0,z.jsx)(`div`,{className:`page-head`,children:(0,z.jsx)(`h2`,{children:r(t===`code`?`claude.pageTitle`:`claudeDesktop.title`)})}),t===`code`?(0,z.jsx)(`p`,{className:`page-sub`,children:r(`claude.subtitle`)}):(0,z.jsx)(`p`,{className:`page-sub`,children:l==null?r(u?`claudeDesktop.loadFail`:`claudeDesktop.loading`):r(`claudeDesktop.subtitle`,{port:l})})]}),(0,z.jsxs)(`div`,{className:`claude-tabs`,role:`tablist`,"aria-label":r(`claude.tabsLabel`),children:[(0,z.jsx)(`button`,{type:`button`,role:`tab`,ref:i,"aria-selected":t===`code`,"aria-controls":`claude-code-panel`,id:`claude-code-tab`,className:t===`code`?`active`:``,tabIndex:t===`code`?0:-1,onKeyDown:p,onClick:()=>f(`code`),children:r(`claude.tabCode`)}),(0,z.jsx)(`button`,{type:`button`,role:`tab`,ref:a,"aria-selected":t===`desktop`,"aria-controls":`claude-desktop-panel`,id:`claude-desktop-tab`,className:t===`desktop`?`active`:``,tabIndex:t===`desktop`?0:-1,onKeyDown:p,onClick:()=>f(`desktop`),children:r(`claude.tabDesktop`)})]}),(0,z.jsx)(`div`,{id:`claude-code-panel`,role:`tabpanel`,"aria-labelledby":`claude-code-tab`,hidden:t!==`code`,children:(0,z.jsx)(fd,{apiBase:e,active:t===`code`},e)}),(0,z.jsx)(`div`,{id:`claude-desktop-panel`,role:`tabpanel`,"aria-labelledby":`claude-desktop-tab`,hidden:t!==`desktop`,children:(0,z.jsx)(Dd,{apiBase:e,active:t===`desktop`,onPortChange:d},e)})]})}function Ad(e,t,n,r){let i=e.filter(e=>r===`native`===e.native).map(e=>({...e,alias:t.get(e.id)??null,enabled:!n.has(e.id)})).toSorted((e,t)=>Number(!e.enabled)-Number(!t.enabled));return{rows:i,total:i.length,enabled:i.filter(e=>e.enabled).length}}var jd=_d(`ocx.grok.collapsedGroups.v2`),Md=[{id:`native`,tkey:`grok.groupNative`},{id:`routed`,tkey:`grok.groupRouted`}],Nd=new Set(Md.map(e=>e.id));function Pd(e,t){return e?e>=1048576?t(`claudeDesktop.contextM`,{n:Math.round(e/1048576)}):e>=1e6?t(`claudeDesktop.contextM`,{n:e/1e6}):t(`claudeDesktop.contextK`,{n:Math.round(e/1e3)}):`—`}function Fd({apiBase:e}){let t=q(),n=`ocx.grok.status.v1:${e}`,r=X(n),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(()=>jd.read()??new Set(Nd)),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(``),m=(0,_.useCallback)(async()=>{let r=await Y(await fetch(`${e}/api/grok`),t(`grok.loadFail`));if(!r)throw Error(t(`grok.loadFail`));let i={...r,candidates:r.candidates??[],excluded:r.excluded??[]};return Z(n,i),i},[e,n,t]),h=`grok-status:${e}`,g=ss(h,[e],m,{isEmpty:()=>!1,initialData:r??void 0}),{state:v}=g,y=g.refresh,b=v.data??r,x=(0,_.useMemo)(()=>new Set(b?.excluded??[]),[b]),S=i??x,C=(0,_.useMemo)(()=>i!==null&&(i.size!==x.size||[...i].some(e=>!x.has(e))),[i,x]),w=(0,_.useMemo)(()=>new Map((b?.models??[]).map(e=>[e.id,e.alias])),[b]),T=e=>{let t=vd(o,e);jd.write(t),s(t)},E=e=>{let t=e?new Set(Md.map(e=>e.id)):new Set;jd.write(t),s(t)},D=(e,t)=>{a(n=>{let r=new Set(n??x);return t?r.delete(e):r.add(e),r})},O=async r=>{if(!c){l(`save`),d(null);try{await Y(await fetch(`${e}/api/grok/selection`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({excluded:[...S]})}),t(`grok.saveFailed`));let i=[...S];if(b&&L(h,{...b,excluded:i}),a(null),r){l(`apply`);let n=await fetch(`${e}/api/grok/apply`,{method:`POST`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.message??e.error??t(`grok.applyFailed`))}let r=await n.json().catch(()=>({}));r.skippedReason?(d({tone:`err`,text:r.message??t(`grok.applySkipped`)}),p(r.message??t(`grok.applySkipped`))):(d({tone:`ok`,text:t(`grok.savedApplied`)}),p(t(`grok.savedApplied`))),await y()}else d({tone:`ok`,text:t(`grok.saved`)}),p(t(`grok.saved`)),b&&Z(n,{...b,excluded:i})}catch(e){let n=e instanceof Error?e.message:t(`grok.saveFailed`);d({tone:`err`,text:n}),p(n)}finally{l(null)}}};return v.showSkeleton&&!b?(0,z.jsx)(`section`,{className:`grok-page`,children:(0,z.jsx)(ls,{label:t(`grok.loading`),rows:4})}):v.kind===`failed-cold`?(0,z.jsxs)(`section`,{className:`grok-page`,children:[(0,z.jsx)(`div`,{className:`alert alert-err`,role:`alert`,children:v.error instanceof Error?v.error.message:t(`grok.loadFail`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>y(),children:t(`common.retry`)})]}):(0,z.jsxs)(`section`,{className:`grok-page`,"aria-busy":v.refreshing||void 0,children:[(0,z.jsx)(`h2`,{className:`page-title`,children:t(`grok.title`)}),(0,z.jsx)(`p`,{className:`page-sub`,children:t(`grok.subtitle`)}),(0,z.jsx)(`div`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:f}),u&&(0,z.jsx)(J,{tone:u.tone,children:u.text}),v.showError&&(0,z.jsx)(J,{tone:`err`,children:t(`grok.loadFail`)}),b&&b.candidates.length>0&&(0,z.jsxs)(`div`,{className:`claude-profile-bar`,children:[(0,z.jsx)(`span`,{className:`claude-dirty${C?` active`:``}`,children:t(C?`grok.unsaved`:`grok.upToDate`)}),(0,z.jsxs)(`div`,{className:`claude-save-actions`,children:[(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:!C||c!==null,onClick:()=>void O(!1),children:t(c===`save`?`grok.saving`:`common.save`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:!C||c!==null,onClick:()=>void O(!0),children:t(c===`apply`?`grok.applying`:c===`save`?`grok.saving`:`grok.saveApply`)})]})]}),b?.present?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`grok-endpoint`,children:[(0,z.jsx)(`span`,{children:t(`grok.endpoint`)}),(0,z.jsx)(`code`,{children:b.baseUrl??`—`})]}),(0,z.jsx)(`p`,{className:`page-sub`,children:(0,z.jsx)(`code`,{children:b.configPath})})]}):(0,z.jsxs)(at,{title:t(`grok.notConfiguredTitle`),children:[t(`grok.notConfiguredHint`),(0,z.jsx)(`br`,{}),(0,z.jsx)(`code`,{children:b?.configPath})]}),b&&b.candidates.length>0&&(0,z.jsxs)(`div`,{className:`ocx-group-stack`,children:[(0,z.jsxs)(`div`,{className:`row`,style:{gap:6,margin:`2px 0 10px`},children:[(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm text-caption`,onClick:()=>E(!0),disabled:c!==null,children:[(0,z.jsx)(ge,{width:12,height:12,"aria-hidden":`true`}),` `,t(`models.collapseAll`)]}),(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm text-caption`,onClick:()=>E(!1),disabled:c!==null,children:[(0,z.jsx)(ge,{width:12,height:12,"aria-hidden":`true`,style:{transform:`rotate(90deg)`}}),` `,t(`models.expandAll`)]})]}),Md.map(e=>{let n=Ad(b.candidates,w,S,e.id);if(n.total===0)return null;let r=o.has(e.id);return(0,z.jsxs)(`section`,{className:`ocx-group${r?` collapsed`:``}`,"aria-labelledby":`grok-group-${e.id}`,children:[(0,z.jsx)(`header`,{className:`ocx-group-head${r?``:` open`}`,children:(0,z.jsx)(`h3`,{id:`grok-group-${e.id}`,className:`ocx-group-heading`,children:(0,z.jsxs)(`button`,{type:`button`,className:`ocx-group-toggle`,"aria-expanded":!r,"aria-controls":`grok-group-body-${e.id}`,onClick:()=>T(e.id),children:[(0,z.jsx)(ge,{className:`ocx-chevron`,width:14,height:14,"aria-hidden":`true`,style:{transform:r?`none`:`rotate(90deg)`}}),(0,z.jsx)(`span`,{className:`ocx-group-name`,children:t(e.tkey)}),(0,z.jsx)(`span`,{className:`ocx-group-count`,children:t(`grok.enabledCount`,{on:n.enabled,total:n.total})})]})})}),!r&&(0,z.jsx)(`div`,{id:`grok-group-body-${e.id}`,className:`grok-model-list`,children:n.rows.map(e=>(0,z.jsxs)(`div`,{className:`grok-model-row`,children:[(0,z.jsx)(rt,{on:e.enabled,onClick:()=>D(e.id,!e.enabled),disabled:c!==null,label:t(`grok.toggleModel`,{id:e.id})}),(0,z.jsxs)(`span`,{className:`grok-model-names`,children:[(0,z.jsx)(`strong`,{title:e.id,children:e.id}),(0,z.jsx)(`code`,{title:e.alias??void 0,children:e.alias??`—`})]}),(0,z.jsx)(`span`,{className:`claude-model-context`,children:Pd(e.contextWindow,t)})]},e.id))})]},e.id)})]})]})}function Id(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.supported==`boolean`&&typeof t.installed==`boolean`&&typeof t.running==`boolean`&&typeof t.stale==`boolean`&&typeof t.summary==`string`}var Ld={native:`startup.status.native`,protected:`startup.status.protected`,"at-risk":`startup.status.atRisk`},Rd={native:`startup.summary.native`,protected:`startup.summary.protected`,"at-risk":`startup.summary.atRisk`},zd={service:`startup.protection.service`,shim:`startup.protection.shim`,none:`startup.protection.none`};function Bd({ok:e,yes:t,no:n}){return(0,z.jsx)(`span`,{className:`badge ${e?`badge-green`:`badge-amber`}`,children:e?t:n})}function Vd({failed:e,data:t}){let{t:n}=Be(),r=e?`startup-hero--risk`:t.status===`protected`?`startup-hero--safe`:t.status===`at-risk`?`startup-hero--risk`:`startup-hero--native`,i=e||t.status===`at-risk`?ue:re,a=t.routingKind===`opencodex-local`?`startup.routing.proxy`:t.routingKind===`custom-local`?`startup.routing.customLocal`:t.routingKind===`custom-remote`?`startup.routing.customRemote`:t.routingKind===`unknown`?`startup.routing.unknown`:`startup.routing.native`;return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`section`,{className:`panel startup-hero ${r}`,"aria-live":`polite`,children:[(0,z.jsx)(`div`,{className:`startup-hero-icon`,children:(0,z.jsx)(i,{})}),(0,z.jsxs)(`div`,{className:`startup-hero-copy`,children:[(0,z.jsx)(`span`,{className:`badge ${e||t.status===`at-risk`?`badge-amber`:`badge-green`}`,children:n(e?`startup.status.atRisk`:Ld[t.status])}),(0,z.jsx)(`h3`,{children:n(e?`startup.error`:Rd[t.status])}),(0,z.jsx)(`p`,{children:e?n(`startup.staleData`):t.status===`at-risk`?n(sn(t)):n(`startup.safeDetail`)})]})]}),(0,z.jsxs)(`div`,{className:`startup-state-grid`,children:[(0,z.jsxs)(`section`,{className:`stat`,children:[(0,z.jsx)(`div`,{className:`label`,children:n(`startup.routing`)}),(0,z.jsx)(`div`,{className:`value`,children:n(a)})]}),(0,z.jsxs)(`section`,{className:`stat`,children:[(0,z.jsx)(`div`,{className:`label`,children:n(`startup.restartProtection`)}),(0,z.jsx)(`div`,{className:`value`,children:n(zd[t.protection])})]}),(0,z.jsxs)(`section`,{className:`stat`,children:[(0,z.jsx)(`div`,{className:`label`,children:n(`startup.preference`)}),(0,z.jsx)(`div`,{className:`value`,children:n(t.autostartEnabled?`startup.enabled`:`startup.disabled`)})]})]})]})}function Hd({data:e,failed:t,loading:n=!1,installBusy:r,installResult:i,onInstall:a}){let{t:o}=Be(),s=e.serviceSupported&&e.serviceInstalled&&e.serviceStale&&!e.serviceConflict,c=e.shimInstalled&&!e.shimHealthy,l=r!==null||t||n;return(0,z.jsxs)(`section`,{className:`panel startup-details`,children:[(0,z.jsxs)(`div`,{className:`panel-head`,children:[(0,z.jsx)(`h3`,{className:`panel-title`,children:o(`startup.details`)}),(0,z.jsx)(`span`,{className:`muted mono`,children:e.platform})]}),(0,z.jsxs)(`div`,{className:`startup-detail-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:o(`startup.service`)}),(0,z.jsx)(`span`,{children:o(`startup.serviceHint`)})]}),(0,z.jsxs)(`div`,{className:`startup-detail-actions`,children:[(0,z.jsx)(Bd,{ok:e.serviceViable,yes:o(`startup.viable`),no:o(e.serviceConflict?`startup.conflict`:e.serviceStale?`startup.stale`:e.serviceInstalled?`startup.unhealthy`:e.serviceSupported?`startup.notInstalled`:`startup.unsupported`)}),e.serviceSupported&&!e.serviceInstalled&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,"aria-label":`${o(`startup.service`)} - ${o(`startup.install`)}`,disabled:l,onClick:()=>a(`install-service`),children:o(r===`install-service`?`startup.installing`:`startup.install`)}),s&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,"aria-label":`${o(`startup.service`)} - ${o(`startup.repair`)}`,disabled:l,onClick:()=>a(`install-service`,{repair:!0}),children:o(r===`install-service`?`startup.repairing`:`startup.repair`)})]})]}),(0,z.jsxs)(`div`,{className:`startup-detail-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:o(`startup.shim`)}),(0,z.jsx)(`span`,{children:o(`startup.shimHint`)})]}),(0,z.jsxs)(`div`,{className:`startup-detail-actions`,children:[(0,z.jsx)(Bd,{ok:e.shimHealthy&&e.autostartEnabled,yes:o(e.shimCoverage===`cli-only`?`startup.cliOnly`:`startup.healthy`),no:o(e.shimInstalled?e.shimHealthy&&!e.autostartEnabled?`startup.installedDisabled`:`startup.stale`:`startup.notInstalled`)}),!e.shimInstalled&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,"aria-label":`${o(`startup.shim`)} - ${o(`startup.install`)}`,disabled:l,onClick:()=>a(`install-shim`),children:o(r===`install-shim`?`startup.installing`:`startup.install`)}),c&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,"aria-label":`${o(`startup.shim`)} - ${o(`startup.repair`)}`,disabled:l,onClick:()=>a(`install-shim`,{repair:!0}),children:o(r===`install-shim`?`startup.repairing`:`startup.repair`)})]})]}),i&&(0,z.jsx)(`div`,{className:`notice ${i.kind===`success`?`notice-ok`:`notice-warn`} startup-action-notice`,role:`status`,"aria-live":`polite`,children:i.kind===`success`?i.action===`install-service`?o(i.repair?`startup.serviceRepaired`:`startup.serviceInstalled`):o(i.repair?`startup.shimRepaired`:`startup.shimInstalled`):`${o(`startup.installFailed`)} ${i.detail??``}`})]})}function Ud({tray:e,trayLoading:t,trayError:n,trayBusy:r,onTrayAction:i}){let{t:a}=Be();return(0,z.jsxs)(`section`,{className:`panel startup-actions`,children:[(0,z.jsxs)(`div`,{className:`panel-head`,children:[(0,z.jsx)(`h3`,{className:`panel-title`,children:a(`startup.tray.title`)}),(0,z.jsx)(ve,{})]}),(0,z.jsx)(`p`,{className:`muted`,children:a(`startup.tray.hint`)}),(0,z.jsxs)(`div`,{className:`startup-detail-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:a(`startup.tray.login`)}),(0,z.jsx)(`span`,{children:a(`startup.tray.notProtection`)})]}),t||n||!e?(0,z.jsx)(`span`,{className:`badge badge-amber`,children:a(t?`startup.tray.loading`:`startup.tray.unavailable`)}):(0,z.jsx)(Bd,{ok:e.running&&!e.stale,yes:a(`startup.tray.running`),no:a(e.stale?`startup.tray.stale`:e.installed?`startup.tray.stopped`:`startup.tray.notInstalled`)})]}),(0,z.jsxs)(`div`,{className:`startup-tray-buttons`,children:[!t&&!n&&e&&!e.installed&&!e.stale&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:r,onClick:()=>i(`install`),children:a(`startup.tray.install`)}),!t&&!n&&e?.installed&&!e.stale&&!e.running&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:r,onClick:()=>i(`start`),children:a(`startup.tray.start`)}),!t&&!n&&e?.running&&!e.stale&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:r,onClick:()=>i(`stop`),children:a(`startup.tray.stop`)}),!t&&!n&&e&&(e.installed||e.stale)&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-danger`,disabled:r,onClick:()=>{window.confirm(a(`startup.tray.uninstall`))&&i(`uninstall`)},children:a(`startup.tray.uninstall`)})]}),(n||e?.stale)&&(0,z.jsx)(`div`,{className:`notice notice-warn startup-tray-error`,role:`alert`,children:a(`startup.tray.error`)})]})}function Wd({data:e,copied:t,onCopy:n}){let{t:r}=Be();return(0,z.jsxs)(`section`,{className:`panel startup-actions`,children:[(0,z.jsxs)(`div`,{className:`panel-head`,children:[(0,z.jsx)(`h3`,{className:`panel-title`,children:r(`startup.recovery`)}),(0,z.jsx)(te,{})]}),(0,z.jsx)(`p`,{className:`muted`,children:r(`startup.recoveryHint`)}),(0,z.jsxs)(`div`,{className:`startup-command-list`,children:[e.serviceSupported&&(0,z.jsxs)(`div`,{className:`startup-command-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:r(`startup.command.service`)}),(0,z.jsx)(`code`,{children:e.commands.installService})]}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>n(e.commands.installService),children:t===e.commands.installService?r(`startup.copied`):r(`startup.copy`)})]}),(0,z.jsxs)(`div`,{className:`startup-command-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:r(`startup.command.shim`)}),(0,z.jsx)(`code`,{children:e.commands.installShim})]}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>n(e.commands.installShim),children:t===e.commands.installShim?r(`startup.copied`):r(`startup.copy`)})]}),(0,z.jsxs)(`div`,{className:`startup-command-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:r(`startup.command.native`)}),(0,z.jsx)(`code`,{children:e.commands.restoreNative})]}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>n(e.commands.restoreNative),children:t===e.commands.restoreNative?r(`startup.copied`):r(`startup.copy`)})]})]}),e.status===`at-risk`&&(0,z.jsxs)(`div`,{className:`notice notice-warn startup-action-notice`,role:`alert`,children:[(0,z.jsx)(ve,{}),` `,r(`startup.recommended`,{cmd:e.recommendedCommand??e.commands.installService})]})]})}var Gd=`ocx.startup.page.v1:`;function Kd(e,t){let n=t===`win32`?`; `:` && `;return e.join(n)}function qd(e,t,n){if(!e)return{warning:null,fix:null};let r=!!e.catalogClamp?.active,i=!!e.newerAvailable,a=(r?e.catalogClamp?.runtimeVersion:e.version)??e.version??`unknown`,o=(e.catalogClamp?.removedEfforts??[]).join(`, `),s=Kd([`ocx doctor --fix-codex-runtime`,`ocx sync`],n);return r?{warning:o?t(`startup.codexRuntime.clampHiddenWithEfforts`,{version:a,efforts:o}):t(`startup.codexRuntime.clampHidden`,{version:a}),fix:i?s:`ocx sync`}:i?{warning:t(`startup.codexRuntime.olderBinary`,{version:a}),fix:s}:{warning:null,fix:null}}function Jd({apiBase:e}){let{t}=Be(),n=`${Gd}${e}`,r=(0,_.useMemo)(()=>X(n),[n]),i=`startup-page:${e}`,[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(()=>r?.tray??null),[l,u]=(0,_.useState)(()=>!r?.data),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(()=>r?.warning??null),[S,C]=(0,_.useState)(()=>r?.fix??null),[w,T]=(0,_.useState)(()=>!r?.data),E=(0,_.useRef)(!!r?.data),D=(0,_.useCallback)(async r=>{let i=E.current;i||(u(!0),T(!0));try{let i=fetch(`${e}/api/settings`,{signal:r}).then(async e=>e.ok?await e.json():null).catch(()=>null),a=await fetch(`${e}/api/startup-health`,{signal:r});if(!a.ok)throw Error(`fetch failed`);let o=await a.json();E.current=!0;let s=X(n);Z(n,{data:o,warning:s?.warning??null,fix:s?.fix??null,tray:s?.tray??null});let l=o.platform===`win32`?fetch(`${e}/api/windows-tray`,{signal:r}).then(async e=>{if(!e.ok)throw Error(`tray status failed`);let t=await e.json();if(!Id(t))throw Error(`invalid tray status`);return{tray:t,error:!1}}).catch(()=>({tray:null,error:!0})):Promise.resolve({tray:null,error:!1});return Promise.all([i,l]).then(([e,i])=>{if(r.aborted)return;let a=o.platform===`win32`?i.tray:null;if(o.platform===`win32`?(c(a),m(i.error)):(c(null),m(!1)),u(!1),T(!1),e){let r=qd(e.codexRuntime,t,o.platform);x(r.warning),C(r.fix),Z(n,{data:o,warning:r.warning,fix:r.fix,tray:a});return}let s=X(n);Z(n,{data:o,warning:s?.warning??null,fix:s?.fix??null,tray:a})}),o}catch(e){throw r.aborted?e:(i||(c(null),m(!0),x(null),C(null)),T(!1),u(!1),e)}},[e,n,t]),O=ss(i,[e],D,{isEmpty:()=>!1,initialData:r?.data??void 0}),k=O.state,A=O.refresh,j=k.data??r?.data??null,M=k.refreshing,N=!!j?.diagnosticStale||k.showError;(0,_.useEffect)(()=>{if(!j?.diagnosticStale)return;let e=window.setTimeout(A,2e3);return()=>window.clearTimeout(e)},[j,A]);let P=async e=>{try{await navigator.clipboard.writeText(e),o(e),window.setTimeout(()=>o(t=>t===e?null:t),1600)}catch{o(null)}},F=async t=>{f(!0),m(!1);try{let n=await fetch(`${e}/api/windows-tray`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:t})});if(!n.ok)throw Error(`tray action failed`);let r=await n.json();if(!Id(r.status))throw Error(`invalid tray action status`);c(r.status),m(!1)}catch{c(null),m(!0)}finally{f(!1)}},I=async(t,n)=>{g(t),y(null);try{let r=await fetch(`${e}/api/startup-action`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:t,repair:n?.repair===!0})});if(!r.ok){let e=await r.json().catch(()=>null);throw Error(typeof e?.error==`string`?e.error:`installation failed`)}y({kind:`success`,action:t,repair:n?.repair===!0}),A()}catch(e){y({kind:`error`,action:t,repair:n?.repair===!0,detail:e instanceof Error?e.message:String(e)})}finally{g(null)}};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`page-head`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{children:t(`startup.title`)}),(0,z.jsx)(`p`,{className:`page-sub startup-page-sub`,children:t(`startup.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`startup-page-head-actions`,children:[(0,z.jsx)(`a`,{className:`btn btn-ghost btn-sm`,href:`#dashboard`,children:t(`startup.backToDashboard`)}),(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>A(),disabled:M,children:[(0,z.jsx)(oe,{}),` `,t(`startup.refresh`)]})]})]}),k.showSkeleton&&!j?(0,z.jsx)(ls,{label:t(`startup.loading`),rows:5}):k.kind===`failed-cold`?(0,z.jsxs)(`div`,{className:`startup-page-notice`,children:[(0,z.jsx)(J,{tone:`err`,children:k.error instanceof Error?k.error.message:t(`startup.error`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>A(),children:t(`common.retry`)})]}):j?(0,z.jsxs)(z.Fragment,{children:[k.showError&&(0,z.jsx)(J,{tone:`err`,children:t(`startup.error`)}),N&&(0,z.jsx)(`div`,{className:`notice notice-warn startup-page-notice`,role:`alert`,children:t(`startup.staleData`)}),(w||b)&&(0,z.jsx)(`div`,{className:`startup-runtime-notice-slot${w&&!b?` startup-runtime-notice-slot--pending`:``}`,"aria-hidden":w&&!b?!0:void 0,children:b&&(0,z.jsxs)(`div`,{className:`notice notice-warn startup-page-notice startup-runtime-notice`,role:`status`,children:[(0,z.jsx)(`p`,{className:`startup-runtime-notice__text`,children:b}),S&&(0,z.jsxs)(`div`,{className:`startup-runtime-notice__fix`,children:[(0,z.jsx)(`code`,{children:S}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void P(S),children:t(a===S?`startup.copied`:`startup.copy`)})]})]})}),(0,z.jsx)(Vd,{failed:N,data:j}),(0,z.jsx)(Hd,{data:j,failed:N,loading:M,installBusy:h,installResult:v,onInstall:(e,t)=>{I(e,t)}}),j.platform===`win32`&&(0,z.jsx)(Ud,{tray:s,trayLoading:l,trayError:p,trayBusy:d,onTrayAction:e=>{F(e)}}),(0,z.jsx)(Wd,{data:j,copied:a,onCopy:e=>{P(e)}})]}):null]})}var Yd=class extends _.Component{state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}reload=()=>{this.setState({error:null})};render(){return this.state.error?(0,z.jsxs)(`section`,{className:`card`,role:`alert`,style:{maxWidth:720,padding:`var(--space-6)`},children:[(0,z.jsxs)(`h2`,{style:{margin:`0 0 var(--space-2)`,fontSize:`var(--text-title)`},children:[this.props.pageName,`: `,this.props.title]}),(0,z.jsx)(`p`,{className:`muted`,style:{margin:`0 0 var(--space-4)`},children:this.props.message}),(0,z.jsxs)(`p`,{style:{margin:`0 0 var(--space-5)`,overflowWrap:`anywhere`},children:[(0,z.jsxs)(`strong`,{children:[this.props.detailsLabel,`:`]}),` `,this.state.error.message]}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:this.reload,children:this.props.reloadLabel})]}):this.props.children}},Xd=5*6e4,Zd=10*6e4,Qd=`https://github.com/lidge-jun/opencodex`;async function $d(e,t){let n=await fetch(e,{signal:t});return n.ok?await n.json():null}function ef({apiBase:e,onOpenUpdate:t}){let n=q(),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(null),s=I(`sidebar-star:${e}`,[e],t=>$d(`${e}/api/github/star`,t),{pollMs:Xd}),c=I(`sidebar-update-badge:${e}`,[e],t=>$d(`${e}/api/update/badge`,t),{pollMs:Zd}),l=s.data?.state??null,u=a!==null&&a.basedOn===l?a.state:l??`not-starred`,d=s.data?.url??Qd,f=u===`starred`,p=c.data,m=p?.updateAvailable===!0,h=p?.latestVersion??null,g=()=>window.open(d,`_blank`,`noopener,noreferrer`),v=async()=>{if(!(f||r)){if(u===`unauthenticated`){g();return}i(!0);try{let t=await fetch(`${e}/api/github/star`,{method:`POST`}),n=t.ok?await t.json():null;if(n?.ok===!0){o({state:`starred`,basedOn:l});return}n?.state&&o({state:n.state,basedOn:l}),g()}catch{g()}finally{i(!1),s.refresh()}}},y=n(f?`sidebar.starred`:u===`unauthenticated`?`sidebar.starUnauthenticated`:`sidebar.star`),b=m&&h?n(`sidebar.updateAvailable`,{version:h}):n(`sidebar.checkUpdate`);return(0,z.jsxs)(`div`,{className:`sidebar-github-row`,children:[(0,z.jsxs)(`a`,{className:`sidebar-link sidebar-github-link`,href:d,target:`_blank`,rel:`noreferrer`,children:[(0,z.jsx)(_e,{}),` `,n(`common.github`)]}),(0,z.jsxs)(`div`,{className:`sidebar-github-actions`,children:[(0,z.jsx)(`button`,{type:`button`,className:`sidebar-orb${f?` sidebar-orb--starred`:``}`,onClick:()=>{v()},disabled:r||f,"aria-label":y,"aria-pressed":f,title:y,children:(0,z.jsx)(je,{"aria-hidden":`true`,...f?{fill:`currentColor`}:{}})}),(0,z.jsxs)(`button`,{type:`button`,className:`sidebar-orb${m?` sidebar-orb--update`:``}`,onClick:t,"aria-label":b,title:b,children:[(0,z.jsx)(he,{"aria-hidden":`true`}),m&&(0,z.jsx)(`span`,{className:`sidebar-orb-dot`,"aria-hidden":`true`})]})]})]})}var tf=!1,nf=null,rf=null,af=!1,of=`/`;function sf(e){try{let t=e instanceof Request?e.url:String(e),n=new URL(t,window.location.href);return n.origin===window.location.origin?n.pathname.startsWith(`/api/`):!1}catch{return!1}}var cf=`opencodex-api-token`,lf=null,uf=null,df=null;function ff(){return lf}function pf(e){lf=e}function mf(){lf=null,uf=null,df=null}function hf(e){let t=document.querySelector(`meta[name="${e}"]`),n=t?.content.trim()||null;return t?.remove(),n}function gf(){vf(hf(`opencodex-session-token`),hf(`opencodex-session-csrf`),hf(`opencodex-session-origin`))}function _f(e){e!=null&&ff()===e&&mf()}function vf(e,t,n){return!e?.startsWith(`ocx_session_`)||!t||n!==window.location.origin?!1:(lf=e,uf=t,df=n,!0)}function yf(e,t){for(let n of e.match(/<meta\b[^>]*>/gi)??[])if(n.match(/\bname="([^"]+)"/i)?.[1]===t)return n.match(/\bcontent="([^"]*)"/i)?.[1]?.trim()||null;return null}async function bf(){if(!rf)return null;try{let e=await rf(of,{cache:`no-store`});if(!e.ok)return null;let t=await e.text();return vf(yf(t,`opencodex-session-token`),yf(t,`opencodex-session-csrf`),yf(t,`opencodex-session-origin`))?ff():null}catch{return null}}function xf(){try{sessionStorage.removeItem(cf)}catch{}}function Sf(e,t,n){let r=new Headers(t?.headers??(e instanceof Request?e.headers:void 0));if(r.set(`X-OpenCodex-API-Key`,n),df&&uf&&n.startsWith(`ocx_session_`)){r.set(`X-OpenCodex-GUI-Origin`,df);let n=(t?.method??(e instanceof Request?e.method:`GET`)).toUpperCase();n!==`GET`&&n!==`HEAD`&&r.set(`X-OpenCodex-CSRF-Token`,uf)}return e instanceof Request?[new Request(e,{headers:r}),t?{...t,headers:r}:void 0]:[e,{...t,headers:r}]}async function Cf(e){return af?null:nf||(nf=(async()=>{if(af)return null;let t=ff();if(t&&t!==e)return t;let n=await bf();if(n)return n;let r=window.prompt(`OpenCodex admin token (OPENCODEX_ADMIN_AUTH_TOKEN)`)?.trim()||null;return r?(pf(r),r):(af=!0,null)})().finally(()=>{nf=null}),nf)}function wf(){if(tf)return;tf=!0,xf(),gf();let e=window.fetch.bind(window);rf=e,window.fetch=async(t,n)=>{if(!sf(t))return e(t,n);let r=ff(),[i,a]=r?Sf(t,n,r):[t,n],o=await e(i,a);if(o.status!==401)return o;let s=ff();if(s&&s!==r){let[r,i]=Sf(t,n,s),a=await e(r,i);if(a.status!==401)return a;_f(s)}else _f(r);let c=await Cf(r);if(!c)return o;let[l,u]=Sf(t,n,c),d=await e(l,u);return d.status===401&&_f(c),d}}var Tf=new Set([`dashboard`,`startup`,`providers`,`models`,`combos`,`subagents`,`logs`,`usage`,`storage`,`codex-auth`,`api`,`claude`,`grok`]);function Ef(e){let t=Ue(e??(typeof window<`u`?window.location.hash:``)).split(`/`)[0];return t===`debug`?`logs`:Tf.has(t)?t:`dashboard`}var Df=[`dashboard/providers`,`dashboard/models`];function Of(e,t){return e===t||t===`logs`&&e===`logs/debug`||t===`dashboard`&&(e===`dashboard/update`||Df.includes(e))}function kf(e){let t=Ef(e);return e===`debug`||e.startsWith(`debug/`)?{page:`logs`,replaceTo:`logs/debug`}:e===`providers/workspace`?{page:`providers`,replaceTo:`providers`}:Of(e,t)?{page:t,replaceTo:null}:{page:t,replaceTo:t}}var Af=[`ocx-global-view`,`ocx-view`,`ocx-providers-view`,`ocx-subagents-view`,`ocx-storage-view`,`ocx-codexauth-view`,`ocx-apikeys-view`,`ocx-claudecode-view`,`ocx-usage-view`,`ocx-logs-view`,`ocx-models-view`,`ocx-dashboard-view`];function jf(){try{for(let e of Af)localStorage.removeItem(e)}catch{}}function Mf(){let[e,t]=(0,_.useState)(Ef);(0,_.useEffect)(()=>{jf()},[]);let n=(0,_.useCallback)(e=>{let n=kf(e);n.replaceTo&&We(n.replaceTo),t(n.page)},[]);return(0,_.useEffect)(()=>{let e=()=>{n(Ue(window.location.hash))};return window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[n]),(0,_.useEffect)(()=>{let t=Ue(window.location.hash);if(t===`debug`||t.startsWith(`debug/`)){We(`logs/debug`);return}if(t===`providers/workspace`){We(`providers`);return}Of(t,e)||We(e)},[e]),{page:e,setPageState:t,navigateToPage:(e,n)=>{Ge(n?`${e}/${n}`:e),t(e)}}}var Nf=15e3;function Pf(e,t,n){return typeof e?.message==`string`&&e.message.trim()?e.message:typeof e?.error==`string`&&e.error.trim()?e.error:n(t)}function Ff(e){return(e instanceof DOMException||e instanceof Error)&&e.name===`AbortError`}async function If(e,t={}){let{fetchFn:n=fetch,timeoutMs:r=Nf,formatFailure:i=e=>`Failed to stop proxy (HTTP ${e}).`}=t,a;try{a=await n(`${e}/api/stop`,{method:`POST`,signal:AbortSignal.timeout(r)})}catch(e){return Ff(e),{accepted:!0}}let o=await a.json().catch(()=>null);return!a.ok||o?.success===!1?{accepted:!1,message:Pf(o,a.status,i)}:{accepted:!0}}wf();var Lf={dashboard:`nav.dashboard`,startup:`nav.startup`,providers:`nav.providers`,models:`nav.models`,combos:`nav.combos`,subagents:`nav.subagents`,logs:`nav.logs`,usage:`nav.usage`,storage:`nav.storage`,"codex-auth":`nav.codexAuth`,api:`nav.api`,claude:`nav.claude`,grok:`nav.grok`},Rf=``,zf=`ocx-theme`,Bf=[{id:`dashboard`,tkey:`nav.dashboard`,Icon:V},{id:`codex-auth`,tkey:`nav.codexAuth`,Icon:be},{id:`providers`,tkey:`nav.providers`,Icon:H},{id:`models`,tkey:`nav.models`,Icon:U},{id:`subagents`,tkey:`nav.subagents`,Icon:W},{id:`logs`,tkey:`nav.logs`,Icon:G},{id:`usage`,tkey:`nav.usage`,Icon:ne},{id:`storage`,tkey:`nav.storage`,Icon:K},{id:`api`,tkey:`nav.api`,Icon:De},{id:`claude`,tkey:`nav.claude`,Icon:Oe},{id:`grok`,tkey:`nav.grok`,Icon:U}],Vf={light:we,dark:Te,system:Ee},Hf={light:`theme.light`,dark:`theme.dark`,system:`theme.system`};function Uf(e){if(!e||typeof e!=`object`||!(`version`in e))return null;let t=e.version;return typeof t==`string`&&t.length>0?t:null}function Wf(){let e=localStorage.getItem(zf);return e===`light`||e===`dark`?e:`system`}function Gf(){let{page:e,navigateToPage:t}=Mf(),[n,r]=(0,_.useState)(Wf),{locale:i,setLocale:a}=Be(),o=q(),[s,c]=(0,_.useState)(!1),l=(0,_.useRef)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(!1);(0,_.useEffect)(()=>{let e=()=>c(!1);return window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[]),(0,_.useEffect)(()=>{let e=document.documentElement;n===`system`?(e.removeAttribute(`data-theme`),localStorage.removeItem(zf)):(e.setAttribute(`data-theme`,n),localStorage.setItem(zf,n))},[n]);let f=I(`app-healthz:${Rf}`,[],async e=>{let t=await fetch(`${Rf}/healthz`,{signal:e});return t.ok?Uf(await t.json()):null},{pollMs:3e4}),p=()=>r(e=>e===`light`?`dark`:e===`dark`?`system`:`light`),m=Vf[n],h=f.data??`2.9.0`,[g,v]=(0,_.useState)(!1),y=(0,_.useCallback)(async e=>{let t=await lt(await fetch(`${Rf}/api/claude-code`,{signal:e}));return t&&typeof t.enabled==`boolean`?t.enabled:null},[]),b=I(`app-claude-code:${Rf}`,[],y).data??null,x=(0,_.useRef)(!1),[S,C]=(0,_.useState)(!1);(0,_.useEffect)(()=>{if(!s)return;let e=e=>{e.key===`Escape`&&c(!1)};window.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{window.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[s]),(0,_.useEffect)(()=>{if(s){d.current=!0;let e=setTimeout(()=>u.current?.focus(),200);return()=>clearTimeout(e)}d.current&&(d.current=!1,l.current?.focus())},[s]),(0,_.useEffect)(()=>{let e=window.matchMedia(`(min-width: 761px)`),t=()=>{e.matches&&c(!1)};return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let w=async()=>{if(b===null||x.current)return;x.current=!0,C(!0);let e=!b;L(`app-claude-code:${Rf}`,e);try{(await fetch(`${Rf}/api/claude-code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:e})})).ok||L(`app-claude-code:${Rf}`,!e)}catch{L(`app-claude-code:${Rf}`,!e)}finally{x.current=!1,C(!1)}},T=async()=>{if(!confirm(o(`dash.stopConfirm`)))return;v(!0);let e=await If(Rf,{formatFailure:e=>o(`dash.stopFailed`,{status:String(e)})});e.accepted||(v(!1),alert(e.message))},E=(0,z.jsxs)(`div`,{className:`brand`,children:[(0,z.jsx)(`span`,{className:`brand-logo`,role:`img`,"aria-label":o(`app.logoAria`)}),(0,z.jsx)(`span`,{className:`name`,children:`opencodex`}),(0,z.jsxs)(`span`,{className:`ver`,children:[`v`,h]})]});return(0,z.jsxs)(`div`,{className:`app`,children:[(0,z.jsxs)(`header`,{className:`mobile-topbar`,inert:s,children:[(0,z.jsx)(`button`,{ref:l,type:`button`,className:`menu-toggle`,onClick:()=>c(e=>!e),"aria-expanded":s,"aria-controls":`app-sidebar`,"aria-label":o(s?`nav.closeMenu`:`nav.openMenu`),title:o(s?`nav.closeMenu`:`nav.openMenu`),children:(0,z.jsx)(ee,{})}),E,(0,z.jsx)(`button`,{type:`button`,className:`theme-toggle stop-toggle`,onClick:T,disabled:g,"aria-label":o(`dash.stop`),title:o(`dash.stop`),children:(0,z.jsx)(ve,{})})]}),s&&(0,z.jsx)(`div`,{className:`drawer-scrim`,onClick:()=>c(!1),"aria-hidden":`true`}),(0,z.jsxs)(`aside`,{id:`app-sidebar`,className:`sidebar${s?` open`:``}`,ref:u,tabIndex:-1,children:[(0,z.jsxs)(`div`,{className:`drawer-head`,children:[E,(0,z.jsx)(`button`,{type:`button`,className:`menu-toggle drawer-close`,onClick:()=>c(!1),"aria-label":o(`nav.closeMenu`),title:o(`nav.closeMenu`),children:(0,z.jsx)(ie,{})})]}),(0,z.jsx)(`nav`,{children:Bf.map(({id:n,tkey:r,Icon:i})=>(0,z.jsxs)(`div`,{className:`nav-entry${n===`claude`?` nav-entry-claude${e===n?` active`:``}`:``}`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`nav-item${e===n?` active`:``}`,"data-page":n,onClick:()=>{t(n),c(!1)},"aria-current":e===n?`page`:void 0,children:[(0,z.jsx)(i,{}),` `,o(r)]}),n===`claude`&&b!==null&&(0,z.jsx)(rt,{on:b,onClick:()=>void w(),disabled:S,label:o(`claude.toggleAria`)})]},n))}),(0,z.jsxs)(`div`,{className:`sidebar-foot`,children:[(0,z.jsxs)(`div`,{className:`lang-toggle`,children:[(0,z.jsx)(De,{"aria-hidden":!0}),(0,z.jsx)(it,{value:i,options:Fe.map(e=>({value:e.code,label:e.name})),onChange:e=>a(e),label:o(`lang.label`),placement:`right`,portal:!1,style:{flex:1,minWidth:0,width:`100%`}})]}),(0,z.jsxs)(`button`,{type:`button`,className:`theme-toggle`,onClick:p,"aria-label":`${o(`theme.label`)}: ${o(Hf[n])}`,title:`${o(`theme.label`)}: ${o(Hf[n])}`,children:[(0,z.jsx)(m,{}),` `,(0,z.jsx)(`span`,{className:`mode`,children:o(Hf[n])})]}),(0,z.jsxs)(`button`,{type:`button`,className:`theme-toggle stop-toggle`,onClick:T,disabled:g,"aria-label":o(`dash.stop`),title:o(`dash.stop`),children:[(0,z.jsx)(ve,{}),` `,(0,z.jsx)(`span`,{className:`mode`,children:o(g?`dash.stopping`:`dash.stop`)})]}),(0,z.jsx)(ef,{apiBase:Rf,onOpenUpdate:()=>{c(!1),t(`dashboard`,`update`)}})]})]}),(0,z.jsx)(`main`,{className:`main`,inert:s,children:(0,z.jsx)(`div`,{className:`main-inner${e===`combos`?` main-inner--combos`:``}`,children:(0,z.jsxs)(Yd,{pageName:o(Lf[e]),title:o(`errorBoundary.title`),message:o(`errorBoundary.message`),detailsLabel:o(`errorBoundary.details`),reloadLabel:o(`errorBoundary.reload`),children:[e===`dashboard`&&(0,z.jsx)(Pn,{apiBase:Rf}),e===`startup`&&(0,z.jsx)(Jd,{apiBase:Rf}),e===`providers`&&(0,z.jsx)(jo,{apiBase:Rf}),e===`models`&&(0,z.jsx)(Ls,{apiBase:Rf}),e===`combos`&&(0,z.jsx)(tc,{apiBase:Rf},Rf),e===`subagents`&&(0,z.jsx)(dc,{apiBase:Rf},Rf),e===`logs`&&(0,z.jsx)(Al,{apiBase:Rf}),e===`usage`&&(0,z.jsx)(Ql,{apiBase:Rf}),e===`storage`&&(0,z.jsx)(hu,{apiBase:Rf}),e===`codex-auth`&&(0,z.jsx)(yu,{apiBase:Rf}),e===`api`&&(0,z.jsx)(Gu,{apiBase:Rf}),e===`claude`&&(0,z.jsx)(kd,{apiBase:Rf}),e===`grok`&&(0,z.jsx)(Fd,{apiBase:Rf})]},e)})})]})}g.createRoot(document.getElementById(`root`)).render((0,z.jsx)(_.StrictMode,{children:(0,z.jsx)(Ve,{children:(0,z.jsx)(Gf,{})})}));
|
|
67
|
+
`)}function Xu(e){return e?e.backend??`auto`:`inherit`}function Zu(e,t){if(t!==`inherit`)return t===`auto`?{...e,backend:void 0}:{...e,backend:t}}function Qu(e,t){return{...e,model:t}}function $u(e){if(!e)return null;let t=(e.model??``).trim();return e.backend?{backend:e.backend,model:t}:t?{backend:null,model:t}:null}function ed({label:e,checked:t,onChange:n,disabled:r=!1,describedBy:i}){return(0,z.jsxs)(`label`,{className:`toggle`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:t,disabled:r,"aria-label":e,"aria-describedby":i,onChange:e=>n(e.target.checked)}),(0,z.jsx)(`span`,{className:`slider`,"aria-hidden":`true`})]})}function td({supported:e,checked:t,onChange:n}){let r=q(),i=e?void 0:`claude-system-env-unsupported`;return(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:r(`claude.systemEnv`)}),e?(0,z.jsx)(`span`,{className:`desc`,children:r(`claude.systemEnvDesc`)}):(0,z.jsx)(`span`,{className:`desc`,id:i,children:(0,z.jsx)(He,{k:`claude.systemEnvUnsupported`,cmd:`ocx claude`})}),e&&t&&(0,z.jsx)(`span`,{className:`desc`,style:{color:`var(--red)`},children:r(`claude.systemEnvWarn`)})]}),(0,z.jsx)(ed,{label:r(`claude.systemEnv`),checked:e&&t,disabled:!e,describedBy:i,onChange:n})]})}function nd({value:e,tierHaikuModel:t,options:n,onChange:r}){let i=q(),a=t??e;return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:i(`claude.smallFastModelAccurateHint`)}),(0,z.jsx)(it,{value:e,options:n,onChange:r,label:i(`claude.smallFastModel`),style:{maxWidth:420}}),a===``&&(0,z.jsx)(`p`,{className:`notice-warn`,role:`status`,style:{marginTop:8},children:i(`claude.smallFastModelNativeWarning`)})]})}function rd(){if(typeof crypto<`u`&&typeof crypto.randomUUID==`function`)try{return crypto.randomUUID()}catch{}let e=new Uint8Array(16);if(typeof crypto<`u`&&typeof crypto.getRandomValues==`function`)crypto.getRandomValues(e);else for(let t=0;t<16;t++)e[t]=Math.floor(Math.random()*256);e[6]=e[6]&15|64,e[8]=e[8]&63|128;let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}function id(e,t=`en`){if(e>=1e6){let n=e/1e6,r=n.toFixed(1).replace(/\.0$/,``);return Number.isInteger(n)||Number(r)*1e6===e?new Intl.NumberFormat(t,{notation:`compact`,compactDisplay:`short`,maximumFractionDigits:+!Number.isInteger(n)}).format(e):`${Math.round(e/1e3)}k`}return`${Math.round(e/1e3)}k`}function ad(e,t){return e&&[`claude-json-oauth`,`claude-credentials-file`,`macos-keychain`,`exported-env`].includes(e)?t(`claude.authSource.${e}`):t(`claude.authSource.unknown`)}function od({state:e,autoCompactOptions:t,availableModels:n,onStateChange:r}){let i=q();return(0,z.jsxs)(`div`,{className:`card`,style:{overflow:`hidden`},children:[(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.enabledLabel`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.enabledHint`)})]}),(0,z.jsx)(ed,{label:i(`claude.enabledLabel`),checked:e.enabled,onChange:t=>r({...e,enabled:t})})]}),(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.authMode`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.authModeHint`)})]}),(0,z.jsx)(`div`,{className:`setting-controls`,children:(0,z.jsx)(it,{value:e.authMode,options:[{value:`auto`,label:i(`claude.authModeAuto`)},{value:`subscription`,label:i(`claude.authModeSubscription`)},{value:`proxy`,label:i(`claude.authModeProxy`)}],onChange:t=>r({...e,authMode:t}),label:i(`claude.authMode`),style:{minWidth:220},align:`right`,portal:!0})})]}),e.authModeOrigin&&(0,z.jsxs)(`div`,{className:`claude-effective-auth${e.authModeOrigin===`auto-unknown`?` warn`:``}`,role:`status`,children:[(0,z.jsx)(`span`,{className:`claude-effective-auth-label`,children:i(`claude.effectiveMode.label`)}),(0,z.jsxs)(`span`,{children:[e.authModeOrigin===`manual`?i(`claude.effectiveMode.manual`,{mode:e.markerMode===`proxy`?i(`claude.authModeProxy`):i(`claude.authModeSubscription`)}):e.authModeOrigin===`auto-present`?i(`claude.effectiveMode.autoPresent`,{source:ad(e.authFoundBy,i)}):e.authModeOrigin===`auto-absent`?i(`claude.effectiveMode.autoAbsent`):i(`claude.effectiveMode.autoUnknown`),e.admissionKeyActive===!0?` ${i(`claude.effectiveMode.admissionKey`)}`:``]})]}),(0,z.jsx)(td,{supported:e.autoConnectSupported,checked:e.systemEnv,onChange:t=>r({...e,systemEnv:t})}),(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.fastMode`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.fastModeDesc`)})]}),(0,z.jsx)(`div`,{className:`setting-controls`,children:(0,z.jsx)(it,{value:e.fastMode===null?`auto`:e.fastMode?`on`:`off`,options:[{value:`auto`,label:i(`claude.fastAuto`)},{value:`on`,label:i(`claude.fastOn`)},{value:`off`,label:i(`claude.fastOff`)}],onChange:t=>r({...e,fastMode:t===`auto`?null:t===`on`}),label:i(`claude.fastMode`),style:{minWidth:140},align:`right`,portal:!0})})]}),(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.autoContext`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.autoContextDesc`)}),e.maxContextTokens!==null&&(0,z.jsx)(`span`,{className:`desc`,style:{color:`var(--muted)`},children:i(`claude.autoContextInert`)})]}),(0,z.jsx)(ed,{label:i(`claude.autoContext`),checked:e.autoContext,onChange:t=>r({...e,autoContext:t})})]}),e.autoContext&&(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.autoCompactWindow`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.autoCompactWindowDesc`)}),e.autoCompactWindow!==null&&(0,z.jsx)(`span`,{className:`desc`,style:{color:`var(--red)`},children:i(`claude.autoCompactWindowWarn`)})]}),(0,z.jsx)(`div`,{className:`setting-controls`,children:(0,z.jsx)(it,{value:e.autoCompactWindow===null?``:String(e.autoCompactWindow),options:t,onChange:t=>r({...e,autoCompactWindow:t===``?null:Number(t)}),label:i(`claude.autoCompactWindow`),style:{minWidth:130},align:`right`,portal:!0})})]}),(0,z.jsxs)(`div`,{className:`setting-row`,children:[(0,z.jsxs)(`div`,{className:`setting-label`,children:[(0,z.jsx)(`span`,{className:`title`,children:i(`claude.injectAgents`)}),(0,z.jsx)(`span`,{className:`desc`,children:i(`claude.injectAgentsDesc`)})]}),(0,z.jsx)(ed,{label:i(`claude.injectAgents`),checked:e.injectAgents,onChange:t=>r({...e,injectAgents:t})})]}),[`webSearchSidecar`,`visionSidecar`].map(t=>{let a=e[t],o=t===`webSearchSidecar`?`claude.webSearchSidecar`:`claude.visionSidecar`,s=t===`webSearchSidecar`?`claude.webSearchSidecarHint`:`claude.visionSidecarHint`,c=`claude-sidecar-models-${t}`;return(0,z.jsxs)(`div`,{className:`setting-row`,style:{alignItems:`flex-start`},children:[(0,z.jsxs)(`div`,{className:`setting-label setting-copy`,style:{flex:1},children:[(0,z.jsx)(`span`,{className:`title`,children:i(o)}),(0,z.jsx)(`span`,{className:`desc`,children:i(s)})]}),(0,z.jsxs)(`div`,{className:`setting-controls`,style:{display:`flex`,gap:8},children:[(0,z.jsx)(it,{value:Xu(a),options:[{value:`inherit`,label:i(`claude.useMainSetting`)},{value:`auto`,label:i(`dash.backendAuto`)},{value:`openai`,label:i(`dash.backendOpenAI`)},{value:`anthropic`,label:i(`dash.backendAnthropic`)}],onChange:n=>{r({...e,[t]:Zu(a,n)})},label:i(`dash.sidecarBackend`),portal:!0}),(0,z.jsx)(`input`,{className:`input mono`,value:a?.model??``,onChange:n=>{r({...e,[t]:Qu(a,n.target.value)})},placeholder:i(`claude.sidecarModelPlaceholder`),disabled:!a,list:a?c:void 0,"aria-label":i(`dash.sidecarModel`),style:{minWidth:210},autoComplete:`off`}),a&&(0,z.jsx)(`datalist`,{id:c,children:n.map(e=>(0,z.jsx)(`option`,{value:e},e))})]})]},t)})]})}function sd({manualEnv:e}){let t=q();return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:(0,z.jsx)(He,{k:`claude.quickstartHint`,cmd:`ocx claude`})}),(0,z.jsx)(`pre`,{className:`mono card`,style:{padding:`10px 14px`,overflowX:`auto`,margin:0},children:`ocx claude`}),(0,z.jsxs)(`details`,{style:{margin:`10px 0 0`},children:[(0,z.jsx)(`summary`,{className:`muted text-label`,style:{cursor:`pointer`,padding:`2px 2px`},children:t(`claude.manualEnv`)}),(0,z.jsx)(`pre`,{className:`mono card text-label`,style:{padding:`10px 14px`,overflowX:`auto`,margin:`6px 0 0`},children:e})]})]})}function cd({rows:e,onRowsChange:t}){let n=q();return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`p`,{className:`muted text-label`,style:{margin:`0 0 8px`},children:n(`claude.modelMapHint`)}),(0,z.jsx)(`div`,{className:`stack`,style:{gap:8},children:e.map((r,i)=>(0,z.jsxs)(`div`,{className:`row`,style:{gap:8},children:[(0,z.jsx)(`input`,{className:`input mono`,value:r.from,placeholder:n(`claude.mapFrom`),"aria-label":n(`claude.mapFrom`),onChange:n=>t(e.map((e,t)=>t===i?{...e,from:n.target.value}:e)),style:{flex:1}}),(0,z.jsx)(`span`,{className:`muted`,"aria-hidden":!0,children:`→`}),(0,z.jsx)(`input`,{className:`input mono`,value:r.to,placeholder:n(`claude.mapTo`),"aria-label":n(`claude.mapTo`),onChange:n=>t(e.map((e,t)=>t===i?{...e,to:n.target.value}:e)),style:{flex:1}}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-icon btn-sm`,onClick:()=>t(e.filter((e,t)=>t!==i)),"aria-label":n(`claude.removeMapping`),style:{color:`var(--red)`},children:(0,z.jsx)(ie,{})})]},r.id))}),(0,z.jsx)(`div`,{style:{marginTop:8},children:(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>t([...e,{id:rd(),from:``,to:``}]),children:[(0,z.jsx)(ae,{}),` `,n(`claude.addMapping`)]})})]})}var ld=`etc`;function ud(e){let t=new Map;for(let n of e){let e=/\(([^)]+)\)\s*$/.exec(n.display_name),r=e?e[1]:ld,i=t.get(r);i?i.push(n):t.set(r,[n])}return Array.from(t)}function dd({aliases:e}){let t=q();return(0,z.jsxs)(`div`,{className:`claude-aliases`,children:[(0,z.jsx)(`p`,{className:`muted text-label claude-aliases-hint`,children:t(`claude.aliasesHint`)}),e.length===0?(0,z.jsx)(`div`,{className:`muted text-label`,children:t(`claude.none`)}):(0,z.jsx)(`div`,{className:`claude-aliases-scroll`,children:ud(e).map(([e,n])=>(0,z.jsxs)(`div`,{className:`claude-aliases-group`,children:[(0,z.jsxs)(`div`,{className:`claude-aliases-group-label`,children:[e===ld?t(`claude.aliasProviderOther`):e,(0,z.jsx)(`span`,{className:`claude-aliases-group-count`,children:n.length})]}),(0,z.jsx)(`div`,{className:`claude-aliases-chips`,children:n.map(e=>(0,z.jsxs)(`span`,{className:`claude-aliases-chip`,children:[(0,z.jsx)(`code`,{className:`claude-aliases-chip-id`,children:e.id}),e.display_name?(0,z.jsx)(`span`,{className:`claude-aliases-chip-name`,children:e.display_name}):null]},e.id))})]},e))})]})}function fd({apiBase:e,active:t=!0}){let n=q(),{locale:r}=Be(),i=Fe.find(e=>e.code===r)?.htmlLang??`en`,a=`ocx.claude-code.v1:${e}`,o=`claude-code:${e}`,s=(0,_.useMemo)(()=>X(a),[a]),[c,l]=(0,_.useState)(()=>s?.state??null),[u,d]=(0,_.useState)(()=>s?.rows??[]),[f,p]=(0,_.useState)(!!s),[m,h]=(0,_.useState)(``),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(`settings`),x=(0,_.useCallback)(async t=>{let r=await Y(await fetch(`${e}/api/claude-code`,{signal:t}),n(`claude.loadFail`));if(!r)throw Error(n(`claude.loadFail`));let i={...r,authMode:r.authMode===`proxy`||r.authMode===`subscription`?r.authMode:`auto`,...qu(r),fastMode:r.fastMode??null,maxContextTokens:r.maxContextTokens??null,autoContext:r.autoContext!==!1,autoCompactWindow:r.autoCompactWindow??null,injectAgents:r.injectAgents!==!1,effectiveModelEnv:r.effectiveModelEnv??{}},o=Object.entries(r.modelMap??{}).map(([e,t])=>({id:rd(),from:e,to:String(t)})),s={state:i,rows:o};if(t.aborted)throw Error(`Claude Code request aborted`);return l(i),d(o),p(!0),Z(a,s),s},[e,a,n]),S=ss(o,[e],x,{isEmpty:()=>!1,enabled:t,initialData:s??void 0}),C=S.state,w=C.data??s,T=c??w?.state??null,E=f?u:w?.rows??u,D=(0,_.useMemo)(()=>Ku(T?.available,n(`claude.smallFastModelUnsetOption`)),[T?.available,n]),O=(0,_.useMemo)(()=>{let e=[1e5,2e5,25e4,3e5,35e4,4e5,5e5,6e5,75e4,9e5,1e6],t=T?.autoCompactWindow??null,r=t!==null&&!e.includes(t)?[...e,t].sort((e,t)=>e-t):e;return[{value:``,label:n(`claude.autoCompactDefault`)},...r.map(e=>({value:String(e),label:id(e,i)}))]},[T?.autoCompactWindow,n,i]),k=async()=>{if(!T)return;h(``);let t={};for(let e of E)e.from.trim()&&e.to.trim()&&(t[e.from.trim()]=e.to.trim());try{await Y(await fetch(`${e}/api/claude-code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:T.enabled,authMode:T.authMode,systemEnv:T.systemEnv,fastMode:T.fastMode,autoContext:T.autoContext,autoCompactWindow:T.autoCompactWindow,injectAgents:T.injectAgents,smallFastModel:T.smallFastModel,modelMap:t,webSearchSidecar:$u(T.webSearchSidecar),visionSidecar:$u(T.visionSidecar)})}),n(`claude.saveFailed`)),v(!0),h(n(`claude.saved`)),S.refresh()}catch(e){v(!1),h(e instanceof Error&&e.message?e.message:n(`claude.networkError`))}};if(C.kind===`disabled`&&!w)return null;if(C.showSkeleton&&!w)return(0,z.jsx)(ls,{label:n(`claude.loading`),rows:3});if(C.kind===`failed-cold`)return(0,z.jsxs)(`div`,{className:`claudecode-workspace-shell`,children:[(0,z.jsx)(J,{tone:`err`,children:C.error instanceof Error?C.error.message:n(`claude.loadFail`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>S.refresh(),children:n(`common.retry`)})]});if(!T)return null;let A=[{id:`settings`,label:n(`claude.workspace.settings`),body:(0,z.jsx)(od,{state:T,autoCompactOptions:O,availableModels:T.available??[],onStateChange:l})},{id:`quickstart`,label:n(`claude.quickstart`),body:(0,z.jsx)(sd,{manualEnv:Yu(T)})},{id:`smallFast`,label:n(`claude.smallFastModel`),body:(0,z.jsx)(nd,{value:T.smallFastModel,tierHaikuModel:T.tierModels?.haiku,options:D,onChange:e=>l({...T,smallFastModel:e})})},{id:`modelMap`,label:n(`claude.modelMap`),meta:String(E.length),body:(0,z.jsx)(cd,{rows:E,onRowsChange:e=>{p(!0),d(e)}})},{id:`aliases`,label:n(`claude.aliases`),meta:String(T.aliases.length),body:(0,z.jsx)(dd,{aliases:T.aliases})}],j=A.find(e=>e.id===y)??A[0],M=y===`settings`||y===`smallFast`||y===`modelMap`;return(0,z.jsxs)(`div`,{className:`claudecode-workspace-shell`,children:[m&&(0,z.jsx)(J,{tone:g?`ok`:`err`,children:m}),C.showError&&(0,z.jsx)(J,{tone:`err`,children:n(`claude.loadFail`)}),(0,z.jsxs)(`div`,{className:`claudecode-workspace-root`,children:[(0,z.jsx)(`aside`,{className:`claudecode-workspace-rail`,"aria-label":n(`claude.pageTitle`),children:(0,z.jsx)(`div`,{className:`claudecode-workspace-rail-list`,children:A.map(e=>(0,z.jsx)(`button`,{type:`button`,className:`claudecode-workspace-rail-row${y===e.id?` claudecode-workspace-rail-row--selected`:``}`,onClick:()=>b(e.id),"aria-current":y===e.id?`true`:void 0,children:(0,z.jsx)(`span`,{className:`claudecode-workspace-rail-name`,children:e.label})},e.id))})}),(0,z.jsxs)(`section`,{className:`claudecode-workspace-main`,"aria-label":j.label,children:[(0,z.jsxs)(`div`,{className:`ccw-main-head`,children:[(0,z.jsxs)(`h3`,{className:`ccw-main-title`,children:[j.label,j.meta==null?null:(0,z.jsx)(`span`,{className:`count`,children:j.meta})]}),(0,z.jsx)(`div`,{className:`claudecode-workspace-save`,"data-visible":M?`true`:`false`,children:(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,disabled:!M,tabIndex:M?0:-1,"aria-hidden":!M,onClick:()=>{k()},children:n(`common.save`)})})]}),(0,z.jsx)(`div`,{className:`ccw-body`,children:j.body})]})]})]})}function pd(e,t,n){let r=t.trim().toLowerCase(),i=(r?e.filter(e=>e.label.toLowerCase().includes(r)||e.route.toLowerCase().includes(r)):e).toSorted((e,t)=>Number(!e.available)-Number(!t.available)),a=i.slice(0,n);return{total:e.length,showSearch:e.length>4,shown:a,hidden:i.length-a.length,noMatch:e.length>0&&i.length===0}}function md(e){return new Set(Object.keys(e))}function hd(e,t){return t!==null&&e===t}function gd(e){return e||(typeof localStorage>`u`?void 0:localStorage)}function _d(e){return{read(t){let n=gd(t);if(!n)return null;try{let t=n.getItem(e);if(t===null)return null;let r=JSON.parse(t);return Array.isArray(r)?new Set(r.filter(e=>typeof e==`string`)):null}catch{return null}},write(t,n){let r=gd(n);if(r)try{r.setItem(e,JSON.stringify([...t]))}catch{}}}}function vd(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}var $=[`opus`,`fable`,`sonnet`,`haiku`],yd=_d(`ocx.claudeDesktop.collapsedFamilies.v2`),bd={opus:`claudeDesktop.family.opus`,fable:`claudeDesktop.family.fable`,sonnet:`claudeDesktop.family.sonnet`,haiku:`claudeDesktop.family.haiku`};function xd(e){return{version:1,assignments:Object.fromEntries(Object.entries(e.assignments).map(([e,t])=>[e,{...t}])),defaults:{...e.defaults},...e.appliedFingerprint===void 0?{}:{appliedFingerprint:e.appliedFingerprint},...e.appliedAt===void 0?{}:{appliedAt:e.appliedAt}}}function Sd(e){let t={...e.profile.assignments};for(let n of e.models){let e=t[n.route]??n.assignment;t[n.route]={family:$.includes(e?.family)?e.family:`opus`,alias:typeof e?.alias==`string`?e.alias:``}}return{version:1,assignments:t,defaults:{opus:e.profile.defaults.opus??null,fable:e.profile.defaults.fable??null,sonnet:e.profile.defaults.sonnet??null,haiku:e.profile.defaults.haiku??null}}}function Cd(e,t){return e&&typeof e==`object`&&`error`in e&&typeof e.error==`string`?e.error:t}function wd(e,t){return e?e>=1048576?t(`claudeDesktop.contextM`,{n:Math.round(e/1048576)}):e>=1e6?t(`claudeDesktop.contextM`,{n:e/1e6}):t(`claudeDesktop.contextK`,{n:Math.round(e/1e3)}):null}function Td(e){return X(e)}function Ed(e){let t=Td(e);return{held:t,data:t?.data??null,profile:t?.profile??null,savedProfile:t?.profile?xd(t.profile):null,destinations:t?.data?Object.fromEntries(t.data.models.map(e=>[e.route,t.profile.assignments[e.route]?.family??`opus`])):{}}}function Dd({apiBase:e,active:t=!0,onPortChange:n}){let{t:r,locale:i}=Be(),a=Fe.find(e=>e.code===i)?.htmlLang,o=`ocx.claude-desktop.v1:${e}`,s=`claude-desktop:${e}`,c=(0,_.useMemo)(()=>Ed(o),[o]),[l,u]=(0,_.useState)(()=>c.profile),[d,f]=(0,_.useState)(()=>c.savedProfile),[p,m]=(0,_.useState)(()=>c.destinations),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(``),[b,x]=(0,_.useState)(null),[S,C]=(0,_.useState)({}),[w,T]=(0,_.useState)({}),[E,D]=(0,_.useState)(()=>yd.read()??new Set($)),[O,k]=(0,_.useState)({}),A=(0,_.useRef)(null),j=(0,_.useCallback)(async t=>{let n=await Y(await fetch(`${e}/api/claude-desktop`,{signal:t}),r(`claudeDesktop.loadFail`));if(!n||!(`profile`in n)||!(`models`in n))throw Error(Cd(n,r(`claudeDesktop.loadFail`)));let i=Sd(n),a={data:n,profile:i};if(t.aborted)throw Error(`Claude Desktop request aborted`);if(u(i),f(xd(i)),m(Object.fromEntries(n.models.map(e=>[e.route,i.assignments[e.route]?.family??`opus`]))),yd.read()===null){let e=Object.fromEntries($.map(e=>[e,0]));for(let t of n.models)e[i.assignments[t.route]?.family??`opus`]+=1;D(md(e))}return Z(o,a),a},[e,o,r,m,u,f]),M=ss(s,[e],j,{isEmpty:()=>!1,enabled:t,initialData:c.held??void 0}),N=M.state,P=N.data??(c.data&&c.profile?{data:c.data,profile:c.profile}:null),F=P?.data??null,I=l??P?.profile??null,L=d??P?.profile??null,R=P?Object.fromEntries(P.data.models.map(e=>[e.route,P.profile.assignments[e.route]?.family??`opus`])):{},B=Object.keys(p).length>0?p:R;(0,_.useEffect)(()=>{if(n){if(typeof F?.port==`number`){n(F.port);return}N.kind===`failed-cold`&&n(null)}},[F?.port,N.kind,n]);let V=(0,_.useMemo)(()=>I!==null&&L!==null&&JSON.stringify(I)!==JSON.stringify(L),[I,L]),H=(0,_.useMemo)(()=>{let e=Object.fromEntries($.map(e=>[e,[]]));if(!F||!I)return e;for(let t of F.models)e[I.assignments[t.route]?.family??`opus`].push(t);return e},[F,I]),U=(0,_.useMemo)(()=>{let e={};for(let t of $){let n=H[t].filter(e=>e.available).map(e=>e.route).sort(),r=I?.defaults[t]??null;e[t]=r&&n.includes(r)?r:n[0]??null}return e},[H,I]),W=`ocx.claude-desktop.status.v1:${e}`,G=`claude-desktop-status:${e}`,ee=X(W),te=ss(G,[e],async t=>{let n=await lt(await fetch(`${e}/api/claude-desktop/status`,{signal:t}));if(!n)throw Error(`Claude Desktop status unavailable`);return Z(W,n),n},{isEmpty:()=>!1,pollMs:5e3,enabled:t,initialData:ee??void 0}),ne=te.state,K=ne.data??ee??null,re=ne.showError,ie=(e,t)=>{!I||I.assignments[e]?.family===t||(u(n=>{if(!n)return n;let r=n.assignments[e];if(!r||r.family===t)return n;let i={...n.assignments,[e]:{...r,family:t}},a={...n.defaults};return a[r.family]===e&&(a[r.family]=Object.keys(i).filter(t=>t!==e&&i[t].family===r.family).sort()[0]??null),a[t]===null&&(a[t]=e),{...n,assignments:i,defaults:a}}),m(n=>({...n,[e]:t})),y(r(`claudeDesktop.moved`,{route:e,family:r(bd[t])})))},ae=e=>{let t=vd(E,e);yd.write(t),D(t)},oe=async t=>{if(!(!I||b)){x(`save`),g(null);try{await Y(await fetch(`${e}/api/claude-desktop`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({profile:I})}),r(`claudeDesktop.saveFailed`)),f(xd(I)),t?(x(`apply`),await Y(await fetch(`${e}/api/claude-desktop/apply`,{method:`POST`}),r(`claudeDesktop.applyFailed`)),g({tone:`ok`,text:r(`claudeDesktop.savedApplied`)}),y(r(`claudeDesktop.savedAppliedAnnounce`))):(g({tone:`ok`,text:r(`claudeDesktop.saved`)}),y(r(`claudeDesktop.savedAnnounce`))),te.refresh()}catch(e){let t=e instanceof Error?e.message:r(`claudeDesktop.updateFailed`);g({tone:`err`,text:t}),y(t)}finally{x(null)}}},se=()=>{if(!I)return;let e=URL.createObjectURL(new Blob([`${JSON.stringify(I,null,2)}\n`],{type:`application/json`})),t=document.createElement(`a`);t.href=e,t.download=`claude-desktop-profile.json`,t.click(),URL.revokeObjectURL(e),y(r(`claudeDesktop.exported`))},ce=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t)try{let e=JSON.parse(await t.text());if(e.version!==1||!e.assignments||!e.defaults)throw Error(r(`claudeDesktop.importExpected`));u(Sd({...F,profile:e})),g({tone:`ok`,text:r(`claudeDesktop.importReady`)}),y(r(`claudeDesktop.importedAnnounce`))}catch(e){let t=e instanceof Error?e.message:r(`claudeDesktop.importInvalid`);g({tone:`err`,text:t}),y(r(`claudeDesktop.importFailed`,{error:t}))}},le=(e,t)=>{e.preventDefault();let n=e.dataTransfer.getData(`text/plain`);n&&ie(n,t)};return N.kind===`disabled`&&!P?null:N.showSkeleton&&!P?(0,z.jsx)(ls,{label:r(`claudeDesktop.loading`),rows:4}):N.kind===`failed-cold`?(0,z.jsxs)(`div`,{className:`claude-desktop-error`,children:[(0,z.jsx)(J,{tone:`err`,children:N.error instanceof Error?N.error.message:r(`claudeDesktop.loadFail`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:()=>M.refresh(),children:r(`claudeDesktop.retry`)})]}):!F||!I?null:(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`claude-desktop-toolbar`,children:(0,z.jsxs)(`div`,{className:`claude-profile-tools`,children:[(0,z.jsx)(`input`,{ref:A,type:`file`,accept:`application/json,.json`,hidden:!0,onChange:e=>void ce(e)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>A.current?.click(),children:r(`claudeDesktop.importJson`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:se,children:r(`claudeDesktop.exportJson`)})]})}),(0,z.jsxs)(`div`,{className:`claude-status-bar ${re&&!K?`not-applied`:K?K.activeProfile===!1?`not-applied`:K.stale?`stale`:K.applied?`applied`:`not-applied`:`pending`}`,"aria-busy":!K&&!re||void 0,children:[(0,z.jsx)(`span`,{className:`claude-status-dot`}),(0,z.jsx)(`span`,{children:re&&!K?r(`claudeDesktop.loadFail`):K?K.activeProfile===!1?r(`claudeDesktop.status.notActiveProfile`):K.stale?r(`claudeDesktop.status.stale`):K.applied?r(`claudeDesktop.status.applied`):r(`claudeDesktop.status.notApplied`):r(`claudeDesktop.loading`)}),K?.health.lastRequestAt&&(0,z.jsxs)(`span`,{className:`claude-status-health`,children:[r(`claudeDesktop.health.lastRequest`),`:`,` `,new Date(K.health.lastRequestAt).toLocaleTimeString(a)]}),K&&K.health.requestCount>0&&(0,z.jsx)(`span`,{className:`claude-status-health`,children:r(`claudeDesktop.health.stats`,{count:K.health.requestCount,errors:K.health.errorCount})})]}),(0,z.jsx)(`div`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:v}),h&&(0,z.jsx)(J,{tone:h.tone,children:h.text}),N.showError&&(0,z.jsx)(J,{tone:`err`,children:r(`claudeDesktop.loadFail`)}),re&&K&&(0,z.jsx)(J,{tone:`err`,children:r(`claudeDesktop.loadFail`)}),(0,z.jsxs)(`div`,{className:`claude-profile-bar`,children:[(0,z.jsx)(`span`,{className:`claude-dirty${V?` active`:``}`,children:r(V?`claudeDesktop.unsaved`:`claudeDesktop.upToDate`)}),(0,z.jsxs)(`div`,{className:`claude-save-actions`,children:[(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:!V||b!==null,onClick:()=>void oe(!1),children:r(b===`save`?`claudeDesktop.saving`:`common.save`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:b!==null,onClick:()=>void oe(!0),children:r(b===`apply`?`claudeDesktop.applying`:b===`save`?`claudeDesktop.saving`:`claudeDesktop.saveApply`)})]})]}),F.models.length===0&&(0,z.jsx)(at,{title:r(`claudeDesktop.emptyTitle`),children:r(`claudeDesktop.emptyHint`)}),(0,z.jsx)(`div`,{className:`ocx-group-stack`,"aria-label":r(`claudeDesktop.assignmentsLabel`),children:$.map(e=>{let t=H[e],n=pd(t,S[e]??``,w[e]??6),i=E.has(e),a=U[e];return(0,z.jsxs)(`section`,{className:`ocx-group${i?` collapsed`:``}`,"aria-labelledby":`claude-lane-${e}`,onDragOver:e=>e.preventDefault(),onDrop:t=>le(t,e),children:[(0,z.jsxs)(`header`,{className:`ocx-group-head${i?``:` open`}`,children:[(0,z.jsx)(`h3`,{id:`claude-lane-${e}`,className:`ocx-group-heading`,children:(0,z.jsxs)(`button`,{type:`button`,className:`ocx-group-toggle`,"aria-expanded":!i,"aria-controls":`claude-lane-body-${e}`,onClick:()=>ae(e),children:[(0,z.jsx)(ge,{className:`ocx-chevron`,width:14,height:14,"aria-hidden":`true`,style:{transform:i?`none`:`rotate(90deg)`}}),(0,z.jsx)(`span`,{className:`ocx-group-name`,children:r(bd[e])}),(0,z.jsx)(`span`,{className:`ocx-group-count`,children:r(t.length===1?`claudeDesktop.modelCountOne`:`claudeDesktop.modelCountMany`,{count:t.length})}),a&&(0,z.jsx)(`code`,{className:`claude-lane-default`,title:a,children:a})]})}),t.length>0&&I.defaults[e]===null&&(0,z.jsx)(`span`,{className:`claude-default-needed`,children:r(`claudeDesktop.chooseDefault`)}),a&&a!==I.defaults[e]&&(0,z.jsx)(`span`,{className:`claude-default-needed`,title:a,children:r(`claudeDesktop.temporaryDefault`)})]}),!i&&(0,z.jsxs)(`div`,{id:`claude-lane-body-${e}`,children:[n.showSearch&&(0,z.jsx)(`input`,{className:`input claude-lane-search`,type:`search`,placeholder:r(`models.search`),"aria-label":r(`models.search`),value:S[e]??``,onChange:t=>{let n=t.target.value;C(t=>({...t,[e]:n})),T(t=>({...t,[e]:6}))}}),(0,z.jsxs)(`div`,{className:`claude-lane-models`,children:[t.length===0?(0,z.jsx)(`div`,{className:`claude-lane-empty`,children:r(`claudeDesktop.laneEmpty`)}):n.noMatch?(0,z.jsx)(`div`,{className:`claude-lane-empty`,children:r(`claudeDesktop.laneNoMatch`)}):n.shown.map(t=>{let n=I.assignments[t.route],i=wd(t.contextWindow,r),a=B[t.route]??`opus`,o=O[t.route]??hd(t.route,U[e]);return(0,z.jsxs)(`article`,{className:`claude-model-card${o?` open`:``}`,draggable:t.available,onDragStart:e=>{e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.route)},children:[(0,z.jsxs)(`button`,{type:`button`,className:`claude-model-summary`,"aria-expanded":o,"aria-controls":`claude-model-body-${t.route}`,onClick:()=>k(e=>({...e,[t.route]:!o})),children:[(0,z.jsx)(ge,{className:`ocx-chevron`,width:12,height:12,"aria-hidden":`true`,style:{transform:o?`rotate(90deg)`:`none`}}),(0,z.jsxs)(`span`,{className:`claude-model-names`,children:[(0,z.jsx)(`strong`,{title:t.label,children:t.label}),(0,z.jsx)(`code`,{title:t.route,children:t.route})]}),i&&(0,z.jsx)(`span`,{className:`claude-model-context`,children:i}),!i&&(0,z.jsx)(`span`,{className:`claude-model-context claude-model-context-unknown`,children:r(`claudeDesktop.contextUnknown`)}),t.supports1m===!0&&(0,z.jsx)(`span`,{className:`claude-1m-chip`,children:r(`claudeDesktop.supports1m`)}),t.effortSupported===!1&&(0,z.jsx)(`span`,{className:`claude-effort-badge off`,children:r(`claudeDesktop.effort.displayOnly`)}),t.effortSupported===!0&&(0,z.jsx)(`span`,{className:`claude-effort-badge on`,children:r(`claudeDesktop.effort.supported`)}),I.defaults[e]===t.route&&(0,z.jsx)(`span`,{className:`claude-row-default`,children:r(`claudeDesktop.defaultBadge`)}),(0,z.jsx)(`span`,{className:`badge ${t.available?`badge-green`:`badge-muted`}`,children:t.available?r(`claudeDesktop.available`):r(`claudeDesktop.unavailable`)})]}),o&&(0,z.jsxs)(`div`,{className:`claude-model-body`,id:`claude-model-body-${t.route}`,children:[U[e]===t.route&&I.defaults[e]!==t.route&&(0,z.jsx)(`span`,{className:`claude-effective-default`,children:r(`claudeDesktop.temporaryDefault`)}),(0,z.jsxs)(`div`,{className:`claude-field`,children:[(0,z.jsx)(`span`,{children:r(`claudeDesktop.alias`)}),(0,z.jsx)(`code`,{className:`claude-alias`,title:n.alias,children:n.alias})]}),(0,z.jsxs)(`label`,{className:`claude-default-radio`,children:[(0,z.jsx)(`input`,{type:`radio`,name:`default-${e}`,checked:I.defaults[e]===t.route,disabled:!t.available,onChange:()=>u(n=>n&&{...n,defaults:{...n.defaults,[e]:t.route}})}),r(`claudeDesktop.useAsDefault`,{family:r(bd[e])})]}),(0,z.jsxs)(`div`,{className:`claude-move-row`,children:[(0,z.jsx)(`label`,{htmlFor:`move-${t.route}`,children:r(`claudeDesktop.moveTo`)}),(0,z.jsx)(`select`,{id:`move-${t.route}`,className:`input`,value:a,disabled:!t.available,onChange:e=>m(n=>({...n,[t.route]:e.target.value})),children:$.map(e=>(0,z.jsx)(`option`,{value:e,children:r(bd[e])},e))}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,disabled:!t.available||a===e,onClick:()=>ie(t.route,a),children:r(`claudeDesktop.move`)})]})]})]},t.route)}),n.hidden>0&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm claude-lane-more`,onClick:()=>T(t=>({...t,[e]:(t[e]??6)+6})),children:r(`models.showMore`,{n:n.hidden})})]})]})]},e)})})]})}function Od(e){let t=X(`ocx.claude-desktop.v1:${e}`);return typeof t?.data?.port==`number`?t.data.port:null}function kd({apiBase:e}){let[t,n]=(0,_.useState)(`code`),r=q(),i=(0,_.useRef)(null),a=(0,_.useRef)(null),o=Od(e),[s,c]=(0,_.useState)(null),l=s?.base===e?s.port:o,u=s?.base===e,d=(0,_.useCallback)(t=>{c(n=>n?.base===e&&n.port===t?n:{base:e,port:t})},[e]),f=e=>{n(e),window.requestAnimationFrame(()=>{(e===`code`?i:a).current?.focus({preventScroll:!0})})},p=e=>{e.key===`ArrowLeft`||e.key===`ArrowRight`?(e.preventDefault(),f(t===`code`?`desktop`:`code`)):e.key===`Home`?(e.preventDefault(),f(`code`)):e.key===`End`&&(e.preventDefault(),f(`desktop`))};return(0,z.jsxs)(`section`,{className:`claude-page`,children:[(0,z.jsxs)(`div`,{className:`claude-page-intro`,children:[(0,z.jsx)(`div`,{className:`page-head`,children:(0,z.jsx)(`h2`,{children:r(t===`code`?`claude.pageTitle`:`claudeDesktop.title`)})}),t===`code`?(0,z.jsx)(`p`,{className:`page-sub`,children:r(`claude.subtitle`)}):(0,z.jsx)(`p`,{className:`page-sub`,children:l==null?r(u?`claudeDesktop.loadFail`:`claudeDesktop.loading`):r(`claudeDesktop.subtitle`,{port:l})})]}),(0,z.jsxs)(`div`,{className:`claude-tabs`,role:`tablist`,"aria-label":r(`claude.tabsLabel`),children:[(0,z.jsx)(`button`,{type:`button`,role:`tab`,ref:i,"aria-selected":t===`code`,"aria-controls":`claude-code-panel`,id:`claude-code-tab`,className:t===`code`?`active`:``,tabIndex:t===`code`?0:-1,onKeyDown:p,onClick:()=>f(`code`),children:r(`claude.tabCode`)}),(0,z.jsx)(`button`,{type:`button`,role:`tab`,ref:a,"aria-selected":t===`desktop`,"aria-controls":`claude-desktop-panel`,id:`claude-desktop-tab`,className:t===`desktop`?`active`:``,tabIndex:t===`desktop`?0:-1,onKeyDown:p,onClick:()=>f(`desktop`),children:r(`claude.tabDesktop`)})]}),(0,z.jsx)(`div`,{id:`claude-code-panel`,role:`tabpanel`,"aria-labelledby":`claude-code-tab`,hidden:t!==`code`,children:(0,z.jsx)(fd,{apiBase:e,active:t===`code`},e)}),(0,z.jsx)(`div`,{id:`claude-desktop-panel`,role:`tabpanel`,"aria-labelledby":`claude-desktop-tab`,hidden:t!==`desktop`,children:(0,z.jsx)(Dd,{apiBase:e,active:t===`desktop`,onPortChange:d},e)})]})}function Ad(e,t,n,r){let i=e.filter(e=>r===`native`===e.native).map(e=>({...e,alias:t.get(e.id)??null,enabled:!n.has(e.id)})).toSorted((e,t)=>Number(!e.enabled)-Number(!t.enabled));return{rows:i,total:i.length,enabled:i.filter(e=>e.enabled).length}}var jd=_d(`ocx.grok.collapsedGroups.v2`),Md=[{id:`native`,tkey:`grok.groupNative`},{id:`routed`,tkey:`grok.groupRouted`}],Nd=new Set(Md.map(e=>e.id));function Pd(e,t){return e?e>=1048576?t(`claudeDesktop.contextM`,{n:Math.round(e/1048576)}):e>=1e6?t(`claudeDesktop.contextM`,{n:e/1e6}):t(`claudeDesktop.contextK`,{n:Math.round(e/1e3)}):`—`}function Fd({apiBase:e}){let t=q(),n=`ocx.grok.status.v1:${e}`,r=X(n),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(()=>jd.read()??new Set(Nd)),[c,l]=(0,_.useState)(null),[u,d]=(0,_.useState)(null),[f,p]=(0,_.useState)(``),m=(0,_.useCallback)(async()=>{let r=await Y(await fetch(`${e}/api/grok`),t(`grok.loadFail`));if(!r)throw Error(t(`grok.loadFail`));let i={...r,candidates:r.candidates??[],excluded:r.excluded??[]};return Z(n,i),i},[e,n,t]),h=`grok-status:${e}`,g=ss(h,[e],m,{isEmpty:()=>!1,initialData:r??void 0}),{state:v}=g,y=g.refresh,b=v.data??r,x=(0,_.useMemo)(()=>new Set(b?.excluded??[]),[b]),S=i??x,C=(0,_.useMemo)(()=>i!==null&&(i.size!==x.size||[...i].some(e=>!x.has(e))),[i,x]),w=(0,_.useMemo)(()=>new Map((b?.models??[]).map(e=>[e.id,e.alias])),[b]),T=e=>{let t=vd(o,e);jd.write(t),s(t)},E=e=>{let t=e?new Set(Md.map(e=>e.id)):new Set;jd.write(t),s(t)},D=(e,t)=>{a(n=>{let r=new Set(n??x);return t?r.delete(e):r.add(e),r})},O=async r=>{if(!c){l(`save`),d(null);try{await Y(await fetch(`${e}/api/grok/selection`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({excluded:[...S]})}),t(`grok.saveFailed`));let i=[...S];if(b&&L(h,{...b,excluded:i}),a(null),r){l(`apply`);let n=await fetch(`${e}/api/grok/apply`,{method:`POST`});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.message??e.error??t(`grok.applyFailed`))}let r=await n.json().catch(()=>({}));r.skippedReason?(d({tone:`err`,text:r.message??t(`grok.applySkipped`)}),p(r.message??t(`grok.applySkipped`))):(d({tone:`ok`,text:t(`grok.savedApplied`)}),p(t(`grok.savedApplied`))),await y()}else d({tone:`ok`,text:t(`grok.saved`)}),p(t(`grok.saved`)),b&&Z(n,{...b,excluded:i})}catch(e){let n=e instanceof Error?e.message:t(`grok.saveFailed`);d({tone:`err`,text:n}),p(n)}finally{l(null)}}};return v.showSkeleton&&!b?(0,z.jsx)(`section`,{className:`grok-page`,children:(0,z.jsx)(ls,{label:t(`grok.loading`),rows:4})}):v.kind===`failed-cold`?(0,z.jsxs)(`section`,{className:`grok-page`,children:[(0,z.jsx)(`div`,{className:`alert alert-err`,role:`alert`,children:v.error instanceof Error?v.error.message:t(`grok.loadFail`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>y(),children:t(`common.retry`)})]}):(0,z.jsxs)(`section`,{className:`grok-page`,"aria-busy":v.refreshing||void 0,children:[(0,z.jsx)(`h2`,{className:`page-title`,children:t(`grok.title`)}),(0,z.jsx)(`p`,{className:`page-sub`,children:t(`grok.subtitle`)}),(0,z.jsx)(`div`,{className:`sr-only`,"aria-live":`polite`,"aria-atomic":`true`,children:f}),u&&(0,z.jsx)(J,{tone:u.tone,children:u.text}),v.showError&&(0,z.jsx)(J,{tone:`err`,children:t(`grok.loadFail`)}),b&&b.candidates.length>0&&(0,z.jsxs)(`div`,{className:`claude-profile-bar`,children:[(0,z.jsx)(`span`,{className:`claude-dirty${C?` active`:``}`,children:t(C?`grok.unsaved`:`grok.upToDate`)}),(0,z.jsxs)(`div`,{className:`claude-save-actions`,children:[(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:!C||c!==null,onClick:()=>void O(!1),children:t(c===`save`?`grok.saving`:`common.save`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:!C||c!==null,onClick:()=>void O(!0),children:t(c===`apply`?`grok.applying`:c===`save`?`grok.saving`:`grok.saveApply`)})]})]}),b?.present?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`grok-endpoint`,children:[(0,z.jsx)(`span`,{children:t(`grok.endpoint`)}),(0,z.jsx)(`code`,{children:b.baseUrl??`—`})]}),(0,z.jsx)(`p`,{className:`page-sub`,children:(0,z.jsx)(`code`,{children:b.configPath})})]}):(0,z.jsxs)(at,{title:t(`grok.notConfiguredTitle`),children:[t(`grok.notConfiguredHint`),(0,z.jsx)(`br`,{}),(0,z.jsx)(`code`,{children:b?.configPath})]}),b&&b.candidates.length>0&&(0,z.jsxs)(`div`,{className:`ocx-group-stack`,children:[(0,z.jsxs)(`div`,{className:`row`,style:{gap:6,margin:`2px 0 10px`},children:[(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm text-caption`,onClick:()=>E(!0),disabled:c!==null,children:[(0,z.jsx)(ge,{width:12,height:12,"aria-hidden":`true`}),` `,t(`models.collapseAll`)]}),(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm text-caption`,onClick:()=>E(!1),disabled:c!==null,children:[(0,z.jsx)(ge,{width:12,height:12,"aria-hidden":`true`,style:{transform:`rotate(90deg)`}}),` `,t(`models.expandAll`)]})]}),Md.map(e=>{let n=Ad(b.candidates,w,S,e.id);if(n.total===0)return null;let r=o.has(e.id);return(0,z.jsxs)(`section`,{className:`ocx-group${r?` collapsed`:``}`,"aria-labelledby":`grok-group-${e.id}`,children:[(0,z.jsx)(`header`,{className:`ocx-group-head${r?``:` open`}`,children:(0,z.jsx)(`h3`,{id:`grok-group-${e.id}`,className:`ocx-group-heading`,children:(0,z.jsxs)(`button`,{type:`button`,className:`ocx-group-toggle`,"aria-expanded":!r,"aria-controls":`grok-group-body-${e.id}`,onClick:()=>T(e.id),children:[(0,z.jsx)(ge,{className:`ocx-chevron`,width:14,height:14,"aria-hidden":`true`,style:{transform:r?`none`:`rotate(90deg)`}}),(0,z.jsx)(`span`,{className:`ocx-group-name`,children:t(e.tkey)}),(0,z.jsx)(`span`,{className:`ocx-group-count`,children:t(`grok.enabledCount`,{on:n.enabled,total:n.total})})]})})}),!r&&(0,z.jsx)(`div`,{id:`grok-group-body-${e.id}`,className:`grok-model-list`,children:n.rows.map(e=>(0,z.jsxs)(`div`,{className:`grok-model-row`,children:[(0,z.jsx)(rt,{on:e.enabled,onClick:()=>D(e.id,!e.enabled),disabled:c!==null,label:t(`grok.toggleModel`,{id:e.id})}),(0,z.jsxs)(`span`,{className:`grok-model-names`,children:[(0,z.jsx)(`strong`,{title:e.id,children:e.id}),(0,z.jsx)(`code`,{title:e.alias??void 0,children:e.alias??`—`})]}),(0,z.jsx)(`span`,{className:`claude-model-context`,children:Pd(e.contextWindow,t)})]},e.id))})]},e.id)})]})]})}function Id(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.supported==`boolean`&&typeof t.installed==`boolean`&&typeof t.running==`boolean`&&typeof t.stale==`boolean`&&typeof t.summary==`string`}var Ld={native:`startup.status.native`,protected:`startup.status.protected`,"at-risk":`startup.status.atRisk`},Rd={native:`startup.summary.native`,protected:`startup.summary.protected`,"at-risk":`startup.summary.atRisk`},zd={service:`startup.protection.service`,shim:`startup.protection.shim`,none:`startup.protection.none`};function Bd({ok:e,yes:t,no:n}){return(0,z.jsx)(`span`,{className:`badge ${e?`badge-green`:`badge-amber`}`,children:e?t:n})}function Vd({failed:e,data:t}){let{t:n}=Be(),r=e?`startup-hero--risk`:t.status===`protected`?`startup-hero--safe`:t.status===`at-risk`?`startup-hero--risk`:`startup-hero--native`,i=e||t.status===`at-risk`?ue:re,a=t.routingKind===`opencodex-local`?`startup.routing.proxy`:t.routingKind===`custom-local`?`startup.routing.customLocal`:t.routingKind===`custom-remote`?`startup.routing.customRemote`:t.routingKind===`unknown`?`startup.routing.unknown`:`startup.routing.native`;return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`section`,{className:`panel startup-hero ${r}`,"aria-live":`polite`,children:[(0,z.jsx)(`div`,{className:`startup-hero-icon`,children:(0,z.jsx)(i,{})}),(0,z.jsxs)(`div`,{className:`startup-hero-copy`,children:[(0,z.jsx)(`span`,{className:`badge ${e||t.status===`at-risk`?`badge-amber`:`badge-green`}`,children:n(e?`startup.status.atRisk`:Ld[t.status])}),(0,z.jsx)(`h3`,{children:n(e?`startup.error`:Rd[t.status])}),(0,z.jsx)(`p`,{children:e?n(`startup.staleData`):t.status===`at-risk`?n(sn(t)):n(`startup.safeDetail`)})]})]}),(0,z.jsxs)(`div`,{className:`startup-state-grid`,children:[(0,z.jsxs)(`section`,{className:`stat`,children:[(0,z.jsx)(`div`,{className:`label`,children:n(`startup.routing`)}),(0,z.jsx)(`div`,{className:`value`,children:n(a)})]}),(0,z.jsxs)(`section`,{className:`stat`,children:[(0,z.jsx)(`div`,{className:`label`,children:n(`startup.restartProtection`)}),(0,z.jsx)(`div`,{className:`value`,children:n(zd[t.protection])})]}),(0,z.jsxs)(`section`,{className:`stat`,children:[(0,z.jsx)(`div`,{className:`label`,children:n(`startup.preference`)}),(0,z.jsx)(`div`,{className:`value`,children:n(t.autostartEnabled?`startup.enabled`:`startup.disabled`)})]})]})]})}function Hd({data:e,failed:t,loading:n=!1,installBusy:r,installResult:i,onInstall:a}){let{t:o}=Be(),s=e.serviceSupported&&e.serviceInstalled&&e.serviceStale&&!e.serviceConflict,c=e.shimInstalled&&!e.shimHealthy,l=r!==null||t||n;return(0,z.jsxs)(`section`,{className:`panel startup-details`,children:[(0,z.jsxs)(`div`,{className:`panel-head`,children:[(0,z.jsx)(`h3`,{className:`panel-title`,children:o(`startup.details`)}),(0,z.jsx)(`span`,{className:`muted mono`,children:e.platform})]}),(0,z.jsxs)(`div`,{className:`startup-detail-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:o(`startup.service`)}),(0,z.jsx)(`span`,{children:o(`startup.serviceHint`)})]}),(0,z.jsxs)(`div`,{className:`startup-detail-actions`,children:[(0,z.jsx)(Bd,{ok:e.serviceViable,yes:o(`startup.viable`),no:o(e.serviceConflict?`startup.conflict`:e.serviceStale?`startup.stale`:e.serviceInstalled?`startup.unhealthy`:e.serviceSupported?`startup.notInstalled`:`startup.unsupported`)}),e.serviceSupported&&!e.serviceInstalled&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,"aria-label":`${o(`startup.service`)} - ${o(`startup.install`)}`,disabled:l,onClick:()=>a(`install-service`),children:o(r===`install-service`?`startup.installing`:`startup.install`)}),s&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,"aria-label":`${o(`startup.service`)} - ${o(`startup.repair`)}`,disabled:l,onClick:()=>a(`install-service`,{repair:!0}),children:o(r===`install-service`?`startup.repairing`:`startup.repair`)})]})]}),(0,z.jsxs)(`div`,{className:`startup-detail-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:o(`startup.shim`)}),(0,z.jsx)(`span`,{children:o(`startup.shimHint`)})]}),(0,z.jsxs)(`div`,{className:`startup-detail-actions`,children:[(0,z.jsx)(Bd,{ok:e.shimHealthy&&e.autostartEnabled,yes:o(e.shimCoverage===`cli-only`?`startup.cliOnly`:`startup.healthy`),no:o(e.shimInstalled?e.shimHealthy&&!e.autostartEnabled?`startup.installedDisabled`:`startup.stale`:`startup.notInstalled`)}),!e.shimInstalled&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,"aria-label":`${o(`startup.shim`)} - ${o(`startup.install`)}`,disabled:l,onClick:()=>a(`install-shim`),children:o(r===`install-shim`?`startup.installing`:`startup.install`)}),c&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary btn-sm`,"aria-label":`${o(`startup.shim`)} - ${o(`startup.repair`)}`,disabled:l,onClick:()=>a(`install-shim`,{repair:!0}),children:o(r===`install-shim`?`startup.repairing`:`startup.repair`)})]})]}),i&&(0,z.jsx)(`div`,{className:`notice ${i.kind===`success`?`notice-ok`:`notice-warn`} startup-action-notice`,role:`status`,"aria-live":`polite`,children:i.kind===`success`?i.action===`install-service`?o(i.repair?`startup.serviceRepaired`:`startup.serviceInstalled`):o(i.repair?`startup.shimRepaired`:`startup.shimInstalled`):`${o(`startup.installFailed`)} ${i.detail??``}`})]})}function Ud({tray:e,trayLoading:t,trayError:n,trayBusy:r,onTrayAction:i}){let{t:a}=Be();return(0,z.jsxs)(`section`,{className:`panel startup-actions`,children:[(0,z.jsxs)(`div`,{className:`panel-head`,children:[(0,z.jsx)(`h3`,{className:`panel-title`,children:a(`startup.tray.title`)}),(0,z.jsx)(ve,{})]}),(0,z.jsx)(`p`,{className:`muted`,children:a(`startup.tray.hint`)}),(0,z.jsxs)(`div`,{className:`startup-detail-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:a(`startup.tray.login`)}),(0,z.jsx)(`span`,{children:a(`startup.tray.notProtection`)})]}),t||n||!e?(0,z.jsx)(`span`,{className:`badge badge-amber`,children:a(t?`startup.tray.loading`:`startup.tray.unavailable`)}):(0,z.jsx)(Bd,{ok:e.running&&!e.stale,yes:a(`startup.tray.running`),no:a(e.stale?`startup.tray.stale`:e.installed?`startup.tray.stopped`:`startup.tray.notInstalled`)})]}),(0,z.jsxs)(`div`,{className:`startup-tray-buttons`,children:[!t&&!n&&e&&!e.installed&&!e.stale&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:r,onClick:()=>i(`install`),children:a(`startup.tray.install`)}),!t&&!n&&e?.installed&&!e.stale&&!e.running&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:r,onClick:()=>i(`start`),children:a(`startup.tray.start`)}),!t&&!n&&e?.running&&!e.stale&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:r,onClick:()=>i(`stop`),children:a(`startup.tray.stop`)}),!t&&!n&&e&&(e.installed||e.stale)&&(0,z.jsx)(`button`,{type:`button`,className:`btn btn-danger`,disabled:r,onClick:()=>{window.confirm(a(`startup.tray.uninstall`))&&i(`uninstall`)},children:a(`startup.tray.uninstall`)})]}),(n||e?.stale)&&(0,z.jsx)(`div`,{className:`notice notice-warn startup-tray-error`,role:`alert`,children:a(`startup.tray.error`)})]})}function Wd({data:e,copied:t,onCopy:n}){let{t:r}=Be();return(0,z.jsxs)(`section`,{className:`panel startup-actions`,children:[(0,z.jsxs)(`div`,{className:`panel-head`,children:[(0,z.jsx)(`h3`,{className:`panel-title`,children:r(`startup.recovery`)}),(0,z.jsx)(te,{})]}),(0,z.jsx)(`p`,{className:`muted`,children:r(`startup.recoveryHint`)}),(0,z.jsxs)(`div`,{className:`startup-command-list`,children:[e.serviceSupported&&(0,z.jsxs)(`div`,{className:`startup-command-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:r(`startup.command.service`)}),(0,z.jsx)(`code`,{children:e.commands.installService})]}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>n(e.commands.installService),children:t===e.commands.installService?r(`startup.copied`):r(`startup.copy`)})]}),(0,z.jsxs)(`div`,{className:`startup-command-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:r(`startup.command.shim`)}),(0,z.jsx)(`code`,{children:e.commands.installShim})]}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>n(e.commands.installShim),children:t===e.commands.installShim?r(`startup.copied`):r(`startup.copy`)})]}),(0,z.jsxs)(`div`,{className:`startup-command-row`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`strong`,{children:r(`startup.command.native`)}),(0,z.jsx)(`code`,{children:e.commands.restoreNative})]}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>n(e.commands.restoreNative),children:t===e.commands.restoreNative?r(`startup.copied`):r(`startup.copy`)})]})]}),e.status===`at-risk`&&(0,z.jsxs)(`div`,{className:`notice notice-warn startup-action-notice`,role:`alert`,children:[(0,z.jsx)(ve,{}),` `,r(`startup.recommended`,{cmd:e.recommendedCommand??e.commands.installService})]})]})}var Gd=`ocx.startup.page.v1:`;function Kd(e,t){let n=t===`win32`?`; `:` && `;return e.join(n)}function qd(e,t,n){if(!e)return{warning:null,fix:null};let r=!!e.catalogClamp?.active,i=!!e.newerAvailable,a=(r?e.catalogClamp?.runtimeVersion:e.version)??e.version??`unknown`,o=(e.catalogClamp?.removedEfforts??[]).join(`, `),s=Kd([`ocx doctor --fix-codex-runtime`,`ocx sync`],n);return r?{warning:o?t(`startup.codexRuntime.clampHiddenWithEfforts`,{version:a,efforts:o}):t(`startup.codexRuntime.clampHidden`,{version:a}),fix:i?s:`ocx sync`}:i?{warning:t(`startup.codexRuntime.olderBinary`,{version:a}),fix:s}:{warning:null,fix:null}}function Jd({apiBase:e}){let{t}=Be(),n=`${Gd}${e}`,r=(0,_.useMemo)(()=>X(n),[n]),i=`startup-page:${e}`,[a,o]=(0,_.useState)(null),[s,c]=(0,_.useState)(()=>r?.tray??null),[l,u]=(0,_.useState)(()=>!r?.data),[d,f]=(0,_.useState)(!1),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)(null),[v,y]=(0,_.useState)(null),[b,x]=(0,_.useState)(()=>r?.warning??null),[S,C]=(0,_.useState)(()=>r?.fix??null),[w,T]=(0,_.useState)(()=>!r?.data),E=(0,_.useRef)(!!r?.data),D=(0,_.useCallback)(async r=>{let i=E.current;i||(u(!0),T(!0));try{let i=fetch(`${e}/api/settings`,{signal:r}).then(async e=>e.ok?await e.json():null).catch(()=>null),a=await fetch(`${e}/api/startup-health`,{signal:r});if(!a.ok)throw Error(`fetch failed`);let o=await a.json();E.current=!0;let s=X(n);Z(n,{data:o,warning:s?.warning??null,fix:s?.fix??null,tray:s?.tray??null});let l=o.platform===`win32`?fetch(`${e}/api/windows-tray`,{signal:r}).then(async e=>{if(!e.ok)throw Error(`tray status failed`);let t=await e.json();if(!Id(t))throw Error(`invalid tray status`);return{tray:t,error:!1}}).catch(()=>({tray:null,error:!0})):Promise.resolve({tray:null,error:!1});return Promise.all([i,l]).then(([e,i])=>{if(r.aborted)return;let a=o.platform===`win32`?i.tray:null;if(o.platform===`win32`?(c(a),m(i.error)):(c(null),m(!1)),u(!1),T(!1),e){let r=qd(e.codexRuntime,t,o.platform);x(r.warning),C(r.fix),Z(n,{data:o,warning:r.warning,fix:r.fix,tray:a});return}let s=X(n);Z(n,{data:o,warning:s?.warning??null,fix:s?.fix??null,tray:a})}),o}catch(e){throw r.aborted?e:(i||(c(null),m(!0),x(null),C(null)),T(!1),u(!1),e)}},[e,n,t]),O=ss(i,[e],D,{isEmpty:()=>!1,initialData:r?.data??void 0}),k=O.state,A=O.refresh,j=k.data??r?.data??null,M=k.refreshing,N=!!j?.diagnosticStale||k.showError;(0,_.useEffect)(()=>{if(!j?.diagnosticStale)return;let e=window.setTimeout(A,2e3);return()=>window.clearTimeout(e)},[j,A]);let P=async e=>{try{await navigator.clipboard.writeText(e),o(e),window.setTimeout(()=>o(t=>t===e?null:t),1600)}catch{o(null)}},F=async t=>{f(!0),m(!1);try{let n=await fetch(`${e}/api/windows-tray`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:t})});if(!n.ok)throw Error(`tray action failed`);let r=await n.json();if(!Id(r.status))throw Error(`invalid tray action status`);c(r.status),m(!1)}catch{c(null),m(!0)}finally{f(!1)}},I=async(t,n)=>{g(t),y(null);try{let r=await fetch(`${e}/api/startup-action`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({action:t,repair:n?.repair===!0})});if(!r.ok){let e=await r.json().catch(()=>null);throw Error(typeof e?.error==`string`?e.error:`installation failed`)}y({kind:`success`,action:t,repair:n?.repair===!0}),A()}catch(e){y({kind:`error`,action:t,repair:n?.repair===!0,detail:e instanceof Error?e.message:String(e)})}finally{g(null)}};return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`page-head`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{children:t(`startup.title`)}),(0,z.jsx)(`p`,{className:`page-sub startup-page-sub`,children:t(`startup.subtitle`)})]}),(0,z.jsxs)(`div`,{className:`startup-page-head-actions`,children:[(0,z.jsx)(`a`,{className:`btn btn-ghost btn-sm`,href:`#dashboard`,children:t(`startup.backToDashboard`)}),(0,z.jsxs)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>A(),disabled:M,children:[(0,z.jsx)(oe,{}),` `,t(`startup.refresh`)]})]})]}),k.showSkeleton&&!j?(0,z.jsx)(ls,{label:t(`startup.loading`),rows:5}):k.kind===`failed-cold`?(0,z.jsxs)(`div`,{className:`startup-page-notice`,children:[(0,z.jsx)(J,{tone:`err`,children:k.error instanceof Error?k.error.message:t(`startup.error`)}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>A(),children:t(`common.retry`)})]}):j?(0,z.jsxs)(z.Fragment,{children:[k.showError&&(0,z.jsx)(J,{tone:`err`,children:t(`startup.error`)}),N&&(0,z.jsx)(`div`,{className:`notice notice-warn startup-page-notice`,role:`alert`,children:t(`startup.staleData`)}),(w||b)&&(0,z.jsx)(`div`,{className:`startup-runtime-notice-slot${w&&!b?` startup-runtime-notice-slot--pending`:``}`,"aria-hidden":w&&!b?!0:void 0,children:b&&(0,z.jsxs)(`div`,{className:`notice notice-warn startup-page-notice startup-runtime-notice`,role:`status`,children:[(0,z.jsx)(`p`,{className:`startup-runtime-notice__text`,children:b}),S&&(0,z.jsxs)(`div`,{className:`startup-runtime-notice__fix`,children:[(0,z.jsx)(`code`,{children:S}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-ghost btn-sm`,onClick:()=>void P(S),children:t(a===S?`startup.copied`:`startup.copy`)})]})]})}),(0,z.jsx)(Vd,{failed:N,data:j}),(0,z.jsx)(Hd,{data:j,failed:N,loading:M,installBusy:h,installResult:v,onInstall:(e,t)=>{I(e,t)}}),j.platform===`win32`&&(0,z.jsx)(Ud,{tray:s,trayLoading:l,trayError:p,trayBusy:d,onTrayAction:e=>{F(e)}}),(0,z.jsx)(Wd,{data:j,copied:a,onCopy:e=>{P(e)}})]}):null]})}var Yd=class extends _.Component{state={error:null};static getDerivedStateFromError(e){return{error:e instanceof Error?e:Error(String(e))}}reload=()=>{this.setState({error:null})};render(){return this.state.error?(0,z.jsxs)(`section`,{className:`card`,role:`alert`,style:{maxWidth:720,padding:`var(--space-6)`},children:[(0,z.jsxs)(`h2`,{style:{margin:`0 0 var(--space-2)`,fontSize:`var(--text-title)`},children:[this.props.pageName,`: `,this.props.title]}),(0,z.jsx)(`p`,{className:`muted`,style:{margin:`0 0 var(--space-4)`},children:this.props.message}),(0,z.jsxs)(`p`,{style:{margin:`0 0 var(--space-5)`,overflowWrap:`anywhere`},children:[(0,z.jsxs)(`strong`,{children:[this.props.detailsLabel,`:`]}),` `,this.state.error.message]}),(0,z.jsx)(`button`,{type:`button`,className:`btn btn-primary`,onClick:this.reload,children:this.props.reloadLabel})]}):this.props.children}},Xd=5*6e4,Zd=10*6e4,Qd=`https://github.com/lidge-jun/opencodex`;async function $d(e,t){let n=await fetch(e,{signal:t});return n.ok?await n.json():null}function ef({apiBase:e,onOpenUpdate:t}){let n=q(),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(null),s=I(`sidebar-star:${e}`,[e],t=>$d(`${e}/api/github/star`,t),{pollMs:Xd}),c=I(`sidebar-update-badge:${e}`,[e],t=>$d(`${e}/api/update/badge`,t),{pollMs:Zd}),l=s.data?.state??null,u=a!==null&&a.basedOn===l?a.state:l??`not-starred`,d=s.data?.url??Qd,f=u===`starred`,p=c.data,m=p?.updateAvailable===!0,h=p?.latestVersion??null,g=()=>window.open(d,`_blank`,`noopener,noreferrer`),v=async()=>{if(!(f||r)){if(u===`unauthenticated`){g();return}i(!0);try{let t=await fetch(`${e}/api/github/star`,{method:`POST`}),n=t.ok?await t.json():null;if(n?.ok===!0){o({state:`starred`,basedOn:l});return}n?.state&&o({state:n.state,basedOn:l}),g()}catch{g()}finally{i(!1),s.refresh()}}},y=n(f?`sidebar.starred`:u===`unauthenticated`?`sidebar.starUnauthenticated`:`sidebar.star`),b=m&&h?n(`sidebar.updateAvailable`,{version:h}):n(`sidebar.checkUpdate`);return(0,z.jsxs)(`div`,{className:`sidebar-github-row`,children:[(0,z.jsxs)(`a`,{className:`sidebar-link sidebar-github-link`,href:d,target:`_blank`,rel:`noreferrer`,children:[(0,z.jsx)(_e,{}),` `,n(`common.github`)]}),(0,z.jsxs)(`div`,{className:`sidebar-github-actions`,children:[(0,z.jsx)(`button`,{type:`button`,className:`sidebar-orb${f?` sidebar-orb--starred`:``}`,onClick:()=>{v()},disabled:r||f,"aria-label":y,"aria-pressed":f,title:y,children:(0,z.jsx)(je,{"aria-hidden":`true`,...f?{fill:`currentColor`}:{}})}),(0,z.jsxs)(`button`,{type:`button`,className:`sidebar-orb${m?` sidebar-orb--update`:``}`,onClick:t,"aria-label":b,title:b,children:[(0,z.jsx)(he,{"aria-hidden":`true`}),m&&(0,z.jsx)(`span`,{className:`sidebar-orb-dot`,"aria-hidden":`true`})]})]})]})}var tf=!1,nf=null,rf=null,af=!1,of=`/`;function sf(e){try{let t=e instanceof Request?e.url:String(e),n=new URL(t,window.location.href);return n.origin===window.location.origin?n.pathname.startsWith(`/api/`):!1}catch{return!1}}var cf=`opencodex-api-token`,lf=null,uf=null,df=null;function ff(){return lf}function pf(e){lf=e}function mf(){lf=null,uf=null,df=null}function hf(e){let t=document.querySelector(`meta[name="${e}"]`),n=t?.content.trim()||null;return t?.remove(),n}function gf(){vf(hf(`opencodex-session-token`),hf(`opencodex-session-csrf`),hf(`opencodex-session-origin`))}function _f(e){e!=null&&ff()===e&&mf()}function vf(e,t,n){return!e?.startsWith(`ocx_session_`)||!t||n!==window.location.origin?!1:(lf=e,uf=t,df=n,!0)}function yf(e,t){for(let n of e.match(/<meta\b[^>]*>/gi)??[])if(n.match(/\bname="([^"]+)"/i)?.[1]===t)return n.match(/\bcontent="([^"]*)"/i)?.[1]?.trim()||null;return null}async function bf(){if(!rf)return null;try{let e=await rf(of,{cache:`no-store`});if(!e.ok)return null;let t=await e.text();return vf(yf(t,`opencodex-session-token`),yf(t,`opencodex-session-csrf`),yf(t,`opencodex-session-origin`))?ff():null}catch{return null}}function xf(){try{sessionStorage.removeItem(cf)}catch{}}function Sf(e,t,n){let r=new Headers(t?.headers??(e instanceof Request?e.headers:void 0));if(r.set(`X-OpenCodex-API-Key`,n),df&&uf&&n.startsWith(`ocx_session_`)){r.set(`X-OpenCodex-GUI-Origin`,df);let n=(t?.method??(e instanceof Request?e.method:`GET`)).toUpperCase();n!==`GET`&&n!==`HEAD`&&r.set(`X-OpenCodex-CSRF-Token`,uf)}return e instanceof Request?[new Request(e,{headers:r}),t?{...t,headers:r}:void 0]:[e,{...t,headers:r}]}async function Cf(e){return af?null:nf||(nf=(async()=>{if(af)return null;let t=ff();if(t&&t!==e)return t;let n=await bf();if(n)return n;let r=window.prompt(`OpenCodex admin token (OPENCODEX_ADMIN_AUTH_TOKEN)`)?.trim()||null;return r?(pf(r),r):(af=!0,null)})().finally(()=>{nf=null}),nf)}function wf(){if(tf)return;tf=!0,xf(),gf();let e=window.fetch.bind(window);rf=e,window.fetch=async(t,n)=>{if(!sf(t))return e(t,n);let r=ff(),[i,a]=r?Sf(t,n,r):[t,n],o=await e(i,a);if(o.status!==401)return o;let s=ff();if(s&&s!==r){let[r,i]=Sf(t,n,s),a=await e(r,i);if(a.status!==401)return a;_f(s)}else _f(r);let c=await Cf(r);if(!c)return o;let[l,u]=Sf(t,n,c),d=await e(l,u);return d.status===401&&_f(c),d}}var Tf=new Set([`dashboard`,`startup`,`providers`,`models`,`combos`,`subagents`,`logs`,`usage`,`storage`,`codex-auth`,`api`,`claude`,`grok`]);function Ef(e){let t=Ue(e??(typeof window<`u`?window.location.hash:``)).split(`/`)[0];return t===`debug`?`logs`:Tf.has(t)?t:`dashboard`}var Df=[`dashboard/providers`,`dashboard/models`];function Of(e,t){return e===t||t===`logs`&&e===`logs/debug`||t===`dashboard`&&(e===`dashboard/update`||Df.includes(e))}function kf(e){let t=Ef(e);return e===`debug`||e.startsWith(`debug/`)?{page:`logs`,replaceTo:`logs/debug`}:e===`providers/workspace`?{page:`providers`,replaceTo:`providers`}:Of(e,t)?{page:t,replaceTo:null}:{page:t,replaceTo:t}}var Af=[`ocx-global-view`,`ocx-view`,`ocx-providers-view`,`ocx-subagents-view`,`ocx-storage-view`,`ocx-codexauth-view`,`ocx-apikeys-view`,`ocx-claudecode-view`,`ocx-usage-view`,`ocx-logs-view`,`ocx-models-view`,`ocx-dashboard-view`];function jf(){try{for(let e of Af)localStorage.removeItem(e)}catch{}}function Mf(){let[e,t]=(0,_.useState)(Ef);(0,_.useEffect)(()=>{jf()},[]);let n=(0,_.useCallback)(e=>{let n=kf(e);n.replaceTo&&We(n.replaceTo),t(n.page)},[]);return(0,_.useEffect)(()=>{let e=()=>{n(Ue(window.location.hash))};return window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[n]),(0,_.useEffect)(()=>{let t=Ue(window.location.hash);if(t===`debug`||t.startsWith(`debug/`)){We(`logs/debug`);return}if(t===`providers/workspace`){We(`providers`);return}Of(t,e)||We(e)},[e]),{page:e,setPageState:t,navigateToPage:(e,n)=>{Ge(n?`${e}/${n}`:e),t(e)}}}var Nf=15e3;function Pf(e,t,n){return typeof e?.message==`string`&&e.message.trim()?e.message:typeof e?.error==`string`&&e.error.trim()?e.error:n(t)}function Ff(e){return(e instanceof DOMException||e instanceof Error)&&e.name===`AbortError`}async function If(e,t={}){let{fetchFn:n=fetch,timeoutMs:r=Nf,formatFailure:i=e=>`Failed to stop proxy (HTTP ${e}).`}=t,a;try{a=await n(`${e}/api/stop`,{method:`POST`,signal:AbortSignal.timeout(r)})}catch(e){return Ff(e),{accepted:!0}}let o=await a.json().catch(()=>null);return!a.ok||o?.success===!1?{accepted:!1,message:Pf(o,a.status,i)}:{accepted:!0}}wf();var Lf={dashboard:`nav.dashboard`,startup:`nav.startup`,providers:`nav.providers`,models:`nav.models`,combos:`nav.combos`,subagents:`nav.subagents`,logs:`nav.logs`,usage:`nav.usage`,storage:`nav.storage`,"codex-auth":`nav.codexAuth`,api:`nav.api`,claude:`nav.claude`,grok:`nav.grok`},Rf=``,zf=`ocx-theme`,Bf=[{id:`dashboard`,tkey:`nav.dashboard`,Icon:V},{id:`codex-auth`,tkey:`nav.codexAuth`,Icon:be},{id:`providers`,tkey:`nav.providers`,Icon:H},{id:`models`,tkey:`nav.models`,Icon:U},{id:`subagents`,tkey:`nav.subagents`,Icon:W},{id:`logs`,tkey:`nav.logs`,Icon:G},{id:`usage`,tkey:`nav.usage`,Icon:ne},{id:`storage`,tkey:`nav.storage`,Icon:K},{id:`api`,tkey:`nav.api`,Icon:De},{id:`claude`,tkey:`nav.claude`,Icon:Oe},{id:`grok`,tkey:`nav.grok`,Icon:U}],Vf={light:we,dark:Te,system:Ee},Hf={light:`theme.light`,dark:`theme.dark`,system:`theme.system`};function Uf(e){if(!e||typeof e!=`object`||!(`version`in e))return null;let t=e.version;return typeof t==`string`&&t.length>0?t:null}function Wf(){let e=localStorage.getItem(zf);return e===`light`||e===`dark`?e:`system`}function Gf(){let{page:e,navigateToPage:t}=Mf(),[n,r]=(0,_.useState)(Wf),{locale:i,setLocale:a}=Be(),o=q(),[s,c]=(0,_.useState)(!1),l=(0,_.useRef)(null),u=(0,_.useRef)(null),d=(0,_.useRef)(!1);(0,_.useEffect)(()=>{let e=()=>c(!1);return window.addEventListener(`hashchange`,e),window.addEventListener(`popstate`,e),()=>{window.removeEventListener(`hashchange`,e),window.removeEventListener(`popstate`,e)}},[]),(0,_.useEffect)(()=>{let e=document.documentElement;n===`system`?(e.removeAttribute(`data-theme`),localStorage.removeItem(zf)):(e.setAttribute(`data-theme`,n),localStorage.setItem(zf,n))},[n]);let f=I(`app-healthz:${Rf}`,[],async e=>{let t=await fetch(`${Rf}/healthz`,{signal:e});return t.ok?Uf(await t.json()):null},{pollMs:3e4}),p=()=>r(e=>e===`light`?`dark`:e===`dark`?`system`:`light`),m=Vf[n],h=f.data??`2.9.1`,[g,v]=(0,_.useState)(!1),y=(0,_.useCallback)(async e=>{let t=await lt(await fetch(`${Rf}/api/claude-code`,{signal:e}));return t&&typeof t.enabled==`boolean`?t.enabled:null},[]),b=I(`app-claude-code:${Rf}`,[],y).data??null,x=(0,_.useRef)(!1),[S,C]=(0,_.useState)(!1);(0,_.useEffect)(()=>{if(!s)return;let e=e=>{e.key===`Escape`&&c(!1)};window.addEventListener(`keydown`,e);let t=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{window.removeEventListener(`keydown`,e),document.body.style.overflow=t}},[s]),(0,_.useEffect)(()=>{if(s){d.current=!0;let e=setTimeout(()=>u.current?.focus(),200);return()=>clearTimeout(e)}d.current&&(d.current=!1,l.current?.focus())},[s]),(0,_.useEffect)(()=>{let e=window.matchMedia(`(min-width: 761px)`),t=()=>{e.matches&&c(!1)};return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let w=async()=>{if(b===null||x.current)return;x.current=!0,C(!0);let e=!b;L(`app-claude-code:${Rf}`,e);try{(await fetch(`${Rf}/api/claude-code`,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({enabled:e})})).ok||L(`app-claude-code:${Rf}`,!e)}catch{L(`app-claude-code:${Rf}`,!e)}finally{x.current=!1,C(!1)}},T=async()=>{if(!confirm(o(`dash.stopConfirm`)))return;v(!0);let e=await If(Rf,{formatFailure:e=>o(`dash.stopFailed`,{status:String(e)})});e.accepted||(v(!1),alert(e.message))},E=(0,z.jsxs)(`div`,{className:`brand`,children:[(0,z.jsx)(`span`,{className:`brand-logo`,role:`img`,"aria-label":o(`app.logoAria`)}),(0,z.jsx)(`span`,{className:`name`,children:`opencodex`}),(0,z.jsxs)(`span`,{className:`ver`,children:[`v`,h]})]});return(0,z.jsxs)(`div`,{className:`app`,children:[(0,z.jsxs)(`header`,{className:`mobile-topbar`,inert:s,children:[(0,z.jsx)(`button`,{ref:l,type:`button`,className:`menu-toggle`,onClick:()=>c(e=>!e),"aria-expanded":s,"aria-controls":`app-sidebar`,"aria-label":o(s?`nav.closeMenu`:`nav.openMenu`),title:o(s?`nav.closeMenu`:`nav.openMenu`),children:(0,z.jsx)(ee,{})}),E,(0,z.jsx)(`button`,{type:`button`,className:`theme-toggle stop-toggle`,onClick:T,disabled:g,"aria-label":o(`dash.stop`),title:o(`dash.stop`),children:(0,z.jsx)(ve,{})})]}),s&&(0,z.jsx)(`div`,{className:`drawer-scrim`,onClick:()=>c(!1),"aria-hidden":`true`}),(0,z.jsxs)(`aside`,{id:`app-sidebar`,className:`sidebar${s?` open`:``}`,ref:u,tabIndex:-1,children:[(0,z.jsxs)(`div`,{className:`drawer-head`,children:[E,(0,z.jsx)(`button`,{type:`button`,className:`menu-toggle drawer-close`,onClick:()=>c(!1),"aria-label":o(`nav.closeMenu`),title:o(`nav.closeMenu`),children:(0,z.jsx)(ie,{})})]}),(0,z.jsx)(`nav`,{children:Bf.map(({id:n,tkey:r,Icon:i})=>(0,z.jsxs)(`div`,{className:`nav-entry${n===`claude`?` nav-entry-claude${e===n?` active`:``}`:``}`,children:[(0,z.jsxs)(`button`,{type:`button`,className:`nav-item${e===n?` active`:``}`,"data-page":n,onClick:()=>{t(n),c(!1)},"aria-current":e===n?`page`:void 0,children:[(0,z.jsx)(i,{}),` `,o(r)]}),n===`claude`&&b!==null&&(0,z.jsx)(rt,{on:b,onClick:()=>void w(),disabled:S,label:o(`claude.toggleAria`)})]},n))}),(0,z.jsxs)(`div`,{className:`sidebar-foot`,children:[(0,z.jsxs)(`div`,{className:`lang-toggle`,children:[(0,z.jsx)(De,{"aria-hidden":!0}),(0,z.jsx)(it,{value:i,options:Fe.map(e=>({value:e.code,label:e.name})),onChange:e=>a(e),label:o(`lang.label`),placement:`right`,portal:!1,style:{flex:1,minWidth:0,width:`100%`}})]}),(0,z.jsxs)(`button`,{type:`button`,className:`theme-toggle`,onClick:p,"aria-label":`${o(`theme.label`)}: ${o(Hf[n])}`,title:`${o(`theme.label`)}: ${o(Hf[n])}`,children:[(0,z.jsx)(m,{}),` `,(0,z.jsx)(`span`,{className:`mode`,children:o(Hf[n])})]}),(0,z.jsxs)(`button`,{type:`button`,className:`theme-toggle stop-toggle`,onClick:T,disabled:g,"aria-label":o(`dash.stop`),title:o(`dash.stop`),children:[(0,z.jsx)(ve,{}),` `,(0,z.jsx)(`span`,{className:`mode`,children:o(g?`dash.stopping`:`dash.stop`)})]}),(0,z.jsx)(ef,{apiBase:Rf,onOpenUpdate:()=>{c(!1),t(`dashboard`,`update`)}})]})]}),(0,z.jsx)(`main`,{className:`main`,inert:s,children:(0,z.jsx)(`div`,{className:`main-inner${e===`combos`?` main-inner--combos`:``}`,children:(0,z.jsxs)(Yd,{pageName:o(Lf[e]),title:o(`errorBoundary.title`),message:o(`errorBoundary.message`),detailsLabel:o(`errorBoundary.details`),reloadLabel:o(`errorBoundary.reload`),children:[e===`dashboard`&&(0,z.jsx)(Pn,{apiBase:Rf}),e===`startup`&&(0,z.jsx)(Jd,{apiBase:Rf}),e===`providers`&&(0,z.jsx)(jo,{apiBase:Rf}),e===`models`&&(0,z.jsx)(Ls,{apiBase:Rf}),e===`combos`&&(0,z.jsx)(tc,{apiBase:Rf},Rf),e===`subagents`&&(0,z.jsx)(dc,{apiBase:Rf},Rf),e===`logs`&&(0,z.jsx)(Al,{apiBase:Rf}),e===`usage`&&(0,z.jsx)(Ql,{apiBase:Rf}),e===`storage`&&(0,z.jsx)(hu,{apiBase:Rf}),e===`codex-auth`&&(0,z.jsx)(yu,{apiBase:Rf}),e===`api`&&(0,z.jsx)(Gu,{apiBase:Rf}),e===`claude`&&(0,z.jsx)(kd,{apiBase:Rf}),e===`grok`&&(0,z.jsx)(Fd,{apiBase:Rf})]},e)})})]})}g.createRoot(document.getElementById(`root`)).render((0,z.jsx)(_.StrictMode,{children:(0,z.jsx)(Ve,{children:(0,z.jsx)(Gf,{})})}));
|
package/gui/dist/index.html
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
} catch (e) {}
|
|
17
17
|
})();
|
|
18
18
|
</script>
|
|
19
|
-
<script type="module" crossorigin src="/assets/index-
|
|
19
|
+
<script type="module" crossorigin src="/assets/index-CuVjugeE.js"></script>
|
|
20
20
|
<link rel="stylesheet" crossorigin href="/assets/index-CHwf3tTD.css">
|
|
21
21
|
</head>
|
|
22
22
|
<body>
|
package/package.json
CHANGED
|
@@ -109,29 +109,19 @@ export function catalogEntryEfforts(entry: RawEntry): string[] {
|
|
|
109
109
|
|
|
110
110
|
export const ROUTED_REASONING_LEVELS = [...CODEX_REASONING_LEVELS];
|
|
111
111
|
|
|
112
|
-
export function applyCatalogModelMetadata(
|
|
113
|
-
entry: RawEntry,
|
|
114
|
-
model?: CatalogModel,
|
|
115
|
-
fallbackDisplayName?: string,
|
|
116
|
-
): void {
|
|
112
|
+
export function applyCatalogModelMetadata(entry: RawEntry, model?: CatalogModel): void {
|
|
117
113
|
if (!model) return;
|
|
118
114
|
// This marker survives strict catalog normalization and lets sync distinguish a stale
|
|
119
115
|
// bare combo alias from a genuine native model row.
|
|
120
116
|
if (model.provider === COMBO_NAMESPACE) entry.owned_by = model.owned_by ?? COMBO_NAMESPACE;
|
|
121
117
|
// displayName is DISPLAY-ONLY: it relabels the picker row but never touches the routing
|
|
122
|
-
// slug, alias, or provider.
|
|
123
|
-
//
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
118
|
+
// slug, alias, or provider. deriveEntry already stamped the slug as display_name; a
|
|
119
|
+
// configured displayName overrides just the label. The `/` separator is rejected at every
|
|
120
|
+
// input boundary (CLI `ocx models add`, management API), so the catalog trusts its source.
|
|
121
|
+
// Combos carry no displayName, and natives never reach here (no CatalogModel), so genuine
|
|
122
|
+
// upstream marketing names and combo alias labels are preserved untouched.
|
|
127
123
|
const displayName = typeof model.displayName === "string" ? model.displayName.trim() : "";
|
|
128
124
|
if (displayName) entry.display_name = displayName;
|
|
129
|
-
else if (!model.alias) {
|
|
130
|
-
const nativeId = model.id.trim();
|
|
131
|
-
const finalSegment = nativeId.slice(nativeId.lastIndexOf("/") + 1).trim();
|
|
132
|
-
const fallback = fallbackDisplayName?.trim() || finalSegment;
|
|
133
|
-
if (fallback) entry.display_name = fallback;
|
|
134
|
-
}
|
|
135
125
|
if (typeof model.contextWindow === "number" && model.contextWindow > 0) {
|
|
136
126
|
entry.context_window = model.contextWindow;
|
|
137
127
|
entry.max_context_window = model.contextWindow;
|
|
@@ -92,9 +92,7 @@ export interface CatalogModel {
|
|
|
92
92
|
/**
|
|
93
93
|
* Display-only Codex catalog `display_name` override. Relabels the picker row ONLY — it never
|
|
94
94
|
* affects the routing slug, alias-collision order, native marketing-name precedence, or provider
|
|
95
|
-
* behavior. When unset,
|
|
96
|
-
* provider namespace does not crowd the picker; basename collisions retain enough route context
|
|
97
|
-
* to stay distinguishable, and aliased combo rows keep their public alias.
|
|
95
|
+
* behavior. When unset, the entry falls back to its Codex-facing slug (the historical behavior).
|
|
98
96
|
* Native upstream entries (e.g. gpt-5.6-sol → "GPT-5.6-Sol") come from the pinned snapshot path
|
|
99
97
|
* which carries no CatalogModel, so a configured displayName can never override a native name.
|
|
100
98
|
*/
|
|
@@ -166,7 +166,6 @@ export function deriveEntry(
|
|
|
166
166
|
priority: number,
|
|
167
167
|
model?: CatalogModel,
|
|
168
168
|
exactComboSlugs: ReadonlySet<string> = new Set(),
|
|
169
|
-
fallbackDisplayName?: string,
|
|
170
169
|
): RawEntry {
|
|
171
170
|
const preserveExact = isExactComboCatalogModel(model, exactComboSlugs);
|
|
172
171
|
const isRouted = model !== undefined;
|
|
@@ -203,7 +202,7 @@ export function deriveEntry(
|
|
|
203
202
|
applyReasoningLevels(e, model?.reasoningEfforts, model?.defaultReasoningEffort, preserveExact);
|
|
204
203
|
normalizeRoutedCatalogEntry(e, model?.parallelToolCalls === true);
|
|
205
204
|
if (model) applyJawcodeCatalogMetadata(e, model.provider, model.id, model.contextCap);
|
|
206
|
-
applyCatalogModelMetadata(e, model
|
|
205
|
+
applyCatalogModelMetadata(e, model);
|
|
207
206
|
} else {
|
|
208
207
|
applyNativeOpenAiContextOverride(e);
|
|
209
208
|
if (isGpt56NativeSlug(slug)) ensureGpt56ReasoningLevels(e);
|
|
@@ -240,7 +239,7 @@ export function deriveEntry(
|
|
|
240
239
|
if (isGpt56NativeSlug(slug)) ensureGpt56ReasoningLevels(entry);
|
|
241
240
|
}
|
|
242
241
|
if (model && isRouted) applyJawcodeCatalogMetadata(entry, model.provider, model.id, model.contextCap);
|
|
243
|
-
applyCatalogModelMetadata(entry, model
|
|
242
|
+
applyCatalogModelMetadata(entry, model);
|
|
244
243
|
if (!isRouted) applyNativeOpenAiContextOverride(entry);
|
|
245
244
|
return ensureStrictCatalogFields(normalizeServiceTiers(entry), {
|
|
246
245
|
preserveExactInputModalities: preserveExact,
|
|
@@ -248,50 +247,6 @@ export function deriveEntry(
|
|
|
248
247
|
});
|
|
249
248
|
}
|
|
250
249
|
|
|
251
|
-
function configuredDisplayName(model: CatalogModel): string {
|
|
252
|
-
return typeof model.displayName === "string" ? model.displayName.trim() : "";
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function defaultPickerLabel(model: CatalogModel): string {
|
|
256
|
-
const nativeId = model.id.trim();
|
|
257
|
-
return nativeId.slice(nativeId.lastIndexOf("/") + 1).trim();
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Keep the common picker path compact, but retain only as much route context as needed when two
|
|
262
|
-
* emitted rows would otherwise have the same label. Explicit display names and combo aliases are
|
|
263
|
-
* author-owned and never rewritten. If distinct native ids share a basename, the native id is
|
|
264
|
-
* enough; if the same native id is exposed by multiple providers, append the provider as well.
|
|
265
|
-
*/
|
|
266
|
-
function routedFallbackDisplayNames(models: readonly CatalogModel[]): Map<CatalogModel, string> {
|
|
267
|
-
const intendedLabel = (model: CatalogModel): string =>
|
|
268
|
-
configuredDisplayName(model) || model.alias?.trim() || defaultPickerLabel(model);
|
|
269
|
-
const labelCounts = new Map<string, number>();
|
|
270
|
-
const nativeIdCounts = new Map<string, number>();
|
|
271
|
-
for (const model of models) {
|
|
272
|
-
const label = intendedLabel(model);
|
|
273
|
-
if (!label) continue;
|
|
274
|
-
labelCounts.set(label, (labelCounts.get(label) ?? 0) + 1);
|
|
275
|
-
const nativeKey = `${label}\u0000${model.id.trim()}`;
|
|
276
|
-
nativeIdCounts.set(nativeKey, (nativeIdCounts.get(nativeKey) ?? 0) + 1);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
const out = new Map<CatalogModel, string>();
|
|
280
|
-
for (const model of models) {
|
|
281
|
-
if (configuredDisplayName(model) || model.alias) continue;
|
|
282
|
-
const label = defaultPickerLabel(model);
|
|
283
|
-
if (!label) continue;
|
|
284
|
-
if ((labelCounts.get(label) ?? 0) <= 1) {
|
|
285
|
-
out.set(model, label);
|
|
286
|
-
continue;
|
|
287
|
-
}
|
|
288
|
-
const nativeId = model.id.trim();
|
|
289
|
-
const sameNativeIdCount = nativeIdCounts.get(`${label}\u0000${nativeId}`) ?? 0;
|
|
290
|
-
out.set(model, sameNativeIdCount > 1 ? `${nativeId} (${model.provider})` : nativeId);
|
|
291
|
-
}
|
|
292
|
-
return out;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
250
|
export function buildCatalogEntries(
|
|
296
251
|
template: RawEntry | null,
|
|
297
252
|
gptSlugs: string[],
|
|
@@ -316,28 +271,22 @@ export function buildCatalogEntries(
|
|
|
316
271
|
if (rank.has(slug)) e.priority = rank.get(slug)!;
|
|
317
272
|
out.push(e);
|
|
318
273
|
}
|
|
319
|
-
const
|
|
320
|
-
if (collisionSkipped.has(m))
|
|
274
|
+
for (const m of goModels) {
|
|
275
|
+
if (collisionSkipped.has(m)) continue;
|
|
321
276
|
const slug = catalogModelSlug(m);
|
|
322
277
|
if (m.provider !== COMBO_NAMESPACE && comboPublicSlugs.has(slug)) {
|
|
323
278
|
warnComboMasqueradeCollisionOnce(slug);
|
|
324
|
-
|
|
279
|
+
continue;
|
|
325
280
|
}
|
|
326
|
-
return true;
|
|
327
|
-
});
|
|
328
|
-
const fallbackDisplayNames = routedFallbackDisplayNames(routedModels);
|
|
329
|
-
for (const m of routedModels) {
|
|
330
|
-
const slug = catalogModelSlug(m);
|
|
331
281
|
// Provider rows use the one-slash slug codec; combo aliases intentionally override that
|
|
332
282
|
// public slug and may be bare.
|
|
333
283
|
const e = deriveEntry(
|
|
334
284
|
template,
|
|
335
285
|
slug,
|
|
336
|
-
`Routed via opencodex → ${
|
|
286
|
+
`Routed via opencodex → ${m.provider} (${m.owned_by ?? m.provider}).`,
|
|
337
287
|
5,
|
|
338
288
|
m,
|
|
339
289
|
exactComboSlugs,
|
|
340
|
-
fallbackDisplayNames.get(m),
|
|
341
290
|
);
|
|
342
291
|
// Featured picks may be stored raw (legacy) or encoded — honor both.
|
|
343
292
|
const rankHit = rank.get(slug) ?? rank.get(`${m.provider}/${m.id}`);
|