@cortexkit/opencode-openai-auth 1.16.0 → 1.17.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 +2 -2
- package/dist/{index-ryj7dj32.js → index-0mhdyzax.js} +26 -26
- package/dist/{index-29mjazwp.js → index-1m3vv9rh.js} +2 -2
- package/dist/index-3dv16qvb.js +101 -0
- package/dist/{index-t4dwp124.js → index-6ts9w66n.js} +1 -1
- package/dist/{index-2r3vgg9c.js → index-99c2fepe.js} +2 -2
- package/dist/{index-7rh2vrrx.js → index-d7bsrp0m.js} +1 -1
- package/dist/{index-cwsxvbag.js → index-dqxk628t.js} +2 -2
- package/dist/{index-9q49makj.js → index-fxqghceg.js} +1 -1
- package/dist/{index-78q36xet.js → index-k2f9vrcr.js} +1 -1
- package/dist/{index-dyc6v3ba.js → index-rm4zt5dv.js} +20 -20
- package/dist/{index-qtkf7nzb.js → index-v9p38mg5.js} +2 -2
- package/dist/{index-mrt0rqtz.js → index-vmcmpezd.js} +1 -1
- package/dist/{index-chp9keaz.js → index-xx2z6bs3.js} +2 -2
- package/dist/{index-ea3ykjex.js → index-ydtpn6ma.js} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/{token-19s0jcbk.js → token-r3vbz9pw.js} +1 -1
- package/dist/token-util-vks3kgse.js +1 -0
- package/dist/tui-preferences.js +1 -1
- package/dist/v2/server.d.ts +1 -1
- package/dist/v2/server.js +2 -2
- package/package.json +2 -2
- package/src/tui-compiled/raw/shared/0f77ebc3c914c9c6-custody.js +147 -2
- package/src/tui-compiled/raw/shared/352d228be2832bd4-hub.js +47 -1
- package/src/tui-compiled/raw/shared/e8d3c8da776ef9cd-index.js +1 -1
- package/src/tui-compiled/runtime/shared/0f77ebc3c914c9c6-custody.js +147 -2
- package/src/tui-compiled/runtime/shared/352d228be2832bd4-hub.js +47 -1
- package/src/tui-compiled/runtime/shared/e8d3c8da776ef9cd-index.js +1 -1
- package/dist/index-4tpqkbv9.js +0 -101
- package/dist/token-util-3pv487zf.js +0 -1
package/dist/bin.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{c as G1}from"./index-
|
|
2
|
+
import{c as G1}from"./index-6ts9w66n.js";import{$b as K1,Aa as c,Ba as e0,Fc as W1,La as s0,Ma as p,Na as H,Oa as d,rc as Q1,xa as D0,ya as l,za as V0}from"./index-0mhdyzax.js";import{$d as L0,Fe as Z1,Yd as E,Zd as r,be as i0,ce as s,de as A,ee as a0,fe as u,ge as M0,he as S0}from"./index-3dv16qvb.js";import"./index-ydtpn6ma.js";import"./index-v9p38mg5.js";import"./index-dqxk628t.js";import{Ag as B0,Dg as $1,yg as b0}from"./index-k2f9vrcr.js";import{Fg as F0}from"./index-1m3vv9rh.js";import"./index-xx2z6bs3.js";import"./index-vmcmpezd.js";import"./index-d7bsrp0m.js";import{spawn as q1}from"node:child_process";var k=4096,Y1=1048576;class U0{buffer=Buffer.alloc(k);start=0;length=0;truncated=!1;get didTruncate(){return this.truncated}push(z){if(z.length>=k){if(z.length>k||this.length>0)this.truncated=!0;z.copy(this.buffer,0,z.length-k),this.start=0,this.length=k;return}let J=Math.max(0,this.length+z.length-k);if(J>0)this.truncated=!0;this.start=(this.start+J)%k,this.length-=J;let Z=(this.start+this.length)%k,$=Math.min(z.length,k-Z);if(z.copy(this.buffer,Z,0,$),$<z.length)z.copy(this.buffer,0,$);this.length+=z.length}toString(){let z=Buffer.alloc(this.length),J=Math.min(this.length,k-this.start);if(this.buffer.copy(z,0,this.start,this.start+J),J<this.length)this.buffer.copy(z,J,0,this.length-J);let Z=0;while(Z<z.length){let $=z[Z];if($===void 0||($&192)!==128)break;Z++}return z.subarray(Z).toString("utf8")}}var P={run(z,J,Z={}){return new Promise(($)=>{let K=performance.now(),Q=Z.timeoutMs??15000,G=new U0,j=[],B=0,X=!1,W=!1,Y=!1,V;try{V=q1(z,[...J],{env:Z.env??process.env,windowsHide:!0,windowsVerbatimArguments:Z.windowsVerbatimArguments,stdio:["ignore","pipe","pipe"]})}catch{$({exitCode:1,stdout:"",stderr:"",spawnError:!0,signal:null,timedOut:!1,durationMs:performance.now()-K});return}let q=Q>0?setTimeout(()=>{Y=!0,V.kill("SIGTERM")},Q):void 0;V.stdout?.on("data",(U)=>{let R=Y1-B,b=Math.min(R,U.length);if(b>0)j.push(U.subarray(0,b)),B+=b;if(U.length>R)X=!0,V.kill("SIGTERM")}),V.stderr?.on("data",(U)=>G.push(U));let D=!1,x=(U,R)=>{if(D)return;if(D=!0,q)clearTimeout(q);$({exitCode:W?1:X?1:U??1,stdout:Buffer.concat(j,B).toString("utf8"),stderr:G.toString(),stderrTruncated:G.didTruncate,...W?{spawnError:!0}:{},signal:R??null,timedOut:Y,durationMs:performance.now()-K})};V.once("error",()=>{if(W=!0,V.pid===void 0)x(null,null)}),V.once("close",(U,R)=>x(U,R))})}};function i(z,J,Z,$,K,Q=15000){if(J==="win32"&&/\.(cmd|bat)$/i.test(Z)){if(/["%!\r\n]/.test(Z)||$.some((G)=>!/^[a-zA-Z0-9@:/._+-]+$/.test(G)))throw Error("Unsafe batch launcher or argument; use an executable instead.");return z.run("cmd.exe",["/d","/s","/c",`""${Z}" ${$.join(" ")}"`],{env:K,timeoutMs:Q,windowsVerbatimArguments:!0})}return z.run(Z,$,{env:K,timeoutMs:Q})}function H0(z){if(/^[a-zA-Z0-9_:@./-]+$/.test(z))return z;return process.platform==="win32"?`'${z.replaceAll("'","''")}'`:`'${z.replaceAll("'","'\\''")}'`}async function f(z,J,Z,$){let K=J.requestedGrants??$;if(!K)return;let Q=K.map((j)=>({grant:j,...J.approvedName!==void 0&&{grantCommand:`ck auth grant --principal ${H0(`enrolled:${J.approvedName}`)} --selector-kind ${j.selector.exact===void 0?"category":"exact"} --selector ${H0(j.selector.exact??j.selector.category)} --operation ${j.operation}`}})),G={grants:Q,...J.requestedGrantsStatus!==void 0&&{requestedGrantsStatus:J.requestedGrantsStatus}};if(J.requestedGrantsStatus==="dropped")return{...G,state:"older-vault"};try{if(!z.listScoped)return{...G,state:"unconfirmed"};let{token:j}=await M0(Z),B=await z.listScoped(j),X=Q.map((W)=>({...W,reachableLogins:B.rows.filter((Y)=>Y.operations.includes(W.grant.operation)&&(W.grant.selector.exact!==void 0?Y.id===W.grant.selector.exact:Y.categories.includes(W.grant.selector.category))).length}));return{...G,state:X.every((W)=>W.reachableLogins>0)?"reachable":X.some((W)=>W.reachableLogins>0)?"partial":"no-logins",grants:X.map((W)=>{if(W.reachableLogins===0)return W;let{grantCommand:Y,...V}=W;return V})}}catch{return{...G,state:"unconfirmed"}}}function g(z,J="setup"){if(J==="plugin"&&z.requestedGrantsStatus!=="sent")return[];let Z=[],$=z.grants.some((K)=>K.grantCommand)?"run:":"check ck auth status for the approved name before granting access.";if(z.state==="older-vault")Z.push(`Approved. This vault is too old to grant access with the approval; ${$}`);else if(z.state==="no-logins")Z.push(`Approved, but no logins are reachable yet; ${$}`);else if(z.state==="partial")Z.push(`Approved, but some requested access has no reachable logins yet; ${$}`);else if(z.state==="unconfirmed")Z.push(`Approved, but access could not be confirmed; ${z.grants.some((K)=>K.grantCommand)?"check ck auth status or run:":$}`);for(let{grant:K,reachableLogins:Q,grantCommand:G}of z.grants){if(Q!==void 0&&Q>0){let j=K.selector.exact===void 0?`the vault's ${JSON.stringify(K.selector.category)} accounts`:`credential ${JSON.stringify(K.selector.exact)}`;Z.push(`Confirmed ${K.operation} access to ${j} (${Q} reachable ${Q===1?"login":"logins"}).`)}if(G)Z.push(` ${G}`)}return Z}var b1="Pi install failed; run pi install after checking your npm connection.";function B1(z){let J=Buffer.from(z,"utf8");if(J.length<=k)return z;let Z=J.length-k;while(Z<J.length){let $=J[Z];if($===void 0||($&192)!==128)break;Z++}return J.subarray(Z).toString("utf8")}function D1(z){let J=z.indexOf(`
|
|
3
3
|
`);return J<0?"":z.slice(J+1)}class a extends Error{step="pi-install";exitCode;signal;stderrTail;constructor(z){super(b1);this.name="SetupCommandError",this.exitCode=z.exitCode,this.signal=z.signal;let J=z.stderrTruncated?D1(z.stderrTail):z.stderrTail,Z=F0(J);this.stderrTail=B1(typeof Z==="string"?Z:"")}}var V1={opencode:"OpenCode",pi:"Pi"},x1={enrolled:"connected to the vault","not-enrolled":"not connected",unknown:"unknown, check with ck auth status"};function O0({host:z,outcome:J,access:Z},$="setup"){let K=Z?g(Z,$):[];return`${V1[z]}: ${x1[J]}${K.length?` — ${K.join(`
|
|
4
4
|
`)}`:""}`}var U1=new WeakMap;function C0(z,J){if(typeof z!=="object"&&typeof z!=="function"||!z)return;U1.set(z,Object.freeze(J.map((Z)=>Object.freeze({...Z}))))}import{accessSync as C1,constants as R1,existsSync as N1,readFileSync as k1,realpathSync as I1,statSync as _1}from"node:fs";import{mkdtemp as w1,rm as A1}from"node:fs/promises";import{tmpdir as T1}from"node:os";import{join as P1}from"node:path";import{parse as L1}from"jsonc-parser";import{homedir as H1}from"node:os";import{posix as M1,win32 as F1}from"node:path";import{fileURLToPath as O1}from"node:url";function I(z={}){let J=z.env??process.env,Z=z.platform??process.platform,$=Z==="win32"?F1:M1,K=z.home??(Z==="win32"?J.USERPROFILE:J.HOME)??H1(),Q=z.cwd??process.cwd(),G=(W)=>$.resolve(Q,W),j=J.OPENCODE_CONFIG_DIR?.trim(),B=J.XDG_CONFIG_HOME?.trim(),X=J.PI_CODING_AGENT_DIR?.trim()||$.join(K,".pi","agent");if(X==="~")X=K;else if(/^~[/\\]/.test(X))X=$.join(K,X.slice(2));if(X.startsWith("file://"))X=O1(X);return{env:J,platform:Z,path:$,home:K,cwd:Q,opencode:j?G(j):B?$.join(G(B),"opencode"):$.join(K,".config","opencode"),pi:G(X)}}function z0(z,J){try{return _1(z)[J]()}catch{return!1}}var L={exists:N1,isFile:(z)=>z0(z,"isFile"),isDirectory:(z)=>z0(z,"isDirectory"),isExecutable(z){try{return C1(z,R1.X_OK),z0(z,"isFile")}catch{return!1}},readText:(z)=>k1(z,"utf8"),realpath:I1};function w(z,J={}){let{env:Z,platform:$,path:K,cwd:Q}=I(J),G=J.fs??L,j=Object.entries(Z).find(([X])=>$==="win32"?X.toUpperCase()==="PATH":X==="PATH")?.[1]??"",B=$==="win32"?[".exe",".cmd",".bat",""]:[""];for(let X of j.split($==="win32"?";":":")){let W=X.trim().replace(/^"|"$/g,"");if(!W)continue;for(let Y of B){let V=K.resolve(Q,W,z+Y);if($==="win32"?G.isFile(V):G.isExecutable(V))return V}}return null}function R0(z={}){let{platform:J,home:Z,env:$,path:K}=I(z);if(J==="darwin")return["/Applications/OpenCode.app","/Applications/OpenCode Beta.app",K.join(Z,"Applications","OpenCode.app"),K.join(Z,"Applications","OpenCode Beta.app")];if(J==="win32"){let Q=$.LOCALAPPDATA||K.join(Z,"AppData","Local");return[K.join(Q,"Programs","opencode"),K.join(Q,"opencode")]}return["/opt/OpenCode","/usr/lib/opencode",K.join(Z,".local","share","applications","opencode.desktop")]}function J0(z,J){let Z=J.fs??L,{path:$}=I(J);try{let K=Z.readText(z);if(K.length>65536)return z;let Q=[...K.matchAll(/"%~?dp0%?\\([^"%\r\n]+)"/g)];if(!Q.length)Q.push(...K.matchAll(/"\$basedir\/([^"$\r\n]+)"/g));let G=Q.at(-1)?.[1];if(G){let j=$.join($.dirname(z),...G.split(/[/\\]+/));if(Z.isFile(j))return Z.realpath(j)}return Z.realpath(z)}catch{return z}}function S1(z,J){let Z=J.fs??L,{path:$}=I(J),K=$.dirname(J0(z,J));for(;;){try{let G=JSON.parse(Z.readText($.join(K,"package.json")));if(["@opencode/cli","@opencode-ai/cli"].includes(G.name))return"2";if(G.name==="opencode-ai")return/^(?:[2-9]\d*|1\d+)\.|^0\.0\.0-(?:beta|dev)-/.test(G.version??"")?"2":"1"}catch{}let Q=$.dirname(K);if(Q===K)return null;K=Q}}function N0(z={}){let J=w("opencode",z),Z=w("opencode2",z),$=J&&Z&&J0(J,z)===J0(Z,z),K=z.fs??L,{path:Q,opencode:G}=I(z),j="1";for(let X of["jsonc","json"]){let W=Q.join(G,`opencode.${X}`);if(!K.exists(W))continue;try{if(Object.hasOwn(L1(K.readText(W))??{},"plugins"))j="2"}catch{}break}let B=J?S1(J,z)??($?"2":j):null;if(Z&&B==="1"&&!$)return"ambiguous";return Z||$?"2":B??j}async function Z0(z,J={}){let Z=J.fs??L,{env:$,platform:K,opencode:Q,pi:G}=I(J),j=J.runner??P,B=w("opencode",J)??w("opencode2",J),X=w("pi",J),W=w("ck",J),Y=async(x)=>{if(!x)return null;let U;try{U=await w1(P1(T1(),"common-auth-setup-version-"));let R={...$,HOME:U,USERPROFILE:U,XDG_CONFIG_HOME:U,XDG_DATA_HOME:U,XDG_STATE_HOME:U,XDG_CACHE_HOME:U,OPENCODE_CONFIG_DIR:U,OPENCODE_CONFIG:void 0,OPENCODE_CONFIG_CONTENT:void 0,OPENCODE_AUTH_CONTENT:void 0,PI_CODING_AGENT_DIR:U},b=await i(j,K,x,["--version"],R,2000);return b.exitCode===0?/\b\d+\.\d+\.\d+(?:-[\w.-]+)?/.exec(b.stdout)?.[0]??null:null}catch{return null}finally{if(U)await A1(U,{recursive:!0,force:!0}).catch(()=>{})}},V=!1;if(W&&Z.exists(z.vault.connectionFile))try{(await(J.connect??s)({connectionFile:z.vault.connectionFile,handshakeTimeoutMs:2000})).close(),V=!0}catch{V=!1}let[q,D]=await Promise.all([Y(B),Y(X)]);return{opencode:{installed:Z.isDirectory(Q)||R0(J).some((x)=>Z.exists(x))||B!==null,executable:B,version:q,directory:Q,generation:N0(J)},pi:{installed:X!==null||Z.isDirectory(G),executable:X,version:D,directory:G},claustrum:{available:V,executable:W}}}import{setTimeout as d1}from"node:timers/promises";import{writeEnrollmentTokenFile as p1}from"@cortexkit/claustrum-client";var k0=45000,$0=new Set(["opencode","litecode","opencode2","pi"]),_0=new Set(["node","bun"]),v1=[...$0,..._0].map((z)=>`Name LIKE '${z}%'`).join(" OR "),y1=`$ErrorActionPreference = 'Stop'; $rows = @(Get-CimInstance Win32_Process -Filter "${v1}" | Select-Object Name,ProcessId,CommandLine); ConvertTo-Json -Compress -Depth 3 -InputObject @{ complete = $true; processes = $rows }`,E1=/(?:^|[/\\])pi-coding-agent[/\\]dist[/\\](?:(?:bundle|bun)[/\\])?cli\.m?js$/i;function f1(z){return[...z.matchAll(/"([^"]*)"|(\S+)/g)].map((J)=>J[1]??J[2]??"")}function I0(z){return(z.split(/[/\\]/).pop()??"").toLowerCase().replace(/\.(?:exe|cmd|bat|m?js)$/,"")}var g1=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"]),h1=new Set(["-e","--eval","-p","--print"]);function m1(z,J){for(let Z=0;Z<J.length;Z++){let $=J[Z]??"";if($==="--")return J[Z+1];if(h1.has($))return;if($.startsWith("-")){if(!$.includes("=")&&g1.has($))Z++;continue}if(z==="bun"&&$==="run")continue;return $}return}function w0(z){let[J,...Z]=f1(z);if(J===void 0)return null;let $=I0(J);if($0.has($))return $;if(!_0.has($))return null;let K=m1($,Z);if(K===void 0)return null;let Q=I0(K);if($0.has(Q))return Q;return E1.test(K)?"pi":null}class C extends Error{code="process-inspection-failed";step;exitCode;signal;timedOut;durationMs;constructor(z){super("Process inspection failed; setup cannot prove hosts are stopped.");this.name="ProcessInspectionError",this.step=z.step,this.exitCode=z.exitCode,this.signal=z.signal,this.timedOut=z.timedOut,this.durationMs=z.durationMs}get refusalText(){let z=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}: ${z} after ${Math.round(this.durationMs)} ms.`}}class y extends Error{activeHosts;constructor(z){let J=z.map((Z)=>({pid:Z.pid,command:w0(Z.command)??"host"}));super(`OpenCode or Pi processes are currently running:
|
|
5
5
|
${J.map((Z)=>` - PID ${Z.pid}: ${Z.command}`).join(`
|
|
@@ -10,5 +10,5 @@ Please quit all OpenCode, LiteCode, and Pi processes before running setup.`);thi
|
|
|
10
10
|
`:`
|
|
11
11
|
`}},G=z,j=K[J],B=Array.isArray(j)?[...j]:[],X=B.flatMap((V,q)=>X0(V)===Z?[q]:[]),W=`${Z}@${$}`;if(!X.length)G=G0(G,d0(G,j===void 0?[J]:[J,B.length],j===void 0?[W]:W,Q));else{let V=X[0],q=B[V],D=Array.isArray(q)?[W,...q.slice(1)]:q&&typeof q==="object"?{...q,package:W}:W;if(JSON.stringify(q)!==JSON.stringify(D))G=G0(G,d0(G,[J,V],D,Q));for(let x of X.slice(1).reverse())G=p0(G,J,x)}let Y=J==="plugin"?"plugins":"plugin";if(Array.isArray(K[Y])){let V=K[Y];for(let q=V.length-1;q>=0;q--)if(X0(V[q])===Z)G=p0(G,Y,q)}return G}function W0(z,J,Z={}){let $=Z.fs??L,{path:K,opencode:Q}=I(Z),G=J==="2"?"plugins":"plugin";return(J==="2"?["opencode"]:["opencode","tui"]).map((B)=>{let X=K.join(Q,`${B}.jsonc`),W=K.join(Q,`${B}.json`),Y=$.exists(X)?X:$.exists(W)?W:X,V=$.exists(Y),q=V?$.readText(Y):`${JSON.stringify({$schema:`https://opencode.ai/${B==="tui"?"tui":"config"}.json`},null,2)}
|
|
12
12
|
`,D=c0(q,G),x=[],U=[];for(let b of["plugin","plugins"]){if(!Array.isArray(D[b]))continue;for(let F of D[b]){let N=u0(F);if(N===null)continue;if(X2(N,Y,Z)===z.packages.opencode)x.push(JSON.stringify(F));else if(X0(F)===z.packages.opencode)U.push(JSON.stringify(F))}}if(x.length>0)return{path:Y,content:q,changed:!1,existingLocalEntries:x,existingNpmEntries:U};let R=l0(q,G,z.packages.opencode,z.version);return{path:Y,content:R,changed:!V||R!==q}})}async function j0(z,J){for(let Z of z){if(!Z.changed)continue;await J?.(),await m0(Z.path,Z.content,{beforeRename:J})}}async function q0(z,J,Z={}){let{platform:$,env:K}=I(Z),Q=await i(Z.runner??P,$,J,["install",`npm:${z.packages.pi}@${z.version}`],K);if(Q.exitCode!==0||Q.timedOut)throw new a({exitCode:Q.spawnError?null:Q.exitCode,signal:Q.signal??null,stderrTail:Q.stderr,stderrTruncated:Q.stderrTruncated??!1})}var r0="Multiple OpenCode generations found. Choose --opencode=1|2|both before running noninteractive setup.";function W2(z){for(let J of Object.values(z.packages))if(!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/.test(J))throw Error("Setup requires npm package names.");if(!/^\d+\.\d+\.\d+(?:-[a-zA-Z0-9.-]+)?(?:\+[a-zA-Z0-9.-]+)?$/.test(z.version))throw Error("Setup requires a concrete package version.");for(let J of Object.values(z.vault.hosts)){if(!/^[a-z0-9][a-z0-9-]*$/.test(J.name))throw Error("Setup requires lowercase vault names containing only letters, digits and dashes.");if(J.requestedGrants!==void 0&&!i0(J.requestedGrants))throw Error("invalid Claustrum enrollment requested grants");if(J.grantFallback!==void 0&&J.grantFallback!=="setup"&&J.grantFallback!=="plugin")throw Error("invalid Claustrum enrollment grant fallback")}}async function j2(z,J,Z,$){let K=[];for(let Q of J){let G=Z.get(Q)??"not-enrolled",j=$.get(Q);if(G==="unknown"){let{name:B,paths:X}=z.vault.hosts[Q],W=await u(A(X),B).catch(()=>"unreadable");if(W==="vault"||W==="host")G="enrolled";else if(W==="local")G="not-enrolled";if(G==="enrolled"){let Y=await a0(A(X),B).catch(()=>{return});if(Y?.state==="approved")j=await f({},Y,A(X).tokenPath,z.vault.hosts[Q].requestedGrants)}}K.push({host:Q,outcome:G,...j&&{access:j}})}return K}async function Y0(z,J=[],Z={}){let $=g0(J);if(r())throw Error(E);W2(z);let K=Z.terminal??s0(),Q=await Z0(z,Z);H(K,`${z.displayName} setup`);for(let[b,F]of[["OpenCode",Q.opencode],["Pi",Q.pi]])H(K,`${b}: ${F.installed?`found (version ${F.version??"unknown"})`:"not found"} — ${F.directory}`);H(K,`Claustrum: ${Q.claustrum.available?"available":"not available"}`);let G=Q.pi.installed&&!Q.pi.executable;if(G)H(K,"Pi: skipped, because its folder exists but pi is not on PATH. Install the Pi CLI and rerun setup to add it.");let j=["opencode","pi"].filter((b)=>Q[b].installed&&!(b==="pi"&&G));if($.hosts.some((b)=>!j.includes(b)))throw Error(f0);let B=$.yes||$.dryRun&&!p(K);if(!B&&!p(K))throw Error("Setup requires a TTY or --yes.");let X=$.hosts.length?j.filter((b)=>$.hosts.includes(b)):B?j:await h0(K,j)??[],W=$.opencode??(Q.opencode.generation==="ambiguous"?"1":Q.opencode.generation);if(X.includes("opencode")&&!$.opencode&&Q.opencode.generation==="ambiguous"){if(B||!p(K))throw Error(r0);let b=await d(K,[{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(b===null)return{hosts:[],dryRun:$.dryRun,mode:"local",detection:Q};W=b}if(!X.length)return H(K,"No hosts selected. Install OpenCode or Pi and rerun setup."),{hosts:X,dryRun:$.dryRun,mode:"local",detection:Q};let{env:Y,platform:V}=I(Z),q=Z.fence??h(Z.runner??P,{platform:V}),D=async()=>{try{await m(q,Y)}catch(b){if(b instanceof C)H(K,b.refusalText);throw b}};if(H(K,"Checking that OpenCode and Pi are not running…"),$.dryRun)try{let b=q.previewRunningHosts?await q.previewRunningHosts(Y):{hosts:await q.listRunningHosts(Y),uncheckedRuntimes:0},F=b.hosts;if(b.uncheckedRuntimes>0)H(K,"Node or Bun programs are running; a real run checks whether any of them is OpenCode or Pi.");let N=new Set(new y(F).activeHosts.map((O)=>O.command.toLowerCase()==="pi"?"Pi":"OpenCode"));for(let O of N)H(K,`${O} is running; setup will ask you to quit it.`)}catch(b){if(H(K,"Process inspection failed; real setup will require successful inspection and stopped OpenCode/Pi hosts."),b instanceof C)H(K,b.refusalText)}else await D();if(($.claustrum||$.enrollOnly)&&!Q.claustrum.available)throw Error("Claustrum is not available. Start ck, or omit vault-only flags and use --no-claustrum for local sign-in.");let x=$.claustrum||$.enrollOnly;if(!x&&!$.login&&!$.noClaustrum&&!B&&Q.claustrum.available&&p(K)){let b=await d(K,[{label:"No",value:!1},{label:"Yes",value:!0}],{message:"Connect these hosts to the Claustrum vault?"});if(b===null)return H(K,"Setup cancelled. Nothing was changed."),{hosts:[],dryRun:$.dryRun,mode:"local",detection:Q};x=b===!0}let U=x?"claustrum":"local",R=!$.enrollOnly&&X.includes("opencode")?W0(z,W,Z):[];for(let b of R){for(let N of b.existingLocalEntries??[])H(K,`OpenCode: already registered from ${N} in ${b.path}.`);let F=[...b.existingLocalEntries??[],...b.existingNpmEntries??[]];if(F.length>1)H(K,`Warning: ${z.displayName} may load twice in ${b.path}: ${F.join(", ")}. Entries were left unchanged.`)}if($.dryRun){H(K,"Dry run: no registrations, enrollment, sign-in or migration will be performed.");for(let b of X){if(z.beforeSignIn)H(K,`Would run beforeSignIn(${b}, ${U}).`);if(x){let F=A(z.vault.hosts[b].paths);H(K,`Would Connect ${b}: write ${F.statePath} and ${F.tokenPath}; wait for ck auth enroll approve.`)}else H(K,`Would sign in locally for ${b}.`);if(!$.enrollOnly&&z.beforeRegister)H(K,`Would run beforeRegister(${b}, ${U}).`)}for(let b of R)H(K,`${b.changed?"Would write":"Unchanged"} ${b.path}:
|
|
13
|
-
${b.content}`);if(!$.enrollOnly&&X.includes("pi"))H(K,`Would run ${Q.pi.executable} install npm:${z.packages.pi}@${z.version}`);if(!$.enrollOnly&&z.migrate)for(let b of X)H(K,`Would migrate ${b} using the plugin callback (provider-specific writes).`)}else{let b={opencodeGeneration:W,mode:U,hosts:Object.freeze([...X]),piAgentDir:Q.pi.directory},F=new Map,N=new Map;try{for(let O of X){if(await D(),await z.beforeSignIn?.(O,b),await D(),x){F.set(O,"unknown");try{let M=await E0(z,O,Z,K,D);if(M)N.set(O,M)}catch(M){if(M instanceof _)F.set(O,"not-enrolled");throw M}F.set(O,"enrolled")}else await z.signInLocal(O,b);if(await D(),$.enrollOnly)continue;if(await z.beforeRegister?.(O,U,b),await D(),O==="opencode")await j0(R,D);else await q0(z,Q.pi.executable,Z);await D(),await z.migrate?.(O,b)}}catch(O){if(F.size===0)throw O;try{let M=await j2(z,X,F,N);C0(O,M);for(let T of M)H(K,O0(T,z.vault.hosts[T.host].grantFallback))}catch{}throw O}}if(H(K,`${$.dryRun?"Planned":$.enrollOnly?"Enrolled":"Configured"} ${z.displayName} for ${X.join(", ")} (${U}).`),$.enrollOnly)H(K,`Enroll-only: no host config or plugin registration ${$.dryRun?"will be":"was"} written.`),H(K,"Next: register the plugin yourself in each selected host and enable vault access as required by the plugin.");else H(K,`Next: ${X.includes("opencode")?"start OpenCode":"start Pi"} and run ${z.slashCommand}.`);return{hosts:X,dryRun:$.dryRun,mode:U,detection:Q}}var S={name:"@cortexkit/opencode-openai-auth",version:"1.
|
|
13
|
+
${b.content}`);if(!$.enrollOnly&&X.includes("pi"))H(K,`Would run ${Q.pi.executable} install npm:${z.packages.pi}@${z.version}`);if(!$.enrollOnly&&z.migrate)for(let b of X)H(K,`Would migrate ${b} using the plugin callback (provider-specific writes).`)}else{let b={opencodeGeneration:W,mode:U,hosts:Object.freeze([...X]),piAgentDir:Q.pi.directory},F=new Map,N=new Map;try{for(let O of X){if(await D(),await z.beforeSignIn?.(O,b),await D(),x){F.set(O,"unknown");try{let M=await E0(z,O,Z,K,D);if(M)N.set(O,M)}catch(M){if(M instanceof _)F.set(O,"not-enrolled");throw M}F.set(O,"enrolled")}else await z.signInLocal(O,b);if(await D(),$.enrollOnly)continue;if(await z.beforeRegister?.(O,U,b),await D(),O==="opencode")await j0(R,D);else await q0(z,Q.pi.executable,Z);await D(),await z.migrate?.(O,b)}}catch(O){if(F.size===0)throw O;try{let M=await j2(z,X,F,N);C0(O,M);for(let T of M)H(K,O0(T,z.vault.hosts[T.host].grantFallback))}catch{}throw O}}if(H(K,`${$.dryRun?"Planned":$.enrollOnly?"Enrolled":"Configured"} ${z.displayName} for ${X.join(", ")} (${U}).`),$.enrollOnly)H(K,`Enroll-only: no host config or plugin registration ${$.dryRun?"will be":"was"} written.`),H(K,"Next: register the plugin yourself in each selected host and enable vault access as required by the plugin.");else H(K,`Next: ${X.includes("opencode")?"start OpenCode":"start Pi"} and run ${z.slashCommand}.`);return{hosts:X,dryRun:$.dryRun,mode:U,detection:Q}}var S={name:"@cortexkit/opencode-openai-auth",version:"1.17.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 && cp ../core/openai-auth.schema.json dist/openai-auth.schema.json","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.48.0","@cortexkit/openai-auth-core":"workspace:*","@cortexkit/opencode-sidebar":"0.1.0","@opencode/plugin":"2.2.6"},dependencies:{"@cortexkit/claustrum-client":"^0.18.0","@cortexkit/private-files":"^0.2.2","@cortexkit/subc-client":"^0.24.0","@opentui/core":">=0.8.3","@opentui/solid":">=0.8.3",ai:"^7.0.165","jsonc-parser":"^3.3.1","solid-js":"1.9.18"}};import{basename as V2}from"node:path";import{resolveClaustrumConnectionPath as x2}from"@cortexkit/claustrum-client";var o0={name:"@cortexkit/pi-openai-auth",version:"1.17.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 jsonc-parser --external @cortexkit/claustrum-client --external @cortexkit/subc-client --minify && bun run build:types && cp ../core/openai-auth.schema.json dist/openai-auth.schema.json","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.48.0","@cortexkit/openai-auth-core":"workspace:*"},dependencies:{"@cortexkit/claustrum-client":"^0.18.0","@cortexkit/private-files":"^0.2.2","@cortexkit/subc-client":"^0.24.0","jsonc-parser":"^3.3.1"},peerDependencies:{"@earendil-works/pi-ai":">=1.0.1","@earendil-works/pi-coding-agent":">=1.0.1","@earendil-works/pi-tui":">=1.0.1"}};import{existsSync as n}from"node:fs";import{homedir as t}from"node:os";import{join as e,resolve as n0}from"node:path";import{fileURLToPath as b2}from"node:url";var t0=new Set;function B2(){let z=process.env.PI_CODING_AGENT_DIR;if(!z)return e(t(),".pi","agent");if(process.platform==="win32"&&z.startsWith("/")&&!z.startsWith("//")&&!z.includes("\\")){let J=z.match(/^\/(?:mnt\/|cygdrive\/)?([a-z])(?:\/(.*))?$/i);if(J?.[1])z=`${J[1].toUpperCase()}:\\${J[2]?.replaceAll("/","\\")??""}`}if(z==="~")return t();if(z.startsWith("~/")||process.platform==="win32"&&z.startsWith("~\\"))return e(t(),z.slice(2));return z.startsWith("file://")?b2(z):z}function z1(z=B2()){let J=process.env.PI_OPENAI_AUTH_FILE?.trim();if(J)return J;let Z=e(z,b0),$=e(t(),".pi","agent",b0),K=(G)=>{let j=B0(G),B=e0(c(j),"pi");return n(G)||n(j)||n(B.tokenPath)||n(B.statePath)};if(n0(Z)===n0($)||K(Z)||!K($))return Z;let Q=`${Z}\x00${$}`;if(!t0.has(Q))t0.add(Q),console.warn(`openai-auth is using its store in the legacy Pi agent directory: ${$} (${Z} has no store). Credentials were not copied or moved. Set PI_OPENAI_AUTH_FILE to choose a store explicitly.`);return $}function D2(z=z1()){return process.env.PI_OPENAI_AUTH_STATE_FILE?.trim()||B0(z)}function J1(z=z1()){return{configPath:z,statePath:D2(z)}}function X1(z={}){let J=z.print??console.log,Z=z.fence??h(),$={opencode:{stateDir:c(K1().statePath),host:"opencode"},pi:{stateDir:c(J1().statePath),host:"pi"}},K=async(Q)=>{let G=await u(A($[Q]),l(Q));if(G==="host")throw Error(E);if(G!=="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:S.name,pi:o0.name},version:S.version,displayName:"OpenAI Auth",slashCommand:"/openai",vault:{connectionFile:x2(),hosts:{opencode:{name:l("opencode"),displayName:V0("opencode"),requestedGrants:D0,paths:$.opencode},pi:{name:l("pi"),displayName:V0("pi"),requestedGrants:D0,paths:$.pi}}},async beforeRegister(Q,G){if(await u(A($[Q]),l(Q))==="host")throw Error(E);if(G==="claustrum"){if(Q==="opencode")J("Then run opencode auth login and choose ChatGPT accounts in the vault to activate vault routing without local sign-in.");return}await K(Q)},async signInLocal(Q,G){if(await K(Q),Q==="pi"){J("Start Pi and run /login openai-codex to sign in with Pi itself.");return}if(G.opencodeGeneration!=="1"){let U=V2(w("opencode2",z.io)??w("opencode",z.io)??"opencode");J(`In OpenCode 2, run ${U} 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(G.opencodeGeneration==="2")return;if(Q1(process.env))throw Error("Unset OPENCODE_AUTH_CONTENT before local setup sign-in.");let j=G1(),B={path:{id:"openai"}};if(await j.get(B)!==void 0){J("OpenCode already has an OpenAI login. Use opencode auth login to change it.");return}let X=z.beginLogin??Z1,W=new AbortController,Y=Boolean(process.env.SSH_CONNECTION||process.env.SSH_TTY||process.platform==="linux"&&!process.env.DISPLAY&&!process.env.WAYLAND_DISPLAY),V={version:S.version,signal:W.signal},q,D=!Y;try{q=await X({...V,headless:Y})}catch(U){if(Y)throw U;D=!1,J("Browser callback unavailable; using device-code sign-in."),q=await X({version:S.version,headless:!0})}if(D){if(!(z.openBrowser??$1)(q.url))W.abort(),await q.completion.catch(()=>{}),J("Browser unavailable; using device-code sign-in."),q=await X({version:S.version,headless:!0})}J(`${q.url}
|
|
14
14
|
${q.instructions}`);let x=await q.completion;await m(Z),await K(Q),await j.set({...B,body:{type:"oauth",access:x.access,refresh:x.refresh,expires:x.expires,...x.accountId?{accountId:x.accountId}:{}}}),J("Signed in to OpenCode. The first plugin start adopts this login into the account pool.")},async migrate(Q){J(`${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 W1({version:S.version}),await Y0(X1(),process.argv.slice(3))}catch(z){console.error(z instanceof Error?z.message:String(z)),process.exitCode=1}
|