@cortexkit/opencode-openai-auth 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -60
- package/dist/bin.js +13 -0
- package/dist/index-116q849r.js +2 -0
- package/dist/index-4fnghj9e.js +65 -0
- package/dist/index-66asrje2.js +2 -0
- package/dist/index-826s1yxa.js +2 -0
- package/dist/index-a69gr76b.js +2 -0
- package/dist/index-fsky1rsh.js +12 -0
- package/dist/index-fsxbncpw.js +3 -0
- package/dist/index-h263aftt.js +157 -0
- package/dist/{index-hy9030jh.js → index-nx2qh047.js} +1 -1
- package/dist/{index-766sfrh5.js → index-pg305s90.js} +1 -1
- package/dist/index-ssj7m2rd.js +8 -0
- package/dist/index-y4gxyxqd.js +2 -0
- package/dist/index-ydz3hbhc.js +2 -0
- package/dist/index.d.ts +2 -56
- package/dist/index.js +1 -1
- package/dist/map-m6f5a_IA.d.ts +56 -0
- package/dist/{pool-lifecycle-YLz2B8A5.d.ts → pool-lifecycle-C_6YRmsh.d.ts} +99 -789
- package/dist/{port-file-Do3lQIEk.d.ts → port-file-ZPlxXB4G.d.ts} +1 -1
- package/dist/{protocol-BOBdkqqm.d.ts → protocol-DctqemRI.d.ts} +1 -1
- package/dist/rpc/port-file.d.ts +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.d.ts +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.d.ts +3 -3
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/{sidebar-state-D6cUKgkm.d.ts → sidebar-state-z_M7Trnd.d.ts} +5 -3
- package/dist/sidebar-state.d.ts +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-ypk61xj0.js → token-bzhkgc29.js} +1 -1
- package/dist/token-util-4a2xxnpg.js +1 -0
- package/dist/tui-preferences.d.ts +2 -1
- package/dist/tui-preferences.js +3 -3
- package/dist/tui.d.ts +2 -2
- package/dist/v2/server.d.ts +1 -1
- package/dist/v2/server.js +3 -4
- package/package.json +13 -8
- package/src/tui-compiled/raw/logger.js +10 -2
- package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +65 -34
- package/src/tui-compiled/raw/shared/053cc17b5419261e-codec.js +2 -1
- package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +26 -10
- package/src/tui-compiled/raw/shared/375d9cca2def037d-private-files.js +302 -0
- package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +3 -1
- package/src/tui-compiled/raw/shared/43fc9e6b994519c7-refresh-lock.js +5 -0
- package/src/tui-compiled/raw/shared/458b934e92490331-mutate.js +2 -2
- package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +4 -0
- package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +21 -5
- package/src/tui-compiled/raw/shared/7211cfec06a298bc-atomic-write.js +21 -0
- package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +36 -1
- package/src/tui-compiled/raw/shared/a09b6a533c11858f-tui-preferences.js +6 -4
- package/src/tui-compiled/raw/shared/c14988621dc60a75-port-file.js +30 -8
- package/src/tui-compiled/raw/shared/c64d7afbc14ca125-sidebar-file.js +17 -8
- package/src/tui-compiled/raw/shared/c852a15cfe489d12-pool.js +3 -0
- package/src/tui-compiled/raw/shared/cd94316a888b0a8e-schema.js +3 -2
- package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +2 -2
- package/src/tui-compiled/raw/shared/d7dcba96fea1685c-engine.js +126 -11
- package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +254 -37
- package/src/tui-compiled/raw/shared/ec971142548df90e-index.js +1 -0
- package/src/tui-compiled/raw/shared/fbcdcd0f925e74c0-rpc-client.js +15 -1
- package/src/tui-compiled/runtime/logger.js +10 -2
- package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +65 -34
- package/src/tui-compiled/runtime/shared/053cc17b5419261e-codec.js +2 -1
- package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +26 -10
- package/src/tui-compiled/runtime/shared/375d9cca2def037d-private-files.js +302 -0
- package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +3 -1
- package/src/tui-compiled/runtime/shared/43fc9e6b994519c7-refresh-lock.js +5 -0
- package/src/tui-compiled/runtime/shared/458b934e92490331-mutate.js +2 -2
- package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +4 -0
- package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +21 -5
- package/src/tui-compiled/runtime/shared/7211cfec06a298bc-atomic-write.js +21 -0
- package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +36 -1
- package/src/tui-compiled/runtime/shared/a09b6a533c11858f-tui-preferences.js +6 -4
- package/src/tui-compiled/runtime/shared/c14988621dc60a75-port-file.js +30 -8
- package/src/tui-compiled/runtime/shared/c64d7afbc14ca125-sidebar-file.js +17 -8
- package/src/tui-compiled/runtime/shared/c852a15cfe489d12-pool.js +3 -0
- package/src/tui-compiled/runtime/shared/cd94316a888b0a8e-schema.js +3 -2
- package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +2 -2
- package/src/tui-compiled/runtime/shared/d7dcba96fea1685c-engine.js +126 -11
- package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +254 -37
- package/src/tui-compiled/runtime/shared/ec971142548df90e-index.js +1 -0
- package/src/tui-compiled/runtime/shared/fbcdcd0f925e74c0-rpc-client.js +15 -1
- package/dist/index-8kj7sa1p.js +0 -12
- package/dist/index-b3q3j39x.js +0 -2
- package/dist/index-bmd7x5aq.js +0 -2
- package/dist/index-ff1jy44a.js +0 -222
- package/dist/index-jyr8y8k4.js +0 -7
- package/dist/index-rv08jmd4.js +0 -2
- package/dist/index-sjx8t1nr.js +0 -2
- package/dist/token-util-wdza526f.js +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{pe as Z,re as W}from"./index-66asrje2.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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createHash as B}from"node:crypto";import{homedir as G,tmpdir as W}from"node:os";import{dirname as J,join as w,resolve as z}from"node:path";var A="OPENCODE_OPENAI_AUTH_RPC_DIR",K="openai-auth-";function L(k){return B("sha256").update(k).digest("hex").slice(0,16)}function M(){let k=process.env.XDG_STATE_HOME||w(G(),".local","state");return w(k,"cortexkit","openai-auth","rpc")}function Q(k){let q=process.env[A]?.trim();if(q)return z(k,q);return w(M(),`${K}${L(k)}`)}async function $(k){let q=process.env[A]?.trim();if(q)return{dir:z(k,q),secureDir:!1};let x=Q(k);return{dir:x,secureDir:!0,sweepRoot:J(x)}}export{W as
|
|
1
|
+
import{createHash as B}from"node:crypto";import{homedir as G,tmpdir as W}from"node:os";import{dirname as J,join as w,resolve as z}from"node:path";var A="OPENCODE_OPENAI_AUTH_RPC_DIR",K="openai-auth-";function L(k){return B("sha256").update(k).digest("hex").slice(0,16)}function M(){let k=process.env.XDG_STATE_HOME||w(G(),".local","state");return w(k,"cortexkit","openai-auth","rpc")}function Q(k){let q=process.env[A]?.trim();if(q)return z(k,q);return w(M(),`${K}${L(k)}`)}async function $(k){let q=process.env[A]?.trim();if(q)return{dir:z(k,q),secureDir:!1};let x=Q(k);return{dir:x,secureDir:!0,sweepRoot:J(x)}}export{W as le,K as me,Q as ne,$ as oe};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{ae as G,be as q,ce as V0,ee as U,fe as h,ge as S,he as v,ie as _0,ke as b}from"./index-116q849r.js";import{randomUUID as I}from"node:crypto";import{mkdir as G0,open as x0,readFile as H0,rename as Q0,rm as L,stat as Y0,writeFile as Z0}from"node:fs/promises";import{dirname as P,join as J0}from"node:path";function N0($,W){return`${$}.${W}.lock`}class W0 extends Error{details;constructor($){super(`Timed out acquiring ${$.name} lock for ${$.target}`);this.name="LockContentionError",this.details=$}}class R extends Error{details;constructor($){super(`Lost ${$.name} lock for ${$.target}`);this.name="LockOwnershipError",this.details=$}}async function O0($,W,Q){let Y=performance.now();for(;;){let Z=await K0({path:$,name:W.name,ttlMs:W.ttlMs,renew:W.renew??!1,...W.onStep?{onStep:W.onStep}:{},...W.onRenewalTimer?{onRenewalTimer:W.onRenewalTimer}:{}});if(Z)try{return await Q(Z)}finally{await Z.release()}let J=W.timeoutMs-(performance.now()-Y);if(J<=0)throw new W0({target:$,name:W.name,timeoutMs:W.timeoutMs});await new Promise((_)=>setTimeout(_,Math.min(25,Math.ceil(J))))}}var g0=globalThis.setTimeout.bind(globalThis),D0=globalThis.clearTimeout.bind(globalThis);function q0($){let W=$?.code;return W==="ENOENT"||!G&&(W==="EINVAL"||W==="ENOTDIR")}async function K0($){let W=N0($.path,$.name),Q=J0(W,"owner.json"),Y=I(),Z=$.now??Date.now,J=null,_=!1,g=!1,B,l,X0=new Promise((z)=>{l=z});function p(z){try{let K=$.onRenewalTimer?.(z);if(K&&(typeof K==="object"||typeof K==="function")&&"then"in K&&typeof K.then==="function")Promise.resolve(K).catch(()=>{})}catch{}}function d(){if(!J)return;D0(J),J=null,p("cancelled")}function C(z,K){if(B||_)return;B=Object.freeze({reason:z,expectedOwnerId:Y,...typeof K?.ownerId==="string"?{observedOwnerId:K.ownerId}:{},...typeof K?.expiresAt==="number"?{observedExpiresAt:K.expiresAt}:{}}),d(),l(B)}let E,f=null,x=`${W}.evicting`,M=J0(x,"owner.json"),a=I(),j0=5000,y=8;async function j(){if(G)try{return JSON.parse(await S(W,!0))}catch(z){if(z.code!=="EISDIR"&&z.reason!=="wrong-kind")throw z;return await U(W,"directory",!0),JSON.parse(await S(Q,!0))}try{return JSON.parse(await H0(W,"utf8"))}catch(z){if(z.code!=="EISDIR")throw z;return JSON.parse(await H0(Q,"utf8"))}}async function C0(){if(G){let H=await j(),V=Number(H?.expiresAt)-Z();await b(W,`${JSON.stringify({ownerId:Y,expiresAt:Z()+$.ttlMs})}
|
|
2
|
+
`,{deadline:performance.now()+Math.max(0,V),beforeRename:async()=>{let A=await j();if(A?.ownerId!==Y||!(Number(A?.expiresAt)>Z())||!await X())throw new R({target:$.path,name:$.name})}});return}let z=`${W}.${I()}.tmp`,K,N=!1;try{K=await x0(z,"wx",384),N=!0,await K.writeFile(`${JSON.stringify({ownerId:Y,expiresAt:Z()+$.ttlMs})}
|
|
3
|
+
`,"utf8"),await K.chmod(384),await K.close(),K=void 0;let H=await j();if(H?.ownerId!==Y||!(Number(H?.expiresAt)>Z())||!await X())throw new R({target:$.path,name:$.name});await Q0(z,W),N=!1}finally{if(await K?.close().catch(()=>{}),N)await L(z,{force:!0}).catch(()=>{})}}async function s(){let z=`${JSON.stringify({ownerId:Y,expiresAt:Z()+$.ttlMs})}
|
|
4
|
+
`;if(G)await v(W,z);else await Z0(W,z,{encoding:"utf8",mode:384,flag:"wx"})}async function n(z){let K=z.code;if(K==="EEXIST"){if(G)await j();return!0}if(K==="EISDIR"){if(G)await U(W,"directory",!0),await S(Q,!0);return!0}return!1}async function k(){if(G)await h(P(W));try{return await s(),!0}catch(z){let K=z.code;if(await n(z))return!1;if(K==="ENOENT"){if(G)await h(P(W));else await G0(P(W),{recursive:!0});try{return await s(),!0}catch(N){if(await n(N))return!1;throw N}}throw z}}async function O(){await new Promise((z)=>setTimeout(z,Math.floor(Math.random()*4)))}async function m(z=!0){if(z&&$.onStep)await $.onStep("lock-read-ready");let K;try{K=await j()}catch(H){if(G&&H.code!=="ENOENT")throw H}let N=Number(K?.expiresAt);if(Number.isFinite(N)&&N>Z())return{status:"live"};if(typeof K?.ownerId==="string"&&Number.isFinite(N))return{status:"stale",identity:{kind:"owner",ownerId:K.ownerId,expiresAt:N}};try{let H=await Y0(W),V=Number.isFinite(N)?N:H.mtimeMs+$.ttlMs;if(V>Z())return{status:"live"};return{status:"stale",identity:{kind:"stat",dev:H.dev,ino:H.ino,mtimeMs:H.mtimeMs,expiresAt:V}}}catch(H){if(H.code==="ENOENT"){if($.onStep)await $.onStep("lock-missing");return{status:"missing"}}throw H}}function i(z,K){if(K.status!=="stale")return!1;let N=K.identity;if(z.kind==="owner"&&N.kind==="owner")return z.ownerId===N.ownerId&&z.expiresAt===N.expiresAt;return z.kind==="stat"&&N.kind==="stat"&&z.dev===N.dev&&z.ino===N.ino&&z.mtimeMs===N.mtimeMs&&z.expiresAt===N.expiresAt}async function X(){try{return JSON.parse(await S(M,G))?.ownerId===a}catch(z){if(G&&z.code!=="ENOENT")throw z;return!1}}async function T(z){if(G)await V0(z,"remove",()=>L(z,{recursive:!0,force:!0}));else await L(z,{recursive:!0,force:!0}).catch(()=>{})}async function u(){if(await X())await T(x)}async function t(){if(G)await _0(x);else await G0(x);try{let z=`${JSON.stringify({ownerId:a,createdAt:Z()})}
|
|
5
|
+
`;if(G)await v(M,z);else await Z0(M,z,{encoding:"utf8",mode:384,flag:"wx"})}catch(z){if(q0(z))return!1;throw await u(),z}if($.onStep)await $.onStep("eviction-marker-acquired");return!0}async function r(){let z;try{z=await Y0(x)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if(G)await U(x,"directory",!0);if(z.mtimeMs+j0>Z())return"fresh";if($.onStep)await $.onStep("stale-marker-stat");let K=`${x}.${I()}`;try{await Q0(x,K)}catch(N){if(N.code==="ENOENT")return"missing";throw N}if($.onStep)await $.onStep("stale-marker-claimed");return await T(K),"recovered"}async function o(z){try{if(!await t())return!1}catch(K){if(K.code==="EEXIST"){if(G){await U(x,"directory",!0);try{await S(M,!0)}catch(N){if(N.code!=="ENOENT")throw N}}return!1}throw K}try{await z()}finally{await u()}return!0}async function e(){for(let z=0;z<y;z++){if($.onStep)await $.onStep("relinquish-read");let K;try{K=await j()}catch(N){if(G)throw N;return}if(K?.ownerId!==Y)return;try{await L(W,{recursive:!0,force:!0});return}catch(N){if(G)throw N;await O()}}}function $0(){if(!$.renew||_||B)return;let z=$.renewIntervalMs??Math.max(1000,Math.floor($.ttlMs/3));if(J=g0(()=>{J=null;let K=(async()=>{let N=!_;try{if(!await o(async()=>{let V=await j(),A=Z();if(_||B){N=!1;return}if(V?.ownerId!==Y){C("taken-over",V),N=!1;return}if(!(Number(V?.expiresAt)>A)){C("expired",V),N=!1;return}if($.onStep)await $.onStep("renewal-owner-confirmed");if(_||B){N=!1;return}if(!await X())return;if($.onStep)await $.onStep("renewal-write-fenced");if(_||B){N=!1;return}if(!await X())return;if($.onStep)await $.onStep("renewal-write-ready");if(_||B){N=!1;return}if(await C0(),$.onStep)await $.onStep("renewal-write-finished");if(!await X()){C("marker-lost"),N=!1,await e();return}})&&$.onStep)await $.onStep("renewal-marker-unavailable")}catch(H){if(G&&H instanceof q)E=H,C("renewal-failed"),N=!1;try{let V=await j();if(V?.ownerId!==Y)C("taken-over",V);else if(!(Number(V?.expiresAt)>Z()))C("expired",V)}catch{C("renewal-failed")}}finally{if($.onStep)try{await $.onStep("renewal-finished")}catch{}if(N&&!_&&!B)$0()}})();f=K,K.finally(()=>{if(f===K)f=null})},z),"unref"in J)J.unref();p("scheduled")}function z0(){try{let z=$.onContended?.();if(z&&(typeof z==="object"||typeof z==="function")&&"then"in z&&typeof z.then==="function")Promise.resolve(z).catch(()=>{})}catch{}return null}let D=await k();if(!D)for(let z=0;z<y;z++){if(D=await k(),D)break;let K=await m();if(K.status==="live")return z0();if(K.status==="missing")continue;if($.onStep)await $.onStep("stale-lock-observed");try{if(!await t()){await O();continue}}catch(N){if(N.code!=="EEXIST")throw N;if(await r()==="fresh")return null;await O();continue}try{let N=await m();if(N.status==="live")return z0();if(!i(K.identity,N))continue;if(!await X())return null;if($.onStep)await $.onStep("stale-lock-confirmed");if(!await X())return null;let H=await m(!1);if(!i(K.identity,H))continue;if(await T(W),!await X())return null;if($.onStep)await $.onStep("stale-lock-removed");if(D=await k(),!D)return null;if($.onStep)await $.onStep("stale-lock-recreated");if(!await X())return await e(),D=!1,null;break}finally{await u()}}if(!D)return null;return $0(),{ownerId:Y,whenLost:()=>X0,hasLost:()=>B!==void 0,assertOwned:async()=>{if(E)throw E;let z;try{let K=await j();if(z=K,!_&&!B&&K?.ownerId===Y&&Number(K?.expiresAt)>Z())return;C(K?.ownerId!==Y?"taken-over":"expired",K)}catch(K){if(C("unreadable"),G&&K instanceof q)throw K}throw new R({target:$.path,name:$.name,expectedOwnerId:Y,...typeof z?.ownerId==="string"?{observedOwnerId:z.ownerId}:{},...typeof z?.expiresAt==="number"?{observedExpiresAt:z.expiresAt}:{}})},release:async()=>{if(G&&g)return;_=!0,d(),await f;for(let z=0;z<y;z++){try{let K=!1;if(await o(async()=>{let H;try{H=await j()}catch(V){if(G&&V.code==="ENOENT"){K=!0;return}throw V}if(H?.ownerId!==Y){K=!0;return}if($.onStep)await $.onStep("release-owner-confirmed");if(!await X())return;await T(W),K=!0})){if(G&&!K)throw new q(W,"release-not-confirmed",{code:"EIO"});g=K;return}await r()}catch(K){if(G)throw K;return}await O()}if(G)throw new q(W,"release-not-confirmed",{code:"ETIMEDOUT"})}}}import{randomUUID as B0}from"node:crypto";import{mkdir as U0,open as F,rename as S0,rm as R0}from"node:fs/promises";import{dirname as w}from"node:path";class c extends Error{constructor($){super("file or directory sync failed",{cause:$});this.name="AtomicSyncError"}}async function P0($,W,Q={}){await f0($,W,Q)}async function f0($,W,Q,Y){if(G)return b($,Q.serialize?Q.serialize(W):`${JSON.stringify(W,null,2)}
|
|
6
|
+
`,{beforeRename:Q.beforeRename,stagePath:`${$}.${(Q.stageName??B0)()}.tmp`,onRenamed:Y,durable:Q.durable,durability:Q.durability,onOutcome:Q.onOutcome});await U0(w($),{recursive:!0});let Z=`${$}.${(Q.stageName??B0)()}.tmp`,J,_=!1;try{if(J=await F(Z,"wx",384),_=!0,await J.writeFile(Q.serialize?Q.serialize(W):`${JSON.stringify(W,null,2)}
|
|
7
|
+
`,"utf8"),await J.chmod(384),Q.durable)try{await J.sync()}catch(g){throw new c(g)}if(await J.close(),J=void 0,await Q.beforeRename?.(),await S0(Z,$),_=!1,Y?.(),Q.durable){let g=await F(w($),"r");try{await g.sync()}catch(B){throw new c(B)}finally{await g.close()}}}finally{if(await J?.close().catch(()=>{}),_)await R0(Z,{force:!0}).catch(()=>{})}}async function h0($){if(G){await U($,"file");let Y=new q($,"directory-sync-unsupported",{code:"ENOTSUP"});throw Y.published=!0,Y}let W=await F($,"r");try{await W.sync()}finally{await W.close()}let Q=await F(w($),"r");try{await Q.sync()}finally{await Q.close()}}var w0=Object.freeze({sidebar:Object.freeze({name:"sidebar-write",ttlMs:1e4,timeoutMs:15000,renew:!0}),preferences:Object.freeze({name:"preferences",ttlMs:1e4,timeoutMs:2000,renew:!0})});
|
|
8
|
+
export{c as wd,P0 as xd,f0 as yd,h0 as zd,K0 as Ad,W0 as Bd,R as Cd,O0 as Dd,w0 as Ed};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ae as q,ce as O,ee as A,fe as y,he as p,je as k}from"./index-116q849r.js";import{appendFileSync as QJ,chmodSync as UJ,existsSync as W,renameSync as g,statSync as ZJ}from"node:fs";import{open as $J}from"node:fs/promises";import{dirname as VJ,resolve as IJ}from"node:path";var i=/^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i,e=/\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;function JJ(J){return J instanceof Error||Object.prototype.toString.call(J)==="[object Error]"}function T(J={}){let H=[e,...J.extraValuePatterns??[]].map((G)=>new RegExp(G.source,G.flags.includes("g")?G.flags:`${G.flags}g`));function Z(G){let U=G.toLowerCase().replace(/[-_]/g,"");return i.test(G)||U.includes("apikey")||U.endsWith("secret")||U.endsWith("password")||U.endsWith("token")&&!U.endsWith("tokens")||!!J.extraSecretKeys?.(U)}function I(G){let U=G,$=[["name",G.name],["message",G.message],["stack",G.stack]];for(let j of["code","status","cause"])if(U[j]!==void 0)$.push([j,U[j]]);let Y=new Set($.map(([j])=>j));for(let j of Object.entries(G))if(!Y.has(j[0]))$.push(j);return $}function B(G,U,$,Y=0){if(typeof G==="string")return H.reduce((j,C)=>j.replace(C,"***REDACTED***"),G);if(!G||typeof G!=="object")return G;if($.has(G))return"[Circular]";$.add(G);try{if(Array.isArray(G))return G.map((N)=>B(N,U,$,Y));let j=JJ(G);if(j&&Y>=8)return"[Truncated]";let C=j?Y+1:Y;return Object.fromEntries((j?I(G):Object.entries(G)).map(([N,z])=>[N,U&&Z(N)?"***REDACTED***":B(z,U,$,C)]))}finally{$.delete(G)}}return{redact:(G)=>B(G,!0,new WeakSet),redactStrings:(G)=>B(G,!1,new WeakSet)}}var F=T(),GJ=F.redact,HJ=F.redactStrings;var D={error:0,warn:1,info:2,debug:3,trace:4},h=5242880,m=3;function b(J){try{UJ(J,384)}catch{}}function jJ(J){try{if(!(W(J)&&ZJ(J).size>=h))return;for(let Z=m-1;Z>=1;Z--)if(W(`${J}.${Z}`)){let I=`${J}.${Z+1}`;g(`${J}.${Z}`,I),b(I)}let H=`${J}.1`;g(J,H),b(H)}catch{}}async function M(J){let{file:H,handle:Z}=J;if(J.file=void 0,J.handle=void 0,H&&Z)await O(H,"log-close",()=>Z.close())}async function w(J,H){await y(VJ(H));try{await A(H,"file",!0)}catch(Z){if(Z.code!=="ENOENT")throw Z;try{await p(H,"")}catch(I){if(I.code!=="EEXIST")throw I;await A(H,"file",!0)}}return J.handle=await O(H,"log-open",()=>$J(H,"a")),J.file=H,J.handle}async function XJ(J,H,Z){H=IJ(H);try{if(J.file!==H)await M(J);let I=J.handle??await w(J,H);if((await O(H,"log-stat",()=>I.stat())).size>=h){await M(J);for(let G=m-1;G>=0;G--){let U=G===0?H:`${H}.${G}`,$=`${H}.${G+1}`;try{await A(U,"file",!0)}catch(Y){if(Y.code==="ENOENT")continue;throw Y}try{await A($,"file",!0)}catch(Y){if(Y.code!=="ENOENT")throw Y}await k(U,$),await A($,"file")}I=await w(J,H)}await O(H,"log-append",()=>I.appendFile(Z,"utf8"))}catch(I){throw await M(J).catch(()=>{}),I}}function YJ(J){try{return` ${JSON.stringify(J)}`}catch{return" [unserializable]"}}function BJ(J){let H,Z,I,B=T(),G,U=[],$,Y=Promise.resolve(),j,C={};function N(Q){let V=Y.then(Q);return Y=V.catch((X)=>{j=X}),V}function z(Q){if(q&&Q.file!==H)N(()=>M(C)).catch(()=>{});H=Q.file,Z=Q.level,B=T(Q),G=Q.captureSink}function s(Q){if(Q===void 0||Q in D)I=Q}function o(){if(H===void 0)return;return(typeof H==="function"?H():H)||void 0}function t(){if(I)return I;let Q=typeof Z==="function"?Z():Z;if(Q&&Q in D)return Q;return"info"}function R(Q=!0){if($)clearTimeout($),$=void 0;if(!U.length){if(q)return N(async()=>{if(Q)await M(C);if(j)throw j});return}let V;try{V=o()}catch{if(U=[],q&&Q)return N(()=>M(C));return}let X=U.join("");if(U=[],!V){if(q&&Q)return N(()=>M(C));return}if(q)return N(async()=>{try{await XJ(C,V,X)}finally{if(Q)await M(C)}});try{if(jJ(V),W(V))b(V);QJ(V,X,{encoding:"utf8",mode:384})}catch{}}function a(){if(!$)$=setTimeout(()=>{$=void 0;let Q=R(!1);if(Q instanceof Promise)Q.catch(()=>{})},500)}function _(Q,V,X,P){if(H===void 0&&G===void 0)return;try{if(D[V]>D[t()])return;let S=B.redactStrings(X),K;try{K=B.redact(P)}catch{K="[unserializable]"}let r=`[${new Date().toISOString()}] ${V.toUpperCase()} [${Q}] ${S}`+(P===void 0?"":YJ(K))+`
|
|
2
|
+
`;try{G?.({channel:Q,level:V,message:S,data:K})}catch{}if(H===void 0)return;if(U.push(r),U.length>=50){let E=R(!1);if(E instanceof Promise)E.catch(()=>{})}else a()}catch{}}function n(Q){return{error:(V,X)=>_(Q,"error",V,X),warn:(V,X)=>_(Q,"warn",V,X),info:(V,X)=>_(Q,"info",V,X),debug:(V,X)=>_(Q,"debug",V,X),trace:(V,X)=>_(Q,"trace",V,X)}}function l(){if(q)N(()=>M(C)).catch(()=>{});if(j=void 0,U=[],$)clearTimeout($),$=void 0;H=void 0,Z=void 0,I=void 0,B=T(),G=void 0}if(J)z(J);return{configure:z,createLogger:n,setLogLevel:s,flushLogs:R,reset:l}}var x=BJ();function L(J){x.configure(J);let{configure:H,createLogger:Z,setLogLevel:I,flushLogs:B}=x;return{configure:H,createLogger:Z,setLogLevel:I,flushLogs:B}}function v(J){x.setLogLevel(J)}function u(){return x.flushLogs()}function c(J){return x.createLogger(J)}function f(J){return J==="chatgptaccountid"||J==="email"||J==="orgname"||J==="organizationname"}var d=T({extraSecretKeys:f}),kJ=d.redact,hJ=d.redactStrings;function mJ(J){L({...J,extraSecretKeys:f})}function cJ(J){if(J instanceof Error)return J.message;if(typeof J==="string")return J;try{return JSON.stringify(J)}catch{return String(J)}}function dJ(J){return"notify"in J}import{basename as MJ,dirname as TJ,join as qJ}from"node:path";var AJ="openai-auth.json",_J="openai-auth-state.json";function tJ(J){return MJ(J)===AJ?qJ(TJ(J),_J):`${J}.state.json`}import{execFileSync as OJ,spawn as xJ}from"node:child_process";function lJ(J,H=process.platform,Z=OJ,I=xJ){try{if(H==="win32"){let B=`Start-Process '${J.replaceAll("'","''")}'`,G=Buffer.from(B,"utf16le").toString("base64"),U=I("powershell.exe",["-NoProfile","-NonInteractive","-WindowStyle","Hidden","-EncodedCommand",G],{stdio:"ignore",windowsHide:!0});return U.on("error",()=>{}),U.unref(),U.pid!==void 0}return Z(H==="darwin"?"open":"xdg-open",[J],{stdio:"ignore",timeout:3000}),!0}catch{return!1}}export{T as Rd,v as Sd,u as Td,c as Ud,hJ as Vd,mJ as Wd,AJ as Xd,tJ as Yd,cJ as Zd,dJ as _d,lJ as $d};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{pd as BZ,rd as QZ,sd as UZ}from"./index-a69gr76b.js";import{Bd as $Z,Cd as JZ,Dd as y,Ed as I,xd as ZZ}from"./index-ssj7m2rd.js";import{Ud as DZ}from"./index-y4gxyxqd.js";import{ae as x,be as t,fe as A,ge as e}from"./index-116q849r.js";import{createHash as AZ}from"node:crypto";import{constants as yZ,copyFileSync as kZ,mkdirSync as wZ,statSync as hZ}from"node:fs";import{readFile as mZ}from"node:fs/promises";import{homedir as pZ,tmpdir as gZ}from"node:os";import{dirname as dZ,join as h}from"node:path";import{chmod as bZ,mkdir as vZ}from"node:fs/promises";import{dirname as n}from"node:path";function k(Z){let{path:$,defaultValue:V,normalize:J}=Z,X=Promise.resolve(),Y=(G)=>{if(G==="")return V;try{return J(JSON.parse(G))}catch{return V}},j=async()=>{try{if(x)await A(n($),Z.secureDir??!0);return await e($,x)}catch(G){if(G.code==="ENOENT")return"";throw G}},z=async()=>{try{return Y(await j())}catch(G){if(G instanceof t)throw G;return V}},Q=(G,D)=>{let N=X.then(G).then((P)=>D?.onResult?.(P));return X=N.catch(()=>{}),N},B={...I.sidebar,name:Z.lockName??I.sidebar.name,timeoutMs:Z.timeoutMs??I.sidebar.timeoutMs},K=async(G,D,N)=>{await ZZ($,D,{serialize:JSON.stringify,beforeRename:async()=>{await N?.beforeCommit?.(),await G.assertOwned()}}),await N?.afterRename?.();try{return await G.assertOwned(),!0}catch(P){if(P instanceof JZ)return!1;throw P}},U=async(G,D,N)=>{Z.logger?.warn("sidebar lock lost after rename; repairing write",{path:$});try{let P=await y($,B,async(W)=>{let O=G(await z(),D);if(O===void 0)return"skipped";return await K(W,O,N)?"written":"lost-again"});if(P==="lost-again")Z.logger?.warn("sidebar repair lost its lock after rename",{path:$});return{status:"lost-after-rename",repair:P}}catch(P){if(!(P instanceof $Z))throw P;return Z.logger?.warn("sidebar repair lock unavailable; repair skipped",{path:$}),{status:"lost-after-rename",repair:"lock-unavailable"}}},L=async(G,D)=>{let N=D,P=n($),W=Z.secureDir??!0;if(x)await A(P,W);else if(await vZ(P,{recursive:!0,mode:448}),W)await bZ(P,448).catch((F)=>{Z.logger?.warn("sidebar directory permission remediation failed",{error:F instanceof Error?F.message:String(F)})});let O=await y($,B,async(F)=>{let o=async(C)=>({value:C,held:await K(F,C,N)});for(let C=0;C<3;C+=1){let i=await j(),s=G(Y(i));if(s===void 0)return;if(C===0)await N?.beforeRecheck?.();if(await j()!==i)continue;return await o(s)}let a=G(await z());return a===void 0?void 0:await o(a)});if(O===void 0)return{status:"skipped"};if(O.held)return{status:"written"};let r=D?.repair??Z.repair;if(!r)return Z.logger?.warn("sidebar lock lost after rename; write not repaired",{path:$}),{status:"lost-after-rename",repair:"none"};return await U(r,O.value,N)};return{read:z,write:(G,D)=>Q(()=>L(()=>G,D),D),update:(G,D)=>Q(()=>L(G,D),D)}}var g=["primary","secondary"],fZ={primary:300,secondary:10080};function SZ(Z,$){return BZ({scope:"all",label:$,windowMinutes:Z})}function W0(Z){if(!Z)return[];let $=[];for(let V of g){let J=Z[V];if(!J)continue;let X=J.windowMinutes,Y=X!==void 0&&Number.isFinite(X)&&X>0?X:fZ[V];$.push({key:V,label:SZ(X,V),window:J,windowMs:Y*60000})}return $}var M=DZ("sidebar"),uZ="OPENCODE_OPENAI_AUTH_SIDEBAR_STATE_FILE";function PZ(){let Z=process.env.XDG_STATE_HOME||h(pZ(),".local","state");return h(Z,"cortexkit","openai-auth","sidebar-state.json")}var NZ=h(gZ(),"opencode-openai-auth","sidebar-state.json");function M0(Z){NZ=Z,m.clear()}var lZ=/^[a-f0-9]{64}$/,d=604800000,WZ=256,OZ=3600000;function T(Z){return AZ("sha256").update(Z).digest("hex")}function cZ(Z){return typeof Z==="number"&&Number.isFinite(Z)&&Z>=0?Z:void 0}function HZ(Z){let $=cZ(Z);return $!==void 0?{resetCredits:$}:{}}function rZ(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return;let $={};for(let[V,J]of Object.entries(Z)){if(J===null||typeof J!=="object"||Array.isArray(J))continue;let X=J;if(typeof X.activeId!=="string"||typeof X.route!=="string"||typeof X.updatedAt!=="number"||!Number.isFinite(X.updatedAt))continue;$[V]={activeId:X.activeId,route:X.route,updatedAt:X.updatedAt}}return Object.keys($).length>0?$:void 0}function oZ(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return;let $={};for(let[V,J]of Object.entries(Z)){if(!lZ.test(V)||J===null||typeof J!=="object"||Array.isArray(J))continue;let X=J;if(typeof X.accountId!=="string"||X.accountId.length===0||typeof X.assignedAt!=="number"||!Number.isFinite(X.assignedAt)||X.assignedAt<0||typeof X.lastSeenAt!=="number"||!Number.isFinite(X.lastSeenAt)||X.lastSeenAt<0||typeof X.inputBytes!=="number"||!Number.isFinite(X.inputBytes)||X.inputBytes<0)continue;let Y=X.quotaCheckedAt;if(Y!==void 0&&(typeof Y!=="number"||!Number.isFinite(Y)||Y<0))continue;let j=X.wireAccountId;$[V]={accountId:X.accountId,assignedAt:X.assignedAt,lastSeenAt:X.lastSeenAt,inputBytes:X.inputBytes,...Y===void 0?{}:{quotaCheckedAt:Y},...typeof j==="string"?{wireAccountId:j}:{}}}return Object.keys($).length>0?$:void 0}function H(){let Z=process.env[uZ];if(Z)return Z;let $=PZ();if(!m.has($))m.add($),aZ($,NZ);return $}var m=new Set;function aZ(Z,$){try{wZ(dZ(Z),{recursive:!0,mode:448}),kZ($,Z,yZ.COPYFILE_EXCL)}catch{}}var q={main:{quota:null,killed:!1},fallbacks:[],activeId:void 0,route:"main",lastUpdated:0};function S(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return q;let $=Z,V=$.main,J;if(V!==null&&typeof V==="object"&&!Array.isArray(V)){let G=V;J={quota:"quota"in G?G.quota:null,killed:typeof G.killed==="boolean"?G.killed:!1,...typeof G.mainAccountId==="string"?{mainAccountId:G.mainAccountId}:{},...typeof G.quotaBackedOff==="boolean"?{quotaBackedOff:G.quotaBackedOff}:{},...typeof G.quotaBackoffUntil==="number"?{quotaBackoffUntil:G.quotaBackoffUntil}:{},...typeof G.refreshBackedOff==="boolean"?{refreshBackedOff:G.refreshBackedOff}:{},...typeof G.refreshBackoffUntil==="number"?{refreshBackoffUntil:G.refreshBackoffUntil}:{},...HZ(G.resetCredits)}}else J={quota:null,killed:!1};let X=XZ($.fallbacks),Y=Array.isArray($.vaultAccounts)?XZ($.vaultAccounts):void 0,j=typeof $.activeId==="string"?$.activeId:void 0,z=typeof $.route==="string"?$.route:q.route,Q=typeof $.lastUpdated==="number"?$.lastUpdated:0,B=typeof $.planType==="string"?$.planType:void 0,K=typeof $.credits==="number"?$.credits:void 0,U=rZ($.activeRouting),L=oZ($.stickyAssignments);return{main:J,fallbacks:X,activeId:j,route:z,lastUpdated:Q,...U!==void 0?{activeRouting:U}:{},...L!==void 0?{stickyAssignments:L}:{},...B!==void 0?{planType:B}:{},...K!==void 0?{credits:K}:{},...$.accountPool===!0?{accountPool:!0}:{},...Y!==void 0?{vaultAccounts:Y}:{}}}function XZ(Z){if(!Array.isArray(Z))return[];return Z.filter(($)=>$!==null&&typeof $==="object"&&!Array.isArray($)&&typeof $.id==="string").map(($)=>({id:$.id,label:typeof $.label==="string"?$.label:void 0,...typeof $.accountId==="string"?{accountId:$.accountId}:{},quota:"quota"in $?$.quota:null,killed:typeof $.killed==="boolean"?$.killed:!1,enabled:typeof $.enabled==="boolean"?$.enabled:!0,...HZ($.resetCredits)}))}function u(Z){return[...Z.fallbacks,...Z.vaultAccounts??[]]}async function iZ(Z=H()){try{let $=await mZ(Z,"utf8");return S(JSON.parse($))}catch{return q}}var sZ=3600000,VZ=128;function RZ(Z,$,V=Date.now()){if(!(Z.updatedAt>=V-sZ&&Z.updatedAt<=V))return!1;if($===void 0)return!0;return Z.activeId==="main"||$.some((X)=>X.enabled!==!1&&X.killed!==!0&&X.id===Z.activeId)}function nZ(Z,$=Date.now()){let V=Z?.spendControl;if(V?.reached!==!0||typeof V.resetsAt!=="string")return;let J=Date.parse(V.resetsAt);if(!Number.isFinite(J)||J<=$)return;return{resetsAt:V.resetsAt,resetAtMs:J}}function tZ(Z,$=Date.now()){let V;for(let X of g){let Y=Z?.[X];if(typeof Y?.resetsAt!=="string"||!Number.isFinite(Y.usedPercent)||Y.usedPercent<100)continue;let j=Date.parse(Y.resetsAt);if(!Number.isFinite(j)||j<=$)continue;if(!V||j<V.resetAtMs)V={resetsAt:Y.resetsAt,resetAtMs:j}}let J=nZ(Z,$);if(J&&(!V||J.resetAtMs<V.resetAtMs))V=J;return V}function b(Z,$=Date.now()){return tZ(Z,$)!==void 0}function eZ(Z,$,V=Date.now()){if(!$||Z.route!=="sticky-balanced")return;let J=Z.stickyAssignments?.[T($)];if(!J||J.lastSeenAt<V-d)return;if(J.accountId==="main")return Z.main?.killed||b(Z.main?.quota,V)?void 0:"main";let X=u(Z).find((Y)=>Y.id===J.accountId);if(!X||X.enabled===!1||X.killed===!0||b(X.quota,V))return;return X.id}function q0(Z,$,V=Date.now()){if(!$)return{activeId:Z.activeId??"main",route:Z.route};let J=$?Z.activeRouting?.[$]:void 0,X=u(Z),Y=J?.activeId==="main"?Z.main.quota:X.find((K)=>K.id===J?.activeId)?.quota;if(J&&RZ(J,X,V)&&!b(Y,V))return{activeId:J.activeId,route:J.route};let j=eZ(Z,$,V);if(j)return{activeId:j,route:Z.route};let z=Z.vaultAccounts!==void 0,Q=(z?Z.vaultAccounts??[]:Z.fallbacks).filter((K)=>K.enabled&&!K.killed),B=Q.find((K)=>!b(K.quota,V))??Q[0];return{activeId:(z||Z.route==="fallback-first")&&B?B.id:"main",route:Z.route}}function TZ(Z,$,V=Date.now(),J){if(!Z)return;let X=Object.entries(Z).filter(([j,z])=>j!==J&&RZ(z,$,V)),Y=X.length<=VZ?X:X.sort((j,z)=>z[1].updatedAt-j[1].updatedAt).slice(0,VZ);return Y.length>0?Object.fromEntries(Y):void 0}function E(Z,$,V=Date.now(),J){if(!Z)return;let X=0,Y=0,j=0,z=[];for(let[B,K]of Object.entries(Z)){if(B===J){j+=1;continue}if(K.lastSeenAt<V-d){Y+=1;continue}if($!==void 0&&!$.has(K.accountId)){X+=1;continue}z.push([B,K])}let Q=X+Y+j;if(Q>0)M.debug("pruned sticky assignments",{pid:process.pid,removed:Q,reasons:{"account-not-in-roster":X,expired:Y,"explicit-removal":j}});return z.length>0?Object.fromEntries(z):void 0}function _Z(Z,$){let V=Object.keys(Z).length-WZ;if(V<=0)return Z;let J=new Set(Object.entries(Z).filter(([X])=>X!==$).sort(([X,Y],[j,z])=>Y.lastSeenAt-z.lastSeenAt||X.localeCompare(j)).slice(0,V).map(([X])=>X));return Object.fromEntries(Object.entries(Z).filter(([X])=>!J.has(X)))}function CZ(Z,$){if(Z===$)return!0;if(!Z||!$)return!1;let V=Object.entries(Z);if(V.length!==Object.keys($).length)return!1;return V.every(([J,X])=>Object.is($[J],X))}function FZ(Z,$,V,J){return Z!==void 0&&$.has(Z.accountId)&&!V.has(Z.accountId)&&Z.lastSeenAt>=J-d}function MZ(Z,$,V,J){return $>Z.inputBytes||V-Z.lastSeenAt>=OZ||Z.wireAccountId===void 0&&J!==void 0}function qZ(Z,$){return typeof Z.wireAccountId==="string"&&typeof $==="string"&&Z.wireAccountId!==$}function Z0(Z){let $=new Map(Z),V={get size(){return $.size},has:(J)=>$.has(J),get:(J)=>$.get(J),entries:()=>$.entries(),keys:()=>$.keys(),values:()=>$.values(),forEach:(J,X)=>{$.forEach((Y,j)=>{J.call(X,Y,j,V)})},[Symbol.iterator]:()=>$[Symbol.iterator]()};return Object.freeze(V)}function $0(Z,$,V){let J=new Map;for(let[X,Y]of Object.entries(Z??{})){if(X===V)continue;if(Y.quotaCheckedAt!==$[Y.accountId])continue;J.set(Y.accountId,(J.get(Y.accountId)??0)+Y.inputBytes)}return Z0(J)}function l(Z){if(Z===void 0)return;return new Set(["main",...Z.filter(($)=>$.enabled!==!1&&$.killed!==!0).map(($)=>$.id)])}var p=Promise.resolve();function R(Z){let $=p.then(Z);return p=$.catch(()=>{}),$}var YZ=new Map;function c(Z){let $=YZ.get(Z);if(!$)$=k({path:Z,defaultValue:q,normalize:S,secureDir:Z===PZ(),logger:M}),YZ.set(Z,$);return $}var w=new Set;async function EZ(Z,$){try{await $}catch(V){let J={pid:process.pid,error:V instanceof Error?V.message:String(V)};if(w.has(Z))M.debug("sidebar write failed again",J);else w.add(Z),M.warn("sidebar write failed",J);throw V}if(w.delete(Z))M.info("sidebar write recovered",{pid:process.pid})}function E0(Z,$=H()){return R(()=>EZ($,c($).write(S(Z))))}function J0(Z){return c(Z).read()}function _(Z,$,V){let J=Symbol("sidebar authority changed");return EZ(Z,c(Z).update((X)=>{if(V?.canWrite&&!V.canWrite())return;let Y=$(X);return Y===void 0?void 0:S(Y)},{beforeRecheck:async(...X)=>{if(await V?.beforeRecheck?.(...X),V?.canWrite&&!V.canWrite())throw J}}).catch((X)=>{if(X!==J)throw X}))}function v(Z){let $;for(let V of[Z?.primary?.checkedAt,Z?.secondary?.checkedAt,Z?.checkedAt])if(typeof V==="number"&&Number.isFinite(V))$=$===void 0?V:Math.max($,V);return $}function zZ(Z,$){let V=v(Z),J=v($);if(J!==void 0&&(V===void 0||J>V))return $;return Z}function jZ(Z,$){return Z!==void 0&&$!==void 0&&Z===$}function f(Z,$){let V=Z?.checkedAt;if(typeof V==="number"&&Number.isFinite(V))return V;if(typeof $==="number"&&Number.isFinite($))return $;return}function GZ(Z,$,V,J,X){if(Z&&$){let Y=f(Z,J),j=f($,X);if(j!==void 0&&(Y===void 0||j>Y))return $;return Z}return V?$:Z}function KZ(Z,$){if(Z.spendControl!==void 0)return Z.spendControl;if(Z.spendControlCleared===!0)return;return $.spendControl}function LZ(Z,$){if(!Z)return $;if(!$)return Z;let V=v(Z),J=v($),X=J!==void 0&&(V===void 0||J>V),Y=GZ(Z.primary,$.primary,X,Z.checkedAt,$.checkedAt),j=GZ(Z.secondary,$.secondary,X,Z.checkedAt,$.checkedAt),z=X?KZ($,Z):KZ(Z,$),Q=z===void 0&&(Z.spendControlCleared===!0||$.spendControlCleared===!0),B;for(let G of[f(Y),f(j)])if(G!==void 0)B=B===void 0?G:Math.max(B,G);let{spendControl:K,spendControlCleared:U,...L}=Z;return{...L,primary:Y,secondary:j,...z!==void 0?{spendControl:z}:{},...Q?{spendControlCleared:!0}:{},checkedAt:B??Z.checkedAt}}function x0(Z,$=H(),V){return R(async()=>{await _($,(J)=>{let X=new Map(J.fallbacks.map((K)=>[K.id,K])),Y=Z.vaultAccounts!==void 0,j=jZ(Z.main.mainAccountId,J.main.mainAccountId),z=j?LZ(Z.main.quota,J.main.quota):zZ(Z.main.quota,J.main.quota),Q=Date.now(),B=E(J.stickyAssignments,l(u(Z)),Q);return{...J,...Z,main:Y?Z.main:{...Z.main,quota:z,mainAccountId:j?Z.main.mainAccountId:z===J.main.quota&&z!==Z.main.quota?J.main.mainAccountId:Z.main.mainAccountId},fallbacks:Y?Z.fallbacks:Z.fallbacks.map((K)=>{let U=X.get(K.id),L=jZ(K.accountId,U?.accountId),G=L?LZ(K.quota,U?.quota??null):zZ(K.quota,U?.quota??null);return{...K,quota:G,accountId:L?K.accountId:G===U?.quota&&G!==K.quota?U?.accountId:K.accountId}}),activeId:J.activeId,activeRouting:J.activeRouting,stickyAssignments:B,lastUpdated:Math.max(Q,J.lastUpdated+1),accountPool:Z.accountPool===!0?!0:void 0,vaultAccounts:Z.vaultAccounts}},V)})}function I0(Z,$,V=H(),J){return R(async()=>{await _(V,(X)=>{let Y=TZ({...X.activeRouting,[Z.sessionId]:{activeId:Z.activeId,route:Z.route,updatedAt:Z.updatedAt}},$,Date.now()),j=E(X.stickyAssignments,l($),Date.now());return{...X,activeId:Z.activeId,route:Z.route,activeRouting:Y,stickyAssignments:j,lastUpdated:Math.max(Date.now(),X.lastUpdated+1)}},J)})}function b0(Z,$=H(),V){return R(async()=>{await _($,(J)=>({...J,activeId:Z.activeId,route:Z.route,lastUpdated:Math.max(Date.now(),J.lastUpdated+1)}),V)})}function v0(Z,$,V=H(),J){return R(async()=>{await _(V,(X)=>{let Y=Date.now(),j=TZ(X.activeRouting,$,Y,Z),z=E(X.stickyAssignments,l($),Y,T(Z));return{...X,activeRouting:j,stickyAssignments:z,lastUpdated:Math.max(Date.now(),X.lastUpdated+1)}},J)})}function xZ(Z,$){return FZ(Z,new Set($.validPinnedAccountIds),new Set($.excludeAccountIds),$.now)&&!qZ(Z,$.wireAccountIdByAccount?.[Z.accountId])&&!MZ(Z,$.requestBytes,$.now,$.wireAccountIdByAccount?.[Z.accountId])}function IZ(Z,$){let V=T($.sessionId),J=new Set($.validPinnedAccountIds),X=new Set($.excludeAccountIds),Y=E(Z.stickyAssignments,J,$.now),j=!CZ(Z.stickyAssignments,Y),z=Y?.[V],Q=z!==void 0&&qZ(z,$.wireAccountIdByAccount?.[z.accountId]);if(FZ(z,J,X,$.now)&&!Q){let U=MZ(z,$.requestBytes,$.now,$.wireAccountIdByAccount?.[z.accountId]),L=U?{...z,inputBytes:Math.max(z.inputBytes,$.requestBytes),...z.wireAccountId===void 0&&$.wireAccountIdByAccount?.[z.accountId]!==void 0?{wireAccountId:$.wireAccountIdByAccount?.[z.accountId]}:{},...$.now-z.lastSeenAt>=OZ?{lastSeenAt:$.now}:{}}:z;if(!j&&!U)return{assignment:L,next:void 0};return{assignment:L,next:{...Z,stickyAssignments:{...Y,[V]:L},lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}let B=$.choose($0(Y,$.quotaCheckedAtByAccount,Q?V:void 0));if(!B){if(!j)return{assignment:void 0,next:void 0};return{assignment:void 0,next:{...Z,stickyAssignments:Y,lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}let K={accountId:B.accountId,assignedAt:$.now,lastSeenAt:$.now,inputBytes:$.requestBytes,...B.quotaCheckedAt===void 0?{}:{quotaCheckedAt:B.quotaCheckedAt},...$.wireAccountIdByAccount?.[B.accountId]===void 0?{}:{wireAccountId:$.wireAccountIdByAccount?.[B.accountId]}};return{assignment:K,next:{...Z,stickyAssignments:_Z({...Y,[V]:K},V),lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}async function f0(Z,$=H(),V){let J=T(Z.sessionId),X=(await J0($)).stickyAssignments?.[J];if(xZ(X,Z))return X;let Y;return await R(async()=>{await _($,(j)=>{let z=IZ(j,Z);return Y=z.assignment,z.next},V)}),Y}function S0(Z,$){let V=Z.stickyAssignments?.[T($.sessionId)];if(xZ(V,$))return{assignment:V,next:void 0};return IZ(Z,$)}function A0(Z,$=H()){let V=T(Z.sessionId),J=new Set(Z.validPinnedAccountIds);return R(async()=>{await _($,(X)=>{let Y=Date.now(),j=E(X.stickyAssignments,J,Y),z=j?.[V];if(z&&z.assignedAt>Z.assignment.assignedAt){if(CZ(X.stickyAssignments,j))return;return{...X,stickyAssignments:j,lastUpdated:Math.max(Y,X.lastUpdated+1)}}let B=z!==void 0&&z.accountId===Z.assignment.accountId&&z.assignedAt===Z.assignment.assignedAt?{...Z.assignment,inputBytes:Math.max(z.inputBytes,Z.assignment.inputBytes),lastSeenAt:Math.max(z.lastSeenAt,Z.assignment.lastSeenAt)}:Z.assignment;return{...X,stickyAssignments:_Z({...j,[V]:B},V),lastUpdated:Math.max(Y,X.lastUpdated+1)}})})}async function y0(Z,$=H()){let V=T(Z),J=!1;return await R(async()=>{await _($,(X)=>{let Y=X.stickyAssignments;if(Y?.[V]===void 0){J=!1;return}J=!0;let{[V]:j,...z}=Y;return{...X,...Object.keys(z).length>0?{stickyAssignments:z}:{stickyAssignments:void 0},lastUpdated:Math.max(Date.now(),X.lastUpdated+1)}})}),J}function k0(){return p}var X0=500;function V0(Z,$,V){return new Promise((J,X)=>{let Y=setTimeout(()=>J(V()),$);Y.unref?.(),Z.then((j)=>{clearTimeout(Y),J(j)},(j)=>{clearTimeout(Y),X(j)})})}function w0(Z,$={}){let V=$.readBudgetMs??X0,J,X,Y=()=>{try{let z=hZ(Z);return`${z.ino}:${z.size}:${z.mtimeMs}`}catch{return}},j=(z)=>{if(X&&X.key===z)return X.promise;let Q=Date.now(),B=iZ(Z).then((L)=>{if(!J||J.readAt<=Q)J={state:L,readAt:Q,key:z};return{state:L,readAt:Q}}),K={key:z,promise:B};X=K;let U=()=>{if(X===K)X=void 0};return B.then(U,U),B};return{get(){let z=Y();if(J&&J.key===z)return Promise.resolve({state:J.state,readAt:J.readAt});return V0(j(z),V,()=>J?{state:J.state,readAt:J.readAt}:{state:q,readAt:0})},read(){return j(Y())},refreshInBackground(){let z=Y();if(J?.key===z)return;j(z)}}}function h0(Z,$,V){let J={assignment:V};Z.delete($),Z.set($,J);while(Z.size>WZ){let X=Z.keys().next().value;if(X===void 0)break;Z.delete(X)}return J}function m0(Z,$){if($.size===0)return Z.state;let V={...Z.state.stickyAssignments},J=!1;for(let[X,Y]of $){if(Y.persistedAt!==void 0&&Z.readAt>Y.persistedAt){$.delete(X);continue}V[X]=Y.assignment,J=!0}if(!J)return Z.state;return{...Z.state,stickyAssignments:V}}function p0(Z){let $=Z.retryDelayMs??500,V=Z.maxRetryDelayMs??30000,J=new Map,X=new Map,Y=new Set,j=0,z=$,Q,B=!1,K=()=>{if(Q||B||X.size===0)return;Q=setTimeout(()=>{Q=void 0;let L=[...X];X.clear(),z=Math.min(z*2,V);for(let[G,D]of L){let N=J.get(G);if(N!==void 0)U(G,D.label,D.write,N)}},z),Q.unref?.()},U=(L,G,D,N)=>{let P;try{P=D()}catch(W){P=Promise.reject(W)}P.then(()=>{if(J.get(L)!==N)return;if(J.delete(L),Y.delete(L))Z.logger.info("sidebar bookkeeping write recovered",{pid:process.pid,write:G});if(Y.size===0)z=$;Z.onWritten?.()},(W)=>{if(J.get(L)!==N)return;let O={pid:process.pid,write:G,error:W instanceof Error?W.message:String(W)};if(B){J.delete(L),Z.logger.debug("sidebar bookkeeping write dropped",O);return}if(Y.has(L))Z.logger.debug("sidebar bookkeeping write failed again",O);else Y.add(L),Z.logger.warn("sidebar bookkeeping write failed; retrying in the background",O);X.set(L,{label:G,write:D}),K()})};return{enqueue(L,G,D){j+=1,J.set(L,j),X.delete(L),U(L,G,D,j)},cancel(L){J.delete(L),X.delete(L),Y.delete(L)},stop(){if(B=!0,Q)clearTimeout(Q);Q=void 0,X.clear()}}}function g0(Z){let $=Z.activeId;if(Z.vaultAccounts!==void 0){let V=Z.vaultAccounts.filter((X)=>X.enabled),J=V.find((X)=>X.id===$)??V[0];return J?{id:J.id,name:J.label??J.id,quota:J.quota,killed:J.killed}:{id:"vault",name:"vault",quota:null,killed:!1}}if($&&$!=="main"){let V=Z.fallbacks.find((J)=>J.enabled&&J.id===$);if(V)return{id:V.id,name:V.label??V.id,quota:V.quota,killed:V.killed}}return{id:"main",name:"main",quota:Z.main.quota,killed:Z.main.killed}}function Y0(Z,$=Date.now()){if(!Z)return;return UZ({limits:g.flatMap((V)=>{let J=Z[V];return J?[{kind:"reading",scope:"all",label:V,usedPercent:J.usedPercent,checkedAt:J.checkedAt??Z.checkedAt??$,windowMinutes:J.windowMinutes,resetsAt:J.resetsAt}]:[]}),...Z.spendControl?{budget:{...Z.spendControl,kind:"reading",checkedAt:Z.checkedAt??$}}:{}})}function d0(Z,$=Date.now()){let V=Z?.primary?.usedPercent??null,J=Z?.secondary?.usedPercent??null,X=Y0(Z,$);return{primaryUsedPercent:V,secondaryUsedPercent:J,text:!X||X.limits.length===0&&!X.budget?null:QZ(X,{now:$,form:"compact"})}}var z0=300000,j0=0.01,G0=1;function u0(Z,$,V){if(!Z.resetsAt)return null;let J=new Date(Z.resetsAt).getTime();if(!Number.isFinite(J))return null;let X=J-$,Y=V-X;if(Y<z0)return null;if(Y<$*j0)return null;if(Y>=$)return null;let j=Z.usedPercent,z=Math.min(Math.max(Y/$*100,0),100),Q=j-z,B=Math.abs(Q)<G0?"on-pace":Q>0?"deficit":"reserve",K=null;if(j>0){let U=Y*100/j,L=X+U;if(L<J)K=new Date(L).toISOString()}return{pacePercent:z,deltaPercent:Q,state:B,runsOutAt:K}}
|
|
2
|
+
export{SZ as wc,W0 as xc,M0 as yc,d as zc,WZ as Ac,T as Bc,H as Cc,q as Dc,S as Ec,iZ as Fc,sZ as Gc,VZ as Hc,RZ as Ic,nZ as Jc,tZ as Kc,b as Lc,eZ as Mc,q0 as Nc,TZ as Oc,E as Pc,E0 as Qc,x0 as Rc,I0 as Sc,b0 as Tc,v0 as Uc,IZ as Vc,f0 as Wc,S0 as Xc,A0 as Yc,y0 as Zc,k0 as _c,X0 as $c,V0 as ad,w0 as bd,h0 as cd,m0 as dd,p0 as ed,g0 as fd,Y0 as gd,d0 as hd,u0 as id};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _ as SidebarMachineState, b as SidebarState } from "./sidebar-state-
|
|
1
|
+
import { a as ResetTargetIdentity, d as TokenResponse, f as beginAccountLogin, g as PoolStore, h as AccountPaths, i as MenuMigrationState, m as parseJwtClaims, o as OpenAiVault, p as extractAccountIdFromClaims, r as CacheKeepManager, t as PoolLifecycleDeps, u as IdTokenClaims } from "./pool-lifecycle-C_6YRmsh.js";
|
|
2
|
+
import { _ as SidebarMachineState, b as SidebarState } from "./sidebar-state-z_M7Trnd.js";
|
|
3
3
|
import { Hooks, Plugin, PluginInput } from "@opencode-ai/plugin";
|
|
4
4
|
//#region ../core/dist/provider.d.ts
|
|
5
5
|
type QuotaWindowName = string;
|
|
@@ -386,60 +386,6 @@ interface RefreshAllQuotaResult {
|
|
|
386
386
|
permanent?: boolean;
|
|
387
387
|
}
|
|
388
388
|
//#endregion
|
|
389
|
-
//#region ../core/dist/commands.d.ts
|
|
390
|
-
/**
|
|
391
|
-
* The prompt-cache manager, as the Cache section uses it.
|
|
392
|
-
*
|
|
393
|
-
* Declared structurally rather than imported: the manager itself is tied to
|
|
394
|
-
* one host's live request loader and stays there. Only the members the Cache
|
|
395
|
-
* section and the host's session cleanup reach appear here.
|
|
396
|
-
*/
|
|
397
|
-
interface CacheKeepManager {
|
|
398
|
-
status(): {
|
|
399
|
-
running: boolean;
|
|
400
|
-
sustain: boolean;
|
|
401
|
-
window?: {
|
|
402
|
-
startHour: number;
|
|
403
|
-
endHour: number;
|
|
404
|
-
} | undefined;
|
|
405
|
-
tracked: number;
|
|
406
|
-
generatedAt: number;
|
|
407
|
-
ttlMs: number;
|
|
408
|
-
leadMs: number;
|
|
409
|
-
maxIdleWarmMs: number;
|
|
410
|
-
maxSubagentIdleMs: number;
|
|
411
|
-
targets: ReadonlyArray<{
|
|
412
|
-
sessionKey: string;
|
|
413
|
-
accountId?: string;
|
|
414
|
-
cacheExpiresAt: number;
|
|
415
|
-
lastWarmedAt?: number;
|
|
416
|
-
backoffUntil?: number;
|
|
417
|
-
}>;
|
|
418
|
-
};
|
|
419
|
-
start(): void;
|
|
420
|
-
stop(): void;
|
|
421
|
-
remove(sessionKey: string): void;
|
|
422
|
-
}
|
|
423
|
-
interface ResetTargetIdentity {
|
|
424
|
-
accountKey: string;
|
|
425
|
-
label: string;
|
|
426
|
-
accessToken: string;
|
|
427
|
-
chatgptAccountId?: string;
|
|
428
|
-
onAuthFailure?: (status: number) => Promise<void>;
|
|
429
|
-
}
|
|
430
|
-
/** One live process, on an older version, that keeps the accounts from moving to the account pool. */
|
|
431
|
-
interface MigrationBlocker {
|
|
432
|
-
/** `'unknown'` when the directory of process heartbeats could not be read. */
|
|
433
|
-
pid: number | 'unknown';
|
|
434
|
-
version: string;
|
|
435
|
-
}
|
|
436
|
-
type MenuMigrationState = {
|
|
437
|
-
migrated: true;
|
|
438
|
-
} | {
|
|
439
|
-
migrated: false;
|
|
440
|
-
blockers: readonly MigrationBlocker[];
|
|
441
|
-
};
|
|
442
|
-
//#endregion
|
|
443
389
|
//#region src/commands.d.ts
|
|
444
390
|
/** What the `/openai` menu reads and changes in this process. */
|
|
445
391
|
interface OpenCodeMenuContext {
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{$ as D,A as c,B as d,C as e,D as f,E as g,F as h,G as i,H as j,I as k,J as l,K as m,L as n,M as o,N as p,O as q,P as r,Q as s,R as t,S as u,T as v,U as w,V as x,W as y,X as z,Y as A,Z as B,_ as C,aa as E}from"./index-4fnghj9e.js";import{sa as a,ta as b}from"./index-h263aftt.js";import"./index-ydz3hbhc.js";import"./index-a69gr76b.js";import"./index-ssj7m2rd.js";import"./index-826s1yxa.js";import"./index-fsky1rsh.js";import"./index-y4gxyxqd.js";import"./index-116q849r.js";import"./index-pg305s90.js";import"./index-66asrje2.js";export{B as rewriteResponsesLiteBody,z as resolveSidebarSessionId,a as parseJwtClaims,w as mergePushedQuotaMetadata,k as getMainRefreshLockName,v as findCachekeepFallbackAccount,b as extractAccountIdFromClaims,E as default,r as createResetTargetResolver,e as codexOAuthModelListed,f as codexOAuthModelLimit,y as buildSidebarState,x as buildSidebarMachineState,s as buildResetRedemptionDeps,o as __resetBootQuotaSeedForTest,t as __menuContextForTest,n as __bootQuotaSeedPromiseForTest,q as ResetTargetResolutionError,h as RESPONSES_LITE_MODELS,u as POOL_MIGRATION_ENABLED,D as OpenAIAuthPlugin,A as MID_CONVERSATION_EFFORT_MODELS,l as MAIN_REFRESH_LOCK_TTL_MS,m as MAIN_REFRESH_LEASE_TTL_MS,g as EMPTY_BEARER_MESSAGE,d as DISALLOWED_MODELS,C as CodexAuthPlugin,i as CODEX_VERSION,j as CODEX_USER_AGENT,p as AuthPersistError,c as ALLOWED_MODELS};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.17.1+0d2d5e37d881ac14/node_modules/@cortexkit/common-auth/dist/quota/map.d.ts
|
|
2
|
+
interface QuotaReadingEntry {
|
|
3
|
+
scope: string;
|
|
4
|
+
label: string;
|
|
5
|
+
kind: 'reading';
|
|
6
|
+
checkedAt: number;
|
|
7
|
+
usedPercent: number;
|
|
8
|
+
/** ISO timestamp at which the window resets, as the provider reported it. */
|
|
9
|
+
resetsAt?: string;
|
|
10
|
+
/** Window length in minutes, when the provider reported one. */
|
|
11
|
+
windowMinutes?: number;
|
|
12
|
+
}
|
|
13
|
+
interface QuotaRetiredEntry {
|
|
14
|
+
scope: string;
|
|
15
|
+
label: string;
|
|
16
|
+
kind: 'retired';
|
|
17
|
+
retiredAt: number;
|
|
18
|
+
}
|
|
19
|
+
interface QuotaAbsentEntry {
|
|
20
|
+
scope: string;
|
|
21
|
+
label: string;
|
|
22
|
+
kind: 'absent';
|
|
23
|
+
checkedAt: number;
|
|
24
|
+
}
|
|
25
|
+
type QuotaEntry = QuotaReadingEntry | QuotaRetiredEntry | QuotaAbsentEntry;
|
|
26
|
+
interface CreditBudgetReading {
|
|
27
|
+
kind: 'reading';
|
|
28
|
+
checkedAt: number;
|
|
29
|
+
/** The provider's own verdict that the budget is spent. */
|
|
30
|
+
reached: boolean;
|
|
31
|
+
remainingPercent?: number;
|
|
32
|
+
usedPercent?: number;
|
|
33
|
+
resetsAt?: string;
|
|
34
|
+
limit?: number;
|
|
35
|
+
used?: number;
|
|
36
|
+
remaining?: number;
|
|
37
|
+
unit?: string;
|
|
38
|
+
}
|
|
39
|
+
interface CreditBudgetCleared {
|
|
40
|
+
kind: 'cleared';
|
|
41
|
+
checkedAt: number;
|
|
42
|
+
}
|
|
43
|
+
type CreditBudgetEntry = CreditBudgetReading | CreditBudgetCleared;
|
|
44
|
+
interface QuotaCounter {
|
|
45
|
+
value: number;
|
|
46
|
+
checkedAt: number;
|
|
47
|
+
}
|
|
48
|
+
interface QuotaMap {
|
|
49
|
+
limits: QuotaEntry[];
|
|
50
|
+
/** Absent means no observation has reported on the budget yet. */
|
|
51
|
+
budget?: CreditBudgetEntry;
|
|
52
|
+
/** Provider-named counts, each with its own observation time. */
|
|
53
|
+
counters?: Record<string, QuotaCounter>;
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { QuotaMap as n, QuotaCounter as t };
|