@cortexkit/opencode-openai-auth 0.7.2 → 0.9.0

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 (118) hide show
  1. package/README.md +9 -5
  2. package/dist/index-301y4qa1.js +2 -0
  3. package/dist/index-338z7171.js +211 -0
  4. package/dist/index-5y4vzdf8.js +2 -0
  5. package/dist/{index-zxqb5ydj.js → index-9ehhb051.js} +1 -1
  6. package/dist/{index-zg1x8sty.js → index-jwn4r3sw.js} +1 -1
  7. package/dist/{index-9jpc8yct.js → index-sdt2d2ra.js} +1 -1
  8. package/dist/index-w42s0g6m.js +2 -0
  9. package/dist/index.d.ts +213 -36
  10. package/dist/index.js +59 -154
  11. package/dist/internal-Y7QNVDJT.d.ts +908 -0
  12. package/dist/quota-normalize-3qffywcm.js +1 -0
  13. package/dist/rpc/port-file.d.ts +11 -9
  14. package/dist/rpc/port-file.js +1 -1
  15. package/dist/rpc/protocol.d.ts +2 -21
  16. package/dist/rpc/rpc-client.d.ts +7 -4
  17. package/dist/rpc/rpc-client.js +1 -1
  18. package/dist/rpc/rpc-dir.d.ts +7 -5
  19. package/dist/rpc/rpc-dir.js +1 -1
  20. package/dist/sidebar-state-B98sERYt.d.ts +219 -0
  21. package/dist/sidebar-state.d.ts +2 -171
  22. package/dist/sidebar-state.js +1 -1
  23. package/dist/{token-bvp0y166.js → token-9823y0pc.js} +1 -1
  24. package/dist/token-util-ypgz7rge.js +1 -0
  25. package/dist/tui-preferences.d.ts +27 -26
  26. package/dist/tui-preferences.js +1 -1
  27. package/dist/tui.d.ts +42 -19
  28. package/package.json +8 -14
  29. package/src/tui/entry.mjs +2 -2
  30. package/src/tui-compiled/{core/account-paths.ts → raw/core-account-paths.ts} +29 -18
  31. package/src/tui-compiled/raw/core-custody-state.ts +243 -0
  32. package/src/tui-compiled/raw/logger.ts +53 -0
  33. package/src/tui-compiled/{rpc/port-file.ts → raw/rpc-port-file.ts} +1 -1
  34. package/src/tui-compiled/raw/rpc-protocol.ts +12 -0
  35. package/src/{rpc/rpc-client.ts → tui-compiled/raw/rpc-rpc-client.ts} +2 -2
  36. package/src/{sidebar-state.ts → tui-compiled/raw/sidebar-state.ts} +142 -13
  37. package/src/{tui/command-dialogs.tsx → tui-compiled/raw/tui-command-dialogs.tsx} +94 -44
  38. package/src/{tui.tsx → tui-compiled/raw/tui.tsx} +149 -28
  39. package/src/{core/account-paths.ts → tui-compiled/runtime/core-account-paths.ts} +29 -18
  40. package/src/tui-compiled/runtime/core-custody-state.ts +243 -0
  41. package/src/tui-compiled/runtime/logger.ts +53 -0
  42. package/src/{rpc/port-file.ts → tui-compiled/runtime/rpc-port-file.ts} +1 -1
  43. package/src/tui-compiled/runtime/rpc-protocol.ts +12 -0
  44. package/src/tui-compiled/{rpc/rpc-client.ts → runtime/rpc-rpc-client.ts} +2 -2
  45. package/src/tui-compiled/{sidebar-state.ts → runtime/sidebar-state.ts} +142 -13
  46. package/src/tui-compiled/{tui/command-dialogs.tsx → runtime/tui-command-dialogs.tsx} +73 -37
  47. package/src/tui-compiled/{tui.tsx → runtime/tui.tsx} +251 -153
  48. package/src/tui-compiled/shared/internal.ts +6 -0
  49. package/src/{logger.ts → tui-compiled/shared/logger.ts} +91 -23
  50. package/src/tui-compiled/shared/paths.ts +33 -0
  51. package/src/{core → tui-compiled/shared}/refresh-file-lock.ts +7 -4
  52. package/dist/cli.d.ts +0 -2
  53. package/dist/cli.js +0 -15
  54. package/dist/codex-http.d.ts +0 -3
  55. package/dist/commands.d.ts +0 -88
  56. package/dist/config.d.ts +0 -47
  57. package/dist/core/account-paths.d.ts +0 -25
  58. package/dist/core/accounts.d.ts +0 -330
  59. package/dist/core/atomic-write.d.ts +0 -1
  60. package/dist/core/background-quota-refresh.d.ts +0 -46
  61. package/dist/core/backoff.d.ts +0 -53
  62. package/dist/core/cachekeep.d.ts +0 -118
  63. package/dist/core/oauth.d.ts +0 -138
  64. package/dist/core/provider.d.ts +0 -70
  65. package/dist/core/quota-manager.d.ts +0 -192
  66. package/dist/core/refresh-all-quota.d.ts +0 -86
  67. package/dist/core/refresh-file-lock.d.ts +0 -12
  68. package/dist/core/reset-credits.d.ts +0 -116
  69. package/dist/core/sticky-routing.d.ts +0 -43
  70. package/dist/dump.d.ts +0 -20
  71. package/dist/hosted-web-search.d.ts +0 -5
  72. package/dist/index-87145jkw.js +0 -2
  73. package/dist/index-8f1200qx.js +0 -6
  74. package/dist/index-cfjed1st.js +0 -89
  75. package/dist/index-nrvjr97q.js +0 -3
  76. package/dist/index-qaggaze1.js +0 -2
  77. package/dist/index-sdcpzbnk.js +0 -2
  78. package/dist/logger.d.ts +0 -22
  79. package/dist/model-costs.d.ts +0 -29
  80. package/dist/prompt-context.d.ts +0 -19
  81. package/dist/quota-normalize-dvwtmy7f.js +0 -1
  82. package/dist/quota-normalize.d.ts +0 -43
  83. package/dist/raw-ws-bun.d.ts +0 -40
  84. package/dist/raw-ws-node.d.ts +0 -37
  85. package/dist/raw-ws-upgrade.d.ts +0 -2
  86. package/dist/raw-ws.d.ts +0 -3
  87. package/dist/response-stream-error.d.ts +0 -12
  88. package/dist/rpc/notifications.d.ts +0 -5
  89. package/dist/rpc/rpc-server.d.ts +0 -17
  90. package/dist/token-util-jcj7k7pa.js +0 -1
  91. package/dist/tui/command-dialogs.d.ts +0 -21
  92. package/dist/util/error.d.ts +0 -1
  93. package/dist/util/open-url.d.ts +0 -6
  94. package/dist/util/proxy-env.d.ts +0 -4
  95. package/dist/util/record.d.ts +0 -1
  96. package/dist/util/stable-json.d.ts +0 -1
  97. package/dist/util/uuid-v7.d.ts +0 -1
  98. package/dist/version.d.ts +0 -1
  99. package/dist/ws-pool.d.ts +0 -57
  100. package/dist/ws.d.ts +0 -71
  101. package/src/rpc/notifications.ts +0 -54
  102. package/src/rpc/protocol.ts +0 -33
  103. package/src/rpc/rpc-server.ts +0 -172
  104. package/src/tui-compiled/core/refresh-file-lock.ts +0 -381
  105. package/src/tui-compiled/logger.ts +0 -196
  106. package/src/tui-compiled/rpc/protocol.ts +0 -33
  107. package/src/util/error.ts +0 -9
  108. package/src/util/open-url.ts +0 -30
  109. package/src/util/proxy-env.ts +0 -42
  110. package/src/util/record.ts +0 -3
  111. package/src/util/stable-json.ts +0 -15
  112. package/src/util/uuid-v7.ts +0 -18
  113. /package/src/{rpc/rpc-dir.ts → tui-compiled/raw/rpc-rpc-dir.ts} +0 -0
  114. /package/src/tui-compiled/{tui-preferences.ts → raw/tui-preferences.ts} +0 -0
  115. /package/src/tui-compiled/{rpc/rpc-dir.ts → runtime/rpc-rpc-dir.ts} +0 -0
  116. /package/src/{tui-preferences.ts → tui-compiled/runtime/tui-preferences.ts} +0 -0
  117. /package/src/tui-compiled/{util → shared/util}/error.ts +0 -0
  118. /package/src/tui-compiled/{util → shared/util}/open-url.ts +0 -0
@@ -0,0 +1,2 @@
1
+ import{Ea as c,Z as o}from"./index-338z7171.js";import{createHash as YT,randomUUID as zT}from"node:crypto";import{chmod as DT,mkdir as KT,readFile as s,rename as UT,rm as BT,writeFile as QT}from"node:fs/promises";import{tmpdir as bT}from"node:os";import{dirname as PT,join as i}from"node:path";var k=["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 _T(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 JT(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 ZT(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 $T(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 GT(T,V,L){switch(T){case"tombstone":case"empty":return jT(T,V);case"real":return JT(V,L);case"gone":return ZT(V);case"slot-absent":return $T(V)}return O(T)}function aT(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 _T(T.local);if(T.manifest==="present")return GT(T.local,T.vault(),T.fingerprintMatch);return O(T.manifest)}return O(T.mode)}var a=["primary","secondary"],n={primary:300,secondary:10080};function y(T){return Number.isInteger(T)?String(T):String(Math.round(T*10)/10)}function XT(T,V){let L=T!==void 0&&Number.isFinite(T)&&T>0?T:n[V];if(L<60)return`${y(L)}m`;if(L<1440)return`${y(L/60)}h`;return`${y(L/1440)}d`}function OT(T){if(!T)return[];let V=[];for(let L of a){let N=T[L];if(!N)continue;let E=N.windowMinutes,C=E!==void 0&&Number.isFinite(E)&&E>0?E:n[L];V.push({key:L,label:XT(C,L),window:N,windowMs:C*60000})}return V}var I=o("sidebar"),FT="OPENCODE_OPENAI_AUTH_SIDEBAR_STATE_FILE",WT=i(bT(),"opencode-openai-auth"),e=i(WT,"sidebar-state.json"),yT=/^[a-f0-9]{64}$/,S=604800000,HT=256,t=3600000;function F(T){return YT("sha256").update(T).digest("hex")}function MT(T){return typeof T==="number"&&Number.isFinite(T)&&T>=0?T:void 0}function A(T){let V=MT(T);return V!==void 0?{resetCredits:V}:{}}var qT=new Set(["vault","needsLogin","local","inert"]),IT=new Set([...k,"corrupt"]);function h(T){if(T===null||typeof T!=="object"||Array.isArray(T))return;let V=T;if(typeof V.state!=="string"||!qT.has(V.state))return;let N={state:V.state};if(typeof V.reason==="string"&&IT.has(V.reason))N.reason=V.reason;return N}function ST(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(!yT.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 C=E.quotaCheckedAt;if(C!==void 0&&(typeof C!=="number"||!Number.isFinite(C)||C<0))continue;let R=E.wireAccountId;V[L]={accountId:E.accountId,assignedAt:E.assignedAt,lastSeenAt:E.lastSeenAt,inputBytes:E.inputBytes,...C===void 0?{}:{quotaCheckedAt:C},...typeof R==="string"?{wireAccountId:R}:{}}}return Object.keys(V).length>0?V:void 0}function z(){return process.env[FT]||e}function NV(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 f(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 _=L;N={quota:"quota"in _?_.quota:null,killed:typeof _.killed==="boolean"?_.killed:!1,...typeof _.mainAccountId==="string"?{mainAccountId:_.mainAccountId}:{},...(()=>{let Y=h(_.custody);return Y?{custody:Y}:{}})(),...typeof _.quotaBackedOff==="boolean"?{quotaBackedOff:_.quotaBackedOff}:{},...typeof _.quotaBackoffUntil==="number"?{quotaBackoffUntil:_.quotaBackoffUntil}:{},...typeof _.refreshBackedOff==="boolean"?{refreshBackedOff:_.refreshBackedOff}:{},...typeof _.refreshBackoffUntil==="number"?{refreshBackoffUntil:_.refreshBackoffUntil}:{},...A(_.resetCredits)}}else N={quota:null,killed:!1};let E=V.fallbacks,C=Array.isArray(E)?E.filter((_)=>_!==null&&typeof _==="object"&&!Array.isArray(_)&&typeof _.id==="string").map((_)=>{let Y=h(_.custody);return{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,...A(_.resetCredits),...Y?{custody:Y}:{}}}):[],R=typeof V.activeId==="string"?V.activeId:void 0,j=typeof V.route==="string"?V.route:K.route,J=typeof V.lastUpdated==="number"?V.lastUpdated:0,Z=typeof V.planType==="string"?V.planType:void 0,G=typeof V.credits==="number"?V.credits:void 0,$=ST(V.activeRouting),X=fT(V.stickyAssignments);return{main:N,fallbacks:C,activeId:R,route:j,lastUpdated:J,...$!==void 0?{activeRouting:$}:{},...X!==void 0?{stickyAssignments:X}:{},...Z!==void 0?{planType:Z}:{},...G!==void 0?{credits:G}:{}}}async function EV(T=z()){try{let V=await s(T,"utf8");return f(JSON.parse(V))}catch{return K}}var vT=3600000,p=128;function TT(T,V,L=Date.now()){if(!(T.updatedAt>=L-vT&&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 kT(T,V=Date.now()){let L;for(let E of a){let C=T?.[E];if(typeof C?.resetsAt!=="string"||!Number.isFinite(C.usedPercent)||C.usedPercent<100)continue;let R=Date.parse(C.resetsAt);if(!Number.isFinite(R)||R<=V)continue;if(!L||R<L.resetAtMs)L={resetsAt:C.resetsAt,resetAtMs:R}}let N=xT(T,V);if(N&&(!L||N.resetAtMs<L.resetAtMs))L=N;return L}function Q(T,V=Date.now()){return kT(T,V)!==void 0}function AT(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((C)=>C.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((J)=>J.id===N?.activeId)?.quota;if(N&&TT(N,T.fallbacks,L)&&!Q(E,L))return{activeId:N.activeId,route:N.route};let C=AT(T,V,L);if(C)return{activeId:C,route:T.route};let R=T.fallbacks.filter((J)=>J.enabled&&!J.killed),j=R.find((J)=>!Q(J.quota,L))??R[0];return{activeId:T.route==="fallback-first"&&j?j.id:"main",route:T.route}}function VT(T,V,L=Date.now(),N){if(!T)return;let E=Object.entries(T).filter(([R,j])=>R!==N&&TT(j,V,L)),C=E.length<=p?E:E.sort((R,j)=>j[1].updatedAt-R[1].updatedAt).slice(0,p);return C.length>0?Object.fromEntries(C):void 0}function W(T,V,L=Date.now(),N){if(!T)return;let E=0,C=0,R=0,j=[];for(let[Z,G]of Object.entries(T)){if(Z===N){R+=1;continue}if(G.lastSeenAt<L-S){C+=1;continue}if(V!==void 0&&!V.has(G.accountId)){E+=1;continue}j.push([Z,G])}let J=E+C+R;if(J>0)I.debug("pruned sticky assignments",{pid:process.pid,removed:J,reasons:{"account-not-in-roster":E,expired:C,"explicit-removal":R}});return j.length>0?Object.fromEntries(j):void 0}function hT(T,V){let L=Object.keys(T).length-HT;if(L<=0)return T;let N=new Set(Object.entries(T).filter(([E])=>E!==V).sort(([E,C],[R,j])=>C.lastSeenAt-j.lastSeenAt||E.localeCompare(R)).slice(0,L).map(([E])=>E));return Object.fromEntries(Object.entries(T).filter(([E])=>!N.has(E)))}function pT(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>=t||T.wireAccountId===void 0&&N!==void 0}function m(T,V){return typeof T.wireAccountId==="string"&&typeof V==="string"&&T.wireAccountId!==V}function rT(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,R)=>{N.call(E,C,R,L)})},[Symbol.iterator]:()=>V[Symbol.iterator]()};return Object.freeze(L)}function wT(T,V,L){let N=new Map;for(let[E,C]of Object.entries(T??{})){if(E===L)continue;if(C.quotaCheckedAt!==V[C.accountId])continue;N.set(C.accountId,(N.get(C.accountId)??0)+C.inputBytes)}return rT(N)}function v(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(),mT=3,dT=1e4,uT=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 LT(T){try{return NT(await M(T))}catch{return K}}async function M(T){try{return await s(T,"utf8")}catch(V){if(V.code==="ENOENT")return"";throw V}}function NT(T){if(T==="")return K;try{return f(JSON.parse(T))}catch{return K}}async function lT(T){await ET(T);let V=Date.now()+uT;while(Date.now()<=V){let L=await c({name:"sidebar-write",path:T,ttlMs:dT,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 ET(T){let V=PT(T);if(await KT(V,{recursive:!0,mode:448}),T!==e)return;await DT(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 lT(T);try{for(let R=0;R<mT;R+=1){let j=await M(T),J=V(NT(j));if(!J)return;if(R===0)await L?.beforeRecheck?.();if(await M(T)!==j)continue;await q(J,T);return}let E=await LT(T),C=V(E);if(C)await q(C,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 C=P(T,N),R=P(V,E);if(R!==void 0&&(C===void 0||R>C))return V;return T}return L?V:T}function g(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),C=l(T.primary,V.primary,E,T.checkedAt,V.checkedAt),R=l(T.secondary,V.secondary,E,T.checkedAt,V.checkedAt),j=E?V.spendControl??T.spendControl:T.spendControl??V.spendControl,J;for(let Z of[P(C),P(R)])if(Z!==void 0)J=J===void 0?Z:Math.max(J,Z);return{...T,primary:C,secondary:R,...j!==void 0?{spendControl:j}:{},checkedAt:J??T.checkedAt}}function _V(T,V=z(),L){return D(async()=>{await U(V,(N)=>{let E=new Map(N.fallbacks.map((Z)=>[Z.id,Z])),C=u(T.main.mainAccountId,N.main.mainAccountId),R=C?g(T.main.quota,N.main.quota):d(T.main.quota,N.main.quota),j=Date.now(),J=W(N.stickyAssignments,v(T.fallbacks),j);return{...N,...T,main:{...T.main,quota:R,mainAccountId:C?T.main.mainAccountId:R===N.main.quota&&R!==T.main.quota?N.main.mainAccountId:T.main.mainAccountId},fallbacks:T.fallbacks.map((Z)=>{let G=E.get(Z.id),$=u(Z.accountId,G?.accountId),X=$?g(Z.quota,G?.quota??null):d(Z.quota,G?.quota??null);return{...Z,quota:X,accountId:$?Z.accountId:X===G?.quota&&X!==Z.quota?G?.accountId:Z.accountId}}),activeId:N.activeId,activeRouting:N.activeRouting,stickyAssignments:J,lastUpdated:Math.max(j,N.lastUpdated+1)}},L)})}function jV(T,V,L=z(),N){return D(async()=>{await U(L,(E)=>{let C=VT({...E.activeRouting,[T.sessionId]:{activeId:T.activeId,route:T.route,updatedAt:T.updatedAt}},V,Date.now()),R=W(E.stickyAssignments,v(V),Date.now());return{...E,activeId:T.activeId,route:T.route,activeRouting:C,stickyAssignments:R,lastUpdated:Math.max(Date.now(),E.lastUpdated+1)}},N)})}function JV(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 ZV(T,V,L=z(),N){return D(async()=>{await U(L,(E)=>{let C=Date.now(),R=VT(E.activeRouting,V,C,T),j=W(E.stickyAssignments,v(V),C,F(T));return{...E,activeRouting:R,stickyAssignments:j,lastUpdated:Math.max(Date.now(),E.lastUpdated+1)}},N)})}async function $V(T,V=z(),L){let N=F(T.sessionId),E=new Set(T.validPinnedAccountIds),C=new Set(T.excludeAccountIds),R=(await LT(V)).stickyAssignments?.[N];if(r(R,E,C,T.now)&&!m(R,T.wireAccountIdByAccount?.[R.accountId])&&!w(R,T.requestBytes,T.now,T.wireAccountIdByAccount?.[R.accountId]))return R;let j;return await D(async()=>{await U(V,(J)=>{let Z=W(J.stickyAssignments,E,T.now),G=!pT(J.stickyAssignments,Z),$=Z?.[N],X=$!==void 0&&m($,T.wireAccountIdByAccount?.[$.accountId]);if(r($,E,C,T.now)&&!X){let Y=w($,T.requestBytes,T.now,T.wireAccountIdByAccount?.[$.accountId]),x=Y?{...$,inputBytes:Math.max($.inputBytes,T.requestBytes),...$.wireAccountId===void 0&&T.wireAccountIdByAccount?.[$.accountId]!==void 0?{wireAccountId:T.wireAccountIdByAccount?.[$.accountId]}:{},...T.now-$.lastSeenAt>=t?{lastSeenAt:T.now}:{}}:$;if(j=x,!G&&!Y)return;return{...J,stickyAssignments:{...Z,[N]:x},lastUpdated:Math.max(T.now,J.lastUpdated+1)}}let _=T.choose(wT(Z,T.quotaCheckedAtByAccount,X?N:void 0));if(!_){if(j=void 0,!G)return;return{...J,stickyAssignments:Z,lastUpdated:Math.max(T.now,J.lastUpdated+1)}}return j={accountId:_.accountId,assignedAt:T.now,lastSeenAt:T.now,inputBytes:T.requestBytes,..._.quotaCheckedAt===void 0?{}:{quotaCheckedAt:_.quotaCheckedAt},...T.wireAccountIdByAccount?.[_.accountId]===void 0?{}:{wireAccountId:T.wireAccountIdByAccount?.[_.accountId]}},{...J,stickyAssignments:hT({...Z,[N]:j},N),lastUpdated:Math.max(T.now,J.lastUpdated+1)}},L)}),j}async function GV(T,V=z()){let L=F(T),N=!1;return await D(async()=>{await U(V,(E)=>{let C=E.stickyAssignments;if(C?.[L]===void 0){N=!1;return}N=!0;let{[L]:R,...j}=C;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}.${zT()}.tmp`;try{await ET(V),await QT(L,JSON.stringify(f(T)),{encoding:"utf8",mode:384}),await UT(L,V)}catch(N){throw await BT(L,{force:!0}).catch(()=>{}),I.warn("sidebar write failed",{pid:process.pid,error:N instanceof Error?N.message:String(N)}),N}}function XV(){return H}function OV(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 YV(T){let V=T?.primary?.usedPercent??null,L=T?.secondary?.usedPercent??null,N=OT(T);return{primaryUsedPercent:V,secondaryUsedPercent:L,text:N.length===0?null:N.map(({label:E,window:C})=>`${E}: ${Math.round(C.usedPercent)}%`).join(" ")}}var gT=300000,oT=0.01,cT=1;function zV(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,C=L-E;if(C<gT)return null;if(C<V*oT)return null;if(C>=V)return null;let R=T.usedPercent,j=Math.min(Math.max(C/V*100,0),100),J=R-j,Z=Math.abs(J)<cT?"on-pace":J>0?"deficit":"reserve",G=null;if(R>0){let $=C*100/R,X=E+$;if(X<N)G=new Date(X).toISOString()}return{pacePercent:j,deltaPercent:J,state:Z,runsOutAt:G}}
2
+ export{aT as c,XT as d,OT as e,S as f,HT as g,F as h,z as i,NV as j,K as k,f as l,EV as m,vT as n,p as o,TT as p,xT as q,kT as r,Q as s,AT as t,CV as u,VT as v,W as w,RV as x,_V as y,jV as z,JV as A,ZV as B,$V as C,GV as D,XV as E,OV as F,YV as G,zV as H};
@@ -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 Ha,u as Ia,v as Ja,x as Ka};
2
+ export{t as qb,u as rb,v as sb,x as tb};
@@ -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 Ea,L as Fa,T as Ga};
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{Ia as Z,Ka as W}from"./index-zxqb5ydj.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};
@@ -0,0 +1,2 @@
1
+ import{Z as _}from"./index-338z7171.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};
package/dist/index.d.ts CHANGED
@@ -1,58 +1,235 @@
1
- import type { Hooks, Plugin, PluginInput } from '@opencode-ai/plugin';
2
- import { type ResetTargetIdentity } from './commands';
3
- import { type AccountStorage, type FallbackAccount, loadAccounts, type OAuthAccount, type OAuthQuotaSnapshot } from './core/accounts';
4
- import { QuotaManager } from './core/quota-manager';
5
- import { type SidebarMachineState, type SidebarState } from './sidebar-state';
1
+ import { C as CustodyManifestIo, E as detectClaustrumConnection, S as acquireRefreshFileLock, T as QuotaManager, _ as loadAccounts, b as ClaustrumCredentialCache, c as IdTokenClaims, d as parseJwtClaims, f as AccountStorage, g as OAuthQuotaSnapshot, h as OAuthAccount, l as TokenResponse, m as FallbackAccount, n as ResetTargetIdentity, p as AccountStoreTransaction, t as CommandContext, u as extractAccountIdFromClaims, v as mutateAccounts, w as CustodyManifestReadResult, x as resolveFallbackAccess, y as withAccountStoreTransaction } from "./internal-Y7QNVDJT.js";
2
+ import { Q as VaultCustodyState, Z as CustodyInertReason, b as SidebarState, m as SidebarAccountCustody, v as SidebarMachineState } from "./sidebar-state-B98sERYt.js";
3
+ import { Hooks, Plugin, PluginInput } from "@opencode-ai/plugin";
4
+ //#region src/core/custody-manifest.d.ts
5
+ declare function readCustodyManifest(path?: string, io?: CustodyManifestIo): Promise<CustodyManifestReadResult>;
6
+ //#endregion
7
+ //#region src/core/custody-transition.d.ts
8
+ type TransitionOutcome = 'ready' | 'tombstoned' | Extract<CustodyInertReason, 'new-local-family-under-claustrum' | 'vault-cold' | 'vault-reauth' | 'identity-mismatch' | 'no-handle'> | 'torn-read-deferred' | `aborted:${string}`;
9
+ type TransitionResult = {
10
+ status: 'completed' | 'incomplete' | 'aborted';
11
+ outcomes: Record<string, TransitionOutcome>;
12
+ reason?: string;
13
+ };
14
+ type CustodyHostAuth = EnterClaustrumModeDeps['auth'];
15
+ type Release = {
16
+ release(): Promise<void>;
17
+ };
18
+ type EnterClaustrumModeDeps = {
19
+ accountIds: readonly string[];
20
+ acquireLock(options: {
21
+ name: string;
22
+ renew: boolean;
23
+ }): Promise<Release | null>;
24
+ withStoreTransaction(action: (transaction: AccountStoreTransaction) => Promise<TransitionResult>): Promise<TransitionResult>;
25
+ readManifest(): Promise<CustodyManifestReadResult>;
26
+ preflight(input: {
27
+ id: string;
28
+ accountId?: string;
29
+ handle: string;
30
+ }): Promise<Exclude<TransitionOutcome, `aborted:${string}` | 'tombstoned' | 'new-local-family-under-claustrum' | 'torn-read-deferred'>>;
31
+ auth: {
32
+ all(): Promise<Record<string, unknown>>;
33
+ get(input: {
34
+ path: {
35
+ id: string;
36
+ };
37
+ }): Promise<unknown>;
38
+ set(input: {
39
+ path: {
40
+ id: string;
41
+ };
42
+ body: {
43
+ type: 'oauth';
44
+ access: string;
45
+ refresh: string;
46
+ expires: number;
47
+ };
48
+ }): Promise<unknown>;
49
+ };
50
+ onStep?(step: string): void | Promise<void>;
51
+ warn?(message: string): void;
52
+ };
53
+ //#endregion
54
+ //#region src/core/custody-runtime.d.ts
55
+ type RuntimeLogger = {
56
+ info: (message: string, meta?: Record<string, unknown>) => void;
57
+ warn: (message: string, meta?: Record<string, unknown>) => void;
58
+ debug: (message: string, meta?: Record<string, unknown>) => void;
59
+ error: (message: string, meta?: Record<string, unknown>) => void;
60
+ };
61
+ type CustodyRuntimeOptions = {
62
+ /** Storage snapshot at loader time — used for the boot sweep pass. */
63
+ storage: AccountStorage | null;
64
+ configPath: string;
65
+ manifestPath?: string;
66
+ /** Test seam: the vendored detector. Production passes the real function. */
67
+ detectClaustrumConnection?: typeof detectClaustrumConnection;
68
+ /** Test seam: transport factory passed to `ClaustrumCredentialCache`. */
69
+ cacheConnector?: (options: {
70
+ connectionFile: string;
71
+ handshakeTimeoutMs?: number;
72
+ }) => Promise<ClaustrumCacheTransportLike>;
73
+ loadAccounts: typeof loadAccounts;
74
+ mutateAccounts: typeof mutateAccounts;
75
+ withAccountStoreTransaction: typeof withAccountStoreTransaction;
76
+ readCustodyManifest: typeof readCustodyManifest;
77
+ acquireRefreshFileLock: typeof acquireRefreshFileLock;
78
+ auth?: CustodyHostAuth;
79
+ resolveFallbackVaultState?: (input: {
80
+ accountId: string;
81
+ handle: string;
82
+ }) => Promise<VaultCustodyState>;
83
+ now?: () => number;
84
+ setIntervalFn?: (callback: () => void, intervalMs: number) => ReturnType<typeof setInterval>;
85
+ clearIntervalFn?: (handle: ReturnType<typeof setInterval>) => void;
86
+ onReconcileStep?: (step: 'discovery-lock-acquired' | 'enabled-manifest-join', accountId?: string) => void | Promise<void>;
87
+ logger: RuntimeLogger;
88
+ };
89
+ type ClaustrumCacheTransportLike = {
90
+ getCredential(handle: string, minTtlMs?: number): Promise<{
91
+ material: string;
92
+ recordVersion: number;
93
+ expiresAtMs: number | null;
94
+ accountId?: string;
95
+ }>;
96
+ statusCredential(handle: string): Promise<{
97
+ ready: boolean;
98
+ lastErrorCode: string | null;
99
+ leaseHeld: boolean;
100
+ recordVersion: number;
101
+ }>;
102
+ reportAuthFailure(params: {
103
+ handle: string;
104
+ providerStatus: number;
105
+ recordVersion: number;
106
+ reporterSource: 'direct' | 'relay_status_field' | 'relay_message_parse';
107
+ }): Promise<void>;
108
+ close(): void;
109
+ };
110
+ type CustodyRuntime = {
111
+ /** Run the initial completion sweep. Resolves BEFORE the background refresh is armed. */
112
+ boot(): Promise<void>;
113
+ /** Clear the timer and close the cache + transport. Idempotent. */
114
+ dispose(): void;
115
+ /** Force one tick pass (used by the timer and tests). */
116
+ runTick(): Promise<void>;
117
+ /** Sync projection read for the sidebar writer. */
118
+ getCustodyProjection(account: OAuthAccount, now: number): SidebarAccountCustody | undefined;
119
+ /** Whether the custody runtime is enabled for this process. */
120
+ isEnabled(): boolean;
121
+ /** Cache handle (undefined when custody is disabled). */
122
+ getCache(): ClaustrumCredentialCache | undefined;
123
+ /** Connect the cache on demand and return it. */
124
+ ensureCache(): Promise<ClaustrumCredentialCache | undefined>;
125
+ /** Transport handle (undefined when custody is disabled). */
126
+ getTransport(): ClaustrumCacheTransportLike | undefined;
127
+ /** True if the detection step produced an `available` connection file. */
128
+ wasDetected(): boolean;
129
+ };
130
+ export declare function __createCustodyRuntimeForTest(options: CustodyRuntimeOptions): CustodyRuntime;
131
+ export declare function __resetSweepFailureLogDedupeForTest(): void;
132
+ //#endregion
133
+ //#region src/index.d.ts
134
+ /**
135
+ * Surfaced when a request would go to the wire with no credential.
136
+ *
137
+ * Fixed text on purpose. The host decides retries by matching this string
138
+ * (opencode v1.18.30, session/retry.ts), so no account label, provider wording
139
+ * or number may reach it - an operator-chosen id like `acct-429` would read as
140
+ * retryable and hide a local defect behind a retry loop. Details go to the
141
+ * transport log.
142
+ */
143
+ export declare const EMPTY_BEARER_MESSAGE = "Refusing to send a request with no access token. This is a defect in the plugin, not a problem with the provider or the account; the transport log names the account and the path that produced it.";
144
+ export declare const getMainRefreshLockName: () => string;
6
145
  export declare const MAIN_REFRESH_LOCK_TTL_MS: number;
7
146
  export declare const MAIN_REFRESH_LEASE_TTL_MS = 90000;
147
+ export declare function __resetBootQuotaSeedForTest(): void;
8
148
  export declare class AuthPersistError extends Error {
9
- readonly code = "OPENAI_AUTH_PERSIST_FAILED";
10
- constructor(cause: unknown);
149
+ readonly code = "OPENAI_AUTH_PERSIST_FAILED";
150
+ constructor(cause: unknown);
11
151
  }
12
152
  export type ResetTargetResolutionErrorKind = 'unknown_account' | 'disabled_account' | 'non_oauth_account' | 'token_unavailable';
13
153
  export declare class ResetTargetResolutionError extends Error {
14
- readonly code: ResetTargetResolutionErrorKind;
15
- constructor(code: ResetTargetResolutionErrorKind, message: string);
154
+ readonly code: ResetTargetResolutionErrorKind;
155
+ constructor(code: ResetTargetResolutionErrorKind, message: string);
16
156
  }
17
157
  interface ResetTargetResolverDeps {
18
- getAuth: () => Promise<{
19
- type: string;
20
- access?: string;
21
- refresh?: string;
22
- expires?: number;
23
- }>;
24
- refreshMainWithLease: () => Promise<{
25
- access: string;
26
- refresh: string;
27
- expires: number;
28
- }>;
29
- refreshFallbackAccount: (account: OAuthAccount, storage: AccountStorage) => Promise<OAuthAccount>;
30
- loadAccounts: typeof loadAccounts;
31
- accountStoragePath: string;
32
- now: () => number;
158
+ getAuth: () => Promise<{
159
+ type: string;
160
+ access?: string;
161
+ refresh?: string;
162
+ expires?: number;
163
+ }>;
164
+ refreshMainWithLease: () => Promise<{
165
+ access: string;
166
+ refresh: string;
167
+ expires: number;
168
+ }>;
169
+ refreshFallbackAccount: (account: OAuthAccount, storage: AccountStorage) => Promise<OAuthAccount>;
170
+ loadAccounts: typeof loadAccounts;
171
+ accountStoragePath: string;
172
+ accountStatePath: string;
173
+ now: () => number;
174
+ isFallbackRefreshInert?: (account: OAuthAccount, storage: AccountStorage) => Promise<boolean>;
175
+ resolveFallbackAccess?: (account: OAuthAccount, storage: AccountStorage) => ReturnType<typeof resolveFallbackAccess>;
176
+ reportAuthFailure?: (params: {
177
+ handle: string;
178
+ providerStatus: number;
179
+ recordVersion: number;
180
+ }) => Promise<void>;
33
181
  }
34
182
  export declare function createResetTargetResolver(deps: ResetTargetResolverDeps): (accountKey: string) => Promise<ResetTargetIdentity>;
35
183
  export declare function buildResetRedemptionDeps(): {
36
- fetchImpl: typeof fetch;
37
- now: () => number;
38
- randomUUID: () => `${string}-${string}-${string}-${string}-${string}`;
184
+ fetchImpl: typeof fetch;
185
+ now: () => number;
186
+ randomUUID: () => `${string}-${string}-${string}-${string}-${string}`;
39
187
  };
40
- export { extractAccountIdFromClaims, type IdTokenClaims, parseJwtClaims, } from './core/oauth';
41
188
  interface CodexAuthPluginOptions {
42
- issuer?: string;
43
- codexApiEndpoint?: string;
44
- experimentalWebSockets?: boolean;
45
- responsesLite?: boolean;
189
+ issuer?: string;
190
+ codexApiEndpoint?: string;
191
+ experimentalWebSockets?: boolean;
192
+ responsesLite?: boolean;
193
+ custody?: {
194
+ /** Test seam: the transport backing the loader-owned runtime. */
195
+ transport: ClaustrumCacheTransportLike;
196
+ /** Test seam: override the connection-file detection result. */
197
+ detection?: 'available' | 'absent';
198
+ /** Test seam: observes the loader-owned runtime for explicit ticks. */
199
+ onRuntime?: (runtime: CustodyRuntime) => void;
200
+ /** Test seam: controls the runtime clock for expiry-bound scenarios. */
201
+ now?: () => number;
202
+ /** Test seam: controls bounded host-write observation without real timers. */
203
+ sleep?: (ms: number) => Promise<void>;
204
+ /** Test seam: observes a host-write observation deadline warning. */
205
+ warn?: (message: string) => void;
206
+ /** Test seam: observes the account lock around custody binding checks. */
207
+ withFallbackAccountLock?: CommandContext['withFallbackAccountLock'];
208
+ /** Test seam: replaces external OAuth I/O while preserving the hook callback. */
209
+ authorize?: {
210
+ browser?: () => Promise<{
211
+ url: string;
212
+ tokens: Promise<TokenResponse>;
213
+ cleanup?: () => void;
214
+ }>;
215
+ headless?: () => Promise<{
216
+ url: string;
217
+ instructions: string;
218
+ tokens: Promise<TokenResponse>;
219
+ }>;
220
+ };
221
+ };
46
222
  }
47
223
  export declare function findCachekeepFallbackAccount(accounts: FallbackAccount[], accountId: string): OAuthAccount | undefined;
48
224
  export declare function mergePushedQuotaMetadata(incoming: OAuthQuotaSnapshot, previous: OAuthQuotaSnapshot | undefined): OAuthQuotaSnapshot;
49
- export declare function buildSidebarMachineState(qm: QuotaManager, store: AccountStorage, now?: number, mainAccountIdentity?: string | undefined): SidebarMachineState;
225
+ export declare function buildSidebarMachineState(qm: QuotaManager, store: AccountStorage, now?: number, mainAccountIdentity?: string | undefined, projectCustody?: (account: FallbackAccount, now: number) => SidebarAccountCustody | undefined): SidebarMachineState;
50
226
  export declare function buildSidebarState(qm: QuotaManager, store: AccountStorage, activeId: string, now?: number): SidebarState;
51
227
  export declare function resolveSidebarSessionId(headers: Headers): string | undefined;
52
228
  export declare function CodexAuthPlugin(input: PluginInput, options?: CodexAuthPluginOptions): Promise<Hooks>;
53
229
  export declare const OpenAIAuthPlugin: Plugin;
54
230
  declare const _default: {
55
- id: string;
56
- server: Plugin;
231
+ id: string;
232
+ server: Plugin;
57
233
  };
58
- export default _default;
234
+ //#endregion
235
+ export { type ClaustrumCacheTransportLike, type CustodyRuntime, type CustodyRuntimeOptions, type IdTokenClaims, _default as default, extractAccountIdFromClaims, parseJwtClaims };