@cortexkit/opencode-openai-auth 0.8.0 → 0.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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/dist/{index-3w4vmckx.js → index-4effjmr6.js} +2 -2
  3. package/dist/{index-507jh8bv.js → index-9ehhb051.js} +1 -1
  4. package/dist/index-g3hsdjh4.js +2 -0
  5. package/dist/index-hh52v8sb.js +2 -0
  6. package/dist/{index-944gsj1s.js → index-jwn4r3sw.js} +1 -1
  7. package/dist/{index-02h7g5f9.js → index-sdt2d2ra.js} +1 -1
  8. package/dist/index-sq36b120.js +211 -0
  9. package/dist/index.d.ts +172 -341
  10. package/dist/index.js +65 -65
  11. package/dist/internal-BTndPmW2.d.ts +914 -0
  12. package/dist/quota-normalize-08hpp51v.js +1 -0
  13. package/dist/rpc/port-file.js +1 -1
  14. package/dist/rpc/protocol.d.ts +1 -1
  15. package/dist/rpc/rpc-client.d.ts +2 -1
  16. package/dist/rpc/rpc-client.js +1 -1
  17. package/dist/rpc/rpc-dir.js +1 -1
  18. package/dist/sidebar-state-CoKYKcLn.d.ts +220 -0
  19. package/dist/sidebar-state.d.ts +2 -172
  20. package/dist/sidebar-state.js +1 -1
  21. package/dist/{token-jdvpwk60.js → token-9823y0pc.js} +1 -1
  22. package/dist/token-util-ypgz7rge.js +1 -0
  23. package/dist/tui-preferences.js +1 -1
  24. package/dist/tui.d.ts +27 -5
  25. package/package.json +3 -2
  26. package/src/tui-compiled/raw/core-custody-state.ts +243 -0
  27. package/src/tui-compiled/raw/sidebar-state.ts +168 -12
  28. package/src/tui-compiled/raw/tui-command-dialogs.tsx +89 -39
  29. package/src/tui-compiled/raw/tui.tsx +138 -18
  30. package/src/tui-compiled/runtime/core-custody-state.ts +243 -0
  31. package/src/tui-compiled/runtime/sidebar-state.ts +168 -12
  32. package/src/tui-compiled/runtime/tui-command-dialogs.tsx +70 -33
  33. package/src/tui-compiled/runtime/tui.tsx +241 -143
  34. package/src/tui-compiled/shared/logger.ts +9 -2
  35. package/dist/index-2xppkvkx.js +0 -2
  36. package/dist/index-nshbgkz1.js +0 -198
  37. package/dist/index-xyg86jgt.js +0 -2
  38. package/dist/protocol-Cv9ZmU0p.d.ts +0 -24
  39. package/dist/quota-normalize-wap0rne8.js +0 -1
  40. package/dist/token-util-zzm7paz9.js +0 -1
package/README.md CHANGED
@@ -10,7 +10,7 @@ The plugin registers the built-in `openai` provider id. OpenCode loads external
10
10
 
11
11
  ```json
12
12
  {
13
- "plugin": ["@cortexkit/opencode-openai-auth@0.1.0"]
13
+ "plugin": ["@cortexkit/opencode-openai-auth@0.9.1"]
14
14
  }
15
15
  ```
16
16
 
@@ -1,2 +1,2 @@
1
- import{Q as _}from"./index-nshbgkz1.js";import{chmod as L,mkdir as M,readdir as W,readFile as $,rename as R,rmdir as S,unlink as X,writeFile as U}from"node:fs/promises";import{join as N,resolve as Y}from"node:path";var A=_("rpc");function E(q){try{return process.kill(q,0),!0}catch(H){return H.code==="EPERM"}}function C(q){return/^(?:openai-auth-)?[0-9a-f]{16}$/.test(q)}function O(q){return q!==null&&typeof q==="object"&&!Array.isArray(q)&&typeof q.pid==="number"&&Number.isFinite(q.pid)&&typeof q.port==="number"&&Number.isFinite(q.port)}async function Z(q){A.debug("rpc corrupt port file",{pid:process.pid,portFile:q}),await X(q).catch(()=>{})}async function w(q,H,I={}){let J=async()=>{if(await M(q,{recursive:!0,mode:I.secureDir?448:void 0}),I.secureDir)await L(q,448);await I.beforeWrite?.();let z={...H,startedAt:Date.now()},K=N(q,`port-${H.pid}.json`),B=`${K}.${process.pid}.tmp`;return await U(B,JSON.stringify(z),{encoding:"utf8",mode:384}),await R(B,K),K};try{return await J()}catch(z){if(z.code==="ENOENT")return await J();throw z}}async function x(q,H){let I;try{I=await W(q,{withFileTypes:!0})}catch(z){if(z.code==="ENOENT")return;throw z}let J=Y(H);for(let z of I){if(!z.isDirectory()||!C(z.name))continue;let K=N(q,z.name),B;try{B=await W(K)}catch(G){if(G.code==="ENOENT")continue;throw G}for(let G of B){if(!G.startsWith("port-")||!G.endsWith(".json"))continue;let Q=N(K,G),T;try{T=await $(Q,"utf8")}catch{continue}if(T===void 0)continue;let V;try{V=JSON.parse(T)}catch{await Z(Q);continue}if(!O(V)){await Z(Q);continue}if(!E(V.pid))await X(Q).catch(()=>{})}if(Y(K)!==J)await S(K).catch(()=>{})}}async function y(q,H){let I;try{I=await W(q)}catch{return null}let J=[];for(let B of I){if(!B.startsWith("port-")||!B.endsWith(".json"))continue;try{let G=JSON.parse(await $(N(q,B),"utf8"));if(Number.isFinite(G.port))if(E(G.pid))J.push(G);else X(N(q,B)).catch(()=>{})}catch{}}if(J.length===0)return null;let z=H!==void 0&&H>=1?J.filter((B)=>B.pid===H):[];return(z.length>0?z:J).sort((B,G)=>G.startedAt-B.startedAt)[0]??null}
2
- export{w as F,x as G,y as H};
1
+ import{Z as _}from"./index-sq36b120.js";import{chmod as L,mkdir as M,readdir as W,readFile as $,rename as R,rmdir as S,unlink as X,writeFile as U}from"node:fs/promises";import{join as N,resolve as Y}from"node:path";var A=_("rpc");function E(q){try{return process.kill(q,0),!0}catch(H){return H.code==="EPERM"}}function C(q){return/^(?:openai-auth-)?[0-9a-f]{16}$/.test(q)}function O(q){return q!==null&&typeof q==="object"&&!Array.isArray(q)&&typeof q.pid==="number"&&Number.isFinite(q.pid)&&typeof q.port==="number"&&Number.isFinite(q.port)}async function Z(q){A.debug("rpc corrupt port file",{pid:process.pid,portFile:q}),await X(q).catch(()=>{})}async function w(q,H,I={}){let J=async()=>{if(await M(q,{recursive:!0,mode:I.secureDir?448:void 0}),I.secureDir)await L(q,448);await I.beforeWrite?.();let z={...H,startedAt:Date.now()},K=N(q,`port-${H.pid}.json`),B=`${K}.${process.pid}.tmp`;return await U(B,JSON.stringify(z),{encoding:"utf8",mode:384}),await R(B,K),K};try{return await J()}catch(z){if(z.code==="ENOENT")return await J();throw z}}async function x(q,H){let I;try{I=await W(q,{withFileTypes:!0})}catch(z){if(z.code==="ENOENT")return;throw z}let J=Y(H);for(let z of I){if(!z.isDirectory()||!C(z.name))continue;let K=N(q,z.name),B;try{B=await W(K)}catch(G){if(G.code==="ENOENT")continue;throw G}for(let G of B){if(!G.startsWith("port-")||!G.endsWith(".json"))continue;let Q=N(K,G),T;try{T=await $(Q,"utf8")}catch{continue}if(T===void 0)continue;let V;try{V=JSON.parse(T)}catch{await Z(Q);continue}if(!O(V)){await Z(Q);continue}if(!E(V.pid))await X(Q).catch(()=>{})}if(Y(K)!==J)await S(K).catch(()=>{})}}async function y(q,H){let I;try{I=await W(q)}catch{return null}let J=[];for(let B of I){if(!B.startsWith("port-")||!B.endsWith(".json"))continue;try{let G=JSON.parse(await $(N(q,B),"utf8"));if(Number.isFinite(G.port))if(E(G.pid))J.push(G);else X(N(q,B)).catch(()=>{})}catch{}}if(J.length===0)return null;let z=H!==void 0&&H>=1?J.filter((B)=>B.pid===H):[];return(z.length>0?z:J).sort((B,G)=>G.startedAt-B.startedAt)[0]??null}
2
+ export{w as I,x as J,y as K};
@@ -1,2 +1,2 @@
1
1
  import{createRequire as s}from"node:module";var j=Object.create;var{getPrototypeOf:k,defineProperty:f,getOwnPropertyNames:l}=Object;var m=Object.prototype.hasOwnProperty;function n(a){return this[a]}var o,p,t=(a,b,c)=>{var g=a!=null&&typeof a==="object";if(g){var h=b?o??=new WeakMap:p??=new WeakMap,i=h.get(a);if(i)return i}c=a!=null?j(k(a)):{};let d=b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c;for(let e of l(a))if(!m.call(d,e))f(d,e,{get:n.bind(a,e),enumerable:!0});if(g)h.set(a,d);return d};var u=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var q=(a)=>a;function r(a,b){this[a]=q.bind(null,b)}var v=(a,b)=>{for(var c in b)f(a,c,{get:b[c],enumerable:!0,configurable:!0,set:r.bind(b,c)})};var x=s(import.meta.url);
2
- export{t as Sa,u as Ta,v as Ua,x as Va};
2
+ export{t as qb,u as rb,v as sb,x as tb};
@@ -0,0 +1,2 @@
1
+ import{Ea as a,Z as c}from"./index-sq36b120.js";import{createHash as zT,randomUUID as DT}from"node:crypto";import{chmod as KT,mkdir as UT,readFile as i,rename as BT,rm as QT,writeFile as bT}from"node:fs/promises";import{tmpdir as PT}from"node:os";import{dirname as FT,join as t}from"node:path";var x=["needs-login","mode-mismatch","corrupt-under-binding","manifest-unreadable","unbound-under-claustrum","orphan-tombstone","vault-cold","vault-reauth","identity-mismatch","no-handle","takeover-incomplete","new-local-family-under-claustrum","takeover-incomplete/vault-unavailable","takeover-incomplete/slot-absent"];function O(T){return T}function B(T,V){return T==="empty"?{...V,canonicalize:!0}:V}function CT(T){switch(T){case"real":return{kind:"LOCAL"};case"tombstone":case"empty":case"slot-absent":return{kind:"NEEDS_LOGIN"};case"gone":return{kind:"NEEDS_LOGIN",reason:"corrupt"}}return O(T)}function RT(T,V){switch(T){case"real":return V?{kind:"LOCAL"}:{kind:"INERT",reason:"needs-login"};case"tombstone":case"empty":case"slot-absent":return{kind:"INERT",reason:"mode-mismatch"};case"gone":return{kind:"INERT",reason:"corrupt-under-binding"}}return O(T)}function jT(T){switch(T){case"tombstone":case"empty":return{kind:"INERT",reason:"orphan-tombstone"};case"real":case"gone":case"slot-absent":return{kind:"INERT",reason:"unbound-under-claustrum"}}return O(T)}function JT(T,V){switch(V){case"serves":return B(T,{kind:"VAULT"});case"cold":return B(T,{kind:"INERT",reason:"vault-cold"});case"needs_reauth":return B(T,{kind:"INERT",reason:"vault-reauth"});case"identity_mismatch":return B(T,{kind:"INERT",reason:"identity-mismatch"});case"no_handle":return B(T,{kind:"INERT",reason:"no-handle"})}return O(V)}function ZT(T,V){switch(T){case"serves":return V===!1?{kind:"INERT",reason:"new-local-family-under-claustrum"}:{kind:"INERT",reason:"takeover-incomplete"};case"cold":case"needs_reauth":return{kind:"INERT",reason:"takeover-incomplete/vault-unavailable"};case"identity_mismatch":return{kind:"INERT",reason:"identity-mismatch"};case"no_handle":return{kind:"INERT",reason:"no-handle"}}return O(T)}function $T(T){switch(T){case"serves":return{kind:"VAULT",installTombstone:!0};case"cold":return{kind:"INERT",reason:"vault-cold",installTombstone:!0};case"needs_reauth":return{kind:"INERT",reason:"vault-reauth",installTombstone:!0};case"identity_mismatch":return{kind:"INERT",reason:"identity-mismatch"};case"no_handle":return{kind:"INERT",reason:"no-handle"}}return O(T)}function GT(T){switch(T){case"serves":case"cold":case"needs_reauth":return{kind:"INERT",reason:"takeover-incomplete/slot-absent"};case"identity_mismatch":return{kind:"INERT",reason:"identity-mismatch"};case"no_handle":return{kind:"INERT",reason:"no-handle"}}return O(T)}function XT(T,V,L){switch(T){case"tombstone":case"empty":return JT(T,V);case"real":return ZT(V,L);case"gone":return $T(V);case"slot-absent":return GT(V)}return O(T)}function nT(T){if(T.manifest==="unreadable")return{kind:"INERT",reason:"manifest-unreadable"};switch(T.mode){case"local":return T.manifest==="present"?RT(T.local,T.verifiedInProcessLogin):CT(T.local);case"claustrum":if(T.manifest==="absent")return jT(T.local);if(T.manifest==="present")return XT(T.local,T.vault(),T.fingerprintMatch);return O(T.manifest)}return O(T.mode)}var n=["primary","secondary"],s={primary:300,secondary:10080};function y(T){return Number.isInteger(T)?String(T):String(Math.round(T*10)/10)}function OT(T,V){let L=T!==void 0&&Number.isFinite(T)&&T>0?T:s[V];if(L<60)return`${y(L)}m`;if(L<1440)return`${y(L/60)}h`;return`${y(L/1440)}d`}function YT(T){if(!T)return[];let V=[];for(let L of n){let N=T[L];if(!N)continue;let E=N.windowMinutes,_=E!==void 0&&Number.isFinite(E)&&E>0?E:s[L];V.push({key:L,label:OT(_,L),window:N,windowMs:_*60000})}return V}var I=c("sidebar"),WT="OPENCODE_OPENAI_AUTH_SIDEBAR_STATE_FILE",yT=t(PT(),"opencode-openai-auth"),e=t(yT,"sidebar-state.json"),HT=/^[a-f0-9]{64}$/,S=604800000,MT=256,TT=3600000;function F(T){return zT("sha256").update(T).digest("hex")}function qT(T){return typeof T==="number"&&Number.isFinite(T)&&T>=0?T:void 0}function A(T){let V=qT(T);return V!==void 0?{resetCredits:V}:{}}var IT=new Set(["vault","needsLogin","local","inert"]),ST=new Set([...x,"corrupt"]);function h(T){if(T===null||typeof T!=="object"||Array.isArray(T))return;let V=T;if(typeof V.state!=="string"||!IT.has(V.state))return;let N={state:V.state};if(typeof V.reason==="string"&&ST.has(V.reason))N.reason=V.reason;return N}function vT(T){if(T===null||typeof T!=="object"||Array.isArray(T))return;let V={};for(let[L,N]of Object.entries(T)){if(N===null||typeof N!=="object"||Array.isArray(N))continue;let E=N;if(typeof E.activeId!=="string"||typeof E.route!=="string"||typeof E.updatedAt!=="number"||!Number.isFinite(E.updatedAt))continue;V[L]={activeId:E.activeId,route:E.route,updatedAt:E.updatedAt}}return Object.keys(V).length>0?V:void 0}function fT(T){if(T===null||typeof T!=="object"||Array.isArray(T))return;let V={};for(let[L,N]of Object.entries(T)){if(!HT.test(L)||N===null||typeof N!=="object"||Array.isArray(N))continue;let E=N;if(typeof E.accountId!=="string"||E.accountId.length===0||typeof E.assignedAt!=="number"||!Number.isFinite(E.assignedAt)||E.assignedAt<0||typeof E.lastSeenAt!=="number"||!Number.isFinite(E.lastSeenAt)||E.lastSeenAt<0||typeof E.inputBytes!=="number"||!Number.isFinite(E.inputBytes)||E.inputBytes<0)continue;let _=E.quotaCheckedAt;if(_!==void 0&&(typeof _!=="number"||!Number.isFinite(_)||_<0))continue;let C=E.wireAccountId;V[L]={accountId:E.accountId,assignedAt:E.assignedAt,lastSeenAt:E.lastSeenAt,inputBytes:E.inputBytes,..._===void 0?{}:{quotaCheckedAt:_},...typeof C==="string"?{wireAccountId:C}:{}}}return Object.keys(V).length>0?V:void 0}function z(){return process.env[WT]||e}function EV(T){switch(T.kind){case"LOCAL":return{state:"local"};case"VAULT":return{state:"vault"};case"INERT":return{state:"inert",reason:T.reason};case"NEEDS_LOGIN":return T.reason==="corrupt"?{state:"needsLogin",reason:"corrupt"}:{state:"needsLogin"}}}var K={main:{quota:null,killed:!1},fallbacks:[],activeId:void 0,route:"main",lastUpdated:0};function v(T){if(T===null||typeof T!=="object"||Array.isArray(T))return K;let V=T,L=V.main,N;if(L!==null&&typeof L==="object"&&!Array.isArray(L)){let R=L;N={quota:"quota"in R?R.quota:null,killed:typeof R.killed==="boolean"?R.killed:!1,...typeof R.mainAccountId==="string"?{mainAccountId:R.mainAccountId}:{},...(()=>{let Y=h(R.custody);return Y?{custody:Y}:{}})(),...typeof R.quotaBackedOff==="boolean"?{quotaBackedOff:R.quotaBackedOff}:{},...typeof R.quotaBackoffUntil==="number"?{quotaBackoffUntil:R.quotaBackoffUntil}:{},...typeof R.refreshBackedOff==="boolean"?{refreshBackedOff:R.refreshBackedOff}:{},...typeof R.refreshBackoffUntil==="number"?{refreshBackoffUntil:R.refreshBackoffUntil}:{},...A(R.resetCredits)}}else N={quota:null,killed:!1};let E=V.fallbacks,_=Array.isArray(E)?E.filter((R)=>R!==null&&typeof R==="object"&&!Array.isArray(R)&&typeof R.id==="string").map((R)=>{let Y=h(R.custody);return{id:R.id,label:typeof R.label==="string"?R.label:void 0,...typeof R.accountId==="string"?{accountId:R.accountId}:{},quota:"quota"in R?R.quota:null,killed:typeof R.killed==="boolean"?R.killed:!1,enabled:typeof R.enabled==="boolean"?R.enabled:!0,...A(R.resetCredits),...Y?{custody:Y}:{}}}):[],C=typeof V.activeId==="string"?V.activeId:void 0,j=typeof V.route==="string"?V.route:K.route,Z=typeof V.lastUpdated==="number"?V.lastUpdated:0,J=typeof V.planType==="string"?V.planType:void 0,G=typeof V.credits==="number"?V.credits:void 0,$=vT(V.activeRouting),X=fT(V.stickyAssignments);return{main:N,fallbacks:_,activeId:C,route:j,lastUpdated:Z,...$!==void 0?{activeRouting:$}:{},...X!==void 0?{stickyAssignments:X}:{},...J!==void 0?{planType:J}:{},...G!==void 0?{credits:G}:{}}}async function _V(T=z()){try{let V=await i(T,"utf8");return v(JSON.parse(V))}catch{return K}}var kT=3600000,p=128;function VT(T,V,L=Date.now()){if(!(T.updatedAt>=L-kT&&T.updatedAt<=L))return!1;if(V===void 0)return!0;return T.activeId==="main"||V.some((E)=>E.enabled!==!1&&E.killed!==!0&&E.id===T.activeId)}function xT(T,V=Date.now()){let L=T?.spendControl;if(L?.reached!==!0||typeof L.resetsAt!=="string")return;let N=Date.parse(L.resetsAt);if(!Number.isFinite(N)||N<=V)return;return{resetsAt:L.resetsAt,resetAtMs:N}}function AT(T,V=Date.now()){let L;for(let E of n){let _=T?.[E];if(typeof _?.resetsAt!=="string"||!Number.isFinite(_.usedPercent)||_.usedPercent<100)continue;let C=Date.parse(_.resetsAt);if(!Number.isFinite(C)||C<=V)continue;if(!L||C<L.resetAtMs)L={resetsAt:_.resetsAt,resetAtMs:C}}let N=xT(T,V);if(N&&(!L||N.resetAtMs<L.resetAtMs))L=N;return L}function Q(T,V=Date.now()){return AT(T,V)!==void 0}function hT(T,V,L=Date.now()){if(!V||T.route!=="sticky-balanced")return;let N=T.stickyAssignments?.[F(V)];if(!N||N.lastSeenAt<L-S)return;if(N.accountId==="main")return T.main?.killed||Q(T.main?.quota,L)?void 0:"main";let E=T.fallbacks?.find((_)=>_.id===N.accountId);if(!E||E.enabled===!1||E.killed===!0||Q(E.quota,L))return;return E.id}function CV(T,V,L=Date.now()){if(!V)return{activeId:T.activeId??"main",route:T.route};let N=V?T.activeRouting?.[V]:void 0,E=N?.activeId==="main"?T.main.quota:T.fallbacks.find((Z)=>Z.id===N?.activeId)?.quota;if(N&&VT(N,T.fallbacks,L)&&!Q(E,L))return{activeId:N.activeId,route:N.route};let _=hT(T,V,L);if(_)return{activeId:_,route:T.route};let C=T.fallbacks.filter((Z)=>Z.enabled&&!Z.killed),j=C.find((Z)=>!Q(Z.quota,L))??C[0];return{activeId:T.route==="fallback-first"&&j?j.id:"main",route:T.route}}function LT(T,V,L=Date.now(),N){if(!T)return;let E=Object.entries(T).filter(([C,j])=>C!==N&&VT(j,V,L)),_=E.length<=p?E:E.sort((C,j)=>j[1].updatedAt-C[1].updatedAt).slice(0,p);return _.length>0?Object.fromEntries(_):void 0}function W(T,V,L=Date.now(),N){if(!T)return;let E=0,_=0,C=0,j=[];for(let[J,G]of Object.entries(T)){if(J===N){C+=1;continue}if(G.lastSeenAt<L-S){_+=1;continue}if(V!==void 0&&!V.has(G.accountId)){E+=1;continue}j.push([J,G])}let Z=E+_+C;if(Z>0)I.debug("pruned sticky assignments",{pid:process.pid,removed:Z,reasons:{"account-not-in-roster":E,expired:_,"explicit-removal":C}});return j.length>0?Object.fromEntries(j):void 0}function pT(T,V){let L=Object.keys(T).length-MT;if(L<=0)return T;let N=new Set(Object.entries(T).filter(([E])=>E!==V).sort(([E,_],[C,j])=>_.lastSeenAt-j.lastSeenAt||E.localeCompare(C)).slice(0,L).map(([E])=>E));return Object.fromEntries(Object.entries(T).filter(([E])=>!N.has(E)))}function rT(T,V){if(T===V)return!0;if(!T||!V)return!1;let L=Object.entries(T);if(L.length!==Object.keys(V).length)return!1;return L.every(([N,E])=>Object.is(V[N],E))}function r(T,V,L,N){return T!==void 0&&V.has(T.accountId)&&!L.has(T.accountId)&&T.lastSeenAt>=N-S}function w(T,V,L,N){return V>T.inputBytes||L-T.lastSeenAt>=TT||T.wireAccountId===void 0&&N!==void 0}function m(T,V){return typeof T.wireAccountId==="string"&&typeof V==="string"&&T.wireAccountId!==V}function wT(T){let V=new Map(T),L={get size(){return V.size},has:(N)=>V.has(N),get:(N)=>V.get(N),entries:()=>V.entries(),keys:()=>V.keys(),values:()=>V.values(),forEach:(N,E)=>{V.forEach((_,C)=>{N.call(E,_,C,L)})},[Symbol.iterator]:()=>V[Symbol.iterator]()};return Object.freeze(L)}function mT(T,V,L){let N=new Map;for(let[E,_]of Object.entries(T??{})){if(E===L)continue;if(_.quotaCheckedAt!==V[_.accountId])continue;N.set(_.accountId,(N.get(_.accountId)??0)+_.inputBytes)}return wT(N)}function f(T){if(T===void 0)return;return new Set(["main",...T.filter((V)=>V.enabled!==!1&&V.killed!==!0).map((V)=>V.id)])}var H=Promise.resolve(),dT=3,uT=1e4,lT=15000;function D(T){let V=H.then(T);return H=V.catch(()=>{}),V}function RV(T,V=z()){return D(()=>q(T,V))}async function NT(T){try{return ET(await M(T))}catch{return K}}async function M(T){try{return await i(T,"utf8")}catch(V){if(V.code==="ENOENT")return"";throw V}}function ET(T){if(T==="")return K;try{return v(JSON.parse(T))}catch{return K}}async function gT(T){await _T(T);let V=Date.now()+lT;while(Date.now()<=V){let L=await a({name:"sidebar-write",path:T,ttlMs:uT,renew:!0});if(L)return L;await new Promise((N)=>setTimeout(N,10))}throw Error("Timed out waiting for the sidebar state write lock")}async function _T(T){let V=FT(T);if(await UT(V,{recursive:!0,mode:448}),T!==e)return;await KT(V,448).catch((L)=>{I.warn("sidebar directory permission remediation failed",{pid:process.pid,error:L instanceof Error?L.message:String(L)})})}async function U(T,V,L){let N=await gT(T);try{for(let C=0;C<dT;C+=1){let j=await M(T),Z=V(ET(j));if(!Z)return;if(C===0)await L?.beforeRecheck?.();if(await M(T)!==j)continue;await q(Z,T);return}let E=await NT(T),_=V(E);if(_)await q(_,T)}finally{await N.release()}}function b(T){let V;for(let L of[T?.primary?.checkedAt,T?.secondary?.checkedAt,T?.checkedAt])if(typeof L==="number"&&Number.isFinite(L))V=V===void 0?L:Math.max(V,L);return V}function d(T,V){let L=b(T),N=b(V);if(N!==void 0&&(L===void 0||N>L))return V;return T}function u(T,V){return T!==void 0&&V!==void 0&&T===V}function P(T,V){let L=T?.checkedAt;if(typeof L==="number"&&Number.isFinite(L))return L;if(typeof V==="number"&&Number.isFinite(V))return V;return}function l(T,V,L,N,E){if(T&&V){let _=P(T,N),C=P(V,E);if(C!==void 0&&(_===void 0||C>_))return V;return T}return L?V:T}function g(T,V){if(T.spendControl!==void 0)return T.spendControl;if(T.spendControlCleared===!0)return;return V.spendControl}function o(T,V){if(!T)return V;if(!V)return T;let L=b(T),N=b(V),E=N!==void 0&&(L===void 0||N>L),_=l(T.primary,V.primary,E,T.checkedAt,V.checkedAt),C=l(T.secondary,V.secondary,E,T.checkedAt,V.checkedAt),j=E?g(V,T):g(T,V),Z=j===void 0&&(T.spendControlCleared===!0||V.spendControlCleared===!0),J;for(let R of[P(_),P(C)])if(R!==void 0)J=J===void 0?R:Math.max(J,R);let{spendControl:G,spendControlCleared:$,...X}=T;return{...X,primary:_,secondary:C,...j!==void 0?{spendControl:j}:{},...Z?{spendControlCleared:!0}:{},checkedAt:J??T.checkedAt}}function jV(T,V=z(),L){return D(async()=>{await U(V,(N)=>{let E=new Map(N.fallbacks.map((J)=>[J.id,J])),_=u(T.main.mainAccountId,N.main.mainAccountId),C=_?o(T.main.quota,N.main.quota):d(T.main.quota,N.main.quota),j=Date.now(),Z=W(N.stickyAssignments,f(T.fallbacks),j);return{...N,...T,main:{...T.main,quota:C,mainAccountId:_?T.main.mainAccountId:C===N.main.quota&&C!==T.main.quota?N.main.mainAccountId:T.main.mainAccountId},fallbacks:T.fallbacks.map((J)=>{let G=E.get(J.id),$=u(J.accountId,G?.accountId),X=$?o(J.quota,G?.quota??null):d(J.quota,G?.quota??null);return{...J,quota:X,accountId:$?J.accountId:X===G?.quota&&X!==J.quota?G?.accountId:J.accountId}}),activeId:N.activeId,activeRouting:N.activeRouting,stickyAssignments:Z,lastUpdated:Math.max(j,N.lastUpdated+1)}},L)})}function JV(T,V,L=z(),N){return D(async()=>{await U(L,(E)=>{let _=LT({...E.activeRouting,[T.sessionId]:{activeId:T.activeId,route:T.route,updatedAt:T.updatedAt}},V,Date.now()),C=W(E.stickyAssignments,f(V),Date.now());return{...E,activeId:T.activeId,route:T.route,activeRouting:_,stickyAssignments:C,lastUpdated:Math.max(Date.now(),E.lastUpdated+1)}},N)})}function ZV(T,V=z()){return D(async()=>{await U(V,(L)=>({...L,activeId:T.activeId,route:T.route,lastUpdated:Math.max(Date.now(),L.lastUpdated+1)}))})}function $V(T,V,L=z(),N){return D(async()=>{await U(L,(E)=>{let _=Date.now(),C=LT(E.activeRouting,V,_,T),j=W(E.stickyAssignments,f(V),_,F(T));return{...E,activeRouting:C,stickyAssignments:j,lastUpdated:Math.max(Date.now(),E.lastUpdated+1)}},N)})}async function GV(T,V=z(),L){let N=F(T.sessionId),E=new Set(T.validPinnedAccountIds),_=new Set(T.excludeAccountIds),C=(await NT(V)).stickyAssignments?.[N];if(r(C,E,_,T.now)&&!m(C,T.wireAccountIdByAccount?.[C.accountId])&&!w(C,T.requestBytes,T.now,T.wireAccountIdByAccount?.[C.accountId]))return C;let j;return await D(async()=>{await U(V,(Z)=>{let J=W(Z.stickyAssignments,E,T.now),G=!rT(Z.stickyAssignments,J),$=J?.[N],X=$!==void 0&&m($,T.wireAccountIdByAccount?.[$.accountId]);if(r($,E,_,T.now)&&!X){let Y=w($,T.requestBytes,T.now,T.wireAccountIdByAccount?.[$.accountId]),k=Y?{...$,inputBytes:Math.max($.inputBytes,T.requestBytes),...$.wireAccountId===void 0&&T.wireAccountIdByAccount?.[$.accountId]!==void 0?{wireAccountId:T.wireAccountIdByAccount?.[$.accountId]}:{},...T.now-$.lastSeenAt>=TT?{lastSeenAt:T.now}:{}}:$;if(j=k,!G&&!Y)return;return{...Z,stickyAssignments:{...J,[N]:k},lastUpdated:Math.max(T.now,Z.lastUpdated+1)}}let R=T.choose(mT(J,T.quotaCheckedAtByAccount,X?N:void 0));if(!R){if(j=void 0,!G)return;return{...Z,stickyAssignments:J,lastUpdated:Math.max(T.now,Z.lastUpdated+1)}}return j={accountId:R.accountId,assignedAt:T.now,lastSeenAt:T.now,inputBytes:T.requestBytes,...R.quotaCheckedAt===void 0?{}:{quotaCheckedAt:R.quotaCheckedAt},...T.wireAccountIdByAccount?.[R.accountId]===void 0?{}:{wireAccountId:T.wireAccountIdByAccount?.[R.accountId]}},{...Z,stickyAssignments:pT({...J,[N]:j},N),lastUpdated:Math.max(T.now,Z.lastUpdated+1)}},L)}),j}async function XV(T,V=z()){let L=F(T),N=!1;return await D(async()=>{await U(V,(E)=>{let _=E.stickyAssignments;if(_?.[L]===void 0){N=!1;return}N=!0;let{[L]:C,...j}=_;return{...E,...Object.keys(j).length>0?{stickyAssignments:j}:{stickyAssignments:void 0},lastUpdated:Math.max(Date.now(),E.lastUpdated+1)}})}),N}async function q(T,V){let L=`${V}.${DT()}.tmp`;try{await _T(V),await bT(L,JSON.stringify(v(T)),{encoding:"utf8",mode:384}),await BT(L,V)}catch(N){throw await QT(L,{force:!0}).catch(()=>{}),I.warn("sidebar write failed",{pid:process.pid,error:N instanceof Error?N.message:String(N)}),N}}function OV(){return H}function YV(T){let V=T.activeId;if(V&&V!=="main"){let L=T.fallbacks.find((N)=>N.enabled&&N.id===V);if(L)return{id:L.id,name:L.label??L.id,quota:L.quota,killed:L.killed}}return{id:"main",name:"main",quota:T.main.quota,killed:T.main.killed}}function zV(T){let V=T?.primary?.usedPercent??null,L=T?.secondary?.usedPercent??null,N=YT(T);return{primaryUsedPercent:V,secondaryUsedPercent:L,text:N.length===0?null:N.map(({label:E,window:_})=>`${E}: ${Math.round(_.usedPercent)}%`).join(" ")}}var oT=300000,cT=0.01,aT=1;function DV(T,V,L){if(!T.resetsAt)return null;let N=new Date(T.resetsAt).getTime();if(!Number.isFinite(N))return null;let E=N-V,_=L-E;if(_<oT)return null;if(_<V*cT)return null;if(_>=V)return null;let C=T.usedPercent,j=Math.min(Math.max(_/V*100,0),100),Z=C-j,J=Math.abs(Z)<aT?"on-pace":Z>0?"deficit":"reserve",G=null;if(C>0){let $=_*100/C,X=E+$;if(X<N)G=new Date(X).toISOString()}return{pacePercent:j,deltaPercent:Z,state:J,runsOutAt:G}}
2
+ export{nT as c,OT as d,YT as e,S as f,MT as g,F as h,z as i,EV as j,K as k,v as l,_V as m,kT as n,p as o,VT as p,xT as q,AT as r,Q as s,hT as t,CV as u,LT as v,W as w,RV as x,jV as y,JV as z,ZV as A,$V as B,GV as C,XV as D,OV as E,YV as F,zV as G,DV as H};
@@ -0,0 +1,2 @@
1
+ function $(q){if(q==null||q==="")return;let z=typeof q==="number"?q:Number(q);if(Number.isFinite(z)){let G=z<100000000000?z*1000:z,K=new Date(G);return Number.isNaN(K.getTime())?void 0:K.toISOString()}let B=new Date(q);return Number.isNaN(B.getTime())?void 0:B.toISOString()}function k(q){let z=Number(q);return Number.isFinite(z)&&z>0?z:void 0}function I(q){return typeof q==="number"&&Number.isFinite(q)&&q>=0?q:void 0}function T(q,z){let B=q.get(z);if(B===null||B.trim()==="")return;let G=Number(B);if(!Number.isFinite(G)||G<0||G>100)return;let K=z.slice(0,-13),Y=k(q.get(`${K}-window-minutes`)),J=$(q.get(`${K}-reset-at`)??void 0);if(G===0&&q.get(`${K}-window-minutes`)==="0"&&!J)return;return{usedPercent:G,remainingPercent:100-G,resetsAt:J,checkedAt:Date.now(),...Y!==void 0?{windowMinutes:Y}:{}}}var f=["x-codex-primary-used-percent","x-codex-secondary-used-percent"];function M(q,z){let B=q.get(z);if(B===null)return"absent";if(B.trim()==="")return"invalid";let G=Number(B);return Number.isFinite(G)&&G>=0&&G<=100?"valid":"invalid"}function C(q){if(f.some((K)=>M(q,K)==="invalid"))return{};let z={},B=T(q,"x-codex-primary-used-percent");if(B)z.primary=B;let G=T(q,"x-codex-secondary-used-percent");if(G)z.secondary=G;return z}function H(q){let z=f.map((B)=>M(q,B));return z.includes("valid")&&!z.includes("invalid")}function U(q){if(!q)return;if(!Number.isFinite(q.used_percent)||q.used_percent<0||q.used_percent>100)return;let z=k(q.window_minutes),B=$(q.reset_at);if(q.used_percent===0&&z===void 0&&!B)return;return{usedPercent:q.used_percent,remainingPercent:100-q.used_percent,resetsAt:B,checkedAt:Date.now(),...z!==void 0?{windowMinutes:z}:{}}}function _(q){let z={},B=U(q.rate_limits?.primary);if(B)z.primary=B;let G=U(q.rate_limits?.secondary);if(G)z.secondary=G;return z}function X(q){if(q==null||q==="")return;let z=Number(q);return Number.isFinite(z)&&z>=0?z:void 0}function W(q){if(!q)return;if(!Number.isFinite(q.used_percent)||q.used_percent<0||q.used_percent>100)return;let z=k(q.limit_window_seconds),B=$(q.reset_at);if(q.used_percent===0&&z===void 0&&!B)return;return{usedPercent:q.used_percent,remainingPercent:100-q.used_percent,resetsAt:B,checkedAt:Date.now(),...z!==void 0?{windowMinutes:z/60}:{}}}function R(q){let z={},B=W(q.rate_limit?.primary_window);if(B)z.primary=B;let G=W(q.rate_limit?.secondary_window);if(G)z.secondary=G;let K=I(q.rate_limit_reset_credits?.available_count);if(K!==void 0)z.resetCreditsAvailable=K;let Y=I(q.rate_limit_reset_credits?.applicable_available_count);if(Y!==void 0)z.resetCreditsApplicable=Y;let J=q.spend_control?.individual_limit;if(q.spend_control===null||J===null)z.spendControlCleared=!0;if(J&&typeof q.spend_control?.reached==="boolean"){let Z=X(J.limit),O=X(J.used),Q=X(J.remaining),x=X(J.used_percent),D=X(J.remaining_percent);if(Z!==void 0&&O!==void 0&&Q!==void 0&&x!==void 0&&D!==void 0)z.spendControl={limit:Z,used:O,remaining:Q,usedPercent:x,remainingPercent:D,resetsAt:$(J.reset_at),unit:J.unit,source:J.source,reached:q.spend_control.reached}}let V=q.credits;if(V&&typeof V.has_credits==="boolean"&&typeof V.unlimited==="boolean"&&typeof V.overage_limit_reached==="boolean"){let Z=X(V.balance);z.credits={hasCredits:V.has_credits,unlimited:V.unlimited,overageLimitReached:V.overage_limit_reached,...Z!==void 0?{balance:Z}:{}}}return z}
2
+ export{$ as lb,C as mb,H as nb,_ as ob,R as pb};
@@ -1 +1 @@
1
- import{createHash as B}from"node:crypto";import{homedir as F,tmpdir as Q}from"node:os";import{dirname as G,join as w,resolve as z}from"node:path";var A="OPENCODE_OPENAI_AUTH_RPC_DIR";function J(k){return B("sha256").update(k).digest("hex").slice(0,16)}function K(){let k=process.env.XDG_STATE_HOME||w(F(),".local","state");return w(k,"cortexkit","openai-auth","rpc")}function L(k){let q=process.env[A]?.trim();if(q)return z(k,q);return w(K(),`openai-auth-${J(k)}`)}async function T(k){let q=process.env[A]?.trim();if(q)return{dir:z(k,q),secureDir:!1};let x=L(k);return{dir:x,secureDir:!0,sweepRoot:G(x)}}export{Q as Ka,L as La,T as Ma};
1
+ import{createHash as B}from"node:crypto";import{homedir as F,tmpdir as Q}from"node:os";import{dirname as G,join as w,resolve as z}from"node:path";var A="OPENCODE_OPENAI_AUTH_RPC_DIR";function J(k){return B("sha256").update(k).digest("hex").slice(0,16)}function K(){let k=process.env.XDG_STATE_HOME||w(F(),".local","state");return w(k,"cortexkit","openai-auth","rpc")}function L(k){let q=process.env[A]?.trim();if(q)return z(k,q);return w(K(),`openai-auth-${J(k)}`)}async function T(k){let q=process.env[A]?.trim();if(q)return{dir:z(k,q),secureDir:!1};let x=L(k);return{dir:x,secureDir:!0,sweepRoot:G(x)}}export{Q as ib,L as jb,T as kb};
@@ -1,2 +1,2 @@
1
- import{Ta as Z,Va as W}from"./index-507jh8bv.js";var R=Z(($G,E)=>{var{defineProperty:N,getOwnPropertyDescriptor:Kz,getOwnPropertyNames:Qz}=Object,Wz=Object.prototype.hasOwnProperty,Xz=(z,G)=>{for(var H in G)N(z,H,{get:G[H],enumerable:!0})},Yz=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of Qz(G))if(!Wz.call(z,K)&&K!==H)N(z,K,{get:()=>G[K],enumerable:!(Q=Kz(G,K))||Q.enumerable})}return z},Zz=(z)=>Yz(N({},"__esModule",{value:!0}),z),O={};Xz(O,{VercelOidcTokenError:()=>S});E.exports=Zz(O);class S extends Error{constructor(z,G){super(z);this.name="VercelOidcTokenError",this.cause=G}toString(){if(this.cause)return`${this.name}: ${this.message}: ${this.cause}`;return`${this.name}: ${this.message}`}}});var P=Z((qG,y)=>{var{create:$z,defineProperty:L,getOwnPropertyDescriptor:qz,getOwnPropertyNames:vz,getPrototypeOf:Bz}=Object,Fz=Object.prototype.hasOwnProperty,Uz=(z,G)=>{for(var H in G)L(z,H,{get:G[H],enumerable:!0})},C=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of vz(G))if(!Fz.call(z,K)&&K!==H)L(z,K,{get:()=>G[K],enumerable:!(Q=qz(G,K))||Q.enumerable})}return z},I=(z,G,H)=>(H=z!=null?$z(Bz(z)):{},C(G||!z||!z.__esModule?L(H,"default",{value:z,enumerable:!0}):H,z)),Lz=(z)=>C(L({},"__esModule",{value:!0}),z),x={};Uz(x,{findRootDir:()=>Jz,getUserDataDir:()=>Nz});y.exports=Lz(x);var B=I(W("path")),bz=I(W("fs")),A=I(W("os")),Vz=R();function Jz(){try{let z=process.cwd();while(z!==B.default.dirname(z)){let G=B.default.join(z,".vercel");if(bz.default.existsSync(G))return z;z=B.default.dirname(z)}}catch(z){throw new Vz.VercelOidcTokenError("Token refresh only supported in node server environments")}return null}function Nz(){if(process.env.XDG_DATA_HOME)return process.env.XDG_DATA_HOME;switch(A.default.platform()){case"darwin":return B.default.join(A.default.homedir(),"Library/Application Support");case"linux":return B.default.join(A.default.homedir(),".local/share");case"win32":if(process.env.LOCALAPPDATA)return process.env.LOCALAPPDATA;return null;default:return null}}});var i=Z((vG,c)=>{var{create:Rz,defineProperty:b,getOwnPropertyDescriptor:Az,getOwnPropertyNames:Iz,getPrototypeOf:Dz}=Object,wz=Object.prototype.hasOwnProperty,Tz=(z,G)=>{for(var H in G)b(z,H,{get:G[H],enumerable:!0})},u=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of Iz(G))if(!wz.call(z,K)&&K!==H)b(z,K,{get:()=>G[K],enumerable:!(Q=Az(G,K))||Q.enumerable})}return z},l=(z,G,H)=>(H=z!=null?Rz(Dz(z)):{},u(G||!z||!z.__esModule?b(H,"default",{value:z,enumerable:!0}):H,z)),jz=(z)=>u(b({},"__esModule",{value:!0}),z),g={};Tz(g,{isValidAccessToken:()=>Ez,readAuthConfig:()=>Oz,writeAuthConfig:()=>Sz});c.exports=jz(g);var F=l(W("fs")),h=l(W("path")),Mz=f();function k(){let z=(0,Mz.getVercelDataDir)();if(!z)throw Error(`Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`);return h.join(z,"auth.json")}function Oz(){try{let z=k();if(!F.existsSync(z))return null;let G=F.readFileSync(z,"utf8");if(!G)return null;return JSON.parse(G)}catch(z){return null}}function Sz(z){let G=k(),H=h.dirname(G);if(!F.existsSync(H))F.mkdirSync(H,{mode:504,recursive:!0});F.writeFileSync(G,JSON.stringify(z,null,2),{mode:384})}function Ez(z,G=0){if(!z.token)return!1;if(typeof z.expiresAt!=="number")return!0;let H=Math.floor(Date.now()/1000),Q=G/1000;return z.expiresAt>=H+Q}});var a=Z((BG,s)=>{var{defineProperty:T,getOwnPropertyDescriptor:Cz,getOwnPropertyNames:xz}=Object,yz=Object.prototype.hasOwnProperty,Pz=(z,G)=>{for(var H in G)T(z,H,{get:G[H],enumerable:!0})},uz=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of xz(G))if(!yz.call(z,K)&&K!==H)T(z,K,{get:()=>G[K],enumerable:!(Q=Cz(G,K))||Q.enumerable})}return z},lz=(z)=>uz(T({},"__esModule",{value:!0}),z),d={};Pz(d,{processTokenResponse:()=>iz,refreshTokenRequest:()=>cz});s.exports=lz(d);var D=W("os"),gz="https://vercel.com",hz="cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp",p=`@vercel/oidc node-${process.version} ${(0,D.platform)()} (${(0,D.arch)()}) ${(0,D.hostname)()}`,w=null;async function kz(){if(w)return w;let z=`${gz}/.well-known/openid-configuration`,G=await fetch(z,{headers:{"user-agent":p}});if(!G.ok)throw Error("Failed to discover OAuth endpoints");let H=await G.json();if(!H||typeof H.token_endpoint!=="string")throw Error("Invalid OAuth discovery response");let Q=H.token_endpoint;return w=Q,Q}async function cz(z){let G=await kz();return await fetch(G,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","user-agent":p},body:new URLSearchParams({client_id:hz,grant_type:"refresh_token",...z})})}async function iz(z){let G=await z.json();if(!z.ok){let H=typeof G==="object"&&G&&"error"in G?String(G.error):"Token refresh failed";return[Error(H)]}if(typeof G!=="object"||G===null)return[Error("Invalid token response")];if(typeof G.access_token!=="string")return[Error("Missing access_token in response")];if(G.token_type!=="Bearer")return[Error("Invalid token_type in response")];if(typeof G.expires_in!=="number")return[Error("Missing expires_in in response")];return[null,G]}});var t=Z((FG,r)=>{var{defineProperty:j,getOwnPropertyDescriptor:fz,getOwnPropertyNames:dz}=Object,pz=Object.prototype.hasOwnProperty,sz=(z,G)=>{for(var H in G)j(z,H,{get:G[H],enumerable:!0})},az=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of dz(G))if(!pz.call(z,K)&&K!==H)j(z,K,{get:()=>G[K],enumerable:!(Q=fz(G,K))||Q.enumerable})}return z},_z=(z)=>az(j({},"__esModule",{value:!0}),z),_={};sz(_,{AccessTokenMissingError:()=>m,RefreshAccessTokenFailedError:()=>n});r.exports=_z(_);class m extends Error{constructor(){super("No authentication found. Please log in with the Vercel CLI (vercel login).");this.name="AccessTokenMissingError"}}class n extends Error{constructor(z){super("Failed to refresh authentication token.",{cause:z});this.name="RefreshAccessTokenFailedError"}}});var f=Z((UG,Hz)=>{var{create:mz,defineProperty:V,getOwnPropertyDescriptor:nz,getOwnPropertyNames:rz,getPrototypeOf:tz}=Object,ez=Object.prototype.hasOwnProperty,oz=(z,G)=>{for(var H in G)V(z,H,{get:G[H],enumerable:!0})},o=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of rz(G))if(!ez.call(z,K)&&K!==H)V(z,K,{get:()=>G[K],enumerable:!(Q=nz(G,K))||Q.enumerable})}return z},zz=(z,G,H)=>(H=z!=null?mz(tz(z)):{},o(G||!z||!z.__esModule?V(H,"default",{value:z,enumerable:!0}):H,z)),zG=(z)=>o(V({},"__esModule",{value:!0}),z),Gz={};oz(Gz,{assertVercelOidcTokenResponse:()=>M,findProjectInfo:()=>QG,getTokenPayload:()=>YG,getVercelDataDir:()=>GG,getVercelOidcToken:()=>KG,getVercelToken:()=>HG,isExpired:()=>ZG,loadToken:()=>XG,saveToken:()=>WG});Hz.exports=zG(Gz);var U=zz(W("path")),X=zz(W("fs")),v=R(),J=P(),$=i(),e=a(),q=t();function GG(){let G=(0,J.getUserDataDir)();if(!G)return null;return U.join(G,"com.vercel.cli")}async function HG(z){let G=(0,$.readAuthConfig)();if(!G?.token)throw new q.AccessTokenMissingError;if((0,$.isValidAccessToken)(G,z?.expirationBufferMs))return G.token;if(!G.refreshToken)throw(0,$.writeAuthConfig)({}),new q.RefreshAccessTokenFailedError("No refresh token available");try{let H=await(0,e.refreshTokenRequest)({refresh_token:G.refreshToken}),[Q,K]=await(0,e.processTokenResponse)(H);if(Q||!K)throw(0,$.writeAuthConfig)({}),new q.RefreshAccessTokenFailedError(Q);let Y={token:K.access_token,expiresAt:Math.floor(Date.now()/1000)+K.expires_in};if(K.refresh_token)Y.refreshToken=K.refresh_token;return(0,$.writeAuthConfig)(Y),Y.token}catch(H){if((0,$.writeAuthConfig)({}),H instanceof q.AccessTokenMissingError||H instanceof q.RefreshAccessTokenFailedError)throw H;throw new q.RefreshAccessTokenFailedError(H)}}async function KG(z,G,H){let Q=`https://api.vercel.com/v1/projects/${G}/token?source=vercel-oidc-refresh${H?`&teamId=${H}`:""}`,K=await fetch(Q,{method:"POST",headers:{Authorization:`Bearer ${z}`}});if(!K.ok)throw new v.VercelOidcTokenError(`Failed to refresh OIDC token: ${K.statusText}`);let Y=await K.json();return M(Y),Y}function M(z){if(!z||typeof z!=="object")throw TypeError("Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again");if(!("token"in z)||typeof z.token!=="string")throw TypeError("Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again")}function QG(){let z=(0,J.findRootDir)();if(!z)throw new v.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");let G=U.join(z,".vercel","project.json");if(!X.existsSync(G))throw new v.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");let H=JSON.parse(X.readFileSync(G,"utf8"));if(typeof H.projectId!=="string"&&typeof H.orgId!=="string")throw TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");return{projectId:H.projectId,teamId:H.orgId}}function WG(z,G){let H=(0,J.getUserDataDir)();if(!H)throw new v.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");let Q=U.join(H,"com.vercel.token",`${G}.json`),K=JSON.stringify(z);X.mkdirSync(U.dirname(Q),{mode:504,recursive:!0}),X.writeFileSync(Q,K),X.chmodSync(Q,432);return}function XG(z){let G=(0,J.getUserDataDir)();if(!G)throw new v.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");let H=U.join(G,"com.vercel.token",`${z}.json`);if(!X.existsSync(H))return null;let Q=JSON.parse(X.readFileSync(H,"utf8"));return M(Q),Q}function YG(z){let G=z.split(".");if(G.length!==3)throw new v.VercelOidcTokenError("Invalid token. Please run `vc env pull` and try again");let H=G[1].replace(/-/g,"+").replace(/_/g,"/"),Q=H.padEnd(H.length+(4-H.length%4)%4,"=");return JSON.parse(Buffer.from(Q,"base64").toString("utf8"))}function ZG(z,G=0){return z.exp*1000<Date.now()+G}});
1
+ import{rb as Z,tb as W}from"./index-9ehhb051.js";var R=Z(($G,E)=>{var{defineProperty:N,getOwnPropertyDescriptor:Kz,getOwnPropertyNames:Qz}=Object,Wz=Object.prototype.hasOwnProperty,Xz=(z,G)=>{for(var H in G)N(z,H,{get:G[H],enumerable:!0})},Yz=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of Qz(G))if(!Wz.call(z,K)&&K!==H)N(z,K,{get:()=>G[K],enumerable:!(Q=Kz(G,K))||Q.enumerable})}return z},Zz=(z)=>Yz(N({},"__esModule",{value:!0}),z),O={};Xz(O,{VercelOidcTokenError:()=>S});E.exports=Zz(O);class S extends Error{constructor(z,G){super(z);this.name="VercelOidcTokenError",this.cause=G}toString(){if(this.cause)return`${this.name}: ${this.message}: ${this.cause}`;return`${this.name}: ${this.message}`}}});var P=Z((qG,y)=>{var{create:$z,defineProperty:L,getOwnPropertyDescriptor:qz,getOwnPropertyNames:vz,getPrototypeOf:Bz}=Object,Fz=Object.prototype.hasOwnProperty,Uz=(z,G)=>{for(var H in G)L(z,H,{get:G[H],enumerable:!0})},C=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of vz(G))if(!Fz.call(z,K)&&K!==H)L(z,K,{get:()=>G[K],enumerable:!(Q=qz(G,K))||Q.enumerable})}return z},I=(z,G,H)=>(H=z!=null?$z(Bz(z)):{},C(G||!z||!z.__esModule?L(H,"default",{value:z,enumerable:!0}):H,z)),Lz=(z)=>C(L({},"__esModule",{value:!0}),z),x={};Uz(x,{findRootDir:()=>Jz,getUserDataDir:()=>Nz});y.exports=Lz(x);var B=I(W("path")),bz=I(W("fs")),A=I(W("os")),Vz=R();function Jz(){try{let z=process.cwd();while(z!==B.default.dirname(z)){let G=B.default.join(z,".vercel");if(bz.default.existsSync(G))return z;z=B.default.dirname(z)}}catch(z){throw new Vz.VercelOidcTokenError("Token refresh only supported in node server environments")}return null}function Nz(){if(process.env.XDG_DATA_HOME)return process.env.XDG_DATA_HOME;switch(A.default.platform()){case"darwin":return B.default.join(A.default.homedir(),"Library/Application Support");case"linux":return B.default.join(A.default.homedir(),".local/share");case"win32":if(process.env.LOCALAPPDATA)return process.env.LOCALAPPDATA;return null;default:return null}}});var i=Z((vG,c)=>{var{create:Rz,defineProperty:b,getOwnPropertyDescriptor:Az,getOwnPropertyNames:Iz,getPrototypeOf:Dz}=Object,wz=Object.prototype.hasOwnProperty,Tz=(z,G)=>{for(var H in G)b(z,H,{get:G[H],enumerable:!0})},u=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of Iz(G))if(!wz.call(z,K)&&K!==H)b(z,K,{get:()=>G[K],enumerable:!(Q=Az(G,K))||Q.enumerable})}return z},l=(z,G,H)=>(H=z!=null?Rz(Dz(z)):{},u(G||!z||!z.__esModule?b(H,"default",{value:z,enumerable:!0}):H,z)),jz=(z)=>u(b({},"__esModule",{value:!0}),z),g={};Tz(g,{isValidAccessToken:()=>Ez,readAuthConfig:()=>Oz,writeAuthConfig:()=>Sz});c.exports=jz(g);var F=l(W("fs")),h=l(W("path")),Mz=f();function k(){let z=(0,Mz.getVercelDataDir)();if(!z)throw Error(`Unable to find Vercel CLI data directory. Your platform: ${process.platform}. Supported: darwin, linux, win32.`);return h.join(z,"auth.json")}function Oz(){try{let z=k();if(!F.existsSync(z))return null;let G=F.readFileSync(z,"utf8");if(!G)return null;return JSON.parse(G)}catch(z){return null}}function Sz(z){let G=k(),H=h.dirname(G);if(!F.existsSync(H))F.mkdirSync(H,{mode:504,recursive:!0});F.writeFileSync(G,JSON.stringify(z,null,2),{mode:384})}function Ez(z,G=0){if(!z.token)return!1;if(typeof z.expiresAt!=="number")return!0;let H=Math.floor(Date.now()/1000),Q=G/1000;return z.expiresAt>=H+Q}});var a=Z((BG,s)=>{var{defineProperty:T,getOwnPropertyDescriptor:Cz,getOwnPropertyNames:xz}=Object,yz=Object.prototype.hasOwnProperty,Pz=(z,G)=>{for(var H in G)T(z,H,{get:G[H],enumerable:!0})},uz=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of xz(G))if(!yz.call(z,K)&&K!==H)T(z,K,{get:()=>G[K],enumerable:!(Q=Cz(G,K))||Q.enumerable})}return z},lz=(z)=>uz(T({},"__esModule",{value:!0}),z),d={};Pz(d,{processTokenResponse:()=>iz,refreshTokenRequest:()=>cz});s.exports=lz(d);var D=W("os"),gz="https://vercel.com",hz="cl_HYyOPBNtFMfHhaUn9L4QPfTZz6TP47bp",p=`@vercel/oidc node-${process.version} ${(0,D.platform)()} (${(0,D.arch)()}) ${(0,D.hostname)()}`,w=null;async function kz(){if(w)return w;let z=`${gz}/.well-known/openid-configuration`,G=await fetch(z,{headers:{"user-agent":p}});if(!G.ok)throw Error("Failed to discover OAuth endpoints");let H=await G.json();if(!H||typeof H.token_endpoint!=="string")throw Error("Invalid OAuth discovery response");let Q=H.token_endpoint;return w=Q,Q}async function cz(z){let G=await kz();return await fetch(G,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","user-agent":p},body:new URLSearchParams({client_id:hz,grant_type:"refresh_token",...z})})}async function iz(z){let G=await z.json();if(!z.ok){let H=typeof G==="object"&&G&&"error"in G?String(G.error):"Token refresh failed";return[Error(H)]}if(typeof G!=="object"||G===null)return[Error("Invalid token response")];if(typeof G.access_token!=="string")return[Error("Missing access_token in response")];if(G.token_type!=="Bearer")return[Error("Invalid token_type in response")];if(typeof G.expires_in!=="number")return[Error("Missing expires_in in response")];return[null,G]}});var t=Z((FG,r)=>{var{defineProperty:j,getOwnPropertyDescriptor:fz,getOwnPropertyNames:dz}=Object,pz=Object.prototype.hasOwnProperty,sz=(z,G)=>{for(var H in G)j(z,H,{get:G[H],enumerable:!0})},az=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of dz(G))if(!pz.call(z,K)&&K!==H)j(z,K,{get:()=>G[K],enumerable:!(Q=fz(G,K))||Q.enumerable})}return z},_z=(z)=>az(j({},"__esModule",{value:!0}),z),_={};sz(_,{AccessTokenMissingError:()=>m,RefreshAccessTokenFailedError:()=>n});r.exports=_z(_);class m extends Error{constructor(){super("No authentication found. Please log in with the Vercel CLI (vercel login).");this.name="AccessTokenMissingError"}}class n extends Error{constructor(z){super("Failed to refresh authentication token.",{cause:z});this.name="RefreshAccessTokenFailedError"}}});var f=Z((UG,Hz)=>{var{create:mz,defineProperty:V,getOwnPropertyDescriptor:nz,getOwnPropertyNames:rz,getPrototypeOf:tz}=Object,ez=Object.prototype.hasOwnProperty,oz=(z,G)=>{for(var H in G)V(z,H,{get:G[H],enumerable:!0})},o=(z,G,H,Q)=>{if(G&&typeof G==="object"||typeof G==="function"){for(let K of rz(G))if(!ez.call(z,K)&&K!==H)V(z,K,{get:()=>G[K],enumerable:!(Q=nz(G,K))||Q.enumerable})}return z},zz=(z,G,H)=>(H=z!=null?mz(tz(z)):{},o(G||!z||!z.__esModule?V(H,"default",{value:z,enumerable:!0}):H,z)),zG=(z)=>o(V({},"__esModule",{value:!0}),z),Gz={};oz(Gz,{assertVercelOidcTokenResponse:()=>M,findProjectInfo:()=>QG,getTokenPayload:()=>YG,getVercelDataDir:()=>GG,getVercelOidcToken:()=>KG,getVercelToken:()=>HG,isExpired:()=>ZG,loadToken:()=>XG,saveToken:()=>WG});Hz.exports=zG(Gz);var U=zz(W("path")),X=zz(W("fs")),v=R(),J=P(),$=i(),e=a(),q=t();function GG(){let G=(0,J.getUserDataDir)();if(!G)return null;return U.join(G,"com.vercel.cli")}async function HG(z){let G=(0,$.readAuthConfig)();if(!G?.token)throw new q.AccessTokenMissingError;if((0,$.isValidAccessToken)(G,z?.expirationBufferMs))return G.token;if(!G.refreshToken)throw(0,$.writeAuthConfig)({}),new q.RefreshAccessTokenFailedError("No refresh token available");try{let H=await(0,e.refreshTokenRequest)({refresh_token:G.refreshToken}),[Q,K]=await(0,e.processTokenResponse)(H);if(Q||!K)throw(0,$.writeAuthConfig)({}),new q.RefreshAccessTokenFailedError(Q);let Y={token:K.access_token,expiresAt:Math.floor(Date.now()/1000)+K.expires_in};if(K.refresh_token)Y.refreshToken=K.refresh_token;return(0,$.writeAuthConfig)(Y),Y.token}catch(H){if((0,$.writeAuthConfig)({}),H instanceof q.AccessTokenMissingError||H instanceof q.RefreshAccessTokenFailedError)throw H;throw new q.RefreshAccessTokenFailedError(H)}}async function KG(z,G,H){let Q=`https://api.vercel.com/v1/projects/${G}/token?source=vercel-oidc-refresh${H?`&teamId=${H}`:""}`,K=await fetch(Q,{method:"POST",headers:{Authorization:`Bearer ${z}`}});if(!K.ok)throw new v.VercelOidcTokenError(`Failed to refresh OIDC token: ${K.statusText}`);let Y=await K.json();return M(Y),Y}function M(z){if(!z||typeof z!=="object")throw TypeError("Vercel OIDC token is malformed. Expected an object. Please run `vc env pull` and try again");if(!("token"in z)||typeof z.token!=="string")throw TypeError("Vercel OIDC token is malformed. Expected a string-valued token property. Please run `vc env pull` and try again")}function QG(){let z=(0,J.findRootDir)();if(!z)throw new v.VercelOidcTokenError("Unable to find project root directory. Have you linked your project with `vc link?`");let G=U.join(z,".vercel","project.json");if(!X.existsSync(G))throw new v.VercelOidcTokenError("project.json not found, have you linked your project with `vc link?`");let H=JSON.parse(X.readFileSync(G,"utf8"));if(typeof H.projectId!=="string"&&typeof H.orgId!=="string")throw TypeError("Expected a string-valued projectId property. Try running `vc link` to re-link your project.");return{projectId:H.projectId,teamId:H.orgId}}function WG(z,G){let H=(0,J.getUserDataDir)();if(!H)throw new v.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");let Q=U.join(H,"com.vercel.token",`${G}.json`),K=JSON.stringify(z);X.mkdirSync(U.dirname(Q),{mode:504,recursive:!0}),X.writeFileSync(Q,K),X.chmodSync(Q,432);return}function XG(z){let G=(0,J.getUserDataDir)();if(!G)throw new v.VercelOidcTokenError("Unable to find user data directory. Please reach out to Vercel support.");let H=U.join(G,"com.vercel.token",`${z}.json`);if(!X.existsSync(H))return null;let Q=JSON.parse(X.readFileSync(H,"utf8"));return M(Q),Q}function YG(z){let G=z.split(".");if(G.length!==3)throw new v.VercelOidcTokenError("Invalid token. Please run `vc env pull` and try again");let H=G[1].replace(/-/g,"+").replace(/_/g,"/"),Q=H.padEnd(H.length+(4-H.length%4)%4,"=");return JSON.parse(Buffer.from(Q,"base64").toString("utf8"))}function ZG(z,G=0){return z.exp*1000<Date.now()+G}});
2
2
  export{R as a,f as b};