@eloqnt/cli 0.2.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @eloqnt/cli
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1512c63: Drop internal exports from `@eloqnt/sdk`'s public entry. The main entry now surfaces only what's intended for external use (`lint`, `defineConfig`, `defineCodec`, `translate`, and their return types); everything else moved to `@eloqnt/sdk/_internal` for workspace-only consumption.
8
+
9
+ ### Patch Changes
10
+
11
+ - 0bea265: `eloqnt translate` now confirms whether your styleguides were picked up before the engine runs.
12
+ - 1512c63: Drop the engine API's backward-compat fields for pre-split CLIs. The older clients weren't actually picking them up in practice, so the fallback wasn't doing anything anyway.
13
+ - 1512c63: Merge `@eloqnt/inference` into `@eloqnt/sdk`.
14
+ - b184054: Add support for messages extracted by experimental `useExtracted` in `next-intl@<4.13`.
15
+ - Updated dependencies [1512c63]
16
+ - Updated dependencies [1512c63]
17
+ - Updated dependencies [b184054]
18
+ - Updated dependencies [5927856]
19
+ - Updated dependencies [e9e4514]
20
+ - Updated dependencies [1512c63]
21
+ - @eloqnt/sdk@0.3.0
22
+
3
23
  ## 0.2.0
4
24
 
5
25
  ### Minor Changes
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import e from"node:process";import{defineCommand as t,runMain as n}from"citty";try{e.loadEnvFile()}catch{}n(t({meta:{name:`eloqnt`,description:`AI-powered translations for developers`},subCommands:{lint:r(()=>import(`../lint-DJ_-UKqz.mjs`)),translate:r(()=>import(`../translate-CTKPYnvn.mjs`)),login:r(()=>import(`../login-7qeWfZff.mjs`)),logout:r(()=>import(`../logout-CzVVtihJ.mjs`)),whoami:r(()=>import(`../whoami-O271iSvl.mjs`))}}));function r(e){return()=>e().then(e=>e.default)}export{};
2
+ import e from"node:process";import{defineCommand as t,runMain as n}from"citty";try{e.loadEnvFile()}catch{}n(t({meta:{name:`eloqnt`,description:`AI-powered translations for developers`},subCommands:{lint:r(()=>import(`../lint-DJ-RHUGB.mjs`)),translate:r(()=>import(`../translate-DPkpSc4M.mjs`)),login:r(()=>import(`../login-r1L6n3HP.mjs`)),logout:r(()=>import(`../logout-BjdvLusP.mjs`)),whoami:r(()=>import(`../whoami-Z3z2RxwG.mjs`))}}));function r(e){return()=>e().then(e=>e.default)}export{};
@@ -0,0 +1 @@
1
+ import{t as e}from"./withErrorFormatting-CnMLjXSn.mjs";import t from"node:process";import{defineCommand as n}from"citty";import{loadConfig as r}from"@eloqnt/sdk/_internal";function i(i){let a=i.requiresConfig!==!1;return n({meta:i.meta,args:{...a&&{config:{type:`string`,description:`Path to the eloqnt config file (defaults to .eloqnt/config.{ts,mts,js,mjs})`}},json:{type:`boolean`,description:`Output the result as JSON`,default:!1},...i.args},run({args:n}){return e(async()=>{let e;if(a){let{config:t,rootDir:i}=await r({configPath:n.config});e={config:t,rootDir:i,args:n}}else e={config:void 0,rootDir:t.cwd(),args:n};let o=await i.execute(e),s=n.json?JSON.stringify(i.json?i.json(o):o,null,2):i.render(o);t.stdout.write(`${s}\n`),i.ok&&!i.ok(o)&&(t.exitCode=1)})}})}export{i as t};
@@ -1,4 +1,4 @@
1
- import{t as e}from"./defineEloqntCommand-BEnYhPuF.mjs";import{t}from"./resolvePaths-Bc7dGH8a.mjs";import{lint as n}from"@eloqnt/sdk";import r from"node:process";import{basename as i,relative as a}from"node:path";import o from"picocolors";const s=new Intl.Segmenter,c=[[4352,4447],[9001,9002],[11904,12350],[12353,13311],[13312,19903],[19968,40959],[40960,42191],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[126976,127743],[127744,129791],[131072,262141]];function l(e){let t=[];for(let{segment:n}of s.segment(e))t.push({text:n,width:d(n)});return t}function u(e){let t=0;for(let{segment:n}of s.segment(e))t+=d(n);return t}function d(e){let t=e.codePointAt(0)??0;return f(t)?0:c.some(([e,n])=>t>=e&&t<=n)?2:1}function f(e){return e<=31||e>=127&&e<=159||e>=768&&e<=879||e>=8203&&e<=8207||e>=8232&&e<=8238||e>=8288&&e<=8292||e===65279}var p=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},async execute({config:e,rootDir:o}){let{messages:s,srcPath:c}=e,l=await n({messagesPath:t(s.path,o),sourceLocale:s.sourceLocale,format:s.format,locales:s.locales,srcPath:c?t(c,o):void 0,cwd:o}),u=r.cwd();return{issues:l.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:a(u,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({path:a(u,e.path)})),n=e.length>1?` (+${e.length-1} more)`:``,r=t.location?i(t.location.file):`the source catalog`;t={...t,sourceReferences:e,message:`Used in ${e[0].path}${n} but not defined in ${r}`}}return t}),sourceLocale:s.sourceLocale}},render:({issues:e,sourceLocale:t})=>m(e,t),ok:({issues:e})=>e.length===0,json:({issues:e})=>e});function m(e,t){if(e.length===0)return`\n${o.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=h(Object.entries(n),t).map(([e,n])=>g(e,n,n[0].locale===t)),i=`${e.length} ${e.length===1?`issue`:`issues`}`,a=o.bold(o.red(`✗ ${i} found`)),s=e.filter(e=>e.rule===`missing-translation`).length,c=s?`${a}\n${o.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`)}`:a;return`\n${[...r,c].join(`
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./resolvePaths-Bc7dGH8a.mjs";import{lint as n}from"@eloqnt/sdk";import r from"node:process";import{basename as i,relative as a}from"node:path";import o from"picocolors";const s=new Intl.Segmenter,c=[[4352,4447],[9001,9002],[11904,12350],[12353,13311],[13312,19903],[19968,40959],[40960,42191],[44032,55203],[63744,64255],[65040,65049],[65072,65135],[65280,65376],[65504,65510],[126976,127743],[127744,129791],[131072,262141]];function l(e){let t=[];for(let{segment:n}of s.segment(e))t.push({text:n,width:d(n)});return t}function u(e){let t=0;for(let{segment:n}of s.segment(e))t+=d(n);return t}function d(e){let t=e.codePointAt(0)??0;return f(t)?0:c.some(([e,n])=>t>=e&&t<=n)?2:1}function f(e){return e<=31||e>=127&&e<=159||e>=768&&e<=879||e>=8203&&e<=8207||e>=8232&&e<=8238||e>=8288&&e<=8292||e===65279}var p=e({meta:{name:`lint`,description:`Statically analyze your source code and messages for common problems.`},async execute({config:e,rootDir:o}){let{messages:s,srcPath:c}=e,l=await n({messagesPath:t(s.path,o),sourceLocale:s.sourceLocale,format:s.format,locales:s.locales,srcPath:c?t(c,o):void 0,cwd:o}),u=r.cwd();return{issues:l.map(e=>{let t=e;if(t.location&&(t={...t,location:{...t.location,file:a(u,t.location.file)}}),t.rule===`undefined-key`&&t.sourceReferences?.length){let e=t.sourceReferences.map(e=>({path:a(u,e.path)})),n=e.length>1?` (+${e.length-1} more)`:``,r=t.location?i(t.location.file):`the source catalog`;t={...t,sourceReferences:e,message:`Used in ${e[0].path}${n} but not defined in ${r}`}}return t}),sourceLocale:s.sourceLocale}},render:({issues:e,sourceLocale:t})=>m(e,t),ok:({issues:e})=>e.length===0,json:({issues:e})=>e});function m(e,t){if(e.length===0)return`\n${o.green(`No issues found`)}\n`;let n=Object.groupBy(e,e=>e.location?.file??e.locale),r=h(Object.entries(n),t).map(([e,n])=>g(e,n,n[0].locale===t)),i=`${e.length} ${e.length===1?`issue`:`issues`}`,a=o.bold(o.red(`✗ ${i} found`)),s=e.filter(e=>e.rule===`missing-translation`).length,c=s?`${a}\n${o.dim(`→ Run \`eloqnt translate\` to fill in ${s} missing ${s===1?`translation`:`translations`}`)}`:a;return`\n${[...r,c].join(`
2
2
 
3
3
  `)}\n`}function h(e,t){let n=e.findIndex(([,e])=>e[0].locale===t);if(n<=0)return e;let r=[...e],[i]=r.splice(n,1);return[i,...r]}function g(e,t,n){let r=[n?`${o.cyan(e)} ${o.dim(`(source locale)`)}`:o.cyan(e)];for(let e of t){r.push(o.dim(`│`));let{content:t,span:n}=_(e);r.push(b(t)),r.push(...y(n,e.message,e.rule))}return r.join(`
4
4
  `)}function _(e){let t=`"${e.key}"`,n=e.targetMessage??e.sourceMessage,r=v(t),i=e.highlight?.type===`value`||e.highlight?.type===`argument`,a=i?o.dim(t):t,s=o.dim(`: `),c=u(t);if(n!==void 0&&e.highlight?.type===`argument`){let t=T(n),i=e.highlight.token,o=t.indexOf(i);if(o>=0){let{inner:e,offset:n}=x(t,o,i.length,r);return{content:`${a}${s}"${e}"`,span:{column:c+3+n,length:u(i)}}}}let l=n===void 0?`"…"`:`"${E(T(n),r)}"`,d=`${a}${s}${i?l:o.dim(l)}`;return n!==void 0&&e.highlight?.type===`value`?{content:d,span:{column:c+2,length:u(l)}}:{content:d,span:{column:0,length:c}}}function v(e){let t=3+u(e)+2+2;return Math.max(24,Math.min(48,80-t))}function y(e,t,n){let r=Math.min(1,e.length-1),i=`─`.repeat(r)+`┬`+`─`.repeat(e.length-1-r),a=`${t} ${o.dim(`(${n})`)}`;return[b(` `.repeat(e.column)+o.yellow(i)),b(`${` `.repeat(e.column+r)}${o.yellow(`╰─`)} ${a}`)]}function b(e){return o.dim(`│ `)+e}function x(e,t,n,r){let i=l(e),a=i.reduce((e,t)=>e+t.width,0),o=S(i,t),s=S(i,t+n);if(a<=r)return{inner:e,offset:C(i,0,o)};let c=Math.max(C(i,o,s),r-2),u=o,d=0;for(;u>0&&d+i[u-1].width<=16;)u--,d+=i[u].width;let f=o;for(;f<i.length&&d+i[f].width<=c;)d+=i[f].width,f++;for(;u>0&&d+i[u-1].width<=c;)u--,d+=i[u].width;let p=u>0?`…`:``,m=f<i.length?`…`:``;return{inner:p+i.slice(u,f).map(e=>e.text).join(``)+m,offset:C(i,u,o)+p.length}}function S(e,t){let n=0;for(let r=0;r<e.length;r++){if(n>=t)return r;n+=e[r].text.length}return e.length}function C(e,t,n){let r=0;for(let i=t;i<n;i++)r+=e[i].width;return r}const w=RegExp(`[\0--Ÿ]`,`g`);function T(e){return e.replace(/\s+/g,` `).replace(w,``).trim()}function E(e,t){if(u(e)<=t)return e;let n=``,r=0;for(let i of l(e)){if(r+i.width>t-1)break;n+=i.text,r+=i.width}return`${n}…`}export{p as default,m as formatLint};
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./withErrorFormatting-CnMLjXSn.mjs";import{a as t,i as n,n as r,t as i}from"./urls-BrJoRsYB.mjs";import{t as a}from"./createSpinner-BBkrpcrh.mjs";import o from"node:process";import{defineCommand as s}from"citty";import c from"picocolors";import{EloqntSdkError as l,getAuthHeaders as u}from"@eloqnt/sdk/_internal";import{hostname as d}from"node:os";import{setTimeout as f}from"node:timers/promises";import{outro as p}from"@clack/prompts";import m from"open";var h=`0.3.0`;function g(e){m(e).catch(()=>{})}const _=`eloqnt-cli`,v=`eloqnt-cli/${h} (${d()}; ${o.platform} ${o.arch}; node ${o.version})`;var y=s({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},run:()=>e(async()=>{let e=i(),s=await n();s&&await fetch(`${e}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${s}`,"content-type":`application/json`,"user-agent":v},body:JSON.stringify({token:s})}).catch(()=>{});let u=await fetch(`${e}/device/code`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({client_id:_})});if(!u.ok)throw new l(`ENGINE_UNREACHABLE`,`Couldn't start the login flow`,{details:`The auth server responded with ${u.status}.`,hint:`Check your connection and run eloqnt login again.`});let d=await u.json();o.stderr.write(`\n${c.cyan(`Log in to eloqnt studio`)}\n`),o.stderr.write(c.dim(`${d.verification_uri_complete}\n\n`)),g(d.verification_uri_complete);let f=o.stderr.isTTY?a():void 0;f?f.start(`Waiting for approval in the browser`):o.stderr.write(c.dim(`Waiting for approval in the browser …
2
+ `));let m=await x(e,d);if(!m.access_token)throw f?.stop(c.dim(`Login cancelled`)),new l(`NOT_AUTHENTICATED`,m.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await t(m.access_token),f?(f.stop(c.dim(`Approved in the browser`)),p(c.green(`Logged in`))):o.stdout.write(`${c.green(`Logged in`)}\n`),await b(m.access_token)&&o.stderr.write(`\n${c.cyan(`→ Choose a plan at ${r()}/plans`)}\n`)})});async function b(e){try{let t=await fetch(new URL(`/api/engine/me`,r()),{headers:u(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 f(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-BzsnYkDV.mjs";import{i as t,r as n,t as r}from"./urls-BrJoRsYB.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 studio 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-CnMLjXSn.mjs";import{i as t,r as n,t as r}from"./urls-BrJoRsYB.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 studio 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};
@@ -0,0 +1,8 @@
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{t}from"./resolvePaths-Bc7dGH8a.mjs";import{i as n,n as r}from"./urls-BrJoRsYB.mjs";import{t as i}from"./createSpinner-BBkrpcrh.mjs";import{translate as a}from"@eloqnt/sdk";import o from"node:process";import{basename as s,dirname as c,relative as l}from"node:path";import u from"picocolors";import{loadStyleguide as d}from"@eloqnt/sdk/_internal";function f(e,t={month:`short`,day:`numeric`}){return new Date(e).toLocaleDateString(`en-US`,t)}function p(e,t){o.stderr.write(`${e} ${u.dim(t)}\n`)}var m=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:s,args:c}){let{messages:f,srcPath:m}=e,h=t(f.path,s),g=m?t(m,s):void 0,_=await d({cwd:s}),v=+!!_.base+Object.keys(_.byLocale).length,y=v===0,b=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,x=typeof c.locale==`string`?c.locale.split(`,`):Array.isArray(f.locales)?f.locales.filter(e=>e!==f.sourceLocale):void 0,S=`${x?.length?`${x.join(`, `)} `:``}via ${b}`,C=o.stderr.isTTY&&!c.json,w;function T(e){if(!c.json){if(e.phase===`context-enrichment`){e.state===`started`?(o.stderr.write(`
2
+ `),C?(w=i({withGuide:!1}),w.start(`Context enrichment running`)):o.stderr.write(u.dim(`Context enrichment running …
3
+ `))):e.state===`completed`?(w?.clear(),w=void 0,p(u.green(`✔`),`Context enrichment complete`)):(o.stderr.write(`
4
+ `),p(u.dim(`–`),"Skipped context enrichment — set `srcPath` to enable"));return}if(e.phase===`translate`){e.state===`started`?(y?p(u.dim(`–`),`No styleguides found`):p(u.green(`✔`),v===1?`Styleguide loaded`:`Styleguides loaded`),C?(w=i({withGuide:!1}),w.start(`Translating ${S}`)):o.stderr.write(u.dim(`Translating ${S} …\n`))):(w?.clear(),w=void 0,p(u.green(`✔`),`Translated ${S}`));return}e.state===`started`?C?(w=i({withGuide:!1}),w.start(`Post-translation checks running`)):o.stderr.write(u.dim(`Post-translation checks running …
5
+ `)):(w?.clear(),w=void 0,p(u.green(`✔`),`Post-translation checks done`))}}let E;try{E=await a({messagesPath:h,sourceLocale:f.sourceLocale,format:f.format,locales:f.locales,cwd:s,engineUrl:r(),languageModel:e.model,authToken:await n(),styleguide:_,ids:typeof c.id==`string`?c.id.split(`,`):void 0,onlyLocales:typeof c.locale==`string`?c.locale.split(`,`):void 0,srcPath:g,onProgress:T})}catch(e){throw w?.clear(),e}let D=o.cwd(),O=E.targets.flatMap(e=>e.files.map(e=>({file:l(D,e.file),count:e.translated.length})));return{result:E,rows:O,complete:E.complete,noStyleguides:y}},render({result:e,rows:t,complete:n,noStyleguides:i}){let a=Object.groupBy(t,e=>c(e.file));return`\n${Object.entries(a).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>s(e.file).length)),r=t.map(e=>` ${s(e.file).padEnd(n)} ${e.count===0?u.dim(`Nothing to translate`):u.green(`${e.count} translated`)}`);return[u.dim(`${e}/`),...r].join(`
6
+ `)}).join(`
7
+
8
+ `)}\n\n${n?u.green(`✔ Project fully translated`):e.quota?u.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${f(e.quota.resetsAt)}`):u.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}${i?`\n\n${u.dim(`→ Add a styleguide to improve your translation quality`)}\n${u.dim(` ${r()}/docs#styleguides`)}`:``}`},json:({result:e})=>e});export{m as default};
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./defineEloqntCommand-BNNDggcZ.mjs";import{i as t,n}from"./urls-BrJoRsYB.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)}`];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
+ `)},json:e=>e});function l(e){if(e.length===0)return r.yellow(`none`);let t=e.map(e=>e===`hosted`?`Hosted model`:`Bring your own model`);return r.green(t.join(` + `))}function u(e){let{status:t,usedPercent:n,resetsAt:i}=e,a=`${n}%`;return`${n>=100?r.red(a):n>=80?r.yellow(a):r.green(a)} (resets ${new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(new Date(i))})${t===`trialing`?r.dim(` (trial)`):``}`}export{c as default};
@@ -0,0 +1,2 @@
1
+ import e from"node:process";import t from"picocolors";import{EloqntSdkError as n}from"@eloqnt/sdk/_internal";function r(e){let n=[`${t.red(t.bold(`✗ ${e.message}`))} ${t.dim(`(${e.code})`)}`],{details:r}=e;if(r)if(n.push(``),typeof r==`string`)n.push(` ${r}`);else{n.push(` ${r.heading}`);for(let e of r.items)n.push(` ${t.dim(`•`)} ${e}`)}return n.push(``,t.cyan(`→ ${e.hint}`)),e.docsUrl&&n.push(t.dim(` ${e.docsUrl}`)),`\n${n.join(`
2
+ `)}`}async function i(t){try{await t()}catch(t){if(t instanceof n){e.stderr.write(`${r(t)}\n`),e.exitCode=1;return}throw t}}export{i as t};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eloqnt/cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "CLI for eloqnt/studio",
5
5
  "repository": {
6
6
  "type": "git",
@@ -30,7 +30,7 @@
30
30
  "citty": "^0.1.6",
31
31
  "open": "^11.0.0",
32
32
  "picocolors": "^1.1.1",
33
- "@eloqnt/sdk": "0.2.0"
33
+ "@eloqnt/sdk": "0.3.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/node": "^25.9.1"
@@ -1 +0,0 @@
1
- import{t as e}from"./withErrorFormatting-BzsnYkDV.mjs";import{loadConfig as t}from"@eloqnt/sdk";import n from"node:process";import{defineCommand as r}from"citty";function i(i){let a=i.requiresConfig!==!1;return r({meta:i.meta,args:{...a&&{config:{type:`string`,description:`Path to the eloqnt config file (defaults to .eloqnt/config.{ts,mts,js,mjs})`}},json:{type:`boolean`,description:`Output the result as JSON`,default:!1},...i.args},run({args:r}){return e(async()=>{let e;if(a){let{config:n,rootDir:i}=await t({configPath:r.config});e={config:n,rootDir:i,args:r}}else e={config:void 0,rootDir:n.cwd(),args:r};let o=await i.execute(e),s=r.json?JSON.stringify(i.json?i.json(o):o,null,2):i.render(o);n.stdout.write(`${s}\n`),i.ok&&!i.ok(o)&&(n.exitCode=1)})}})}export{i as t};
@@ -1,2 +0,0 @@
1
- import{t as e}from"./withErrorFormatting-BzsnYkDV.mjs";import{a as t,i as n,n as r,t as i}from"./urls-BrJoRsYB.mjs";import{t as a}from"./createSpinner-BBkrpcrh.mjs";import{EloqntSdkError as o,getAuthHeaders as s}from"@eloqnt/sdk";import c from"node:process";import{defineCommand as l}from"citty";import u from"picocolors";import{hostname as d}from"node:os";import{setTimeout as f}from"node:timers/promises";import{outro as p}from"@clack/prompts";import m from"open";var h=`0.2.0`;function g(e){m(e).catch(()=>{})}const _=`eloqnt-cli`,v=`eloqnt-cli/${h} (${d()}; ${c.platform} ${c.arch}; node ${c.version})`;var y=l({meta:{name:`login`,description:`Authenticates the CLI by storing an auth token locally.`},run:()=>e(async()=>{let e=i(),s=await n();s&&await fetch(`${e}/revoke-session`,{method:`POST`,headers:{authorization:`Bearer ${s}`,"content-type":`application/json`,"user-agent":v},body:JSON.stringify({token:s})}).catch(()=>{});let l=await fetch(`${e}/device/code`,{method:`POST`,headers:{"content-type":`application/json`,"user-agent":v},body:JSON.stringify({client_id:_})});if(!l.ok)throw new o(`ENGINE_UNREACHABLE`,`Couldn't start the login flow`,{details:`The auth server responded with ${l.status}.`,hint:`Check your connection and run eloqnt login again.`});let d=await l.json();c.stderr.write(`\n${u.cyan(`Log in to eloqnt studio`)}\n`),c.stderr.write(u.dim(`${d.verification_uri_complete}\n\n`)),g(d.verification_uri_complete);let f=c.stderr.isTTY?a():void 0;f?f.start(`Waiting for approval in the browser`):c.stderr.write(u.dim(`Waiting for approval in the browser …
2
- `));let m=await x(e,d);if(!m.access_token)throw f?.stop(u.dim(`Login cancelled`)),new o(`NOT_AUTHENTICATED`,m.error_description??`Login failed`,{hint:`Run eloqnt login to try again.`});await t(m.access_token),f?(f.stop(u.dim(`Approved in the browser`)),p(u.green(`Logged in`))):c.stdout.write(`${u.green(`Logged in`)}\n`),await b(m.access_token)&&c.stderr.write(`\n${u.cyan(`→ Choose a plan at ${r()}/plans`)}\n`)})});async function b(e){try{let t=await fetch(new URL(`/api/engine/me`,r()),{headers:s(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 f(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,8 +0,0 @@
1
- import{t as e}from"./defineEloqntCommand-BEnYhPuF.mjs";import{t}from"./resolvePaths-Bc7dGH8a.mjs";import{i as n,n as r}from"./urls-BrJoRsYB.mjs";import{t as i}from"./createSpinner-BBkrpcrh.mjs";import{loadStyleguide as a,translate as o}from"@eloqnt/sdk";import s from"node:process";import{basename as c,dirname as l,relative as u}from"node:path";import d from"picocolors";function f(e,t={month:`short`,day:`numeric`}){return new Date(e).toLocaleDateString(`en-US`,t)}function p(e,t){s.stderr.write(`${e} ${d.dim(t)}\n`)}var m=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:c,args:l}){let{messages:f,srcPath:m}=e,h=t(f.path,c),g=m?t(m,c):void 0,_=await a({cwd:c}),v=e.model?`eloqnt/engine (${typeof e.model==`string`?e.model:e.model.modelId})`:`eloqnt/engine (hosted)`,y=typeof l.locale==`string`?l.locale.split(`,`):Array.isArray(f.locales)?f.locales.filter(e=>e!==f.sourceLocale):void 0,b=`${y?.length?`${y.join(`, `)} `:``}via ${v}`,x=s.stderr.isTTY&&!l.json,S;function C(e){if(!l.json){if(e.phase===`context-enrichment`){e.state===`started`?(s.stderr.write(`
2
- `),x?(S=i({withGuide:!1}),S.start(`Context enrichment running`)):s.stderr.write(d.dim(`Context enrichment running …
3
- `))):e.state===`completed`?(S?.clear(),S=void 0,p(d.green(`✔`),`Context enrichment complete`)):(s.stderr.write(`
4
- `),p(d.dim(`–`),"Skipped context enrichment — set `srcPath` to enable"));return}if(e.phase===`translate`){e.state===`started`?x?(S=i({withGuide:!1}),S.start(`Translating ${b}`)):s.stderr.write(d.dim(`Translating ${b} …\n`)):(S?.clear(),S=void 0,p(d.green(`✔`),`Translated ${b}`));return}e.state===`started`?x?(S=i({withGuide:!1}),S.start(`Post-translation checks running`)):s.stderr.write(d.dim(`Post-translation checks running …
5
- `)):(S?.clear(),S=void 0,p(d.green(`✔`),`Post-translation checks done`))}}let w;try{w=await o({messagesPath:h,sourceLocale:f.sourceLocale,format:f.format,locales:f.locales,cwd:c,engineUrl:r(),languageModel:e.model,authToken:await n(),styleguide:_,ids:typeof l.id==`string`?l.id.split(`,`):void 0,onlyLocales:typeof l.locale==`string`?l.locale.split(`,`):void 0,srcPath:g,onProgress:C})}catch(e){throw S?.clear(),e}let T=s.cwd(),E=w.targets.flatMap(e=>e.files.map(e=>({file:u(T,e.file),count:e.translated.length})));return{result:w,rows:E,complete:w.complete}},render({result:e,rows:t,complete:n}){let r=Object.groupBy(t,e=>l(e.file));return`\n${Object.entries(r).map(([e,t=[]])=>{let n=Math.max(0,...t.map(e=>c(e.file).length)),r=t.map(e=>` ${c(e.file).padEnd(n)} ${e.count===0?d.dim(`Nothing to translate`):d.green(`${e.count} translated`)}`);return[d.dim(`${e}/`),...r].join(`
6
- `)}).join(`
7
-
8
- `)}\n\n${n?d.green(`✔ Project fully translated`):e.quota?d.yellow(`! Monthly included usage exhausted, translated as much as possible. Resets ${f(e.quota.resetsAt)}`):d.dim(`✗ Partially translated, run eloqnt lint to see what's left`)}`},json:({result:e})=>e});export{m as default};
@@ -1,2 +0,0 @@
1
- import{t as e}from"./defineEloqntCommand-BEnYhPuF.mjs";import{i as t,n}from"./urls-BrJoRsYB.mjs";import{EloqntSdkError as r,getAuthHeaders as i}from"@eloqnt/sdk";import a from"picocolors";function o(e){return a.dim(e.padEnd(12))}var s=e({meta:{name:`whoami`,description:`Shows the logged-in user account.`},requiresConfig:!1,async execute(){let e=await t();if(!e)throw new r(`NOT_AUTHENTICATED`,`Not logged in`,{hint:`Run eloqnt login to authenticate.`});let a=await fetch(new URL(`/api/engine/me`,n()),{headers:i(e)});if(a.status===401)throw new r(`NOT_AUTHENTICATED`,`Your session has expired`,{hint:`Run eloqnt login to sign in again.`});if(!a.ok)throw new r(`ENGINE_ERROR`,`Sorry, we couldn't load your account`,{details:`The studio API responded with ${a.status}.`,hint:`This is on our end. Try again in a few minutes.`});let o=await a.json();return{email:o.user.email,plans:o.plans,hosted:o.hosted}},render:({email:e,plans:t,hosted:r})=>{let i=[`${o(`Email:`)}${e}`,`${o(`Plan:`)}${c(t)}`];return r&&i.push(`${o(`Quota used:`)}${l(r)}`),t.length===0&&i.push(``,a.cyan(`→ Choose a plan at ${n()}/plans`)),i.join(`
2
- `)},json:e=>e});function c(e){if(e.length===0)return a.yellow(`none`);let t=e.map(e=>e===`hosted`?`Hosted model`:`Bring your own model`);return a.green(t.join(` + `))}function l({status:e,usedPercent:t,resetsAt:n}){let r=`${t}%`;return`${t>=100?a.red(r):t>=80?a.yellow(r):a.green(r)} (resets ${new Intl.DateTimeFormat(`en-US`,{month:`short`,day:`numeric`}).format(new Date(n))})${e===`trialing`?a.dim(` (trial)`):``}`}export{s as default};
@@ -1,2 +0,0 @@
1
- import{EloqntSdkError as e}from"@eloqnt/sdk";import t from"node:process";import n from"picocolors";function r(e){let t=[`${n.red(n.bold(`✗ ${e.message}`))} ${n.dim(`(${e.code})`)}`],{details:r}=e;if(r)if(t.push(``),typeof r==`string`)t.push(` ${r}`);else{t.push(` ${r.heading}`);for(let e of r.items)t.push(` ${n.dim(`•`)} ${e}`)}return t.push(``,n.cyan(`→ ${e.hint}`)),e.docsUrl&&t.push(n.dim(` ${e.docsUrl}`)),`\n${t.join(`
2
- `)}`}async function i(n){try{await n()}catch(n){if(n instanceof e){t.stderr.write(`${r(n)}\n`),t.exitCode=1;return}throw n}}export{i as t};