anyray-connect 0.11.220 → 0.11.221

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  var aG=Object.defineProperty;var F=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(r){throw n=[r],r}};var xy=(e,t)=>{for(var n in t)aG(e,n,{get:t[n],enumerable:!0})};var sG,nl,uI,iG,cG,Fe,rr,_t,Ry,lG,pI,$n,De,Be=F(()=>{"use strict";sG="http://localhost:8787",nl="anyray-placeholder",uI=/^ark_[A-Za-z0-9_-]{20,512}$/,iG="ark_svc_",cG=/^ark_svc_[A-Za-z0-9_-]{20,512}$/,Fe=e=>{let t=e?.trim();return!!(t&&uI.test(t))},rr=e=>{let t=e?.trim();if(t){if(cG.test(t))return"service";if(!t.startsWith(iG))return uI.test(t)?"personal":void 0}},_t=e=>{let t=e.trim().replace(/\/+$/,"");return t=t.replace(/\/v1$/,""),t},Ry=(e,t)=>e?.trim()||process.env[t]?.trim()||void 0,lG=new Set(["localhost","127.0.0.1","::1","0.0.0.0"]),pI=e=>{try{let{protocol:t,hostname:n}=new URL(e);return t==="http:"&&!lG.has(n)}catch{return!1}},$n=e=>{let t=_t(e||process.env.ANYRAY_GATEWAY_URL||sG),n;try{n=new URL(t)}catch{throw new Error(`invalid gateway URL: "${t}" (expected e.g. http://localhost:8787)`)}if(n.protocol!=="http:"&&n.protocol!=="https:")throw new Error(`invalid gateway URL: "${t}" \u2014 must start with http:// or https://`);return t},De=(e={})=>{let t=$n(e.origin),n=e.placeholderKey?.trim()||nl,r=e.clientKey?.trim()||process.env.ANYRAY_CLIENT_KEY?.trim()||void 0,o={user:e.user?.trim()||void 0,team:e.team?.trim()||void 0,intent:Ry(e.intent,"ANYRAY_METADATA_INTENT"),intentLabel:Ry(e.intentLabel,"ANYRAY_METADATA_INTENT_LABEL"),session:Ry(e.session,"ANYRAY_METADATA_SESSION")},a=e.subscription?"subscription":e.placeholder?"placeholder":e.seat?"auto":"placeholder";return{origin:t,anthropicBaseUrl:t,openaiBaseUrl:`${t}/v1`,placeholderKey:n,clientKey:r,keyKind:rr(r),authMode:a,byoUpstream:e.byoUpstream,seat:a==="auto"?e.seat:void 0,metadata:o}}});var fI,mI,Fu,Wu=F(()=>{"use strict";fI="/connect/optimize-output",mI=e=>({matcher:"*",hooks:[{type:"http",url:`${e}${fI}`,timeout:2,headers:{"x-anyray-api-key":"$ANYRAY_CLIENT_KEY",Authorization:"Bearer $ANTHROPIC_AUTH_TOKEN"},allowedEnvVars:["ANYRAY_CLIENT_KEY","ANTHROPIC_AUTH_TOKEN"]}]}),Fu=e=>{if(!e||typeof e!="object")return!1;let t=e;if(t.type!=="http"||typeof t.url!="string")return!1;try{let n=new URL(t.url);return["http:","https:"].includes(n.protocol)&&n.pathname===fI&&!n.search&&!n.hash}catch{return!1}}});var or,Qe,Vr,zs,wn=F(()=>{"use strict";or=(e=process.env)=>e.CODESPACES==="true"||e.CODESPACE_NAME?"codespaces":e.REMOTE_CONTAINERS==="true"||e.REMOTE_CONTAINERS_IPC||e.DEVCONTAINER?"devcontainer":e.SSH_CONNECTION||e.SSH_TTY?"ssh":null,Qe=(e=process.env)=>or(e)!==null,Vr=e=>e==="codespaces"||e==="devcontainer",zs=e=>{switch(e){case"codespaces":return"a GitHub Codespace";case"devcontainer":return"a dev container";case"ssh":return"an SSH session"}}});import{randomUUID as dG}from"node:crypto";import{lstat as Oy,open as uG,readFile as _y,rename as Hu,rm as pG,writeFile as fG}from"node:fs/promises";import{platform as hI}from"node:os";var yI,mG,_o,Ra,hG,xe,Wt=F(()=>{"use strict";yI=e=>e?.code==="ENOENT",mG=new Set(["EBUSY","EXDEV","ETXTBSY"]),_o=async(e,t=hI())=>{try{await e.sync()}catch(n){if(t!=="win32")throw n}},Ra=class extends Error{recoveryCopy;code="ANYRAY_PUBLISH_CONFLICT";constructor(t){super("destination changed before publication"),this.recoveryCopy=t,this.name="PublishConflictError"}},hG=async(e,t,n={})=>{let r=await _y(e),o;try{o=await _y(t)}catch(s){if(!yI(s))throw s;await fG(t,r);return}let a=async s=>{let i=await uG(t,"r+");try{await i.write(s,0,s.length,0),await i.truncate(s.length),await _o(i)}finally{await i.close()}};try{if(await a(r),await n.corruptAfterWrite?.(t),!(await _y(t)).equals(r))throw Object.assign(new Error("in-place publication did not persist"),{code:"EIO"})}catch(s){throw await a(o).catch(()=>{}),s}},xe=async(e,t,n=hI(),r={})=>{let o=r.rename??Hu;if(n!=="win32"){try{await o(e,t)}catch(i){if(!mG.has(i?.code??""))throw i;await hG(e,t,r)}return}let a=`${t}.anyray-old-${process.pid}-${dG()}`,s=!1;try{let i=await Oy(t);if(!i.isFile()&&!i.isSymbolicLink())throw new Error("refusing to replace a non-file destination");await Hu(t,a),s=!0}catch(i){if(!yI(i))throw i}if(s&&r.verifyDisplaced){let i=!1;try{i=await r.verifyDisplaced(a)}catch{i=!1}if(!i){let c=!1;try{await Oy(t),c=!0}catch{c=!1}if(c)throw new Ra(a);try{await o(a,t)}catch(l){let d=l?.code==="EEXIST";if(!d)try{await Oy(t),d=!0}catch{d=!1}throw d?new Ra(a):new Error(`destination changed before publication and could not be restored; recovery copy remains at ${a}`,{cause:l})}throw new Ra}}try{await Hu(e,t)}catch(i){if(s)try{await Hu(a,t)}catch{throw new Error(`failed to publish file and restore the previous destination; recovery copy remains at ${a}`)}throw i}s&&await pG(a,{force:!0})}});import{writeFile as Vu,readFile as ol,chmod as Ny,stat as Ly,mkdir as wI,rm as qs}from"node:fs/promises";import{AsyncLocalStorage as yG}from"node:async_hooks";import{randomUUID as gG}from"node:crypto";import{homedir as bI}from"node:os";import{join as Oa}from"node:path";var q,Zu,Dy,Ze,Ku,lt,al,N,wG,bG,kI,kG,CG,Uu,AG,vG,rl,Qs,By,Pt,Py,Ce,Ht,Ty,gI,$y,ju,Po,Yu,te=F(()=>{"use strict";Wt();q=()=>Oa(bI(),".anyray"),Zu=async()=>{let e=q();try{if((await Ly(e)).isDirectory())return Oa(e,"connect.json")}catch{}return e},Dy=()=>Oa(q(),"dev-key.pem"),Ze=async()=>{let e=q(),t;try{if(!(await Ly(e)).isDirectory())t=await ol(e,"utf-8").catch(()=>{}),await qs(e,{force:!0});else return}catch{}if(await wI(e,{recursive:!0,mode:448}),t!==void 0){let n=Oa(e,"connect.json");await Vu(n,t,{mode:384}),await Ny(n,384)}},Ku=async e=>{await Ze();let t=Dy();await Vu(t,e,{mode:384}),await Ny(t,384)},lt=async()=>{try{let e=await ol(Dy(),"utf-8");return e.trim()?e:void 0}catch{return}},al=async()=>{await qs(Dy(),{force:!0}).catch(()=>{})},N=async()=>{try{let e=await ol(await Zu(),"utf-8"),t=JSON.parse(e);return t===null||typeof t!="object"||Array.isArray(t)?{}:t}catch{return{}}},wG=0,bG=3e4,kI=5e3,kG=25,CG=()=>Oa(bI(),".anyray-connect-profile.lock"),Uu=new yG,AG=e=>{try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}},vG=async(e,t)=>{try{let n=JSON.parse(await ol(Oa(e,"owner.json"),"utf-8"));if(typeof n.pid=="number"&&Number.isSafeInteger(n.pid)&&n.pid>0)return!AG(n.pid)}catch{}return Date.now()-(await Ly(e)).mtimeMs>t},rl=class extends Error{constructor(t){super(t),this.name="LockBusyError"}},Qs=async(e,t={})=>{let n=t.waitMs??kI,r=t.staleMs??bG,o=Oa(e,"owner.json"),a=Date.now()+n;for(;;){let s=gG();try{await wI(e,{mode:448});try{await Vu(o,`${JSON.stringify({pid:process.pid,nonce:s})}
3
3
  `,{mode:384})}catch(c){throw await qs(e,{recursive:!0,force:!0}).catch(()=>{}),c}return async()=>{try{JSON.parse(await ol(o,"utf-8")).nonce===s&&await qs(e,{recursive:!0,force:!0})}catch{}}}catch(c){if(c.code!=="EEXIST")throw c}if(!(await vG(e,r).catch(()=>!1)&&await qs(e,{recursive:!0,force:!0}).then(()=>!0).catch(()=>!1))){if(Date.now()>=a)throw new rl(t.busyMessage??`${e} is busy; retry the command`);await new Promise(c=>setTimeout(c,kG))}}},By=(e=kI)=>Qs(CG(),{waitMs:e,busyMessage:"connect profile is busy; retry the command"}),Pt=async(e,t={})=>{if(Uu.getStore()===!0)return e();let n=await By(t.waitMs);try{return await Uu.run(!0,e)}finally{await n()}},Py=async e=>{let t=Object.fromEntries(Object.entries(e).filter(([,o])=>o!==void 0)),n=await Zu(),r=`${n}.${process.pid}.${wG++}.tmp`;await Vu(r,`${JSON.stringify(t,null,2)}
4
- `,{mode:384}),await Ny(r,384);try{await xe(r,n)}catch(o){throw await qs(r,{force:!0}).catch(()=>{}),o}},Ce=async e=>{if(Uu.getStore()===!0){await Py(e);return}let t=await By();try{await Py(e)}finally{await t()}},Ht=async e=>{let t=async()=>{let r=await N(),{next:o,result:a}=e(r);return o&&await Py(o),a};if(Uu.getStore()===!0)return t();let n=await By();try{return await t()}finally{await n()}},Ty=["clientKey","clientKeyExpiresAt","enrolledCert","enrolledCertExpiry","enrolledCertLifetimeMs","enrolledTokenHash"],gI="ssoLink",$y=async()=>{let e=await N();return Ty.some(t=>e[t]!==void 0)?!0:await lt()!==void 0},ju=async()=>{let e=await N(),t=Ty.some(a=>e[a]!==void 0),n=e[gI]!==void 0,r=e.byoUpstream!==void 0,o=await lt()!==void 0;if(t||n||r||e.managedEnrollmentDisabled!==!0){let a={...e};for(let s of Ty)delete a[s];delete a[gI],delete a.byoUpstream,a.managedEnrollmentDisabled=!0,delete a.anyrayFleetManaged,await Ce(a)}if(await al(),await lt())throw new Error(`could not remove the dev key from ${q()}`);return t||n||r||o},Po=async(e,t,n=!1)=>{let r=await N(),o=new Set(r.managedTools??[]),a=new Set(r.revertedTools??[]),s=new Set(r.blockedTools??[]),i=r.offboardedAt;for(let b of e){let w=b.status==="configured"||b.status==="queued";!t&&w&&(o.add(b.id),a.delete(b.id),s.delete(b.id),i=void 0),!t&&b.refused===!0&&s.add(b.id),t&&(b.status==="reverted"||b.status==="queued")&&(o.delete(b.id),a.add(b.id),s.delete(b.id))}n&&(o.clear(),s.clear());let c=[...o].sort(),l=[...r.managedTools??[]].sort(),d=[...a].sort(),u=[...r.revertedTools??[]].sort(),p=[...s].sort(),f=[...r.blockedTools??[]].sort(),h=(b,w)=>b.length===w.length&&b.every((A,C)=>A===w[C]);if(h(c,l)&&r.revertedTools!=null&&h(d,u)&&h(p,f)&&i===r.offboardedAt)return;let{offboardedAt:g,...y}=r;await Ce({...y,...i!==void 0?{offboardedAt:i}:{},managedTools:c,revertedTools:d,blockedTools:p})},Yu=async(e=new Date().toISOString())=>{await Ce({...await N(),offboardedAt:e})}});var Pe,Mn=F(()=>{"use strict";Pe="0.11.220"});import{access as IG,chmod as SG,mkdir as My,open as Uy,readFile as RI,rm as Gn,stat as CI,utimes as EG}from"node:fs/promises";import{createHash as Vy,randomUUID as OI}from"node:crypto";import{readFileSync as _I,statSync as AI}from"node:fs";import{dirname as Zy,join as xG}from"node:path";import{isDeepStrictEqual as ei}from"node:util";var To,PI,vI,RG,_,V,ni,II,TI,No,NI,re,LI,SI,OG,_G,DI,PG,Gy,Fy,Wy,EI,TG,Hy,ti,NG,BI,$I,MI,Xu,xI,Ju,_a,le,ke=F(()=>{"use strict";Wt();To=e=>`${e}.anyray-bak`,PI=async e=>{let t;try{t=await Uy(Zy(e),"r"),await t.sync()}catch(n){if(process.platform!=="win32")throw n}finally{await t?.close().catch(()=>{})}},vI=async(e,t)=>{let n,r;try{n=await Uy(e,"wx",384),await n.writeFile(t,"utf-8"),await _o(n)}catch(o){r=o}finally{await n?.close().catch(()=>{})}if(r)throw n&&await Gn(e,{force:!0}).catch(()=>{}),r;await PI(e)},RG=async e=>{let t;try{t=await Uy(e,"r"),await _o(t)}finally{await t?.close().catch(()=>{})}await PI(e)},_=async e=>{try{return await IG(e),!0}catch{return!1}},V=async e=>{if(!await _(e))return{};let t=await RI(e,"utf-8");if(!t.trim())return{};let n=JSON.parse(t);if(n===null||typeof n!="object"||Array.isArray(n))throw new Error(`${e} is not a JSON object`);return n},ni=class extends Error{constructor(){super("repair deferred: configuration changed before publication")}},II=e=>`${e.dev}:${e.ino}:${e.size}:${e.mtimeNs}:${e.ctimeNs}`,TI=e=>{try{let t=II(AI(e,{bigint:!0})),n=_I(e),r=II(AI(e,{bigint:!0}));if(t!==r)throw new ni;return{raw:n.toString("utf8"),fingerprint:`${r}:${Vy("sha256").update(n).digest("hex")}`}}catch(t){if(t.code==="ENOENT")return{raw:"",fingerprint:"missing"};throw t}},No=e=>{let{raw:t,fingerprint:n}=TI(e),r=t.trim()?JSON.parse(t):{};if(r===null||typeof r!="object"||Array.isArray(r))throw new Error("configuration is not a JSON object");return{value:r,fingerprint:n}},NI=async(e,t,n={})=>{for(let r=0;r<3;r++)try{let o=No(e);if(n.requireExisting&&o.fingerprint==="missing")return"unchanged";let a=JSON.stringify(o.value);return t(o.value),JSON.stringify(o.value)===a?"unchanged":(await re(e,o.value,{backup:n.backup,expectedFingerprint:o.fingerprint}),"written")}catch(o){if(!(o instanceof ni))throw o}return"repair deferred"},re=async(e,t,n={})=>{await My(Zy(e),{recursive:!0,mode:448});let r=To(e);if(n.backup!==!1&&!await _(r)){let a=await _(e),s=a?await RI(e,"utf-8"):`{}
4
+ `,{mode:384}),await Ny(r,384);try{await xe(r,n)}catch(o){throw await qs(r,{force:!0}).catch(()=>{}),o}},Ce=async e=>{if(Uu.getStore()===!0){await Py(e);return}let t=await By();try{await Py(e)}finally{await t()}},Ht=async e=>{let t=async()=>{let r=await N(),{next:o,result:a}=e(r);return o&&await Py(o),a};if(Uu.getStore()===!0)return t();let n=await By();try{return await t()}finally{await n()}},Ty=["clientKey","clientKeyExpiresAt","enrolledCert","enrolledCertExpiry","enrolledCertLifetimeMs","enrolledTokenHash"],gI="ssoLink",$y=async()=>{let e=await N();return Ty.some(t=>e[t]!==void 0)?!0:await lt()!==void 0},ju=async()=>{let e=await N(),t=Ty.some(a=>e[a]!==void 0),n=e[gI]!==void 0,r=e.byoUpstream!==void 0,o=await lt()!==void 0;if(t||n||r||e.managedEnrollmentDisabled!==!0){let a={...e};for(let s of Ty)delete a[s];delete a[gI],delete a.byoUpstream,a.managedEnrollmentDisabled=!0,delete a.anyrayFleetManaged,await Ce(a)}if(await al(),await lt())throw new Error(`could not remove the dev key from ${q()}`);return t||n||r||o},Po=async(e,t,n=!1)=>{let r=await N(),o=new Set(r.managedTools??[]),a=new Set(r.revertedTools??[]),s=new Set(r.blockedTools??[]),i=r.offboardedAt;for(let b of e){let w=b.status==="configured"||b.status==="queued";!t&&w&&(o.add(b.id),a.delete(b.id),s.delete(b.id),i=void 0),!t&&b.refused===!0&&s.add(b.id),t&&(b.status==="reverted"||b.status==="queued")&&(o.delete(b.id),a.add(b.id),s.delete(b.id))}n&&(o.clear(),s.clear());let c=[...o].sort(),l=[...r.managedTools??[]].sort(),d=[...a].sort(),u=[...r.revertedTools??[]].sort(),p=[...s].sort(),f=[...r.blockedTools??[]].sort(),h=(b,w)=>b.length===w.length&&b.every((A,C)=>A===w[C]);if(h(c,l)&&r.revertedTools!=null&&h(d,u)&&h(p,f)&&i===r.offboardedAt)return;let{offboardedAt:g,...y}=r;await Ce({...y,...i!==void 0?{offboardedAt:i}:{},managedTools:c,revertedTools:d,blockedTools:p})},Yu=async(e=new Date().toISOString())=>{await Ce({...await N(),offboardedAt:e})}});var Pe,Mn=F(()=>{"use strict";Pe="0.11.221"});import{access as IG,chmod as SG,mkdir as My,open as Uy,readFile as RI,rm as Gn,stat as CI,utimes as EG}from"node:fs/promises";import{createHash as Vy,randomUUID as OI}from"node:crypto";import{readFileSync as _I,statSync as AI}from"node:fs";import{dirname as Zy,join as xG}from"node:path";import{isDeepStrictEqual as ei}from"node:util";var To,PI,vI,RG,_,V,ni,II,TI,No,NI,re,LI,SI,OG,_G,DI,PG,Gy,Fy,Wy,EI,TG,Hy,ti,NG,BI,$I,MI,Xu,xI,Ju,_a,le,ke=F(()=>{"use strict";Wt();To=e=>`${e}.anyray-bak`,PI=async e=>{let t;try{t=await Uy(Zy(e),"r"),await t.sync()}catch(n){if(process.platform!=="win32")throw n}finally{await t?.close().catch(()=>{})}},vI=async(e,t)=>{let n,r;try{n=await Uy(e,"wx",384),await n.writeFile(t,"utf-8"),await _o(n)}catch(o){r=o}finally{await n?.close().catch(()=>{})}if(r)throw n&&await Gn(e,{force:!0}).catch(()=>{}),r;await PI(e)},RG=async e=>{let t;try{t=await Uy(e,"r"),await _o(t)}finally{await t?.close().catch(()=>{})}await PI(e)},_=async e=>{try{return await IG(e),!0}catch{return!1}},V=async e=>{if(!await _(e))return{};let t=await RI(e,"utf-8");if(!t.trim())return{};let n=JSON.parse(t);if(n===null||typeof n!="object"||Array.isArray(n))throw new Error(`${e} is not a JSON object`);return n},ni=class extends Error{constructor(){super("repair deferred: configuration changed before publication")}},II=e=>`${e.dev}:${e.ino}:${e.size}:${e.mtimeNs}:${e.ctimeNs}`,TI=e=>{try{let t=II(AI(e,{bigint:!0})),n=_I(e),r=II(AI(e,{bigint:!0}));if(t!==r)throw new ni;return{raw:n.toString("utf8"),fingerprint:`${r}:${Vy("sha256").update(n).digest("hex")}`}}catch(t){if(t.code==="ENOENT")return{raw:"",fingerprint:"missing"};throw t}},No=e=>{let{raw:t,fingerprint:n}=TI(e),r=t.trim()?JSON.parse(t):{};if(r===null||typeof r!="object"||Array.isArray(r))throw new Error("configuration is not a JSON object");return{value:r,fingerprint:n}},NI=async(e,t,n={})=>{for(let r=0;r<3;r++)try{let o=No(e);if(n.requireExisting&&o.fingerprint==="missing")return"unchanged";let a=JSON.stringify(o.value);return t(o.value),JSON.stringify(o.value)===a?"unchanged":(await re(e,o.value,{backup:n.backup,expectedFingerprint:o.fingerprint}),"written")}catch(o){if(!(o instanceof ni))throw o}return"repair deferred"},re=async(e,t,n={})=>{await My(Zy(e),{recursive:!0,mode:448});let r=To(e);if(n.backup!==!1&&!await _(r)){let a=await _(e),s=a?await RI(e,"utf-8"):`{}
5
5
  `;if(a||n.tombstoneAbsent!==!1)try{await vI(r,s)}catch(i){if(i.code!=="EEXIST")throw i}}let o=`${e}.anyray-tmp-${process.pid}-${OI()}`;try{if(await vI(o,`${JSON.stringify(t,null,2)}
6
6
  `),n.expectedFingerprint!==void 0){if(TI(e).fingerprint!==n.expectedFingerprint)throw new ni;let a=n.expectedFingerprint.slice(n.expectedFingerprint.lastIndexOf(":")+1);try{await xe(o,e,n.runtimePlatform,{verifyDisplaced:async s=>Vy("sha256").update(_I(s)).digest("hex")===a})}catch(s){throw s instanceof Ra?new ni:s}return}await xe(o,e,n.runtimePlatform),await SG(e,384),await RG(e)}finally{await Gn(o,{force:!0}).catch(()=>{})}},LI=1,SI=3e4,OG=5e3,_G=/^[a-f0-9]{64}$/,DI=e=>`${e}.pending`,PG=e=>`${e}.lock`,Gy=e=>{if(e===void 0)return"null";if(e===null||typeof e!="object")return JSON.stringify(e)??"null";if(Array.isArray(e))return`[${e.map(n=>Gy(n)).join(",")}]`;let t=e;return`{${Object.keys(t).sort().filter(n=>t[n]!==void 0).map(n=>`${JSON.stringify(n)}:${Gy(t[n])}`).join(",")}}`},Fy=(e,t)=>({exists:e,sha256:Vy("sha256").update(Gy(t)).digest("hex")}),Wy=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),EI=e=>Wy(e)&&typeof e.exists=="boolean"&&typeof e.sha256=="string"&&_G.test(e.sha256),TG=e=>Wy(e)&&e.transactionVersion===LI&&EI(e.before)&&EI(e.after)&&Wy(e.journal),Hy=(e,t)=>e.exists===t.exists&&e.sha256===t.sha256,ti=async(e,t)=>{try{return await V(e)}catch{throw new Error(`${t} is malformed; no configuration was changed`)}},NG=e=>{try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}},BI=async e=>{let t=PG(e),n=xG(t,"owner.json");await My(Zy(t),{recursive:!0,mode:448});for(let r=0;r<2;r++){let o=OI();try{await My(t,{mode:448})}catch(s){if(s.code!=="EEXIST")throw s;let i=!1;try{let c=await ti(n,"ownership journal");if(typeof c.pid!="number"||!Number.isSafeInteger(c.pid)||c.pid<=0)throw new Error("lock owner is missing or invalid");let l=Date.now()-(await CI(n)).mtimeMs;i=!NG(c.pid)||l>SI}catch{try{i=Date.now()-(await CI(t)).mtimeMs>SI}catch{i=!1}}if(!i||r>0)throw new Error("ownership transaction already in progress");await Gn(t,{recursive:!0,force:!0});continue}try{await re(n,{pid:process.pid,nonce:o,createdAt:Date.now()},{backup:!1})}catch(s){throw await Gn(t,{recursive:!0,force:!0}).catch(()=>{}),s}let a=setInterval(()=>{(async()=>{try{if((await ti(n,"ownership journal")).nonce!==o)return;let i=new Date;await EG(n,i,i)}catch{}})()},OG);return a.unref(),async()=>{clearInterval(a);try{(await ti(n,"ownership journal")).nonce===o&&await Gn(t,{recursive:!0,force:!0})}catch{}}}throw new Error("ownership transaction already in progress")},$I=async e=>{let t=await _(e),n={};if(t)try{n=await V(e)}catch{throw new Error("configuration is malformed during ownership recovery; it was left unchanged")}return{exists:t,value:n,fingerprint:Fy(t,n)}},MI=async(e,t)=>{let n=DI(t);if(!await _(n))return;let r=await ti(n,"prepared ownership transaction");if(!TG(r))throw new Error("prepared ownership transaction is invalid; no recovery write was attempted");let o=await $I(e),a=await _(t),s=await _(To(e)),i=Hy(o.fingerprint,r.before),c=Hy(o.fingerprint,r.after),l=r.journal.fileExisted;if(c&&(a||l===!1||s)&&(!i||a||s)){await re(t,r.journal,{backup:!1}),await Gn(n,{force:!0});return}if(i){await Gn(n,{force:!0}),a||await le(e);return}throw new Error("configuration changed during an interrupted ownership transaction; recovery files were preserved")},Xu=async(e,t,n)=>{let r=await BI(t);try{return await MI(e,t),await n()}finally{await r()}},xI=async(e,t,n,r)=>{if(!await _(e)){if(n)throw new Error("journaled JSON rollback found a missing prior file");return}let a=await ti(e,"ownership journal");if(!(n&&ei(a,t))){if(!ei(a,r))throw new Error("journaled JSON rollback found a concurrent file edit");n?await re(e,t,{backup:!1}):await Gn(e,{force:!0})}},Ju=async(e,t={})=>{let{configPath:n,current:r,next:o,journalPath:a,journal:s,fileExisted:i}=e,c=await BI(a);try{await MI(n,a);let l=await $I(n),d=Fy(i,r),u=await _(a),p=u?await ti(a,"ownership journal"):void 0,f=p&&typeof p.fileExisted=="boolean"?{...s,fileExisted:p.fileExisted}:s;if(!Hy(l.fingerprint,d)){if(ei(l.value,o)&&p&&ei(p,f))return;throw new Error("configuration changed before the ownership transaction acquired its lock; retry")}if(l.exists&&ei(l.value,o)&&p&&ei(p,f))return;let h=await _(To(n));if(p?.fileExisted===!0&&!h)throw new Error("ownership backup is missing; configuration was left unchanged");if(h&&!p)throw new Error("an unjournaled ownership backup already exists; configuration was left unchanged");let m=DI(a),g={transactionVersion:LI,before:l.fingerprint,after:Fy(!0,o),journal:f};await re(m,g,{backup:!1});try{await re(n,o,p?{backup:!1}:{tombstoneAbsent:!1}),await(t.writeJournal??re)(a,f,{backup:!1}),await Gn(m,{force:!0})}catch(y){try{await xI(n,l.value,l.exists,o)}catch(b){throw new AggregateError([y,b],"ownership journal publication failed and config rollback was incomplete")}try{await xI(a,p??{},u,f),await Gn(m,{force:!0}),!h&&!p&&await le(n)}catch(b){throw new AggregateError([y,b],"ownership journal publication failed after config rollback")}throw y}}finally{await c()}},_a=async e=>{try{return await V(To(e))}catch{return{}}},le=async e=>{await Gn(To(e),{force:!0}).catch(()=>{})}});var sl,GI,LG,FI,Ut,Zr=F(()=>{"use strict";sl=e=>{let t=e.enrolledCert?.payload.keyTtlSeconds;return typeof t=="number"&&Number.isFinite(t)&&t>0?t*1e3:void 0},GI=new Set(["claude-code","codex","opencode","cursor","copilot","copilot-cli","claude-desktop","jetbrains","windsurf","omp"]),LG=10080*60*1e3,FI=(e,t,n=Date.now())=>{let r=[],o=sl(e);o!==void 0&&r.push(o);let a=Date.parse(t??e.clientKeyExpiresAt??"");Number.isFinite(a)&&r.push(a-n);let s=Date.parse(e.enrolledCertExpiry??e.enrolledCert?.payload.expiresAt??"");return Number.isFinite(s)&&r.push(s-n),r.length===0?!1:Math.min(...r)<=LG},Ut=(e,t={},n=Date.now())=>{if(!e.enrolledCert)return!1;let o=(t.toolIds??e.managedTools??[]).some(a=>GI.has(a));return FI(e,t.keyExpiresAt,n)||!o}});import{delimiter as DG,dirname as BG}from"node:path";var ar,Pa,nn,Fn=F(()=>{"use strict";pt();ar=e=>{let{command:t,args:n}=bn([e]);return{command:t,args:n}},Pa=()=>Ta(),nn=(e="",t=process.env.PATH??"",n=zu(),r=Ta())=>{let a=t.split(DG).filter(Boolean).some(s=>s===n)||BG(r)!==n?"anyray-connect":r;return e?`${a} ${e}`:a}});var qu,kn,jy,WI,$G,sr,ri,il,Yy,Ky,MG,GG,FG,HI,Kr=F(()=>{"use strict";qu="anyray-org",kn="x-anyray-api-key",jy=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),WI=e=>{try{return new URL(e).origin}catch{return}},$G=(e,t)=>{if(!jy(e)||typeof e.url!="string")return!1;try{let n=new URL(e.url);return t.includes(n.origin)&&/\/mcp\/org\/?$/.test(n.pathname)}catch{return!1}},sr=(e,t,n,r)=>{let o=e[t];if(o!==void 0&&!jy(o))return"conflict";let a=jy(o)?o:{},s=a[qu];return s!==void 0&&!$G(s,n)?"conflict":r===void 0?s===void 0?"unchanged":(delete a[qu],Object.keys(a).length===0?delete e[t]:e[t]=a,"changed"):JSON.stringify(s)===JSON.stringify(r)?"unchanged":(a[qu]=r,e[t]=a,"changed")},ri="# >>> anyray org mcp >>>",il="# <<< anyray org mcp <<<",Yy=`[mcp_servers.${qu}]`,Ky=e=>JSON.stringify(e),MG=e=>[Yy,`url = ${Ky(e.url)}`,`http_headers = { ${Ky(kn)} = ${Ky(e.clientKey)} }`],GG=new RegExp(`\\n?${ri.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}[\\s\\S]*?${il.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\n?`),FG=e=>{let t=e.indexOf(ri);if(t<0||e.indexOf(il,t+ri.length)>=0)return e;let n=e.slice(t).split(`
7
7
  `),r=1,o=!1,a=!1;for(;r<n.length;){let s=n[r].trim();if(s===Yy){if(o)break;o=!0,r+=1;continue}if(s.startsWith("[")||(s.includes(kn)&&(a=!0),s!==""&&!s.startsWith("#")&&!/^[\w."'-]+\s*=/.test(s)))break;r+=1}return!o||!a?e:e.slice(0,t)+n.slice(r).join(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anyray-connect",
3
- "version": "0.11.220",
3
+ "version": "0.11.221",
4
4
  "description": "Anyray connect \u2014 points local coding tools (Claude Code, Cursor, Windsurf, SDKs) at the Anyray gateway through supported configuration and enrolled personal authentication.",
5
5
  "type": "module",
6
6
  "bin": {