@cortexkit/opencode-anthropic-auth 2.12.0 → 2.13.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/cli.js CHANGED
@@ -63,7 +63,7 @@ Setup --yes selects every found host, including Pi. Run setup without --yes to c
63
63
  Run setup --help to list every setup option.
64
64
  Native credentials are managed by the offline setup migration.
65
65
  Legacy import source:
66
- ${az()}`)}function S$($,Z){let J=$?.trim();if(!J)throw Error(`${Z} is required`);return J}async function d3($){let J=await($.fetchImpl??fetch)(`https://api.cloudflare.com/client/v4${$.path}`,{method:$.method,headers:{authorization:`Bearer ${$.token}`,...$.body instanceof FormData?{}:{"content-type":"application/json"},...$.headers},body:$.body}),z=await J.text(),X;try{X=JSON.parse(z)}catch{throw Error(`Cloudflare API returned ${J.status}: ${z}`)}if(!J.ok||X.success===!1){let G=X.errors?.map((Q)=>Q.message).filter(Boolean).join("; ");throw Error(G||`Cloudflare API returned ${J.status}`)}return X.result}async function rz($,Z,J,z){return d3({token:$,method:"POST",path:`/accounts/${Z}/storage/kv/namespaces`,body:JSON.stringify({title:J}),fetchImpl:z})}async function tz($){let Z={main_module:"worker.js",compatibility_date:"2026-04-28",bindings:[{type:"kv_namespace",name:"RELAY_STATE",namespace_id:$.kvNamespaceId},{type:"secret_text",name:"RELAY_TOKEN",text:$.relayToken}]},J=new FormData;return J.set("metadata",JSON.stringify(Z)),J.set("worker.js",new Blob([oz],{type:"application/javascript+module"}),"worker.js"),d3({token:$.token,method:"PUT",path:`/accounts/${$.accountId}/workers/scripts/${$.scriptName}`,body:J,fetchImpl:$.fetchImpl})}async function ez($,Z,J,z){await d3({token:$,method:"POST",path:`/accounts/${Z}/workers/scripts/${J}/subdomain`,body:JSON.stringify({enabled:!0,previews_enabled:!1}),fetchImpl:z})}async function $X($,Z,J){return d3({token:$,method:"GET",path:`/accounts/${Z}/workers/subdomain`,fetchImpl:J}).catch(()=>null)}async function ZX($={}){await k1((B)=>B.read());let Z=$.fetchImpl??fetch,J=$.prompt??p3,z=$.warn??((B)=>console.warn(B)),X=S$(process.env.CLOUDFLARE_API_TOKEN?.trim()||await J("Cloudflare API token: "),"Cloudflare API token");$.secrets?.push(X);let G=S$(process.env.CLOUDFLARE_ACCOUNT_ID||await J("Cloudflare account ID: "),"Cloudflare account ID"),Q=await J("Worker name [opencode-anthropic-relay]: ")||"opencode-anthropic-relay",W=`${Q}-state`,Y=lz();$.secrets?.push(Y),console.log("Creating Cloudflare KV namespace...");let H=await rz(X,G,W,Z);console.log("Uploading relay Worker..."),await tz({token:X,accountId:G,scriptName:Q,kvNamespaceId:H.id,relayToken:Y,fetchImpl:Z}),await ez(X,G,Q,Z).catch(async(B)=>{z(await r0("cli-relay-workers-dev",B,process.env,[X,Y]))});let U=await $X(X,G,Z),F=(U?.subdomain?`https://${Q}.${U.subdomain}.workers.dev`:"")||S$(await p3("Relay Worker URL: "),"Relay Worker URL");await k1((B)=>B.updateRelay({enabled:!0,url:F,token:Y,fallbackToDirect:!0,transport:"http"})),console.log(`Relay enabled at ${F}`),console.log("Relay settings saved to the native account store.")}var c3=null;async function p3($){return c3??=mz({input:gz,output:wz}),(await c3.question($)).trim()}function JX(){c3?.close(),c3=null}async function zX($,Z={}){if(process.env.OPENCODE_AUTH_CONTENT!==void 0)throw Error("Local login cannot be verified while OPENCODE_AUTH_CONTENT is set");let J=Z.prompt??p3,z=Z.authorize??hz,X=Z.exchange??pz;await u3(),await k1(async(G)=>{let Q=await G.read(),W=$?.trim()||await J("Fallback account label (optional): "),Y=await z("max");console.log(`
66
+ ${az()}`)}function S$($,Z){let J=$?.trim();if(!J)throw Error(`${Z} is required`);return J}async function d3($){let J=await($.fetchImpl??fetch)(`https://api.cloudflare.com/client/v4${$.path}`,{method:$.method,headers:{authorization:`Bearer ${$.token}`,...$.body instanceof FormData?{}:{"content-type":"application/json"},...$.headers},body:$.body}),z=await J.text(),X;try{X=JSON.parse(z)}catch{throw Error(`Cloudflare API returned ${J.status}: ${z}`)}if(!J.ok||X.success===!1){let G=X.errors?.map((Q)=>Q.message).filter(Boolean).join("; ");throw Error(G||`Cloudflare API returned ${J.status}`)}return X.result}async function rz($,Z,J,z){return d3({token:$,method:"POST",path:`/accounts/${Z}/storage/kv/namespaces`,body:JSON.stringify({title:J}),fetchImpl:z})}async function tz($){let Z={main_module:"worker.js",compatibility_date:"2026-04-28",bindings:[{type:"kv_namespace",name:"RELAY_STATE",namespace_id:$.kvNamespaceId},{type:"secret_text",name:"RELAY_TOKEN",text:$.relayToken}]},J=new FormData;return J.set("metadata",JSON.stringify(Z)),J.set("worker.js",new Blob([oz],{type:"application/javascript+module"}),"worker.js"),d3({token:$.token,method:"PUT",path:`/accounts/${$.accountId}/workers/scripts/${$.scriptName}`,body:J,fetchImpl:$.fetchImpl})}async function ez($,Z,J,z){await d3({token:$,method:"POST",path:`/accounts/${Z}/workers/scripts/${J}/subdomain`,body:JSON.stringify({enabled:!0,previews_enabled:!1}),fetchImpl:z})}async function $X($,Z,J){return d3({token:$,method:"GET",path:`/accounts/${Z}/workers/subdomain`,fetchImpl:J}).catch(()=>null)}async function ZX($={}){await k1((B)=>B.assertRelayLocation());let Z=$.fetchImpl??fetch,J=$.prompt??p3,z=$.warn??((B)=>console.warn(B)),X=S$(process.env.CLOUDFLARE_API_TOKEN?.trim()||await J("Cloudflare API token: "),"Cloudflare API token");$.secrets?.push(X);let G=S$(process.env.CLOUDFLARE_ACCOUNT_ID||await J("Cloudflare account ID: "),"Cloudflare account ID"),Q=await J("Worker name [opencode-anthropic-relay]: ")||"opencode-anthropic-relay",W=`${Q}-state`,Y=lz();$.secrets?.push(Y),console.log("Creating Cloudflare KV namespace...");let H=await rz(X,G,W,Z);console.log("Uploading relay Worker..."),await tz({token:X,accountId:G,scriptName:Q,kvNamespaceId:H.id,relayToken:Y,fetchImpl:Z}),await ez(X,G,Q,Z).catch(async(B)=>{z(await r0("cli-relay-workers-dev",B,process.env,[X,Y]))});let U=await $X(X,G,Z),F=(U?.subdomain?`https://${Q}.${U.subdomain}.workers.dev`:"")||S$(await p3("Relay Worker URL: "),"Relay Worker URL");await k1((B)=>B.updateRelay({enabled:!0,url:F,token:Y,fallbackToDirect:!0,transport:"http"})),console.log(`Relay enabled at ${F}`),console.log("Relay settings saved to the native account store.")}var c3=null;async function p3($){return c3??=mz({input:gz,output:wz}),(await c3.question($)).trim()}function JX(){c3?.close(),c3=null}async function zX($,Z={}){if(process.env.OPENCODE_AUTH_CONTENT!==void 0)throw Error("Local login cannot be verified while OPENCODE_AUTH_CONTENT is set");let J=Z.prompt??p3,z=Z.authorize??hz,X=Z.exchange??pz;await u3(),await k1(async(G)=>{let Q=await G.read(),W=$?.trim()||await J("Fallback account label (optional): "),Y=await z("max");console.log(`
67
67
  Open this URL in your browser and complete Claude sign-in:
68
68
  `),console.log(`${Y.url}
69
69
  `);let H=await J("Paste the full callback URL or authorization code here: ");Z.secrets?.push(H);let U=await X(H,Y.verifier,Y.redirectUri,Y.state);if(U.type==="failed")throw Error("Authentication failed");if(Z.secrets?.push(U.access,U.refresh),process.env.OPENCODE_AUTH_CONTENT!==void 0)throw Error("Local login cannot be verified while OPENCODE_AUTH_CONTENT is set");await u3();let K=W&&W!=="main"?W:crypto.randomUUID(),F=Q.accounts.some((B)=>B.id===K&&B.source==="local");await G.loginOAuth({routeId:K,replace:F,label:W||void 0,credential:{access:U.access,refresh:U.refresh,expires:U.expires}}),console.log(`