@eloqnt/cli 0.7.0 → 0.7.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @eloqnt/cli
2
2
 
3
+ ## 0.7.2
4
+
5
+ ### Patch Changes
6
+
7
+ - c7c7977: Start up faster by lazy-loading more dependencies.
8
+ - Updated dependencies [c7c7977]
9
+ - @eloqnt/sdk@0.7.1
10
+
11
+ ## 0.7.1
12
+
13
+ ### Patch Changes
14
+
15
+ - ba84f57: `eloqnt login` and `eloqnt logout` now revoke the stored session even when `ELOQNT_TOKEN` is set, instead of leaving it behind in your logged-in CLIs.
16
+
3
17
  ## 0.7.0
4
18
 
5
19
  ### Minor Changes
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import e from"node:process";import{defineCommand as t,renderUsage as n,runMain as r}from"citty";import i from"picocolors";var a=`0.7.0`;try{e.loadEnvFile()}catch{}const o=t({meta:{name:`eloqnt`,version:a,description:`AI-powered translations for developers`},subCommands:{lint:d(()=>import(`../lint-CfQICr8Y.mjs`)),review:d(()=>import(`../review-B_PGSNrY.mjs`)),translate:d(()=>import(`../translate-CZbtc5Zk.mjs`)),crowdin:d(()=>import(`../crowdin-MDUTKr-r.mjs`)),login:d(()=>import(`../login-wvtfpkQs.mjs`)),logout:d(()=>import(`../logout-DvSJiVwt.mjs`)),whoami:d(()=>import(`../whoami-QGFYR_hV.mjs`))}}),s=e.argv.slice(2);r(o,{rawArgs:s.length===1&&s[0]===`-v`?[`--version`]:s,async showUsage(e,t){console.log(await n(e,t)),console.log(i.dim(`Docs: ${await c(e,t)}`))}});async function c(e,t){let n=(await u(e.meta))?.name,r=(await u(t?.meta))?.name,i=r===void 0||r===`eloqnt`?n:r;return i===void 0||i===`eloqnt`?`https://cli.eloqnt.dev/docs`:`https://cli.eloqnt.dev/docs/cli/${await l(i)}`}async function l(e){let t=o.subCommands??{};if(e in t)return e;for(let[n,r]of Object.entries(t)){let t=(await u(r))?.subCommands;if(t&&e in t)return n}return e}function u(e){return typeof e==`function`?e():e}function d(e){return()=>e().then(e=>e.default)}export{a as t};
2
+ import e from"node:process";import{defineCommand as t,renderUsage as n,runMain as r}from"citty";import i from"picocolors";var a=`0.7.2`;try{e.loadEnvFile()}catch{}const o=t({meta:{name:`eloqnt`,version:a,description:`AI-powered translations for developers`},subCommands:{lint:d(()=>import(`../lint-CfQICr8Y.mjs`)),review:d(()=>import(`../review-ccqeTV4a.mjs`)),translate:d(()=>import(`../translate-C-ol7zSp.mjs`)),crowdin:d(()=>import(`../crowdin-MDUTKr-r.mjs`)),login:d(()=>import(`../login-CtE25dA8.mjs`)),logout:d(()=>import(`../logout-DcZnPra1.mjs`)),whoami:d(()=>import(`../whoami-B94g_10F.mjs`))}}),s=e.argv.slice(2);r(o,{rawArgs:s.length===1&&s[0]===`-v`?[`--version`]:s,async showUsage(e,t){console.log(await n(e,t)),console.log(i.dim(`Docs: ${await c(e,t)}`))}});async function c(e,t){let n=(await u(e.meta))?.name,r=(await u(t?.meta))?.name,i=r===void 0||r===`eloqnt`?n:r;return i===void 0||i===`eloqnt`?`https://cli.eloqnt.dev/docs`:`https://cli.eloqnt.dev/docs/cli/${await l(i)}`}async function l(e){let t=o.subCommands??{};if(e in t)return e;for(let[n,r]of Object.entries(t)){let t=(await u(r))?.subCommands;if(t&&e in t)return n}return e}function u(e){return typeof e==`function`?e():e}function d(e){return()=>e().then(e=>e.default)}export{a as t};
@@ -1,2 +1,2 @@
1
- import{t as e}from"./bin/eloqnt.mjs";import{t}from"./withErrorFormatting-rhiaj7Md.mjs";import{t as n}from"./createSpinner-BBkrpcrh.mjs";import{a as r,n as i,o as a,r as o}from"./urls-qvEAJDcV.mjs";import s from"node:process";import{defineCommand as c}from"citty";import l from"picocolors";import{EloqntSdkError as u,getAuthHeaders as d}from"@eloqnt/sdk/_internal";import{outro as f}from"@clack/prompts";import{hostname as p}from"node:os";import{setTimeout as m}from"node:timers/promises";import h from"open";function g(e){h(e).catch(()=>{})}const _=`eloqnt-cli`,v=`eloqnt-cli/${e} (${p()}; ${s.platform} ${s.arch}; node ${s.version})`;var y=c({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},run:()=>t(async()=>{let e=i(),t=await r();t&&await fetch(`${e}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${t}`,"content-type":`application/json`,"user-agent":v},body:JSON.stringify({token:t})}).catch(()=>{});let c=await fetch(`${e}/device/code`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({client_id:_})});if(!c.ok)throw new u(`ENGINE_UNREACHABLE`,`Couldn't start the login flow`,{details:`The auth server responded with ${c.status}.`,hint:`Check your connection and run eloqnt login again.`});let d=await c.json();s.stderr.write(`\n${l.cyan(`Log in to eloqnt/engine`)}\n`),s.stderr.write(l.dim(`${d.verification_uri_complete}\n\n`)),g(d.verification_uri_complete);let p=s.stderr.isTTY?n():void 0;p?p.start(`Waiting for approval in the browser`):s.stderr.write(l.dim(`Waiting for approval in the browser …
2
- `));let m=await x(e,d);if(!m.access_token)throw p?.stop(l.dim(`Login canceled`)),new u(`NOT_AUTHENTICATED`,m.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await a(m.access_token),p?(p.stop(l.dim(`Approved in the browser`)),f(l.green(`Logged in`))):s.stdout.write(`${l.green(`Logged in`)}\n`),await b(m.access_token)&&s.stderr.write(`\n${l.cyan(`→ Choose a plan at ${o()}/plans`)}\n`)})});async function b(e){try{let t=await fetch(new URL(`/api/engine/me`,o()),{headers:d(e)});if(!t.ok)return!1;let n=await t.json();return Array.isArray(n.plans)&&n.plans.length===0}catch{return!1}}async function x(e,t){let n=Date.now()+t.expires_in*1e3,r=t.interval;for(;Date.now()<n;){await m(r*1e3);let n=await(await fetch(`${e}/device/token`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({grant_type:`urn:ietf:params:oauth:grant-type:device_code`,device_code:t.device_code,client_id:_})})).json();if(n.access_token)return n;if(n.error!==`authorization_pending`){if(n.error===`slow_down`){r+=5;continue}return n}}return{error:`expired_token`,error_description:`The login request expired`}}export{y as default};
1
+ import{t as e}from"./bin/eloqnt.mjs";import{t}from"./withErrorFormatting-rhiaj7Md.mjs";import{t as n}from"./createSpinner-BBkrpcrh.mjs";import{a as r,n as i,r as a,s as o}from"./urls-BqUTSfHP.mjs";import s from"node:process";import{defineCommand as c}from"citty";import l from"picocolors";import{EloqntSdkError as u,getAuthHeaders as d}from"@eloqnt/sdk/_internal";import{outro as f}from"@clack/prompts";import{hostname as p}from"node:os";import{setTimeout as m}from"node:timers/promises";import h from"open";function g(e){h(e).catch(()=>{})}const _=`eloqnt-cli`,v=`eloqnt-cli/${e} (${p()}; ${s.platform} ${s.arch}; node ${s.version})`;var y=c({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},run:()=>t(async()=>{let e=i(),t=await r();t&&await fetch(`${e}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${t}`,"content-type":`application/json`,"user-agent":v},body:JSON.stringify({token:t})}).catch(()=>{});let c=await fetch(`${e}/device/code`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({client_id:_})});if(!c.ok)throw new u(`ENGINE_UNREACHABLE`,`Couldn't start the login flow`,{details:`The auth server responded with ${c.status}.`,hint:`Check your connection and run eloqnt login again.`});let d=await c.json();s.stderr.write(`\n${l.cyan(`Log in to eloqnt/engine`)}\n`),s.stderr.write(l.dim(`${d.verification_uri_complete}\n\n`)),g(d.verification_uri_complete);let p=s.stderr.isTTY?n():void 0;p?p.start(`Waiting for approval in the browser`):s.stderr.write(l.dim(`Waiting for approval in the browser …
2
+ `));let m=await x(e,d);if(!m.access_token)throw p?.stop(l.dim(`Login canceled`)),new u(`NOT_AUTHENTICATED`,m.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await o(m.access_token),p?(p.stop(l.dim(`Approved in the browser`)),f(l.green(`Logged in`))):s.stdout.write(`${l.green(`Logged in`)}\n`),await b(m.access_token)&&s.stderr.write(`\n${l.cyan(`→ Choose a plan at ${a()}/plans`)}\n`)})});async function b(e){try{let t=await fetch(new URL(`/api/engine/me`,a()),{headers:d(e)});if(!t.ok)return!1;let n=await t.json();return Array.isArray(n.plans)&&n.plans.length===0}catch{return!1}}async function x(e,t){let n=Date.now()+t.expires_in*1e3,r=t.interval;for(;Date.now()<n;){await m(r*1e3);let n=await(await fetch(`${e}/device/token`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({grant_type:`urn:ietf:params:oauth:grant-type:device_code`,device_code:t.device_code,client_id:_})})).json();if(n.access_token)return n;if(n.error!==`authorization_pending`){if(n.error===`slow_down`){r+=5;continue}return n}}return{error:`expired_token`,error_description:`The login request expired`}}export{y as default};
@@ -1 +1 @@
1
- import{t as e}from"./withErrorFormatting-rhiaj7Md.mjs";import{a as t,i as n,n as r}from"./urls-qvEAJDcV.mjs";import i from"node:process";import{defineCommand as a}from"citty";import o from"picocolors";var s=a({meta:{name:`logout`,description:`Logs out of eloqnt/engine by removing a local auth token.`},run:()=>e(async()=>{let e=await t();e&&await fetch(`${r()}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${e}`,"content-type":`application/json`},body:JSON.stringify({token:e})}).catch(()=>{});let a=await n();i.stdout.write(`${a||e?o.green(`Logged out`):o.dim(`Not logged in`)}\n`)})});export{s as default};
1
+ import{t as e}from"./withErrorFormatting-rhiaj7Md.mjs";import{a as t,i as n,n as r}from"./urls-BqUTSfHP.mjs";import i from"node:process";import{defineCommand as a}from"citty";import o from"picocolors";var s=a({meta:{name:`logout`,description:`Logs out of eloqnt/engine by removing a local auth token.`},run:()=>e(async()=>{let e=await t();e&&await fetch(`${r()}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${e}`,"content-type":`application/json`},body:JSON.stringify({token:e})}).catch(()=>{});let a=await n();i.stdout.write(`${a||e?o.green(`Logged out`):o.dim(`Not logged in`)}\n`)})});export{s as default};
@@ -1 +1 @@
1
- import{defineCommand as e}from"citty";var t=e({meta:{name:`review`,description:`Review source strings and fix issues in place.`},setup({rawArgs:e}){e.find(e=>!e.startsWith(`-`))!==`source`&&e.unshift(`source`)},subCommands:{source:()=>import(`./source-QvIhIT-3.mjs`).then(e=>e.default)}});export{t as default};
1
+ import{defineCommand as e}from"citty";var t=e({meta:{name:`review`,description:`Review source strings and fix issues in place.`},setup({rawArgs:e}){e.find(e=>!e.startsWith(`-`))!==`source`&&e.unshift(`source`)},subCommands:{source:()=>import(`./source-ChBxXGHK.mjs`).then(e=>e.default)}});export{t as default};
@@ -1,4 +1,4 @@
1
- import{t as e}from"./defineEloqntCommand-GkAsZ0sd.mjs";import{t}from"./createSpinner-BBkrpcrh.mjs";import{t as n}from"./resolvePaths-CKsEPHfH.mjs";import{t as r}from"./parseListArg-p5H1s5JC.mjs";import{n as i,t as a}from"./report-CIHPhU_6.mjs";import{a as o,i as s,n as c,r as l}from"./stringWidth-D0Z3LOKi.mjs";import{a as u,r as d}from"./urls-qvEAJDcV.mjs";import{n as f,r as p,t as m}from"./writeStep-CerCYWGN.mjs";import{reviewSource as h}from"@eloqnt/sdk";import g from"node:process";import _ from"picocolors";import{basename as v,dirname as y,relative as b}from"node:path";import{loadStyleguide as x}from"@eloqnt/sdk/_internal";var S=e({meta:{name:`source`,description:`Review source strings for errors and fix them in place.`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)review these message ids (comma-separated)`}},async execute({config:e,rootDir:i,args:a}){let{messages:o,srcPath:s}=e,c=n(o.path,i),l=s?n(s,i):void 0,f=await x({rootDir:i,path:e.styleguides}),v=p(f,[o.sourceLocale]),y=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,S=g.stderr.isTTY&&!a.json,C;function w(e){if(!a.json){if(e.phase===`context-enrichment`){e.state===`started`?(g.stderr.write(`
1
+ import{t as e}from"./defineEloqntCommand-GkAsZ0sd.mjs";import{t}from"./createSpinner-BBkrpcrh.mjs";import{t as n}from"./resolvePaths-CKsEPHfH.mjs";import{t as r}from"./parseListArg-p5H1s5JC.mjs";import{n as i,t as a}from"./report-CIHPhU_6.mjs";import{a as o,i as s,n as c,r as l}from"./stringWidth-D0Z3LOKi.mjs";import{o as u,r as d}from"./urls-BqUTSfHP.mjs";import{n as f,r as p,t as m}from"./writeStep-CerCYWGN.mjs";import{reviewSource as h}from"@eloqnt/sdk";import g from"node:process";import _ from"picocolors";import{basename as v,dirname as y,relative as b}from"node:path";import{loadStyleguide as x}from"@eloqnt/sdk/_internal";var S=e({meta:{name:`source`,description:`Review source strings for errors and fix them in place.`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)review these message ids (comma-separated)`}},async execute({config:e,rootDir:i,args:a}){let{messages:o,srcPath:s}=e,c=n(o.path,i),l=s?n(s,i):void 0,f=await x({rootDir:i,path:e.styleguides}),v=p(f,[o.sourceLocale]),y=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,S=g.stderr.isTTY&&!a.json,C;function w(e){if(!a.json){if(e.phase===`context-enrichment`){e.state===`started`?(g.stderr.write(`
2
2
  `),S?(C=t({withGuide:!1}),C.start(`Context enrichment running`)):g.stderr.write(_.dim(`Context enrichment running …
3
3
  `))):e.state===`completed`?(C?.clear(),C=void 0,m(_.green(`✔`),`Context enrichment complete`)):(g.stderr.write(`
4
4
  `),m(_.dim(`–`),"Skipped source code analysis due to absent `srcPath`"));return}if(e.phase===`post-checks`){e.state===`started`?S?(C=t({withGuide:!1}),C.start(`Post-review checks running`)):g.stderr.write(_.dim(`Post-review checks running …
@@ -1,4 +1,4 @@
1
- import{t as e}from"./defineEloqntCommand-GkAsZ0sd.mjs";import{t}from"./createSpinner-BBkrpcrh.mjs";import{t as n}from"./resolvePaths-CKsEPHfH.mjs";import{t as r}from"./parseListArg-p5H1s5JC.mjs";import{a as i,i as a,n as o}from"./stringWidth-D0Z3LOKi.mjs";import{a as s,r as c,t as l}from"./urls-qvEAJDcV.mjs";import{n as u,r as d,t as f}from"./writeStep-CerCYWGN.mjs";import{translate as p}from"@eloqnt/sdk";import m from"node:process";import h from"picocolors";import{basename as g,dirname as _,relative as v}from"node:path";import{loadStyleguide as y}from"@eloqnt/sdk/_internal";var b=e({meta:{name:`translate`,description:`Translate strings to target locales (defaults to missing ones).`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)translate these message ids (comma-separated)`},locale:{type:`string`,description:`Restrict to these target locales (comma-separated)`}},async execute({config:e,rootDir:l,args:u}){let{messages:g,srcPath:_}=e,b=n(g.path,l),x=_?n(_,l):void 0,S=await y({rootDir:l,path:e.styleguides}),C=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,w=r(u.locale),T=w??(Array.isArray(g.locales)?g.locales.filter(e=>e!==g.sourceLocale):void 0),E=`${T?.length?`${T.join(`, `)} `:``}via ${C}`,D=d(S,T??Object.keys(S.byLocale)),O=m.stderr.isTTY&&!u.json,k;function A(e,t,n){let r=`(${t}/${n})`,s=a()-4,c=`Translating ${e}% done`;return o(s,[`Translating ${E} · ${e}% done ${r}`,`Translating ${E} · ${e}% done`,`Translating ${e}% done ${r}`,c])||i(c,s)}let j=0;function M(e){if(!u.json){if(e.phase===`context-enrichment`){e.state===`started`?(m.stderr.write(`
1
+ import{t as e}from"./defineEloqntCommand-GkAsZ0sd.mjs";import{t}from"./createSpinner-BBkrpcrh.mjs";import{t as n}from"./resolvePaths-CKsEPHfH.mjs";import{t as r}from"./parseListArg-p5H1s5JC.mjs";import{a as i,i as a,n as o}from"./stringWidth-D0Z3LOKi.mjs";import{o as s,r as c,t as l}from"./urls-BqUTSfHP.mjs";import{n as u,r as d,t as f}from"./writeStep-CerCYWGN.mjs";import{translate as p}from"@eloqnt/sdk";import m from"node:process";import h from"picocolors";import{basename as g,dirname as _,relative as v}from"node:path";import{loadStyleguide as y}from"@eloqnt/sdk/_internal";var b=e({meta:{name:`translate`,description:`Translate strings to target locales (defaults to missing ones).`,requiresLogin:!0},args:{id:{type:`string`,description:`(Re-)translate these message ids (comma-separated)`},locale:{type:`string`,description:`Restrict to these target locales (comma-separated)`}},async execute({config:e,rootDir:l,args:u}){let{messages:g,srcPath:_}=e,b=n(g.path,l),x=_?n(_,l):void 0,S=await y({rootDir:l,path:e.styleguides}),C=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,w=r(u.locale),T=w??(Array.isArray(g.locales)?g.locales.filter(e=>e!==g.sourceLocale):void 0),E=`${T?.length?`${T.join(`, `)} `:``}via ${C}`,D=d(S,T??Object.keys(S.byLocale)),O=m.stderr.isTTY&&!u.json,k;function A(e,t,n){let r=`(${t}/${n})`,s=a()-4,c=`Translating ${e}% done`;return o(s,[`Translating ${E} · ${e}% done ${r}`,`Translating ${E} · ${e}% done`,`Translating ${e}% done ${r}`,c])||i(c,s)}let j=0;function M(e){if(!u.json){if(e.phase===`context-enrichment`){e.state===`started`?(m.stderr.write(`
2
2
  `),O?(k=t({withGuide:!1}),k.start(`Context enrichment running`)):m.stderr.write(h.dim(`Context enrichment running …
3
3
  `))):e.state===`completed`?(k?.clear(),k=void 0,f(h.green(`✔`),`Context enrichment complete`)):(m.stderr.write(`
4
4
  `),f(h.dim(`–`),"Skipped context enrichment (no `srcPath` set)"));return}if(e.phase===`translate`){if(e.state===`started`)D?f(h.green(`✔`),D):f(h.dim(`–`),`No styleguides found`),O?(k=t({withGuide:!1}),k.start(`Translating ${E}`)):m.stderr.write(h.dim(`Translating ${E} …\n`));else if(e.state===`progress`){let t=Math.floor(e.completedStrings/e.totalStrings*100);if(O)k?.message(A(t,e.completedStrings,e.totalStrings));else{let n=Math.floor(t/25);n>j&&n<4&&(j=n,m.stderr.write(h.dim(`Translating ${t}% done (${e.completedStrings}/${e.totalStrings}) …\n`)))}}else e.state===`stopped`?(k?.clear(),k=void 0):(k?.clear(),k=void 0,f(h.green(`✔`),`Translated ${E}`));return}e.state===`started`?O?(k=t({withGuide:!1}),k.start(`Post-translation checks running`)):m.stderr.write(h.dim(`Post-translation checks running …
@@ -0,0 +1 @@
1
+ import e from"node:process";import{dirname as t,join as n}from"node:path";import{EloqntSdkError as r}from"@eloqnt/sdk/_internal";import{homedir as i}from"node:os";import{mkdir as a,readFile as o,rm as s,writeFile as c}from"node:fs/promises";function l(){let t=e.env.XDG_CONFIG_HOME??n(i(),`.config`);return n(t,`eloqnt`,`credentials.json`)}async function u(){return e.env.ELOQNT_TOKEN||d()}async function d(){try{let e=await o(l(),`utf8`),t=JSON.parse(e);return typeof t.token==`string`?t.token:void 0}catch{return}}async function f(e){let n=l();return await a(t(n),{recursive:!0}),await c(n,`${JSON.stringify({token:e},null,2)}\n`,{mode:384}),n}async function p(){try{return await s(l()),!0}catch{return!1}}const m=`https://engine.eloqnt.dev`;function h(e,t){let n;try{n=new URL(e)}catch{throw new r(`INVALID_ENGINE_URL`,`Can't use ${e} as the engine URL`,{details:`${t} isn't a valid URL.`,hint:`Unset ${t} to use ${m}.`})}if(n.origin!==m&&n.hostname!==`localhost`)throw new r(`INVALID_ENGINE_URL`,`Can't use ${n.origin} as the engine URL`,{details:`${t} takes ${m} or a localhost address, and nothing else.`,hint:`Unset ${t} to use ${m}.`});return n.origin}function g(){return e.env.ELOQNT_ENGINE_URL===void 0?e.env.ELOQNT_STUDIO_URL===void 0?m:h(e.env.ELOQNT_STUDIO_URL,`ELOQNT_STUDIO_URL`):h(e.env.ELOQNT_ENGINE_URL,`ELOQNT_ENGINE_URL`)}function _(){return`${g()}/api/auth`}const v=`https://cli.eloqnt.dev`;export{d as a,p as i,_ as n,u as o,g as r,f as s,v as t};
@@ -1,2 +1,2 @@
1
- import{t as e}from"./defineEloqntCommand-GkAsZ0sd.mjs";import{a as t,r as n}from"./urls-qvEAJDcV.mjs";import r from"picocolors";import{EloqntSdkError as i,MeResponseSchema as a,getAuthHeaders as o}from"@eloqnt/sdk/_internal";function s(e){return r.dim(e.padEnd(12))}var c=e({meta:{name:`whoami`,description:`Shows the logged-in user account.`},requiresConfig:!1,async execute(){let e=await t();if(!e)throw new i(`NOT_AUTHENTICATED`,`Not logged in`,{hint:`Run eloqnt login to authenticate.`});let r=await fetch(new URL(`/api/engine/me`,n()),{headers:o(e)});if(r.status===401)throw new i(`NOT_AUTHENTICATED`,`Your session has expired`,{hint:`Run eloqnt login to sign in again.`});if(!r.ok)throw new i(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API responded with ${r.status}.`,hint:`This is on our end. Try again in a few minutes.`});let s=a.safeParse(await r.json());if(!s.success)throw new i(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API returned an unexpected shape.`,hint:`This is on our end. Try again in a few minutes.`});let{user:c,plans:l,hosted:u}=s.data;return{email:c.email,plans:l,hosted:u}},render:({email:e,plans:t,hosted:i})=>{let a=[`${s(`Email:`)}${e}`,`${s(`Plan:`)}${l(t,i)}`];return i&&a.push(`${s(`Quota used:`)}${u(i)}`),t.length===0&&a.push(``,r.cyan(`→ Choose a plan at ${n()}/plans`)),a.join(`
1
+ import{t as e}from"./defineEloqntCommand-GkAsZ0sd.mjs";import{o as t,r as n}from"./urls-BqUTSfHP.mjs";import r from"picocolors";import{EloqntSdkError as i,MeResponseSchema as a,getAuthHeaders as o}from"@eloqnt/sdk/_internal";function s(e){return r.dim(e.padEnd(12))}var c=e({meta:{name:`whoami`,description:`Shows the logged-in user account.`},requiresConfig:!1,async execute(){let e=await t();if(!e)throw new i(`NOT_AUTHENTICATED`,`Not logged in`,{hint:`Run eloqnt login to authenticate.`});let r=await fetch(new URL(`/api/engine/me`,n()),{headers:o(e)});if(r.status===401)throw new i(`NOT_AUTHENTICATED`,`Your session has expired`,{hint:`Run eloqnt login to sign in again.`});if(!r.ok)throw new i(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The engine responded with ${r.status}.`,hint:`This is on our end. Try again in a few minutes.`});let s=a.safeParse(await r.json());if(!s.success)throw new i(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The engine returned an unexpected response.`,hint:`This is on our end. Try again in a few minutes.`});let{user:c,plans:l,hosted:u}=s.data;return{email:c.email,plans:l,hosted:u}},render:({email:e,plans:t,hosted:i})=>{let a=[`${s(`Email:`)}${e}`,`${s(`Plan:`)}${l(t,i)}`];return i&&a.push(`${s(`Quota used:`)}${u(i)}`),t.length===0&&a.push(``,r.cyan(`→ Choose a plan at ${n()}/plans`)),a.join(`
2
2
  `)},json:e=>e});function l(e,t){if(e.length===0)return r.yellow(`none`);let n=e.map(e=>e===`hosted`?`Hosted model`:`Bring your own model`),i=t?.status===`trialing`?r.dim(` (trial, includes 1/4 of monthly usage)`):``;return r.green(n.join(` + `))+i}function u(e){let{usedPercent:t,resetsAt:n}=e,i=`${t}%`;return`${t>=100?r.red(i):t>=80?r.yellow(i):r.green(i)} (resets ${new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(new Date(n))})`}export{c as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eloqnt/cli",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "A linter for your translation files, with AI translation built in.",
5
5
  "keywords": [
6
6
  "i18n",
@@ -37,7 +37,7 @@
37
37
  "citty": "^0.1.6",
38
38
  "open": "^11.0.0",
39
39
  "picocolors": "^1.1.1",
40
- "@eloqnt/sdk": "0.7.0"
40
+ "@eloqnt/sdk": "0.7.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/node": "^25.9.5"
@@ -1 +0,0 @@
1
- import e from"node:process";import{dirname as t,join as n}from"node:path";import{EloqntSdkError as r}from"@eloqnt/sdk/_internal";import{homedir as i}from"node:os";import{mkdir as a,readFile as o,rm as s,writeFile as c}from"node:fs/promises";function l(){let t=e.env.XDG_CONFIG_HOME??n(i(),`.config`);return n(t,`eloqnt`,`credentials.json`)}async function u(){if(e.env.ELOQNT_TOKEN)return e.env.ELOQNT_TOKEN;try{let e=await o(l(),`utf8`),t=JSON.parse(e);return typeof t.token==`string`?t.token:void 0}catch{return}}async function d(e){let n=l();return await a(t(n),{recursive:!0}),await c(n,`${JSON.stringify({token:e},null,2)}\n`,{mode:384}),n}async function f(){try{return await s(l()),!0}catch{return!1}}const p=`https://engine.eloqnt.dev`;function m(e,t){let n;try{n=new URL(e)}catch{throw new r(`INVALID_ENGINE_URL`,`Can't use ${e} as the engine URL`,{details:`${t} isn't a valid URL.`,hint:`Unset ${t} to use ${p}.`})}if(n.origin!==p&&n.hostname!==`localhost`)throw new r(`INVALID_ENGINE_URL`,`Can't use ${n.origin} as the engine URL`,{details:`${t} takes ${p} or a localhost address, and nothing else.`,hint:`Unset ${t} to use ${p}.`});return n.origin}function h(){return e.env.ELOQNT_ENGINE_URL===void 0?e.env.ELOQNT_STUDIO_URL===void 0?p:m(e.env.ELOQNT_STUDIO_URL,`ELOQNT_STUDIO_URL`):m(e.env.ELOQNT_ENGINE_URL,`ELOQNT_ENGINE_URL`)}function g(){return`${h()}/api/auth`}const _=`https://cli.eloqnt.dev`;export{u as a,f as i,g as n,d as o,h as r,_ as t};