anyray-connect 0.11.260 → 0.11.261
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/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
var P2=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 hb=(e,t)=>{for(var n in t)P2(e,n,{get:t[n],enumerable:!0})};var N2,Bs,J0,L2,D2,He,Ur,nn,yb,B2,Kf,gr,Ge,Be=F(()=>{"use strict";N2="http://localhost:8787",Bs="anyray-placeholder",J0=/^ark_[A-Za-z0-9_-]{20,512}$/,L2="ark_svc_",D2=/^ark_svc_[A-Za-z0-9_-]{20,512}$/,He=e=>{let t=e?.trim();return!!(t&&J0.test(t))},Ur=e=>{let t=e?.trim();if(t){if(D2.test(t))return"service";if(!t.startsWith(L2))return J0.test(t)?"personal":void 0}},nn=e=>{let t=e.trim().replace(/\/+$/,"");return t=t.replace(/\/v1$/,""),t},yb=(e,t)=>e?.trim()||process.env[t]?.trim()||void 0,B2=new Set(["localhost","127.0.0.1","[::1]","::1","0.0.0.0"]),Kf=e=>{try{let{protocol:t,hostname:n}=new URL(e);return t==="http:"&&!B2.has(n)}catch{return!1}},gr=e=>{let t=nn(e||process.env.ANYRAY_GATEWAY_URL||N2),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},Ge=(e={})=>{let t=gr(e.origin),n=e.placeholderKey?.trim()||Bs,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:yb(e.intent,"ANYRAY_METADATA_INTENT"),intentLabel:yb(e.intentLabel,"ANYRAY_METADATA_INTENT_LABEL"),session:yb(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:Ur(r),authMode:a,byoUpstream:e.byoUpstream,seat:a==="auto"?e.seat:void 0,metadata:o}}});var z0,q0,Zf,jf=F(()=>{"use strict";z0="/connect/optimize-output",q0=e=>({matcher:"*",hooks:[{type:"http",url:`${e}${z0}`,timeout:2,headers:{"x-anyray-api-key":"$ANYRAY_CLIENT_KEY",Authorization:"Bearer $ANTHROPIC_AUTH_TOKEN"},allowedEnvVars:["ANYRAY_CLIENT_KEY","ANTHROPIC_AUTH_TOKEN"]}]}),Zf=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===z0&&!n.search&&!n.hash}catch{return!1}}});import{randomUUID as M2}from"node:crypto";import{lstat as gb,open as $2,readFile as wb,rename as Yf,rm as F2,writeFile as G2}from"node:fs/promises";import{platform as Q0}from"node:os";var ex,H2,_a,Ms,W2,Oe,cn=F(()=>{"use strict";ex=e=>e?.code==="ENOENT",H2=new Set(["EBUSY","EXDEV","ETXTBSY"]),_a=async(e,t=Q0())=>{try{await e.sync()}catch(n){if(t!=="win32")throw n}},Ms=class extends Error{recoveryCopy;code="ANYRAY_PUBLISH_CONFLICT";constructor(t){super("destination changed before publication"),this.recoveryCopy=t,this.name="PublishConflictError"}},W2=async(e,t,n={})=>{let r=await wb(e),o;try{o=await wb(t)}catch(s){if(!ex(s))throw s;await G2(t,r);return}let a=async s=>{let i=await $2(t,"r+");try{await i.write(s,0,s.length,0),await i.truncate(s.length),await _a(i)}finally{await i.close()}};try{if(await a(r),await n.corruptAfterWrite?.(t),!(await wb(t)).equals(r))throw Object.assign(new Error("in-place publication did not persist"),{code:"EIO"})}catch(s){throw await a(o).catch(()=>{}),s}},Oe=async(e,t,n=Q0(),r={})=>{let o=r.rename??Yf;if(n!=="win32"){try{await o(e,t)}catch(i){if(!H2.has(i?.code??""))throw i;await W2(e,t,r)}return}let a=`${t}.anyray-old-${process.pid}-${M2()}`,s=!1;try{let i=await gb(t);if(!i.isFile()&&!i.isSymbolicLink())throw new Error("refusing to replace a non-file destination");await Yf(t,a),s=!0}catch(i){if(!ex(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 gb(t),c=!0}catch{c=!1}if(c)throw new Ms(a);try{await o(a,t)}catch(l){let d=l?.code==="EEXIST";if(!d)try{await gb(t),d=!0}catch{d=!1}throw d?new Ms(a):new Error(`destination changed before publication and could not be restored; recovery copy remains at ${a}`,{cause:l})}throw new Ms}}try{await Yf(e,t)}catch(i){if(s)try{await Yf(a,t)}catch{throw new Error(`failed to publish file and restore the previous destination; recovery copy remains at ${a}`)}throw i}s&&await F2(a,{force:!0})}});var Vr,lc=F(()=>{"use strict";Vr=e=>{try{return process.kill(e,0),!0}catch(t){return t.code==="EPERM"}}});import{writeFile as Jf,readFile as dc,chmod as Cb,stat as Ab,mkdir as nx,rm as $s}from"node:fs/promises";import{AsyncLocalStorage as U2}from"node:async_hooks";import{randomUUID as V2}from"node:crypto";import{homedir as rx}from"node:os";import{join as Fs}from"node:path";var q,Md,vb,Te,zf,gt,$d,G,In,wt,K2,Z2,ox,j2,Y2,Xf,ax,X2,J2,Bd,Kr,Sb,Et,bb,Me,Bt,qf,kb,tx,Ib,Qf,Oa,em,ne=F(()=>{"use strict";cn();lc();q=()=>Fs(rx(),".anyray"),Md=async()=>{let e=q();try{if((await Ab(e)).isDirectory())return Fs(e,"connect.json")}catch{}return e},vb=()=>Fs(q(),"dev-key.pem"),Te=async()=>{let e=q(),t;try{if(!(await Ab(e)).isDirectory())t=await dc(e,"utf-8").catch(()=>{}),await $s(e,{force:!0});else return}catch{}if(await nx(e,{recursive:!0,mode:448}),t!==void 0){let n=Fs(e,"connect.json");await Jf(n,t,{mode:384}),await Cb(n,384)}},zf=async e=>{await Te();let t=vb();await Jf(t,e,{mode:384}),await Cb(t,384)},gt=async()=>{try{let e=await dc(vb(),"utf-8");return e.trim()?e:void 0}catch{return}},$d=async()=>{await $s(vb(),{force:!0}).catch(()=>{})},G=async()=>{try{let e=await dc(await Md(),"utf-8"),t=JSON.parse(e);return t===null||typeof t!="object"||Array.isArray(t)?{}:t}catch{return{}}},In=class extends Error{reason;constructor(t){super(`the connect profile could not be ${t==="read"?"read":"parsed"}`),this.reason=t,this.name="ProfileUnreadableError"}},wt=async()=>{let e;try{e=await dc(await Md(),"utf-8")}catch(n){if(n?.code==="ENOENT")return{};throw new In("read")}let t;try{t=JSON.parse(e)}catch{throw new In("parse")}if(t===null||typeof t!="object"||Array.isArray(t))throw new In("parse");return t},K2=0,Z2=3e4,ox=5e3,j2=25,Y2=()=>Fs(rx(),".anyray-connect-profile.lock"),Xf=new U2,ax=async e=>{let t=await dc(Fs(e,"owner.json"),"utf-8").catch(()=>{}),n=await Ab(e,{bigint:!0});return{dev:n.dev,ino:n.ino,mtimeNs:n.mtimeNs,owner:t}},X2=(e,t)=>e.dev===t.dev&&e.ino===t.ino&&e.mtimeNs===t.mtimeNs&&e.owner===t.owner,J2=async(e,t)=>{let n=await ax(e);if(n.owner!==void 0)try{let o=JSON.parse(n.owner);if(typeof o.pid=="number"&&Number.isSafeInteger(o.pid)&&o.pid>0)return Vr(o.pid)?void 0:n}catch{}let r=Number(n.mtimeNs/1000000n);return Date.now()-r>t?n:void 0},Bd=class extends Error{constructor(t){super(t),this.name="LockBusyError"}},Kr=async(e,t={},n={})=>{let r=t.waitMs??ox,o=t.staleMs??Z2,a=Fs(e,"owner.json"),s=Date.now()+r;for(;;){let i=V2();try{await nx(e,{mode:448});let l=`${a}.anyray-tmp-${process.pid}-${i}`;try{await Jf(l,`${JSON.stringify({pid:process.pid,nonce:i})}
|
|
3
3
|
`,{flag:"wx",mode:384}),await Oe(l,a)}catch(d){throw await $s(l,{force:!0}).catch(()=>{}),await $s(e,{recursive:!0,force:!0}).catch(()=>{}),d}return async()=>{try{JSON.parse(await dc(a,"utf-8")).nonce===i&&await $s(e,{recursive:!0,force:!0})}catch{}}}catch(l){if(l.code!=="EEXIST")throw l}let c=await J2(e,o).catch(()=>{});if(c){await n.beforeReclaim?.();let l=await ax(e).catch(()=>{});if(l&&X2(c,l)&&await $s(e,{recursive:!0,force:!0}).then(()=>!0).catch(()=>!1))continue}if(Date.now()>=s)throw new Bd(t.busyMessage??`${e} is busy; retry the command`);await new Promise(l=>setTimeout(l,j2))}},Sb=(e=ox)=>Kr(Y2(),{waitMs:e,busyMessage:"connect profile is busy; retry the command"}),Et=async(e,t={})=>{if(Xf.getStore()===!0)return e();let n=await Sb(t.waitMs);try{return await Xf.run(!0,e)}finally{await n()}},bb=async e=>{let t=Object.fromEntries(Object.entries(e).filter(([,o])=>o!==void 0)),n=await Md(),r=`${n}.${process.pid}.${K2++}.tmp`;await Jf(r,`${JSON.stringify(t,null,2)}
|
|
4
|
-
`,{mode:384}),await Cb(r,384);try{await Oe(r,n)}catch(o){throw await $s(r,{force:!0}).catch(()=>{}),o}},Me=async e=>{if(Xf.getStore()===!0){await bb(e);return}let t=await Sb();try{await bb(e)}finally{await t()}},Bt=async e=>{let t=async()=>{let r=await wt(),{next:o,result:a}=e(r);return o&&await bb(o),a};if(Xf.getStore()===!0)return t();let n=await Sb();try{return await t()}finally{await n()}},qf=e=>Bt(t=>({next:{...t,...e},result:void 0})),kb=["clientKey","clientKeyExpiresAt","enrolledCert","enrolledCertExpiry","enrolledCertLifetimeMs","enrolledTokenHash"],tx="ssoLink",Ib=async()=>{let e=await G();return kb.some(t=>e[t]!==void 0)?!0:await gt()!==void 0},Qf=async()=>{let e=await wt(),t=kb.some(a=>e[a]!==void 0),n=e[tx]!==void 0,r=e.byoUpstream!==void 0,o=await gt()!==void 0;if(t||n||r||e.managedEnrollmentDisabled!==!0){let a={...e};for(let s of kb)delete a[s];delete a[tx],delete a.byoUpstream,a.managedEnrollmentDisabled=!0,delete a.anyrayFleetManaged,delete a.fleetRefreshAt,delete a.fleetRefreshAwaitedSince,await Me(a)}if(await $d(),await gt())throw new Error(`could not remove the dev key from ${q()}`);return t||n||r||o},Oa=async(e,t,n=!1,r)=>{await Bt(o=>{let a=new Set(o.managedTools??[]),s=new Set(o.revertedTools??[]),i=new Set(o.blockedTools??[]),c=Array.isArray(o.selectedTools)?o.selectedTools:void 0,l=o.toolSelection,d=o.offboardedAt;for(let v of e){let _=v.status==="configured"||v.status==="queued"||v.status==="manual"&&v.landed===!0;!t&&_&&(a.add(v.id),s.delete(v.id),i.delete(v.id),d=void 0),!t&&v.refused===!0&&i.add(v.id),t&&(v.status==="reverted"||v.status==="queued")&&(a.delete(v.id),s.add(v.id),i.delete(v.id))}if(n&&(a.clear(),i.clear()),r&&!t){let v=new Set(r.knownToolIds);for(let _ of r.declinedToolIds??[])v.has(_)&&!a.has(_)&&s.add(_)}if(r){let v=r.namedToolIds??[];if(n)c=[];else if(t&&c){let _=new Set(c);for(let O of v)_.delete(O);c=[..._].sort()}else if(!t&&v.length>0){let _=new Set(r.knownToolIds),O=new Set((c??[]).filter(R=>_.has(R)));for(let R of v)_.has(R)&&O.add(R);c=[...O].sort()}t||(l=v.length>0?"explicit":"all")}let u=[...a].sort(),p=[...o.managedTools??[]].sort(),f=[...s].sort(),m=[...o.revertedTools??[]].sort(),h=[...i].sort(),w=[...o.blockedTools??[]].sort(),g=(v,_)=>v.length===_.length&&v.every((O,R)=>O===_[R]),y=c===void 0?o.selectedTools===void 0:o.selectedTools!==void 0&&g(c,o.selectedTools);if(g(u,p)&&o.revertedTools!=null&&g(f,m)&&g(h,w)&&y&&l===o.toolSelection&&d===o.offboardedAt)return{result:void 0};let{offboardedAt:k,...A}=o;return{next:{...A,...d!==void 0?{offboardedAt:d}:{},managedTools:u,revertedTools:f,blockedTools:h,selectedTools:c,toolSelection:l},result:void 0}})},em=async(e=new Date().toISOString())=>{await qf({offboardedAt:e})}});var Un,bt,wr,uc,Vn=F(()=>{"use strict";Un=(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,bt=(e=process.env)=>Un(e)!==null,wr=e=>e==="codespaces"||e==="devcontainer",uc=e=>{switch(e){case"codespaces":return"a GitHub Codespace";case"devcontainer":return"a dev container";case"ssh":return"an SSH session"}}});var _e,Kn=F(()=>{"use strict";_e="0.11.
|
|
4
|
+
`,{mode:384}),await Cb(r,384);try{await Oe(r,n)}catch(o){throw await $s(r,{force:!0}).catch(()=>{}),o}},Me=async e=>{if(Xf.getStore()===!0){await bb(e);return}let t=await Sb();try{await bb(e)}finally{await t()}},Bt=async e=>{let t=async()=>{let r=await wt(),{next:o,result:a}=e(r);return o&&await bb(o),a};if(Xf.getStore()===!0)return t();let n=await Sb();try{return await t()}finally{await n()}},qf=e=>Bt(t=>({next:{...t,...e},result:void 0})),kb=["clientKey","clientKeyExpiresAt","enrolledCert","enrolledCertExpiry","enrolledCertLifetimeMs","enrolledTokenHash"],tx="ssoLink",Ib=async()=>{let e=await G();return kb.some(t=>e[t]!==void 0)?!0:await gt()!==void 0},Qf=async()=>{let e=await wt(),t=kb.some(a=>e[a]!==void 0),n=e[tx]!==void 0,r=e.byoUpstream!==void 0,o=await gt()!==void 0;if(t||n||r||e.managedEnrollmentDisabled!==!0){let a={...e};for(let s of kb)delete a[s];delete a[tx],delete a.byoUpstream,a.managedEnrollmentDisabled=!0,delete a.anyrayFleetManaged,delete a.fleetRefreshAt,delete a.fleetRefreshAwaitedSince,await Me(a)}if(await $d(),await gt())throw new Error(`could not remove the dev key from ${q()}`);return t||n||r||o},Oa=async(e,t,n=!1,r)=>{await Bt(o=>{let a=new Set(o.managedTools??[]),s=new Set(o.revertedTools??[]),i=new Set(o.blockedTools??[]),c=Array.isArray(o.selectedTools)?o.selectedTools:void 0,l=o.toolSelection,d=o.offboardedAt;for(let v of e){let _=v.status==="configured"||v.status==="queued"||v.status==="manual"&&v.landed===!0;!t&&_&&(a.add(v.id),s.delete(v.id),i.delete(v.id),d=void 0),!t&&v.refused===!0&&i.add(v.id),t&&(v.status==="reverted"||v.status==="queued")&&(a.delete(v.id),s.add(v.id),i.delete(v.id))}if(n&&(a.clear(),i.clear()),r&&!t){let v=new Set(r.knownToolIds);for(let _ of r.declinedToolIds??[])v.has(_)&&!a.has(_)&&s.add(_)}if(r){let v=r.namedToolIds??[];if(n)c=[];else if(t&&c){let _=new Set(c);for(let O of v)_.delete(O);c=[..._].sort()}else if(!t&&v.length>0){let _=new Set(r.knownToolIds),O=new Set((c??[]).filter(R=>_.has(R)));for(let R of v)_.has(R)&&O.add(R);c=[...O].sort()}t||(l=v.length>0?"explicit":"all")}let u=[...a].sort(),p=[...o.managedTools??[]].sort(),f=[...s].sort(),m=[...o.revertedTools??[]].sort(),h=[...i].sort(),w=[...o.blockedTools??[]].sort(),g=(v,_)=>v.length===_.length&&v.every((O,R)=>O===_[R]),y=c===void 0?o.selectedTools===void 0:o.selectedTools!==void 0&&g(c,o.selectedTools);if(g(u,p)&&o.revertedTools!=null&&g(f,m)&&g(h,w)&&y&&l===o.toolSelection&&d===o.offboardedAt)return{result:void 0};let{offboardedAt:k,...A}=o;return{next:{...A,...d!==void 0?{offboardedAt:d}:{},managedTools:u,revertedTools:f,blockedTools:h,selectedTools:c,toolSelection:l},result:void 0}})},em=async(e=new Date().toISOString())=>{await qf({offboardedAt:e})}});var Un,bt,wr,uc,Vn=F(()=>{"use strict";Un=(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,bt=(e=process.env)=>Un(e)!==null,wr=e=>e==="codespaces"||e==="devcontainer",uc=e=>{switch(e){case"codespaces":return"a GitHub Codespace";case"devcontainer":return"a dev container";case"ssh":return"an SSH session"}}});var _e,Kn=F(()=>{"use strict";_e="0.11.261"});import{access as z2,chmod as q2,mkdir as Eb,open as Ob,readFile as fx,rm as br,stat as sx,utimes as Q2}from"node:fs/promises";import{createHash as Tb,randomUUID as mx}from"node:crypto";import{readFileSync as hx,statSync as ix}from"node:fs";import{dirname as Pb,join as eV}from"node:path";import{isDeepStrictEqual as pc}from"node:util";var Ta,yx,cx,tV,N,j,mc,lx,gx,Pa,tm,se,wx,dx,nV,rV,bx,oV,Fd,xb,Rb,ux,aV,_b,fc,kx,Cx,Ax,nm,px,rm,Go,pe,ge=F(()=>{"use strict";lc();cn();Ta=e=>`${e}.anyray-bak`,yx=async e=>{let t;try{t=await Ob(Pb(e),"r"),await t.sync()}catch(n){if(process.platform!=="win32")throw n}finally{await t?.close().catch(()=>{})}},cx=async(e,t)=>{let n,r;try{n=await Ob(e,"wx",384),await n.writeFile(t,"utf-8"),await _a(n)}catch(o){r=o}finally{await n?.close().catch(()=>{})}if(r)throw n&&await br(e,{force:!0}).catch(()=>{}),r;await yx(e)},tV=async e=>{let t;try{t=await Ob(e,"r"),await _a(t)}finally{await t?.close().catch(()=>{})}await yx(e)},N=async e=>{try{return await z2(e),!0}catch{return!1}},j=async e=>{if(!await N(e))return{};let t=await fx(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},mc=class extends Error{constructor(){super("repair deferred: configuration changed before publication")}},lx=e=>`${e.dev}:${e.ino}:${e.size}:${e.mtimeNs}:${e.ctimeNs}`,gx=e=>{try{let t=lx(ix(e,{bigint:!0})),n=hx(e),r=lx(ix(e,{bigint:!0}));if(t!==r)throw new mc;return{raw:n.toString("utf8"),fingerprint:`${r}:${Tb("sha256").update(n).digest("hex")}`}}catch(t){if(t.code==="ENOENT")return{raw:"",fingerprint:"missing"};throw t}},Pa=e=>{let{raw:t,fingerprint:n}=gx(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}},tm=async(e,t,n={})=>{for(let r=0;r<3;r++)try{let o=Pa(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 se(e,o.value,{backup:n.backup,expectedFingerprint:o.fingerprint}),"written")}catch(o){if(!(o instanceof mc))throw o}return"repair deferred"},se=async(e,t,n={})=>{await Eb(Pb(e),{recursive:!0,mode:448});let r=Ta(e);if(n.backup!==!1&&!await N(r)){let a=await N(e),s=a?await fx(e,"utf-8"):`{}
|
|
5
5
|
`;if(a||n.tombstoneAbsent!==!1)try{await cx(r,s)}catch(i){if(i.code!=="EEXIST")throw i}}let o=`${e}.anyray-tmp-${process.pid}-${mx()}`;try{if(await cx(o,`${JSON.stringify(t,null,2)}
|
|
6
6
|
`),n.expectedFingerprint!==void 0){if(gx(e).fingerprint!==n.expectedFingerprint)throw new mc;let a=n.expectedFingerprint.slice(n.expectedFingerprint.lastIndexOf(":")+1);try{await Oe(o,e,n.runtimePlatform,{verifyDisplaced:async s=>Tb("sha256").update(hx(s)).digest("hex")===a})}catch(s){throw s instanceof Ms?new mc:s}return}await Oe(o,e,n.runtimePlatform),await q2(e,384),await tV(e)}finally{await br(o,{force:!0}).catch(()=>{})}},wx=1,dx=3e4,nV=5e3,rV=/^[a-f0-9]{64}$/,bx=e=>`${e}.pending`,oV=e=>`${e}.lock`,Fd=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=>Fd(n)).join(",")}]`;let t=e;return`{${Object.keys(t).sort().filter(n=>t[n]!==void 0).map(n=>`${JSON.stringify(n)}:${Fd(t[n])}`).join(",")}}`},xb=(e,t)=>({exists:e,sha256:Tb("sha256").update(Fd(t)).digest("hex")}),Rb=e=>e!==null&&typeof e=="object"&&!Array.isArray(e),ux=e=>Rb(e)&&typeof e.exists=="boolean"&&typeof e.sha256=="string"&&rV.test(e.sha256),aV=e=>Rb(e)&&e.transactionVersion===wx&&ux(e.before)&&ux(e.after)&&Rb(e.journal),_b=(e,t)=>e.exists===t.exists&&e.sha256===t.sha256,fc=async(e,t)=>{try{return await j(e)}catch{throw new Error(`${t} is malformed; no configuration was changed`)}},kx=async e=>{let t=oV(e),n=eV(t,"owner.json");await Eb(Pb(t),{recursive:!0,mode:448});for(let r=0;r<2;r++){let o=mx();try{await Eb(t,{mode:448})}catch(s){if(s.code!=="EEXIST")throw s;let i=!1;try{let c=await fc(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 sx(n)).mtimeMs;i=!Vr(c.pid)||l>dx}catch{try{i=Date.now()-(await sx(t)).mtimeMs>dx}catch{i=!1}}if(!i||r>0)throw new Error("ownership transaction already in progress");await br(t,{recursive:!0,force:!0});continue}try{await se(n,{pid:process.pid,nonce:o,createdAt:Date.now()},{backup:!1})}catch(s){throw await br(t,{recursive:!0,force:!0}).catch(()=>{}),s}let a=setInterval(()=>{(async()=>{try{if((await fc(n,"ownership journal")).nonce!==o)return;let i=new Date;await Q2(n,i,i)}catch{}})()},nV);return a.unref(),async()=>{clearInterval(a);try{(await fc(n,"ownership journal")).nonce===o&&await br(t,{recursive:!0,force:!0})}catch{}}}throw new Error("ownership transaction already in progress")},Cx=async e=>{let t=await N(e),n={};if(t)try{n=await j(e)}catch{throw new Error("configuration is malformed during ownership recovery; it was left unchanged")}return{exists:t,value:n,fingerprint:xb(t,n)}},Ax=async(e,t)=>{let n=bx(t);if(!await N(n))return;let r=await fc(n,"prepared ownership transaction");if(!aV(r))throw new Error("prepared ownership transaction is invalid; no recovery write was attempted");let o=await Cx(e),a=await N(t),s=await N(Ta(e)),i=_b(o.fingerprint,r.before),c=_b(o.fingerprint,r.after),l=r.journal.fileExisted;if(c&&(a||l===!1||s)&&(!i||a||s)){await se(t,r.journal,{backup:!1}),await br(n,{force:!0});return}if(i){await br(n,{force:!0}),a||await pe(e);return}throw new Error("configuration changed during an interrupted ownership transaction; recovery files were preserved")},nm=async(e,t,n)=>{let r=await kx(t);try{return await Ax(e,t),await n()}finally{await r()}},px=async(e,t,n,r)=>{if(!await N(e)){if(n)throw new Error("journaled JSON rollback found a missing prior file");return}let a=await fc(e,"ownership journal");if(!(n&&pc(a,t))){if(!pc(a,r))throw new Error("journaled JSON rollback found a concurrent file edit");n?await se(e,t,{backup:!1}):await br(e,{force:!0})}},rm=async(e,t={})=>{let{configPath:n,current:r,next:o,journalPath:a,journal:s,fileExisted:i}=e,c=await kx(a);try{await Ax(n,a);let l=await Cx(n),d=xb(i,r),u=await N(a),p=u?await fc(a,"ownership journal"):void 0,f=p&&typeof p.fileExisted=="boolean"?{...s,fileExisted:p.fileExisted}:s;if(!_b(l.fingerprint,d)){if(pc(l.value,o)&&p&&pc(p,f))return;throw new Error("configuration changed before the ownership transaction acquired its lock; retry")}if(l.exists&&pc(l.value,o)&&p&&pc(p,f))return;let m=await N(Ta(n));if(p?.fileExisted===!0&&!m)throw new Error("ownership backup is missing; configuration was left unchanged");if(m&&!p)throw new Error("an unjournaled ownership backup already exists; configuration was left unchanged");let h=bx(a),w={transactionVersion:wx,before:l.fingerprint,after:xb(!0,o),journal:f};await se(h,w,{backup:!1});try{await se(n,o,p?{backup:!1}:{tombstoneAbsent:!1}),await(t.writeJournal??se)(a,f,{backup:!1}),await br(h,{force:!0})}catch(g){try{await px(n,l.value,l.exists,o)}catch(y){throw new AggregateError([g,y],"ownership journal publication failed and config rollback was incomplete")}try{await px(a,p??{},u,f),await br(h,{force:!0}),!m&&!p&&await pe(n)}catch(y){throw new AggregateError([g,y],"ownership journal publication failed after config rollback")}throw g}}finally{await c()}},Go=async e=>{try{return await j(Ta(e))}catch{return{}}},pe=async e=>{await br(Ta(e),{force:!0}).catch(()=>{})}});var Gd,vx,sV,Sx,ln,iV,Hd,cV,lV,om,hc,Ix,Gs,am,Ho=F(()=>{"use strict";Gd=e=>{let t=e.enrolledCert?.payload.keyTtlSeconds;return typeof t=="number"&&Number.isFinite(t)&&t>0?t*1e3:void 0},vx=new Set(["claude-code","opencode","cursor","copilot","copilot-cli","claude-desktop","jetbrains","windsurf","omp"]),sV=10080*60*1e3,Sx=(e,t,n=Date.now())=>{let r=[],o=Gd(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)<=sV},ln=(e,t={},n=Date.now())=>{if(!e.enrolledCert)return!1;let o=(t.toolIds??e.managedTools??[]).some(a=>vx.has(a));return Sx(e,t.keyExpiresAt,n)||!o},iV=1440*60*1e3,Hd=2*iV,cV=360*60*1e3,lV=300*1e3,om=(e,t)=>{let n=Date.parse(e??"");return Number.isFinite(n)&&n<=t+lV?n:void 0},hc=(e,t=Date.now())=>{let n=om(e.fleetRefreshAt,t);if(n!==void 0&&t-n<Hd)return"live";let r=om(e.fleetRefreshAwaitedSince,t);return r===void 0||t-r<cV?"awaiting":"stale"},Ix=(e,t,n=Date.now())=>{if(t){let o={...e,anyrayFleetManaged:!0,fleetRefreshAt:new Date(n).toISOString()};return delete o.fleetRefreshAwaitedSince,o}if(e.anyrayFleetManaged!==!0)return;let r=om(e.fleetRefreshAt,n);if(r!==void 0&&n-r<Hd){if(e.fleetRefreshAwaitedSince===void 0)return;let o={...e};return delete o.fleetRefreshAwaitedSince,o}if(om(e.fleetRefreshAwaitedSince,n)===void 0)return{...e,fleetRefreshAwaitedSince:new Date(n).toISOString()}},Gs=(e,t,n,r=Date.now())=>n!=="win32"&&e.anyrayFleetManaged===!0&&t&&hc(e,r)!=="stale",am=(e,t,n,r=Date.now())=>Gs(e,t,n,r)&&hc(e,r)==="live"});import{delimiter as dV,dirname as uV}from"node:path";var Zr,Hs,En,kr=F(()=>{"use strict";xt();Zr=e=>{let{command:t,args:n}=Zn([e]);return{command:t,args:n}},Hs=()=>Ws(),En=(e="",t=process.env.PATH??"",n=sm(),r=Ws())=>{let a=t.split(dV).filter(Boolean).some(s=>s===n)||uV(r)!==n?"anyray-connect":r;return e?`${a} ${e}`:a}});var xe,yc=F(()=>{"use strict";xe=(e,t,n=0)=>{let r=e.indexOf(t,n);for(;r>=0;){let o=e.lastIndexOf(`
|
|
7
7
|
`,r-1)+1,a=e.indexOf(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "anyray-connect",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.261",
|
|
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": {
|