@cortexkit/opencode-openai-auth 1.14.1 → 1.15.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.
- package/dist/bin.js +9 -9
- package/dist/{codex-request-Cl6zEfsR.d.ts → codex-request-DYqSE0ti.d.ts} +373 -2
- package/dist/{index-wma2ggn9.js → index-14x5shtc.js} +2 -2
- package/dist/index-1wcg7g9d.js +2 -0
- package/dist/index-50p400eg.js +8 -0
- package/dist/index-98q3mydm.js +64 -0
- package/dist/{index-yygzbxjk.js → index-bhkycxbm.js} +1 -1
- package/dist/{index-k5av4j8p.js → index-dzpjz8hv.js} +2 -2
- package/dist/{index-cxnrd85v.js → index-f7kmsdfk.js} +1 -1
- package/dist/{index-z9cj13z7.js → index-hnfqppx9.js} +1 -1
- package/dist/{index-2f330s35.js → index-m8m7rakq.js} +2 -2
- package/dist/index-mjsmvmt4.js +76 -0
- package/dist/{index-gkye2xh1.js → index-s8ghhc9z.js} +2 -2
- package/dist/{index-94b345dw.js → index-t65axpta.js} +1 -1
- package/dist/index-xjtbg7sx.js +101 -0
- package/dist/index.d.ts +1 -372
- package/dist/index.js +1 -1
- package/dist/openai-auth.schema.json +400 -0
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-sgwxn4xg.js → token-j34j1zhm.js} +1 -1
- package/dist/token-util-bf619nmg.js +1 -0
- package/dist/tui-preferences.js +3 -3
- package/dist/v2/server.d.ts +1 -1
- package/dist/v2/server.js +2 -2
- package/package.json +3 -3
- package/src/tui-compiled/raw/logger.js +8 -1
- package/src/tui-compiled/raw/shared/061e741c052de9c1-paths.js +48 -0
- package/src/tui-compiled/raw/shared/0766d78c6f481f18-watcher.js +41 -18
- package/src/tui-compiled/raw/shared/23300c068d0b2ffc-parse.js +65 -0
- package/src/tui-compiled/raw/shared/3000be4f79f20eb6-write.js +88 -0
- package/src/tui-compiled/raw/shared/44449e891fab9fbc-edit.js +229 -0
- package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +1 -1
- package/src/tui-compiled/raw/shared/5803fadb30af0ec0-descriptors.js +81 -0
- package/src/tui-compiled/raw/shared/58bc35a3cd459085-define.js +52 -0
- package/src/tui-compiled/raw/shared/5f4bc45522ab9bc6-update.js +139 -0
- package/src/tui-compiled/raw/shared/6948d70969aa7a55-fs.js +19 -0
- package/src/tui-compiled/raw/shared/754d6017f8e419cf-builtins.js +28 -12
- package/src/tui-compiled/raw/shared/81758f9fe7c2a576-handle.js +228 -0
- package/src/tui-compiled/raw/shared/87f6e22d4fc34918-resolve.js +51 -0
- package/src/tui-compiled/raw/shared/8a18abe4fa2977c8-menu.js +1 -0
- package/src/tui-compiled/raw/shared/8ab1f5794e677151-move.js +351 -0
- package/src/tui-compiled/raw/shared/92e38944b51b2405-file-read-cache.js +9 -5
- package/src/tui-compiled/raw/shared/9865a4fa45882c6f-settings-decisions.js +13 -0
- package/src/tui-compiled/raw/shared/cc0f2d1963547799-index.js +7 -0
- package/src/tui-compiled/raw/shared/dbc61cd405941828-accounts.js +48 -5
- package/src/tui-compiled/raw/shared/e0ed4a490e4eaa4f-schema.js +81 -0
- package/src/tui-compiled/raw/shared/e8cd4929507508d8-refresh-file-lock.js +146 -2
- package/src/tui-compiled/raw/shared/eac0bed49f3d4110-lock-errors.js +15 -0
- package/src/tui-compiled/raw/shared/facfd8afc431d68a-refusal.js +15 -0
- package/src/tui-compiled/raw/shared/fc7db0c5aa764565-settings-install.js +85 -0
- package/src/tui-compiled/raw/shared/fcd26e77bc538838-snapshot.js +150 -0
- package/src/tui-compiled/runtime/logger.js +8 -1
- package/src/tui-compiled/runtime/shared/061e741c052de9c1-paths.js +48 -0
- package/src/tui-compiled/runtime/shared/0766d78c6f481f18-watcher.js +41 -18
- package/src/tui-compiled/runtime/shared/23300c068d0b2ffc-parse.js +65 -0
- package/src/tui-compiled/runtime/shared/3000be4f79f20eb6-write.js +88 -0
- package/src/tui-compiled/runtime/shared/44449e891fab9fbc-edit.js +229 -0
- package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +1 -1
- package/src/tui-compiled/runtime/shared/5803fadb30af0ec0-descriptors.js +81 -0
- package/src/tui-compiled/runtime/shared/58bc35a3cd459085-define.js +52 -0
- package/src/tui-compiled/runtime/shared/5f4bc45522ab9bc6-update.js +139 -0
- package/src/tui-compiled/runtime/shared/6948d70969aa7a55-fs.js +19 -0
- package/src/tui-compiled/runtime/shared/754d6017f8e419cf-builtins.js +28 -12
- package/src/tui-compiled/runtime/shared/81758f9fe7c2a576-handle.js +228 -0
- package/src/tui-compiled/runtime/shared/87f6e22d4fc34918-resolve.js +51 -0
- package/src/tui-compiled/runtime/shared/8a18abe4fa2977c8-menu.js +1 -0
- package/src/tui-compiled/runtime/shared/8ab1f5794e677151-move.js +351 -0
- package/src/tui-compiled/runtime/shared/92e38944b51b2405-file-read-cache.js +9 -5
- package/src/tui-compiled/runtime/shared/9865a4fa45882c6f-settings-decisions.js +13 -0
- package/src/tui-compiled/runtime/shared/cc0f2d1963547799-index.js +7 -0
- package/src/tui-compiled/runtime/shared/dbc61cd405941828-accounts.js +48 -5
- package/src/tui-compiled/runtime/shared/e0ed4a490e4eaa4f-schema.js +81 -0
- package/src/tui-compiled/runtime/shared/e8cd4929507508d8-refresh-file-lock.js +146 -2
- package/src/tui-compiled/runtime/shared/eac0bed49f3d4110-lock-errors.js +15 -0
- package/src/tui-compiled/runtime/shared/facfd8afc431d68a-refusal.js +15 -0
- package/src/tui-compiled/runtime/shared/fc7db0c5aa764565-settings-install.js +85 -0
- package/src/tui-compiled/runtime/shared/fcd26e77bc538838-snapshot.js +150 -0
- package/dist/index-3mbw88h7.js +0 -91
- package/dist/index-999nwa9p.js +0 -76
- package/dist/index-pc4vrrex.js +0 -2
- package/dist/index-snq7bwr6.js +0 -8
- package/dist/index-xk7f1aef.js +0 -64
- package/dist/token-util-8mrnmkge.js +0 -1
package/dist/index-pc4vrrex.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{eg as q,hg as _,jg as A,kg as w,mg as k,og as p}from"./index-2f330s35.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 $(G){let U=G,V=[["name",G.name],["message",G.message],["stack",G.stack]];for(let j of["code","status","cause"])if(U[j]!==void 0)V.push([j,U[j]]);let Y=new Set(V.map(([j])=>j));for(let j of Object.entries(G))if(!Y.has(j[0]))V.push(j);return V}function B(G,U,V,Y=0){if(typeof G==="string")return H.reduce((j,C)=>j.replace(C,"***REDACTED***"),G);if(!G||typeof G!=="object")return G;if(V.has(G))return"[Circular]";V.add(G);try{if(Array.isArray(G))return G.map((N)=>B(N,U,V,Y));let j=JJ(G);if(j&&Y>=8)return"[Truncated]";let C=j?Y+1:Y;return Object.fromEntries((j?$(G):Object.entries(G)).map(([N,z])=>[N,U&&Z(N)?"***REDACTED***":B(z,U,V,C)]))}finally{V.delete(G)}}return{redact:(G)=>B(G,!0,new WeakSet),redactStrings:(G)=>B(G,!1,new WeakSet)}}var E=T(),GJ=E.redact,HJ=E.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 $=`${J}.${Z+1}`;g(`${J}.${Z}`,$),b($)}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 _(H,"log-close",()=>Z.close())}async function y(J,H){await w(VJ(H));try{await A(H,"file",!0)}catch(Z){if(Z.code!=="ENOENT")throw Z;try{await k(H,"")}catch($){if($.code!=="EEXIST")throw $;await A(H,"file",!0)}}return J.handle=await _(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 $=J.handle??await y(J,H);if((await _(H,"log-stat",()=>$.stat())).size>=h){await M(J);for(let G=m-1;G>=0;G--){let U=G===0?H:`${H}.${G}`,V=`${H}.${G+1}`;try{await A(U,"file",!0)}catch(Y){if(Y.code==="ENOENT")continue;throw Y}try{await A(V,"file",!0)}catch(Y){if(Y.code!=="ENOENT")throw Y}await p(U,V),await A(V,"file")}$=await y(J,H)}await _(H,"log-append",()=>$.appendFile(Z,"utf8"))}catch($){throw await M(J).catch(()=>{}),$}}function YJ(J){try{return` ${JSON.stringify(J)}`}catch{return" [unserializable]"}}function BJ(J){let H,Z,$,B=T(),G,U=[],V,Y=Promise.resolve(),j,C={};function N(Q){let I=Y.then(Q);return Y=I.catch((X)=>{j=X}),I}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)$=Q}function o(){if(H===void 0)return;return(typeof H==="function"?H():H)||void 0}function t(){if($)return $;let Q=typeof Z==="function"?Z():Z;if(Q&&Q in D)return Q;return"info"}function R(Q=!0){if(V)clearTimeout(V),V=void 0;if(!U.length){if(q)return N(async()=>{if(Q)await M(C);if(j)throw j});return}let I;try{I=o()}catch{if(U=[],q&&Q)return N(()=>M(C));return}let X=U.join("");if(U=[],!I){if(q&&Q)return N(()=>M(C));return}if(q)return N(async()=>{try{await XJ(C,I,X)}finally{if(Q)await M(C)}});try{if(jJ(I),W(I))b(I);QJ(I,X,{encoding:"utf8",mode:384})}catch{}}function a(){if(!V)V=setTimeout(()=>{V=void 0;let Q=R(!1);if(Q instanceof Promise)Q.catch(()=>{})},500)}function x(Q,I,X,P){if(H===void 0&&G===void 0)return;try{if(D[I]>D[t()])return;let S=B.redactStrings(X),K;try{K=B.redact(P)}catch{K="[unserializable]"}let r=`[${new Date().toISOString()}] ${I.toUpperCase()} [${Q}] ${S}`+(P===void 0?"":YJ(K))+`
|
|
2
|
-
`;try{G?.({channel:Q,level:I,message:S,data:K})}catch{}if(H===void 0)return;if(U.push(r),U.length>=50){let F=R(!1);if(F instanceof Promise)F.catch(()=>{})}else a()}catch{}}function n(Q){return{error:(I,X)=>x(Q,"error",I,X),warn:(I,X)=>x(Q,"warn",I,X),info:(I,X)=>x(Q,"info",I,X),debug:(I,X)=>x(Q,"debug",I,X),trace:(I,X)=>x(Q,"trace",I,X)}}function l(){if(q)N(()=>M(C)).catch(()=>{});if(j=void 0,U=[],V)clearTimeout(V),V=void 0;H=void 0,Z=void 0,$=void 0,B=T(),G=void 0}if(J)z(J);return{configure:z,createLogger:n,setLogLevel:s,flushLogs:R,reset:l}}var O=BJ();function L(J){O.configure(J);let{configure:H,createLogger:Z,setLogLevel:$,flushLogs:B}=O;return{configure:H,createLogger:Z,setLogLevel:$,flushLogs:B}}function v(J){O.setLogLevel(J)}function u(){return O.flushLogs()}function c(J){return O.createLogger(J)}function f(J){return J==="chatgptaccountid"||J==="email"||J==="orgname"||J==="organizationname"}var d=T({extraSecretKeys:f}),kJ=d.redact,pJ=d.redactStrings;function hJ(J){L({...J,extraSecretKeys:f})}function uJ(J){if(J instanceof Error)return J.message;if(typeof J==="string")return J;try{return JSON.stringify(J)}catch{return String(J)}}function fJ(J){return"notify"in J}import{basename as MJ,dirname as TJ,join as qJ}from"node:path";var AJ="openai-auth.json",xJ="openai-auth-state.json";function oJ(J){return MJ(J)===AJ?qJ(TJ(J),xJ):`${J}.state.json`}import{spawn as _J}from"node:child_process";function nJ(J,H=process.platform,Z=_J){try{if(H==="win32"){let B=`Start-Process '${J.replaceAll("'","''")}'`,G=Buffer.from(B,"utf16le").toString("base64"),U=Z("powershell.exe",["-NoProfile","-NonInteractive","-WindowStyle","Hidden","-EncodedCommand",G],{stdio:"ignore",windowsHide:!0});return U.on("error",()=>{}),U.unref(),U.pid!==void 0}let $=Z(H==="darwin"?"open":"xdg-open",[J],{stdio:"ignore"});return $.on("error",()=>{}),$.unref(),$.pid!==void 0}catch{return!1}}export{T as Tf,GJ as Uf,v as Vf,u as Wf,c as Xf,pJ as Yf,hJ as Zf,AJ as _f,xJ as $f,oJ as ag,uJ as bg,fJ as cg,nJ as dg};
|
package/dist/index-snq7bwr6.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{eg as $,fg as D,gg as h,hg as L0,jg as C,kg as N0,lg as b,mg as B0,ng as O0,pg as l}from"./index-2f330s35.js";import{randomUUID as k}from"node:crypto";import{link as v0,lstat as R,mkdir as f0,open as G0,readFile as C0,rename as M0,rm as L,stat as g}from"node:fs/promises";import{dirname as r,join as b0}from"node:path";import{resolve as I0}from"node:path";class y extends Error{path;code="ENOENT";constructor(z,G){super(`Lock record disappeared: ${z}`,{cause:G});this.path=z}}function f(z,G){return z instanceof D&&z.reason==="io-error"&&z.win32Code===5&&(z.stage==="read"||z.stage==="verify")&&G.some((Q)=>I0(Q)===z.path)}function M(z,G,Q){return z instanceof D&&z.reason==="io-error"&&z.win32Code===5&&z.stage===Q&&G.some((Z)=>I0(Z)===z.path)}async function I(z,G){try{return await G()}catch(Q){if(!f(Q,[z]))throw Q;try{return await G()}catch(Z){if(Z.code==="ENOENT")throw new y(z,Q);throw Q}}}import{join as u0,resolve as P0}from"node:path";function e(z,G){return`${z}.${G}.lock`}class A0 extends Error{details;constructor(z){super(`Timed out acquiring ${z.name} lock for ${z.target}`);this.name="LockContentionError",this.details=z}}class E extends Error{details;constructor(z){super(`Lost ${z.name} lock for ${z.target}`);this.name="LockOwnershipError",this.details=z}}function w0(z,G,Q){let Z=P0(e(G,Q)),J=[Z,u0(Z,"owner.json")];return(h(z)||f(z,J))&&(z.stage==="read"||z.stage==="verify")&&J.includes(z.path)||$&&(M(z,[Z],"create")||M(z,[`${Z}.evicting`],"directory-create"))}async function Hz(z,G,Q){let Z=performance.now(),J;for(;;){G.signal?.throwIfAborted();let _;try{_=await T0({path:z,name:G.name,ttlMs:G.ttlMs,renew:G.renew??!1,...G.onStep?{onStep:G.onStep}:{},...G.onRenewalTimer?{onRenewalTimer:G.onRenewalTimer}:{}}),J=void 0}catch(j){if(!w0(j,z,G.name))throw j;_=null,J??=j}if(_)try{return G.signal?.throwIfAborted(),await Q(_)}finally{await _.release(G.signal)}let W=G.timeoutMs-(performance.now()-Z);if(W<=0){if(J)throw J;throw new A0({target:z,name:G.name,timeoutMs:G.timeoutMs})}await new Promise((j)=>setTimeout(j,Math.min(25,Math.ceil(W))))}}var O;async function p0(z,G){let Q=`${z}.${k()}.tmp`,Z;try{Z=await G0(Q,"wx",384);try{if(O?.beforeWrite)await O.beforeWrite(Q);await Z.writeFile(G,"utf8")}finally{await Z.close()}try{if(O?.beforeLink)await O.beforeLink(Q,z);await v0(Q,z)}catch(J){let _=J.code;if(_!=="EPERM"&&_!=="ENOTSUP"&&_!=="EOPNOTSUPP"&&_!=="EXDEV")throw J;await y0(z,G)}}finally{if(Z)await L(Q,{force:!0}).catch(()=>{})}}async function y0(z,G){let Q=await G0(z,"wx",384),Z;try{Z=await Q.stat()}catch{Z=void 0}try{if(O?.beforeWrite)await O.beforeWrite(z);await Q.writeFile(G,"utf8")}catch(J){try{let _=await R(z).catch(()=>{return});if(Z&&_&&_.dev===Z.dev&&_.ino===Z.ino)await L(z,{force:!0}).catch(()=>{})}catch{}throw J}finally{await Q.close()}}var h0=globalThis.setTimeout.bind(globalThis),l0=globalThis.clearTimeout.bind(globalThis);function c0(z){let G=z?.code;return G==="ENOENT"||!$&&(G==="EINVAL"||G==="ENOTDIR")}var R0;function z0(z,G){if(z.dev!==G.dev||z.ino!==G.ino)return!1;if(z.ino===0&&z.birthtimeMs!==G.birthtimeMs)return!1;return!0}var d0=1000;function T0(z){return s0({...z,now:Date.now})}async function s0(z){let G=e(z.path,z.name),Q=b0(G,"owner.json"),Z=k(),J=z.now??Date.now,_=null,W=!1,j=!1,F,Q0,g0=new Promise((N)=>{Q0=N});function Y0(N){try{let B=z.onRenewalTimer?.(N);if(B&&(typeof B==="object"||typeof B==="function")&&"then"in B&&typeof B.then==="function")Promise.resolve(B).catch(()=>{})}catch{}}function Z0(){if(!_)return;l0(_),_=null,Y0("cancelled")}function T(N,B){if(F||W)return;F=Object.freeze({reason:N,expectedOwnerId:Z,...typeof B?.ownerId==="string"?{observedOwnerId:B.ownerId}:{},...typeof B?.expiresAt==="number"?{observedExpiresAt:B.expiresAt}:{}}),Z0(),Q0(F)}let d,m=null,X=`${G}.evicting`,x=b0(X,"owner.json"),$0=k(),s=5000,J0=8;function u(N){return $&&(M(N,[G],"create")||M(N,[X],"directory-create"))}async function S(){if($)try{return JSON.parse(await I(G,()=>b(G,!0)))}catch(N){if(N.code!=="EISDIR"&&N.reason!=="wrong-kind")throw N;return await I(G,()=>C(G,"directory",!0)),JSON.parse(await I(Q,()=>b(Q,!0)))}try{return JSON.parse(await C0(G,"utf8"))}catch(N){if(N.code!=="EISDIR")throw N;return JSON.parse(await C0(Q,"utf8"))}}async function k0(){if($){let K=await S(),Y=Number(K?.expiresAt)-J();await l(G,`${JSON.stringify({ownerId:Z,expiresAt:J()+z.ttlMs})}
|
|
2
|
-
`,{deadline:performance.now()+Math.max(0,Y),beforeRename:async()=>{let V=await S();if(V?.ownerId!==Z||!(Number(V?.expiresAt)>J())||!await q())throw new E({target:z.path,name:z.name})}});return}let N=`${G}.${k()}.tmp`,B,H=!1;try{B=await G0(N,"wx",384),H=!0,await B.writeFile(`${JSON.stringify({ownerId:Z,expiresAt:J()+z.ttlMs})}
|
|
3
|
-
`,"utf8"),await B.chmod(384),await B.close(),B=void 0;let K=await S();if(K?.ownerId!==Z||!(Number(K?.expiresAt)>J())||!await q())throw new E({target:z.path,name:z.name});await M0(N,G),H=!1}finally{if(await B?.close().catch(()=>{}),H)await L(N,{force:!0}).catch(()=>{})}}async function _0(){let N=`${JSON.stringify({ownerId:Z,expiresAt:J()+z.ttlMs})}
|
|
4
|
-
`;if($)await B0(G,N);else await p0(G,N)}async function X0(N){let B=N.code;if(B!=="EEXIST"&&B!=="EISDIR")return!1;if($){if(z.onStep)await z.onStep("lease-contention-read-ready");try{if(B==="EISDIR")await I(G,()=>C(G,"directory",!0)),await I(Q,()=>b(Q,!0));else await S()}catch(H){if(H.code!=="ENOENT")throw H}}return!0}async function i(){if($)await N0(r(G));try{return await _0(),!0}catch(N){let B=N.code;if(await X0(N))return!1;if(B==="ENOENT"){if($)await N0(r(G));else await f0(r(G),{recursive:!0});try{return await _0(),!0}catch(H){if(await X0(H))return!1;throw H}}throw N}}async function P(){await new Promise((N)=>setTimeout(N,Math.floor(Math.random()*4)))}async function n(N=!0){if(N&&z.onStep)await z.onStep("lock-read-ready");let B;try{B=await S()}catch(K){if(K instanceof y)return{status:"missing"};if($&&K.code!=="ENOENT")throw K}let H=Number(B?.expiresAt);if(Number.isFinite(H)&&H>J())return{status:"live"};if(typeof B?.ownerId==="string"&&Number.isFinite(H))return{status:"stale",identity:{kind:"owner",ownerId:B.ownerId,expiresAt:H}};try{let K=await g(G),Y=Number.isFinite(H)?H:K.mtimeMs+z.ttlMs;if(Y>J())return{status:"live"};return{status:"stale",identity:{kind:"stat",dev:K.dev,ino:K.ino,mtimeMs:K.mtimeMs,expiresAt:Y}}}catch(K){if(K.code==="ENOENT"){if(z.onStep)await z.onStep("lock-missing");return{status:"missing"}}throw K}}function U0(N,B){if(B.status!=="stale")return!1;let H=B.identity;if(N.kind==="owner"&&H.kind==="owner")return N.ownerId===H.ownerId&&N.expiresAt===H.expiresAt;return N.kind==="stat"&&H.kind==="stat"&&N.dev===H.dev&&N.ino===H.ino&&N.mtimeMs===H.mtimeMs&&N.expiresAt===H.expiresAt}async function q(){try{return JSON.parse(await I(x,()=>b(x,$)))?.ownerId===$0}catch(N){if($&&N.code!=="ENOENT")throw N;return!1}}async function a(N){if($)await L0(N,"remove",()=>L(N,{recursive:!0,force:!0}));else await L(N,{recursive:!0,force:!0}).catch(()=>{})}function w(N,B){if(!$||!(N instanceof D)||N.stage!=="remove"||N.path!==B)return!1;return h(N)||N.win32Code===void 0&&N.reason===void 0&&(N.code==="EBUSY"||N.code==="EPERM")}async function t(N,B,H=performance.now()+s+1000){let K,Y=5;while(await B()){try{await a(N);return}catch(U){if(!w(U,N))throw U;K??=U}let V=H-performance.now();if(V<=0)throw K;if(await new Promise((U)=>setTimeout(U,Math.min(Y,V))),performance.now()>=H)throw K;Y=Math.min(Y*2,50)}}async function o(N){let B;await t(X,async()=>{if(!$)return q();let H=await R(X).catch((K)=>{if(K.code!=="ENOENT")throw K;return});if(!H||B&&!z0(B,H))return!1;if(await q())return B=H,!0;if(!B)return!1;try{return await g(x),!1}catch(K){if(K.code!=="ENOENT")throw K;return!0}},N)}async function m0(N,B){if(!N)return!1;let H=!1;try{await t(X,async()=>{H=!1;let K=await R(X).catch(()=>{return});if(!K||!z0(N,K))return!1;H=!0;try{return await g(x),!1}catch(Y){return Y.code==="ENOENT"}},B)}catch{}return H}async function V0(N){if($)await O0(X);else await f0(X);let B;try{let H=await R(X);B={dev:H.dev,ino:H.ino,birthtimeMs:H.birthtimeMs}}catch{B=void 0}try{await R0?.beforeOwnerWrite?.(X,x);let H=await R0?.failOwnerWrite?.(X,x);if(H!==void 0)throw H;let K=`${JSON.stringify({ownerId:$0,createdAt:J()})}
|
|
5
|
-
`;if($)await B0(x,K);else await y0(x,K)}catch(H){let K=await m0(B,N);if(c0(H)&&!K)return!1;try{await o(N)}catch{}throw H}if(z.onStep)await z.onStep("eviction-marker-acquired");return!0}async function W0(N){let B;try{B=await g(X)}catch(Y){if(Y.code==="ENOENT")return"missing";throw Y}if($)try{await I(X,()=>C(X,"directory",!0))}catch(Y){if(Y.code==="ENOENT")return"missing";throw Y}if(B.mtimeMs+s>J()){let Y=!0;try{await g(x)}catch(V){if(V.code==="ENOENT")Y=!1;else return"fresh"}if(Y)return"fresh";if(B.mtimeMs+d0>J())return"fresh"}if(z.onStep)await z.onStep("stale-marker-stat");let H=`${X}.${k()}`;try{await M0(X,H)}catch(Y){if(Y.code==="ENOENT")return"missing";throw Y}if(z.onStep)await z.onStep("stale-marker-claimed");let K=$?await R(H):void 0;return await t(H,async()=>{if(!K)return!0;let Y=await R(H).catch((V)=>{if(V.code!=="ENOENT")throw V;return});return!!Y&&z0(K,Y)},N),"recovered"}async function x0(N,B){try{if(!await V0(B))return!1}catch(Y){if(Y.code==="EEXIST"){if($)try{await I(X,()=>C(X,"directory",!0)),await I(x,()=>b(x,!0))}catch(V){if(V.code!=="ENOENT")throw V}return!1}throw Y}let H=!1,K;try{await N()}catch(Y){H=!0,K=Y}try{await o(B)}catch(Y){if((w(K,G)||f(K,[G,Q,x]))&&(w(Y,X)||f(Y,[x])))throw K;throw Y}if(H)throw K;return!0}async function j0(){for(let N=0;N<J0;N++){if(z.onStep)await z.onStep("relinquish-read");let B;try{B=await S()}catch(H){if($&&!(H instanceof y))throw H;return}if(B?.ownerId!==Z)return;try{await L(G,{recursive:!0,force:!0});return}catch(H){if($)throw H;await P()}}}function F0(){if(!z.renew||W||F)return;let N=z.renewIntervalMs??Math.max(1000,Math.floor(z.ttlMs/3));if(_=h0(()=>{_=null;let B=(async()=>{let H=!W;try{if(!await x0(async()=>{let Y=await S(),V=J();if(W||F){H=!1;return}if(Y?.ownerId!==Z){T("taken-over",Y),H=!1;return}if(!(Number(Y?.expiresAt)>V)){T("expired",Y),H=!1;return}if(z.onStep)await z.onStep("renewal-owner-confirmed");if(W||F){H=!1;return}if(!await q())return;if(z.onStep)await z.onStep("renewal-write-fenced");if(W||F){H=!1;return}if(!await q())return;if(z.onStep)await z.onStep("renewal-write-ready");if(W||F){H=!1;return}if(await k0(),z.onStep)await z.onStep("renewal-write-finished");if(!await q()){T("marker-lost"),H=!1,await j0();return}})&&z.onStep)await z.onStep("renewal-marker-unavailable")}catch(K){if($&&K instanceof D&&!u(K))d=K,T("renewal-failed"),H=!1;try{let Y=await S();if(Y?.ownerId!==Z)T("taken-over",Y);else if(!(Number(Y?.expiresAt)>J()))T("expired",Y)}catch{T("renewal-failed")}}finally{if(z.onStep)try{await z.onStep("renewal-finished")}catch{}if(H&&!W&&!F)F0()}})();m=B,B.finally(()=>{if(m===B)m=null})},N),"unref"in _)_.unref();Y0("scheduled")}function q0(){try{let N=z.onContended?.();if(N&&(typeof N==="object"||typeof N==="function")&&"then"in N&&typeof N.then==="function")Promise.resolve(N).catch(()=>{})}catch{}return null}let A=!1,v;try{A=await i()}catch(N){if(!u(N))throw N;v=N}if(!A)for(let N=0;N<J0;N++)try{if(A=await i(),A)break;let B=await n();if(B.status==="live")return q0();if(B.status==="missing")continue;if(z.onStep)await z.onStep("stale-lock-observed");try{if(!await V0()){await P();continue}}catch(H){if(H.code!=="EEXIST")throw H;if(await W0()==="fresh")return null;await P();continue}try{let H=await n();if(H.status==="live")return q0();if(!U0(B.identity,H))continue;if(!await q())return null;if(z.onStep)await z.onStep("stale-lock-confirmed");if(!await q())return null;let K=await n(!1);if(!U0(B.identity,K))continue;if(await a(G),!await q())return null;if(z.onStep)await z.onStep("stale-lock-removed");if(A=await i(),!A)return null;if(z.onStep)await z.onStep("stale-lock-recreated");if(!await q())return await j0(),A=!1,null;break}finally{await o()}}catch(B){if(!u(B))throw B;v??=B,await P()}if(!A){if(v)throw v;return null}return F0(),{ownerId:Z,whenLost:()=>g0,hasLost:()=>F!==void 0,assertOwned:async()=>{if(d)throw d;let N;try{let B=await S();if(N=B,!W&&!F&&B?.ownerId===Z&&Number(B?.expiresAt)>J())return;T(B?.ownerId!==Z?"taken-over":"expired",B)}catch(B){if(T("unreadable"),$&&B instanceof D)throw B}throw new E({target:z.path,name:z.name,expectedOwnerId:Z,...typeof N?.ownerId==="string"?{observedOwnerId:N.ownerId}:{},...typeof N?.expiresAt==="number"?{observedExpiresAt:N.expiresAt}:{}})},release:async(N)=>{if($&&j)return;W=!0,Z0(),await m;let B=performance.now()+s+1000,H=5,K,Y;for(;;){try{let U=!1,p=await x0(async()=>{let D0;try{D0=await S()}catch(S0){if($&&S0.code==="ENOENT"){U=!0;return}throw S0}if(D0?.ownerId!==Z){U=!0;return}if(z.onStep)await z.onStep("release-owner-confirmed");if(!await q())return;await a(G),U=!0},B);if(Y=void 0,p){if($&&!U)throw new D(G,"release-not-confirmed",{code:"EIO"});j=U;return}if(N?.aborted)return;await W0(B)}catch(U){let p=$&&(u(U)||f(U,[G,Q,X,x]));if(!w(U,G)&&!p){if($)throw U;return}if(p)Y??=U;else K??=U}let V=B-performance.now();if(V<=0)break;if(await new Promise((U)=>setTimeout(U,Math.min(H,V))),$&&performance.now()>=B)break;H=Math.min(H*2,50)}if($)throw Y??K??new D(G,"release-not-confirmed",{code:"ETIMEDOUT"})}}}import{randomUUID as E0}from"node:crypto";import{mkdir as i0,open as c,rename as n0,rm as a0}from"node:fs/promises";import{dirname as H0}from"node:path";class K0 extends Error{constructor(z){super("file or directory sync failed",{cause:z});this.name="AtomicSyncError"}}async function jz(z,G,Q={}){await t0(z,G,Q)}async function t0(z,G,Q,Z){if($)return l(z,Q.serialize?Q.serialize(G):`${JSON.stringify(G,null,2)}
|
|
6
|
-
`,{beforeRename:Q.beforeRename,stagePath:`${z}.${(Q.stageName??E0)()}.tmp`,onRenamed:Z,durable:Q.durable,durability:Q.durability,onOutcome:Q.onOutcome});await i0(H0(z),{recursive:!0});let J=`${z}.${(Q.stageName??E0)()}.tmp`,_,W=!1;try{if(_=await c(J,"wx",384),W=!0,await _.writeFile(Q.serialize?Q.serialize(G):`${JSON.stringify(G,null,2)}
|
|
7
|
-
`,"utf8"),await _.chmod(384),Q.durable)try{await _.sync()}catch(j){throw new K0(j)}if(await _.close(),_=void 0,await Q.beforeRename?.(),await n0(J,z),W=!1,Z?.(),Q.durable){let j=await c(H0(z),"r");try{await j.sync()}catch(F){throw new K0(F)}finally{await j.close()}}}finally{if(await _?.close().catch(()=>{}),W)await a0(J,{force:!0}).catch(()=>{})}}async function Fz(z){if($){await C(z,"file");let Z=new D(z,"directory-sync-unsupported",{code:"ENOTSUP"});throw Z.published=!0,Z}let G=await c(z,"r");try{await G.sync()}finally{await G.close()}let Q=await c(H0(z),"r");try{await Q.sync()}finally{await Q.close()}}var Dz=Object.freeze({sidebar:Object.freeze({name:"sidebar-write",ttlMs:1e4,timeoutMs:15000,renew:!0}),preferences:Object.freeze({name:"preferences",ttlMs:1e4,timeoutMs:2000,renew:!0})});
|
|
8
|
-
export{K0 as vf,jz as wf,t0 as xf,Fz as yf,T0 as zf,e as Af,A0 as Bf,E as Cf,Hz as Df,Dz as Ef};
|