bailian-cli-runtime 2.0.1 → 2.1.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.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -1
  2. package/package.json +2 -2
package/dist/index.mjs CHANGED
@@ -46,7 +46,7 @@ If you are behind a VPN or corporate proxy, route ${R} through it:\nexport HTTPS
46
46
  `):Fn(e),process.exit(e.exitCode)),e instanceof Error){if(e.name===`AbortError`||e.name===`TimeoutError`||e.message.includes(`timed out`))return B(new t(`Request timed out.`,c.TIMEOUT,`Try increasing --timeout (e.g. --timeout 60).
47
47
  ${En()}\nRun: ${R} auth status — to check credentials.`,{cause:e}),R);if(e instanceof TypeError&&e.message===`fetch failed`)return B(jn(e),R);let n=e.code;if(typeof n==`string`&&n.startsWith(`E`))return B(Nn(e),R);process.stderr.write(`\n${z(`Error:`)}${e.message}\n`),Pn(e),process.env.DASHSCOPE_VERBOSE===`1`&&process.stderr.write(`${e.stack}\n`)}else process.stderr.write(`\n${z(`Error:`)}${String(e)}\n`);process.exit(c.GENERAL)}function In(e){return N(ne(),`plugins`,e.npmPackage)}function Ln(e){return N(In(e),`package.json`)}function Rn(e,t){return N(In(e),`node_modules`,...t.split(`/`))}async function zn(e){try{return JSON.parse(await We(e,`utf8`))}catch(n){throw new t(`Could not parse JSON file: ${e}`,c.GENERAL,`Repair or remove the invalid file and try again.`,{cause:n})}}async function Bn(e){let t=Ln(e);return Re(t)?zn(t):{dependencies:{}}}async function Vn(e,t){return Hn(Rn(e,t))}async function Hn(e){return zn(N(e,`package.json`))}const Un=/* @__PURE__ */ new Set([`none`,`apiKey`,`console`,`openapi`]),Wn=/^[a-z0-9][a-z0-9-]*$/;function Gn(e,t,r){if(t.name!==e)throw Error(`Package name mismatch: expected "${e}", received "${t.name??``}".`);let i=t.bailianCli;if(!i||i.type!==`command-pack`)throw Error(`Package "${e}" is missing bailianCli.type="command-pack".`);if(i.apiVersion!==n)throw Error(`Command Pack API ${i.apiVersion} is not supported; this CLI supports API ${n}.`);if(i.minCliVersion&&qt(r.version,i.minCliVersion)<0)throw Error(`Command Pack requires ${r.npmPackage} ${i.minCliVersion} or newer; current version is ${r.version}.`);if(!i.entry||Qe(i.entry))throw Error(`Command Pack "${e}" must declare a relative bailianCli.entry.`);return i}function Kn(e,t){let n=e.split(/\s+/).filter(Boolean).join(` `);if(!e||e!==n||!e.split(` `).every(e=>Wn.test(e)))throw Error(`Invalid command path "${e}".`);if(!t.commandPrefixes.some(t=>e===t||e.startsWith(`${t} `)))throw Error(`Command "${e}" is outside the allowed prefixes: ${t.commandPrefixes.join(`, `)}.`)}function qn(e){if(typeof e==`string`)return e.length>0;if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return f.every(e=>typeof t[e]==`string`&&t[e].length>0)}function Jn(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return t.level===`high`&&qn(t.message)}function Yn(e,t){if(!t||typeof t!=`object`)throw Error(`Command "${e}" must export an object.`);let n=t;if(!qn(n.description))throw Error(`Command "${e}" is missing a description.`);if(!n.auth||!Un.has(n.auth))throw Error(`Command "${e}" has an invalid auth requirement.`);if(n.risk!==void 0&&!Jn(n.risk))throw Error(`Command "${e}" has invalid risk metadata.`);if(typeof n.run!=`function`)throw Error(`Command "${e}" is missing run(ctx).`)}function Xn(e,n,r){return Object.fromEntries(Object.entries(n).map(([n,i])=>[n,{description:i.description,auth:i.auth,risk:i.risk,usageArgs:i.usageArgs,exampleArgs:i.exampleArgs,notes:i.notes,flags:i.flags,validate:i.validate,run:a=>{let o={identity:a.identity,settings:a.settings,flags:a.flags,client:a.client,output:{result(e,t){let n=a.settings.output===`text`&&t?.text!==void 0?t.text:te(e,a.settings.output);process.stdout.write(`${n}\n`)},line(e){process.stdout.write(`${e}\n`)},write(e){process.stdout.write(e)}},errors:{general(e,n){return new t(e,c.GENERAL,n?.hint,{cause:n?.cause})},usage(e,t){return new p(e,t)},timeout(e=`Request timed out.`,n){return new t(e,c.TIMEOUT,n?.hint,{cause:n?.cause})}},credentials:{apiKey(){if(!r.credentialAccess?.includes(`apiKey`))throw new t(`Command Pack "${e}" is not allowed to access API-key credentials.`,c.GENERAL);if(i.auth!==`apiKey`)throw new t(`Command "${n}" must declare auth="apiKey" before accessing API-key credentials.`,c.GENERAL);let o=a.client.exportApiCredential();if(!o)throw new t(`No API key available to the Command Pack.`,c.AUTH);return o}}};return i.run(o)}}]))}async function Zn(e,t,n,r,i=Rn(r,e)){let a=Gn(e,t,r),o=await qe(i),s=await qe(et(o,a.entry)),c=$e(o,s);if(!c||c.startsWith(`..`)||Qe(c))throw Error(`Command Pack entry must stay inside the package root: ${a.entry}`);let l=(await import(tt(s).href)).default;if(!l||typeof l!=`object`||Array.isArray(l))throw Error(`Command Pack "${e}" must default-export a command map.`);let u=Object.entries(l);if(u.length===0)throw Error(`Command Pack "${e}" does not export any commands.`);for(let[e,t]of u)Kn(e,n),Yn(e,t);let d=Xn(e,l,n);return new Nt(d,r.binName),d}function Qn(e){return e.startsWith(`file:`)?`linked`:`installed`}async function $n(e,t,n){let r={...e},i=[],a;try{a=await Bn(t)}catch(e){return{commands:r,reports:[{name:`(plugin sandbox)`,source:`installed`,status:`failed`,commands:[],error:e instanceof Error?e.message:String(e)}]}}for(let[e,o]of Object.entries(a.dependencies??{}).sort(([e],[t])=>e.localeCompare(t))){let a=Qn(o),s=n.supported[e];if(!s){i.push({name:e,source:a,status:`failed`,commands:[],error:`Command Pack "${e}" is not supported by ${t.binName}.`});continue}try{let n=await Vn(t,e),o=await Zn(e,n,s,t),c=Object.keys(o).filter(e=>e in r);if(c.length>0)throw Error(`Command conflicts: ${c.join(`, `)}.`);Object.assign(r,o),i.push({name:e,version:n.version,source:a,status:`loaded`,commands:Object.keys(o).sort()})}catch(t){i.push({name:e,source:a,status:`failed`,commands:[],error:t instanceof Error?t.message:String(t)})}}return{commands:r,reports:i}}const er={name:`bailian-cli-command-packs`,private:!0,dependencies:{}},tr=/* @__PURE__ */ new Set(/* @__PURE__ */ `PATH.HOME.USER.LOGNAME.SHELL.TMPDIR.TEMP.TMP.LANG.TERM.NODE.NODE_PATH.NODE_OPTIONS.FORCE_COLOR.NO_COLOR.NPM_TOKEN.NODE_AUTH_TOKEN.HTTP_PROXY.HTTPS_PROXY.NO_PROXY.http_proxy.https_proxy.no_proxy.SystemRoot.ComSpec.APPDATA.PATHEXT`.split(`.`)),nr=/* @__PURE__ */ new Set([`registry`,`userconfig`,`globalconfig`,`cache`,`proxy`,`https_proxy`,`noproxy`,`strict_ssl`,`ca`,`cafile`]);function rr(e){let t=/^(?:npm_config_|NPM_CONFIG_)(.+)$/.exec(e);return!!t&&nr.has(t[1].toLowerCase())}function ir(e,t){let n=Object.keys(t.supported);return n.length>0?`Allowed packages: ${n.join(`, `)}`:`${e.binName} does not currently support any Command Packs.`}function ar(e=process.env){let t={};for(let[n,r]of Object.entries(e))r!==void 0&&(tr.has(n)||n.startsWith(`LC_`)||rr(n))&&(t[n]=r);return t}async function or(e){await A(e,{recursive:!0,mode:448});let t=N(e,`package.json`);Re(t)||await Xe(t,`${JSON.stringify(er,null,2)}\n`,{mode:384})}async function sr(e,n){if(rt(`npm`,[`--version`],{encoding:`utf-8`}).status!==0){let e=ie()?"Command Packs need a local npm. Install Node.js, or use `npm install -g bailian-cli` instead of the binary install.":`Install Node.js / npm and retry.`;throw new t(`npm is required to install, link, or remove Command Packs, but was not found on PATH.`,c.GENERAL,e)}await new Promise((r,i)=>{let a=nt(`npm`,e,{cwd:n,env:ar(),stdio:[`inherit`,`pipe`,`pipe`]});a.stdout.on(`data`,e=>process.stderr.write(e)),a.stderr.on(`data`,e=>process.stderr.write(e)),a.once(`error`,i),a.once(`close`,(n,a)=>{if(n===0){r();return}i(new t(`npm ${e[0]} failed${a?` with signal ${a}`:` with exit code ${n}`}.`,c.GENERAL))})})}async function cr(e){let n=In(e);await or(n);let r=N(n,`.lock`);for(let e=0;e<2;e++)try{let e=await Ue(r,`wx`,384);return await e.writeFile(`${process.pid} ${Date.now()}\n`),await e.close(),async()=>{try{await M(r)}catch{}}}catch(e){if(e.code!==`EEXIST`)throw e;try{let e=await Ye(r);if(Date.now()-e.mtimeMs>6e5){await M(r);continue}}catch{continue}throw new t(`Another Command Pack install, link, or remove operation is already running.`,c.GENERAL,`Wait for it to finish and try again.`)}throw new t(`Could not acquire the Command Pack operation lock.`,c.GENERAL)}async function lr(e,t){let n=await cr(e);try{return await t()}finally{await n()}}function ur(e,n,r){let i=e.trim(),a=/^(@[^/\s]+\/[^@/\s]+)(?:@([a-zA-Z0-9][a-zA-Z0-9._-]*))?$/.exec(i);if(!a)throw new t(`Unsupported Command Pack package spec: "${e}".`,c.USAGE,`Use an allowlisted scoped package name with an optional version or tag.`);let o=a[1];if(!r.supported[o])throw new t(`Command Pack "${o}" is not allowlisted for ${n.binName}.`,c.USAGE,ir(n,r));return{name:o,requested:i}}async function dr(e,t,n,r){let i=r.supported[e],a=await Hn(t);return{pjson:a,commands:await Zn(e,a,i,n,t)}}function fr(e,t){return t.startsWith(`file:`)?t:`${e}@${t}`}async function pr(e,t,n){if(t){await sr([`install`,fr(e,t),`--save-exact`,`--ignore-scripts`,`--no-fund`,`--no-audit`],n);return}await sr([`uninstall`,e,`--ignore-scripts`,`--no-fund`,`--no-audit`],n)}async function mr(e,n,r){let{name:i,requested:a}=ur(e,n,r);return lr(n,async()=>{let e=In(n),o=(await Bn(n)).dependencies?.[i];try{await sr([`install`,a,`--save-exact`,`--ignore-scripts`,`--no-fund`,`--no-audit`],e);let o=await dr(i,Rn(n,i),n,r);if(!o.pjson.version)throw new t(`Command Pack "${i}" has no package version.`,c.USAGE);return{name:i,version:o.pjson.version,commands:Object.keys(o.commands).sort()}}catch(t){try{await pr(i,o,e)}catch{}throw t}})}async function hr(e,n,r){let i=et(e);if(!Re(N(i,`package.json`)))throw new t(`Command Pack path does not exist: ${i}`,c.USAGE);let a=(await Hn(i)).name;if(!a||!r.supported[a])throw new t(`Local package "${a??`(unnamed)`}" is not an allowlisted Command Pack for ${n.binName}.`,c.USAGE,ir(n,r));let o=await dr(a,i,n,r);return lr(n,async()=>{await sr([`install`,`file:${i}`,`--save-exact`,`--ignore-scripts`,`--no-fund`,`--no-audit`],In(n));let e=await dr(a,Rn(n,a),n,r);return{name:a,version:e.pjson.version??o.pjson.version,commands:Object.keys(e.commands).sort()}})}async function gr(e,n,r){if(!r.supported[e])throw new t(`Command Pack "${e}" is not allowlisted for ${n.binName}.`,c.USAGE,ir(n,r));if(!(e in((await Bn(n)).dependencies??{})))throw new t(`Command Pack "${e}" is not installed.`,c.USAGE);await lr(n,()=>sr([`uninstall`,e,`--ignore-scripts`,`--no-fund`,`--no-audit`],In(n)))}async function _r(e,t){return(await $n({},e,t)).reports}function vr(e,t){return{install:n=>mr(n,e,t),link:n=>hr(n,e,t),list:()=>_r(e,t),remove:n=>gr(n,e,t)}}function yr(e,t){let n={};for(let r of t)r in e&&(n[r]=e[r]);return n}function br(e){for(let t=0;t<e.length;t++){let n=e[t];if(n===`--config`)return{config:e[t+1]};if(n?.startsWith(`--config=`))return{config:n.slice(9)}}return{}}function xr(e){try{_n()}catch(t){B(t,e)}process.on(`SIGINT`,()=>{process.stderr.write(`
48
48
  Interrupted. Exiting.
49
- `),k(500).finally(()=>process.exit(130))}),process.stdout.on(`error`,e=>{if(e.code===`EPIPE`)process.exit(0);else throw e})}function Sr(e,t){let{binName:n,version:a,npmPackage:o,clientName:c}=t,f={binName:n,version:a,npmPackage:o,clientName:c},m=t.commandPacks??{supported:{}},h=vr(f,m),g;xr(n);let _=ln([dn,pn,fn,un,mn]);function v(){return g||=$n(e,f,m),g}async function x(e){let t=Lt(b(br(e)).file.language??s);return{registry:new Nt((await v()).commands,n,t),localize:e=>t.localize(e)}}function S(e,n,i){if(e.printHelp(n,process.stderr),n.length>0)return;let a=!1;try{let e=T(b(vt(i,{...l,...u,...r,...d})));a=!!(e.apiKey||e.console)}catch{}a?t.quickStartTasks?.length&&e.printQuickStart(t.quickStartTasks):e.printWelcome()}async function C(e,t,r){let o=Pt(t,e);switch(o.kind){case`version`:process.stdout.write(`${n} ${a}\n`);return;case`help`:S(e,o.path,t);return;case`usageError`:B(o.error,n);return;case`run`:try{let e=w(o.command),t=Dt(o.command),n=vt(o.rest,{...l,...e,...t,...o.command.flags}),a=yr(n,[...Object.keys(l),...Object.keys(e)]),s=yr(n,Object.keys(o.command.flags??{})),c=await o.command.validate?.(s);if(c)throw new p(c);let u=b(a),d=y(u),m={identity:f,path:o.path,command:o.command,flags:s,confirmed:n.yes===!0,localize:r,settings:d,sources:u,configStore:se(u.configName),authStore:oe(u),commandPacks:h,client:new i({identity:f,settings:d,..._e(u)})};await _(m),await k(1e3)}catch(t){if(t instanceof p&&o.rest.length===0){e.printHelp(o.path,process.stderr);return}await k(1e3),B(t,n)}return}}return{run(e=process.argv.slice(2)){return Promise.resolve().then(()=>x(e)).then(({registry:t,localize:n})=>C(t,e,n)).catch(e=>k(1e3).finally(()=>B(e,n)))}}}const Cr=`2.0.1`;function wr(e,t){process.stdout.write(te(e,t)+`
49
+ `),k(500).finally(()=>process.exit(130))}),process.stdout.on(`error`,e=>{if(e.code===`EPIPE`)process.exit(0);else throw e})}function Sr(e,t){let{binName:n,version:a,npmPackage:o,clientName:c}=t,f={binName:n,version:a,npmPackage:o,clientName:c},m=t.commandPacks??{supported:{}},h=vr(f,m),g;xr(n);let _=ln([dn,pn,fn,un,mn]);function v(){return g||=$n(e,f,m),g}async function x(e){let t=Lt(b(br(e)).file.language??s);return{registry:new Nt((await v()).commands,n,t),localize:e=>t.localize(e)}}function S(e,n,i){if(e.printHelp(n,process.stderr),n.length>0)return;let a=!1;try{let e=T(b(vt(i,{...l,...u,...r,...d})));a=!!(e.apiKey||e.console)}catch{}a?t.quickStartTasks?.length&&e.printQuickStart(t.quickStartTasks):e.printWelcome()}async function C(e,t,r){let o=Pt(t,e);switch(o.kind){case`version`:process.stdout.write(`${n} ${a}\n`);return;case`help`:S(e,o.path,t);return;case`usageError`:B(o.error,n);return;case`run`:try{let e=w(o.command),t=Dt(o.command),n=vt(o.rest,{...l,...e,...t,...o.command.flags}),a=yr(n,[...Object.keys(l),...Object.keys(e)]),s=yr(n,Object.keys(o.command.flags??{})),c=await o.command.validate?.(s);if(c)throw new p(c);let u=b(a),d=y(u),m={identity:f,path:o.path,command:o.command,flags:s,confirmed:n.yes===!0,localize:r,settings:d,sources:u,configStore:se(u.configName),authStore:oe(u),commandPacks:h,client:new i({identity:f,settings:d,..._e(u)})};await _(m),await k(1e3)}catch(t){if(t instanceof p&&o.rest.length===0){e.printHelp(o.path,process.stderr);return}await k(1e3),B(t,n)}return}}return{run(e=process.argv.slice(2)){return Promise.resolve().then(()=>x(e)).then(({registry:t,localize:n})=>C(t,e,n)).catch(e=>k(1e3).finally(()=>B(e,n)))}}}const Cr=`2.1.0`;function wr(e,t){process.stdout.write(te(e,t)+`
50
50
  `)}function Tr(e){process.stdout.write(e+`
51
51
  `)}function Er(e,t){e&&!t&&process.stderr.write(`request_id: ${e}\n`)}function Dr(e,t,{gap:n=2}={}){let r=e.map((e,n)=>{let r=e.length;for(let e of t){let t=e[n]??``;t.length>r&&(r=t.length)}return r}),i=` `.repeat(n),a=e=>e.map((e,t)=>(e??``).padEnd(r[t])).join(i),o=[];o.push(a(e));for(let e of t)o.push(a(e));return o}function Or(e){return e>=11904&&e<=40959||e>=63744&&e<=64255||e>=65072&&e<=65103||e>=65280&&e<=65376||e>=65504&&e<=65510||e>=131072&&e<=195103}function V(e){let t=0;for(let n of e){let e=n.codePointAt(0)??0;t+=Or(e)?2:1}return t}function kr(e,t){let n=t-V(e);return n>0?e+` `.repeat(n):e}const Ar=` │ `,jr=[0,150,160],Mr=[176,205,250],Nr=[160,160,170];function Pr(e){if(`NO_COLOR`in process.env)return 0;let t=process.env.FORCE_COLOR;if(t!=null){if(t===`0`||t===`false`)return 0;if(t===`3`||t===`truecolor`)return 3;if(t===`2`)return 2;if(t===`1`||t===`true`||t===``)return 1}if(!bt(e))return 0;let n=process.env.COLORTERM;if(n===`truecolor`||n===`24bit`)return 3;let r=process.env.TERM??``;return r===`dumb`?1:/-256(color)?$/i.test(r)?2:1}function Fr(e,t,n){return e===t&&t===n?e<8?16:e>248?231:232+Math.round((e-8)/247*24):16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)}function Ir(e,t,n,r){let i=Math.max(e,t,n)>127,a=i?128:64;return(r===48?i?100:40:i?90:30)+(e>=a|(t>=a?2:0)|(n>=a?4:0))}function Lr(e,t,n,r,i=38){return e>=3?`${i};2;${t};${n};${r}`:e===2?`${i};5;${Fr(t,n,r)}`:String(Ir(t,n,r,i))}function Rr(e,[t,n,r],i){return e<=0?i:`\x1b[${Lr(e,t,n,r)}m${i}\x1b[0m`}function zr(e,t,n){return t<=0?e:`\x1b[1;${Lr(t,255,255,255,38)};${Lr(t,n[0],n[1],n[2],48)}m${e}\x1b[0m`}function Br(e,t){let n=t-V(e);return n>0?` `.repeat(n)+e:e}function Vr(e,t,n=20,r=process.stdout){return Hr(e,t,n,Pr(r))}function Hr(e,t,n,r){let i=e==null?0:Math.max(0,Math.min(100,e)),a=e!=null,o=a?Math.round(i/100*n):0,s=``,c=``;for(let e=0;e<n;e++)a&&e<o?(s+=`█`,c+=Rr(r,jr,`█`)):(s+=` `,c+=` `);let l=a?Mr:Nr;return s+=` ${t}`,c+=` ${Rr(r,l,t)}`,{plain:s,colored:c}}function Ur(e){let t=Pr(e.out??process.stdout),n=e.align??[],r=e.barColumns??[],i=e.headers.length,a={};for(let n of r){let r=n.width??20,i=[];for(let a=0;a<e.rows.length;a++){let e=n.percents[a]??null,o=n.labels?.[a]??(e==null?`-`:`${Number.isInteger(e)?e:e.toFixed(1)}%`);i.push(Hr(e,o,r,t))}a[n.index]=i}let o=(t,n)=>a[n]?a[n][t].plain:e.rows[t][n]??``,s=e.headers.map((t,n)=>{let r=V(t);for(let t=0;t<e.rows.length;t++){let e=V(o(t,n));e>r&&(r=e)}return r}),c=[],l=e.headers.map((e,t)=>n[t]===`right`?Br(e,s[t]):kr(e,s[t])).join(Ar),u=Math.max(V(l),...e.rows.map((e,t)=>V(Array.from({length:i},(e,n)=>o(t,n)).join(Ar))));c.push(zr(` ${kr(l,u)} `,t,jr));let d=` ${Rr(t,jr,`│`)} `;for(let t=0;t<e.rows.length;t++){let r=[];for(let o=0;o<i;o++){let i=s[o];if(a[o]){let e=a[o][t],n=i-V(e.plain);r.push(n>0?e.colored+` `.repeat(n):e.colored);continue}let c=e.rows[t][o]??``,l=e.cellColor?.(t,o,c),u=n[o]===`right`?Br(c,i):kr(c,i);l?r.push(n[o]===`right`?u.slice(0,u.length-c.length)+l:l+u.slice(c.length)):r.push(u)}let o=` `;for(let e=0;e<i;e++)o+=r[e],e<i-1&&(o+=d);c.push(o)}return c}const Wr=[`⠋`,`⠙`,`⠹`,`⠸`,`⠼`,`⠴`,`⠦`,`⠧`,`⠇`,`⠏`];function Gr(e){let t=process.stderr.isTTY,n=0,r=null,i=e;return{start(){t&&(r=setInterval(()=>{process.stderr.write(`\r${Wr[n%Wr.length]} ${i}`),n++},80))},update(e){i=e},stop(e){r&&=(clearInterval(r),null),t&&(process.stderr.write(`\r\x1B[K`),e&&process.stderr.write(`${e}\n`))}}}function Kr(e,t=``){let n=process.stderr.isTTY;return{update(r){if(!n)return;let i=Math.min(1,r/e),a=Math.round(30*i),o=30-a,s=`█`.repeat(a)+`░`.repeat(o),c=`${Math.round(i*100)}%`;process.stderr.write(`\r${t} ${s} ${c}`)},finish(){n&&process.stderr.write(`
52
52
  `)}}}async function qr(e,n,r){let i=Date.now()+r.timeoutSec*1e3,a=Gr(`Polling...`);n.quiet||a.start();try{for(;Date.now()<i;){let i=await e.requestJson({path:r.url});if(r.getStatus&&!n.quiet&&a.update(`Status: ${r.getStatus(i)}`),r.isComplete(i))return a.stop(`Done.`),i;if(r.isFailed(i)){a.stop(`Failed.`),n.verbose&&process.stderr.write(`[verbose] Task response: ${JSON.stringify(i,null,2)}\n`);let e=r.getErrorMessage?.(i);throw new t(e?`Task failed: ${e}`:`Task failed.`,c.GENERAL,e?void 0:`Use --verbose to see full API response details.`)}await new Promise(e=>setTimeout(e,r.intervalSec*1e3))}}finally{a.stop()}throw new t(`Polling timed out.`,c.TIMEOUT,`Try increasing --timeout or check task status manually.`)}async function Jr(e,n,r){let i=await fetch(e);if(!i.ok)throw new t(`Download failed: HTTP ${i.status}`,c.GENERAL);let a=Number(i.headers.get(`content-length`)||0),o=i.body?.getReader();if(!o)throw new t(`No response body`,c.GENERAL);Me(ke(n),{recursive:!0});let s=je(n),l=a>0&&!r?.quiet?Kr(a,`Downloading`):null,u=0,d=!1;try{let e=new Promise((e,t)=>{s.on(`error`,t)});for(;;){let{done:t,value:n}=await Promise.race([o.read(),e]);if(t)break;s.write(n)||await new Promise(e=>s.once(`drain`,()=>e())),u+=n.byteLength,l?.update(u)}d=!0}finally{if(o.releaseLock(),l?.finish(),await new Promise((e,t)=>{s.on(`finish`,e),s.on(`error`,t),s.end()}),!d)try{Pe(n)}catch{}}return{size:u}}function Yr(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:e<1073741824?`${(e/1048576).toFixed(1)} MB`:`${(e/1073741824).toFixed(1)} GB`}function Xr(e){return Math.max(1,e.concurrent??1)}async function Zr(e,t,n,r=`requests`){if(e<=1)return[await n(0)];t.quiet||process.stderr.write(`[Concurrent: ${e} ${r}]\n`);let i=Array.from({length:e},(e,t)=>n(t));return Promise.all(i)}async function Qr(e,t,n){return Promise.all(e.map(({url:e,destPath:r})=>t(e,r,n).then(()=>r)))}const $r={"qwen-image-2.0":{"16:9":`2688*1536`,"9:16":`1536*2688`,"1:1":`2048*2048`,"4:3":`2368*1728`,"3:4":`1728*2368`},"qwen-image-fixed":{"16:9":`1664*928`,"4:3":`1472*1104`,"1:1":`1328*1328`,"3:4":`1104*1472`,"9:16":`928*1664`},wan27:{"16:9":`2688*1536`,"9:16":`1536*2688`,"1:1":`2048*2048`,"4:3":`2368*1728`,"3:4":`1728*2368`},"z-image":{"1:1":`1024*1024`,"16:9":`1280*720`,"9:16":`720*1280`,"4:3":`1152*864`,"3:4":`864*1152`,"3:2":`1248*832`,"2:3":`832*1248`},wan26:{"1:1":`1280*1280`,"16:9":`1696*960`,"9:16":`960*1696`,"4:3":`1472*1104`,"3:4":`1104*1472`},"wan-legacy":{"1:1":`1024*1024`,"16:9":`1280*720`,"9:16":`720*1280`,"3:4":`768*1152`,"4:3":`1152*768`},"wanx-v1":{"1:1":`1024*1024`,"9:16":`720*1280`,"3:4":`768*1152`,"16:9":`1280*720`},"wan25-i2i":{"1:1":`1280*1280`,"16:9":`1280*720`,"9:16":`720*1280`,"4:3":`1152*864`,"3:4":`864*1152`}};function ei(e,t){if(e)return $r[typeof t==`boolean`?t?`qwen-image-2.0`:`qwen-image-fixed`:t][e]??e}var ti=/* @__PURE__ */ ft({ensureBinaryPathEntries:()=>yi,ensureWindowsBinJunction:()=>xi,fetchBinaryChannelManifest:()=>oi,fetchBinaryChannelVersion:()=>ai,getBinaryBinRoot:()=>ni,getBinaryCurrentPath:()=>ii,getBinaryShareRoot:()=>H,getBinaryVersionsDir:()=>ri,isValidUpdateTargetVersion:()=>li,normalizeBinaryVersion:()=>si,performBinaryUpdate:()=>Ci,pruneBinaryVersions:()=>Si,readCurrentVersionDir:()=>gi,resolveBinaryDownloadSpec:()=>di,switchCurrentToVersion:()=>vi});function H(){return process.env.BAILIAN_SHARE_DIR?process.env.BAILIAN_SHARE_DIR:process.platform===`win32`?N(process.env.LOCALAPPDATA||N(it(),`AppData`,`Local`),`bailian-cli`):N(it(),`.local`,`share`,`bailian-cli`)}function ni(){return process.env.BAILIAN_BIN_DIR?process.env.BAILIAN_BIN_DIR:process.platform===`win32`?N(H(),`bin`):N(it(),`.local`,`bin`)}function ri(){return N(H(),`versions`)}function ii(){return N(H(),`current`)}async function ai(e=`latest`,t=5e3){try{let n=await fetch(x(e),{signal:AbortSignal.timeout(t)});return n.ok?(await n.json()).version??null:null}catch{return null}}async function oi(e=`latest`,t=8e3){try{let n=await fetch(x(e),{signal:AbortSignal.timeout(t)});return n.ok?await n.json():null}catch{return null}}function si(e){let t=e.trim();return/^v\d/i.test(t)?t.slice(1):t}const ci=/^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;function li(e){let t=e.trim();return t?ci.test(t):!1}async function ui(e,t,n=8e3){try{let r=await fetch(le(e,`SHA256SUMS`),{signal:AbortSignal.timeout(n)});if(!r.ok)return;let i=await r.text();for(let e of i.split(`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bailian-cli-runtime",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Runtime framework for bailian-cli (createCli, registry, args, output, pipeline). See https://www.npmjs.com/package/bailian-cli for usage.",
5
5
  "homepage": "https://bailian.console.aliyun.com/cli",
6
6
  "bugs": {
@@ -30,7 +30,7 @@
30
30
  "boxen": "^8.0.1",
31
31
  "chalk": "^5.6.2",
32
32
  "undici": "^6.27.0",
33
- "bailian-cli-core": "2.0.1"
33
+ "bailian-cli-core": "2.1.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@clack/prompts": "^0.7.0",