@cortexkit/opencode-openai-auth 1.0.2 → 1.0.4
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-2hch7e8n.js +8 -0
- package/dist/{index-766sfrh5.js → index-45qgkb0m.js} +1 -1
- package/dist/index-5dg931q0.js +65 -0
- package/dist/index-99esnzg0.js +157 -0
- package/dist/index-9reyazwh.js +2 -0
- package/dist/index-bgq9d21h.js +2 -0
- package/dist/index-dryydk6b.js +2 -0
- package/dist/index-egrty6tz.js +12 -0
- package/dist/index-envpbt0k.js +3 -0
- package/dist/index-jye6vccc.js +2 -0
- package/dist/index-k4eacw7x.js +2 -0
- package/dist/{index-hy9030jh.js → index-yeyp8t0k.js} +1 -1
- package/dist/index-yf6arn5w.js +2 -0
- package/dist/index.d.ts +2 -56
- package/dist/index.js +1 -1
- package/dist/map-CCbSZIhT.d.ts +56 -0
- package/dist/{pool-lifecycle-DbDmgabd.d.ts → pool-lifecycle-DqKq8Eej.d.ts} +104 -790
- package/dist/{port-file-Do3lQIEk.d.ts → port-file-CZ9MIdy2.d.ts} +1 -1
- package/dist/{protocol-BOBdkqqm.d.ts → protocol-CSIDDBDf.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-BCxFpH68.d.ts} +5 -3
- package/dist/sidebar-state.d.ts +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/token-util-gmn5yaqc.js +1 -0
- package/dist/{token-ypk61xj0.js → token-vykm9bxh.js} +1 -1
- 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/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 +1 -1
- 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/raw/sidebar-state.js +3 -3
- package/src/tui-compiled/runtime/logger.js +10 -2
- 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 +1 -1
- 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/src/tui-compiled/runtime/sidebar-state.js +3 -3
- package/dist/index-8kj7sa1p.js +0 -12
- package/dist/index-b3q3j39x.js +0 -2
- package/dist/index-bmd7x5aq.js +0 -2
- package/dist/index-eqh53k8v.js +0 -2
- package/dist/index-jyr8y8k4.js +0 -7
- package/dist/index-m9d2bfkn.js +0 -222
- package/dist/index-rv08jmd4.js +0 -2
- package/dist/token-util-wdza526f.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{qd as BZ,sd as QZ,td as UZ}from"./index-yf6arn5w.js";import{Cd as $Z,Dd as JZ,Ed as y,Fd as I,yd as ZZ}from"./index-2hch7e8n.js";import{Vd as DZ}from"./index-k4eacw7x.js";import{be as x,ce as t,ge as A,he as e}from"./index-dryydk6b.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 xc,W0 as yc,M0 as zc,d as Ac,WZ as Bc,T as Cc,H as Dc,q as Ec,S as Fc,iZ as Gc,sZ as Hc,VZ as Ic,RZ as Jc,nZ as Kc,tZ as Lc,b as Mc,eZ as Nc,q0 as Oc,TZ as Pc,E as Qc,E0 as Rc,x0 as Sc,I0 as Tc,b0 as Uc,v0 as Vc,IZ as Wc,f0 as Xc,S0 as Yc,A0 as Zc,y0 as _c,k0 as $c,X0 as ad,V0 as bd,w0 as cd,h0 as dd,m0 as ed,p0 as fd,g0 as gd,Y0 as hd,d0 as id,u0 as jd};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createRequire as n}from"node:module";var k=Object.defineProperty;var q=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports);var l=(b)=>b;function m(b,a){this[b]=l.bind(null,a)}var r=(b,a)=>{for(var c in a)k(b,c,{get:a[c],enumerable:!0,configurable:!0,set:m.bind(a,c)})};var t=n(import.meta.url),o=Symbol.dispose||Symbol.for("Symbol.dispose"),p=Symbol.asyncDispose||Symbol.for("Symbol.asyncDispose"),u=(b,a,c)=>{if(a!=null){if(typeof a!=="object"&&typeof a!=="function")throw TypeError('Object expected to be assigned to "using" declaration');var e;if(c)e=a[p];if(e===void 0)e=a[o];if(typeof e!=="function")throw TypeError("Object not disposable");b.push([c,e,a])}else if(c)b.push([c]);return a},v=(b,a,c)=>{var e=typeof SuppressedError==="function"?SuppressedError:function(d,i,f,g){return g=Error(f),g.name="SuppressedError",g.error=d,g.suppressed=i,g},j=(d)=>a=c?new e(d,a,"An error was suppressed during disposal"):(c=!0,d),h=(d)=>{while(d=b.pop())try{var i=d[1]&&d[1].call(d[2]);if(d[0])return Promise.resolve(i).then(h,(f)=>(j(f),h()))}catch(f){j(f)}if(c)throw a};return h()};
|
|
2
|
+
export{q as qe,r as re,t as se,u as te,v as ue};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{se as O}from"./index-bgq9d21h.js";import{randomUUID as w}from"node:crypto";import{lstat as N,readFile as B,rename as b,unlink as U}from"node:fs/promises";import{dirname as V,resolve as L}from"node:path";var S=process.platform==="win32",W=new Set;function I(j){if(j?.reason==="io-error"){if(j.win32Code===2||j.win32Code===3)return"ENOENT";if(j.win32Code===80||j.win32Code===183)return"EEXIST"}return j?.code??"ERR_PRIVATE_FILE"}var C;function q(){return C??=import("@cortexkit/private-files"),C}class R extends Error{path;stage;code;win32Code;reason;published=!1;durabilityConfirmed=!1;fileDurable=!1;attempts=0;elapsedMs=0;orphanPath;constructor(j,G,A){let z=A;super(`Private file refused at ${G}: ${j} (${z?.reason??z?.code??"io-error"}). Use a safe parent directory. Repair only a named secret file in safe ancestry whose owner the published policy trusts, without changing its owner or any existing directory. Previously exposed credentials may need rotation. Windows requires the private-files native prebuild and an ACL-persisting local filesystem such as NTFS.`,{cause:A});this.path=j,this.stage=G,this.name="PrivateFileError",this.code=I(z),this.win32Code=z?.win32Code,this.reason=z?.reason}}async function x(j,G,A){try{return await A()}catch(z){if(z instanceof R)throw z;throw new R(j,G,z)}}var E;async function _(j,G){j=L(j),G??=E,await x(j,"safe-parent",async()=>{let A=await(await q()).verifySafeParent(j,G);if(A.ok===!1){if(A.reason==="io-error"||A.reason==="wrong-kind")await N(j);throw new R(A.level??A.path,"safe-parent",{...A,code:"ERR_PRIVATE_FILES_SECURITY"})}})}async function T(j,G,A=!1){if(j=L(j),G==="directory")return _(j);await x(j,"verify",async()=>{let z=await q(),K=await z.verifyOwnerOnly(j),H=!1;if(!K.ok){let{reason:M}=K.refusal;if(M==="io-error")await z.verifyPrivatePath(j,G);if(A&&[z.EXTRA_ACE,z.NOT_PROTECTED,z.NULL_DACL,z.EMPTY_DACL].includes(M))await _(V(j)),await z.securePrivatePath(j,G),H=!0;else throw Object.assign(Error("Owner-only verification refused"),{reason:M,code:"ERR_PRIVATE_FILES_SECURITY"})}if(await z.verifyPrivatePath(j,G),H&&!W.has(j))W.add(j),process.emitWarning(`Private permissions tightened: ${j}. This object may have been readable before; rotate credentials if needed.`,"PrivateFileMigration")})}async function D(j,G=!1,A){j=L(j),await x(j,"directory",async()=>{let z=await q();try{return await N(j),await _(j,A)}catch(H){if(I(H)!=="ENOENT")throw H}let K=V(j);if(K===j)throw Object.assign(Error("Missing root"),{code:"ENOENT"});await D(K,!1,A);try{await z.createOwnerOnly(j,{kind:"dir"})}catch(H){if(I(H)!=="EEXIST")throw H}await _(j,A)})}async function m(j,G=!1){if(!S)return B(j,"utf8");return(await k(j,G)).toString("utf8")}async function k(j,G=!1){if(!S)return B(j);if(j=L(j),G)await _(V(j)),await T(j,"file",!0);return x(j,"read",async()=>(await q()).readOwnerOnly(j))}async function F(j,G){await _(V(L(j))),await x(j,"create",async()=>{await(await q()).createPrivateFile(L(j),G)})}async function c(j){await _(V(L(j))),await x(j,"directory-create",async()=>{await(await q()).createOwnerOnly(L(j),{kind:"dir"})})}async function g(j,G,A={}){j=L(j),G=L(G);let z=A.now??(()=>performance.now()),K=z(),H=Math.min(K+500,A.deadline??1/0),M=[0,10,20,40,80,100],Y,$=0;for(let Q of M){if(z()>=H)break;if(Q)await(A.sleep??((X)=>new Promise((Z)=>setTimeout(Z,X))))(Math.min(Q,Math.max(0,H-z())));if(z()>=H)break;if(await A.beforeRename?.(),z()>=H)break;$++;try{return await(A.rename??b)(j,G),{attempts:$,elapsedMs:z()-K}}catch(X){Y??=X;let Z=X;if(!(Z.win32Code!==void 0?Z.win32Code===32||Z.win32Code===33:["EBUSY","EPERM","EACCES"].includes(Z.code??"")&&!Z.reason))break}}let J=new R(G,"rename",Y??Object.assign(Error("Publication deadline expired"),{code:"ETIMEDOUT"}));throw J.attempts=$,J.elapsedMs=z()-K,J}async function v(j,G,A={}){j=L(j),await D(V(j));try{await T(j,"file",!0)}catch(J){if(J.code!=="ENOENT")throw J}let z=L(A.stagePath??`${j}.${w()}.tmp`);if(V(z)!==V(j))throw new R(j,"stage-directory",{code:"EXDEV"});let K=!1,H=!1,M={attempts:0,elapsedMs:0},Y="stage-create",$=(J)=>{try{A.onOutcome?.({path:j,stage:J?.stage??"published",published:H,fileDurable:H,durabilityConfirmed:!1,attempts:J?.attempts??M.attempts,elapsedMs:J?.elapsedMs??M.elapsedMs,...J&&{code:J.code,win32Code:J.win32Code}})}catch{}};try{if(await F(z,G),K=!0,Y="before-rename",M=await g(z,j,A),K=!1,H=!0,Y="published-callback",A.onRenamed?.(),Y="published-verify",await T(j,"file"),A.durable&&A.durability!=="file-only-on-windows")throw new R(j,"directory-sync-unsupported",{code:"ENOTSUP"});$()}catch(J){let Q=J instanceof R?J:new R(j,Y,J);if(Q.published=H,Q.fileDurable=H,H)Object.assign(Q,M);if(K){try{await U(z)}catch{Q.orphanPath=z}K=!1}throw $(Q),Q}finally{if(K)await U(z).catch(()=>{})}}
|
|
2
|
+
export{S as be,R as ce,x as de,_ as ee,T as fe,D as ge,m as he,F as ie,c as je,g as ke,v as le};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{be as O,ce as U,fe as b,ge as m,he as L,le as y}from"./index-dryydk6b.js";import{createHash as Zz,randomUUID as v}from"node:crypto";import{chmod as t,mkdir as r,open as e,readdir as j,rename as zz,rmdir as Gz,stat as Jz,unlink as S}from"node:fs/promises";import{join as R,resolve as D}from"node:path";function l(z){return typeof z==="number"&&Number.isSafeInteger(z)&&z>0}function F(z){if(!l(z))return!1;try{return process.kill(z,0),!0}catch(J){return J.code==="EPERM"}}function Cz(z){return(J)=>Kz(J,z)}function Kz(z,J){if(/^[0-9a-f]{16}$/.test(z))return!0;return z.startsWith(J)&&/^[0-9a-f]{16}$/.test(z.slice(J.length))}function Nz(z){let J=/^port-(\d+)\.json$/.exec(z);return J?Number(J[1]):void 0}function p(z,J){if(z===null||typeof z!=="object"||Array.isArray(z))return!1;let{pid:V,port:Q,token:K}=z;return l(V)&&Nz(J)===V&&typeof Q==="number"&&Number.isInteger(Q)&&Q>=1&&Q<=65535&&typeof K==="string"&&K.length>0}async function h(z,J){J?.debug("rpc corrupt port file",{pid:process.pid,portFile:z}),await S(z).catch(()=>{})}async function Az(z,J,V={}){let Q=async()=>{let K=R(z,`port-${J.pid}.json`);if(O)return await m(z,V.secureDir??!1),await V.beforeWrite?.(),await y(K,JSON.stringify({...J,startedAt:Date.now()}),{stagePath:`${K}.${(V.stageName??v)()}.tmp`}),K;if(await r(z,{recursive:!0,mode:V.secureDir?448:void 0}),V.secureDir)await t(z,448);await V.beforeWrite?.();let W={...J,startedAt:Date.now()},Y=`${K}.${(V.stageName??v)()}.tmp`,N,G=!1;try{N=await e(Y,"wx",384),G=!0,await N.writeFile(JSON.stringify(W),"utf8"),await N.chmod(384),await N.close(),N=void 0,await zz(Y,K),G=!1}finally{if(await N?.close().catch(()=>{}),G)await S(Y).catch(()=>{})}return K};try{return await Q()}catch(K){if(K.code==="ENOENT")return await Q();throw K}}async function Oz(z,J,V,Q){let K;try{K=await j(z,{withFileTypes:!0})}catch(Y){if(Y.code==="ENOENT")return;throw Y}let W=D(J);for(let Y of K){if(!Y.isDirectory()||!V(Y.name))continue;let N=R(z,Y.name),G;try{G=await j(N)}catch(X){if(X.code==="ENOENT")continue;throw X}for(let X of G){if(!X.startsWith("port-")||!X.endsWith(".json"))continue;let $=R(N,X),Z;try{Z=await L($)}catch(H){if(H instanceof U&&H.code!=="ENOENT")throw H;continue}if(Z===void 0)continue;let q;try{q=JSON.parse(Z)}catch{await h($,Q);continue}if(!p(q,X)){await h($,Q);continue}if(!F(q.pid))await S($).catch(()=>{})}if(D(N)!==W)await Gz(N).catch(()=>{})}}async function c(z,J){if(!F(J.pid))return null;let V=R(D(z),`port-${J.pid}.json`);try{if(O)await b(V,"file");let Q=await Jz(V);return`${V}:${Q.dev}:${Q.ino}:${Q.mtimeMs}:${Q.size}`}catch(Q){if(Q instanceof U&&Q.code!=="ENOENT")throw Q;return null}}async function a(z,J,V={}){let Q;try{if(O)await b(z,"directory");Q=await j(z)}catch(G){if(G instanceof U&&G.code!=="ENOENT")throw G;return null}let K=[];for(let G of Q){if(!G.startsWith("port-")||!G.endsWith(".json"))continue;try{let X=JSON.parse(await L(R(z,G)));if(p(X,G))if(F(X.pid))K.push(X);else await S(R(z,G)).catch(()=>{})}catch(X){if(X instanceof U&&X.code!=="ENOENT")throw X}}if(K.length===0)return null;let W=J!==void 0&&J>=1?K.filter((G)=>G.pid===J):[];if(V.exactPid===!0&&W.length===0)return null;let Y=W.length>0?W:K,N=(G)=>typeof G.startedAt==="number"&&Number.isFinite(G.startedAt)?G.startedAt:-1/0;return Y.sort((G,X)=>N(X)-N(G))[0]??null}import{open as Qz}from"node:fs/promises";import{connect as Vz}from"node:net";import{join as Wz,resolve as o}from"node:path";var i=2000,A=new Map,T=new Map;async function Xz(z,J){let V=Wz(o(z),`port-${J.pid}.json`);if(O){let K=JSON.parse(await L(V));if(K.pid!==J.pid||K.port!==J.port||K.token!==J.token)return null;return null}let Q;try{Q=await Qz(V,"r");let K=await Q.stat(),W=JSON.parse(await Q.readFile("utf8"));if(W.pid!==J.pid||W.port!==J.port||W.token!==J.token)return null;return`${V}:${K.dev}:${K.ino}:${K.mtimeMs}:${K.size}`}catch{return null}finally{await Q?.close().catch(()=>{})}}async function s(z,J,V,Q){let K=A.get(z);if(!O&&K&&await c(J,K.entry)===K.identity)return K;A.delete(z);let W=T.get(z);if(W)return W;let Y=(async()=>{let N=await(Q.discover??a)(J,V,Q);if(!N)return null;let G=await Xz(J,N);if(!G)return{entry:N,identity:""};let X={entry:N,identity:G};return A.set(z,X),X})();T.set(z,Y);try{return await Y}finally{if(T.get(z)===Y)T.delete(z)}}async function d(z,J,V,Q=i){return new Promise((K)=>{let W,Y=!1,N=!1,G=($,Z=!1)=>{if(Y)return;Y=!0,clearTimeout(X),W?.destroy(),K({value:$,stale:Z})},X=setTimeout(()=>G(null),Q);try{let $=JSON.stringify(V);W=Vz({host:"127.0.0.1",port:z.port}),W.on("connect",()=>{N=!0,W?.write(`POST /rpc/${J} HTTP/1.0\r
|
|
2
|
+
Host: 127.0.0.1:${z.port}\r
|
|
3
|
+
Connection: close\r
|
|
4
|
+
Content-Type: application/json\r
|
|
5
|
+
Content-Length: ${Buffer.byteLength($)}\r
|
|
6
|
+
Authorization: Bearer ${z.token}\r
|
|
7
|
+
\r
|
|
8
|
+
`+$)});let Z=[],q=0,C,H,_=Buffer.alloc(0),g=()=>{if(C===void 0)return G(null);try{let E=Buffer.concat(Z).subarray(C);G(JSON.parse(E.toString("utf8")))}catch{G(null)}};W.on("data",(E)=>{if(Y)return;if(q+=E.length,Z.push(E),C===void 0){_=Buffer.concat([_,E]);let B=_.indexOf(`\r
|
|
9
|
+
\r
|
|
10
|
+
`);if(B>=0)C=B+4;if((C??_.length)>16384)return G(null);if(C!==void 0){let x=_.subarray(0,B).toString("latin1").split(`\r
|
|
11
|
+
`),f=/^HTTP\/1\.[01] (\d{3})(?: |$)/.exec(x[0]??"");if(!f)return G(null);let w=Number(f[1]);if(w<200||w>=300)return G(null,[401,403,404,410].includes(w));for(let M of x.slice(1)){let k=M.indexOf(":"),u=M.slice(0,k).toLowerCase(),P=M.slice(k+1).trim();if(u==="transfer-encoding")return G(null);if(u==="content-length"){if(H!==void 0||!/^\d+$/.test(P))return G(null);if(H=Number(P),!Number.isSafeInteger(H)||H>8388608)return G(null)}}_=Buffer.alloc(0)}}let I=q-(C??q);if(I>8388608)return G(null);if(H!==void 0){if(I>H)return G(null);if(I===H)g()}}),W.on("end",()=>{if(H!==void 0&&q-(C??0)!==H)return G(null);g()}),W.on("error",()=>G(null,!N)),W.on("close",()=>G(null))}catch{G(null,!N)}})}async function n(z,J,V,Q,K,W,Y=i){let N=JSON.stringify([o(z),J??null,V.exactPid===!0]),G=await s(N,z,J,V);if(Q(G?.entry??null),!G)return null;let X=Date.now()+Y,$=await d(G.entry,K,W,Y);if(!$.stale)return $.value;if(A.get(N)===G)A.delete(N);let Z=await s(N,z,J,V);if(!Z||Date.now()>=X)return null;if(Z.entry.port===G.entry.port&&Z.entry.pid===G.entry.pid&&Z.entry.token===G.entry.token){if(A.get(N)===Z)A.delete(N);return null}let q=await d(Z.entry,K,W,X-Date.now());if(q.stale&&A.get(N)===Z)A.delete(N);return q.value}function Tz(z,J,V,Q={}){let K={exactPid:Q.exactPid,discover:Q.discover},W=!1,Y=(N)=>{if(W)return;V?.(N),W=!0};return{async pending(N,G,X){return(await n(z,J,K,Y,"pending-notifications",{lastReceivedId:N,sessionId:G},X))?.messages??[]},async apply(N,G){return await n(z,J,K,Y,"apply",{...N},G)??{text:"apply failed",knobs:{}}}}}
|
|
12
|
+
export{Cz as Md,Az as Nd,Oz as Od,a as Pd,i as Qd,Tz as Rd};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{tc as X,vc as V}from"./index-99esnzg0.js";import{randomUUID as Z}from"node:crypto";import{chmod as $,mkdir as G,readFile as H,rename as L,rm as T,stat as f,writeFile as g}from"node:fs/promises";import{dirname as k,resolve as w}from"node:path";var x="(no OpenCode 1 logins on this machine)";function C(b=process.env){return X(b)}async function Q(b){let z;try{z=await H(b,"utf8")}catch(q){if(q.code==="ENOENT")return;throw q}let j=JSON.parse(z);if(!j||typeof j!=="object"||Array.isArray(j))throw Error(`${b} does not hold a JSON object`);return j}function R(b){return b===void 0?void 0:JSON.stringify(b)}async function D(b){try{return(await f(b)).mode&511}catch(z){if(z.code==="ENOENT")return;throw z}}function _(b=C()){let z=new Map;return{path:w(b),async get(j){let q=(await Q(b))?.[j.path.id];return z.set(j.path.id,R(q)),q},async set(j){let q=j.path.id,W=await D(b),J=await Q(b)??{};if(!z.has(q)||z.get(q)!==R(J[q]))throw new V;J[q]=j.body,await G(k(b),{recursive:!0});let B=`${b}.${Z()}.tmp`;try{await g(B,`${JSON.stringify(J,null,2)}
|
|
2
|
+
`,{mode:W??384}),await $(B,W??384),await L(B,b)}catch(Y){throw await T(B,{force:!0}).catch(()=>{}),Y}return z.set(q,R(j.body)),!0},async all(){let j=await Q(b);if(!j||Object.keys(j).length===0)return{[x]:!0};return j}}}
|
|
3
|
+
export{_ as c};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Md as k,Nd as _,Od as R}from"./index-egrty6tz.js";import{ce as h,he as D}from"./index-dryydk6b.js";import{ne as w}from"./index-45qgkb0m.js";class T extends Error{operation;constructor(f){super(`a ${f} on a strict notification scope needs a session id`);this.name="RpcSessionRequiredError",this.operation=f}}function F(f){return typeof f==="string"&&f.length>0}var S=new Map;function W(f){let x=JSON.stringify([f.rpcRoot,f.directoryPrefix,f.registrationSessionId,...f.requireSession===!0?["strict"]:[]]),z=S.get(x);if(!z)z={queue:[],nextId:1,lastDrainAtBySession:new Map,lastDrainAtAny:0},S.set(x,z);return z}var U=100,j=3000;function d(f,x,z){if(f.requireSession===!0&&!F(z))throw new T("push");let J=W(f);if(J.queue.push({id:J.nextId++,type:"open-dialog",payload:x,sessionId:z}),J.queue.length>U)J.queue=J.queue.slice(-U)}function i(f,x=0,z){if(f.requireSession===!0&&!F(z))throw new T("drain");let J=W(f),Y=Date.now();if(J.lastDrainAtAny=Y,z!==void 0)J.lastDrainAtBySession.set(z,Y);let Z=f.sessionlessDrain==="broadcast-only",V=(B)=>z===void 0?!Z||B.sessionId===void 0:B.sessionId===void 0||B.sessionId===z;if(x>0)J.queue=J.queue.filter((B)=>{if(B.id>x)return!0;if(z===void 0)return!Z||B.sessionId!==void 0;return B.sessionId!==z});return J.queue.filter((B)=>B.id>x&&V(B))}function n(f,x){let z=Date.now(),J=W(f),Y=x!==void 0?J.lastDrainAtBySession.get(x)??0:f.sessionlessDrain==="broadcast-only"?J.lastDrainAtAny:0;return Y>0&&z-Y<j}import{randomBytes as t,timingSafeEqual as q}from"node:crypto";import{unlink as v}from"node:fs/promises";import{createServer as u}from"node:http";import{join as I}from"node:path";class N extends Error{status;constructor(f,x){if(!Number.isInteger(f)||f<400||f>499)throw RangeError(`RpcRequestError status must be 4xx, got ${f}`);super(x);this.name="RpcRequestError",this.status=f}}var E=1e6;class g extends Error{declaredOversize;constructor(f){super("body too large");this.declaredOversize=f}}function l(f){return new Promise((x,z)=>{let J=(B=!1)=>{f.removeAllListeners("data"),f.on("data",()=>{}),f.resume(),z(new g(B))},Y=Number(f.headers["content-length"]);if(Number.isFinite(Y)&&Y>E){J(!0);return}let Z=[],V=0;f.on("data",(B)=>{if(V+=B.length,V>E){J();return}Z.push(B)}),f.on("end",()=>x(Buffer.concat(Z).toString("utf8"))),f.on("error",z)})}class m extends Error{}async function p(f,x){let z,J=new Promise((Y,Z)=>{z=setTimeout(()=>Z(new m("apply deadline exceeded")),x),z.unref?.()});f.catch(()=>{});try{return await Promise.race([f,J])}finally{clearTimeout(z)}}function c(f,x){if(!f?.startsWith("Bearer "))return!1;let z=Buffer.from(f.slice(7)),J=Buffer.from(x);return z.length===J.length&&q(z,J)}async function Bf(f){if(typeof f.drain==="function"===(typeof f.drainAsync==="function"))throw TypeError("exactly one of drain or drainAsync must be provided");let x=f.log??{warn(){},debug(){}},z=t(32).toString("hex"),J=f.timeoutMs??90000,Y=f.receiptTimeoutMs??2000,Z=!1,V=new Set,B=u((G,K)=>{G.setTimeout(J,()=>{G.socket.destroy()}),M(G,K)});B.on("connection",(G)=>{V.add(G),G.once("close",()=>V.delete(G))}),B.requestTimeout=Y,B.headersTimeout=Y;async function M(G,K){let H=(X,Q,C={})=>{if(K.headersSent||K.writableEnded||K.destroyed)return;K.writeHead(X,{"content-type":"application/json",...C}),K.end(JSON.stringify(Q))};try{let X=new URL(G.url??"/","http://127.0.0.1").pathname;if(G.method==="GET"&&X==="/health")return H(200,{ok:!0});if(G.method!=="POST"||!X.startsWith("/rpc/"))return H(404,{error:"not found"});if(!c(G.headers.authorization,z))return H(401,{error:"unauthorized"});let Q=X.slice(5),C;try{C=await l(G)}catch($){if(!($ instanceof g))throw $;if($.declaredOversize){let y=G.socket;K.once("finish",()=>{y.end();let A=setTimeout(()=>y.destroy(),2000);if(A.unref(),G.once("end",()=>y.destroy()),y.once("close",()=>clearTimeout(A)),G.complete)y.destroy()})}return H(413,{error:"body too large"},{connection:"close"})}let b;try{b=JSON.parse(C||"{}")}catch{return H(400,{error:"invalid json"})}if(Q==="pending-notifications"){let $;try{if(f.parsePending)$=f.parsePending(b);else{if(!b||typeof b!=="object"||Array.isArray(b))throw Error("invalid params");let L=b;if(f.requireSession===!0&&!F(L.sessionId))return H(400,{error:"session required"});if("lastReceivedId"in L&&(typeof L.lastReceivedId!=="number"||!Number.isSafeInteger(L.lastReceivedId)||L.lastReceivedId<0)||"sessionId"in L&&typeof L.sessionId!=="string")throw Error("invalid params");$={lastReceivedId:Number(L.lastReceivedId??0),sessionId:typeof L.sessionId==="string"?L.sessionId:void 0}}}catch(L){if(L instanceof N)throw L;return H(400,{error:"invalid params"})}let{lastReceivedId:y,sessionId:A}=$;if(f.requireSession===!0&&!F(A))return H(400,{error:"session required"});if(A===void 0&&!Z)Z=!0,x.warn("rpc notification drain missing session id",{pid:process.pid});let O;if(f.drainAsync)try{O=await f.drainAsync(y,A)}catch(L){return x.warn("rpc notification drain failed",{pid:process.pid,error:L instanceof Error?L.message:String(L)}),H(500,{error:"drain failed"})}else O=f.drain?.(y,A);return H(200,{messages:O})}if(Q==="apply"){let $=Promise.resolve(f.apply(b)),y=f.applyDeadlineMs===void 0?await $:await p($,f.applyDeadlineMs);return H(200,y)}return H(404,{error:"unknown method"})}catch(X){if(X instanceof N)return x.debug("rpc request refused",{pid:process.pid,status:X.status}),H(X.status,{error:X.message});if(X instanceof m)return x.warn("rpc apply deadline exceeded",{pid:process.pid,deadlineMs:f.applyDeadlineMs}),H(504,{error:"handler deadline exceeded"});x.warn("rpc request failed",{pid:process.pid,error:X instanceof Error?X.message:String(X)}),H(500,{error:"internal error"})}}let P=await new Promise((G,K)=>{B.on("error",K),B.listen(0,"127.0.0.1",()=>{let H=B.address();if(H&&typeof H==="object")G(H.port);else K(Error("no port"))})});if(B.unref(),f.sweepRoot)try{await R(f.sweepRoot,f.dir,f.isManagedDir,x)}catch(G){x.warn("rpc state sweep failed",{pid:process.pid,error:G instanceof Error?G.message:String(G)})}try{await _(f.dir,{port:P,token:z,pid:process.pid},{secureDir:f.secureDir}),x.debug("rpc server pid",{pid:process.pid,rpcPort:P})}catch(G){throw await new Promise((K)=>B.close(()=>K())),G}return{port:P,token:z,async stop(){await new Promise((H)=>{B.closeAllConnections?.(),B.close(()=>H());for(let X of V)X.destroy()});let G=I(f.dir,`port-${process.pid}.json`),K=await D(G).then((H)=>JSON.parse(H)).catch((H)=>{if(H instanceof h&&H.code!=="ENOENT")throw H;return});if(K?.port===P&&K.token===z)await v(G).catch(()=>{})}}}async function Hf(f,x,z){let J=globalThis,Y=Symbol.for(f),Z=J[Y]??{servers:new Map,pending:new Map};J[Y]=Z;let{servers:V,pending:B}=Z,M=B.get(x)??Promise.resolve(),P,G=M.catch(()=>{}).then(async()=>{let H=V.get(x);if(H){if(await H.stop(),V.get(x)===H)V.delete(x)}P=await z(),V.set(x,P)});B.set(x,G);try{await G}finally{if(B.get(x)===G)B.delete(x)}let K=P;if(!K)throw Error("RPC server failed to start");return{server:K,release:async()=>{if(V.get(x)!==K)return;if(await K.stop(),V.get(x)===K)V.delete(x)}}}var bf=k(w);
|
|
2
|
+
export{d as Gd,i as Hd,n as Id,Bf as Jd,Hf as Kd,bf as Ld};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{be as q,de as O,fe as A,ge as y,ie as p,ke as k}from"./index-dryydk6b.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 Sd,v as Td,u as Ud,c as Vd,hJ as Wd,mJ as Xd,AJ as Yd,tJ as Zd,cJ as _d,dJ as $d,lJ as ae};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{qe as Z,se as W}from"./index-bgq9d21h.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{Ud as S,Xd as i}from"./index-k4eacw7x.js";var G="all",t=Object.freeze(["primary"]);function b(z){return z.kind==="retired"?z.retiredAt:z.checkedAt}function Q(z,D){return JSON.stringify([z,D])}function M(z){return typeof z==="object"&&z!==null&&!Array.isArray(z)}function V(z){return typeof z==="number"&&Number.isFinite(z)}function h(z){return typeof z==="string"&&z.length>0}function I(z,D,H){return z[D]===void 0||H(z[D])}function e(z){return V(z)&&z>0}function F(z){return typeof z==="string"}function zz(z){if(!M(z)||!h(z.scope)||!h(z.label))return!1;switch(z.kind){case"reading":return V(z.checkedAt)&&V(z.usedPercent)&&I(z,"resetsAt",F)&&I(z,"windowMinutes",e);case"retired":return V(z.retiredAt);case"absent":return V(z.checkedAt);default:return!1}}function Dz(z){if(!M(z)||!V(z.checkedAt))return!1;if(z.kind==="cleared")return!0;return z.kind==="reading"&&typeof z.reached==="boolean"&&I(z,"remainingPercent",V)&&I(z,"usedPercent",V)&&I(z,"resetsAt",F)&&I(z,"limit",V)&&I(z,"used",V)&&I(z,"remaining",V)&&I(z,"unit",F)}function p(z){return M(z)&&V(z.value)&&Number.isInteger(z.value)&&z.value>=0&&V(z.checkedAt)}function N(z){return M(z)&&Object.values(z).every(p)}function A(z){if(!M(z))return;let D=Object.entries(z).filter(([,H])=>p(H));return D.length===0?void 0:Object.fromEntries(D)}function _(z){if(R(z))return z;if(!M(z))return;let{counters:D,...H}=z;if(!R(H))return;let J=A(D);return{...H,...J===void 0?{}:{counters:J}}}function R(z){if(!M(z)||!Array.isArray(z.limits))return!1;let D=new Set;for(let H of z.limits){if(!zz(H))return!1;let J=Q(H.scope,H.label);if(D.has(J))return!1;D.add(J)}return I(z,"budget",Dz)&&I(z,"counters",N)}var g=900000,m="no quota reading yet",d="no limits reported";function v(z){let D=Math.max(1,Math.round(z/60000));if(D<60)return`${D}m`;let H=Math.round(D/60);if(H<24)return`${H}h`;return`${Math.max(1,Math.round(D/1440))}d`}function Hz(z){if(z%1440===0)return`${z/1440}d`;if(z%60===0)return`${z/60}h`;return`${z}m`}function s(z){if(z.scope!==G||z.windowMinutes===void 0)return z.label;return Hz(z.windowMinutes)}function c(z){return`${Math.round(Math.min(100,Math.max(0,z)))}% left`}function y(z,D){if(z===void 0)return"";let H=Date.parse(z);if(!Number.isFinite(H)||H<=D)return"";return`, resets ${v(H-D)}`}function Jz(z,D){let H=z.windowMinutes,J=D.windowMinutes;if(H!==void 0&&J!==void 0&&H!==J)return H-J;if(H===void 0!==(J===void 0))return H===void 0?1:-1;if(z.scope!==D.scope){if(z.scope===G)return-1;if(D.scope===G)return 1;return z.scope<D.scope?-1:1}return z.label<D.label?-1:z.label>D.label?1:0}function o(z,D){if(!z)return[];let{now:H}=D,J=(D.form??"full")==="full",U=[],X=[],T=z.limits.filter((Z)=>Z.kind==="reading"&&Z.remainingPercent!==void 0).sort(Jz);for(let Z of T)X.push(Z.checkedAt),U.push(`${s(Z)} ${c(Z.remainingPercent??0)}${J?y(Z.resetsAt,H):""}`);let W=z.budget;if(W){X.push(W.checkedAt);let Z=W.reached?"credits spent":W.remainingPercent!==void 0?`credits ${c(W.remainingPercent)}`:"credits available";U.push(`${Z}${J?y(W.resetsAt,H):""}`)}if(X.length>0){let Z=H-Math.min(...X);if(Z>(D.staleAfterMs??g))U.push(`checked ${v(Z)} ago`)}return U}function Uz(z,D){let H=o(z,D);if(H.length>0)return H.join(" · ");return z&&z.limits.length>0?d:m}function Xz(z){if(z.kind==="retired")return{scope:z.scope,label:z.label,kind:"retired",checkedAt:z.retiredAt};if(z.kind==="absent")return{scope:z.scope,label:z.label,kind:"absent",checkedAt:z.checkedAt};return{scope:z.scope,label:z.label,kind:"reading",checkedAt:z.checkedAt,usedPercent:z.usedPercent,remainingPercent:100-z.usedPercent,...z.windowMinutes===void 0?{}:{windowMinutes:z.windowMinutes},...z.resetsAt===void 0?{}:{resetsAt:z.resetsAt}}}function Yz(z,D){let H=z.windowMinutes!==void 0,J=D.windowMinutes!==void 0;if(H!==J)return H?-1:1;if(H&&J&&z.windowMinutes!==D.windowMinutes)return(D.windowMinutes??0)-(z.windowMinutes??0);if(z.label!==D.label)return z.label<D.label?-1:1;return 0}function Zz(z){return{checkedAt:z.checkedAt,reached:z.reached,...z.remainingPercent===void 0?{}:{remainingPercent:z.remainingPercent},...z.resetsAt===void 0?{}:{resetsAt:z.resetsAt}}}function $z(z,D=G){let H=new Map;for(let $ of z?.limits??[]){if($.scope!==D&&$.scope!==G)continue;let P=H.get($.label);if(P===void 0){H.set($.label,$);continue}let j=$.scope===G?P:$,E=$.scope===G?$:P;H.set($.label,j.kind==="reading"?j:E)}let J=[...H.values()].map(Xz).sort(Yz),U=J.filter(($)=>$.kind==="reading"),X=U.length>0?U:J,T=X.length>0?Math.min(...X.map(($)=>$.checkedAt)):void 0,W=z?.budget?.kind==="reading"?Zz(z.budget):void 0,Z=A(z?.counters);return{scope:D,limits:J,...T===void 0?{}:{checkedAt:T},...W===void 0?{}:{budget:W},...Z===void 0?{}:{counters:Z}}}function Gz(z,D){let H=z?.budget;if(H?.reached!==!0||typeof H.resetsAt!=="string")return;let J=Date.parse(H.resetsAt);if(!Number.isFinite(J)||J<=D)return;return{resetsAt:H.resetsAt,resetAtMs:J}}function Vz(z){return z.kind==="reading"&&typeof z.usedPercent==="number"&&Number.isFinite(z.usedPercent)&&z.usedPercent>=100}function Wz(z,D){if(typeof z.resetsAt!=="string")return;let H=Date.parse(z.resetsAt);return Number.isFinite(H)&&H>D?H:void 0}class q extends TypeError{constructor(z){super(z);this.name="QuotaCodecError"}}function C(z){return typeof z==="object"&&z!==null&&!Array.isArray(z)}function O(z){return typeof z==="number"&&Number.isFinite(z)}function n(z){return z===void 0||typeof z==="string"&&z!==""}function u(z){return typeof z==="string"&&z!==""}function K(z,D){return z[D]===void 0||O(z[D])}function L(z,D){return z[D]===void 0||typeof z[D]==="string"}function Iz(z){return C(z)&&n(z.scope)&&u(z.label)&&O(z.usedPercent)&&L(z,"resetsAt")&&(z.windowMinutes===void 0||O(z.windowMinutes)&&z.windowMinutes>0)}function xz(z){return C(z)&&n(z.scope)&&u(z.label)}function Bz(z){if(!C(z))return!1;if(z.kind==="cleared")return!0;return z.kind==="reading"&&typeof z.reached==="boolean"&&K(z,"remainingPercent")&&K(z,"usedPercent")&&L(z,"resetsAt")&&K(z,"limit")&&K(z,"used")&&K(z,"remaining")&&L(z,"unit")}function l(z){if(!C(z)||!O(z.checkedAt))return!1;let D=z.readings??[],H=z.coverage??[];if(!Array.isArray(D)||!Array.isArray(H))return!1;let J=new Set;for(let U of D){if(!Iz(U))return!1;let X=Q(U.scope??G,U.label);if(J.has(X))return!1;J.add(X)}if(!H.every(xz))return!1;return(z.budget===void 0||Bz(z.budget))&&(z.counters===void 0||N(z.counters))}function Tz(z,D){if(z.scope!==D.scope)return z.scope<D.scope?-1:1;if(z.label!==D.label)return z.label<D.label?-1:1;return 0}function Mz(z,D,H){if(D===void 0)return z;if(z!==void 0&&H<z.checkedAt)return z;return{...D,checkedAt:H}}function Qz(z,D){let H=new Map(Object.entries(z??{}));for(let[J,U]of Object.entries(D??{})){let X=H.get(J);if(X===void 0||U.checkedAt>=X.checkedAt)H.set(J,U)}return H.size===0?void 0:Object.fromEntries(H)}function w(z,D){let H=z===void 0?void 0:_(z);if(z!==void 0&&H===void 0)throw new q("stored quota map is malformed");if(!l(D))throw new q("quota observation is malformed");let J=H??{limits:[]},U=D.checkedAt,X=new Map;for(let Y of J.limits)X.set(Q(Y.scope,Y.label),Y);let T=(Y)=>{let x=X.get(Y);return x===void 0||U>=b(x)},W=new Set;for(let Y of D.readings??[]){let x=Y.scope??G,B=Q(x,Y.label);if(W.add(B),!T(B))continue;X.set(B,{scope:x,label:Y.label,kind:"reading",checkedAt:U,usedPercent:Y.usedPercent,...Y.resetsAt===void 0?{}:{resetsAt:Y.resetsAt},...Y.windowMinutes===void 0?{}:{windowMinutes:Y.windowMinutes}})}for(let Y of D.coverage??[]){let x=Y.scope??G,B=Q(x,Y.label);if(W.has(B)||!T(B))continue;let f=X.get(B);X.set(B,f===void 0||f.kind==="absent"?{scope:x,label:Y.label,kind:"absent",checkedAt:U}:{scope:x,label:Y.label,kind:"retired",retiredAt:U})}let{limits:Z,budget:$,counters:P,...j}=J,E=Mz(J.budget,D.budget,U),k=Qz(J.counters,D.counters);return{...j,limits:[...X.values()].sort(Tz),...E===void 0?{}:{budget:E},...k===void 0?{}:{counters:k}}}var Rz=Object.freeze({validate:R,decode:_,merge:w});import{tmpdir as r}from"node:os";import{join as a}from"node:path";var _z=["error","warn","info","debug","trace"];function Kz(){return process.env.OPENCODE_OPENAI_AUTH_LOG_FILE??(process.platform==="win32"?a(r(),"opencode-openai-auth","opencode-openai-auth.log"):a(r(),"opencode-openai-auth.log"))}function Pz(){let z=process.env.OPENCODE_OPENAI_AUTH_LOG_LEVEL;return z&&_z.includes(z)?z:void 0}i({file:Kz,level:Pz});if(process.once("beforeExit",async()=>{try{await S()}catch{process.emitWarning("OpenAI auth could not flush its log file at shutdown")}}),process.platform!=="win32")process.on("exit",()=>S());
|
|
2
|
+
export{G as kd,t as ld,_ as md,R as nd,w as od,Rz as pd,s as qd,o as rd,Uz as sd,$z as td,Gz as ud,Vz as vd,Wz as wd};
|
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-DqKq8Eej.js";
|
|
2
|
+
import { _ as SidebarMachineState, b as SidebarState } from "./sidebar-state-BCxFpH68.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-5dg931q0.js";import{sa as a,ta as b}from"./index-99esnzg0.js";import"./index-9reyazwh.js";import"./index-yf6arn5w.js";import"./index-2hch7e8n.js";import"./index-jye6vccc.js";import"./index-egrty6tz.js";import"./index-k4eacw7x.js";import"./index-dryydk6b.js";import"./index-45qgkb0m.js";import"./index-bgq9d21h.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.0+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 };
|