@diggerhq/catty 0.3.8 → 0.3.9
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 +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,10 +10,10 @@ Your confirmation code:
|
|
|
10
10
|
`),console.log(` ${s.user_code}
|
|
11
11
|
`),console.log(`Opening ${s.verification_uri_complete}
|
|
12
12
|
`),await Ye(s.verification_uri_complete),console.log("Waiting for authentication...");let n=(s.interval||5)*1e3,o=Date.now()+s.expires_in*1e3;for(;Date.now()<o;){await T(n);let i=await(await fetch(`${e}/v1/auth/device/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({device_code:s.device_code})})).json();if(!i.pending){if(i.error)throw new Error(i.error);if(i.access_token){w({access_token:i.access_token,refresh_token:i.refresh_token,user_id:i.user?.id||"",email:i.user?.email||"",expires_at:i.expires_in?new Date(Date.now()+(i.expires_in-30)*1e3).toISOString():void 0}),console.log(`
|
|
13
|
-
Logged in as ${i.user?.email}`),console.log("You can now run 'catty new' to start a session");return}}}throw new Error("Authentication timed out")});import{Command as qe}from"commander";var te=new qe("logout").description("Log out of Catty").action(async()=>{if(!h()){console.log("Not logged in");return}let t=f()?.email||"";D(),console.log(t?`Logged out from ${t}`:"Logged out")});import{Command as Je}from"commander";var oe=new Je("version").description("Print the version number").action(()=>{console.log("0.3.
|
|
13
|
+
Logged in as ${i.user?.email}`),console.log("You can now run 'catty new' to start a session");return}}}throw new Error("Authentication timed out")});import{Command as qe}from"commander";var te=new qe("logout").description("Log out of Catty").action(async()=>{if(!h()){console.log("Not logged in");return}let t=f()?.email||"";D(),console.log(t?`Logged out from ${t}`:"Logged out")});import{Command as Je}from"commander";var oe=new Je("version").description("Print the version number").action(()=>{console.log("0.3.9")});import{Command as it}from"commander";import{readFileSync as Ke,writeFileSync as Ze,existsSync as se,mkdirSync as Xe}from"fs";import{join as ne}from"path";import{homedir as re}from"os";import{createInterface as He}from"readline";import{spawn as Qe}from"child_process";var et=900*1e3,tt=2880*60*1e3,ot="https://registry.npmjs.org/@diggerhq/catty/latest";function ie(){return ne(re(),_,"version-cache.json")}function ae(){try{let e=ie();if(!se(e))return null;let t=Ke(e,"utf-8");return JSON.parse(t)}catch{return null}}function ce(e,t){try{let s=ie(),n=ne(re(),_);se(n)||Xe(n,{recursive:!0});let o=ae(),r={latestVersion:e,lastChecked:Date.now(),declinedVersion:t?e:o?.declinedVersion,declinedAt:t?Date.now():o?.declinedAt};Ze(s,JSON.stringify(r,null,2))}catch{}}async function st(){try{let e=await fetch(ot,{signal:AbortSignal.timeout(5e3)});return e.ok&&(await e.json()).version||null}catch{return null}}function nt(e,t){let s=e.split(".").map(Number),n=t.split(".").map(Number);for(let o=0;o<3;o++){let r=s[o]||0,i=n[o]||0;if(i>r)return!0;if(i<r)return!1}return!1}async function R(){let e="0.3.9";if(e==="dev")return{updateAvailable:!1,currentVersion:e,latestVersion:null,shouldPrompt:!1};let t=ae(),s=Date.now(),n=null;if(t&&s-t.lastChecked<et?n=t.latestVersion:(n=await st(),n&&ce(n)),!n)return{updateAvailable:!1,currentVersion:e,latestVersion:null,shouldPrompt:!1};let o=nt(e,n),r=o;return o&&t?.declinedVersion===n&&t.declinedAt&&(r=s-t.declinedAt>=tt),{updateAvailable:o,currentVersion:e,latestVersion:n,shouldPrompt:r}}function le(e,t){console.log(""),console.log(`\x1B[33mUpdate available:\x1B[0m \x1B[2m${e}\x1B[0m \u2192 \x1B[32m${t}\x1B[0m`)}async function de(){let e=He({input:process.stdin,output:process.stdout});return new Promise(t=>{e.question("Would you like to update? (Y/n): ",s=>{e.close();let n=s.trim().toLowerCase();t(n===""||n==="y"||n==="yes")})})}function pe(e){ce(e,!0)}function rt(){let e=process.env.npm_config_user_agent||"";return e.includes("yarn")?"yarn":e.includes("pnpm")?"pnpm":e.includes("bun")?"bun":"npm"}async function x(e,t){console.log(`
|
|
14
14
|
Updating from ${e} to ${t}...
|
|
15
15
|
`);let s=rt(),n,o;switch(s){case"yarn":n="yarn",o=["global","add","@diggerhq/catty@latest"];break;case"pnpm":n="pnpm",o=["add","-g","@diggerhq/catty@latest"];break;case"bun":n="bun",o=["install","-g","@diggerhq/catty@latest"];break;default:n="npm",o=["install","-g","@diggerhq/catty@latest"]}return new Promise((r,i)=>{let l=Qe(n,o,{stdio:"inherit",shell:process.platform==="win32"});l.on("close",c=>{c===0?(console.log(`
|
|
16
16
|
\x1B[32m\u2713\x1B[0m Successfully updated to version ${t}`),r()):(console.error(`
|
|
17
17
|
\x1B[31m\u2717\x1B[0m Update failed with exit code ${c}`),i(new Error(`Update process exited with code ${c}`)))}),l.on("error",c=>{console.error(`
|
|
18
|
-
\x1B[31m\u2717\x1B[0m Failed to run update command: ${c.message}`),i(c)})})}var ue=new it("update").description("Update catty to the latest version").action(async()=>{try{let e="0.3.
|
|
18
|
+
\x1B[31m\u2717\x1B[0m Failed to run update command: ${c.message}`),i(c)})})}var ue=new it("update").description("Update catty to the latest version").action(async()=>{try{let e="0.3.9";if(e==="dev"){console.log("Cannot update in development mode.");return}console.log("Checking for updates...");let{updateAvailable:t,latestVersion:s}=await R();if(!t||!s){console.log(`You are already using the latest version (${e}).`);return}await x(e,s)}catch(e){e instanceof Error&&console.error(`Error: ${e.message}`),process.exit(1)}});var at="0.3.9";m.name("catty").description("Catty - Remote AI agent sessions").option("--api <url>","API server address").version(at);m.addCommand(K);m.addCommand(Z);m.addCommand(X);m.addCommand(H);m.addCommand(Q,{hidden:!0});m.addCommand(ee);m.addCommand(te);m.addCommand(oe);m.addCommand(ue);m.exitOverride();async function ct(){try{await m.parseAsync(process.argv);let e=process.argv[2];if(e&&!["version","update","-v","--version","-h","--help","help"].includes(e)){let{updateAvailable:s,currentVersion:n,latestVersion:o,shouldPrompt:r}=await R();if(s&&o&&r)if(le(n,o),await de())try{await x(n,o)}catch{}else pe(o)}}catch(e){e instanceof Error?(e.name==="CommanderError"&&["commander.helpDisplayed","commander.version"].includes(e.code||"")&&process.exit(0),console.error(`Error: ${e.message}`)):console.error(`Error: ${e}`),process.exit(1)}}ct();
|
|
19
19
|
//# sourceMappingURL=index.js.map
|