@cortexkit/opencode-openai-auth 1.21.1 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/bin.js +2 -2
  2. package/dist/index-2z4dbnsf.js +60 -0
  3. package/dist/{index-fgt2dy20.js → index-7hcv94as.js} +1 -1
  4. package/dist/{index-hxp3dm9e.js → index-897br01q.js} +2 -2
  5. package/dist/{index-7v9tyyrn.js → index-bbrpg1ms.js} +2 -2
  6. package/dist/index-bpx4spyr.js +1 -0
  7. package/dist/{index-wwp78jx3.js → index-d0g5g290.js} +1 -1
  8. package/dist/index-f340dq90.js +101 -0
  9. package/dist/{index-0cpz8t4q.js → index-fasy4end.js} +2 -2
  10. package/dist/{index-vqy1mwn3.js → index-j700j6at.js} +1 -1
  11. package/dist/index-q2czrasr.js +2 -0
  12. package/dist/{index-0hk39zee.js → index-r31f36mn.js} +2 -2
  13. package/dist/index-s7dwe5n8.js +79 -0
  14. package/dist/{index-ecqb42ev.js → index-sx9jjkry.js} +2 -2
  15. package/dist/{index-r891a915.js → index-x25m9spd.js} +2 -2
  16. package/dist/index.d.ts +4 -24
  17. package/dist/index.js +1 -1
  18. package/dist/map-D5PHhv4z.d.ts +72 -0
  19. package/dist/openai-auth.schema.json +274 -27
  20. package/dist/rpc/port-file.js +1 -1
  21. package/dist/rpc/protocol.js +1 -1
  22. package/dist/rpc/rpc-client.js +1 -1
  23. package/dist/rpc/rpc-dir.js +1 -1
  24. package/dist/{codex-request-WGAY0gn4.d.ts → runtime-layout-B07ApQZL.d.ts} +665 -645
  25. package/dist/{sidebar-state-CrRiE9hw.d.ts → sidebar-state--OTpRzFd.d.ts} +2 -72
  26. package/dist/sidebar-state.d.ts +1 -1
  27. package/dist/sidebar-state.js +1 -1
  28. package/dist/{token-8afntt1a.js → token-hczqrmmz.js} +1 -1
  29. package/dist/token-util-9t4ma4jz.js +1 -0
  30. package/dist/tui-preferences.js +1 -1
  31. package/dist/tui.d.ts +1 -1
  32. package/dist/v2/server.d.ts +16 -8
  33. package/dist/v2/server.js +4 -4
  34. package/package.json +2 -2
  35. package/src/tui-compiled/raw/logger.js +5 -22
  36. package/src/tui-compiled/raw/shared/58bc35a3cd459085-define.js +10 -1
  37. package/src/tui-compiled/raw/shared/87f6e22d4fc34918-resolve.js +10 -5
  38. package/src/tui-compiled/raw/shared/bfbdd0f9aae56b47-pool-quota.js +10 -0
  39. package/src/tui-compiled/raw/shared/d669d72c40e9e116-logger.js +30 -1
  40. package/src/tui-compiled/raw/shared/dbc61cd405941828-accounts.js +1 -1
  41. package/src/tui-compiled/raw/shared/fe02abeadc535f77-rows.js +8 -3
  42. package/src/tui-compiled/runtime/logger.js +5 -22
  43. package/src/tui-compiled/runtime/shared/58bc35a3cd459085-define.js +10 -1
  44. package/src/tui-compiled/runtime/shared/87f6e22d4fc34918-resolve.js +10 -5
  45. package/src/tui-compiled/runtime/shared/bfbdd0f9aae56b47-pool-quota.js +10 -0
  46. package/src/tui-compiled/runtime/shared/d669d72c40e9e116-logger.js +30 -1
  47. package/src/tui-compiled/runtime/shared/dbc61cd405941828-accounts.js +1 -1
  48. package/src/tui-compiled/runtime/shared/fe02abeadc535f77-rows.js +8 -3
  49. package/dist/index-0cht4a77.js +0 -64
  50. package/dist/index-dmdmb1pp.js +0 -1
  51. package/dist/index-j28pt8dy.js +0 -2
  52. package/dist/index-jq1efs0q.js +0 -101
  53. package/dist/index-s1tk4br4.js +0 -75
  54. package/dist/token-util-htrre2k8.js +0 -1
@@ -1,2 +1,2 @@
1
- import{Ug as K,Xg as T,Zg as A,_g as y,ah as m,ch as h}from"./index-ecqb42ev.js";import{appendFileSync as r,chmodSync as i,existsSync as L,renameSync as F,statSync as e}from"node:fs";import{open as C0}from"node:fs/promises";import{dirname as G0,resolve as H0}from"node:path";var s=/^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i,o=/\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;function t(C){return C instanceof Error||Object.prototype.toString.call(C)==="[object Error]"}function q(C={}){let H=[o,...C.extraValuePatterns??[]].map((G)=>new RegExp(G.source,G.flags.includes("g")?G.flags:`${G.flags}g`));function $(G){let J=G.toLowerCase().replace(/[-_]/g,"");return s.test(G)||J.includes("apikey")||J.endsWith("secret")||J.endsWith("password")||J.endsWith("token")&&!J.endsWith("tokens")||!!C.extraSecretKeys?.(J)}function U(G){let J=G,Q=[["name",G.name],["message",G.message],["stack",G.stack]];for(let V of["code","status","cause"])if(J[V]!==void 0)Q.push([V,J[V]]);let N=new Set(Q.map(([V])=>V));for(let V of Object.entries(G))if(!N.has(V[0]))Q.push(V);return Q}function B(G,J,Q,N=0){if(typeof G==="string")return H.reduce((V,X)=>V.replace(X,"***REDACTED***"),G);if(!G||typeof G!=="object")return G;if(Q.has(G))return"[Circular]";Q.add(G);try{if(Array.isArray(G))return G.map((Y)=>B(Y,J,Q,N));let V=t(G);if(V&&N>=8)return"[Truncated]";let X=V?N+1:N;return Object.fromEntries((V?U(G):Object.entries(G)).map(([Y,O])=>[Y,J&&$(Y)?"***REDACTED***":B(O,J,Q,X)]))}finally{Q.delete(G)}}return{redact:(G)=>B(G,!0,new WeakSet),redactStrings:(G)=>B(G,!1,new WeakSet)}}var E=q(),n=E.redact,l=E.redactStrings;var R={error:0,warn:1,info:2,debug:3,trace:4},w=5242880,p=3;function P(C){try{i(C,384)}catch{}}function I0(C){try{if(!(L(C)&&e(C).size>=w))return;for(let $=p-1;$>=1;$--)if(L(`${C}.${$}`)){let U=`${C}.${$+1}`;F(`${C}.${$}`,U),P(U)}let H=`${C}.1`;F(C,H),P(H)}catch{}}async function M(C){let{file:H,handle:$}=C;if(C.file=void 0,C.handle=void 0,H&&$)await T(H,"log-close",()=>$.close())}async function g(C,H){await y(G0(H));try{await A(H,"file",!0)}catch($){if($.code!=="ENOENT")throw $;try{await m(H,"")}catch(U){if(U.code!=="EEXIST")throw U;await A(H,"file",!0)}}return C.handle=await T(H,"log-open",()=>C0(H,"a")),C.file=H,C.handle}async function J0(C,H,$){H=H0(H);try{if(C.file!==H)await M(C);let U=C.handle??await g(C,H);if((await T(H,"log-stat",()=>U.stat())).size>=w){await M(C);for(let G=p-1;G>=0;G--){let J=G===0?H:`${H}.${G}`,Q=`${H}.${G+1}`;try{await A(J,"file",!0)}catch(N){if(N.code==="ENOENT")continue;throw N}try{await A(Q,"file",!0)}catch(N){if(N.code!=="ENOENT")throw N}await h(J,Q),await A(Q,"file")}U=await g(C,H)}await T(H,"log-append",()=>U.appendFile($,"utf8"))}catch(U){throw await M(C).catch(()=>{}),U}}function Q0(C){try{return` ${JSON.stringify(C)}`}catch{return" [unserializable]"}}function Z0(C){let H,$,U,B=q(),G,J=[],Q,N=Promise.resolve(),V,X={};function Y(I){let Z=N.then(I);return N=Z.catch((j)=>{V=j}),Z}function O(I){if(K&&I.file!==H)Y(()=>M(X)).catch(()=>{});H=I.file,$=I.level,B=q(I),G=I.captureSink}function k(I){if(I===void 0||I in R)U=I}function v(){if(H===void 0)return;return(typeof H==="function"?H():H)||void 0}function c(){if(U)return U;let I=typeof $==="function"?$():$;if(I&&I in R)return I;return"info"}function D(I=!0){if(Q)clearTimeout(Q),Q=void 0;if(!J.length){if(K)return Y(async()=>{if(I)await M(X);if(V)throw V});return}let Z;try{Z=v()}catch{if(J=[],K&&I)return Y(()=>M(X));return}let j=J.join("");if(J=[],!Z){if(K&&I)return Y(()=>M(X));return}if(K)return Y(async()=>{try{await J0(X,Z,j)}finally{if(I)await M(X)}});try{if(I0(Z),L(Z))P(Z);r(Z,j,{encoding:"utf8",mode:384})}catch{}}function f(){if(!Q)Q=setTimeout(()=>{Q=void 0;let I=D(!1);if(I instanceof Promise)I.catch(()=>{})},500)}function z(I,Z,j,W){if(H===void 0&&G===void 0)return;try{if(R[Z]>R[c()])return;let b=B.redactStrings(j),x;try{x=B.redact(W)}catch{x="[unserializable]"}let a=`[${new Date().toISOString()}] ${Z.toUpperCase()} [${I}] ${b}`+(W===void 0?"":Q0(x))+`
2
- `;try{G?.({channel:I,level:Z,message:b,data:x})}catch{}if(H===void 0)return;if(J.push(a),J.length>=50){let S=D(!1);if(S instanceof Promise)S.catch(()=>{})}else f()}catch{}}function u(I){return{error:(Z,j)=>z(I,"error",Z,j),warn:(Z,j)=>z(I,"warn",Z,j),info:(Z,j)=>z(I,"info",Z,j),debug:(Z,j)=>z(I,"debug",Z,j),trace:(Z,j)=>z(I,"trace",Z,j)}}function d(){if(K)Y(()=>M(X)).catch(()=>{});if(V=void 0,J=[],Q)clearTimeout(Q),Q=void 0;H=void 0,$=void 0,U=void 0,B=q(),G=void 0}if(C)O(C);return{configure:O,createLogger:u,setLogLevel:k,flushLogs:D,reset:d}}var _=Z0();function $0(C){_.configure(C);let{configure:H,createLogger:$,setLogLevel:U,flushLogs:B}=_;return{configure:H,createLogger:$,setLogLevel:U,flushLogs:B}}function U0(C){_.setLogLevel(C)}function V0(){return _.flushLogs()}function j0(C){return _.createLogger(C)}export{q as Og,n as Pg,$0 as Qg,U0 as Rg,V0 as Sg,j0 as Tg};
1
+ import{Ah as y,Ch as m,Eh as h,uh as K,xh as T,zh as A}from"./index-sx9jjkry.js";import{appendFileSync as r,chmodSync as i,existsSync as L,renameSync as F,statSync as e}from"node:fs";import{open as C0}from"node:fs/promises";import{dirname as G0,resolve as H0}from"node:path";var s=/^(authorization|x-api-key|cookie|set-cookie|refresh|access|token)$/i,o=/\b(Bearer\s+[\w.-]+|sk-[\w-]+|eyJ[\w.-]+)\b|ckh_[A-Za-z0-9_-]{20,}/g;function t(C){return C instanceof Error||Object.prototype.toString.call(C)==="[object Error]"}function q(C={}){let H=[o,...C.extraValuePatterns??[]].map((G)=>new RegExp(G.source,G.flags.includes("g")?G.flags:`${G.flags}g`));function $(G){let J=G.toLowerCase().replace(/[-_]/g,"");return s.test(G)||J.includes("apikey")||J.endsWith("secret")||J.endsWith("password")||J.endsWith("token")&&!J.endsWith("tokens")||!!C.extraSecretKeys?.(J)}function U(G){let J=G,Q=[["name",G.name],["message",G.message],["stack",G.stack]];for(let V of["code","status","cause"])if(J[V]!==void 0)Q.push([V,J[V]]);let N=new Set(Q.map(([V])=>V));for(let V of Object.entries(G))if(!N.has(V[0]))Q.push(V);return Q}function B(G,J,Q,N=0){if(typeof G==="string")return H.reduce((V,X)=>V.replace(X,"***REDACTED***"),G);if(!G||typeof G!=="object")return G;if(Q.has(G))return"[Circular]";Q.add(G);try{if(Array.isArray(G))return G.map((Y)=>B(Y,J,Q,N));let V=t(G);if(V&&N>=8)return"[Truncated]";let X=V?N+1:N;return Object.fromEntries((V?U(G):Object.entries(G)).map(([Y,O])=>[Y,J&&$(Y)?"***REDACTED***":B(O,J,Q,X)]))}finally{Q.delete(G)}}return{redact:(G)=>B(G,!0,new WeakSet),redactStrings:(G)=>B(G,!1,new WeakSet)}}var E=q(),n=E.redact,l=E.redactStrings;var R={error:0,warn:1,info:2,debug:3,trace:4},w=5242880,p=3;function P(C){try{i(C,384)}catch{}}function I0(C){try{if(!(L(C)&&e(C).size>=w))return;for(let $=p-1;$>=1;$--)if(L(`${C}.${$}`)){let U=`${C}.${$+1}`;F(`${C}.${$}`,U),P(U)}let H=`${C}.1`;F(C,H),P(H)}catch{}}async function M(C){let{file:H,handle:$}=C;if(C.file=void 0,C.handle=void 0,H&&$)await T(H,"log-close",()=>$.close())}async function g(C,H){await y(G0(H));try{await A(H,"file",!0)}catch($){if($.code!=="ENOENT")throw $;try{await m(H,"")}catch(U){if(U.code!=="EEXIST")throw U;await A(H,"file",!0)}}return C.handle=await T(H,"log-open",()=>C0(H,"a")),C.file=H,C.handle}async function J0(C,H,$){H=H0(H);try{if(C.file!==H)await M(C);let U=C.handle??await g(C,H);if((await T(H,"log-stat",()=>U.stat())).size>=w){await M(C);for(let G=p-1;G>=0;G--){let J=G===0?H:`${H}.${G}`,Q=`${H}.${G+1}`;try{await A(J,"file",!0)}catch(N){if(N.code==="ENOENT")continue;throw N}try{await A(Q,"file",!0)}catch(N){if(N.code!=="ENOENT")throw N}await h(J,Q),await A(Q,"file")}U=await g(C,H)}await T(H,"log-append",()=>U.appendFile($,"utf8"))}catch(U){throw await M(C).catch(()=>{}),U}}function Q0(C){try{return` ${JSON.stringify(C)}`}catch{return" [unserializable]"}}function Z0(C){let H,$,U,B=q(),G,J=[],Q,N=Promise.resolve(),V,X={};function Y(I){let Z=N.then(I);return N=Z.catch((j)=>{V=j}),Z}function O(I){if(K&&I.file!==H)Y(()=>M(X)).catch(()=>{});H=I.file,$=I.level,B=q(I),G=I.captureSink}function k(I){if(I===void 0||I in R)U=I}function v(){if(H===void 0)return;return(typeof H==="function"?H():H)||void 0}function c(){if(U)return U;let I=typeof $==="function"?$():$;if(I&&I in R)return I;return"info"}function D(I=!0){if(Q)clearTimeout(Q),Q=void 0;if(!J.length){if(K)return Y(async()=>{if(I)await M(X);if(V)throw V});return}let Z;try{Z=v()}catch{if(J=[],K&&I)return Y(()=>M(X));return}let j=J.join("");if(J=[],!Z){if(K&&I)return Y(()=>M(X));return}if(K)return Y(async()=>{try{await J0(X,Z,j)}finally{if(I)await M(X)}});try{if(I0(Z),L(Z))P(Z);r(Z,j,{encoding:"utf8",mode:384})}catch{}}function f(){if(!Q)Q=setTimeout(()=>{Q=void 0;let I=D(!1);if(I instanceof Promise)I.catch(()=>{})},500)}function z(I,Z,j,W){if(H===void 0&&G===void 0)return;try{if(R[Z]>R[c()])return;let b=B.redactStrings(j),x;try{x=B.redact(W)}catch{x="[unserializable]"}let a=`[${new Date().toISOString()}] ${Z.toUpperCase()} [${I}] ${b}`+(W===void 0?"":Q0(x))+`
2
+ `;try{G?.({channel:I,level:Z,message:b,data:x})}catch{}if(H===void 0)return;if(J.push(a),J.length>=50){let S=D(!1);if(S instanceof Promise)S.catch(()=>{})}else f()}catch{}}function u(I){return{error:(Z,j)=>z(I,"error",Z,j),warn:(Z,j)=>z(I,"warn",Z,j),info:(Z,j)=>z(I,"info",Z,j),debug:(Z,j)=>z(I,"debug",Z,j),trace:(Z,j)=>z(I,"trace",Z,j)}}function d(){if(K)Y(()=>M(X)).catch(()=>{});if(V=void 0,J=[],Q)clearTimeout(Q),Q=void 0;H=void 0,$=void 0,U=void 0,B=q(),G=void 0}if(C)O(C);return{configure:O,createLogger:u,setLogLevel:k,flushLogs:D,reset:d}}var _=Z0();function $0(C){_.configure(C);let{configure:H,createLogger:$,setLogLevel:U,flushLogs:B}=_;return{configure:H,createLogger:$,setLogLevel:U,flushLogs:B}}function U0(C){_.setLogLevel(C)}function V0(){return _.flushLogs()}function j0(C){return _.createLogger(C)}export{q as oh,n as ph,$0 as qh,U0 as rh,V0 as sh,j0 as th};
@@ -1 +1 @@
1
- import{createHash as B}from"node:crypto";import{homedir as G,tmpdir as W}from"node:os";import{dirname as J,join as w,resolve as z}from"node:path";var A="OPENCODE_OPENAI_AUTH_RPC_DIR",K="openai-auth-";function L(k){return B("sha256").update(k).digest("hex").slice(0,16)}function M(){let k=process.env.XDG_STATE_HOME||w(G(),".local","state");return w(k,"cortexkit","openai-auth","rpc")}function Q(k){let q=process.env[A]?.trim();if(q)return z(k,q);return w(M(),`${K}${L(k)}`)}async function $(k){let q=process.env[A]?.trim();if(q)return{dir:z(k,q),secureDir:!1};let x=Q(k);return{dir:x,secureDir:!0,sweepRoot:J(x)}}export{W as eh,K as fh,Q as gh,$ as hh};
1
+ import{createHash as B}from"node:crypto";import{homedir as G,tmpdir as W}from"node:os";import{dirname as J,join as w,resolve as z}from"node:path";var A="OPENCODE_OPENAI_AUTH_RPC_DIR",K="openai-auth-";function L(k){return B("sha256").update(k).digest("hex").slice(0,16)}function M(){let k=process.env.XDG_STATE_HOME||w(G(),".local","state");return w(k,"cortexkit","openai-auth","rpc")}function Q(k){let q=process.env[A]?.trim();if(q)return z(k,q);return w(M(),`${K}${L(k)}`)}async function $(k){let q=process.env[A]?.trim();if(q)return{dir:z(k,q),secureDir:!1};let x=Q(k);return{dir:x,secureDir:!0,sweepRoot:J(x)}}export{W as Gh,K as Hh,Q as Ih,$ as Jh};
@@ -0,0 +1,2 @@
1
+ import{createRequire as g}from"node:module";var d=Object.defineProperty;var h=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports);var e=(b)=>b;function f(b,a){this[b]=e.bind(null,a)}var i=(b,a)=>{for(var c in a)d(b,c,{get:a[c],enumerable:!0,configurable:!0,set:f.bind(a,c)})};var k=g(import.meta.url);
2
+ export{h as Kh,i as Lh,k as Mh};
@@ -1,2 +1,2 @@
1
- import{Ag as T,Bg as y,Cg as D,zg as R}from"./index-7v9tyyrn.js";import{$g as I,Vg as v}from"./index-ecqb42ev.js";import{fh as t}from"./index-vqy1mwn3.js";class O extends Error{operation;constructor(f){super(`a ${f} on a strict notification scope needs a session id`);this.name="RpcSessionRequiredError",this.operation=f}}function S(f){return typeof f==="string"&&f.length>0}var g=new Map;function _(f){let x=JSON.stringify([f.rpcRoot,f.directoryPrefix,f.registrationSessionId,...f.requireSession===!0?["strict"]:[]]),P=g.get(x);if(!P)P={queue:[],nextId:1,lastDrainAtBySession:new Map,lastDrainAtAny:0},g.set(x,P);return P}var m=100,l=3000;function Vf(f,x,P){if(f.requireSession===!0&&!S(P))throw new O("push");let V=_(f);if(V.queue.push({id:V.nextId++,type:"open-dialog",payload:x,sessionId:P}),V.queue.length>m)V.queue=V.queue.slice(-m)}function Bf(f,x=0,P){if(f.requireSession===!0&&!S(P))throw new O("drain");let V=_(f),J=Date.now();if(V.lastDrainAtAny=J,P!==void 0)V.lastDrainAtBySession.set(P,J);let K=f.sessionlessDrain==="broadcast-only",H=(B)=>P===void 0?!K||B.sessionId===void 0:B.sessionId===void 0||B.sessionId===P;if(x>0)V.queue=V.queue.filter((B)=>{if(B.id>x)return!0;if(P===void 0)return!K||B.sessionId!==void 0;return B.sessionId!==P});return V.queue.filter((B)=>B.id>x&&H(B))}function Ff(f,x){let P=Date.now(),V=_(f),J=x!==void 0?V.lastDrainAtBySession.get(x)??0:f.sessionlessDrain==="broadcast-only"?V.lastDrainAtAny:0;return J>0&&P-J<l}import{randomBytes as a,timingSafeEqual as o}from"node:crypto";import{unlink as r}from"node:fs/promises";import{createServer as s}from"node:http";import{join as e}from"node:path";import{lstat as c}from"node:fs/promises";import{basename as d,dirname as i,resolve as k}from"node:path";var j=globalThis,w=Symbol.for("common-auth.rpc.startup-sweep");j[w]??={};var U=j[w],n=Date.now;async function q(f,x,P,V){let J=n();if(U.lastSweepAt!==void 0&&J-U.lastSweepAt<60000){let K=k(x);if(i(K)===k(f)&&P(d(K))&&(await c(K).catch((H)=>{if(H.code!=="ENOENT")throw H;return}))?.isDirectory())await D(K,V);return}U.lastSweepAt=J,await y(f,x,P,V)}class b 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 u=1e6;class E extends Error{declaredOversize;constructor(f){super("body too large");this.declaredOversize=f}}function ff(f){return new Promise((x,P)=>{let V=(B=!1)=>{f.removeAllListeners("data"),f.on("data",()=>{}),f.resume(),P(new E(B))},J=Number(f.headers["content-length"]);if(Number.isFinite(J)&&J>u){V(!0);return}let K=[],H=0;f.on("data",(B)=>{if(H+=B.length,H>u){V();return}K.push(B)}),f.on("end",()=>x(Buffer.concat(K).toString("utf8"))),f.on("error",P)})}class h extends Error{}async function xf(f,x){let P,V=new Promise((J,K)=>{P=setTimeout(()=>K(new h("apply deadline exceeded")),x),P.unref?.()});f.catch(()=>{});try{return await Promise.race([f,V])}finally{clearTimeout(P)}}function Pf(f,x){if(!f?.startsWith("Bearer "))return!1;let P=Buffer.from(f.slice(7)),V=Buffer.from(x);return P.length===V.length&&o(P,V)}async function Wf(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(){}},P=a(32).toString("hex"),V=f.timeoutMs??90000,J=f.receiptTimeoutMs??2000,K=!1,H=new Set,B=s((z,G)=>{z.setTimeout(V,()=>{z.socket.destroy()}),M(z,G)});B.on("connection",(z)=>{H.add(z),z.once("close",()=>H.delete(z))}),B.requestTimeout=J,B.headersTimeout=J;async function M(z,G){let F=(X,W,C={})=>{if(G.headersSent||G.writableEnded||G.destroyed)return;G.writeHead(X,{"content-type":"application/json",...C}),G.end(JSON.stringify(W))};try{let X=new URL(z.url??"/","http://127.0.0.1").pathname;if(z.method==="GET"&&X==="/health")return F(200,{ok:!0});if(z.method!=="POST"||!X.startsWith("/rpc/"))return F(404,{error:"not found"});if(!Pf(z.headers.authorization,P))return F(401,{error:"unauthorized"});let W=X.slice(5),C;try{C=await ff(z)}catch(Y){if(!(Y instanceof E))throw Y;let Z=z.socket;if(G.once("finish",()=>{Z.end();let $=setTimeout(()=>Z.destroy(),2000);if($.unref(),z.once("end",()=>Z.destroy()),Z.once("close",()=>clearTimeout($)),z.complete)Z.destroy()}),!Y.declaredOversize&&!z.complete){if(G.headersSent||G.writableEnded||G.destroyed)return;let $=JSON.stringify({error:"body too large"});G.writeHead(413,{"content-type":"application/json","content-length":Buffer.byteLength($),connection:"close"}),G.write($),z.once("end",()=>G.end());return}return F(413,{error:"body too large"},{connection:"close"})}let Q;try{Q=JSON.parse(C||"{}")}catch{return F(400,{error:"invalid json"})}if(W==="pending-notifications"){let Y;try{if(f.parsePending)Y=f.parsePending(Q);else{if(!Q||typeof Q!=="object"||Array.isArray(Q))throw Error("invalid params");let L=Q;if(f.requireSession===!0&&!S(L.sessionId))return F(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");Y={lastReceivedId:Number(L.lastReceivedId??0),sessionId:typeof L.sessionId==="string"?L.sessionId:void 0}}}catch(L){if(L instanceof b)throw L;return F(400,{error:"invalid params"})}let{lastReceivedId:Z,sessionId:$}=Y;if(f.requireSession===!0&&!S($))return F(400,{error:"session required"});if($===void 0&&!K)K=!0,x.warn("rpc notification drain missing session id",{pid:process.pid});let N;if(f.drainAsync)try{N=await f.drainAsync(Z,$)}catch(L){return x.warn("rpc notification drain failed",{pid:process.pid,error:L instanceof Error?L.message:String(L)}),F(500,{error:"drain failed"})}else N=f.drain?.(Z,$);return F(200,{messages:N})}if(W==="apply"){let Y=Promise.resolve(f.apply(Q)),Z=f.applyDeadlineMs===void 0?await Y:await xf(Y,f.applyDeadlineMs);return F(200,Z)}return F(404,{error:"unknown method"})}catch(X){if(X instanceof b)return x.debug("rpc request refused",{pid:process.pid,status:X.status}),F(X.status,{error:X.message});if(X instanceof h)return x.warn("rpc apply deadline exceeded",{pid:process.pid,deadlineMs:f.applyDeadlineMs}),F(504,{error:"handler deadline exceeded"});x.warn("rpc request failed",{pid:process.pid,error:X instanceof Error?X.message:String(X)}),F(500,{error:"internal error"})}}let A=await new Promise((z,G)=>{B.on("error",G),B.listen(0,"127.0.0.1",()=>{let F=B.address();if(F&&typeof F==="object")z(F.port);else G(Error("no port"))})});if(B.unref(),f.sweepRoot)try{await q(f.sweepRoot,f.dir,f.isManagedDir,x)}catch(z){x.warn("rpc state sweep failed",{pid:process.pid,error:z instanceof Error?z.message:String(z)})}try{await T(f.dir,{port:A,token:P,pid:process.pid},{secureDir:f.secureDir}),x.debug("rpc server pid",{pid:process.pid,rpcPort:A})}catch(z){throw await new Promise((G)=>B.close(()=>G())),z}return{port:A,token:P,async stop(){await new Promise((F)=>{B.closeAllConnections?.(),B.close(()=>F());for(let X of H)X.destroy()});let z=e(f.dir,`port-${process.pid}.json`),G=await I(z).then((F)=>JSON.parse(F)).catch((F)=>{if(F instanceof v&&F.code!=="ENOENT")throw F;return});if(G?.port===A&&G.token===P)await r(z).catch(()=>{})}}}async function Mf(f,x,P){let V=globalThis,J=Symbol.for(f),K=V[J]??{servers:new Map,pending:new Map};V[J]=K;let{servers:H,pending:B}=K,M=B.get(x)??Promise.resolve(),A,z=M.catch(()=>{}).then(async()=>{let F=H.get(x);if(F){if(await F.stop(),H.get(x)===F)H.delete(x)}A=await P(),H.set(x,A)});B.set(x,z);try{await z}finally{if(B.get(x)===z)B.delete(x)}let G=A;if(!G)throw Error("RPC server failed to start");return{server:G,release:async()=>{if(H.get(x)!==G)return;if(await G.stop(),H.get(x)===G)H.delete(x)}}}var p="1.21.1";function wf(f,x,P){let V={...x,version:p};return T(f,V,P)}var qf=R(t);
2
- export{Vf as rg,Bf as sg,Ff as tg,Wf as ug,Mf as vg,p as wg,wf as xg,qf as yg};
1
+ import{$g as y,Zg as R,_g as T,ah as D}from"./index-bbrpg1ms.js";import{Bh as I,vh as v}from"./index-sx9jjkry.js";import{Hh as t}from"./index-j700j6at.js";class O extends Error{operation;constructor(f){super(`a ${f} on a strict notification scope needs a session id`);this.name="RpcSessionRequiredError",this.operation=f}}function S(f){return typeof f==="string"&&f.length>0}var g=new Map;function _(f){let x=JSON.stringify([f.rpcRoot,f.directoryPrefix,f.registrationSessionId,...f.requireSession===!0?["strict"]:[]]),P=g.get(x);if(!P)P={queue:[],nextId:1,lastDrainAtBySession:new Map,lastDrainAtAny:0},g.set(x,P);return P}var m=100,l=3000;function Vf(f,x,P){if(f.requireSession===!0&&!S(P))throw new O("push");let V=_(f);if(V.queue.push({id:V.nextId++,type:"open-dialog",payload:x,sessionId:P}),V.queue.length>m)V.queue=V.queue.slice(-m)}function Bf(f,x=0,P){if(f.requireSession===!0&&!S(P))throw new O("drain");let V=_(f),J=Date.now();if(V.lastDrainAtAny=J,P!==void 0)V.lastDrainAtBySession.set(P,J);let K=f.sessionlessDrain==="broadcast-only",H=(B)=>P===void 0?!K||B.sessionId===void 0:B.sessionId===void 0||B.sessionId===P;if(x>0)V.queue=V.queue.filter((B)=>{if(B.id>x)return!0;if(P===void 0)return!K||B.sessionId!==void 0;return B.sessionId!==P});return V.queue.filter((B)=>B.id>x&&H(B))}function Ff(f,x){let P=Date.now(),V=_(f),J=x!==void 0?V.lastDrainAtBySession.get(x)??0:f.sessionlessDrain==="broadcast-only"?V.lastDrainAtAny:0;return J>0&&P-J<l}import{randomBytes as a,timingSafeEqual as o}from"node:crypto";import{unlink as r}from"node:fs/promises";import{createServer as s}from"node:http";import{join as e}from"node:path";import{lstat as c}from"node:fs/promises";import{basename as d,dirname as i,resolve as k}from"node:path";var j=globalThis,w=Symbol.for("common-auth.rpc.startup-sweep");j[w]??={};var U=j[w],n=Date.now;async function q(f,x,P,V){let J=n();if(U.lastSweepAt!==void 0&&J-U.lastSweepAt<60000){let K=k(x);if(i(K)===k(f)&&P(d(K))&&(await c(K).catch((H)=>{if(H.code!=="ENOENT")throw H;return}))?.isDirectory())await D(K,V);return}U.lastSweepAt=J,await y(f,x,P,V)}class b 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 u=1e6;class E extends Error{declaredOversize;constructor(f){super("body too large");this.declaredOversize=f}}function ff(f){return new Promise((x,P)=>{let V=(B=!1)=>{f.removeAllListeners("data"),f.on("data",()=>{}),f.resume(),P(new E(B))},J=Number(f.headers["content-length"]);if(Number.isFinite(J)&&J>u){V(!0);return}let K=[],H=0;f.on("data",(B)=>{if(H+=B.length,H>u){V();return}K.push(B)}),f.on("end",()=>x(Buffer.concat(K).toString("utf8"))),f.on("error",P)})}class h extends Error{}async function xf(f,x){let P,V=new Promise((J,K)=>{P=setTimeout(()=>K(new h("apply deadline exceeded")),x),P.unref?.()});f.catch(()=>{});try{return await Promise.race([f,V])}finally{clearTimeout(P)}}function Pf(f,x){if(!f?.startsWith("Bearer "))return!1;let P=Buffer.from(f.slice(7)),V=Buffer.from(x);return P.length===V.length&&o(P,V)}async function Wf(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(){}},P=a(32).toString("hex"),V=f.timeoutMs??90000,J=f.receiptTimeoutMs??2000,K=!1,H=new Set,B=s((z,G)=>{z.setTimeout(V,()=>{z.socket.destroy()}),M(z,G)});B.on("connection",(z)=>{H.add(z),z.once("close",()=>H.delete(z))}),B.requestTimeout=J,B.headersTimeout=J;async function M(z,G){let F=(X,W,C={})=>{if(G.headersSent||G.writableEnded||G.destroyed)return;G.writeHead(X,{"content-type":"application/json",...C}),G.end(JSON.stringify(W))};try{let X=new URL(z.url??"/","http://127.0.0.1").pathname;if(z.method==="GET"&&X==="/health")return F(200,{ok:!0});if(z.method!=="POST"||!X.startsWith("/rpc/"))return F(404,{error:"not found"});if(!Pf(z.headers.authorization,P))return F(401,{error:"unauthorized"});let W=X.slice(5),C;try{C=await ff(z)}catch(Y){if(!(Y instanceof E))throw Y;let Z=z.socket;if(G.once("finish",()=>{Z.end();let $=setTimeout(()=>Z.destroy(),2000);if($.unref(),z.once("end",()=>Z.destroy()),Z.once("close",()=>clearTimeout($)),z.complete)Z.destroy()}),!Y.declaredOversize&&!z.complete){if(G.headersSent||G.writableEnded||G.destroyed)return;let $=JSON.stringify({error:"body too large"});G.writeHead(413,{"content-type":"application/json","content-length":Buffer.byteLength($),connection:"close"}),G.write($),z.once("end",()=>G.end());return}return F(413,{error:"body too large"},{connection:"close"})}let Q;try{Q=JSON.parse(C||"{}")}catch{return F(400,{error:"invalid json"})}if(W==="pending-notifications"){let Y;try{if(f.parsePending)Y=f.parsePending(Q);else{if(!Q||typeof Q!=="object"||Array.isArray(Q))throw Error("invalid params");let L=Q;if(f.requireSession===!0&&!S(L.sessionId))return F(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");Y={lastReceivedId:Number(L.lastReceivedId??0),sessionId:typeof L.sessionId==="string"?L.sessionId:void 0}}}catch(L){if(L instanceof b)throw L;return F(400,{error:"invalid params"})}let{lastReceivedId:Z,sessionId:$}=Y;if(f.requireSession===!0&&!S($))return F(400,{error:"session required"});if($===void 0&&!K)K=!0,x.warn("rpc notification drain missing session id",{pid:process.pid});let N;if(f.drainAsync)try{N=await f.drainAsync(Z,$)}catch(L){return x.warn("rpc notification drain failed",{pid:process.pid,error:L instanceof Error?L.message:String(L)}),F(500,{error:"drain failed"})}else N=f.drain?.(Z,$);return F(200,{messages:N})}if(W==="apply"){let Y=Promise.resolve(f.apply(Q)),Z=f.applyDeadlineMs===void 0?await Y:await xf(Y,f.applyDeadlineMs);return F(200,Z)}return F(404,{error:"unknown method"})}catch(X){if(X instanceof b)return x.debug("rpc request refused",{pid:process.pid,status:X.status}),F(X.status,{error:X.message});if(X instanceof h)return x.warn("rpc apply deadline exceeded",{pid:process.pid,deadlineMs:f.applyDeadlineMs}),F(504,{error:"handler deadline exceeded"});x.warn("rpc request failed",{pid:process.pid,error:X instanceof Error?X.message:String(X)}),F(500,{error:"internal error"})}}let A=await new Promise((z,G)=>{B.on("error",G),B.listen(0,"127.0.0.1",()=>{let F=B.address();if(F&&typeof F==="object")z(F.port);else G(Error("no port"))})});if(B.unref(),f.sweepRoot)try{await q(f.sweepRoot,f.dir,f.isManagedDir,x)}catch(z){x.warn("rpc state sweep failed",{pid:process.pid,error:z instanceof Error?z.message:String(z)})}try{await T(f.dir,{port:A,token:P,pid:process.pid},{secureDir:f.secureDir}),x.debug("rpc server pid",{pid:process.pid,rpcPort:A})}catch(z){throw await new Promise((G)=>B.close(()=>G())),z}return{port:A,token:P,async stop(){await new Promise((F)=>{B.closeAllConnections?.(),B.close(()=>F());for(let X of H)X.destroy()});let z=e(f.dir,`port-${process.pid}.json`),G=await I(z).then((F)=>JSON.parse(F)).catch((F)=>{if(F instanceof v&&F.code!=="ENOENT")throw F;return});if(G?.port===A&&G.token===P)await r(z).catch(()=>{})}}}async function Mf(f,x,P){let V=globalThis,J=Symbol.for(f),K=V[J]??{servers:new Map,pending:new Map};V[J]=K;let{servers:H,pending:B}=K,M=B.get(x)??Promise.resolve(),A,z=M.catch(()=>{}).then(async()=>{let F=H.get(x);if(F){if(await F.stop(),H.get(x)===F)H.delete(x)}A=await P(),H.set(x,A)});B.set(x,z);try{await z}finally{if(B.get(x)===z)B.delete(x)}let G=A;if(!G)throw Error("RPC server failed to start");return{server:G,release:async()=>{if(H.get(x)!==G)return;if(await G.stop(),H.get(x)===G)H.delete(x)}}}var p="1.23.0";function wf(f,x,P){let V={...x,version:p};return T(f,V,P)}var qf=R(t);
2
+ export{Vf as Rg,Bf as Sg,Ff as Tg,Wf as Ug,Mf as Vg,p as Wg,wf as Xg,qf as Yg};