@cortexkit/opencode-openai-auth 1.3.0 → 1.4.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 +8 -8
- package/dist/{codex-request-B9D0e97Q.d.ts → codex-request-hw0XcldE.d.ts} +27 -27
- package/dist/index-1eq2s1cp.js +2 -0
- package/dist/{index-m3ctrabv.js → index-1tdnrt68.js} +1 -1
- package/dist/{index-8x1aj7q3.js → index-5230x6s8.js} +2 -2
- package/dist/{index-gn2b097f.js → index-ag04nyv7.js} +7 -7
- package/dist/index-brbqqer5.js +90 -0
- package/dist/{index-xwvze96g.js → index-d98f1xdp.js} +1 -1
- package/dist/index-jcyrm58f.js +65 -0
- package/dist/{index-2pgkrebq.js → index-rsvnabbe.js} +2 -2
- package/dist/{index-ftkhhr6d.js → index-s88n2bjn.js} +1 -1
- package/dist/{index-bc89akak.js → index-t5m0dhmq.js} +1 -1
- package/dist/index-vy729a0b.js +69 -0
- package/dist/index-wgwze391.js +2 -0
- package/dist/{index-tddr876f.js → index-yhw3hnsh.js} +2 -2
- package/dist/index.d.ts +11 -3
- package/dist/index.js +1 -1
- package/dist/{model-BdITTmeb.d.ts → model-DphbMQce.d.ts} +1 -1
- package/dist/{port-file-DbHIVC9a.d.ts → port-file-Cx-wwe5Q.d.ts} +1 -1
- package/dist/{protocol-MysYPAho.d.ts → protocol-CDqdjh74.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-CVSok7zv.d.ts → sidebar-state-pTd9gg9W.d.ts} +55 -7
- package/dist/sidebar-state.d.ts +2 -2
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-z6qq7a1d.js → token-0z5g59p8.js} +1 -1
- package/dist/token-util-jf9g6stk.js +1 -0
- package/dist/tui-preferences.js +1 -1
- package/dist/tui.d.ts +30 -3
- package/dist/v2/server.d.ts +2 -2
- package/dist/v2/server.js +2 -2
- package/package.json +4 -4
- package/src/tui-compiled/raw/shared/0332701351b3eeec-format.js +50 -5
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +70 -1
- package/src/tui-compiled/raw/shared/169b2b4bf30909bc-consumer.js +88 -61
- package/src/tui-compiled/raw/shared/2577ec69f9973ae9-quota-normalize.js +45 -1
- package/src/tui-compiled/raw/shared/30f5bc480f31f51c-roster.js +100 -43
- package/src/tui-compiled/raw/shared/39c3cb05738fcf6d-projection.js +3 -1
- package/src/tui-compiled/raw/shared/42ae93ab554fcec2-open-url.js +7 -9
- package/src/tui-compiled/raw/shared/4825e03209d6ae3e-with-lock.js +2 -0
- package/src/tui-compiled/raw/shared/4f36d333d081d040-merge.js +17 -3
- package/src/tui-compiled/raw/shared/81dddd203f1b92a3-quota-writer.js +253 -0
- package/src/tui-compiled/raw/shared/905bffc0220f43d0-map.js +31 -6
- package/src/tui-compiled/raw/shared/abd062d633e29fd2-pool-routing.js +116 -12
- package/src/tui-compiled/raw/shared/bfbdd0f9aae56b47-pool-quota.js +15 -3
- package/src/tui-compiled/raw/shared/d0f0b6be200311af-insula.js +64 -2
- package/src/tui-compiled/raw/shared/d5a8f1061ee2f114-index.js +2 -2
- package/src/tui-compiled/raw/shared/dbc61cd405941828-accounts.js +5 -4
- package/src/tui-compiled/raw/shared/dc9290c2a7552ba6-watch.js +2 -1
- package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +1 -0
- package/src/tui-compiled/raw/sidebar-state.js +32 -3
- package/src/tui-compiled/raw/tui/v2-dialog.js +2 -1
- package/src/tui-compiled/raw/tui.tsx +170 -26
- package/src/tui-compiled/runtime/shared/0332701351b3eeec-format.js +50 -5
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +70 -1
- package/src/tui-compiled/runtime/shared/169b2b4bf30909bc-consumer.js +88 -61
- package/src/tui-compiled/runtime/shared/2577ec69f9973ae9-quota-normalize.js +45 -1
- package/src/tui-compiled/runtime/shared/30f5bc480f31f51c-roster.js +100 -43
- package/src/tui-compiled/runtime/shared/39c3cb05738fcf6d-projection.js +3 -1
- package/src/tui-compiled/runtime/shared/42ae93ab554fcec2-open-url.js +7 -9
- package/src/tui-compiled/runtime/shared/4825e03209d6ae3e-with-lock.js +2 -0
- package/src/tui-compiled/runtime/shared/4f36d333d081d040-merge.js +17 -3
- package/src/tui-compiled/runtime/shared/81dddd203f1b92a3-quota-writer.js +253 -0
- package/src/tui-compiled/runtime/shared/905bffc0220f43d0-map.js +31 -6
- package/src/tui-compiled/runtime/shared/abd062d633e29fd2-pool-routing.js +116 -12
- package/src/tui-compiled/runtime/shared/bfbdd0f9aae56b47-pool-quota.js +15 -3
- package/src/tui-compiled/runtime/shared/d0f0b6be200311af-insula.js +64 -2
- package/src/tui-compiled/runtime/shared/d5a8f1061ee2f114-index.js +2 -2
- package/src/tui-compiled/runtime/shared/dbc61cd405941828-accounts.js +5 -4
- package/src/tui-compiled/runtime/shared/dc9290c2a7552ba6-watch.js +2 -1
- package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +1 -0
- package/src/tui-compiled/runtime/sidebar-state.js +32 -3
- package/src/tui-compiled/runtime/tui/v2-dialog.js +2 -1
- package/src/tui-compiled/runtime/tui.js +350 -219
- package/dist/index-1mbgsxsr.js +0 -2
- package/dist/index-4v2fs42x.js +0 -65
- package/dist/index-ex6nx3mq.js +0 -2
- package/dist/index-psjyexj3.js +0 -69
- package/dist/index-tn8x5tz8.js +0 -90
- package/dist/token-util-cf0nyh7n.js +0 -1
package/dist/bin.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{c as _0}from"./index-
|
|
3
|
-
`);return b<0?"":G.slice(b+1)}class d extends Error{step="pi-install";exitCode;signal;stderrTail;constructor(G){super(y0);this.name="SetupCommandError",this.exitCode=G.exitCode,this.signal=G.signal;let b=G.stderrTruncated?E0(G.stderrTail):G.stderrTail,z=e(b);this.stderrTail=v0(typeof z==="string"?z:"")}}var f0={opencode:"OpenCode",pi:"Pi"},g0={enrolled:"connected to the vault","not-enrolled":"not connected",unknown:"unknown, check with ck auth status"};function G0({host:G,outcome:b}){return`${f0[G]}: ${g0[b]}`}var d0=new WeakMap;function b0(G,b){if(typeof G!=="object"&&typeof G!=="function"||!G)return;d0.set(G,Object.freeze(b.map((z)=>Object.freeze({...z}))))}import{accessSync as p0,constants as l0,existsSync as a0,readFileSync as i0,realpathSync as s0,statSync as r0}from"node:fs";import{mkdtemp as n0,rm as o0}from"node:fs/promises";import{tmpdir as t0}from"node:os";import{join as e0}from"node:path";import{parse as
|
|
2
|
+
import{c as _0}from"./index-1tdnrt68.js";import{Cb as I0,Fa as j0,Ga as E,Ha as O,Ia as v,kb as A0,ta as k0,ua as f,va as o}from"./index-vy729a0b.js";import{cd as R0,jd as m,kd as L,md as c,nd as q0}from"./index-brbqqer5.js";import"./index-ag04nyv7.js";import{Je as e,Pe as Y0,Qe as C0,Te as w0}from"./index-wgwze391.js";import"./index-5230x6s8.js";import"./index-d98f1xdp.js";import{spawn as P0}from"node:child_process";var M=4096,S0=1048576;class t{buffer=Buffer.alloc(M);start=0;length=0;truncated=!1;get didTruncate(){return this.truncated}push(G){if(G.length>=M){if(G.length>M||this.length>0)this.truncated=!0;G.copy(this.buffer,0,G.length-M),this.start=0,this.length=M;return}let b=Math.max(0,this.length+G.length-M);if(b>0)this.truncated=!0;this.start=(this.start+b)%M,this.length-=b;let z=(this.start+this.length)%M,K=Math.min(G.length,M-z);if(G.copy(this.buffer,z,0,K),K<G.length)G.copy(this.buffer,0,K);this.length+=G.length}toString(){let G=Buffer.alloc(this.length),b=Math.min(this.length,M-this.start);if(this.buffer.copy(G,0,this.start,this.start+b),b<this.length)this.buffer.copy(G,b,0,this.length-b);let z=0;while(z<G.length){let K=G[z];if(K===void 0||(K&192)!==128)break;z++}return G.subarray(z).toString("utf8")}}var A={run(G,b,z={}){return new Promise((K)=>{let J=performance.now(),Q=z.timeoutMs??15000,$=new t,q=[],U=0,Z=!1,D=!1,W=!1,F;try{F=P0(G,[...b],{env:z.env??process.env,windowsHide:!0,windowsVerbatimArguments:z.windowsVerbatimArguments,stdio:["ignore","pipe","pipe"]})}catch{K({exitCode:1,stdout:"",stderr:"",spawnError:!0,signal:null,timedOut:!1,durationMs:performance.now()-J});return}let x=Q>0?setTimeout(()=>{W=!0,F.kill("SIGTERM")},Q):void 0;F.stdout?.on("data",(j)=>{let R=S0-U,V=Math.min(R,j.length);if(V>0)q.push(j.subarray(0,V)),U+=V;if(j.length>R)Z=!0,F.kill("SIGTERM")}),F.stderr?.on("data",(j)=>$.push(j));let X=!1,B=(j,R)=>{if(X)return;if(X=!0,x)clearTimeout(x);K({exitCode:D?1:Z?1:j??1,stdout:Buffer.concat(q,U).toString("utf8"),stderr:$.toString(),stderrTruncated:$.didTruncate,...D?{spawnError:!0}:{},signal:R??null,timedOut:W,durationMs:performance.now()-J})};F.once("error",()=>{if(D=!0,F.pid===void 0)B(null,null)}),F.once("close",(j,R)=>B(j,R))})}};function g(G,b,z,K,J,Q=15000){if(b==="win32"&&/\.(cmd|bat)$/i.test(z)){if(/["%!\r\n]/.test(z)||K.some(($)=>!/^[a-zA-Z0-9@:/._+-]+$/.test($)))throw Error("Unsafe batch launcher or argument; use an executable instead.");return G.run("cmd.exe",["/d","/s","/c",`""${z}" ${K.join(" ")}"`],{env:J,timeoutMs:Q,windowsVerbatimArguments:!0})}return G.run(z,K,{env:J,timeoutMs:Q})}var y0="Pi install failed; run pi install after checking your npm connection.";function v0(G){let b=Buffer.from(G,"utf8");if(b.length<=M)return G;let z=b.length-M;while(z<b.length){let K=b[z];if(K===void 0||(K&192)!==128)break;z++}return b.subarray(z).toString("utf8")}function E0(G){let b=G.indexOf(`
|
|
3
|
+
`);return b<0?"":G.slice(b+1)}class d extends Error{step="pi-install";exitCode;signal;stderrTail;constructor(G){super(y0);this.name="SetupCommandError",this.exitCode=G.exitCode,this.signal=G.signal;let b=G.stderrTruncated?E0(G.stderrTail):G.stderrTail,z=e(b);this.stderrTail=v0(typeof z==="string"?z:"")}}var f0={opencode:"OpenCode",pi:"Pi"},g0={enrolled:"connected to the vault","not-enrolled":"not connected",unknown:"unknown, check with ck auth status"};function G0({host:G,outcome:b}){return`${f0[G]}: ${g0[b]}`}var d0=new WeakMap;function b0(G,b){if(typeof G!=="object"&&typeof G!=="function"||!G)return;d0.set(G,Object.freeze(b.map((z)=>Object.freeze({...z}))))}import{accessSync as p0,constants as l0,existsSync as a0,readFileSync as i0,realpathSync as s0,statSync as r0}from"node:fs";import{mkdtemp as n0,rm as o0}from"node:fs/promises";import{tmpdir as t0}from"node:os";import{join as e0}from"node:path";import{parse as G2}from"jsonc-parser";import{homedir as m0}from"node:os";import{posix as c0,win32 as h0}from"node:path";import{fileURLToPath as u0}from"node:url";function N(G={}){let b=G.env??process.env,z=G.platform??process.platform,K=z==="win32"?h0:c0,J=G.home??(z==="win32"?b.USERPROFILE:b.HOME)??m0(),Q=G.cwd??process.cwd(),$=(D)=>K.resolve(Q,D),q=b.OPENCODE_CONFIG_DIR?.trim(),U=b.XDG_CONFIG_HOME?.trim(),Z=b.PI_CODING_AGENT_DIR?.trim()||K.join(J,".pi","agent");if(Z==="~")Z=J;else if(/^~[/\\]/.test(Z))Z=K.join(J,Z.slice(2));if(Z.startsWith("file://"))Z=u0(Z);return{env:b,platform:z,path:K,home:J,cwd:Q,opencode:q?$(q):U?K.join($(U),"opencode"):K.join(J,".config","opencode"),pi:$(Z)}}function h(G,b){try{return r0(G)[b]()}catch{return!1}}var _={exists:a0,isFile:(G)=>h(G,"isFile"),isDirectory:(G)=>h(G,"isDirectory"),isExecutable(G){try{return p0(G,l0.X_OK),h(G,"isFile")}catch{return!1}},readText:(G)=>i0(G,"utf8"),realpath:s0};function k(G,b={}){let{env:z,platform:K,path:J,cwd:Q}=N(b),$=b.fs??_,q=Object.entries(z).find(([Z])=>K==="win32"?Z.toUpperCase()==="PATH":Z==="PATH")?.[1]??"",U=K==="win32"?[".exe",".cmd",".bat",""]:[""];for(let Z of q.split(K==="win32"?";":":")){let D=Z.trim().replace(/^"|"$/g,"");if(!D)continue;for(let W of U){let F=J.resolve(Q,D,G+W);if(K==="win32"?$.isFile(F):$.isExecutable(F))return F}}return null}function z0(G={}){let{platform:b,home:z,env:K,path:J}=N(G);if(b==="darwin")return["/Applications/OpenCode.app","/Applications/OpenCode Beta.app",J.join(z,"Applications","OpenCode.app"),J.join(z,"Applications","OpenCode Beta.app")];if(b==="win32"){let Q=K.LOCALAPPDATA||J.join(z,"AppData","Local");return[J.join(Q,"Programs","opencode"),J.join(Q,"opencode")]}return["/opt/OpenCode","/usr/lib/opencode",J.join(z,".local","share","applications","opencode.desktop")]}function u(G,b){let z=b.fs??_,{path:K}=N(b);try{let J=z.readText(G);if(J.length>65536)return G;let Q=[...J.matchAll(/"%~?dp0%?\\([^"%\r\n]+)"/g)];if(!Q.length)Q.push(...J.matchAll(/"\$basedir\/([^"$\r\n]+)"/g));let $=Q.at(-1)?.[1];if($){let q=K.join(K.dirname(G),...$.split(/[/\\]+/));if(z.isFile(q))return z.realpath(q)}return z.realpath(G)}catch{return G}}function b2(G,b){let z=b.fs??_,{path:K}=N(b),J=K.dirname(u(G,b));for(;;){try{let $=JSON.parse(z.readText(K.join(J,"package.json")));if(["@opencode/cli","@opencode-ai/cli"].includes($.name))return"2";if($.name==="opencode-ai")return/^(?:[2-9]\d*|1\d+)\.|^0\.0\.0-(?:beta|dev)-/.test($.version??"")?"2":"1"}catch{}let Q=K.dirname(J);if(Q===J)return null;J=Q}}function J0(G={}){let b=k("opencode",G),z=k("opencode2",G),K=b&&z&&u(b,G)===u(z,G),J=G.fs??_,{path:Q,opencode:$}=N(G),q="1";for(let Z of["jsonc","json"]){let D=Q.join($,`opencode.${Z}`);if(!J.exists(D))continue;try{if(Object.hasOwn(G2(J.readText(D))??{},"plugins"))q="2"}catch{}break}let U=b?b2(b,G)??(K?"2":q):null;if(z&&U==="1"&&!K)return"ambiguous";return z||K?"2":U??q}async function p(G,b={}){let z=b.fs??_,{env:K,platform:J,opencode:Q,pi:$}=N(b),q=b.runner??A,U=k("opencode",b)??k("opencode2",b),Z=k("pi",b),D=k("ck",b),W=async(B)=>{if(!B)return null;let j;try{j=await n0(e0(t0(),"common-auth-setup-version-"));let R={...K,HOME:j,USERPROFILE:j,XDG_CONFIG_HOME:j,XDG_DATA_HOME:j,XDG_STATE_HOME:j,XDG_CACHE_HOME:j,OPENCODE_CONFIG_DIR:j,OPENCODE_CONFIG:void 0,OPENCODE_CONFIG_CONTENT:void 0,OPENCODE_AUTH_CONTENT:void 0,PI_CODING_AGENT_DIR:j},V=await g(q,J,B,["--version"],R,2000);return V.exitCode===0?/\b\d+\.\d+\.\d+(?:-[\w.-]+)?/.exec(V.stdout)?.[0]??null:null}catch{return null}finally{if(j)await o0(j,{recursive:!0,force:!0}).catch(()=>{})}},F=!1;if(D&&z.exists(G.vault.connectionFile))try{(await(b.connect??m)({connectionFile:G.vault.connectionFile,handshakeTimeoutMs:2000})).close(),F=!0}catch{F=!1}let[x,X]=await Promise.all([W(U),W(Z)]);return{opencode:{installed:z.isDirectory(Q)||z0(b).some((B)=>z.exists(B))||U!==null,executable:U,version:x,directory:Q,generation:J0(b)},pi:{installed:Z!==null||z.isDirectory($),executable:Z,version:X,directory:$},claustrum:{available:F,executable:D}}}import{setTimeout as U2}from"node:timers/promises";import{writeEnrollmentTokenFile as W2}from"@cortexkit/claustrum-client";var z2=45000,K0=new Set(["opencode","litecode","opencode2","pi"]),J2=new Set(["node","bun"]),K2=/(?:^|[/\\])pi-coding-agent[/\\]dist[/\\](?:(?:bundle|bun)[/\\])?cli\.m?js$/i;function Q2(G){return[...G.matchAll(/"([^"]*)"|(\S+)/g)].map((b)=>b[1]??b[2]??"")}function Q0(G){return(G.split(/[/\\]/).pop()??"").toLowerCase().replace(/\.(?:exe|cmd|bat|m?js)$/,"")}var Z2=new Set(["-r","--require","--import","--loader","--experimental-loader","-C","--conditions","--env-file","--title","--input-type","--preload","--cwd","-c","--config","--tsconfig-override","-d","--define","-l","--main-fields"]),$2=new Set(["-e","--eval","-p","--print"]);function q2(G,b){for(let z=0;z<b.length;z++){let K=b[z]??"";if(K==="--")return b[z+1];if($2.has(K))return;if(K.startsWith("-")){if(!K.includes("=")&&Z2.has(K))z++;continue}if(G==="bun"&&K==="run")continue;return K}return}function Z0(G){let[b,...z]=Q2(G);if(b===void 0)return null;let K=Q0(b);if(K0.has(K))return K;if(!J2.has(K))return null;let J=q2(K,z);if(J===void 0)return null;let Q=Q0(J);if(K0.has(Q))return Q;return K2.test(J)?"pi":null}class Y extends Error{code="process-inspection-failed";step;exitCode;signal;timedOut;durationMs;constructor(G){super("Process inspection failed; setup cannot prove hosts are stopped.");this.name="ProcessInspectionError",this.step=G.step,this.exitCode=G.exitCode,this.signal=G.signal,this.timedOut=G.timedOut,this.durationMs=G.durationMs}get refusalText(){let G=this.timedOut?"timed out":this.signal?`signal ${this.signal}`:this.exitCode===null?"could not start or complete":this.exitCode===0?"invalid output (exit code 0)":`exit code ${this.exitCode}`;return`${this.message} ${this.step}: ${G} after ${Math.round(this.durationMs)} ms.`}}class T extends Error{activeHosts;constructor(G){let b=G.map((z)=>({pid:z.pid,command:Z0(z.command)??"host"}));super(`OpenCode or Pi processes are currently running:
|
|
4
4
|
${b.map((z)=>` - PID ${z.pid}: ${z.command}`).join(`
|
|
5
5
|
`)}
|
|
6
6
|
|
|
7
|
-
Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);this.activeHosts=b,this.name="ProcessFenceViolationError"}}async function l(G=A,b={}){let z=(b.platform??process.platform)==="win32",J={step:z?"tasklist":"ps",exitCode:null,signal:null,timedOut:!1,durationMs:0},
|
|
7
|
+
Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);this.activeHosts=b,this.name="ProcessFenceViolationError"}}async function l(G=A,b={}){let z=(b.platform??process.platform)==="win32",K=b.selfPid??process.pid,J={step:z?"tasklist":"ps",exitCode:null,signal:null,timedOut:!1,durationMs:0},Q=async($,q,U,Z)=>{let D=performance.now();J={step:$,exitCode:null,signal:null,timedOut:!1,durationMs:0};try{let W=await G.run(q,U,{env:b.env,timeoutMs:Z});return J={step:$,exitCode:W.exitCode,signal:W.signal??null,timedOut:W.timedOut??!1,durationMs:W.durationMs??performance.now()-D},W}finally{if(J.exitCode===null)J.durationMs=performance.now()-D;b.onStep?.({...J})}};try{let $=await Q(z?"tasklist":"ps",z?"tasklist.exe":"ps",z?["/fo","csv","/nh"]:["-eo","pid,command"]);if($.exitCode!==0)throw new Y(J);let q=[];for(let Z of $.stdout.split(/\r?\n/)){let D=Z.trim();if(!D)continue;let W,F;if(z){let x=/^"([^"]+)","(\d+)"(?:,|$)/.exec(D);if(!x)throw new Y(J);F=x[1]??"",W=Number(x[2])}else{let x=/^(\d+)\s+(.+)$/.exec(D);if(!x){if(/^PID\s+COMMAND$/i.test(D))continue;throw new Y(J)}W=Number(x[1]),F=x[2]??""}if(!Number.isSafeInteger(W)||W<0)throw new Y(J);q.push({pid:W,command:F})}if(!q.length)throw new Y(J);let U=q.filter((Z)=>Z.pid!==K&&/^(?:node|bun)\.exe$/i.test(Z.command));if(z&&U.length&&b.inspectRuntimes!==!1){let Z=await Q("CIM","powershell.exe",["-NoProfile","-NonInteractive","-Command",`$ErrorActionPreference = 'Stop'; Get-CimInstance Win32_Process -Filter "Name = 'node.exe' OR Name = 'bun.exe'" | Select-Object ProcessId,CommandLine | ConvertTo-Json -Compress`],z2);if(Z.exitCode!==0)throw new Y(J);let D=JSON.parse(Z.stdout||"null"),W=D===null?[]:Array.isArray(D)?D:[D],F=new Map;for(let x of W){if(!x||typeof x!=="object"||!("ProcessId"in x)||!("CommandLine"in x)||!Number.isSafeInteger(x.ProcessId))throw new Y(J);if(typeof x.CommandLine==="string")F.set(Number(x.ProcessId),x.CommandLine);else if(U.some((X)=>X.pid===x.ProcessId))throw new Y(J)}for(let x of U)x.command=F.get(x.pid)??""}return q}catch($){if($ instanceof Y)throw $;throw new Y(J)}}function S(G=A,b={}){let z=b.selfPid??process.pid,K=(J)=>J.pid!==z&&Z0(J.command)!==null;return{async listRunningHosts(J){return(await l(G,{...b,env:J})).filter(K)},async previewRunningHosts(J){let Q=await l(G,{...b,env:J,inspectRuntimes:!1}),$=(b.platform??process.platform)==="win32";return{hosts:Q.filter(K),uncheckedRuntimes:$?Q.filter((q)=>q.pid!==z&&/^(?:node|bun)\.exe$/i.test(q.command)).length:0}}}}async function y(G,b){let z=await G.listRunningHosts(b);if(z.length)throw new T(z)}var $0="Claustrum enrollment did not complete. Inspect and approve with ck, then rerun setup.";class I extends Error{}async function U0(G,b,z,K,J){let{name:Q,paths:$}=G.vault.hosts[b],q=L($);await J();let U=await(z.connect??m)({connectionFile:G.vault.connectionFile,handshakeTimeoutMs:2000}).catch(()=>{throw new I("Claustrum connection failed; start ck and rerun setup.")});try{let Z=new q0({proposedName:Q,paths:q,client:{enrollPropose:async(W)=>{return await J(),U.enrollPropose(W)},enrollPoll:async(W)=>{return await J(),U.enrollPoll(W)}},writeTokenFile:async(W,F)=>{await J(),await W2(W,F)}}),D;for(let W=0;W<300;W++){await J();let F=await Z.reconcile();if(F.state==="approved"){O(K,`Connected ${b} to Claustrum.`);return}if(F.state!=="pending"&&F.state!=="busy")throw new I("Claustrum enrollment refused; inspect its status with ck before rerunning setup.");if(F.state==="pending"&&F.requestId&&F.requestId!==D){if(!/^[a-zA-Z0-9_-]+$/.test(F.requestId))throw new I("Invalid enrollment request id.");D=F.requestId,O(K,"Waiting for approval. In another terminal, run:"),O(K,` ck auth enroll approve --request-id ${F.requestId} --name ${Q}`),O(K,`Enrollment files: ${q.statePath}, ${q.tokenPath}`)}await(z.wait??U2)(1000)}throw new I("Claustrum approval is still pending; approve with ck and rerun setup.")}catch(Z){if(Z instanceof T||Z instanceof Y)throw Z;if(Z instanceof I)throw new I($0);throw Error($0)}finally{U.close()}}async function W0(G,b){let z=new Set(b);for(;;){let K=await v(G,[...["opencode","pi"].map((J)=>({value:J,label:`[${z.has(J)?"x":" "}] ${J==="opencode"?"OpenCode":"Pi"}`,hint:b.includes(J)?"found":"not found"})),{value:"done",label:"Continue with selected hosts"}],{message:"Select hosts to set up",subtitle:"Enter toggles a host; choose Continue when ready."});if(K===null)return null;if(K==="done")return[...z];if(z.has(K))z.delete(K);else z.add(K)}}import{applyEdits as a,createScanner as H2,findNodeAtLocation as M2,modify as D0,parse as N2,parseTree as R2}from"jsonc-parser";import{randomUUID as x2}from"node:crypto";import{mkdir as D2,open as F2,rename as V2,stat as X2,unlink as j2}from"node:fs/promises";import{basename as O2,dirname as B2,join as Y2}from"node:path";import{setTimeout as C2}from"node:timers/promises";async function x0(G,b,z={}){let K=(z.platform??process.platform)==="win32",J=B2(G);await D2(J,{recursive:!0});let Q;if(!K)try{Q=(await X2(G)).mode&4095}catch(U){if(U.code!=="ENOENT")throw U}let $=Y2(J,`.${O2(G)}.${(z.stageName??x2)()}.tmp`),q=!1;try{let U=await F2($,"wx",Q??438);q=!0;try{if(await U.writeFile(b,"utf8"),Q!==void 0)await U.chmod(Q)}finally{await U.close()}let Z=z.now??(()=>performance.now()),D=Z();for(let W=0;;W++){await z.beforeRename?.();try{await(z.rename??V2)($,G),q=!1;return}catch(F){let x=F.code,X=2000-(Z()-D);if(!K||!["EPERM","EBUSY","EACCES"].includes(x??"")||X<=0||W>=40)throw Error(`Unable to replace host config ${G}. Close editors or other programs using the file, then rerun setup.`);await(z.wait??C2)(Math.min(X,25*2**Math.min(W,2)))}}}finally{if(q)await j2($).catch(()=>{})}}function F0(G){let b=typeof G==="string"?G:Array.isArray(G)?G[0]:G&&typeof G==="object"&&("package"in G)?G.package:null;if(typeof b!=="string")return null;let z=b.indexOf("@",b.startsWith("@")?1:0);return z<0?b:b.slice(0,z)}function V0(G,b,z){let K=R2(G),J=K&&M2(K,[b]),Q=J?.children??[],$=Q[z];if(!$||!J)throw Error("Invalid plugin array edit.");let q=[{offset:$.offset,length:$.length,content:""}],U=(Z,D)=>{let W=H2(G.slice(Z,D),!0);if(W.scan(),G[Z+W.getTokenOffset()]===",")q.push({offset:Z+W.getTokenOffset(),length:1,content:""})};if(z===Q.length-1){let Z=Q[z-1];if(Z)U(Z.offset+Z.length,$.offset);U($.offset+$.length,J.offset+J.length-1)}else U($.offset+$.length,Q[z+1]?.offset??$.offset+$.length);return a(G,q)}function X0(G,b,z,K){let J=[],Q=N2(G,J,{allowTrailingComma:!0});if(J.length||!Q||typeof Q!=="object"||Array.isArray(Q))throw Error("Invalid OpenCode config; refusing to overwrite it.");let $={formattingOptions:{insertSpaces:!/^\t+/m.test(G),tabSize:/^([ ]+)"/m.exec(G)?.[1]?.length??2,eol:G.includes(`\r
|
|
8
8
|
`)?`\r
|
|
9
9
|
`:`
|
|
10
|
-
`}},
|
|
11
|
-
`,
|
|
12
|
-
${
|
|
13
|
-
ck auth grant --principal enrolled:${f(Q)} --selector-kind category --selector ${k0.category} --operation read`),Q==="opencode")b("Then run opencode auth login and choose ChatGPT accounts in the vault to activate vault routing without local sign-in.");return}await
|
|
14
|
-
${
|
|
10
|
+
`}},q=G,U=Q[b];if(U!==void 0&&!Array.isArray(U))throw Error(`OpenCode ${b} must be an array.`);let Z=Array.isArray(U)?[...U]:[],D=Z.flatMap((x,X)=>F0(x)===z?[X]:[]),W=`${z}@${K}`;if(!D.length)q=a(q,D0(q,U===void 0?[b]:[b,Z.length],U===void 0?[W]:W,$));else{let x=D[0],X=Z[x],B=Array.isArray(X)?[W,...X.slice(1)]:X&&typeof X==="object"?{...X,package:W}:W;if(JSON.stringify(X)!==JSON.stringify(B))q=a(q,D0(q,[b,x],B,$));for(let j of D.slice(1).reverse())q=V0(q,b,j)}let F=b==="plugin"?"plugins":"plugin";if(Array.isArray(Q[F])){let x=Q[F];for(let X=x.length-1;X>=0;X--)if(F0(x[X])===z)q=V0(q,F,X)}return q}function i(G,b,z={}){let K=z.fs??_,{path:J,opencode:Q}=N(z),$=b==="2"?"plugins":"plugin";return(b==="2"?["opencode"]:["opencode","tui"]).map((U)=>{let Z=J.join(Q,`${U}.jsonc`),D=J.join(Q,`${U}.json`),W=K.exists(Z)?Z:K.exists(D)?D:Z,F=K.exists(W),x=F?K.readText(W):`${JSON.stringify({$schema:`https://opencode.ai/${U==="tui"?"tui":"config"}.json`},null,2)}
|
|
11
|
+
`,X=X0(x,$,G.packages.opencode,G.version);return{path:W,content:X,changed:!F||X!==x}})}async function s(G,b){for(let z of G){if(!z.changed)continue;await b?.(),await x0(z.path,z.content,{beforeRename:b})}}async function r(G,b,z={}){let{platform:K,env:J}=N(z),Q=await g(z.runner??A,K,b,["install",`npm:${G.packages.pi}@${G.version}`],J);if(Q.exitCode!==0||Q.timedOut)throw new d({exitCode:Q.spawnError?null:Q.exitCode,signal:Q.signal??null,stderrTail:Q.stderr,stderrTruncated:Q.stderrTruncated??!1})}var O0="Multiple OpenCode generations found. Choose --opencode=1|2|both before running noninteractive setup.";function k2(G){let b={yes:!1,dryRun:!1,claustrum:!1,noClaustrum:!1,login:!1,opencode:void 0};for(let z of G)if(z==="--yes")b.yes=!0;else if(z==="--dry-run")b.dryRun=!0;else if(z==="--claustrum")b.claustrum=!0;else if(z==="--no-claustrum")b.noClaustrum=!0;else if(z==="--login")b.login=!0;else if(/^--opencode=(1|2|both)$/.test(z))b.opencode=z.slice(11);else throw Error(`Unknown setup argument: ${z}`);if(b.claustrum&&b.noClaustrum)throw Error("--claustrum and --no-claustrum cannot be used together.");if(b.login&&b.claustrum)throw Error("--login and --claustrum cannot be used together.");return b}function w2(G){for(let b of Object.values(G.packages))if(!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(b))throw Error("Setup requires npm package names.");if(!/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?(?:\+[a-zA-Z0-9.-]+)?$/.test(G.version))throw Error("Setup requires a concrete package version.");for(let b of Object.values(G.vault.hosts))if(!/^[a-z0-9][a-z0-9-]*$/.test(b.name))throw Error("Setup requires lowercase vault names containing only letters, digits and dashes.")}async function A2(G,b,z){let K=[];for(let J of b){let Q=z.get(J)??"not-enrolled";if(Q==="unknown"){let{name:$,paths:q}=G.vault.hosts[J],U=await c(L(q),$).catch(()=>"unreadable");if(U==="vault")Q="enrolled";else if(U==="local")Q="not-enrolled"}K.push({host:J,outcome:Q})}return K}async function n(G,b=[],z={}){let K=k2(b);w2(G);let J=z.terminal??j0(),Q=await p(G,z);O(J,`${G.displayName} setup`);for(let[V,H]of[["OpenCode",Q.opencode],["Pi",Q.pi]])O(J,`${V}: ${H.installed?`found (version ${H.version??"unknown"})`:"not found"} — ${H.directory}`);O(J,`Claustrum: ${Q.claustrum.available?"available":"not available"}`);let $=Q.pi.installed&&!Q.pi.executable;if($)O(J,"Pi: skipped, because its folder exists but pi is not on PATH. Install the Pi CLI and rerun setup to add it.");let q=["opencode","pi"].filter((V)=>Q[V].installed&&!(V==="pi"&&$)),U=K.yes||K.dryRun&&!E(J);if(!U&&!E(J))throw Error("Setup requires a TTY or --yes.");let Z=U?q:await W0(J,q)??[],D=K.opencode??(Q.opencode.generation==="ambiguous"?"1":Q.opencode.generation);if(Z.includes("opencode")&&!K.opencode&&Q.opencode.generation==="ambiguous"){if(U||!E(J))throw Error(O0);let V=await v(J,[{value:"1",label:"OpenCode 1"},{value:"2",label:"OpenCode 2"},{value:"both",label:"Both (one compatible registration)"}],{message:"Which OpenCode generation should be registered?"});if(V===null)return{hosts:[],dryRun:K.dryRun,mode:"local",detection:Q};D=V}if(!Z.length)return O(J,"No hosts selected. Install OpenCode or Pi and rerun setup."),{hosts:Z,dryRun:K.dryRun,mode:"local",detection:Q};let{env:W,platform:F}=N(z),x=z.fence??S(z.runner??A,{platform:F}),X=async()=>{try{await y(x,W)}catch(V){if(V instanceof Y)O(J,V.refusalText);throw V}};if(O(J,"Checking that OpenCode and Pi are not running…"),K.dryRun)try{let V=x.previewRunningHosts?await x.previewRunningHosts(W):{hosts:await x.listRunningHosts(W),uncheckedRuntimes:0},H=V.hosts;if(V.uncheckedRuntimes>0)O(J,"Node or Bun programs are running; a real run checks whether any of them is OpenCode or Pi.");let C=new Set(new T(H).activeHosts.map((w)=>w.command.toLowerCase()==="pi"?"Pi":"OpenCode"));for(let w of C)O(J,`${w} is running; setup will ask you to quit it.`)}catch(V){if(O(J,"Process inspection failed; real setup will require successful inspection and stopped OpenCode/Pi hosts."),V instanceof Y)O(J,V.refusalText)}else await X();if(K.claustrum&&!Q.claustrum.available)throw Error("Claustrum is not available. Start ck or use --no-claustrum for local sign-in.");let B=Boolean(K.claustrum);if(!B&&!K.login&&!K.noClaustrum&&!U&&Q.claustrum.available&&E(J)){let V=await v(J,[{label:"No",value:!1},{label:"Yes",value:!0}],{message:"Connect these hosts to the Claustrum vault?"});if(V===null)return O(J,"Setup cancelled. Nothing was changed."),{hosts:[],dryRun:K.dryRun,mode:"local",detection:Q};B=V===!0}let j=B?"claustrum":"local",R=Z.includes("opencode")?i(G,D,z):[];if(K.dryRun){O(J,"Dry run: no registrations, enrollment, sign-in or migration will be performed.");for(let V of Z){if(G.beforeSignIn)O(J,`Would run beforeSignIn(${V}, ${j}).`);if(B){let H=L(G.vault.hosts[V].paths);O(J,`Would Connect ${V}: write ${H.statePath} and ${H.tokenPath}; wait for ck auth enroll approve.`)}else O(J,`Would sign in locally for ${V}.`);if(G.beforeRegister)O(J,`Would run beforeRegister(${V}, ${j}).`)}for(let V of R)O(J,`${V.changed?"Would write":"Unchanged"} ${V.path}:
|
|
12
|
+
${V.content}`);if(Z.includes("pi"))O(J,`Would run ${Q.pi.executable} install npm:${G.packages.pi}@${G.version}`);for(let V of Z)O(J,`Would migrate ${V} using the plugin callback (provider-specific writes).`)}else{let V={opencodeGeneration:D,mode:j,hosts:Object.freeze([...Z]),piAgentDir:Q.pi.directory},H=new Map;try{for(let C of Z){if(await X(),await G.beforeSignIn?.(C,V),await X(),B){H.set(C,"unknown");try{await U0(G,C,z,J,X)}catch(w){if(w instanceof I)H.set(C,"not-enrolled");throw w}H.set(C,"enrolled")}else await G.signInLocal(C,V);if(await X(),await G.beforeRegister?.(C,j,V),await X(),C==="opencode")await s(R,X);else await r(G,Q.pi.executable,z);await X(),await G.migrate(C,V)}}catch(C){if(H.size===0)throw C;try{let w=await A2(G,Z,H);b0(C,w);for(let L0 of w)O(J,G0(L0))}catch{}throw C}}return O(J,`${K.dryRun?"Planned":"Configured"} ${G.displayName} for ${Z.join(", ")} (${j}).`),O(J,`Next: ${Z.includes("opencode")?"start OpenCode":"start Pi"} and run ${G.slashCommand}.`),{hosts:Z,dryRun:K.dryRun,mode:j,detection:Q}}import{basename as S2}from"node:path";import{resolveClaustrumConnectionPath as y2}from"@cortexkit/claustrum-client";var B0={name:"@cortexkit/pi-openai-auth",version:"1.4.0",license:"MIT",type:"module",repository:{type:"git",url:"git+https://github.com/cortexkit/openai-auth.git",directory:"packages/pi"},main:"./dist/index.js",types:"./dist/index.d.ts",exports:{".":{import:"./dist/index.js",types:"./dist/index.d.ts"}},files:["dist","README.md","LICENSE"],keywords:["pi-package"],pi:{extensions:["./dist/index.js"]},scripts:{build:"rm -rf dist && bun build src/index.ts --outdir dist --target node --format esm --external '@earendil-works/pi-ai' --external '@earendil-works/pi-ai/*' --external '@earendil-works/pi-coding-agent' --external '@earendil-works/pi-coding-agent/*' --external '@earendil-works/pi-tui' --external '@earendil-works/pi-tui/*' --external @cortexkit/private-files --external @cortexkit/claustrum-client --external @cortexkit/subc-client --minify && bun run build:types","build:types":"cd ../core && bun run build && cd ../pi && tsdown --config tsdown.config.ts --config-loader native",test:"bun test src/tests",typecheck:"tsc",types:"tsc",prepublishOnly:"bun run build"},devDependencies:{"@cortexkit/common-auth":"^0.23.0","@cortexkit/openai-auth-core":"workspace:*"},dependencies:{"@cortexkit/claustrum-client":"^0.12.0","@cortexkit/private-files":"^0.2.1","@cortexkit/subc-client":"^0.22.0"},peerDependencies:{"@earendil-works/pi-ai":">=1.0.1","@earendil-works/pi-coding-agent":">=1.0.1","@earendil-works/pi-tui":">=1.0.1"}};import{homedir as _2}from"node:os";import{join as H0}from"node:path";function T2(){return process.env.PI_AGENT_DIR?.trim()||H0(_2(),".pi","agent")}function M0(){return process.env.PI_OPENAI_AUTH_FILE?.trim()||H0(T2(),Y0)}function L2(G=M0()){return process.env.PI_OPENAI_AUTH_STATE_FILE?.trim()||C0(G)}function N0(G=M0()){return{configPath:G,statePath:L2(G)}}var P={name:"@cortexkit/opencode-openai-auth",version:"1.4.0",license:"MIT",type:"module",repository:{type:"git",url:"git+https://github.com/cortexkit/openai-auth.git",directory:"packages/opencode"},main:"./dist/index.js",types:"./dist/index.d.ts",bin:{"opencode-openai-auth":"./dist/bin.js"},exports:{".":{import:"./dist/index.js",types:"./dist/index.d.ts"},"./tui":{types:"./dist/tui.d.ts",import:"./src/tui/entry.mjs"},"./tui-prefs":{types:"./dist/tui-preferences.d.ts",import:"./dist/tui-preferences.js"},"./server":{types:"./dist/v2/server.d.ts",import:"./dist/v2/server.js"}},"oc-plugin":["server","tui"],engines:{bun:"1.3.14"},files:["dist","src/tui/entry.mjs","src/tui-compiled","README.md","LICENSE"],scripts:{build:"rm -rf dist && bun build src/index.ts src/v2/server.ts src/sidebar-state.ts src/tui-preferences.ts src/rpc/rpc-client.ts src/rpc/port-file.ts src/rpc/protocol.ts src/rpc/rpc-dir.ts src/bin.ts --root src --outdir dist --target node --format esm --splitting --external @opencode-ai/plugin --external @opencode/plugin --external @cortexkit/private-files --external jsonc-parser --external @cortexkit/claustrum-client --external @cortexkit/subc-client --minify && bun run build:types && bun run build:tui","build:tui":"bun scripts/build-tui.ts","build:types":"cd ../core && bun run build && cd ../opencode && tsdown --config tsdown.config.ts --config-loader native","build:dev":"rm -rf dist && tsc -p tsconfig.build.json",test:"bun test src/tests",typecheck:"tsc",types:"tsc",prepublishOnly:"bun run build"},peerDependencies:{"@opencode-ai/plugin":"*","@opencode/plugin":">=2.0.21"},peerDependenciesMeta:{"@opencode/plugin":{optional:!0}},devDependencies:{"@ai-sdk/openai":"3.0.88","@cortexkit/common-auth":"^0.23.0","@cortexkit/openai-auth-core":"workspace:*","@opencode/plugin":"2.0.32"},dependencies:{"@cortexkit/claustrum-client":"^0.12.0","@cortexkit/private-files":"^0.2.1","@cortexkit/subc-client":"^0.22.0","@opentui/core":">=0.6.1","@opentui/solid":">=0.6.1",ai:"^7.0.143","jsonc-parser":"^3.3.1","solid-js":"1.9.12"}};function T0(G={}){let b=G.print??console.log,z=G.fence??S(),K={opencode:{stateDir:o(A0().statePath),host:"opencode"},pi:{stateDir:o(N0().statePath),host:"pi"}},J=async(Q)=>{if(await c(L(K[Q]),f(Q))!=="local")throw Error(`${Q} is enrolled in Claustrum or its enrollment is unreadable. Disconnect it from the vault before using local sign-in.`)};return{packages:{opencode:P.name,pi:B0.name},version:P.version,displayName:"OpenAI Auth",slashCommand:"/openai",vault:{connectionFile:y2(),hosts:{opencode:{name:f("opencode"),paths:K.opencode},pi:{name:f("pi"),paths:K.pi}}},async beforeRegister(Q,$){if($==="claustrum"){if(b(`Allow this host to read OpenAI accounts with:
|
|
13
|
+
ck auth grant --principal enrolled:${f(Q)} --selector-kind category --selector ${k0.category} --operation read`),Q==="opencode")b("Then run opencode auth login and choose ChatGPT accounts in the vault to activate vault routing without local sign-in.");return}await J(Q)},async signInLocal(Q,$){if(await J(Q),Q==="pi"){b("Start Pi and run /login openai-codex to sign in with Pi itself.");return}if($.opencodeGeneration!=="1"){let j=S2(k("opencode2",G.io)??k("opencode",G.io)??"opencode");b(`In OpenCode 2, run ${j} auth login openai and choose "ChatGPT (openai-auth pool, browser)" or "ChatGPT (openai-auth pool, headless)" to sign in to the account pool and activate it.`)}if($.opencodeGeneration==="2")return;if(I0(process.env))throw Error("Unset OPENCODE_AUTH_CONTENT before local setup sign-in.");let q=_0(),U={path:{id:"openai"}};if(await q.get(U)!==void 0){b("OpenCode already has an OpenAI login. Use opencode auth login to change it.");return}let Z=G.beginLogin??R0,D=new AbortController,W=Boolean(process.env.SSH_CONNECTION||process.env.SSH_TTY||process.platform==="linux"&&!process.env.DISPLAY&&!process.env.WAYLAND_DISPLAY),F={version:P.version,signal:D.signal},x,X=!W;try{x=await Z({...F,headless:W})}catch(j){if(W)throw j;X=!1,b("Browser callback unavailable; using device-code sign-in."),x=await Z({version:P.version,headless:!0})}if(X){if(!(G.openBrowser??w0)(x.url))D.abort(),await x.completion.catch(()=>{}),b("Browser unavailable; using device-code sign-in."),x=await Z({version:P.version,headless:!0})}b(`${x.url}
|
|
14
|
+
${x.instructions}`);let B=await x.completion;await y(z),await J(Q),await q.set({...U,body:{type:"oauth",access:B.access,refresh:B.refresh,expires:B.expires,...B.accountId?{accountId:B.accountId}:{}}}),b("Signed in to OpenCode. The first plugin start adopts this login into the account pool.")},async migrate(Q){b(`${Q}: account migration runs on first plugin start; setup leaves existing credentials unchanged.`)}}}if(process.argv[2]!=="setup")console.log("Usage: opencode-openai-auth setup [options]");else try{await n(T0(),process.argv.slice(3))}catch(G){console.error(G instanceof Error?G.message:String(G)),process.exitCode=1}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { a as KnobValues, c as PluginExtraSection, i as CommandInvocation, l as PluginSection, o as MenuKnob, t as CommandApplyRequest } from "./model-
|
|
2
|
-
import {
|
|
1
|
+
import { a as KnobValues, c as PluginExtraSection, i as CommandInvocation, l as PluginSection, o as MenuKnob, t as CommandApplyRequest } from "./model-DphbMQce.js";
|
|
2
|
+
import { _t as QuotaMap } from "./sidebar-state-pTd9gg9W.js";
|
|
3
3
|
import { ClaustrumClient, EnrollmentPollOutcome } from "@cortexkit/claustrum-client";
|
|
4
4
|
import "@cortexkit/private-files";
|
|
5
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
5
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/schema.d.ts
|
|
6
6
|
type OAuthCredential = {
|
|
7
7
|
type: 'oauth';
|
|
8
8
|
access?: string;
|
|
@@ -191,7 +191,7 @@ interface PoolRow {
|
|
|
191
191
|
unbound?: true;
|
|
192
192
|
}
|
|
193
193
|
//#endregion
|
|
194
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
194
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/errors.d.ts
|
|
195
195
|
/** Every library operation that can fail, as named in the failure value. */
|
|
196
196
|
type PoolOperation = 'initialize' | 'add' | 'replace' | 'rotate' | 'disable' | 'enable' | 'remove' | 'reorder' | 'updateSettings' | 'recordIdentity' | 'updateProviderState' | 'refresh' | 'pull' | 'publishRoster';
|
|
197
197
|
/**
|
|
@@ -238,12 +238,12 @@ declare class PoolOperationError extends Error {
|
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
//#endregion
|
|
241
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
241
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/hooks.d.ts
|
|
242
242
|
interface PoolLogger {
|
|
243
243
|
warn(message: string, data?: unknown): void;
|
|
244
244
|
}
|
|
245
245
|
//#endregion
|
|
246
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
246
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/fs/refresh-file-lock.d.ts
|
|
247
247
|
interface LockLoss {
|
|
248
248
|
readonly reason: 'taken-over' | 'expired' | 'unreadable' | 'renewal-failed' | 'marker-lost';
|
|
249
249
|
readonly expectedOwnerId: string;
|
|
@@ -278,7 +278,7 @@ type RefreshFileLockOptions = {
|
|
|
278
278
|
/** Filesystem leases share wall time across all callers and processes. */
|
|
279
279
|
declare function acquireRefreshFileLock(options: RefreshFileLockOptions): Promise<RefreshFileLock | null>;
|
|
280
280
|
//#endregion
|
|
281
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
281
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/refresh-lock.d.ts
|
|
282
282
|
type LockStep = NonNullable<Parameters<typeof acquireRefreshFileLock>[0]['onStep']> extends ((step: infer S) => unknown) ? S : never;
|
|
283
283
|
/** Tuning shared by every lock the store takes; each field is overridable. */
|
|
284
284
|
interface PoolLockOptions {
|
|
@@ -310,7 +310,7 @@ interface LockEnvironment {
|
|
|
310
310
|
}, event: 'scheduled' | 'cancelled') => void;
|
|
311
311
|
}
|
|
312
312
|
//#endregion
|
|
313
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
313
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/mutate.d.ts
|
|
314
314
|
/** Named points on the write path, for crash and ownership injection. */
|
|
315
315
|
type WriteStep = 'before-config-write' | 'after-config-write' | 'before-state-write' | 'after-state-write';
|
|
316
316
|
/** Awaitable pause points on the pull and refresh paths. */
|
|
@@ -345,11 +345,11 @@ interface StoreContext {
|
|
|
345
345
|
/** What `initializePool` did. */
|
|
346
346
|
type InitializeOutcome = 'initialized' | 'already-ready';
|
|
347
347
|
//#endregion
|
|
348
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
348
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/runtime.d.ts
|
|
349
349
|
/** Where a pull was fired from; `load` fires at most once per process per row. */
|
|
350
350
|
type PullReason = 'load' | 'add' | 'replace' | 'admission';
|
|
351
351
|
//#endregion
|
|
352
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
352
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/attribution.d.ts
|
|
353
353
|
/**
|
|
354
354
|
* What a pull or refresh captured about its row (named by id alongside) when
|
|
355
355
|
* it was issued. A result applies only while the row with that id still has
|
|
@@ -372,7 +372,7 @@ interface Attribution {
|
|
|
372
372
|
identity?: string;
|
|
373
373
|
}
|
|
374
374
|
//#endregion
|
|
375
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
375
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/rows.d.ts
|
|
376
376
|
type FailureHook = (rowId: string, error: PoolOperationError) => void | Promise<void>;
|
|
377
377
|
interface RowOperationOptions {
|
|
378
378
|
/** Called once, awaited, on every non-success path, before locks release. */
|
|
@@ -588,7 +588,7 @@ interface RowTransitionResult {
|
|
|
588
588
|
providerState?: unknown;
|
|
589
589
|
}
|
|
590
590
|
//#endregion
|
|
591
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
591
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/provider-state.d.ts
|
|
592
592
|
/**
|
|
593
593
|
* Receives a private copy of the row's provider state (undefined when the row
|
|
594
594
|
* shows none) and the row as loaded under the locks, and returns the next
|
|
@@ -624,7 +624,7 @@ declare const DECLINE_TRANSITION: unique symbol;
|
|
|
624
624
|
*/
|
|
625
625
|
type RowTransitionMutator = (current: unknown | undefined, row: PoolRow) => unknown | typeof DECLINE_TRANSITION | Promise<unknown | typeof DECLINE_TRANSITION>;
|
|
626
626
|
//#endregion
|
|
627
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
627
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/publication.d.ts
|
|
628
628
|
interface PublishPlan {
|
|
629
629
|
operationId: string;
|
|
630
630
|
remove: Array<{
|
|
@@ -667,7 +667,7 @@ interface PublishResult {
|
|
|
667
667
|
receipt: PublicationReceipt;
|
|
668
668
|
}
|
|
669
669
|
//#endregion
|
|
670
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
670
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/pull.d.ts
|
|
671
671
|
/** What a pull is issued with: the credential and its attribution tuple. */
|
|
672
672
|
interface PullRequest {
|
|
673
673
|
id: string;
|
|
@@ -678,7 +678,7 @@ interface PullRequest {
|
|
|
678
678
|
}
|
|
679
679
|
type PullHook = (request: PullRequest) => Promise<unknown>;
|
|
680
680
|
//#endregion
|
|
681
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
681
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/refresh.d.ts
|
|
682
682
|
/** What the injected provider refresh function returns. */
|
|
683
683
|
interface ProviderRefreshResult {
|
|
684
684
|
access: string;
|
|
@@ -741,7 +741,7 @@ type RefreshOutcome = {
|
|
|
741
741
|
reason: string;
|
|
742
742
|
};
|
|
743
743
|
//#endregion
|
|
744
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
744
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/settings.d.ts
|
|
745
745
|
/** The plugin's settings: every top-level config key except the pool-owned ones. */
|
|
746
746
|
type PoolSettings = Record<string, unknown>;
|
|
747
747
|
type SettingsRead = {
|
|
@@ -785,7 +785,7 @@ type UpdateSettingsResult = {
|
|
|
785
785
|
outcome: 'updated' | 'unchanged';
|
|
786
786
|
};
|
|
787
787
|
//#endregion
|
|
788
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
788
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/store/pool.d.ts
|
|
789
789
|
interface OpenPoolStoreOptions {
|
|
790
790
|
/** The provider every row of this pool belongs to; keys the provider-wide lock. */
|
|
791
791
|
provider: string;
|
|
@@ -971,13 +971,13 @@ interface PoolStore {
|
|
|
971
971
|
pullsSettled(): Promise<void>;
|
|
972
972
|
}
|
|
973
973
|
//#endregion
|
|
974
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
974
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/commands/seam.d.ts
|
|
975
975
|
/** Where a dropped field is reported. Names only, never values. */
|
|
976
976
|
interface SeamLogger {
|
|
977
977
|
warn(message: string, data?: unknown): void;
|
|
978
978
|
}
|
|
979
979
|
//#endregion
|
|
980
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
980
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/commands/builtins.d.ts
|
|
981
981
|
/**
|
|
982
982
|
* What a plugin's login hands back. `ready` adds the account now. `pending`
|
|
983
983
|
* means the user must finish somewhere else (a browser, a device code):
|
|
@@ -1097,7 +1097,7 @@ interface BeginAccountLoginResult {
|
|
|
1097
1097
|
*/
|
|
1098
1098
|
declare function beginAccountLogin(opts: BeginAccountLoginOptions): Promise<BeginAccountLoginResult>;
|
|
1099
1099
|
//#endregion
|
|
1100
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
1100
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/watch.d.ts
|
|
1101
1101
|
/**
|
|
1102
1102
|
* How a host currently learns about changes, for logs and status displays.
|
|
1103
1103
|
* `watching`: a watch was accepted and is open, so polling is reduced to a
|
|
@@ -1151,7 +1151,7 @@ interface ScopedWatchSource {
|
|
|
1151
1151
|
}): ScopedWatchHandle;
|
|
1152
1152
|
}
|
|
1153
1153
|
//#endregion
|
|
1154
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
1154
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/insula.d.ts
|
|
1155
1155
|
/**
|
|
1156
1156
|
* A held-open `usage.watch` stream. `closed` resolves when insula ends the
|
|
1157
1157
|
* stream (STREAM_END at shutdown, or a reply that ends it) or after `stop()`,
|
|
@@ -1175,7 +1175,7 @@ interface InsulaUsageTransport {
|
|
|
1175
1175
|
watchUsage?(onNotice: (body: Uint8Array) => void): InsulaUsageWatch;
|
|
1176
1176
|
}
|
|
1177
1177
|
//#endregion
|
|
1178
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
1178
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/custody.d.ts
|
|
1179
1179
|
/**
|
|
1180
1180
|
* `watchScoped` is present from claustrum-client 0.12.0. Hosts detect it at
|
|
1181
1181
|
* run time and keep polling without it.
|
|
@@ -1280,7 +1280,7 @@ interface KeptReceiptState {
|
|
|
1280
1280
|
readonly since: number | null;
|
|
1281
1281
|
}
|
|
1282
1282
|
//#endregion
|
|
1283
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
1283
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/interlock.d.ts
|
|
1284
1284
|
/**
|
|
1285
1285
|
* The declined-account interlock: the user's "do not use this vault account",
|
|
1286
1286
|
* kept on the consumer side because the vault has no notion of it.
|
|
@@ -1299,7 +1299,7 @@ interface DeclinedAccount {
|
|
|
1299
1299
|
readonly accountIdentity?: string;
|
|
1300
1300
|
}
|
|
1301
1301
|
//#endregion
|
|
1302
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
1302
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/roster.d.ts
|
|
1303
1303
|
/**
|
|
1304
1304
|
* One vault account as the pool sees it. It carries no bearer material: the
|
|
1305
1305
|
* access token is fetched from the vault for every send. Several vault
|
|
@@ -1354,7 +1354,7 @@ interface VaultRosterFile {
|
|
|
1354
1354
|
*/
|
|
1355
1355
|
type QuotaReceipt = Pick<ClaustrumScopedAttempt, 'credentialId' | 'accountIdentity' | 'accountIdentitySource' | 'expectedAccountIdentity'>;
|
|
1356
1356
|
//#endregion
|
|
1357
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
1357
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/consumer.d.ts
|
|
1358
1358
|
/**
|
|
1359
1359
|
* How a started consumer learns about changes, for logs and status displays.
|
|
1360
1360
|
* `insula` is present when the consumer was given an insula source. Never
|
|
@@ -1365,7 +1365,7 @@ interface ClaustrumWatchState {
|
|
|
1365
1365
|
readonly insula?: WatchMode;
|
|
1366
1366
|
}
|
|
1367
1367
|
//#endregion
|
|
1368
|
-
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.
|
|
1368
|
+
//#region ../../node_modules/.bun/@cortexkit+common-auth@0.23.0+48f2e2ce69c71a39/node_modules/@cortexkit/common-auth/dist/claustrum/enrollment.d.ts
|
|
1369
1369
|
interface ClaustrumEnrollmentClient {
|
|
1370
1370
|
enrollPropose(input: {
|
|
1371
1371
|
name: string;
|
|
@@ -1593,7 +1593,7 @@ declare class OpenAiVault {
|
|
|
1593
1593
|
* the background; a failure is logged.
|
|
1594
1594
|
*/
|
|
1595
1595
|
recordSnapshot(routeId: string, snapshot: unknown, complete: boolean, receipt: QuotaReceipt): Promise<void>;
|
|
1596
|
-
/** Joins a quota poll;
|
|
1596
|
+
/** Joins a quota poll; insula decides whether a background provider read is needed. */
|
|
1597
1597
|
pollQuota(routeId: string, background?: boolean): Promise<{
|
|
1598
1598
|
ok: boolean;
|
|
1599
1599
|
error?: string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{Ac as NZ,Bc as PZ,Dc as g,Ec as WZ,Fc as HZ,Ic as d,be as _Z,ee as TZ,ge as RZ}from"./index-brbqqer5.js";import{oe as XZ,se as VZ,te as YZ,ue as y,ve as x}from"./index-ag04nyv7.js";import{Me as OZ}from"./index-wgwze391.js";import{Ue as b,Ve as $Z,Ze as A,_e as JZ}from"./index-5230x6s8.js";import{createHash as cZ}from"node:crypto";import{constants as oZ,copyFileSync as aZ,mkdirSync as iZ,statSync as sZ}from"node:fs";import{readFile as nZ}from"node:fs/promises";import{homedir as eZ,tmpdir as tZ}from"node:os";import{dirname as Z0,join as h}from"node:path";import{chmod as dZ,mkdir as lZ}from"node:fs/promises";import{dirname as ZZ}from"node:path";function k(Z){let{path:$,defaultValue:V,normalize:J}=Z,X=Promise.resolve(),Y=(B)=>{if(B==="")return V;try{return J(JSON.parse(B))}catch{return V}},G=async()=>{try{if(b)await A(ZZ($),Z.secureDir??!0);return await JZ($,b)}catch(B){if(B.code==="ENOENT")return"";throw B}},z=async()=>{try{return Y(await G())}catch(B){if(B instanceof $Z)throw B;return V}},U=(B,D)=>{let N=X.then(B).then((P)=>D?.onResult?.(P));return X=N.catch(()=>{}),N},L={...x.sidebar,name:Z.lockName??x.sidebar.name,timeoutMs:Z.timeoutMs??x.sidebar.timeoutMs},j=async(B,D,N)=>{await XZ($,D,{serialize:JSON.stringify,beforeRename:async()=>{await N?.beforeCommit?.(),await B.assertOwned()}}),await N?.afterRename?.();try{return await B.assertOwned(),!0}catch(P){if(P instanceof YZ)return!1;throw P}},Q=async(B,D,N)=>{Z.logger?.warn("sidebar lock lost after rename; repairing write",{path:$});try{let P=await y($,L,async(W)=>{let H=B(await z(),D);if(H===void 0)return"skipped";return await j(W,H,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 VZ))throw P;return Z.logger?.warn("sidebar repair lock unavailable; repair skipped",{path:$}),{status:"lost-after-rename",repair:"lock-unavailable"}}},K=async(B,D)=>{let N=D,P=ZZ($),W=Z.secureDir??!0;if(b)await A(P,W);else if(await lZ(P,{recursive:!0,mode:448}),W)await dZ(P,448).catch((F)=>{Z.logger?.warn("sidebar directory permission remediation failed",{error:F instanceof Error?F.message:String(F)})});let H=await y($,L,async(F)=>{let s=async(C)=>({value:C,held:await j(F,C,N)});for(let C=0;C<3;C+=1){let e=await G(),t=B(Y(e));if(t===void 0)return;if(C===0)await N?.beforeRecheck?.();if(await G()!==e)continue;return await s(t)}let n=B(await z());return n===void 0?void 0:await s(n)});if(H===void 0)return{status:"skipped"};if(H.held)return{status:"written"};let i=D?.repair??Z.repair;if(!i)return Z.logger?.warn("sidebar lock lost after rename; write not repaired",{path:$}),{status:"lost-after-rename",repair:"none"};return await Q(i,H.value,N)};return{read:z,write:(B,D)=>U(()=>K(()=>B,D),D),update:(B,D)=>U(()=>K(B,D),D)}}function v0(Z){let $=Z?.credits;if($===null||typeof $!=="object")return;let{hasCredits:V,unlimited:J,balance:X}=$;if(typeof V!=="boolean"||typeof J!=="boolean")return;return WZ({hasCredits:V,unlimited:J,...typeof X==="number"?{balance:X}:{}})}function S0(Z,$=Date.now()){if(!xZ(Z,$))return!1;if(bZ(Z,$))return!1;return RZ(Z?.credits,$)}var l=["primary","secondary"],uZ={primary:300,secondary:10080};function rZ(Z,$){return NZ({scope:"all",label:$,windowMinutes:Z})}function f0(Z){if(!Z)return[];let $=[];for(let V of l){let J=Z[V];if(!J)continue;let X=J.windowMinutes,Y=X!==void 0&&Number.isFinite(X)&&X>0?X:uZ[V];$.push({key:V,label:rZ(X,V),window:J,windowMs:Y*60000})}return $}var M=OZ("sidebar"),$0="OPENCODE_OPENAI_AUTH_SIDEBAR_STATE_FILE";function CZ(){let Z=process.env.XDG_STATE_HOME||h(eZ(),".local","state");return h(Z,"cortexkit","openai-auth","sidebar-state.json")}var FZ=h(tZ(),"opencode-openai-auth","sidebar-state.json");function g0(Z){FZ=Z,m.clear()}var J0=/^[a-f0-9]{64}$/,u=604800000,MZ=256,EZ=3600000;function T(Z){return cZ("sha256").update(Z).digest("hex")}function X0(Z){return typeof Z==="number"&&Number.isFinite(Z)&&Z>=0?Z:void 0}function qZ(Z){let $=X0(Z);return $!==void 0?{resetCredits:$}:{}}function V0(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 Y0(Z){if(Z===null||typeof Z!=="object"||Array.isArray(Z))return;let $={};for(let[V,J]of Object.entries(Z)){if(!J0.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 G=X.wireAccountId;$[V]={accountId:X.accountId,assignedAt:X.assignedAt,lastSeenAt:X.lastSeenAt,inputBytes:X.inputBytes,...Y===void 0?{}:{quotaCheckedAt:Y},...typeof G==="string"?{wireAccountId:G}:{}}}return Object.keys($).length>0?$:void 0}function O(){let Z=process.env[$0];if(Z)return Z;let $=CZ();if(!m.has($))m.add($),z0($,FZ);return $}var m=new Set;function z0(Z,$){try{iZ(Z0(Z),{recursive:!0,mode:448}),aZ($,Z,oZ.COPYFILE_EXCL)}catch{}}var q={main:{quota:null,killed:!1},fallbacks:[],activeId:void 0,route:"main",lastUpdated:0};function f(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 K=V;J={quota:"quota"in K?K.quota:null,killed:typeof K.killed==="boolean"?K.killed:!1,...typeof K.mainAccountId==="string"?{mainAccountId:K.mainAccountId}:{},...typeof K.quotaBackedOff==="boolean"?{quotaBackedOff:K.quotaBackedOff}:{},...typeof K.quotaBackoffUntil==="number"?{quotaBackoffUntil:K.quotaBackoffUntil}:{},...typeof K.refreshBackedOff==="boolean"?{refreshBackedOff:K.refreshBackedOff}:{},...typeof K.refreshBackoffUntil==="number"?{refreshBackoffUntil:K.refreshBackoffUntil}:{},...qZ(K.resetCredits)}}else J={quota:null,killed:!1};let X=zZ($.fallbacks),Y=Array.isArray($.vaultAccounts)?zZ($.vaultAccounts):void 0,G=typeof $.activeId==="string"?$.activeId:void 0,z=typeof $.route==="string"?$.route:q.route,U=typeof $.lastUpdated==="number"?$.lastUpdated:0,L=typeof $.planType==="string"?$.planType:void 0,j=V0($.activeRouting),Q=Y0($.stickyAssignments);return{main:J,fallbacks:X,activeId:G,route:z,lastUpdated:U,...j!==void 0?{activeRouting:j}:{},...Q!==void 0?{stickyAssignments:Q}:{},...L!==void 0?{planType:L}:{},...$.accountPool===!0?{accountPool:!0}:{},...Y!==void 0?{vaultAccounts:Y}:{}}}function zZ(Z){if(!Array.isArray(Z))return[];return Z.filter(($)=>$!==null&&typeof $==="object"&&!Array.isArray($)&&typeof $.id==="string").map(($)=>({id:$.id,...typeof $.credentialId==="string"?{credentialId:$.credentialId}:{},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,...typeof $.routable==="boolean"?{routable:$.routable}:{},...["needs sign-in","turned off in vault","unavailable"].includes($.vaultState)?{vaultState:$.vaultState}:{},...qZ($.resetCredits)}))}function r(Z){return[...Z.fallbacks,...Z.vaultAccounts??[]]}async function G0(Z=O()){try{let $=await nZ(Z,"utf8");return f(JSON.parse($))}catch{return q}}var K0=3600000,GZ=128;function IZ(Z,$,V=Date.now()){if(!(Z.updatedAt>=V-K0&&Z.updatedAt<=V))return!1;if($===void 0)return!0;return Z.activeId==="main"||$.some((X)=>X.enabled!==!1&&X.routable!==!1&&X.killed!==!0&&X.id===Z.activeId)}function bZ(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 xZ(Z,$=Date.now()){let V;for(let X of l){let Y=Z?.[X];if(typeof Y?.resetsAt!=="string"||!Number.isFinite(Y.usedPercent)||Y.usedPercent<100)continue;let G=Date.parse(Y.resetsAt);if(!Number.isFinite(G)||G<=$)continue;if(!V||G<V.resetAtMs)V={resetsAt:Y.resetsAt,resetAtMs:G}}let J=bZ(Z,$);if(J&&(!V||J.resetAtMs<V.resetAtMs))V=J;return V}function E(Z,$=Date.now()){return xZ(Z,$)!==void 0}function j0(Z,$,V=Date.now()){if(!$||Z.route!=="sticky-balanced")return;let J=Z.stickyAssignments?.[T($)];if(!J||J.lastSeenAt<V-u)return;if(J.accountId==="main"&&Z.vaultAccounts===void 0)return Z.main?.killed||E(Z.main?.quota,V)?void 0:"main";let X=r(Z).find((Y)=>Y.id===J.accountId);if(!X||X.enabled===!1||X.routable===!1||X.killed===!0||E(X.quota,V))return;return X.id}function d0(Z,$,V=Date.now()){if(!$){if(Z.vaultAccounts===void 0)return{activeId:Z.activeId??"main",route:Z.route};let j=Z.vaultAccounts.find((Q)=>Q.id===Z.activeId&&Q.enabled&&Q.routable!==!1&&!Q.killed);if(j&&!E(j.quota,V))return{activeId:j.id,route:Z.route}}let J=$?Z.activeRouting?.[$]:void 0,X=r(Z),Y=J?.activeId==="main"?Z.main.quota:X.find((j)=>j.id===J?.activeId)?.quota;if(J&&(Z.vaultAccounts===void 0||J.activeId.startsWith("vault:"))&&IZ(J,X,V)&&!E(Y,V))return{activeId:J.activeId,route:J.route};let G=j0(Z,$,V);if(G)return{activeId:G,route:Z.route};let z=Z.vaultAccounts!==void 0,U=(z?c(Z):Z.fallbacks).filter((j)=>j.enabled&&j.routable!==!1&&!j.killed),L=U.find((j)=>!E(j.quota,V))??U[0];return{activeId:z?L?.id??"vault":Z.route==="fallback-first"&&L?L.id:"main",route:Z.route}}function c(Z){let $=Z.vaultAccounts??[],V=new Map($.map((J)=>[J.id,J]));return d($.map((J)=>J.id),gZ(Z),_Z($)??"").flatMap((J)=>{let X=V.get(J);return X?[X]:[]})}function vZ(Z,$,V=Date.now(),J){if(!Z)return;let X=Object.entries(Z).filter(([G,z])=>G!==J&&IZ(z,$,V)),Y=X.length<=GZ?X:X.sort((G,z)=>z[1].updatedAt-G[1].updatedAt).slice(0,GZ);return Y.length>0?Object.fromEntries(Y):void 0}function I(Z,$,V=Date.now(),J){if(!Z)return;let X=0,Y=0,G=0,z=[];for(let[L,j]of Object.entries(Z)){if(L===J){G+=1;continue}if(j.lastSeenAt<V-u){Y+=1;continue}if($!==void 0&&!$.has(j.accountId)){X+=1;continue}z.push([L,j])}let U=X+Y+G;if(U>0)M.debug("pruned sticky assignments",{pid:process.pid,removed:U,reasons:{"account-not-in-roster":X,expired:Y,"explicit-removal":G}});return z.length>0?Object.fromEntries(z):void 0}function SZ(Z,$){let V=Object.keys(Z).length-MZ;if(V<=0)return Z;let J=new Set(Object.entries(Z).filter(([X])=>X!==$).sort(([X,Y],[G,z])=>Y.lastSeenAt-z.lastSeenAt||X.localeCompare(G)).slice(0,V).map(([X])=>X));return Object.fromEntries(Object.entries(Z).filter(([X])=>!J.has(X)))}function fZ(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 AZ(Z,$,V,J){return Z!==void 0&&$.has(Z.accountId)&&!V.has(Z.accountId)&&Z.lastSeenAt>=J-u}function yZ(Z,$,V,J){return $>Z.inputBytes||V-Z.lastSeenAt>=EZ||Z.wireAccountId===void 0&&J!==void 0}function kZ(Z,$){return typeof Z.wireAccountId==="string"&&typeof $==="string"&&Z.wireAccountId!==$}function L0(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,G)=>{J.call(X,Y,G,V)})},[Symbol.iterator]:()=>$[Symbol.iterator]()};return Object.freeze(V)}function B0(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 L0(J)}function o(Z){if(Z===void 0)return;return new Set(["main",...Z.filter(($)=>$.enabled!==!1&&$.killed!==!0).map(($)=>$.id)])}var p=Promise.resolve();function _(Z){let $=p.then(Z);return p=$.catch(()=>{}),$}var KZ=new Map;function a(Z){let $=KZ.get(Z);if(!$)$=k({path:Z,defaultValue:q,normalize:f,secureDir:Z===CZ(),logger:M}),KZ.set(Z,$);return $}var w=new Set;async function wZ(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 l0(Z,$=O()){return _(()=>wZ($,a($).write(f(Z))))}function U0(Z){return a(Z).read()}function R(Z,$,V){let J=Symbol("sidebar authority changed");return wZ(Z,a(Z).update((X)=>{if(V?.canWrite&&!V.canWrite())return;let Y=$(X);if(Y===void 0)return;if(Y.vaultAccounts!==void 0)Y.activeId=Y.activeId?.startsWith("vault:")?Y.activeId:void 0,Y.activeRouting=Object.fromEntries(Object.entries(Y.activeRouting??{}).filter(([,G])=>G.activeId.startsWith("vault:"))),Y.stickyAssignments=Object.fromEntries(Object.entries(Y.stickyAssignments??{}).filter(([,G])=>G.accountId.startsWith("vault:")&&!Y.vaultAccounts?.some((z)=>z.id===G.accountId&&z.killed)));return f(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 jZ(Z,$){let V=v(Z),J=v($);if(J!==void 0&&(V===void 0||J>V))return $;return Z}function LZ(Z,$){return Z!==void 0&&$!==void 0&&Z===$}function S(Z,$){let V=Z?.checkedAt;if(typeof V==="number"&&Number.isFinite(V))return V;if(typeof $==="number"&&Number.isFinite($))return $;return}function BZ(Z,$,V,J,X){if(Z&&$){let Y=S(Z,J),G=S($,X);if(G!==void 0&&(Y===void 0||G>Y))return $;return Z}return V?$:Z}function UZ(Z,$){if(Z.spendControl!==void 0)return Z.spendControl;if(Z.spendControlCleared===!0)return;return $.spendControl}function Q0(Z,$){if(!Z||!$)return Z??$;let V=(J)=>typeof J.checkedAt==="number"&&Number.isFinite(J.checkedAt)?J.checkedAt:Number.NEGATIVE_INFINITY;return V($)>V(Z)?$:Z}function QZ(Z,$){if(!Z)return $;if(!$)return Z;let V=v(Z),J=v($),X=J!==void 0&&(V===void 0||J>V),Y=BZ(Z.primary,$.primary,X,Z.checkedAt,$.checkedAt),G=BZ(Z.secondary,$.secondary,X,Z.checkedAt,$.checkedAt),z=X?UZ($,Z):UZ(Z,$),U=z===void 0&&(Z.spendControlCleared===!0||$.spendControlCleared===!0),L=Q0(Z.credits,$.credits),j;for(let N of[S(Y),S(G)])if(N!==void 0)j=j===void 0?N:Math.max(j,N);let{spendControl:Q,spendControlCleared:K,credits:B,...D}=Z;return{...D,primary:Y,secondary:G,...z!==void 0?{spendControl:z}:{},...U?{spendControlCleared:!0}:{},...L!==void 0?{credits:L}:{},checkedAt:j??Z.checkedAt}}function u0(Z,$=O(),V){return _(async()=>{await R($,(J)=>{let X=new Map(J.fallbacks.map((j)=>[j.id,j])),Y=Z.vaultAccounts!==void 0,G=LZ(Z.main.mainAccountId,J.main.mainAccountId),z=G?QZ(Z.main.quota,J.main.quota):jZ(Z.main.quota,J.main.quota),U=Date.now(),L=I(J.stickyAssignments,Y?void 0:o(r(Z)),U);return{...J,...Z,main:Y?Z.main:{...Z.main,quota:z,mainAccountId:G?Z.main.mainAccountId:z===J.main.quota&&z!==Z.main.quota?J.main.mainAccountId:Z.main.mainAccountId},fallbacks:Y?Z.fallbacks:Z.fallbacks.map((j)=>{let Q=X.get(j.id),K=LZ(j.accountId,Q?.accountId),B=K?QZ(j.quota,Q?.quota??null):jZ(j.quota,Q?.quota??null);return{...j,quota:B,accountId:K?j.accountId:B===Q?.quota&&B!==j.quota?Q?.accountId:j.accountId}}),activeId:J.activeId,activeRouting:J.activeRouting,stickyAssignments:L,lastUpdated:Math.max(U,J.lastUpdated+1),accountPool:Z.accountPool===!0?!0:void 0,vaultAccounts:Z.vaultAccounts}},V)})}function r0(Z,$,V=O(),J){return _(async()=>{await R(V,(X)=>{let Y=vZ({...X.activeRouting,[Z.sessionId]:{activeId:Z.activeId,route:Z.route,updatedAt:Z.updatedAt}},$,Date.now()),G=I(X.stickyAssignments,X.vaultAccounts!==void 0?void 0:o($),Date.now());return{...X,activeId:Z.activeId,route:Z.route,activeRouting:Y,stickyAssignments:G,lastUpdated:Math.max(Date.now(),X.lastUpdated+1)}},J)})}function c0(Z,$=O(),V){return _(async()=>{await R($,(J)=>({...J,activeId:Z.activeId,route:Z.route,lastUpdated:Math.max(Date.now(),J.lastUpdated+1)}),V)})}function o0(Z,$,V=O(),J){return _(async()=>{await R(V,(X)=>{let Y=Date.now(),G=vZ(X.activeRouting,$,Y,Z),z=I(X.stickyAssignments,X.vaultAccounts!==void 0?void 0:o($),Y,T(Z));return{...X,activeRouting:G,stickyAssignments:z,lastUpdated:Math.max(Date.now(),X.lastUpdated+1)}},J)})}function hZ(Z,$){return AZ(Z,new Set($.validPinnedAccountIds),new Set($.excludeAccountIds),$.now)&&!kZ(Z,$.wireAccountIdByAccount?.[Z.accountId])&&!yZ(Z,$.requestBytes,$.now,$.wireAccountIdByAccount?.[Z.accountId])}function mZ(Z,$){let V=T($.sessionId),J=new Set($.validPinnedAccountIds),X=new Set($.excludeAccountIds),Y=I(Z.stickyAssignments,J,$.now),G=!fZ(Z.stickyAssignments,Y),z=Y?.[V],U=z!==void 0&&kZ(z,$.wireAccountIdByAccount?.[z.accountId]);if(AZ(z,J,X,$.now)&&!U){let Q=yZ(z,$.requestBytes,$.now,$.wireAccountIdByAccount?.[z.accountId]),K=Q?{...z,inputBytes:Math.max(z.inputBytes,$.requestBytes),...z.wireAccountId===void 0&&$.wireAccountIdByAccount?.[z.accountId]!==void 0?{wireAccountId:$.wireAccountIdByAccount?.[z.accountId]}:{},...$.now-z.lastSeenAt>=EZ?{lastSeenAt:$.now}:{}}:z;if(!G&&!Q)return{assignment:K,next:void 0};return{assignment:K,next:{...Z,stickyAssignments:{...Y,[V]:K},lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}let L=$.choose(B0(Y,$.quotaCheckedAtByAccount,U?V:void 0));if(!L){if(!G)return{assignment:void 0,next:void 0};return{assignment:void 0,next:{...Z,stickyAssignments:Y,lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}let j={accountId:L.accountId,assignedAt:$.now,lastSeenAt:$.now,inputBytes:$.requestBytes,...L.quotaCheckedAt===void 0?{}:{quotaCheckedAt:L.quotaCheckedAt},...$.wireAccountIdByAccount?.[L.accountId]===void 0?{}:{wireAccountId:$.wireAccountIdByAccount?.[L.accountId]}};return{assignment:j,next:{...Z,stickyAssignments:SZ({...Y,[V]:j},V),lastUpdated:Math.max($.now,Z.lastUpdated+1)}}}async function a0(Z,$=O(),V){let J=T(Z.sessionId),X=(await U0($)).stickyAssignments?.[J];if(hZ(X,Z))return X;let Y;return await _(async()=>{await R($,(G)=>{let z=mZ(G,Z);return Y=z.assignment,z.next},V)}),Y}function i0(Z,$){let V=Z.stickyAssignments?.[T($.sessionId)];if(hZ(V,$))return{assignment:V,next:void 0};return mZ(Z,$)}function s0(Z,$=O()){let V=T(Z.sessionId),J=new Set(Z.validPinnedAccountIds);return _(async()=>{await R($,(X)=>{let Y=Date.now(),G=I(X.stickyAssignments,X.vaultAccounts!==void 0?void 0:J,Y),z=G?.[V];if(z&&z.assignedAt>Z.assignment.assignedAt){if(fZ(X.stickyAssignments,G))return;return{...X,stickyAssignments:G,lastUpdated:Math.max(Y,X.lastUpdated+1)}}let L=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:SZ({...G,[V]:L},V),lastUpdated:Math.max(Y,X.lastUpdated+1)}})})}async function n0(Z,$=O()){let V=T(Z),J=!1;return await _(async()=>{await R($,(X)=>{let Y=X.stickyAssignments;if(Y?.[V]===void 0){J=!1;return}J=!0;let{[V]:G,...z}=Y;return{...X,...Object.keys(z).length>0?{stickyAssignments:z}:{stickyAssignments:void 0},lastUpdated:Math.max(Date.now(),X.lastUpdated+1)}})}),J}function e0(){return p}var D0=500;function N0(Z,$,V){return new Promise((J,X)=>{let Y=setTimeout(()=>J(V()),$);Y.unref?.(),Z.then((G)=>{clearTimeout(Y),J(G)},(G)=>{clearTimeout(Y),X(G)})})}function t0(Z,$={}){let V=$.readBudgetMs??D0,J,X,Y=()=>{try{let z=sZ(Z);return`${z.ino}:${z.size}:${z.mtimeMs}`}catch{return}},G=(z)=>{if(X&&X.key===z)return X.promise;let U=Date.now(),L=G0(Z).then((K)=>{if(!J||J.readAt<=U)J={state:K,readAt:U,key:z};return{state:K,readAt:U}}),j={key:z,promise:L};X=j;let Q=()=>{if(X===j)X=void 0};return L.then(Q,Q),L};return{get(){let z=Y();if(J&&J.key===z)return Promise.resolve({state:J.state,readAt:J.readAt});return N0(G(z),V,()=>J?{state:J.state,readAt:J.readAt}:{state:q,readAt:0})},read(){return G(Y())},refreshInBackground(){let z=Y();if(J?.key===z)return;G(z)}}}function Z1(Z,$,V){let J={assignment:V};Z.delete($),Z.set($,J);while(Z.size>MZ){let X=Z.keys().next().value;if(X===void 0)break;Z.delete(X)}return J}function $1(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 J1(Z){let $=Z.retryDelayMs??500,V=Z.maxRetryDelayMs??30000,J=new Map,X=new Map,Y=new Set,G=0,z=$,U,L=!1,j=()=>{if(U||L||X.size===0)return;U=setTimeout(()=>{U=void 0;let K=[...X];X.clear(),z=Math.min(z*2,V);for(let[B,D]of K){let N=J.get(B);if(N!==void 0)Q(B,D.label,D.write,N)}},z),U.unref?.()},Q=(K,B,D,N)=>{let P;try{P=D()}catch(W){P=Promise.reject(W)}P.then(()=>{if(J.get(K)!==N)return;if(J.delete(K),Y.delete(K))Z.logger.info("sidebar bookkeeping write recovered",{pid:process.pid,write:B});if(Y.size===0)z=$;Z.onWritten?.()},(W)=>{if(J.get(K)!==N)return;let H={pid:process.pid,write:B,error:W instanceof Error?W.message:String(W)};if(L){J.delete(K),Z.logger.debug("sidebar bookkeeping write dropped",H);return}if(Y.has(K))Z.logger.debug("sidebar bookkeeping write failed again",H);else Y.add(K),Z.logger.warn("sidebar bookkeeping write failed; retrying in the background",H);X.set(K,{label:B,write:D}),j()})};return{enqueue(K,B,D){G+=1,J.set(K,G),X.delete(K),Q(K,B,D,G)},cancel(K){J.delete(K),X.delete(K),Y.delete(K)},stop(){if(L=!0,U)clearTimeout(U);U=void 0,X.clear()}}}function P0(Z){let $=Z.activeId;if(Z.vaultAccounts!==void 0){let V=c(Z).filter((X)=>X.enabled&&X.routable!==!1),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 pZ(Z,$=Date.now()){if(!Z)return;return HZ({limits:l.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 X1(Z,$=Date.now()){let V=Z?.primary?.usedPercent??null,J=Z?.secondary?.usedPercent??null,X=pZ(Z,$);return{primaryUsedPercent:V,secondaryUsedPercent:J,text:!X||X.limits.length===0&&!X.budget?null:g(X,{now:$,form:"compact"})}}function gZ(Z){return Z.route==="sticky-balanced"?"roster":TZ(Z.route)}function V1(Z,$={}){let V=$.now??Date.now(),J=P0(Z).id;return(Z.vaultAccounts!==void 0?c(Z).map((Y)=>({id:Y.id,name:Y.label??Y.id,quota:Y.quota,killed:Y.killed})):W0(Z,J,$.showFallbacks??!0)).map((Y)=>{let G=pZ(Y.quota,V),z=G&&(G.limits.length>0||G.budget)?G:void 0;return{id:Y.id,name:Y.name,killed:Y.killed,active:Y.id===J,stale:z?PZ(z,{now:V}):!1,text:z?g(z,{now:V,form:"narrow"}):null}})}function W0(Z,$,V){let J=[{id:"main",name:"main",quota:Z.main.quota,killed:Z.main.killed},...Z.fallbacks.filter((Y)=>Y.enabled&&(V||Y.id===$)).map((Y)=>({id:Y.id,name:Y.label??Y.id,quota:Y.quota,killed:Y.killed}))],X=new Map(J.map((Y)=>[Y.id,Y]));return d(J.map((Y)=>Y.id),gZ(Z),"main").flatMap((Y)=>{let G=X.get(Y);return G?[G]:[]})}function DZ(Z){let $=globalThis.Bun;return $?.stringWidth?$.stringWidth(Z):Array.from(Z).length}function Y1(Z,$){if(DZ(Z)<=$)return Z;if($<1)return"";let V="",J=0;for(let X of Z){let Y=DZ(X);if(J+Y>$-1)break;V+=X,J+=Y}return`${V}…`}var H0=300000,O0=0.01,_0=1;function z1(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<H0)return null;if(Y<$*O0)return null;if(Y>=$)return null;let G=Z.usedPercent,z=Math.min(Math.max(Y/$*100,0),100),U=G-z,L=Math.abs(U)<_0?"on-pace":U>0?"deficit":"reserve",j=null;if(G>0){let Q=Y*100/G,K=X+Q;if(K<J)j=new Date(K).toISOString()}return{pacePercent:z,deltaPercent:U,state:L,runsOutAt:j}}
|
|
2
|
+
export{v0 as Fb,S0 as Gb,rZ as Hb,f0 as Ib,g0 as Jb,u as Kb,MZ as Lb,T as Mb,O as Nb,q as Ob,f as Pb,G0 as Qb,K0 as Rb,GZ as Sb,IZ as Tb,bZ as Ub,xZ as Vb,E as Wb,j0 as Xb,d0 as Yb,vZ as Zb,I as _b,l0 as $b,u0 as ac,r0 as bc,c0 as cc,o0 as dc,mZ as ec,a0 as fc,i0 as gc,s0 as hc,n0 as ic,e0 as jc,D0 as kc,N0 as lc,t0 as mc,Z1 as nc,$1 as oc,J1 as pc,P0 as qc,pZ as rc,X1 as sc,V1 as tc,DZ as uc,Y1 as vc,z1 as wc};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{Bb as X,Db as V}from"./index-
|
|
1
|
+
import{Bb as X,Db as V}from"./index-vy729a0b.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
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
3
|
export{_ as c};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
2
|
-
export{b as
|
|
1
|
+
import{jf as E}from"./index-d98f1xdp.js";import{randomUUID as k}from"node:crypto";import{lstat as S,readFile as O,rename as F,unlink as C}from"node:fs/promises";import{dirname as V,resolve as M}from"node:path";var b=process.platform==="win32",N=new Set;function T(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 B;function $(){return B??=import("@cortexkit/private-files"),B}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=T(z),this.win32Code=z?.win32Code,this.reason=z?.reason}}async function q(j,G,A){try{return await A()}catch(z){if(z instanceof R)throw z;throw new R(j,G,z)}}var g;async function Z(j,G){j=M(j),G??=g,await q(j,"safe-parent",async()=>{let A=await(await $()).verifySafeParent(j,G);if(A.ok===!1){if(A.reason==="io-error"||A.reason==="wrong-kind")await S(j);throw new R(A.level??A.path,"safe-parent",{...A,code:"ERR_PRIVATE_FILES_SECURITY"})}})}async function U(j,G,A=!1){if(j=M(j),G==="directory")return Z(j);await q(j,"verify",async()=>{let z=await $(),K=await z.verifyOwnerOnly(j),H=!1;if(!K.ok){let{reason:L}=K.refusal;if(L==="io-error")await z.verifyPrivatePath(j,G);if(A&&[z.EXTRA_ACE,z.NOT_PROTECTED,z.NULL_DACL,z.EMPTY_DACL].includes(L))await Z(V(j)),await z.securePrivatePath(j,G),H=!0;else throw Object.assign(Error("Owner-only verification refused"),{reason:L,code:"ERR_PRIVATE_FILES_SECURITY"})}if(await z.verifyPrivatePath(j,G),H&&!N.has(j))N.add(j),process.emitWarning(`Private permissions tightened: ${j}. This object may have been readable before; rotate credentials if needed.`,"PrivateFileMigration")})}async function w(j,G=!1,A){j=M(j),await q(j,"directory",async()=>{let z=await $();try{return await S(j),await Z(j,A)}catch(H){if(T(H)!=="ENOENT")throw H}let K=V(j);if(K===j)throw Object.assign(Error("Missing root"),{code:"ENOENT"});await w(K,!1,A);try{await z.createOwnerOnly(j,{kind:"dir"})}catch(H){if(T(H)!=="EEXIST")throw H}await Z(j,A)})}async function d(j,G=!1){if(!b)return O(j,"utf8");return(await P(j,G)).toString("utf8")}async function P(j,G=!1){if(!b)return O(j);if(j=M(j),G)await Z(V(j)),await U(j,"file",!0);return q(j,"read",async()=>(await $()).readOwnerOnly(j))}async function f(j,G){await Z(V(M(j))),await q(j,"create",async()=>{await(await $()).createPrivateFile(M(j),G)})}async function l(j){await Z(V(M(j))),await q(j,"directory-create",async()=>{await(await $()).createOwnerOnly(M(j),{kind:"dir"})})}async function y(j,G,A={}){j=M(j),G=M(G);let z=A.now??(()=>performance.now()),K=z(),H=A.deadline??1/0,L,_=[0,10,20,40,80,100],x,J=0;for(let W of _){let I=Math.min(L??1/0,H);if(z()>=I)break;if(W)await(A.sleep??((X)=>new Promise((Y)=>setTimeout(Y,X))))(Math.min(W,Math.max(0,I-z())));if(z()>=I)break;let D=z();if(await A.beforeRename?.(),L!==void 0)L+=z()-D;if(z()>=H)break;J++;try{return await(A.rename??F)(j,G),{attempts:J,elapsedMs:z()-K}}catch(X){x??=X;let Y=X;if(!(Y.win32Code!==void 0?Y.win32Code===32||Y.win32Code===33:["EBUSY","EPERM","EACCES"].includes(Y.code??"")&&!Y.reason))break;L??=z()+500}}let Q=new R(G,"rename",x??Object.assign(Error("Publication deadline expired"),{code:"ETIMEDOUT"}));throw Q.attempts=J,Q.elapsedMs=z()-K,Q}async function n(j,G,A={}){j=M(j),await w(V(j));try{await U(j,"file",!0)}catch(J){if(J.code!=="ENOENT")throw J}let z=M(A.stagePath??`${j}.${k()}.tmp`);if(V(z)!==V(j))throw new R(j,"stage-directory",{code:"EXDEV"});let K=!1,H=!1,L={attempts:0,elapsedMs:0},_="stage-create",x=(J)=>{try{A.onOutcome?.({path:j,stage:J?.stage??"published",published:H,fileDurable:H,durabilityConfirmed:!1,attempts:J?.attempts??L.attempts,elapsedMs:J?.elapsedMs??L.elapsedMs,...J&&{code:J.code,win32Code:J.win32Code}})}catch{}};try{if(await f(z,G),K=!0,_="before-rename",L=await y(z,j,A),K=!1,H=!0,_="published-callback",A.onRenamed?.(),_="published-verify",await U(j,"file"),A.durable&&A.durability!=="file-only-on-windows")throw new R(j,"directory-sync-unsupported",{code:"ENOTSUP"});x()}catch(J){let Q=J instanceof R?J:new R(j,_,J);if(Q.published=H,Q.fileDurable=H,H)Object.assign(Q,L);if(K){try{await C(z)}catch{Q.orphanPath=z}K=!1}throw x(Q),Q}finally{if(K)await C(z).catch(()=>{})}}
|
|
2
|
+
export{b as Ue,R as Ve,q as We,Z as Xe,U as Ye,w as Ze,d as _e,f as $e,l as af,y as bf,n as cf};
|