@cortexkit/opencode-openai-auth 1.9.5 → 1.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +2 -2
- package/dist/{index-f1cqptqa.js → index-3mmdgz6r.js} +1 -1
- package/dist/{index-8rj2xddq.js → index-5xs8nfcx.js} +23 -23
- package/dist/{index-npj40h62.js → index-7bv7pgy8.js} +1 -1
- package/dist/{index-1nrre3d8.js → index-jqqeynjm.js} +1 -1
- package/dist/{index-h3vtzckv.js → index-qn927h9w.js} +1 -1
- package/dist/{index-7qxa018z.js → index-se7mn1wg.js} +1 -1
- package/dist/{index-41yn5c02.js → index-t52k32ab.js} +1 -1
- package/dist/{index-4gnwkw3a.js → index-tcaef7wq.js} +1 -1
- package/dist/{index-s2vrkdj4.js → index-x8qjasc7.js} +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/tui-preferences.js +1 -1
- package/dist/v2/server.js +2 -2
- package/package.json +4 -4
- /package/dist/{index-mcy24ej8.js → index-1kbr03m0.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Cf as c,rf as U,sf as E,wf as F,xf as p,yf as L}from"./index-
|
|
1
|
+
import{Cf as c,rf as U,sf as E,wf as F,xf as p,yf as L}from"./index-1kbr03m0.js";import{createHash as Cz,randomUUID as y}from"node:crypto";import{chmod as zz,mkdir as Gz,open as Jz,readdir as b,rename as Kz,rmdir as Nz,stat as S,unlink as T}from"node:fs/promises";import{uptime as Qz}from"node:os";import{join as R,resolve as g}from"node:path";function x(z){return(z.now??Date.now)()-(z.uptime??Qz)()*1000-300000}function k(z,G,Q){let V=z.startedAt===void 0?G?.mtimeMs:z.startedAt;return typeof V==="number"&&Number.isFinite(V)&&V<Q}async function Vz(z,G,Q,V){if(!Q)return;await V?.(z);try{let J=await L(z),K=await S(z);if(J===G&&K.dev===Q.dev&&K.ino===Q.ino&&K.mtimeMs===Q.mtimeMs&&K.size===Q.size)await T(z).catch(()=>{})}catch(J){if(J instanceof E&&J.code!=="ENOENT")throw J}}function a(z){return typeof z==="number"&&Number.isSafeInteger(z)&&z>0}function u(z){if(!a(z))return!1;try{return process.kill(z,0),!0}catch(G){return G.code==="EPERM"}}function Uz(z){return(G)=>Wz(G,z)}function Wz(z,G){if(/^[0-9a-f]{16}$/.test(z))return!0;return z.startsWith(G)&&/^[0-9a-f]{16}$/.test(z.slice(G.length))}function Xz(z){let G=/^port-(\d+)\.json$/.exec(z);return G?Number(G[1]):void 0}function s(z,G){if(z===null||typeof z!=="object"||Array.isArray(z))return!1;let{pid:Q,port:V,token:J}=z;return a(Q)&&Xz(G)===Q&&typeof V==="number"&&Number.isInteger(V)&&V>=1&&V<=65535&&typeof J==="string"&&J.length>0}async function l(z,G){G?.debug("rpc corrupt port file",{pid:process.pid,portFile:z}),await T(z).catch(()=>{})}async function Ez(z,G,Q={}){let V=async()=>{let J=R(z,`port-${G.pid}.json`);if(U)return await p(z,Q.secureDir??!1),await Q.beforeWrite?.(),await c(J,JSON.stringify({...G,startedAt:Date.now()}),{stagePath:`${J}.${(Q.stageName??y)()}.tmp`}),J;if(await Gz(z,{recursive:!0,mode:Q.secureDir?448:void 0}),Q.secureDir)await zz(z,448);await Q.beforeWrite?.();let K={...G,startedAt:Date.now()},Y=`${J}.${(Q.stageName??y)()}.tmp`,W,N=!1;try{W=await Jz(Y,"wx",384),N=!0,await W.writeFile(JSON.stringify(K),"utf8"),await W.chmod(384),await W.close(),W=void 0,await Kz(Y,J),N=!1}finally{if(await W?.close().catch(()=>{}),N)await T(Y).catch(()=>{})}return J};try{return await V()}catch(J){if(J.code==="ENOENT")return await V();throw J}}async function Lz(z,G,Q,V,J={}){let K=x(J),Y;try{Y=await b(z,{withFileTypes:!0})}catch(N){if(N.code==="ENOENT")return;throw N}let W=g(G);for(let N of Y){if(!N.isDirectory()||!Q(N.name))continue;let X=R(z,N.name),Z;try{Z=await b(X)}catch($){if($.code==="ENOENT")continue;throw $}for(let $ of Z){if(!$.startsWith("port-")||!$.endsWith(".json"))continue;let H=R(X,$),C=await S(H).catch(()=>{return}),q;try{q=await L(H)}catch(O){if(O instanceof E&&O.code!=="ENOENT")throw O;continue}if(q===void 0)continue;let A;try{A=JSON.parse(q)}catch{await l(H,V);continue}if(!s(A,$)){await l(H,V);continue}let I=A;if(!u(I.pid))await T(H).catch(()=>{});else if(k(I,C,K))await Vz(H,q,C,J.beforeRemove)}if(g(X)!==W)await Nz(X).catch(()=>{})}}async function d(z,G,Q={}){let V=x(Q);if(!u(G.pid))return null;let J=R(g(z),`port-${G.pid}.json`);try{if(U)await F(J,"file");let K=await S(J);if(k(G,K,V))return null;return`${J}:${K.dev}:${K.ino}:${K.mtimeMs}:${K.size}`}catch(K){if(K instanceof E&&K.code!=="ENOENT")throw K;return null}}async function n(z,G,Q={}){let V=x(Q),J;try{if(U)await F(z,"directory");J=await b(z)}catch(X){if(X instanceof E&&X.code!=="ENOENT")throw X;return null}let K=[];for(let X of J){if(!X.startsWith("port-")||!X.endsWith(".json"))continue;try{let Z=JSON.parse(await L(R(z,X)));if(s(Z,X))if(u(Z.pid)){let $=Z.startedAt===void 0?await S(R(z,X)).catch(()=>{return}):void 0;if(!k(Z,$,V))K.push(Z)}else await T(R(z,X)).catch(()=>{})}catch(Z){if(Z instanceof E&&Z.code!=="ENOENT")throw Z}}if(K.length===0)return null;let Y=G!==void 0&&G>=1?K.filter((X)=>X.pid===G):[];if(Q.exactPid===!0&&Y.length===0)return null;let W=Y.length>0?Y:K,N=(X)=>typeof X.startedAt==="number"&&Number.isFinite(X.startedAt)?X.startedAt:-1/0;return W.sort((X,Z)=>N(Z)-N(X))[0]??null}import{open as Yz}from"node:fs/promises";import{connect as Zz}from"node:net";import{join as $z,resolve as t}from"node:path";var e=2000,_=new Map,B=new Map;async function Hz(z,G){let Q=$z(t(z),`port-${G.pid}.json`);if(U){let J=JSON.parse(await L(Q));if(J.pid!==G.pid||J.port!==G.port||J.token!==G.token)return null;return null}let V;try{V=await Yz(Q,"r");let J=await V.stat(),K=JSON.parse(await V.readFile("utf8"));if(K.pid!==G.pid||K.port!==G.port||K.token!==G.token)return null;return`${Q}:${J.dev}:${J.ino}:${J.mtimeMs}:${J.size}`}catch{return null}finally{await V?.close().catch(()=>{})}}async function i(z,G,Q,V){let J=_.get(z);if(!U&&J&&await d(G,J.entry)===J.identity)return J;_.delete(z);let K=B.get(z);if(K)return K;let Y=(async()=>{let W=await(V.discover??n)(G,Q,V);if(!W)return null;let N=await Hz(G,W);if(!N)return{entry:W,identity:""};let X={entry:W,identity:N};return _.set(z,X),X})();B.set(z,Y);try{return await Y}finally{if(B.get(z)===Y)B.delete(z)}}async function o(z,G,Q,V=e){return new Promise((J)=>{let K,Y=!1,W=!1,N=(Z,$=!1)=>{if(Y)return;Y=!0,clearTimeout(X),K?.destroy(),J({value:Z,stale:$})},X=setTimeout(()=>N(null),V);try{let Z=JSON.stringify(Q);K=Zz({host:"127.0.0.1",port:z.port}),K.on("connect",()=>{W=!0,K?.write(`POST /rpc/${G} HTTP/1.0\r
|
|
2
2
|
Host: 127.0.0.1:${z.port}\r
|
|
3
3
|
Connection: close\r
|
|
4
4
|
Content-Type: application/json\r
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{Je as d,Me as y,Ne as Q3,Oe as V$,Pe as U3,Qe as V3}from"./index-41yn5c02.js";import{hf as u$,if as A,kf as s6,of as U6}from"./index-s2vrkdj4.js";import{Cf as W4,rf as Z0,sf as g0,vf as K4,xf as S3,yf as T$}from"./index-mcy24ej8.js";var L="all",t$=Object.freeze(["primary"]);function UZ($){return $.kind==="retired"?$.retiredAt:$.checkedAt}function x0($,Z){return JSON.stringify([$,Z])}function n($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function S($){return typeof $==="number"&&Number.isFinite($)}function QZ($){return typeof $==="string"&&$.length>0}function T($,Z,z){return $[Z]===void 0||z($[Z])}function o6($){return S($)&&$>0}function r$($){return typeof $==="string"}function r6($){if(!n($)||!QZ($.scope)||!QZ($.label))return!1;switch($.kind){case"reading":return S($.checkedAt)&&S($.usedPercent)&&T($,"resetsAt",r$)&&T($,"windowMinutes",o6);case"retired":return S($.retiredAt);case"absent":return S($.checkedAt);default:return!1}}function t6($){if(!n($)||!S($.checkedAt))return!1;if($.kind==="cleared")return!0;return $.kind==="reading"&&typeof $.reached==="boolean"&&T($,"remainingPercent",S)&&T($,"usedPercent",S)&&T($,"resetsAt",r$)&&T($,"limit",S)&&T($,"used",S)&&T($,"remaining",S)&&T($,"unit",r$)}function VZ($){return n($)&&S($.value)&&Number.isInteger($.value)&&$.value>=0&&S($.checkedAt)}function e$($){return n($)&&Object.values($).every(VZ)}function e6($){return typeof $==="boolean"}function l($){return n($)&&typeof $.hasCredits==="boolean"&&typeof $.unlimited==="boolean"&&T($,"balance",S)&&T($,"overageLimitReached",e6)&&S($.checkedAt)}function $3($){if(!n($))return;let Z=Object.entries($).filter(([,z])=>VZ(z));return Z.length===0?void 0:Object.fromEntries(Z)}function K0($){if(H0($))return $;if(!n($))return;let{counters:Z,credits:z,...X}=$;if(!H0(X))return;let Y=$3(Z),G=l(z)?z:void 0;return{...X,...Y===void 0?{}:{counters:Y},...G===void 0?{}:{credits:G}}}function H0($){if(!n($)||!Array.isArray($.limits))return!1;let Z=new Set;for(let z of $.limits){if(!r6(z))return!1;let X=x0(z.scope,z.label);if(Z.has(X))return!1;Z.add(X)}return T($,"budget",t6)&&T($,"counters",e$)&&T($,"credits",l)}var MZ=900000,_Z="no quota reading yet",jZ="no limits reported";function OZ($){let Z=Math.max(1,Math.floor($/60000));if(Z<60)return`${Z}m`;if(Z<1440){let Y=Math.floor(Z/60),G=Z%60;return G===0?`${Y}h`:`${Y}h${G}m`}let z=Math.floor(Z/1440),X=Math.floor(Z%1440/60);return X===0?`${z}d`:`${z}d${X}h`}function PZ($){if($%1440===0)return`${$/1440}d`;if($%60===0)return`${$/60}h`;return`${$}m`}function Z3($){if($.scope!==L||$.windowMinutes===void 0)return $.label;return PZ($.windowMinutes)}function z3($){return Math.min(100,Math.max(0,$))}function G$($){return Math.round(z3($))}function DZ($){return`${G$($)}% left`}function FZ($,Z,z){let X=$===void 0?Number.NaN:Date.parse($);return{...Number.isFinite(X)&&X>z?{resetIn:OZ(X-z)}:{},resetSinceReading:Number.isFinite(X)&&X>Z&&X<=z}}function $8($,Z){let z=$.windowMinutes,X=Z.windowMinutes;if(z!==void 0&&X!==void 0&&z!==X)return z-X;if(z===void 0!==(X===void 0))return z===void 0?1:-1;if($.scope!==Z.scope){if($.scope===L)return-1;if(Z.scope===L)return 1;return $.scope<Z.scope?-1:1}return $.label<Z.label?-1:$.label>Z.label?1:0}function Z8($){let Z=LZ($.filter(({part:z,scope:X})=>z.kind==="window"&&X!==L).map(({scope:z})=>z));for(let z of $)z.part.short=z.part.kind==="budget"?"cr":z.scope===L?z.part.name:Z.get(z.scope)??z.scope;return $}function qZ($){return Number.isFinite($.remainingPercent)&&Number.isFinite($.checkedAt)}function X3($,Z,z=!1){if(!$)return{windows:[]};let{now:X}=Z,G=$.limits.filter((H)=>H.kind==="reading"&&(z||qZ(H))).sort($8).map((H)=>{let Q=qZ(H)?{kind:"window",reading:"known",name:Z3(H),short:"",figure:DZ(H.remainingPercent),remainingPercent:z3(H.remainingPercent),checkedAt:H.checkedAt,...FZ(H.resetsAt,H.checkedAt,X)}:{kind:"window",reading:"unknown",name:Z3(H),short:"",figure:"no reading",resetSinceReading:!1};return{scope:H.scope,...H.windowMinutes===void 0?{}:{windowMinutes:H.windowMinutes},part:Q}}),J=$.budget;if(J){let H=J.remainingPercent,Q=J.reached?"credits spent":H!==void 0?`credits ${DZ(H)}`:"credits available";G.push({scope:L,spent:J.reached,part:{kind:"budget",reading:"known",name:"credits",short:"",figure:Q,...H===void 0?{}:{remainingPercent:z3(H)},checkedAt:J.checkedAt,...FZ(J.resetsAt,J.checkedAt,X)}})}Z8(G);let B=G.flatMap(({part:H})=>H.reading==="known"&&H.checkedAt!==void 0?[H.checkedAt]:[]);if(B.length>0){let H=X-Math.min(...B);if(H>(Z.staleAfterMs??MZ))return{windows:G,age:`checked ${OZ(H)} ago`}}return{windows:G}}function z8($,Z){return X3($,Z).age!==void 0}function NZ($){let Z=$.slice($.indexOf(":")+1);return Z.charAt(0).toUpperCase()+Z.slice(1)}function LZ($){let Z=[...new Set($.map(NZ))],z=new Map(Z.map((Y)=>[Y,2])),X=(Y)=>Y.slice(0,z.get(Y));for(;;){let Y=new Map;for(let J of Z)Y.set(X(J),[...Y.get(X(J))??[],J]);let G=!1;for(let J of Y.values()){if(J.length<2)continue;for(let B of J){let H=z.get(B)??2;if(H<B.length)z.set(B,H+1),G=!0}}if(!G)break}return new Map($.map((Y)=>[Y,X(NZ(Y))]))}var X8=2;function Y8($){let Z=$.map((X)=>X.label.trim()||X.scope),z=LZ(Z);return Z.map((X)=>z.get(X)??X)}function J8($,Z){if(!$||$.length===0)return;let z=Z.filter(({part:B})=>B.kind==="window");if(z.some(({scope:B})=>B===L))return;let X=$.flatMap((B,H)=>{let K=z.filter(({scope:W})=>W===B.scope).reduce((W,D)=>W===void 0||(D.part.remainingPercent??0)<(W.part.remainingPercent??0)?D:W,void 0);return K?[{group:B,listed:H,window:K}]:[]});if(X.length===0)return;let Y=Y8($),G=(B)=>B.window.part.remainingPercent??0,J=[...X].sort((B,H)=>G(B)-G(H)||B.listed-H.listed).slice(0,X8).sort((B,H)=>B.listed-H.listed);return J.map((B,H)=>{let{windowMinutes:Q}=B.window,K=[Y[B.listed]??B.group.scope,...Q===void 0?[]:[PZ(Q)],`${G$(G(B))}%`].join(" ");return H===J.length-1?`${K} left`:K})}function G8($,Z){let{windows:z}=X3($,Z),X=J8($?.groups,z);if(X)return X;let Y=z.filter(({part:W,scope:D})=>W.kind==="window"&&D===L),G=z.filter(({part:W,scope:D})=>W.kind==="window"&&D!==L),J=z.find(({part:W})=>W.kind==="budget"),B=J?.spent?0:J?.part.remainingPercent,Q=[...G.map(({part:W})=>({label:W.short,remaining:W.remainingPercent??0})),...B===void 0||J===void 0?[]:[{label:J.part.short,remaining:B}]].reduce((W,D)=>W===void 0||D.remaining<W.remaining?D:W,void 0),K=Y.map(({part:W})=>`${W.name} ${G$(W.remainingPercent??0)}%`);if(Q)K.push(`${Q.label} ${G$(Q.remaining)}%`);if(K.length===0)return z.map(({part:W})=>W.figure);return K.map((W,D)=>D===K.length-1?`${W} left`:W)}function xZ($,Z){if(Z.form==="narrow")return G8($,Z);let{windows:z,age:X}=X3($,Z),Y=(Z.form??"full")==="full",G=z.map(({part:J})=>{let B=Y&&J.resetIn?`, resets ${J.resetIn}`:"";return`${J.kind==="budget"?"":`${J.name} `}${J.figure}${B}`});return X===void 0?G:[...G,X]}function B8($,Z){let z=xZ($,Z);if(z.length>0)return z.join(" · ");return $&&$.limits.length>0?jZ:_Z}function H8($){if($===void 0)return;if($.unlimited)return"Unlimited";if(!$.hasCredits)return;let{balance:Z}=$;return typeof Z==="number"&&Number.isFinite(Z)&&Z>0?`${Math.round(Z)} credits`:"Available"}function K8($){if($.kind==="retired")return{scope:$.scope,label:$.label,kind:"retired",checkedAt:$.retiredAt};if($.kind==="absent")return{scope:$.scope,label:$.label,kind:"absent",checkedAt:$.checkedAt};return{scope:$.scope,label:$.label,kind:"reading",checkedAt:$.checkedAt,usedPercent:$.usedPercent,remainingPercent:100-$.usedPercent,...$.windowMinutes===void 0?{}:{windowMinutes:$.windowMinutes},...$.resetsAt===void 0?{}:{resetsAt:$.resetsAt}}}function W8($,Z){let z=$.windowMinutes!==void 0,X=Z.windowMinutes!==void 0;if(z!==X)return z?-1:1;if(z&&X&&$.windowMinutes!==Z.windowMinutes)return(Z.windowMinutes??0)-($.windowMinutes??0);if($.label!==Z.label)return $.label<Z.label?-1:1;return 0}function Q8($){return{checkedAt:$.checkedAt,reached:$.reached,...$.remainingPercent===void 0?{}:{remainingPercent:$.remainingPercent},...$.resetsAt===void 0?{}:{resetsAt:$.resetsAt}}}function b($,Z=L){let z=new Map;for(let K of $?.limits??[]){if(K.scope!==Z&&K.scope!==L)continue;let W=z.get(K.label);if(W===void 0){z.set(K.label,K);continue}let D=K.scope===L?W:K,V=K.scope===L?K:W;z.set(K.label,D.kind==="reading"?D:V)}let X=[...z.values()].map(K8).sort(W8),Y=X.filter((K)=>K.kind==="reading"),G=Y.length>0?Y:X,J=G.length>0?Math.min(...G.map((K)=>K.checkedAt)):void 0,B=$?.budget?.kind==="reading"?Q8($.budget):void 0,H=$3($?.counters),Q=l($?.credits)?$.credits:void 0;return{scope:Z,limits:X,...J===void 0?{}:{checkedAt:J},...B===void 0?{}:{budget:B},...H===void 0?{}:{counters:H},...Q===void 0?{}:{credits:Q}}}function W0($,Z){let z=$?.budget;if(z?.reached!==!0||typeof z.resetsAt!=="string")return;let X=Date.parse(z.resetsAt);if(!Number.isFinite(X)||X<=Z)return;return{resetsAt:z.resetsAt,resetAtMs:X}}function B$($){return $.kind==="reading"&&typeof $.usedPercent==="number"&&Number.isFinite($.usedPercent)&&$.usedPercent>=100}function h0($,Z){if(typeof $.resetsAt!=="string")return;let z=Date.parse($.resetsAt);return Number.isFinite(z)&&z>Z?z:void 0}class H$ extends TypeError{constructor($){super($);this.name="QuotaCodecError"}}function W$($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function K$($){return typeof $==="number"&&Number.isFinite($)}function RZ($){return $===void 0||typeof $==="string"&&$!==""}function SZ($){return typeof $==="string"&&$!==""}function w0($,Z){return $[Z]===void 0||K$($[Z])}function Y3($,Z){return $[Z]===void 0||typeof $[Z]==="string"}function U8($){return W$($)&&RZ($.scope)&&SZ($.label)&&K$($.usedPercent)&&Y3($,"resetsAt")&&($.windowMinutes===void 0||K$($.windowMinutes)&&$.windowMinutes>0)}function V8($){return W$($)&&RZ($.scope)&&SZ($.label)}function D8($){if(!W$($))return!1;if($.kind==="cleared")return!0;return $.kind==="reading"&&typeof $.reached==="boolean"&&w0($,"remainingPercent")&&w0($,"usedPercent")&&Y3($,"resetsAt")&&w0($,"limit")&&w0($,"used")&&w0($,"remaining")&&Y3($,"unit")}function R0($){if(!W$($)||!K$($.checkedAt))return!1;let Z=$.readings??[],z=$.coverage??[];if(!Array.isArray(Z)||!Array.isArray(z))return!1;let X=new Set;for(let Y of Z){if(!U8(Y))return!1;let G=x0(Y.scope??L,Y.label);if(X.has(G))return!1;X.add(G)}if(!z.every(V8))return!1;return($.budget===void 0||D8($.budget))&&($.counters===void 0||e$($.counters))&&($.credits===void 0||l($.credits))}function F8($,Z){if($.scope!==Z.scope)return $.scope<Z.scope?-1:1;if($.label!==Z.label)return $.label<Z.label?-1:1;return 0}function q8($,Z,z){if(Z===void 0)return $;if($!==void 0&&z<$.checkedAt)return $;return{...Z,checkedAt:z}}function N8($,Z){let z=new Map(Object.entries($??{}));for(let[X,Y]of Object.entries(Z??{})){let G=z.get(X);if(G===void 0||Y.checkedAt>=G.checkedAt)z.set(X,Y)}return z.size===0?void 0:Object.fromEntries(z)}function M8($,Z){if(Z===void 0)return $;if($!==void 0&&Z.checkedAt<$.checkedAt)return $;return{...Z}}function m0($,Z){let z=$===void 0?void 0:K0($);if($!==void 0&&z===void 0)throw new H$("stored quota map is malformed");if(!R0(Z))throw new H$("quota observation is malformed");let X=z??{limits:[]},Y=Z.checkedAt,G=new Map;for(let M of X.limits)G.set(x0(M.scope,M.label),M);let J=(M)=>{let P=G.get(M);return P===void 0||Y>=UZ(P)},B=new Set;for(let M of Z.readings??[]){let P=M.scope??L,x=x0(P,M.label);if(B.add(x),!J(x))continue;G.set(x,{scope:P,label:M.label,kind:"reading",checkedAt:Y,usedPercent:M.usedPercent,...M.resetsAt===void 0?{}:{resetsAt:M.resetsAt},...M.windowMinutes===void 0?{}:{windowMinutes:M.windowMinutes}})}for(let M of Z.coverage??[]){let P=M.scope??L,x=x0(P,M.label);if(B.has(x)||!J(x))continue;let k=G.get(x);G.set(x,k===void 0||k.kind==="absent"?{scope:P,label:M.label,kind:"absent",checkedAt:Y}:{scope:P,label:M.label,kind:"retired",retiredAt:Y})}let{limits:H,budget:Q,counters:K,credits:W,...D}=X,V=q8(X.budget,Z.budget,Y),U=N8(X.counters,Z.counters),_=M8(X.credits,Z.credits);return{...D,limits:[...G.values()].sort(F8),...V===void 0?{}:{budget:V},...U===void 0?{}:{counters:U},..._===void 0?{}:{credits:_}}}var _8=Object.freeze({validate:H0,decode:K0,merge:m0});function TZ($,Z,z){let X=Z.rateLimitMarks?.get($);if(X!==void 0&&z<X)return{id:$,reason:"rate-limited",until:X};let Y=Z.refreshBackoff?.get($);if(Y!==void 0&&z<Y)return{id:$,reason:"refresh-backoff",until:Y};return}function j8($,Z,z,X,Y){if(Z.limits.length===0)return{id:$,stage:1,gate:2,reason:"needs-first-reading",pullRequested:!0};for(let J of z)if(!Z.limits.some((B)=>B.label===J))return{id:$,stage:1,gate:3,reason:"unknown-window",window:{scope:Z.scope,label:J},pullRequested:!0};let G=Z.limits.filter(B$);for(let J of G)if(h0(J,X)===void 0&&!Y.some((B)=>B.scope===J.scope&&B.label===J.label))return{id:$,stage:1,gate:4,reason:"unknown-reset",window:{scope:J.scope,label:J.label},pullRequested:!0};for(let J of G){let B=h0(J,X);if(B!==void 0&&typeof J.resetsAt==="string")return{id:$,stage:1,gate:5,reason:"exhausted",window:{scope:J.scope,label:J.label},resetsAt:J.resetsAt,resetAtMs:B}}return}function v($){let Z=$.scope??L,z=$.requiredLabels??t$,X=[],Y=[],G=[],J=new Set;for(let V of $.rows){let U=TZ(V.id,$,$.now);if(U){X.push(U);continue}if(V.kind==="api-key"){G.push({id:V.id,kind:V.kind});continue}let _=b(V.quota,Z),M=$.liftedWindows?.get(V.id)??[];if(_.limits.some((x)=>B$(x)&&h0(x,$.now)===void 0&&M.some((k)=>k.scope===x.scope&&k.label===x.label)))J.add(V.id);let P=j8(V.id,_,z,$.now,M);if(P){Y.push(P);continue}G.push({id:V.id,kind:V.kind,projection:_})}let B=new Map(G.flatMap((V)=>{let U=W0(V.projection,$.now);return U?[[V.id,U]]:[]})),H=B.size>0&&B.size===G.length,Q=[];for(let V of G){let U=B.get(V.id);if(U===void 0)Q.push(V);else if(H)Q.push({...V,lastPath:!0});else Y.push({id:V.id,stage:2,reason:"budget-spent",...U})}let K=new Map($.rows.map((V,U)=>[V.id,U])),W=(V,U)=>(K.get(V.id)??0)-(K.get(U.id)??0);Y.sort(W);for(let V of Y)if("pullRequested"in V)J.add(V.id);let D=$.rows.filter((V)=>J.has(V.id)).map((V)=>V.id);for(let V of D)$.requestPull?.(V);return{admitted:Q,refused:Y,excluded:X,pulls:D}}var AZ="main";function O8($){switch($){case"sticky-balanced":return{mode:"sticky-balanced",placement:"roster"};case"main-first":return{mode:"ordered",placement:"main-first"};case"fallback-first":return{mode:"ordered",placement:"fallback-first"};default:return{mode:"ordered",placement:"roster"}}}function Q$($,Z,z=AZ){if(Z==="roster"||!$.includes(z))return[...$];let X=$.filter((Y)=>Y!==z);return Z==="main-first"?[z,...X]:[...X,z]}function J3($){let Z=v($),z=new Set(Z.admitted.map((Y)=>Y.id));return{order:Q$($.rows.map((Y)=>Y.id),$.placement??"roster",$.formerMainId).filter((Y)=>z.has(Y)&&$.killswitch?.get(Y)!==!1),admission:Z}}function P8($,Z,z){let X=Z.at(-1);if(X!==void 0){if(X.status===void 0||!z.includes(X.status))return}let Y=new Set(Z.map((G)=>G.id));return $.find((G)=>!Y.has(G))}function G3($,Z,z){if(!Z.has($.accountId))return!1;return!(typeof $.wireIdentity==="string"&&typeof z==="string"&&$.wireIdentity!==z)}function L8($,Z,z){let X=new Map;for(let[Y,G]of $){if(Y===z)continue;if(G.quotaCheckedAt!==Z.get(G.accountId))continue;X.set(G.accountId,(X.get(G.accountId)??0)+(G.inputBytes??0))}return X}var v0=900000,CZ=0.016666666666666666,B3=0.000001;function U$($,Z){for(let z of[$?.checkedAt,Z])if(typeof z==="number"&&Number.isFinite(z))return z;return}function IZ($){if($===401||$===403)return"permanent";if($===void 0||$===0||!Number.isFinite($)||$>=500&&$<=599||$===429)return"transient";return"healthy"}function kZ($){return $.limits.filter((Z)=>Z.kind==="reading").sort((Z,z)=>{let X=Z.windowMinutes!==void 0,Y=z.windowMinutes!==void 0;if(X!==Y)return X?-1:1;if(X&&Y)return(z.windowMinutes??0)-(Z.windowMinutes??0);return 0})}function K3($){let Z=($.classifyStatus??IZ)($.status);if(Z==="permanent")return{action:"migrate",reason:"permanent"};if(!$.quota)return{action:"retain",reason:"unknown"};let z=U$($.quota,$.quotaCheckedAt);if(z===void 0||!Number.isFinite(z)||$.now-z>v0)return{action:"retain",reason:"stale"};if($.killswitchPasses===!1)return{action:"migrate",reason:"killswitch"};for(let Y of kZ($.quota)){let G=Y.remainingPercent;if(typeof G==="number"&&Number.isFinite(G)&&G<=0)return{action:"migrate",reason:"exhausted",window:{scope:Y.scope,label:Y.label},...typeof Y.resetsAt==="string"?{resetsAt:Y.resetsAt}:{}}}let X=W0($.quota,$.now);if(X)return{action:"migrate",reason:"exhausted",resetsAt:X.resetsAt};return{action:"retain",reason:Z}}function H3($,Z,z){let X=Math.max(0,$.remainingPercent-Z);if(X<=0)return 0;if(!$.resetsAt)return X;let Y=Date.parse($.resetsAt);if(!Number.isFinite(Y)||Y<=z)return X;let G=Math.max((Y-z)/3600000,CZ);return X/G}function EZ($,Z){if($<Z)return-1;if($>Z)return 1;return 0}function x8($,Z){if(!$.quota)return;let z=U$($.quota,$.quotaCheckedAt);if(z===void 0||Z-z>v0)return;let X=kZ($.quota).map((J)=>H3({remainingPercent:J.remainingPercent??Number.NaN,...J.resetsAt===void 0?{}:{resetsAt:J.resetsAt}},$.reservePercent[J.label]??0,Z)),Y=$.quota.budget;if(Y&&typeof Y.remainingPercent==="number"&&Number.isFinite(Y.remainingPercent))X.push(H3({remainingPercent:Y.remainingPercent,...Y.resetsAt===void 0?{}:{resetsAt:Y.resetsAt}},0,Z));let G=X.length>0?Math.min(...X):0;return G>0?{candidate:$,quotaCheckedAt:z,weight:G}:void 0}function fZ($){let Z=$.candidates.filter((Y)=>Y.killswitchPasses!==!1);if($.candidates.length===0)throw Error("Cannot select a sticky candidate: input.candidates is empty");if(Z.length===0)return;let z=Z.map((Y)=>x8(Y,$.now)).filter((Y)=>Y!==void 0);if(z.length>0){z.sort((G,J)=>{let B=(($.pendingBytes.get(G.candidate.accountId)??0)+$.requestBytes)/Math.max(G.weight,B3),H=(($.pendingBytes.get(J.candidate.accountId)??0)+$.requestBytes)/Math.max(J.weight,B3);return B-H||G.candidate.configuredOrder-J.candidate.configuredOrder||EZ(G.candidate.accountId,J.candidate.accountId)});let Y=z[0];if(Y)return{accountId:Y.candidate.accountId,quotaCheckedAt:Y.quotaCheckedAt,source:"weighted"}}$.onEmptyWeightedSet?.();let X=[...Z].sort((Y,G)=>{let J=(Y.resetCreditsApplicable??0)>0?1:0;return((G.resetCreditsApplicable??0)>0?1:0)-J||Y.configuredOrder-G.configuredOrder||EZ(Y.accountId,G.accountId)})[0];if(!X)throw Error("Cannot select a sticky candidate: input.candidates is empty");return{accountId:X.accountId,quotaCheckedAt:U$(X.quota,X.quotaCheckedAt),source:"mode-fallback"}}function W3($){let Z=v($),z=new Map(Z.admitted.map((U)=>[U.id,U])),X=new Map(Z.refused.map((U)=>[U.id,U])),Y=new Set(Z.excluded.map((U)=>U.id)),G=new Set($.rows.map((U)=>U.id)),J=$.pin!==void 0&&G3($.pin,G,$.identities?.get($.pin.accountId));if(J&&$.pin){let U=z.get($.pin.accountId);if(U&&$.killswitch?.get(U.id)!==!1)return{outcome:"dispatch",accountId:U.id,source:"pin",...U.projection?.checkedAt===void 0?{}:{quotaCheckedAt:U.projection.checkedAt},pin:{action:"retain"},refusedSelections:[],admission:Z}}let B=$.pin?X.get($.pin.accountId):void 0,H=J&&$.pin!==void 0&&$.refusedPinPolicy==="move-on-confirmed-exhaustion"&&($.killswitch?.get($.pin.accountId)===!1||B?.reason==="exhausted"||B?.reason==="budget-spent"),Q=(U)=>{return(typeof $.rowReservePercent==="function"?$.rowReservePercent(U):$.rowReservePercent?.get(U.id))??$.reservePercent??{}},K=$.scope,W=$.rows.map((U,_)=>({row:U,configuredOrder:_})).filter(({row:U})=>!Y.has(U.id)).map(({row:U,configuredOrder:_})=>{let M=$.killswitch?.get(U.id),P=$.resetCreditsApplicable?.get(U.id);return{accountId:U.id,quota:U.kind==="api-key"?void 0:z.get(U.id)?.projection??b(U.quota,K),reservePercent:Q(U),configuredOrder:_,...P===void 0?{}:{resetCreditsApplicable:P},...M===void 0?{}:{killswitchPasses:M}}}),D=[],V=J?{action:"retain"}:$.pin?{action:"clear"}:{action:"none"};while(W.length>0){let U=fZ({candidates:W,pendingBytes:$.pendingBytes??new Map,requestBytes:$.requestBytes,now:$.now,...$.onEmptyWeightedSet?{onEmptyWeightedSet:$.onEmptyWeightedSet}:{}});if(!U)break;let _=X.get(U.accountId);if(_){D.push(_),W=W.filter((P)=>P.accountId!==U.accountId);continue}let M=$.identities?.get(U.accountId);return{outcome:"dispatch",accountId:U.accountId,source:U.source,...U.quotaCheckedAt===void 0?{}:{quotaCheckedAt:U.quotaCheckedAt},pin:J&&!H?{action:"retain"}:{action:"assign",pin:{accountId:U.accountId,inputBytes:$.requestBytes,...M===void 0?{}:{wireIdentity:M},...U.quotaCheckedAt===void 0?{}:{quotaCheckedAt:U.quotaCheckedAt}}},refusedSelections:D,admission:Z}}return{outcome:"no-admissible-account",pin:V,refusedSelections:D,admission:Z}}import{createHash as R8}from"node:crypto";var S8=86400000,T8=300000,A8=3600000,E8=60000,C8=900000,I8=300000;function D3($){return $ instanceof Error?$.message:String($)}function k8($){let Z=$?.status;if(typeof Z==="number")return Z===429||Z>=500;if(!($ instanceof Error))return!1;return $.name==="AbortError"||$.name==="TimeoutError"||$.message.includes("fetch failed")||"code"in $&&($.code==="ECONNRESET"||$.code==="ECONNREFUSED"||$.code==="ETIMEDOUT"||$.code==="UND_ERR_CONNECT_TIMEOUT")}function F3($){let Z=D3($),z=$?.status;if(typeof z==="number")return z===429||z>=500;if(!($ instanceof Error))return!1;let X=$.code;return $.name==="AbortError"||$.name==="TimeoutError"||Z.includes("fetch failed")||X==="ECONNRESET"||X==="ECONNREFUSED"||X==="ETIMEDOUT"||X==="UND_ERR_CONNECT_TIMEOUT"}function bZ($){return R8("sha256").update($).digest("hex")}function yZ($){let Z=bZ($.refreshToken),X=($.previous?.tokenHash===Z?$.previous.retryCount??0:0)+1,Y,G=$.error?.retryAfter;if(typeof G==="number"&&G>0)Y=G*1000;else if(k8($.error))Y=Math.min(A8,T8*2**Math.min(X-1,6));else Y=S8;return{message:D3($.error),checkedAt:$.now,nextRetryAt:$.now+Y,retryCount:X,tokenHash:Z}}function Q0($,Z,z){if(!$?.nextRetryAt||$.nextRetryAt<=z)return!1;if(!Z)return!0;return $.tokenHash===bZ(Z)}function D$($,Z){return`Codex OAuth refresh is backed off for ${Math.max(1,Math.ceil((($.nextRetryAt??Z)-Z)/1000))}s after: ${$.message}`}function p0($){let z=($.previous?.retryCount??0)+1,X,Y=$.error?.retryAfter;if(typeof Y==="number"&&Y>0)X=Y*1000;else if(F3($.error))X=Math.min(C8,E8*2**Math.min(z-1,6));else X=I8;return{message:D3($.error),checkedAt:$.now,nextRetryAt:$.now+X,retryCount:z}}function S0($,Z){if(!$?.nextRetryAt||$.nextRetryAt<=Z)return!1;return!0}function q3($){if(!$)return;let Z=Number($);if(Number.isFinite(Z)&&Z>0)return Math.ceil(Z);let z=Date.parse($);if(Number.isFinite(z)){let X=Math.ceil((z-Date.now())/1000);return X>0?X:void 0}return}import{createServer as hZ}from"node:http";import{setTimeout as f8}from"node:timers/promises";var M$="app_EMoamEEZ73f0CkXaXp7hrann",D0="https://auth.openai.com",d0=1455,b8=3000,y8="cortexkit-opencode-openai-auth";function gZ($){return`${y8}/${$}`}var pZ="main",h8=`"${pZ}" is a reserved account id; choose a different label.`;function lZ($){let Z=new Uint8Array($),z=String.fromCharCode(...Z);return btoa(z).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function w8(){let Z=Array.from(crypto.getRandomValues(new Uint8Array(43))).map((X)=>"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"[X%66]).join(""),z=lZ(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(Z)));return{verifier:Z,challenge:z}}function wZ($){if($.length>16384)return;let Z=$.split(".");if(Z.length!==3)return;let z=Z[1];if(!z||z.length>8192)return;try{return JSON.parse(Buffer.from(z,"base64url").toString())}catch{return}}function mZ($){let Z=$.chatgpt_account_id;if(typeof Z==="string"&&Z.length>0)return Z;let z=$["https://api.openai.com/auth"];if(z&&typeof z==="object"&&!Array.isArray(z)&&typeof z.chatgpt_account_id==="string"&&z.chatgpt_account_id.length>0)return z.chatgpt_account_id;let X=$.organizations;if(Array.isArray(X)){let Y=X[0];if(Y&&typeof Y==="object"&&!Array.isArray(Y)&&typeof Y.id==="string"&&Y.id.length>0)return Y.id}return}function q$($){if($.id_token){let Z=wZ($.id_token),z=Z&&mZ(Z);if(z)return z}if($.access_token){let Z=wZ($.access_token);return Z?mZ(Z):void 0}return}function m8($){return typeof $==="string"&&$.toLowerCase()===pZ}function N3($){if(m8($))throw Error(h8);return $}function v8($,Z,z){let X=new URLSearchParams({response_type:"code",client_id:M$,redirect_uri:$,scope:"openid profile email offline_access",code_challenge:Z.challenge,code_challenge_method:"S256",id_token_add_organizations:"true",codex_cli_simplified_flow:"true",state:z,originator:"opencode"});return`${D0}/oauth/authorize?${X.toString()}`}async function g8($,Z,z){let X=await fetch(`${D0}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",code:$,redirect_uri:Z,client_id:M$,code_verifier:z.verifier}).toString()});if(!X.ok)throw Error(`Token exchange failed: ${X.status}`);return await X.json()}function p8($){return $.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}var l8=`<!doctype html>
|
|
1
|
+
import{Je as d,Me as y,Ne as Q3,Oe as V$,Pe as U3,Qe as V3}from"./index-t52k32ab.js";import{hf as u$,if as A,kf as s6,of as U6}from"./index-x8qjasc7.js";import{Cf as W4,rf as Z0,sf as g0,vf as K4,xf as S3,yf as T$}from"./index-1kbr03m0.js";var L="all",t$=Object.freeze(["primary"]);function UZ($){return $.kind==="retired"?$.retiredAt:$.checkedAt}function x0($,Z){return JSON.stringify([$,Z])}function n($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function S($){return typeof $==="number"&&Number.isFinite($)}function QZ($){return typeof $==="string"&&$.length>0}function T($,Z,z){return $[Z]===void 0||z($[Z])}function o6($){return S($)&&$>0}function r$($){return typeof $==="string"}function r6($){if(!n($)||!QZ($.scope)||!QZ($.label))return!1;switch($.kind){case"reading":return S($.checkedAt)&&S($.usedPercent)&&T($,"resetsAt",r$)&&T($,"windowMinutes",o6);case"retired":return S($.retiredAt);case"absent":return S($.checkedAt);default:return!1}}function t6($){if(!n($)||!S($.checkedAt))return!1;if($.kind==="cleared")return!0;return $.kind==="reading"&&typeof $.reached==="boolean"&&T($,"remainingPercent",S)&&T($,"usedPercent",S)&&T($,"resetsAt",r$)&&T($,"limit",S)&&T($,"used",S)&&T($,"remaining",S)&&T($,"unit",r$)}function VZ($){return n($)&&S($.value)&&Number.isInteger($.value)&&$.value>=0&&S($.checkedAt)}function e$($){return n($)&&Object.values($).every(VZ)}function e6($){return typeof $==="boolean"}function l($){return n($)&&typeof $.hasCredits==="boolean"&&typeof $.unlimited==="boolean"&&T($,"balance",S)&&T($,"overageLimitReached",e6)&&S($.checkedAt)}function $3($){if(!n($))return;let Z=Object.entries($).filter(([,z])=>VZ(z));return Z.length===0?void 0:Object.fromEntries(Z)}function K0($){if(H0($))return $;if(!n($))return;let{counters:Z,credits:z,...X}=$;if(!H0(X))return;let Y=$3(Z),G=l(z)?z:void 0;return{...X,...Y===void 0?{}:{counters:Y},...G===void 0?{}:{credits:G}}}function H0($){if(!n($)||!Array.isArray($.limits))return!1;let Z=new Set;for(let z of $.limits){if(!r6(z))return!1;let X=x0(z.scope,z.label);if(Z.has(X))return!1;Z.add(X)}return T($,"budget",t6)&&T($,"counters",e$)&&T($,"credits",l)}var MZ=900000,_Z="no quota reading yet",jZ="no limits reported";function OZ($){let Z=Math.max(1,Math.floor($/60000));if(Z<60)return`${Z}m`;if(Z<1440){let Y=Math.floor(Z/60),G=Z%60;return G===0?`${Y}h`:`${Y}h${G}m`}let z=Math.floor(Z/1440),X=Math.floor(Z%1440/60);return X===0?`${z}d`:`${z}d${X}h`}function PZ($){if($%1440===0)return`${$/1440}d`;if($%60===0)return`${$/60}h`;return`${$}m`}function Z3($){if($.scope!==L||$.windowMinutes===void 0)return $.label;return PZ($.windowMinutes)}function z3($){return Math.min(100,Math.max(0,$))}function G$($){return Math.round(z3($))}function DZ($){return`${G$($)}% left`}function FZ($,Z,z){let X=$===void 0?Number.NaN:Date.parse($);return{...Number.isFinite(X)&&X>z?{resetIn:OZ(X-z)}:{},resetSinceReading:Number.isFinite(X)&&X>Z&&X<=z}}function $8($,Z){let z=$.windowMinutes,X=Z.windowMinutes;if(z!==void 0&&X!==void 0&&z!==X)return z-X;if(z===void 0!==(X===void 0))return z===void 0?1:-1;if($.scope!==Z.scope){if($.scope===L)return-1;if(Z.scope===L)return 1;return $.scope<Z.scope?-1:1}return $.label<Z.label?-1:$.label>Z.label?1:0}function Z8($){let Z=LZ($.filter(({part:z,scope:X})=>z.kind==="window"&&X!==L).map(({scope:z})=>z));for(let z of $)z.part.short=z.part.kind==="budget"?"cr":z.scope===L?z.part.name:Z.get(z.scope)??z.scope;return $}function qZ($){return Number.isFinite($.remainingPercent)&&Number.isFinite($.checkedAt)}function X3($,Z,z=!1){if(!$)return{windows:[]};let{now:X}=Z,G=$.limits.filter((H)=>H.kind==="reading"&&(z||qZ(H))).sort($8).map((H)=>{let Q=qZ(H)?{kind:"window",reading:"known",name:Z3(H),short:"",figure:DZ(H.remainingPercent),remainingPercent:z3(H.remainingPercent),checkedAt:H.checkedAt,...FZ(H.resetsAt,H.checkedAt,X)}:{kind:"window",reading:"unknown",name:Z3(H),short:"",figure:"no reading",resetSinceReading:!1};return{scope:H.scope,...H.windowMinutes===void 0?{}:{windowMinutes:H.windowMinutes},part:Q}}),J=$.budget;if(J){let H=J.remainingPercent,Q=J.reached?"credits spent":H!==void 0?`credits ${DZ(H)}`:"credits available";G.push({scope:L,spent:J.reached,part:{kind:"budget",reading:"known",name:"credits",short:"",figure:Q,...H===void 0?{}:{remainingPercent:z3(H)},checkedAt:J.checkedAt,...FZ(J.resetsAt,J.checkedAt,X)}})}Z8(G);let B=G.flatMap(({part:H})=>H.reading==="known"&&H.checkedAt!==void 0?[H.checkedAt]:[]);if(B.length>0){let H=X-Math.min(...B);if(H>(Z.staleAfterMs??MZ))return{windows:G,age:`checked ${OZ(H)} ago`}}return{windows:G}}function z8($,Z){return X3($,Z).age!==void 0}function NZ($){let Z=$.slice($.indexOf(":")+1);return Z.charAt(0).toUpperCase()+Z.slice(1)}function LZ($){let Z=[...new Set($.map(NZ))],z=new Map(Z.map((Y)=>[Y,2])),X=(Y)=>Y.slice(0,z.get(Y));for(;;){let Y=new Map;for(let J of Z)Y.set(X(J),[...Y.get(X(J))??[],J]);let G=!1;for(let J of Y.values()){if(J.length<2)continue;for(let B of J){let H=z.get(B)??2;if(H<B.length)z.set(B,H+1),G=!0}}if(!G)break}return new Map($.map((Y)=>[Y,X(NZ(Y))]))}var X8=2;function Y8($){let Z=$.map((X)=>X.label.trim()||X.scope),z=LZ(Z);return Z.map((X)=>z.get(X)??X)}function J8($,Z){if(!$||$.length===0)return;let z=Z.filter(({part:B})=>B.kind==="window");if(z.some(({scope:B})=>B===L))return;let X=$.flatMap((B,H)=>{let K=z.filter(({scope:W})=>W===B.scope).reduce((W,D)=>W===void 0||(D.part.remainingPercent??0)<(W.part.remainingPercent??0)?D:W,void 0);return K?[{group:B,listed:H,window:K}]:[]});if(X.length===0)return;let Y=Y8($),G=(B)=>B.window.part.remainingPercent??0,J=[...X].sort((B,H)=>G(B)-G(H)||B.listed-H.listed).slice(0,X8).sort((B,H)=>B.listed-H.listed);return J.map((B,H)=>{let{windowMinutes:Q}=B.window,K=[Y[B.listed]??B.group.scope,...Q===void 0?[]:[PZ(Q)],`${G$(G(B))}%`].join(" ");return H===J.length-1?`${K} left`:K})}function G8($,Z){let{windows:z}=X3($,Z),X=J8($?.groups,z);if(X)return X;let Y=z.filter(({part:W,scope:D})=>W.kind==="window"&&D===L),G=z.filter(({part:W,scope:D})=>W.kind==="window"&&D!==L),J=z.find(({part:W})=>W.kind==="budget"),B=J?.spent?0:J?.part.remainingPercent,Q=[...G.map(({part:W})=>({label:W.short,remaining:W.remainingPercent??0})),...B===void 0||J===void 0?[]:[{label:J.part.short,remaining:B}]].reduce((W,D)=>W===void 0||D.remaining<W.remaining?D:W,void 0),K=Y.map(({part:W})=>`${W.name} ${G$(W.remainingPercent??0)}%`);if(Q)K.push(`${Q.label} ${G$(Q.remaining)}%`);if(K.length===0)return z.map(({part:W})=>W.figure);return K.map((W,D)=>D===K.length-1?`${W} left`:W)}function xZ($,Z){if(Z.form==="narrow")return G8($,Z);let{windows:z,age:X}=X3($,Z),Y=(Z.form??"full")==="full",G=z.map(({part:J})=>{let B=Y&&J.resetIn?`, resets ${J.resetIn}`:"";return`${J.kind==="budget"?"":`${J.name} `}${J.figure}${B}`});return X===void 0?G:[...G,X]}function B8($,Z){let z=xZ($,Z);if(z.length>0)return z.join(" · ");return $&&$.limits.length>0?jZ:_Z}function H8($){if($===void 0)return;if($.unlimited)return"Unlimited";if(!$.hasCredits)return;let{balance:Z}=$;return typeof Z==="number"&&Number.isFinite(Z)&&Z>0?`${Math.round(Z)} credits`:"Available"}function K8($){if($.kind==="retired")return{scope:$.scope,label:$.label,kind:"retired",checkedAt:$.retiredAt};if($.kind==="absent")return{scope:$.scope,label:$.label,kind:"absent",checkedAt:$.checkedAt};return{scope:$.scope,label:$.label,kind:"reading",checkedAt:$.checkedAt,usedPercent:$.usedPercent,remainingPercent:100-$.usedPercent,...$.windowMinutes===void 0?{}:{windowMinutes:$.windowMinutes},...$.resetsAt===void 0?{}:{resetsAt:$.resetsAt}}}function W8($,Z){let z=$.windowMinutes!==void 0,X=Z.windowMinutes!==void 0;if(z!==X)return z?-1:1;if(z&&X&&$.windowMinutes!==Z.windowMinutes)return(Z.windowMinutes??0)-($.windowMinutes??0);if($.label!==Z.label)return $.label<Z.label?-1:1;return 0}function Q8($){return{checkedAt:$.checkedAt,reached:$.reached,...$.remainingPercent===void 0?{}:{remainingPercent:$.remainingPercent},...$.resetsAt===void 0?{}:{resetsAt:$.resetsAt}}}function b($,Z=L){let z=new Map;for(let K of $?.limits??[]){if(K.scope!==Z&&K.scope!==L)continue;let W=z.get(K.label);if(W===void 0){z.set(K.label,K);continue}let D=K.scope===L?W:K,V=K.scope===L?K:W;z.set(K.label,D.kind==="reading"?D:V)}let X=[...z.values()].map(K8).sort(W8),Y=X.filter((K)=>K.kind==="reading"),G=Y.length>0?Y:X,J=G.length>0?Math.min(...G.map((K)=>K.checkedAt)):void 0,B=$?.budget?.kind==="reading"?Q8($.budget):void 0,H=$3($?.counters),Q=l($?.credits)?$.credits:void 0;return{scope:Z,limits:X,...J===void 0?{}:{checkedAt:J},...B===void 0?{}:{budget:B},...H===void 0?{}:{counters:H},...Q===void 0?{}:{credits:Q}}}function W0($,Z){let z=$?.budget;if(z?.reached!==!0||typeof z.resetsAt!=="string")return;let X=Date.parse(z.resetsAt);if(!Number.isFinite(X)||X<=Z)return;return{resetsAt:z.resetsAt,resetAtMs:X}}function B$($){return $.kind==="reading"&&typeof $.usedPercent==="number"&&Number.isFinite($.usedPercent)&&$.usedPercent>=100}function h0($,Z){if(typeof $.resetsAt!=="string")return;let z=Date.parse($.resetsAt);return Number.isFinite(z)&&z>Z?z:void 0}class H$ extends TypeError{constructor($){super($);this.name="QuotaCodecError"}}function W$($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function K$($){return typeof $==="number"&&Number.isFinite($)}function RZ($){return $===void 0||typeof $==="string"&&$!==""}function SZ($){return typeof $==="string"&&$!==""}function w0($,Z){return $[Z]===void 0||K$($[Z])}function Y3($,Z){return $[Z]===void 0||typeof $[Z]==="string"}function U8($){return W$($)&&RZ($.scope)&&SZ($.label)&&K$($.usedPercent)&&Y3($,"resetsAt")&&($.windowMinutes===void 0||K$($.windowMinutes)&&$.windowMinutes>0)}function V8($){return W$($)&&RZ($.scope)&&SZ($.label)}function D8($){if(!W$($))return!1;if($.kind==="cleared")return!0;return $.kind==="reading"&&typeof $.reached==="boolean"&&w0($,"remainingPercent")&&w0($,"usedPercent")&&Y3($,"resetsAt")&&w0($,"limit")&&w0($,"used")&&w0($,"remaining")&&Y3($,"unit")}function R0($){if(!W$($)||!K$($.checkedAt))return!1;let Z=$.readings??[],z=$.coverage??[];if(!Array.isArray(Z)||!Array.isArray(z))return!1;let X=new Set;for(let Y of Z){if(!U8(Y))return!1;let G=x0(Y.scope??L,Y.label);if(X.has(G))return!1;X.add(G)}if(!z.every(V8))return!1;return($.budget===void 0||D8($.budget))&&($.counters===void 0||e$($.counters))&&($.credits===void 0||l($.credits))}function F8($,Z){if($.scope!==Z.scope)return $.scope<Z.scope?-1:1;if($.label!==Z.label)return $.label<Z.label?-1:1;return 0}function q8($,Z,z){if(Z===void 0)return $;if($!==void 0&&z<$.checkedAt)return $;return{...Z,checkedAt:z}}function N8($,Z){let z=new Map(Object.entries($??{}));for(let[X,Y]of Object.entries(Z??{})){let G=z.get(X);if(G===void 0||Y.checkedAt>=G.checkedAt)z.set(X,Y)}return z.size===0?void 0:Object.fromEntries(z)}function M8($,Z){if(Z===void 0)return $;if($!==void 0&&Z.checkedAt<$.checkedAt)return $;return{...Z}}function m0($,Z){let z=$===void 0?void 0:K0($);if($!==void 0&&z===void 0)throw new H$("stored quota map is malformed");if(!R0(Z))throw new H$("quota observation is malformed");let X=z??{limits:[]},Y=Z.checkedAt,G=new Map;for(let M of X.limits)G.set(x0(M.scope,M.label),M);let J=(M)=>{let P=G.get(M);return P===void 0||Y>=UZ(P)},B=new Set;for(let M of Z.readings??[]){let P=M.scope??L,x=x0(P,M.label);if(B.add(x),!J(x))continue;G.set(x,{scope:P,label:M.label,kind:"reading",checkedAt:Y,usedPercent:M.usedPercent,...M.resetsAt===void 0?{}:{resetsAt:M.resetsAt},...M.windowMinutes===void 0?{}:{windowMinutes:M.windowMinutes}})}for(let M of Z.coverage??[]){let P=M.scope??L,x=x0(P,M.label);if(B.has(x)||!J(x))continue;let k=G.get(x);G.set(x,k===void 0||k.kind==="absent"?{scope:P,label:M.label,kind:"absent",checkedAt:Y}:{scope:P,label:M.label,kind:"retired",retiredAt:Y})}let{limits:H,budget:Q,counters:K,credits:W,...D}=X,V=q8(X.budget,Z.budget,Y),U=N8(X.counters,Z.counters),_=M8(X.credits,Z.credits);return{...D,limits:[...G.values()].sort(F8),...V===void 0?{}:{budget:V},...U===void 0?{}:{counters:U},..._===void 0?{}:{credits:_}}}var _8=Object.freeze({validate:H0,decode:K0,merge:m0});function TZ($,Z,z){let X=Z.rateLimitMarks?.get($);if(X!==void 0&&z<X)return{id:$,reason:"rate-limited",until:X};let Y=Z.refreshBackoff?.get($);if(Y!==void 0&&z<Y)return{id:$,reason:"refresh-backoff",until:Y};return}function j8($,Z,z,X,Y){if(Z.limits.length===0)return{id:$,stage:1,gate:2,reason:"needs-first-reading",pullRequested:!0};for(let J of z)if(!Z.limits.some((B)=>B.label===J))return{id:$,stage:1,gate:3,reason:"unknown-window",window:{scope:Z.scope,label:J},pullRequested:!0};let G=Z.limits.filter(B$);for(let J of G)if(h0(J,X)===void 0&&!Y.some((B)=>B.scope===J.scope&&B.label===J.label))return{id:$,stage:1,gate:4,reason:"unknown-reset",window:{scope:J.scope,label:J.label},pullRequested:!0};for(let J of G){let B=h0(J,X);if(B!==void 0&&typeof J.resetsAt==="string")return{id:$,stage:1,gate:5,reason:"exhausted",window:{scope:J.scope,label:J.label},resetsAt:J.resetsAt,resetAtMs:B}}return}function v($){let Z=$.scope??L,z=$.requiredLabels??t$,X=[],Y=[],G=[],J=new Set;for(let V of $.rows){let U=TZ(V.id,$,$.now);if(U){X.push(U);continue}if(V.kind==="api-key"){G.push({id:V.id,kind:V.kind});continue}let _=b(V.quota,Z),M=$.liftedWindows?.get(V.id)??[];if(_.limits.some((x)=>B$(x)&&h0(x,$.now)===void 0&&M.some((k)=>k.scope===x.scope&&k.label===x.label)))J.add(V.id);let P=j8(V.id,_,z,$.now,M);if(P){Y.push(P);continue}G.push({id:V.id,kind:V.kind,projection:_})}let B=new Map(G.flatMap((V)=>{let U=W0(V.projection,$.now);return U?[[V.id,U]]:[]})),H=B.size>0&&B.size===G.length,Q=[];for(let V of G){let U=B.get(V.id);if(U===void 0)Q.push(V);else if(H)Q.push({...V,lastPath:!0});else Y.push({id:V.id,stage:2,reason:"budget-spent",...U})}let K=new Map($.rows.map((V,U)=>[V.id,U])),W=(V,U)=>(K.get(V.id)??0)-(K.get(U.id)??0);Y.sort(W);for(let V of Y)if("pullRequested"in V)J.add(V.id);let D=$.rows.filter((V)=>J.has(V.id)).map((V)=>V.id);for(let V of D)$.requestPull?.(V);return{admitted:Q,refused:Y,excluded:X,pulls:D}}var AZ="main";function O8($){switch($){case"sticky-balanced":return{mode:"sticky-balanced",placement:"roster"};case"main-first":return{mode:"ordered",placement:"main-first"};case"fallback-first":return{mode:"ordered",placement:"fallback-first"};default:return{mode:"ordered",placement:"roster"}}}function Q$($,Z,z=AZ){if(Z==="roster"||!$.includes(z))return[...$];let X=$.filter((Y)=>Y!==z);return Z==="main-first"?[z,...X]:[...X,z]}function J3($){let Z=v($),z=new Set(Z.admitted.map((Y)=>Y.id));return{order:Q$($.rows.map((Y)=>Y.id),$.placement??"roster",$.formerMainId).filter((Y)=>z.has(Y)&&$.killswitch?.get(Y)!==!1),admission:Z}}function P8($,Z,z){let X=Z.at(-1);if(X!==void 0){if(X.status===void 0||!z.includes(X.status))return}let Y=new Set(Z.map((G)=>G.id));return $.find((G)=>!Y.has(G))}function G3($,Z,z){if(!Z.has($.accountId))return!1;return!(typeof $.wireIdentity==="string"&&typeof z==="string"&&$.wireIdentity!==z)}function L8($,Z,z){let X=new Map;for(let[Y,G]of $){if(Y===z)continue;if(G.quotaCheckedAt!==Z.get(G.accountId))continue;X.set(G.accountId,(X.get(G.accountId)??0)+(G.inputBytes??0))}return X}var v0=900000,CZ=0.016666666666666666,B3=0.000001;function U$($,Z){for(let z of[$?.checkedAt,Z])if(typeof z==="number"&&Number.isFinite(z))return z;return}function IZ($){if($===401||$===403)return"permanent";if($===void 0||$===0||!Number.isFinite($)||$>=500&&$<=599||$===429)return"transient";return"healthy"}function kZ($){return $.limits.filter((Z)=>Z.kind==="reading").sort((Z,z)=>{let X=Z.windowMinutes!==void 0,Y=z.windowMinutes!==void 0;if(X!==Y)return X?-1:1;if(X&&Y)return(z.windowMinutes??0)-(Z.windowMinutes??0);return 0})}function K3($){let Z=($.classifyStatus??IZ)($.status);if(Z==="permanent")return{action:"migrate",reason:"permanent"};if(!$.quota)return{action:"retain",reason:"unknown"};let z=U$($.quota,$.quotaCheckedAt);if(z===void 0||!Number.isFinite(z)||$.now-z>v0)return{action:"retain",reason:"stale"};if($.killswitchPasses===!1)return{action:"migrate",reason:"killswitch"};for(let Y of kZ($.quota)){let G=Y.remainingPercent;if(typeof G==="number"&&Number.isFinite(G)&&G<=0)return{action:"migrate",reason:"exhausted",window:{scope:Y.scope,label:Y.label},...typeof Y.resetsAt==="string"?{resetsAt:Y.resetsAt}:{}}}let X=W0($.quota,$.now);if(X)return{action:"migrate",reason:"exhausted",resetsAt:X.resetsAt};return{action:"retain",reason:Z}}function H3($,Z,z){let X=Math.max(0,$.remainingPercent-Z);if(X<=0)return 0;if(!$.resetsAt)return X;let Y=Date.parse($.resetsAt);if(!Number.isFinite(Y)||Y<=z)return X;let G=Math.max((Y-z)/3600000,CZ);return X/G}function EZ($,Z){if($<Z)return-1;if($>Z)return 1;return 0}function x8($,Z){if(!$.quota)return;let z=U$($.quota,$.quotaCheckedAt);if(z===void 0||Z-z>v0)return;let X=kZ($.quota).map((J)=>H3({remainingPercent:J.remainingPercent??Number.NaN,...J.resetsAt===void 0?{}:{resetsAt:J.resetsAt}},$.reservePercent[J.label]??0,Z)),Y=$.quota.budget;if(Y&&typeof Y.remainingPercent==="number"&&Number.isFinite(Y.remainingPercent))X.push(H3({remainingPercent:Y.remainingPercent,...Y.resetsAt===void 0?{}:{resetsAt:Y.resetsAt}},0,Z));let G=X.length>0?Math.min(...X):0;return G>0?{candidate:$,quotaCheckedAt:z,weight:G}:void 0}function fZ($){let Z=$.candidates.filter((Y)=>Y.killswitchPasses!==!1);if($.candidates.length===0)throw Error("Cannot select a sticky candidate: input.candidates is empty");if(Z.length===0)return;let z=Z.map((Y)=>x8(Y,$.now)).filter((Y)=>Y!==void 0);if(z.length>0){z.sort((G,J)=>{let B=(($.pendingBytes.get(G.candidate.accountId)??0)+$.requestBytes)/Math.max(G.weight,B3),H=(($.pendingBytes.get(J.candidate.accountId)??0)+$.requestBytes)/Math.max(J.weight,B3);return B-H||G.candidate.configuredOrder-J.candidate.configuredOrder||EZ(G.candidate.accountId,J.candidate.accountId)});let Y=z[0];if(Y)return{accountId:Y.candidate.accountId,quotaCheckedAt:Y.quotaCheckedAt,source:"weighted"}}$.onEmptyWeightedSet?.();let X=[...Z].sort((Y,G)=>{let J=(Y.resetCreditsApplicable??0)>0?1:0;return((G.resetCreditsApplicable??0)>0?1:0)-J||Y.configuredOrder-G.configuredOrder||EZ(Y.accountId,G.accountId)})[0];if(!X)throw Error("Cannot select a sticky candidate: input.candidates is empty");return{accountId:X.accountId,quotaCheckedAt:U$(X.quota,X.quotaCheckedAt),source:"mode-fallback"}}function W3($){let Z=v($),z=new Map(Z.admitted.map((U)=>[U.id,U])),X=new Map(Z.refused.map((U)=>[U.id,U])),Y=new Set(Z.excluded.map((U)=>U.id)),G=new Set($.rows.map((U)=>U.id)),J=$.pin!==void 0&&G3($.pin,G,$.identities?.get($.pin.accountId));if(J&&$.pin){let U=z.get($.pin.accountId);if(U&&$.killswitch?.get(U.id)!==!1)return{outcome:"dispatch",accountId:U.id,source:"pin",...U.projection?.checkedAt===void 0?{}:{quotaCheckedAt:U.projection.checkedAt},pin:{action:"retain"},refusedSelections:[],admission:Z}}let B=$.pin?X.get($.pin.accountId):void 0,H=J&&$.pin!==void 0&&$.refusedPinPolicy==="move-on-confirmed-exhaustion"&&($.killswitch?.get($.pin.accountId)===!1||B?.reason==="exhausted"||B?.reason==="budget-spent"),Q=(U)=>{return(typeof $.rowReservePercent==="function"?$.rowReservePercent(U):$.rowReservePercent?.get(U.id))??$.reservePercent??{}},K=$.scope,W=$.rows.map((U,_)=>({row:U,configuredOrder:_})).filter(({row:U})=>!Y.has(U.id)).map(({row:U,configuredOrder:_})=>{let M=$.killswitch?.get(U.id),P=$.resetCreditsApplicable?.get(U.id);return{accountId:U.id,quota:U.kind==="api-key"?void 0:z.get(U.id)?.projection??b(U.quota,K),reservePercent:Q(U),configuredOrder:_,...P===void 0?{}:{resetCreditsApplicable:P},...M===void 0?{}:{killswitchPasses:M}}}),D=[],V=J?{action:"retain"}:$.pin?{action:"clear"}:{action:"none"};while(W.length>0){let U=fZ({candidates:W,pendingBytes:$.pendingBytes??new Map,requestBytes:$.requestBytes,now:$.now,...$.onEmptyWeightedSet?{onEmptyWeightedSet:$.onEmptyWeightedSet}:{}});if(!U)break;let _=X.get(U.accountId);if(_){D.push(_),W=W.filter((P)=>P.accountId!==U.accountId);continue}let M=$.identities?.get(U.accountId);return{outcome:"dispatch",accountId:U.accountId,source:U.source,...U.quotaCheckedAt===void 0?{}:{quotaCheckedAt:U.quotaCheckedAt},pin:J&&!H?{action:"retain"}:{action:"assign",pin:{accountId:U.accountId,inputBytes:$.requestBytes,...M===void 0?{}:{wireIdentity:M},...U.quotaCheckedAt===void 0?{}:{quotaCheckedAt:U.quotaCheckedAt}}},refusedSelections:D,admission:Z}}return{outcome:"no-admissible-account",pin:V,refusedSelections:D,admission:Z}}import{createHash as R8}from"node:crypto";var S8=86400000,T8=300000,A8=3600000,E8=60000,C8=900000,I8=300000;function D3($){return $ instanceof Error?$.message:String($)}function k8($){let Z=$?.status;if(typeof Z==="number")return Z===429||Z>=500;if(!($ instanceof Error))return!1;return $.name==="AbortError"||$.name==="TimeoutError"||$.message.includes("fetch failed")||"code"in $&&($.code==="ECONNRESET"||$.code==="ECONNREFUSED"||$.code==="ETIMEDOUT"||$.code==="UND_ERR_CONNECT_TIMEOUT")}function F3($){let Z=D3($),z=$?.status;if(typeof z==="number")return z===429||z>=500;if(!($ instanceof Error))return!1;let X=$.code;return $.name==="AbortError"||$.name==="TimeoutError"||Z.includes("fetch failed")||X==="ECONNRESET"||X==="ECONNREFUSED"||X==="ETIMEDOUT"||X==="UND_ERR_CONNECT_TIMEOUT"}function bZ($){return R8("sha256").update($).digest("hex")}function yZ($){let Z=bZ($.refreshToken),X=($.previous?.tokenHash===Z?$.previous.retryCount??0:0)+1,Y,G=$.error?.retryAfter;if(typeof G==="number"&&G>0)Y=G*1000;else if(k8($.error))Y=Math.min(A8,T8*2**Math.min(X-1,6));else Y=S8;return{message:D3($.error),checkedAt:$.now,nextRetryAt:$.now+Y,retryCount:X,tokenHash:Z}}function Q0($,Z,z){if(!$?.nextRetryAt||$.nextRetryAt<=z)return!1;if(!Z)return!0;return $.tokenHash===bZ(Z)}function D$($,Z){return`Codex OAuth refresh is backed off for ${Math.max(1,Math.ceil((($.nextRetryAt??Z)-Z)/1000))}s after: ${$.message}`}function p0($){let z=($.previous?.retryCount??0)+1,X,Y=$.error?.retryAfter;if(typeof Y==="number"&&Y>0)X=Y*1000;else if(F3($.error))X=Math.min(C8,E8*2**Math.min(z-1,6));else X=I8;return{message:D3($.error),checkedAt:$.now,nextRetryAt:$.now+X,retryCount:z}}function S0($,Z){if(!$?.nextRetryAt||$.nextRetryAt<=Z)return!1;return!0}function q3($){if(!$)return;let Z=Number($);if(Number.isFinite(Z)&&Z>0)return Math.ceil(Z);let z=Date.parse($);if(Number.isFinite(z)){let X=Math.ceil((z-Date.now())/1000);return X>0?X:void 0}return}import{createServer as hZ}from"node:http";import{setTimeout as f8}from"node:timers/promises";var M$="app_EMoamEEZ73f0CkXaXp7hrann",D0="https://auth.openai.com",d0=1455,b8=3000,y8="cortexkit-opencode-openai-auth";function gZ($){return`${y8}/${$}`}var pZ="main",h8=`"${pZ}" is a reserved account id; choose a different label.`;function lZ($){let Z=new Uint8Array($),z=String.fromCharCode(...Z);return btoa(z).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}async function w8(){let Z=Array.from(crypto.getRandomValues(new Uint8Array(43))).map((X)=>"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"[X%66]).join(""),z=lZ(await crypto.subtle.digest("SHA-256",new TextEncoder().encode(Z)));return{verifier:Z,challenge:z}}function wZ($){if($.length>16384)return;let Z=$.split(".");if(Z.length!==3)return;let z=Z[1];if(!z||z.length>8192)return;try{return JSON.parse(Buffer.from(z,"base64url").toString())}catch{return}}function mZ($){let Z=$.chatgpt_account_id;if(typeof Z==="string"&&Z.length>0)return Z;let z=$["https://api.openai.com/auth"];if(z&&typeof z==="object"&&!Array.isArray(z)&&typeof z.chatgpt_account_id==="string"&&z.chatgpt_account_id.length>0)return z.chatgpt_account_id;let X=$.organizations;if(Array.isArray(X)){let Y=X[0];if(Y&&typeof Y==="object"&&!Array.isArray(Y)&&typeof Y.id==="string"&&Y.id.length>0)return Y.id}return}function q$($){if($.id_token){let Z=wZ($.id_token),z=Z&&mZ(Z);if(z)return z}if($.access_token){let Z=wZ($.access_token);return Z?mZ(Z):void 0}return}function m8($){return typeof $==="string"&&$.toLowerCase()===pZ}function N3($){if(m8($))throw Error(h8);return $}function v8($,Z,z){let X=new URLSearchParams({response_type:"code",client_id:M$,redirect_uri:$,scope:"openid profile email offline_access",code_challenge:Z.challenge,code_challenge_method:"S256",id_token_add_organizations:"true",codex_cli_simplified_flow:"true",state:z,originator:"opencode"});return`${D0}/oauth/authorize?${X.toString()}`}async function g8($,Z,z){let X=await fetch(`${D0}/oauth/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"authorization_code",code:$,redirect_uri:Z,client_id:M$,code_verifier:z.verifier}).toString()});if(!X.ok)throw Error(`Token exchange failed: ${X.status}`);return await X.json()}function p8($){return $.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">").replaceAll('"',""").replaceAll("'","'")}var l8=`<!doctype html>
|
|
2
2
|
<html>
|
|
3
3
|
<head>
|
|
4
4
|
<title>CortexKit OpenAI Auth - Authorization Successful</title>
|