bailian-cli 0.1.0 → 0.1.2-beta.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/bailian.mjs CHANGED
@@ -1,119 +1,119 @@
1
1
  #!/usr/bin/env node
2
- import{createRequire as dn}from"node:module";var On=Object.create;var{getPrototypeOf:Xn,defineProperty:De,getOwnPropertyNames:Pn}=Object;var Yn=Object.prototype.hasOwnProperty;function Cn(e){return this[e]}var Ln,Vn,He=(e,t,n)=>{var i=e!=null&&typeof e==="object";if(i){var $=t?Ln??=new WeakMap:Vn??=new WeakMap,p=$.get(e);if(p)return p}n=e!=null?On(Xn(e)):{};let r=t||!e||!e.__esModule?De(n,"default",{value:e,enumerable:!0}):n;for(let m of Pn(e))if(!Yn.call(r,m))De(r,m,{get:Cn.bind(e,m),enumerable:!0});if(i)$.set(e,r);return r};var Xt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var vn=(e)=>e;function En(e,t){this[e]=vn.bind(null,t)}var In=(e,t)=>{for(var n in t)De(e,n,{get:t[n],enumerable:!0,configurable:!0,set:En.bind(t,n)})};var Pt=(e,t)=>()=>(e&&(t=e(e=0)),t);var oe=dn(import.meta.url);var bt=Xt((qm,ft)=>{var xt={to(e,t){if(!t)return`\x1B[${e+1}G`;return`\x1B[${t+1};${e+1}H`},move(e,t){let n="";if(e<0)n+=`\x1B[${-e}D`;else if(e>0)n+=`\x1B[${e}C`;if(t<0)n+=`\x1B[${-t}A`;else if(t>0)n+=`\x1B[${t}B`;return n},up:(e=1)=>`\x1B[${e}A`,down:(e=1)=>`\x1B[${e}B`,forward:(e=1)=>`\x1B[${e}C`,backward:(e=1)=>`\x1B[${e}D`,nextLine:(e=1)=>"\x1B[E".repeat(e),prevLine:(e=1)=>"\x1B[F".repeat(e),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},bi={up:(e=1)=>"\x1B[S".repeat(e),down:(e=1)=>"\x1B[T".repeat(e)},wi={screen:"\x1B[2J",up:(e=1)=>"\x1B[1J".repeat(e),down:(e=1)=>"\x1B[J".repeat(e),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?xt.up():"");if(e)t+=xt.left;return t}};ft.exports={cursor:xt,scroll:bi,erase:wi,beep:"\x07"}});var ut=Xt((Gm,wt)=>{var Ce=process||{},gt=Ce.argv||[],Ye=Ce.env||{},ui=!(!!Ye.NO_COLOR||gt.includes("--no-color"))&&(!!Ye.FORCE_COLOR||gt.includes("--color")||Ce.platform==="win32"||(Ce.stdout||{}).isTTY&&Ye.TERM!=="dumb"||!!Ye.CI),hi=(e,t,n=e)=>(i)=>{let $=""+i,p=$.indexOf(t,e.length);return~p?e+oi($,t,n,p)+t:e+$+t},oi=(e,t,n,i)=>{let $="",p=0;do $+=e.substring(p,i)+n,p=i+t.length,i=e.indexOf(t,p);while(~i);return $+e.substring(p)},er=(e=ui)=>{let t=e?hi:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};wt.exports=er();wt.exports.createColors=er});import{stdin as hr,stdout as or}from"node:process";import*as xe from"node:readline";import tr from"node:readline";import{WriteStream as Si}from"node:tty";function Ai({onlyFirst:e=!1}={}){let t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(t,e?void 0:"g")}function Sr(e){if(typeof e!="string")throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);return e.replace(ki,"")}function Ar(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Ze(e,t={}){if(typeof e!="string"||e.length===0||(t={ambiguousIsNarrow:!0,...t},e=Sr(e),e.length===0))return 0;e=e.replace(Ki()," ");let n=t.ambiguousIsNarrow?1:2,i=0;for(let $ of e){let p=$.codePointAt(0);if(p<=31||p>=127&&p<=159||p>=768&&p<=879)continue;switch(Gi.eastAsianWidth($)){case"F":case"W":i+=2;break;case"A":i+=n;break;default:i+=1}}return i}function Ri(){let e=new Map;for(let[t,n]of Object.entries(C)){for(let[i,$]of Object.entries(n))C[i]={open:`\x1B[${$[0]}m`,close:`\x1B[${$[1]}m`},n[i]=C[i],e.set($[0],$[1]);Object.defineProperty(C,t,{value:n,enumerable:!1})}return Object.defineProperty(C,"codes",{value:e,enumerable:!1}),C.color.close="\x1B[39m",C.bgColor.close="\x1B[49m",C.color.ansi=rr(),C.color.ansi256=nr(),C.color.ansi16m=ir(),C.bgColor.ansi=rr(ht),C.bgColor.ansi256=nr(ht),C.bgColor.ansi16m=ir(ht),Object.defineProperties(C,{rgbToAnsi256:{value:(t,n,i)=>t===n&&n===i?t<8?16:t>248?231:Math.round((t-8)/247*24)+232:16+36*Math.round(t/255*5)+6*Math.round(n/255*5)+Math.round(i/255*5),enumerable:!1},hexToRgb:{value:(t)=>{let n=/[a-f\d]{6}|[a-f\d]{3}/i.exec(t.toString(16));if(!n)return[0,0,0];let[i]=n;i.length===3&&(i=[...i].map((p)=>p+p).join(""));let $=Number.parseInt(i,16);return[$>>16&255,$>>8&255,$&255]},enumerable:!1},hexToAnsi256:{value:(t)=>C.rgbToAnsi256(...C.hexToRgb(t)),enumerable:!1},ansi256ToAnsi:{value:(t)=>{if(t<8)return 30+t;if(t<16)return 90+(t-8);let n,i,$;if(t>=232)n=((t-232)*10+8)/255,i=n,$=n;else{t-=16;let m=t%36;n=Math.floor(t/36)/5,i=Math.floor(m/6)/5,$=m%6/5}let p=Math.max(n,i,$)*2;if(p===0)return 30;let r=30+(Math.round($)<<2|Math.round(i)<<1|Math.round(n));return p===2&&(r+=60),r},enumerable:!1},rgbToAnsi:{value:(t,n,i)=>C.ansi256ToAnsi(C.rgbToAnsi256(t,n,i)),enumerable:!1},hexToAnsi:{value:(t)=>C.ansi256ToAnsi(C.hexToAnsi256(t)),enumerable:!1}}),C}function mr(e,t,n){return String(e).normalize().replace(/\r\n/g,`
2
+ import{createRequire as En}from"node:module";var On=Object.create;var{getPrototypeOf:cn,defineProperty:le,getOwnPropertyNames:Cn}=Object;var Ln=Object.prototype.hasOwnProperty;var ne=(e,t,n)=>{n=e!=null?On(cn(e)):{};let i=t||!e||!e.__esModule?le(n,"default",{value:e,enumerable:!0}):n;for(let $ of Cn(e))if(!Ln.call(i,$))le(i,$,{get:()=>e[$],enumerable:!0});return i};var Yt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Vn=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0,configurable:!0,set:(i)=>t[n]=()=>i})};var Ot=(e,t)=>()=>(e&&(t=e(e=0)),t);var ke=En(import.meta.url);var bt=Yt((ky,ft)=>{var xt={to(e,t){if(!t)return`\x1B[${e+1}G`;return`\x1B[${t+1};${e+1}H`},move(e,t){let n="";if(e<0)n+=`\x1B[${-e}D`;else if(e>0)n+=`\x1B[${e}C`;if(t<0)n+=`\x1B[${-t}A`;else if(t>0)n+=`\x1B[${t}B`;return n},up:(e=1)=>`\x1B[${e}A`,down:(e=1)=>`\x1B[${e}B`,forward:(e=1)=>`\x1B[${e}C`,backward:(e=1)=>`\x1B[${e}D`,nextLine:(e=1)=>"\x1B[E".repeat(e),prevLine:(e=1)=>"\x1B[F".repeat(e),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},_i={up:(e=1)=>"\x1B[S".repeat(e),down:(e=1)=>"\x1B[T".repeat(e)},mi={screen:"\x1B[2J",up:(e=1)=>"\x1B[1J".repeat(e),down:(e=1)=>"\x1B[J".repeat(e),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?xt.up():"");if(e)t+=xt.left;return t}};ft.exports={cursor:xt,scroll:_i,erase:mi,beep:"\x07"}});var ht=Yt((qy,wt)=>{var Ve=process||{},gt=Ve.argv||[],Le=Ve.env||{},xi=!(!!Le.NO_COLOR||gt.includes("--no-color"))&&(!!Le.FORCE_COLOR||gt.includes("--color")||Ve.platform==="win32"||(Ve.stdout||{}).isTTY&&Le.TERM!=="dumb"||!!Le.CI),bi=(e,t,n=e)=>(i)=>{let $=""+i,p=$.indexOf(t,e.length);return~p?e+wi($,t,n,p)+t:e+$+t},wi=(e,t,n,i)=>{let $="",p=0;do $+=e.substring(p,i)+n,p=i+t.length,i=e.indexOf(t,p);while(~i);return $+e.substring(p)},er=(e=xi)=>{let t=e?bi:()=>String;return{isColorSupported:e,reset:t("\x1B[0m","\x1B[0m"),bold:t("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:t("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:t("\x1B[3m","\x1B[23m"),underline:t("\x1B[4m","\x1B[24m"),inverse:t("\x1B[7m","\x1B[27m"),hidden:t("\x1B[8m","\x1B[28m"),strikethrough:t("\x1B[9m","\x1B[29m"),black:t("\x1B[30m","\x1B[39m"),red:t("\x1B[31m","\x1B[39m"),green:t("\x1B[32m","\x1B[39m"),yellow:t("\x1B[33m","\x1B[39m"),blue:t("\x1B[34m","\x1B[39m"),magenta:t("\x1B[35m","\x1B[39m"),cyan:t("\x1B[36m","\x1B[39m"),white:t("\x1B[37m","\x1B[39m"),gray:t("\x1B[90m","\x1B[39m"),bgBlack:t("\x1B[40m","\x1B[49m"),bgRed:t("\x1B[41m","\x1B[49m"),bgGreen:t("\x1B[42m","\x1B[49m"),bgYellow:t("\x1B[43m","\x1B[49m"),bgBlue:t("\x1B[44m","\x1B[49m"),bgMagenta:t("\x1B[45m","\x1B[49m"),bgCyan:t("\x1B[46m","\x1B[49m"),bgWhite:t("\x1B[47m","\x1B[49m"),blackBright:t("\x1B[90m","\x1B[39m"),redBright:t("\x1B[91m","\x1B[39m"),greenBright:t("\x1B[92m","\x1B[39m"),yellowBright:t("\x1B[93m","\x1B[39m"),blueBright:t("\x1B[94m","\x1B[39m"),magentaBright:t("\x1B[95m","\x1B[39m"),cyanBright:t("\x1B[96m","\x1B[39m"),whiteBright:t("\x1B[97m","\x1B[39m"),bgBlackBright:t("\x1B[100m","\x1B[49m"),bgRedBright:t("\x1B[101m","\x1B[49m"),bgGreenBright:t("\x1B[102m","\x1B[49m"),bgYellowBright:t("\x1B[103m","\x1B[49m"),bgBlueBright:t("\x1B[104m","\x1B[49m"),bgMagentaBright:t("\x1B[105m","\x1B[49m"),bgCyanBright:t("\x1B[106m","\x1B[49m"),bgWhiteBright:t("\x1B[107m","\x1B[49m")}};wt.exports=er();wt.exports.createColors=er});import{stdin as Ar,stdout as ur}from"node:process";import*as we from"node:readline";import tr from"node:readline";import{WriteStream as hi}from"node:tty";function Ai({onlyFirst:e=!1}={}){let t=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(t,e?void 0:"g")}function Sr(e){if(typeof e!="string")throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);return e.replace(ui,"")}function kr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function ze(e,t={}){if(typeof e!="string"||e.length===0||(t={ambiguousIsNarrow:!0,...t},e=Sr(e),e.length===0))return 0;e=e.replace(oi()," ");let n=t.ambiguousIsNarrow?1:2,i=0;for(let $ of e){let p=$.codePointAt(0);if(p<=31||p>=127&&p<=159||p>=768&&p<=879)continue;switch(ki.eastAsianWidth($)){case"F":case"W":i+=2;break;case"A":i+=n;break;default:i+=1}}return i}function Ni(){let e=new Map;for(let[t,n]of Object.entries(C)){for(let[i,$]of Object.entries(n))C[i]={open:`\x1B[${$[0]}m`,close:`\x1B[${$[1]}m`},n[i]=C[i],e.set($[0],$[1]);Object.defineProperty(C,t,{value:n,enumerable:!1})}return Object.defineProperty(C,"codes",{value:e,enumerable:!1}),C.color.close="\x1B[39m",C.bgColor.close="\x1B[49m",C.color.ansi=rr(),C.color.ansi256=nr(),C.color.ansi16m=ir(),C.bgColor.ansi=rr(At),C.bgColor.ansi256=nr(At),C.bgColor.ansi16m=ir(At),Object.defineProperties(C,{rgbToAnsi256:{value:(t,n,i)=>t===n&&n===i?t<8?16:t>248?231:Math.round((t-8)/247*24)+232:16+36*Math.round(t/255*5)+6*Math.round(n/255*5)+Math.round(i/255*5),enumerable:!1},hexToRgb:{value:(t)=>{let n=/[a-f\d]{6}|[a-f\d]{3}/i.exec(t.toString(16));if(!n)return[0,0,0];let[i]=n;i.length===3&&(i=[...i].map((p)=>p+p).join(""));let $=Number.parseInt(i,16);return[$>>16&255,$>>8&255,$&255]},enumerable:!1},hexToAnsi256:{value:(t)=>C.rgbToAnsi256(...C.hexToRgb(t)),enumerable:!1},ansi256ToAnsi:{value:(t)=>{if(t<8)return 30+t;if(t<16)return 90+(t-8);let n,i,$;if(t>=232)n=((t-232)*10+8)/255,i=n,$=n;else{t-=16;let y=t%36;n=Math.floor(t/36)/5,i=Math.floor(y/6)/5,$=y%6/5}let p=Math.max(n,i,$)*2;if(p===0)return 30;let r=30+(Math.round($)<<2|Math.round(i)<<1|Math.round(n));return p===2&&(r+=60),r},enumerable:!1},rgbToAnsi:{value:(t,n,i)=>C.ansi256ToAnsi(C.rgbToAnsi256(t,n,i)),enumerable:!1},hexToAnsi:{value:(t)=>C.ansi256ToAnsi(C.hexToAnsi256(t)),enumerable:!1}}),C}function yr(e,t,n){return String(e).normalize().replace(/\r\n/g,`
3
3
  `).split(`
4
- `).map((i)=>Zi(i,t,n)).join(`
5
- `)}function zi(e,t){if(e===t)return;let n=e.split(`
4
+ `).map((i)=>Ti(i,t,n)).join(`
5
+ `)}function Hi(e,t){if(e===t)return;let n=e.split(`
6
6
  `),i=t.split(`
7
- `),$=[];for(let p=0;p<Math.max(n.length,i.length);p++)n[p]!==i[p]&&$.push(p);return $}function ve(e){return e===Br}function Le(e,t){e.isTTY&&e.setRawMode(t)}class be{constructor({render:e,input:t=hr,output:n=or,...i},$=!0){te(this,"input"),te(this,"output"),te(this,"rl"),te(this,"opts"),te(this,"_track",!1),te(this,"_render"),te(this,"_cursor",0),te(this,"state","initial"),te(this,"value"),te(this,"error",""),te(this,"subscribers",new Map),te(this,"_prevFrame",""),this.opts=i,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=e.bind(this),this._track=$,this.input=t,this.output=n}prompt(){let e=new Si(0);return e._write=(t,n,i)=>{this._track&&(this.value=this.rl.line.replace(/\t/g,""),this._cursor=this.rl.cursor,this.emit("value",this.value)),i()},this.input.pipe(e),this.rl=tr.createInterface({input:this.input,output:e,tabSize:2,prompt:"",escapeCodeTimeout:50}),tr.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on("keypress",this.onKeypress),Le(this.input,!0),this.output.on("resize",this.render),this.render(),new Promise((t,n)=>{this.once("submit",()=>{this.output.write(s.cursor.show),this.output.off("resize",this.render),Le(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(s.cursor.show),this.output.off("resize",this.render),Le(this.input,!1),t(Br)})})}on(e,t){let n=this.subscribers.get(e)??[];n.push({cb:t}),this.subscribers.set(e,n)}once(e,t){let n=this.subscribers.get(e)??[];n.push({cb:t,once:!0}),this.subscribers.set(e,n)}emit(e,...t){let n=this.subscribers.get(e)??[],i=[];for(let $ of n)$.cb(...t),$.once&&i.push(()=>n.splice(n.indexOf($),1));for(let $ of i)$()}unsubscribe(){this.subscribers.clear()}onKeypress(e,t){if(this.state==="error"&&(this.state="active"),t?.name&&!this._track&&yr.has(t.name)&&this.emit("cursor",yr.get(t.name)),t?.name&&Oi.has(t.name)&&this.emit("cursor",t.name),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),e==="\t"&&this.opts.placeholder&&(this.value||(this.rl.write(this.opts.placeholder),this.emit("value",this.opts.placeholder))),e&&this.emit("key",e.toLowerCase()),t?.name==="return"){if(this.opts.validate){let n=this.opts.validate(this.value);n&&(this.error=n,this.state="error",this.rl.write(this.value))}this.state!=="error"&&(this.state="submit")}e==="\x03"&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
8
- `),Le(this.input,!1),this.rl.close(),this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=mr(this._prevFrame,process.stdout.columns,{hard:!0}).split(`
9
- `).length-1;this.output.write(s.cursor.move(-999,e*-1))}render(){let e=mr(this._render(this)??"",process.stdout.columns,{hard:!0});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(s.cursor.hide);else{let t=zi(this._prevFrame,e);if(this.restoreCursor(),t&&t?.length===1){let n=t[0];this.output.write(s.cursor.move(0,n)),this.output.write(s.erase.lines(1));let i=e.split(`
10
- `);this.output.write(i[n]),this._prevFrame=e,this.output.write(s.cursor.move(0,i.length-n-1));return}else if(t&&t?.length>1){let n=t[0];this.output.write(s.cursor.move(0,n)),this.output.write(s.erase.down());let i=e.split(`
7
+ `),$=[];for(let p=0;p<Math.max(n.length,i.length);p++)n[p]!==i[p]&&$.push(p);return $}function ve(e){return e===Kr}function Ee(e,t){e.isTTY&&e.setRawMode(t)}class he{constructor({render:e,input:t=Ar,output:n=ur,...i},$=!0){re(this,"input"),re(this,"output"),re(this,"rl"),re(this,"opts"),re(this,"_track",!1),re(this,"_render"),re(this,"_cursor",0),re(this,"state","initial"),re(this,"value"),re(this,"error",""),re(this,"subscribers",new Map),re(this,"_prevFrame",""),this.opts=i,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=e.bind(this),this._track=$,this.input=t,this.output=n}prompt(){let e=new hi(0);return e._write=(t,n,i)=>{this._track&&(this.value=this.rl.line.replace(/\t/g,""),this._cursor=this.rl.cursor,this.emit("value",this.value)),i()},this.input.pipe(e),this.rl=tr.createInterface({input:this.input,output:e,tabSize:2,prompt:"",escapeCodeTimeout:50}),tr.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on("keypress",this.onKeypress),Ee(this.input,!0),this.output.on("resize",this.render),this.render(),new Promise((t,n)=>{this.once("submit",()=>{this.output.write(F.cursor.show),this.output.off("resize",this.render),Ee(this.input,!1),t(this.value)}),this.once("cancel",()=>{this.output.write(F.cursor.show),this.output.off("resize",this.render),Ee(this.input,!1),t(Kr)})})}on(e,t){let n=this.subscribers.get(e)??[];n.push({cb:t}),this.subscribers.set(e,n)}once(e,t){let n=this.subscribers.get(e)??[];n.push({cb:t,once:!0}),this.subscribers.set(e,n)}emit(e,...t){let n=this.subscribers.get(e)??[],i=[];for(let $ of n)$.cb(...t),$.once&&i.push(()=>n.splice(n.indexOf($),1));for(let $ of i)$()}unsubscribe(){this.subscribers.clear()}onKeypress(e,t){if(this.state==="error"&&(this.state="active"),t?.name&&!this._track&&_r.has(t.name)&&this.emit("cursor",_r.get(t.name)),t?.name&&Zi.has(t.name)&&this.emit("cursor",t.name),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),e==="\t"&&this.opts.placeholder&&(this.value||(this.rl.write(this.opts.placeholder),this.emit("value",this.opts.placeholder))),e&&this.emit("key",e.toLowerCase()),t?.name==="return"){if(this.opts.validate){let n=this.opts.validate(this.value);n&&(this.error=n,this.state="error",this.rl.write(this.value))}this.state!=="error"&&(this.state="submit")}e==="\x03"&&(this.state="cancel"),(this.state==="submit"||this.state==="cancel")&&this.emit("finalize"),this.render(),(this.state==="submit"||this.state==="cancel")&&this.close()}close(){this.input.unpipe(),this.input.removeListener("keypress",this.onKeypress),this.output.write(`
8
+ `),Ee(this.input,!1),this.rl.close(),this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=yr(this._prevFrame,process.stdout.columns,{hard:!0}).split(`
9
+ `).length-1;this.output.write(F.cursor.move(-999,e*-1))}render(){let e=yr(this._render(this)??"",process.stdout.columns,{hard:!0});if(e!==this._prevFrame){if(this.state==="initial")this.output.write(F.cursor.hide);else{let t=Hi(this._prevFrame,e);if(this.restoreCursor(),t&&t?.length===1){let n=t[0];this.output.write(F.cursor.move(0,n)),this.output.write(F.erase.lines(1));let i=e.split(`
10
+ `);this.output.write(i[n]),this._prevFrame=e,this.output.write(F.cursor.move(0,i.length-n-1));return}else if(t&&t?.length>1){let n=t[0];this.output.write(F.cursor.move(0,n)),this.output.write(F.erase.down());let i=e.split(`
11
11
  `).slice(n);this.output.write(i.join(`
12
- `)),this._prevFrame=e;return}this.output.write(s.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}}function jr({input:e=hr,output:t=or,overwrite:n=!0,hideCursor:i=!0}={}){let $=xe.createInterface({input:e,output:t,prompt:"",tabSize:1});xe.emitKeypressEvents(e,$),e.isTTY&&e.setRawMode(!0);let p=(r,{name:m})=>{if(String(r)==="\x03"){i&&t.write(s.cursor.show),process.exit(0);return}if(!n)return;xe.moveCursor(t,m==="return"?0:-1,m==="return"?-1:0,()=>{xe.clearLine(t,1,()=>{e.once("keypress",p)})})};return i&&t.write(s.cursor.hide),e.once("keypress",p),()=>{e.off("keypress",p),i&&t.write(s.cursor.show),e.isTTY&&!ai&&e.setRawMode(!1),$.terminal=!1,$.close()}}var s,Se,ki,kr,qi,Gi,Bi=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g},Ki,ht=10,rr=(e=0)=>(t)=>`\x1B[${t+e}m`,nr=(e=0)=>(t)=>`\x1B[${38+e};5;${t}m`,ir=(e=0)=>(t,n,i)=>`\x1B[${38+e};2;${t};${n};${i}m`,C,Ni,ji,Ji,Ve,Wi=39,St="\x07",qr="[",Ti="]",Gr="m",At,$r=(e)=>`${Ve.values().next().value}${qr}${e}${Gr}`,pr=(e)=>`${Ve.values().next().value}${At}${e}${St}`,Mi=(e)=>e.split(" ").map((t)=>Ze(t)),ot=(e,t,n)=>{let i=[...t],$=!1,p=!1,r=Ze(Sr(e[e.length-1]));for(let[m,_]of i.entries()){let x=Ze(_);if(r+x<=n?e[e.length-1]+=_:(e.push(_),r=0),Ve.has(_)&&($=!0,p=i.slice(m+1).join("").startsWith(At)),$){p?_===St&&($=!1,p=!1):_===Gr&&($=!1);continue}r+=x,r===n&&m<i.length-1&&(e.push(""),r=0)}!r&&e[e.length-1].length>0&&e.length>1&&(e[e.length-2]+=e.pop())},Qi=(e)=>{let t=e.split(" "),n=t.length;for(;n>0&&!(Ze(t[n-1])>0);)n--;return n===t.length?e:t.slice(0,n).join(" ")+t.slice(n).join("")},Zi=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let i="",$,p,r=Mi(e),m=[""];for(let[x,b]of e.split(" ").entries()){n.trim!==!1&&(m[m.length-1]=m[m.length-1].trimStart());let w=Ze(m[m.length-1]);if(x!==0&&(w>=t&&(n.wordWrap===!1||n.trim===!1)&&(m.push(""),w=0),(w>0||n.trim===!1)&&(m[m.length-1]+=" ",w++)),n.hard&&r[x]>t){let u=t-w,k=1+Math.floor((r[x]-u-1)/t);Math.floor((r[x]-1)/t)<k&&m.push(""),ot(m,b,t);continue}if(w+r[x]>t&&w>0&&r[x]>0){if(n.wordWrap===!1&&w<t){ot(m,b,t);continue}m.push("")}if(w+r[x]>t&&n.wordWrap===!1){ot(m,b,t);continue}m[m.length-1]+=b}n.trim!==!1&&(m=m.map((x)=>Qi(x)));let _=[...m.join(`
13
- `)];for(let[x,b]of _.entries()){if(i+=b,Ve.has(b)){let{groups:u}=new RegExp(`(?:\\${qr}(?<code>\\d+)m|\\${At}(?<uri>.*)${St})`).exec(_.slice(x).join(""))||{groups:{}};if(u.code!==void 0){let k=Number.parseFloat(u.code);$=k===Wi?void 0:k}else u.uri!==void 0&&(p=u.uri.length===0?void 0:u.uri)}let w=Ji.codes.get(Number($));_[x+1]===`
12
+ `)),this._prevFrame=e;return}this.output.write(F.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}}function jr({input:e=Ar,output:t=ur,overwrite:n=!0,hideCursor:i=!0}={}){let $=we.createInterface({input:e,output:t,prompt:"",tabSize:1});we.emitKeypressEvents(e,$),e.isTTY&&e.setRawMode(!0);let p=(r,{name:y})=>{if(String(r)==="\x03"){i&&t.write(F.cursor.show),process.exit(0);return}if(!n)return;we.moveCursor(t,y==="return"?0:-1,y==="return"?-1:0,()=>{we.clearLine(t,1,()=>{e.once("keypress",p)})})};return i&&t.write(F.cursor.hide),e.once("keypress",p),()=>{e.off("keypress",p),i&&t.write(F.cursor.show),e.isTTY&&!di&&e.setRawMode(!1),$.terminal=!1,$.close()}}var F,qe,ui,qr,Si,ki,qi=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g},oi,At=10,rr=(e=0)=>(t)=>`\x1B[${t+e}m`,nr=(e=0)=>(t)=>`\x1B[${38+e};5;${t}m`,ir=(e=0)=>(t,n,i)=>`\x1B[${38+e};2;${t};${n};${i}m`,C,Gi,Ki,Bi,Ie,ji=39,St="\x07",or="[",Ri="]",Gr="m",kt,$r=(e)=>`${Ie.values().next().value}${or}${e}${Gr}`,pr=(e)=>`${Ie.values().next().value}${kt}${e}${St}`,Ji=(e)=>e.split(" ").map((t)=>ze(t)),ut=(e,t,n)=>{let i=[...t],$=!1,p=!1,r=ze(Sr(e[e.length-1]));for(let[y,m]of i.entries()){let x=ze(m);if(r+x<=n?e[e.length-1]+=m:(e.push(m),r=0),Ie.has(m)&&($=!0,p=i.slice(y+1).join("").startsWith(kt)),$){p?m===St&&($=!1,p=!1):m===Gr&&($=!1);continue}r+=x,r===n&&y<i.length-1&&(e.push(""),r=0)}!r&&e[e.length-1].length>0&&e.length>1&&(e[e.length-2]+=e.pop())},Wi=(e)=>{let t=e.split(" "),n=t.length;for(;n>0&&!(ze(t[n-1])>0);)n--;return n===t.length?e:t.slice(0,n).join(" ")+t.slice(n).join("")},Ti=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let i="",$,p,r=Ji(e),y=[""];for(let[x,b]of e.split(" ").entries()){n.trim!==!1&&(y[y.length-1]=y[y.length-1].trimStart());let w=ze(y[y.length-1]);if(x!==0&&(w>=t&&(n.wordWrap===!1||n.trim===!1)&&(y.push(""),w=0),(w>0||n.trim===!1)&&(y[y.length-1]+=" ",w++)),n.hard&&r[x]>t){let S=t-w,q=1+Math.floor((r[x]-S-1)/t);Math.floor((r[x]-1)/t)<q&&y.push(""),ut(y,b,t);continue}if(w+r[x]>t&&w>0&&r[x]>0){if(n.wordWrap===!1&&w<t){ut(y,b,t);continue}y.push("")}if(w+r[x]>t&&n.wordWrap===!1){ut(y,b,t);continue}y[y.length-1]+=b}n.trim!==!1&&(y=y.map((x)=>Wi(x)));let m=[...y.join(`
13
+ `)];for(let[x,b]of m.entries()){if(i+=b,Ie.has(b)){let{groups:S}=new RegExp(`(?:\\${or}(?<code>\\d+)m|\\${kt}(?<uri>.*)${St})`).exec(m.slice(x).join(""))||{groups:{}};if(S.code!==void 0){let q=Number.parseFloat(S.code);$=q===ji?void 0:q}else S.uri!==void 0&&(p=S.uri.length===0?void 0:S.uri)}let w=Bi.codes.get(Number($));m[x+1]===`
14
14
  `?(p&&(i+=pr("")),$&&w&&(i+=$r(w))):b===`
15
- `&&($&&w&&(i+=$r($)),p&&(i+=pr(p)))}return i},ci,Hi=(e,t,n)=>(t in e)?ci(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,te=(e,t,n)=>(Hi(e,typeof t!="symbol"?t+"":t,n),n),Br,yr,Oi,kt,Xi,Pi=(e,t,n)=>(t in e)?Xi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,_r=(e,t,n)=>(Pi(e,typeof t!="symbol"?t+"":t,n),n),qt,Yi,Ci=(e,t,n)=>(t in e)?Yi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xr=(e,t,n)=>(Ci(e,typeof t!="symbol"?t+"":t,n),n),Kr,Li,Vi=(e,t,n)=>(t in e)?Li(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,br=(e,t,n)=>(Vi(e,typeof t!="symbol"?t+"":t,n),n),Gt,vi,Ei=(e,t,n)=>(t in e)?vi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wr=(e,t,n)=>(Ei(e,typeof t!="symbol"?t+"":t,n),n),Nr,Ii,di=(e,t,n)=>(t in e)?Ii(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ur=(e,t,n)=>(di(e,typeof t!="symbol"?t+"":t,n),n),Bt,Ui,si=(e,t,n)=>(t in e)?Ui(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Fi=(e,t,n)=>(si(e,typeof t!="symbol"?t+"":t,n),n),Kt,ai;var Nt=Pt(()=>{s=He(bt(),1),Se=He(ut(),1);ki=Ai();kr={exports:{}};(function(e){var t={};e.exports=t,t.eastAsianWidth=function(i){var $=i.charCodeAt(0),p=i.length==2?i.charCodeAt(1):0,r=$;return 55296<=$&&$<=56319&&56320<=p&&p<=57343&&($&=1023,p&=1023,r=$<<10|p,r+=65536),r==12288||65281<=r&&r<=65376||65504<=r&&r<=65510?"F":r==8361||65377<=r&&r<=65470||65474<=r&&r<=65479||65482<=r&&r<=65487||65490<=r&&r<=65495||65498<=r&&r<=65500||65512<=r&&r<=65518?"H":4352<=r&&r<=4447||4515<=r&&r<=4519||4602<=r&&r<=4607||9001<=r&&r<=9002||11904<=r&&r<=11929||11931<=r&&r<=12019||12032<=r&&r<=12245||12272<=r&&r<=12283||12289<=r&&r<=12350||12353<=r&&r<=12438||12441<=r&&r<=12543||12549<=r&&r<=12589||12593<=r&&r<=12686||12688<=r&&r<=12730||12736<=r&&r<=12771||12784<=r&&r<=12830||12832<=r&&r<=12871||12880<=r&&r<=13054||13056<=r&&r<=19903||19968<=r&&r<=42124||42128<=r&&r<=42182||43360<=r&&r<=43388||44032<=r&&r<=55203||55216<=r&&r<=55238||55243<=r&&r<=55291||63744<=r&&r<=64255||65040<=r&&r<=65049||65072<=r&&r<=65106||65108<=r&&r<=65126||65128<=r&&r<=65131||110592<=r&&r<=110593||127488<=r&&r<=127490||127504<=r&&r<=127546||127552<=r&&r<=127560||127568<=r&&r<=127569||131072<=r&&r<=194367||177984<=r&&r<=196605||196608<=r&&r<=262141?"W":32<=r&&r<=126||162<=r&&r<=163||165<=r&&r<=166||r==172||r==175||10214<=r&&r<=10221||10629<=r&&r<=10630?"Na":r==161||r==164||167<=r&&r<=168||r==170||173<=r&&r<=174||176<=r&&r<=180||182<=r&&r<=186||188<=r&&r<=191||r==198||r==208||215<=r&&r<=216||222<=r&&r<=225||r==230||232<=r&&r<=234||236<=r&&r<=237||r==240||242<=r&&r<=243||247<=r&&r<=250||r==252||r==254||r==257||r==273||r==275||r==283||294<=r&&r<=295||r==299||305<=r&&r<=307||r==312||319<=r&&r<=322||r==324||328<=r&&r<=331||r==333||338<=r&&r<=339||358<=r&&r<=359||r==363||r==462||r==464||r==466||r==468||r==470||r==472||r==474||r==476||r==593||r==609||r==708||r==711||713<=r&&r<=715||r==717||r==720||728<=r&&r<=731||r==733||r==735||768<=r&&r<=879||913<=r&&r<=929||931<=r&&r<=937||945<=r&&r<=961||963<=r&&r<=969||r==1025||1040<=r&&r<=1103||r==1105||r==8208||8211<=r&&r<=8214||8216<=r&&r<=8217||8220<=r&&r<=8221||8224<=r&&r<=8226||8228<=r&&r<=8231||r==8240||8242<=r&&r<=8243||r==8245||r==8251||r==8254||r==8308||r==8319||8321<=r&&r<=8324||r==8364||r==8451||r==8453||r==8457||r==8467||r==8470||8481<=r&&r<=8482||r==8486||r==8491||8531<=r&&r<=8532||8539<=r&&r<=8542||8544<=r&&r<=8555||8560<=r&&r<=8569||r==8585||8592<=r&&r<=8601||8632<=r&&r<=8633||r==8658||r==8660||r==8679||r==8704||8706<=r&&r<=8707||8711<=r&&r<=8712||r==8715||r==8719||r==8721||r==8725||r==8730||8733<=r&&r<=8736||r==8739||r==8741||8743<=r&&r<=8748||r==8750||8756<=r&&r<=8759||8764<=r&&r<=8765||r==8776||r==8780||r==8786||8800<=r&&r<=8801||8804<=r&&r<=8807||8810<=r&&r<=8811||8814<=r&&r<=8815||8834<=r&&r<=8835||8838<=r&&r<=8839||r==8853||r==8857||r==8869||r==8895||r==8978||9312<=r&&r<=9449||9451<=r&&r<=9547||9552<=r&&r<=9587||9600<=r&&r<=9615||9618<=r&&r<=9621||9632<=r&&r<=9633||9635<=r&&r<=9641||9650<=r&&r<=9651||9654<=r&&r<=9655||9660<=r&&r<=9661||9664<=r&&r<=9665||9670<=r&&r<=9672||r==9675||9678<=r&&r<=9681||9698<=r&&r<=9701||r==9711||9733<=r&&r<=9734||r==9737||9742<=r&&r<=9743||9748<=r&&r<=9749||r==9756||r==9758||r==9792||r==9794||9824<=r&&r<=9825||9827<=r&&r<=9829||9831<=r&&r<=9834||9836<=r&&r<=9837||r==9839||9886<=r&&r<=9887||9918<=r&&r<=9919||9924<=r&&r<=9933||9935<=r&&r<=9953||r==9955||9960<=r&&r<=9983||r==10045||r==10071||10102<=r&&r<=10111||11093<=r&&r<=11097||12872<=r&&r<=12879||57344<=r&&r<=63743||65024<=r&&r<=65039||r==65533||127232<=r&&r<=127242||127248<=r&&r<=127277||127280<=r&&r<=127337||127344<=r&&r<=127386||917760<=r&&r<=917999||983040<=r&&r<=1048573||1048576<=r&&r<=1114109?"A":"N"},t.characterLength=function(i){var $=this.eastAsianWidth(i);return $=="F"||$=="W"||$=="A"?2:1};function n(i){return i.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g)||[]}t.length=function(i){for(var $=n(i),p=0,r=0;r<$.length;r++)p=p+this.characterLength($[r]);return p},t.slice=function(i,$,p){textLen=t.length(i),$=$||0,p=p||1,$<0&&($=textLen+$),p<0&&(p=textLen+p);for(var r="",m=0,_=n(i),x=0;x<_.length;x++){var b=_[x],w=t.length(b);if(m>=$-(w==2?1:0))if(m+w<=p)r+=b;else break;m+=w}return r}})(kr);qi=kr.exports,Gi=Ar(qi),Ki=Ar(Bi);C={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(C.modifier);Ni=Object.keys(C.color),ji=Object.keys(C.bgColor);[...Ni,...ji];Ji=Ri(),Ve=new Set(["\x1B","›"]),At=`${Ti}8;;`;ci=Object.defineProperty;Br=Symbol("clack:cancel");yr=new Map([["k","up"],["j","down"],["h","left"],["l","right"]]),Oi=new Set(["up","down","left","right","space","enter"]);kt=class kt extends be{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on("value",()=>{this.value=this._value}),this.on("confirm",(t)=>{this.output.write(s.cursor.move(0,-1)),this.value=t,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}};Xi=Object.defineProperty;qt=class qt extends be{constructor(e){super(e,!1),_r(this,"options"),_r(this,"cursor",0);let{options:t}=e;this.options=Object.entries(t).flatMap(([n,i])=>[{value:n,group:!0,label:n},...i.map(($)=>({...$,group:n}))]),this.value=[...e.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:n})=>n===e.cursorAt),0),this.on("cursor",(n)=>{switch(n){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case"space":this.toggleValue();break}})}getGroupItems(e){return this.options.filter((t)=>t.group===e)}isGroupSelected(e){return this.getGroupItems(e).every((t)=>this.value.includes(t.value))}toggleValue(){let e=this.options[this.cursor];if(e.group===!0){let t=e.value,n=this.getGroupItems(t);this.isGroupSelected(t)?this.value=this.value.filter((i)=>n.findIndex(($)=>$.value===i)===-1):this.value=[...this.value,...n.map((i)=>i.value)],this.value=Array.from(new Set(this.value))}else{let t=this.value.includes(e.value);this.value=t?this.value.filter((n)=>n!==e.value):[...this.value,e.value]}}};Yi=Object.defineProperty,Kr=class extends be{constructor(e){super(e,!1),xr(this,"options"),xr(this,"cursor",0),this.options=e.options,this.value=[...e.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:t})=>t===e.cursorAt),0),this.on("key",(t)=>{t==="a"&&this.toggleAll()}),this.on("cursor",(t)=>{switch(t){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case"space":this.toggleValue();break}})}get _value(){return this.options[this.cursor].value}toggleAll(){let e=this.value.length===this.options.length;this.value=e?[]:this.options.map((t)=>t.value)}toggleValue(){let e=this.value.includes(this._value);this.value=e?this.value.filter((t)=>t!==this._value):[...this.value,this._value]}},Li=Object.defineProperty;Gt=class Gt extends be{constructor({mask:e,...t}){super(t),br(this,"valueWithCursor",""),br(this,"_mask","•"),this._mask=e??"•",this.on("finalize",()=>{this.valueWithCursor=this.masked}),this.on("value",()=>{if(this.cursor>=this.value.length)this.valueWithCursor=`${this.masked}${Se.default.inverse(Se.default.hidden("_"))}`;else{let n=this.masked.slice(0,this.cursor),i=this.masked.slice(this.cursor);this.valueWithCursor=`${n}${Se.default.inverse(i[0])}${i.slice(1)}`}})}get cursor(){return this._cursor}get masked(){return this.value.replaceAll(/./g,this._mask)}};vi=Object.defineProperty,Nr=class extends be{constructor(e){super(e,!1),wr(this,"options"),wr(this,"cursor",0),this.options=e.options,this.cursor=this.options.findIndex(({value:t})=>t===e.initialValue),this.cursor===-1&&(this.cursor=0),this.changeValue(),this.on("cursor",(t)=>{switch(t){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break}this.changeValue()})}get _value(){return this.options[this.cursor]}changeValue(){this.value=this._value.value}},Ii=Object.defineProperty;Bt=class Bt extends be{constructor(e){super(e,!1),ur(this,"options"),ur(this,"cursor",0),this.options=e.options;let t=this.options.map(({value:[n]})=>n?.toLowerCase());this.cursor=Math.max(t.indexOf(e.initialValue),0),this.on("key",(n)=>{if(!t.includes(n))return;let i=this.options.find(({value:[$]})=>$?.toLowerCase()===n);i&&(this.value=i.value,this.state="submit",this.emit("submit"))})}};Ui=Object.defineProperty;Kt=class Kt extends be{constructor(e){super(e),Fi(this,"valueWithCursor",""),this.on("finalize",()=>{this.value||(this.value=e.defaultValue),this.valueWithCursor=this.value}),this.on("value",()=>{if(this.cursor>=this.value.length)this.valueWithCursor=`${this.value}${Se.default.inverse(Se.default.hidden("_"))}`;else{let t=this.value.slice(0,this.cursor),n=this.value.slice(this.cursor);this.valueWithCursor=`${t}${Se.default.inverse(n[0])}${n.slice(1)}`}})}get cursor(){return this._cursor}};ai=globalThis.process.platform.startsWith("win")});var Ie={};In(Ie,{text:()=>m$,spinner:()=>k$,selectKey:()=>b$,select:()=>x$,password:()=>y$,outro:()=>A$,note:()=>h$,multiselect:()=>w$,log:()=>Ae,isCancel:()=>ve,intro:()=>S$,groupMultiselect:()=>u$,group:()=>G$,confirm:()=>_$,cancel:()=>o$});import ie from"node:process";function li(){return ie.platform!=="win32"?ie.env.TERM!=="linux":Boolean(ie.env.CI)||Boolean(ie.env.WT_SESSION)||Boolean(ie.env.TERMINUS_SUBLIME)||ie.env.ConEmuTask==="{cmd::Cmder}"||ie.env.TERM_PROGRAM==="Terminus-Sublime"||ie.env.TERM_PROGRAM==="vscode"||ie.env.TERM==="xterm-256color"||ie.env.TERM==="alacritty"||ie.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}function q$(){let e=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(e,"g")}var y,Je,Rt,I=(e,t)=>Rt?e:t,Di,Jr,Wr,Ee,fi,N,a,Jt,Wt,Tt,ce,Tr,gi,Rr,e$,t$,r$,n$,i$,$$,p$,ke=(e)=>{switch(e){case"initial":case"active":return y.default.cyan(Di);case"cancel":return y.default.red(Jr);case"error":return y.default.yellow(Wr);case"submit":return y.default.green(Ee)}},m$=(e)=>new Kt({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,render(){let t=`${y.default.gray(N)}
16
- ${ke(this.state)} ${e.message}
17
- `,n=e.placeholder?y.default.inverse(e.placeholder[0])+y.default.dim(e.placeholder.slice(1)):y.default.inverse(y.default.hidden("_")),i=this.value?this.valueWithCursor:n;switch(this.state){case"error":return`${t.trim()}
18
- ${y.default.yellow(N)} ${i}
19
- ${y.default.yellow(a)} ${y.default.yellow(this.error)}
20
- `;case"submit":return`${t}${y.default.gray(N)} ${y.default.dim(this.value||e.placeholder)}`;case"cancel":return`${t}${y.default.gray(N)} ${y.default.strikethrough(y.default.dim(this.value??""))}${this.value?.trim()?`
21
- `+y.default.gray(N):""}`;default:return`${t}${y.default.cyan(N)} ${i}
22
- ${y.default.cyan(a)}
23
- `}}}).prompt(),y$=(e)=>new Gt({validate:e.validate,mask:e.mask??gi,render(){let t=`${y.default.gray(N)}
24
- ${ke(this.state)} ${e.message}
15
+ `&&($&&w&&(i+=$r($)),p&&(i+=pr(p)))}return i},Mi,Qi=(e,t,n)=>(t in e)?Mi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,re=(e,t,n)=>(Qi(e,typeof t!="symbol"?t+"":t,n),n),Kr,_r,Zi,qt,zi,Xi=(e,t,n)=>(t in e)?zi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,mr=(e,t,n)=>(Xi(e,typeof t!="symbol"?t+"":t,n),n),ot,Pi,Yi=(e,t,n)=>(t in e)?Pi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,xr=(e,t,n)=>(Yi(e,typeof t!="symbol"?t+"":t,n),n),Nr,Oi,ci=(e,t,n)=>(t in e)?Oi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,br=(e,t,n)=>(ci(e,typeof t!="symbol"?t+"":t,n),n),Gt,Ci,Li=(e,t,n)=>(t in e)?Ci(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,wr=(e,t,n)=>(Li(e,typeof t!="symbol"?t+"":t,n),n),Br,Vi,Ei=(e,t,n)=>(t in e)?Vi(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hr=(e,t,n)=>(Ei(e,typeof t!="symbol"?t+"":t,n),n),Kt,Ii,vi=(e,t,n)=>(t in e)?Ii(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Ui=(e,t,n)=>(vi(e,typeof t!="symbol"?t+"":t,n),n),Nt,di;var Bt=Ot(()=>{F=ne(bt(),1),qe=ne(ht(),1);ui=Ai();qr={exports:{}};(function(e){var t={};e.exports=t,t.eastAsianWidth=function(i){var $=i.charCodeAt(0),p=i.length==2?i.charCodeAt(1):0,r=$;return 55296<=$&&$<=56319&&56320<=p&&p<=57343&&($&=1023,p&=1023,r=$<<10|p,r+=65536),r==12288||65281<=r&&r<=65376||65504<=r&&r<=65510?"F":r==8361||65377<=r&&r<=65470||65474<=r&&r<=65479||65482<=r&&r<=65487||65490<=r&&r<=65495||65498<=r&&r<=65500||65512<=r&&r<=65518?"H":4352<=r&&r<=4447||4515<=r&&r<=4519||4602<=r&&r<=4607||9001<=r&&r<=9002||11904<=r&&r<=11929||11931<=r&&r<=12019||12032<=r&&r<=12245||12272<=r&&r<=12283||12289<=r&&r<=12350||12353<=r&&r<=12438||12441<=r&&r<=12543||12549<=r&&r<=12589||12593<=r&&r<=12686||12688<=r&&r<=12730||12736<=r&&r<=12771||12784<=r&&r<=12830||12832<=r&&r<=12871||12880<=r&&r<=13054||13056<=r&&r<=19903||19968<=r&&r<=42124||42128<=r&&r<=42182||43360<=r&&r<=43388||44032<=r&&r<=55203||55216<=r&&r<=55238||55243<=r&&r<=55291||63744<=r&&r<=64255||65040<=r&&r<=65049||65072<=r&&r<=65106||65108<=r&&r<=65126||65128<=r&&r<=65131||110592<=r&&r<=110593||127488<=r&&r<=127490||127504<=r&&r<=127546||127552<=r&&r<=127560||127568<=r&&r<=127569||131072<=r&&r<=194367||177984<=r&&r<=196605||196608<=r&&r<=262141?"W":32<=r&&r<=126||162<=r&&r<=163||165<=r&&r<=166||r==172||r==175||10214<=r&&r<=10221||10629<=r&&r<=10630?"Na":r==161||r==164||167<=r&&r<=168||r==170||173<=r&&r<=174||176<=r&&r<=180||182<=r&&r<=186||188<=r&&r<=191||r==198||r==208||215<=r&&r<=216||222<=r&&r<=225||r==230||232<=r&&r<=234||236<=r&&r<=237||r==240||242<=r&&r<=243||247<=r&&r<=250||r==252||r==254||r==257||r==273||r==275||r==283||294<=r&&r<=295||r==299||305<=r&&r<=307||r==312||319<=r&&r<=322||r==324||328<=r&&r<=331||r==333||338<=r&&r<=339||358<=r&&r<=359||r==363||r==462||r==464||r==466||r==468||r==470||r==472||r==474||r==476||r==593||r==609||r==708||r==711||713<=r&&r<=715||r==717||r==720||728<=r&&r<=731||r==733||r==735||768<=r&&r<=879||913<=r&&r<=929||931<=r&&r<=937||945<=r&&r<=961||963<=r&&r<=969||r==1025||1040<=r&&r<=1103||r==1105||r==8208||8211<=r&&r<=8214||8216<=r&&r<=8217||8220<=r&&r<=8221||8224<=r&&r<=8226||8228<=r&&r<=8231||r==8240||8242<=r&&r<=8243||r==8245||r==8251||r==8254||r==8308||r==8319||8321<=r&&r<=8324||r==8364||r==8451||r==8453||r==8457||r==8467||r==8470||8481<=r&&r<=8482||r==8486||r==8491||8531<=r&&r<=8532||8539<=r&&r<=8542||8544<=r&&r<=8555||8560<=r&&r<=8569||r==8585||8592<=r&&r<=8601||8632<=r&&r<=8633||r==8658||r==8660||r==8679||r==8704||8706<=r&&r<=8707||8711<=r&&r<=8712||r==8715||r==8719||r==8721||r==8725||r==8730||8733<=r&&r<=8736||r==8739||r==8741||8743<=r&&r<=8748||r==8750||8756<=r&&r<=8759||8764<=r&&r<=8765||r==8776||r==8780||r==8786||8800<=r&&r<=8801||8804<=r&&r<=8807||8810<=r&&r<=8811||8814<=r&&r<=8815||8834<=r&&r<=8835||8838<=r&&r<=8839||r==8853||r==8857||r==8869||r==8895||r==8978||9312<=r&&r<=9449||9451<=r&&r<=9547||9552<=r&&r<=9587||9600<=r&&r<=9615||9618<=r&&r<=9621||9632<=r&&r<=9633||9635<=r&&r<=9641||9650<=r&&r<=9651||9654<=r&&r<=9655||9660<=r&&r<=9661||9664<=r&&r<=9665||9670<=r&&r<=9672||r==9675||9678<=r&&r<=9681||9698<=r&&r<=9701||r==9711||9733<=r&&r<=9734||r==9737||9742<=r&&r<=9743||9748<=r&&r<=9749||r==9756||r==9758||r==9792||r==9794||9824<=r&&r<=9825||9827<=r&&r<=9829||9831<=r&&r<=9834||9836<=r&&r<=9837||r==9839||9886<=r&&r<=9887||9918<=r&&r<=9919||9924<=r&&r<=9933||9935<=r&&r<=9953||r==9955||9960<=r&&r<=9983||r==10045||r==10071||10102<=r&&r<=10111||11093<=r&&r<=11097||12872<=r&&r<=12879||57344<=r&&r<=63743||65024<=r&&r<=65039||r==65533||127232<=r&&r<=127242||127248<=r&&r<=127277||127280<=r&&r<=127337||127344<=r&&r<=127386||917760<=r&&r<=917999||983040<=r&&r<=1048573||1048576<=r&&r<=1114109?"A":"N"},t.characterLength=function(i){var $=this.eastAsianWidth(i);return $=="F"||$=="W"||$=="A"?2:1};function n(i){return i.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g)||[]}t.length=function(i){for(var $=n(i),p=0,r=0;r<$.length;r++)p=p+this.characterLength($[r]);return p},t.slice=function(i,$,p){textLen=t.length(i),$=$||0,p=p||1,$<0&&($=textLen+$),p<0&&(p=textLen+p);for(var r="",y=0,m=n(i),x=0;x<m.length;x++){var b=m[x],w=t.length(b);if(y>=$-(w==2?1:0))if(y+w<=p)r+=b;else break;y+=w}return r}})(qr);Si=qr.exports,ki=kr(Si),oi=kr(qi);C={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(C.modifier);Gi=Object.keys(C.color),Ki=Object.keys(C.bgColor);[...Gi,...Ki];Bi=Ni(),Ie=new Set(["\x1B","›"]),kt=`${Ri}8;;`;Mi=Object.defineProperty;Kr=Symbol("clack:cancel");_r=new Map([["k","up"],["j","down"],["h","left"],["l","right"]]),Zi=new Set(["up","down","left","right","space","enter"]);qt=class qt extends he{get cursor(){return this.value?0:1}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on("value",()=>{this.value=this._value}),this.on("confirm",(t)=>{this.output.write(F.cursor.move(0,-1)),this.value=t,this.state="submit",this.close()}),this.on("cursor",()=>{this.value=!this.value})}};zi=Object.defineProperty;ot=class ot extends he{constructor(e){super(e,!1),mr(this,"options"),mr(this,"cursor",0);let{options:t}=e;this.options=Object.entries(t).flatMap(([n,i])=>[{value:n,group:!0,label:n},...i.map(($)=>({...$,group:n}))]),this.value=[...e.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:n})=>n===e.cursorAt),0),this.on("cursor",(n)=>{switch(n){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case"space":this.toggleValue();break}})}getGroupItems(e){return this.options.filter((t)=>t.group===e)}isGroupSelected(e){return this.getGroupItems(e).every((t)=>this.value.includes(t.value))}toggleValue(){let e=this.options[this.cursor];if(e.group===!0){let t=e.value,n=this.getGroupItems(t);this.isGroupSelected(t)?this.value=this.value.filter((i)=>n.findIndex(($)=>$.value===i)===-1):this.value=[...this.value,...n.map((i)=>i.value)],this.value=Array.from(new Set(this.value))}else{let t=this.value.includes(e.value);this.value=t?this.value.filter((n)=>n!==e.value):[...this.value,e.value]}}};Pi=Object.defineProperty,Nr=class extends he{constructor(e){super(e,!1),xr(this,"options"),xr(this,"cursor",0),this.options=e.options,this.value=[...e.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:t})=>t===e.cursorAt),0),this.on("key",(t)=>{t==="a"&&this.toggleAll()}),this.on("cursor",(t)=>{switch(t){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case"space":this.toggleValue();break}})}get _value(){return this.options[this.cursor].value}toggleAll(){let e=this.value.length===this.options.length;this.value=e?[]:this.options.map((t)=>t.value)}toggleValue(){let e=this.value.includes(this._value);this.value=e?this.value.filter((t)=>t!==this._value):[...this.value,this._value]}},Oi=Object.defineProperty;Gt=class Gt extends he{constructor({mask:e,...t}){super(t),br(this,"valueWithCursor",""),br(this,"_mask","•"),this._mask=e??"•",this.on("finalize",()=>{this.valueWithCursor=this.masked}),this.on("value",()=>{if(this.cursor>=this.value.length)this.valueWithCursor=`${this.masked}${qe.default.inverse(qe.default.hidden("_"))}`;else{let n=this.masked.slice(0,this.cursor),i=this.masked.slice(this.cursor);this.valueWithCursor=`${n}${qe.default.inverse(i[0])}${i.slice(1)}`}})}get cursor(){return this._cursor}get masked(){return this.value.replaceAll(/./g,this._mask)}};Ci=Object.defineProperty,Br=class extends he{constructor(e){super(e,!1),wr(this,"options"),wr(this,"cursor",0),this.options=e.options,this.cursor=this.options.findIndex(({value:t})=>t===e.initialValue),this.cursor===-1&&(this.cursor=0),this.changeValue(),this.on("cursor",(t)=>{switch(t){case"left":case"up":this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case"down":case"right":this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break}this.changeValue()})}get _value(){return this.options[this.cursor]}changeValue(){this.value=this._value.value}},Vi=Object.defineProperty;Kt=class Kt extends he{constructor(e){super(e,!1),hr(this,"options"),hr(this,"cursor",0),this.options=e.options;let t=this.options.map(({value:[n]})=>n?.toLowerCase());this.cursor=Math.max(t.indexOf(e.initialValue),0),this.on("key",(n)=>{if(!t.includes(n))return;let i=this.options.find(({value:[$]})=>$?.toLowerCase()===n);i&&(this.value=i.value,this.state="submit",this.emit("submit"))})}};Ii=Object.defineProperty;Nt=class Nt extends he{constructor(e){super(e),Ui(this,"valueWithCursor",""),this.on("finalize",()=>{this.value||(this.value=e.defaultValue),this.valueWithCursor=this.value}),this.on("value",()=>{if(this.cursor>=this.value.length)this.valueWithCursor=`${this.value}${qe.default.inverse(qe.default.hidden("_"))}`;else{let t=this.value.slice(0,this.cursor),n=this.value.slice(this.cursor);this.valueWithCursor=`${t}${qe.default.inverse(n[0])}${n.slice(1)}`}})}get cursor(){return this._cursor}};di=globalThis.process.platform.startsWith("win")});var Pe={};Vn(Pe,{text:()=>i$,spinner:()=>u$,selectKey:()=>_$,select:()=>y$,password:()=>$$,outro:()=>A$,note:()=>b$,multiselect:()=>m$,log:()=>oe,isCancel:()=>ve,intro:()=>h$,groupMultiselect:()=>x$,group:()=>k$,confirm:()=>p$,cancel:()=>w$});import $e from"node:process";function si(){return $e.platform!=="win32"?$e.env.TERM!=="linux":Boolean($e.env.CI)||Boolean($e.env.WT_SESSION)||Boolean($e.env.TERMINUS_SUBLIME)||$e.env.ConEmuTask==="{cmd::Cmder}"||$e.env.TERM_PROGRAM==="Terminus-Sublime"||$e.env.TERM_PROGRAM==="vscode"||$e.env.TERM==="xterm-256color"||$e.env.TERM==="alacritty"||$e.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}function S$(){let e=["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)","(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");return new RegExp(e,"g")}var _,We,Rt,v=(e,t)=>Rt?e:t,Fi,Jr,Wr,Ue,ai,R,D,Jt,Wt,Tt,Xe,Tr,Di,Rr,li,fi,gi,e$,t$,r$,n$,Ge=(e)=>{switch(e){case"initial":case"active":return _.default.cyan(Fi);case"cancel":return _.default.red(Jr);case"error":return _.default.yellow(Wr);case"submit":return _.default.green(Ue)}},i$=(e)=>new Nt({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,render(){let t=`${_.default.gray(R)}
16
+ ${Ge(this.state)} ${e.message}
17
+ `,n=e.placeholder?_.default.inverse(e.placeholder[0])+_.default.dim(e.placeholder.slice(1)):_.default.inverse(_.default.hidden("_")),i=this.value?this.valueWithCursor:n;switch(this.state){case"error":return`${t.trim()}
18
+ ${_.default.yellow(R)} ${i}
19
+ ${_.default.yellow(D)} ${_.default.yellow(this.error)}
20
+ `;case"submit":return`${t}${_.default.gray(R)} ${_.default.dim(this.value||e.placeholder)}`;case"cancel":return`${t}${_.default.gray(R)} ${_.default.strikethrough(_.default.dim(this.value??""))}${this.value?.trim()?`
21
+ `+_.default.gray(R):""}`;default:return`${t}${_.default.cyan(R)} ${i}
22
+ ${_.default.cyan(D)}
23
+ `}}}).prompt(),$$=(e)=>new Gt({validate:e.validate,mask:e.mask??Di,render(){let t=`${_.default.gray(R)}
24
+ ${Ge(this.state)} ${e.message}
25
25
  `,n=this.valueWithCursor,i=this.masked;switch(this.state){case"error":return`${t.trim()}
26
- ${y.default.yellow(N)} ${i}
27
- ${y.default.yellow(a)} ${y.default.yellow(this.error)}
28
- `;case"submit":return`${t}${y.default.gray(N)} ${y.default.dim(i)}`;case"cancel":return`${t}${y.default.gray(N)} ${y.default.strikethrough(y.default.dim(i??""))}${i?`
29
- `+y.default.gray(N):""}`;default:return`${t}${y.default.cyan(N)} ${n}
30
- ${y.default.cyan(a)}
31
- `}}}).prompt(),_$=(e)=>{let t=e.active??"Yes",n=e.inactive??"No";return new kt({active:t,inactive:n,initialValue:e.initialValue??!0,render(){let i=`${y.default.gray(N)}
32
- ${ke(this.state)} ${e.message}
33
- `,$=this.value?t:n;switch(this.state){case"submit":return`${i}${y.default.gray(N)} ${y.default.dim($)}`;case"cancel":return`${i}${y.default.gray(N)} ${y.default.strikethrough(y.default.dim($))}
34
- ${y.default.gray(N)}`;default:return`${i}${y.default.cyan(N)} ${this.value?`${y.default.green(Jt)} ${t}`:`${y.default.dim(Wt)} ${y.default.dim(t)}`} ${y.default.dim("/")} ${this.value?`${y.default.dim(Wt)} ${y.default.dim(n)}`:`${y.default.green(Jt)} ${n}`}
35
- ${y.default.cyan(a)}
36
- `}}}).prompt()},x$=(e)=>{let t=(i,$)=>{let p=i.label??String(i.value);return $==="active"?`${y.default.green(Jt)} ${p} ${i.hint?y.default.dim(`(${i.hint})`):""}`:$==="selected"?`${y.default.dim(p)}`:$==="cancelled"?`${y.default.strikethrough(y.default.dim(p))}`:`${y.default.dim(Wt)} ${y.default.dim(p)}`},n=0;return new Nr({options:e.options,initialValue:e.initialValue,render(){let i=`${y.default.gray(N)}
37
- ${ke(this.state)} ${e.message}
38
- `;switch(this.state){case"submit":return`${i}${y.default.gray(N)} ${t(this.options[this.cursor],"selected")}`;case"cancel":return`${i}${y.default.gray(N)} ${t(this.options[this.cursor],"cancelled")}
39
- ${y.default.gray(N)}`;default:{let $=e.maxItems===void 0?1/0:Math.max(e.maxItems,5);this.cursor>=n+$-3?n=Math.max(Math.min(this.cursor-$+3,this.options.length-$),0):this.cursor<n+2&&(n=Math.max(this.cursor-2,0));let p=$<this.options.length&&n>0,r=$<this.options.length&&n+$<this.options.length;return`${i}${y.default.cyan(N)} ${this.options.slice(n,n+$).map((m,_,x)=>_===0&&p?y.default.dim("..."):_===x.length-1&&r?y.default.dim("..."):t(m,_+n===this.cursor?"active":"inactive")).join(`
40
- ${y.default.cyan(N)} `)}
41
- ${y.default.cyan(a)}
42
- `}}}}).prompt()},b$=(e)=>{let t=(n,i="inactive")=>{let $=n.label??String(n.value);return i==="selected"?`${y.default.dim($)}`:i==="cancelled"?`${y.default.strikethrough(y.default.dim($))}`:i==="active"?`${y.default.bgCyan(y.default.gray(` ${n.value} `))} ${$} ${n.hint?y.default.dim(`(${n.hint})`):""}`:`${y.default.gray(y.default.bgWhite(y.default.inverse(` ${n.value} `)))} ${$} ${n.hint?y.default.dim(`(${n.hint})`):""}`};return new Bt({options:e.options,initialValue:e.initialValue,render(){let n=`${y.default.gray(N)}
43
- ${ke(this.state)} ${e.message}
44
- `;switch(this.state){case"submit":return`${n}${y.default.gray(N)} ${t(this.options.find((i)=>i.value===this.value),"selected")}`;case"cancel":return`${n}${y.default.gray(N)} ${t(this.options[0],"cancelled")}
45
- ${y.default.gray(N)}`;default:return`${n}${y.default.cyan(N)} ${this.options.map((i,$)=>t(i,$===this.cursor?"active":"inactive")).join(`
46
- ${y.default.cyan(N)} `)}
47
- ${y.default.cyan(a)}
48
- `}}}).prompt()},w$=(e)=>{let t=(n,i)=>{let $=n.label??String(n.value);return i==="active"?`${y.default.cyan(Tt)} ${$} ${n.hint?y.default.dim(`(${n.hint})`):""}`:i==="selected"?`${y.default.green(ce)} ${y.default.dim($)}`:i==="cancelled"?`${y.default.strikethrough(y.default.dim($))}`:i==="active-selected"?`${y.default.green(ce)} ${$} ${n.hint?y.default.dim(`(${n.hint})`):""}`:i==="submitted"?`${y.default.dim($)}`:`${y.default.dim(Tr)} ${y.default.dim($)}`};return new Kr({options:e.options,initialValues:e.initialValues,required:e.required??!0,cursorAt:e.cursorAt,validate(n){if(this.required&&n.length===0)return`Please select at least one option.
49
- ${y.default.reset(y.default.dim(`Press ${y.default.gray(y.default.bgWhite(y.default.inverse(" space ")))} to select, ${y.default.gray(y.default.bgWhite(y.default.inverse(" enter ")))} to submit`))}`},render(){let n=`${y.default.gray(N)}
50
- ${ke(this.state)} ${e.message}
51
- `;switch(this.state){case"submit":return`${n}${y.default.gray(N)} ${this.options.filter(({value:i})=>this.value.includes(i)).map((i)=>t(i,"submitted")).join(y.default.dim(", "))||y.default.dim("none")}`;case"cancel":{let i=this.options.filter(({value:$})=>this.value.includes($)).map(($)=>t($,"cancelled")).join(y.default.dim(", "));return`${n}${y.default.gray(N)} ${i.trim()?`${i}
52
- ${y.default.gray(N)}`:""}`}case"error":{let i=this.error.split(`
53
- `).map(($,p)=>p===0?`${y.default.yellow(a)} ${y.default.yellow($)}`:` ${$}`).join(`
54
- `);return n+y.default.yellow(N)+" "+this.options.map(($,p)=>{let r=this.value.includes($.value),m=p===this.cursor;return m&&r?t($,"active-selected"):r?t($,"selected"):t($,m?"active":"inactive")}).join(`
55
- ${y.default.yellow(N)} `)+`
26
+ ${_.default.yellow(R)} ${i}
27
+ ${_.default.yellow(D)} ${_.default.yellow(this.error)}
28
+ `;case"submit":return`${t}${_.default.gray(R)} ${_.default.dim(i)}`;case"cancel":return`${t}${_.default.gray(R)} ${_.default.strikethrough(_.default.dim(i??""))}${i?`
29
+ `+_.default.gray(R):""}`;default:return`${t}${_.default.cyan(R)} ${n}
30
+ ${_.default.cyan(D)}
31
+ `}}}).prompt(),p$=(e)=>{let t=e.active??"Yes",n=e.inactive??"No";return new qt({active:t,inactive:n,initialValue:e.initialValue??!0,render(){let i=`${_.default.gray(R)}
32
+ ${Ge(this.state)} ${e.message}
33
+ `,$=this.value?t:n;switch(this.state){case"submit":return`${i}${_.default.gray(R)} ${_.default.dim($)}`;case"cancel":return`${i}${_.default.gray(R)} ${_.default.strikethrough(_.default.dim($))}
34
+ ${_.default.gray(R)}`;default:return`${i}${_.default.cyan(R)} ${this.value?`${_.default.green(Jt)} ${t}`:`${_.default.dim(Wt)} ${_.default.dim(t)}`} ${_.default.dim("/")} ${this.value?`${_.default.dim(Wt)} ${_.default.dim(n)}`:`${_.default.green(Jt)} ${n}`}
35
+ ${_.default.cyan(D)}
36
+ `}}}).prompt()},y$=(e)=>{let t=(i,$)=>{let p=i.label??String(i.value);return $==="active"?`${_.default.green(Jt)} ${p} ${i.hint?_.default.dim(`(${i.hint})`):""}`:$==="selected"?`${_.default.dim(p)}`:$==="cancelled"?`${_.default.strikethrough(_.default.dim(p))}`:`${_.default.dim(Wt)} ${_.default.dim(p)}`},n=0;return new Br({options:e.options,initialValue:e.initialValue,render(){let i=`${_.default.gray(R)}
37
+ ${Ge(this.state)} ${e.message}
38
+ `;switch(this.state){case"submit":return`${i}${_.default.gray(R)} ${t(this.options[this.cursor],"selected")}`;case"cancel":return`${i}${_.default.gray(R)} ${t(this.options[this.cursor],"cancelled")}
39
+ ${_.default.gray(R)}`;default:{let $=e.maxItems===void 0?1/0:Math.max(e.maxItems,5);this.cursor>=n+$-3?n=Math.max(Math.min(this.cursor-$+3,this.options.length-$),0):this.cursor<n+2&&(n=Math.max(this.cursor-2,0));let p=$<this.options.length&&n>0,r=$<this.options.length&&n+$<this.options.length;return`${i}${_.default.cyan(R)} ${this.options.slice(n,n+$).map((y,m,x)=>m===0&&p?_.default.dim("..."):m===x.length-1&&r?_.default.dim("..."):t(y,m+n===this.cursor?"active":"inactive")).join(`
40
+ ${_.default.cyan(R)} `)}
41
+ ${_.default.cyan(D)}
42
+ `}}}}).prompt()},_$=(e)=>{let t=(n,i="inactive")=>{let $=n.label??String(n.value);return i==="selected"?`${_.default.dim($)}`:i==="cancelled"?`${_.default.strikethrough(_.default.dim($))}`:i==="active"?`${_.default.bgCyan(_.default.gray(` ${n.value} `))} ${$} ${n.hint?_.default.dim(`(${n.hint})`):""}`:`${_.default.gray(_.default.bgWhite(_.default.inverse(` ${n.value} `)))} ${$} ${n.hint?_.default.dim(`(${n.hint})`):""}`};return new Kt({options:e.options,initialValue:e.initialValue,render(){let n=`${_.default.gray(R)}
43
+ ${Ge(this.state)} ${e.message}
44
+ `;switch(this.state){case"submit":return`${n}${_.default.gray(R)} ${t(this.options.find((i)=>i.value===this.value),"selected")}`;case"cancel":return`${n}${_.default.gray(R)} ${t(this.options[0],"cancelled")}
45
+ ${_.default.gray(R)}`;default:return`${n}${_.default.cyan(R)} ${this.options.map((i,$)=>t(i,$===this.cursor?"active":"inactive")).join(`
46
+ ${_.default.cyan(R)} `)}
47
+ ${_.default.cyan(D)}
48
+ `}}}).prompt()},m$=(e)=>{let t=(n,i)=>{let $=n.label??String(n.value);return i==="active"?`${_.default.cyan(Tt)} ${$} ${n.hint?_.default.dim(`(${n.hint})`):""}`:i==="selected"?`${_.default.green(Xe)} ${_.default.dim($)}`:i==="cancelled"?`${_.default.strikethrough(_.default.dim($))}`:i==="active-selected"?`${_.default.green(Xe)} ${$} ${n.hint?_.default.dim(`(${n.hint})`):""}`:i==="submitted"?`${_.default.dim($)}`:`${_.default.dim(Tr)} ${_.default.dim($)}`};return new Nr({options:e.options,initialValues:e.initialValues,required:e.required??!0,cursorAt:e.cursorAt,validate(n){if(this.required&&n.length===0)return`Please select at least one option.
49
+ ${_.default.reset(_.default.dim(`Press ${_.default.gray(_.default.bgWhite(_.default.inverse(" space ")))} to select, ${_.default.gray(_.default.bgWhite(_.default.inverse(" enter ")))} to submit`))}`},render(){let n=`${_.default.gray(R)}
50
+ ${Ge(this.state)} ${e.message}
51
+ `;switch(this.state){case"submit":return`${n}${_.default.gray(R)} ${this.options.filter(({value:i})=>this.value.includes(i)).map((i)=>t(i,"submitted")).join(_.default.dim(", "))||_.default.dim("none")}`;case"cancel":{let i=this.options.filter(({value:$})=>this.value.includes($)).map(($)=>t($,"cancelled")).join(_.default.dim(", "));return`${n}${_.default.gray(R)} ${i.trim()?`${i}
52
+ ${_.default.gray(R)}`:""}`}case"error":{let i=this.error.split(`
53
+ `).map(($,p)=>p===0?`${_.default.yellow(D)} ${_.default.yellow($)}`:` ${$}`).join(`
54
+ `);return n+_.default.yellow(R)+" "+this.options.map(($,p)=>{let r=this.value.includes($.value),y=p===this.cursor;return y&&r?t($,"active-selected"):r?t($,"selected"):t($,y?"active":"inactive")}).join(`
55
+ ${_.default.yellow(R)} `)+`
56
56
  `+i+`
57
- `}default:return`${n}${y.default.cyan(N)} ${this.options.map((i,$)=>{let p=this.value.includes(i.value),r=$===this.cursor;return r&&p?t(i,"active-selected"):p?t(i,"selected"):t(i,r?"active":"inactive")}).join(`
58
- ${y.default.cyan(N)} `)}
59
- ${y.default.cyan(a)}
60
- `}}}).prompt()},u$=(e)=>{let t=(n,i,$=[])=>{let p=n.label??String(n.value),r=typeof n.group=="string",m=r&&($[$.indexOf(n)+1]??{group:!0}),_=r&&m.group===!0,x=r?`${_?a:N} `:"";return i==="active"?`${y.default.dim(x)}${y.default.cyan(Tt)} ${p} ${n.hint?y.default.dim(`(${n.hint})`):""}`:i==="group-active"?`${x}${y.default.cyan(Tt)} ${y.default.dim(p)}`:i==="group-active-selected"?`${x}${y.default.green(ce)} ${y.default.dim(p)}`:i==="selected"?`${y.default.dim(x)}${y.default.green(ce)} ${y.default.dim(p)}`:i==="cancelled"?`${y.default.strikethrough(y.default.dim(p))}`:i==="active-selected"?`${y.default.dim(x)}${y.default.green(ce)} ${p} ${n.hint?y.default.dim(`(${n.hint})`):""}`:i==="submitted"?`${y.default.dim(p)}`:`${y.default.dim(x)}${y.default.dim(Tr)} ${y.default.dim(p)}`};return new qt({options:e.options,initialValues:e.initialValues,required:e.required??!0,cursorAt:e.cursorAt,validate(n){if(this.required&&n.length===0)return`Please select at least one option.
61
- ${y.default.reset(y.default.dim(`Press ${y.default.gray(y.default.bgWhite(y.default.inverse(" space ")))} to select, ${y.default.gray(y.default.bgWhite(y.default.inverse(" enter ")))} to submit`))}`},render(){let n=`${y.default.gray(N)}
62
- ${ke(this.state)} ${e.message}
63
- `;switch(this.state){case"submit":return`${n}${y.default.gray(N)} ${this.options.filter(({value:i})=>this.value.includes(i)).map((i)=>t(i,"submitted")).join(y.default.dim(", "))}`;case"cancel":{let i=this.options.filter(({value:$})=>this.value.includes($)).map(($)=>t($,"cancelled")).join(y.default.dim(", "));return`${n}${y.default.gray(N)} ${i.trim()?`${i}
64
- ${y.default.gray(N)}`:""}`}case"error":{let i=this.error.split(`
65
- `).map(($,p)=>p===0?`${y.default.yellow(a)} ${y.default.yellow($)}`:` ${$}`).join(`
66
- `);return`${n}${y.default.yellow(N)} ${this.options.map(($,p,r)=>{let m=this.value.includes($.value)||$.group===!0&&this.isGroupSelected(`${$.value}`),_=p===this.cursor;return!_&&typeof $.group=="string"&&this.options[this.cursor].value===$.group?t($,m?"group-active-selected":"group-active",r):_&&m?t($,"active-selected",r):m?t($,"selected",r):t($,_?"active":"inactive",r)}).join(`
67
- ${y.default.yellow(N)} `)}
57
+ `}default:return`${n}${_.default.cyan(R)} ${this.options.map((i,$)=>{let p=this.value.includes(i.value),r=$===this.cursor;return r&&p?t(i,"active-selected"):p?t(i,"selected"):t(i,r?"active":"inactive")}).join(`
58
+ ${_.default.cyan(R)} `)}
59
+ ${_.default.cyan(D)}
60
+ `}}}).prompt()},x$=(e)=>{let t=(n,i,$=[])=>{let p=n.label??String(n.value),r=typeof n.group=="string",y=r&&($[$.indexOf(n)+1]??{group:!0}),m=r&&y.group===!0,x=r?`${m?D:R} `:"";return i==="active"?`${_.default.dim(x)}${_.default.cyan(Tt)} ${p} ${n.hint?_.default.dim(`(${n.hint})`):""}`:i==="group-active"?`${x}${_.default.cyan(Tt)} ${_.default.dim(p)}`:i==="group-active-selected"?`${x}${_.default.green(Xe)} ${_.default.dim(p)}`:i==="selected"?`${_.default.dim(x)}${_.default.green(Xe)} ${_.default.dim(p)}`:i==="cancelled"?`${_.default.strikethrough(_.default.dim(p))}`:i==="active-selected"?`${_.default.dim(x)}${_.default.green(Xe)} ${p} ${n.hint?_.default.dim(`(${n.hint})`):""}`:i==="submitted"?`${_.default.dim(p)}`:`${_.default.dim(x)}${_.default.dim(Tr)} ${_.default.dim(p)}`};return new ot({options:e.options,initialValues:e.initialValues,required:e.required??!0,cursorAt:e.cursorAt,validate(n){if(this.required&&n.length===0)return`Please select at least one option.
61
+ ${_.default.reset(_.default.dim(`Press ${_.default.gray(_.default.bgWhite(_.default.inverse(" space ")))} to select, ${_.default.gray(_.default.bgWhite(_.default.inverse(" enter ")))} to submit`))}`},render(){let n=`${_.default.gray(R)}
62
+ ${Ge(this.state)} ${e.message}
63
+ `;switch(this.state){case"submit":return`${n}${_.default.gray(R)} ${this.options.filter(({value:i})=>this.value.includes(i)).map((i)=>t(i,"submitted")).join(_.default.dim(", "))}`;case"cancel":{let i=this.options.filter(({value:$})=>this.value.includes($)).map(($)=>t($,"cancelled")).join(_.default.dim(", "));return`${n}${_.default.gray(R)} ${i.trim()?`${i}
64
+ ${_.default.gray(R)}`:""}`}case"error":{let i=this.error.split(`
65
+ `).map(($,p)=>p===0?`${_.default.yellow(D)} ${_.default.yellow($)}`:` ${$}`).join(`
66
+ `);return`${n}${_.default.yellow(R)} ${this.options.map(($,p,r)=>{let y=this.value.includes($.value)||$.group===!0&&this.isGroupSelected(`${$.value}`),m=p===this.cursor;return!m&&typeof $.group=="string"&&this.options[this.cursor].value===$.group?t($,y?"group-active-selected":"group-active",r):m&&y?t($,"active-selected",r):y?t($,"selected",r):t($,m?"active":"inactive",r)}).join(`
67
+ ${_.default.yellow(R)} `)}
68
68
  ${i}
69
- `}default:return`${n}${y.default.cyan(N)} ${this.options.map((i,$,p)=>{let r=this.value.includes(i.value)||i.group===!0&&this.isGroupSelected(`${i.value}`),m=$===this.cursor;return!m&&typeof i.group=="string"&&this.options[this.cursor].value===i.group?t(i,r?"group-active-selected":"group-active",p):m&&r?t(i,"active-selected",p):r?t(i,"selected",p):t(i,m?"active":"inactive",p)}).join(`
70
- ${y.default.cyan(N)} `)}
71
- ${y.default.cyan(a)}
72
- `}}}).prompt()},jt=(e)=>e.replace(q$(),""),h$=(e="",t="")=>{let n=`
69
+ `}default:return`${n}${_.default.cyan(R)} ${this.options.map((i,$,p)=>{let r=this.value.includes(i.value)||i.group===!0&&this.isGroupSelected(`${i.value}`),y=$===this.cursor;return!y&&typeof i.group=="string"&&this.options[this.cursor].value===i.group?t(i,r?"group-active-selected":"group-active",p):y&&r?t(i,"active-selected",p):r?t(i,"selected",p):t(i,y?"active":"inactive",p)}).join(`
70
+ ${_.default.cyan(R)} `)}
71
+ ${_.default.cyan(D)}
72
+ `}}}).prompt()},jt=(e)=>e.replace(S$(),""),b$=(e="",t="")=>{let n=`
73
73
  ${e}
74
74
  `.split(`
75
- `),i=jt(t).length,$=Math.max(n.reduce((r,m)=>(m=jt(m),m.length>r?m.length:r),0),i)+2,p=n.map((r)=>`${y.default.gray(N)} ${y.default.dim(r)}${" ".repeat($-jt(r).length)}${y.default.gray(N)}`).join(`
76
- `);process.stdout.write(`${y.default.gray(N)}
77
- ${y.default.green(Ee)} ${y.default.reset(t)} ${y.default.gray(Rr.repeat(Math.max($-i-1,1))+e$)}
75
+ `),i=jt(t).length,$=Math.max(n.reduce((r,y)=>(y=jt(y),y.length>r?y.length:r),0),i)+2,p=n.map((r)=>`${_.default.gray(R)} ${_.default.dim(r)}${" ".repeat($-jt(r).length)}${_.default.gray(R)}`).join(`
76
+ `);process.stdout.write(`${_.default.gray(R)}
77
+ ${_.default.green(Ue)} ${_.default.reset(t)} ${_.default.gray(Rr.repeat(Math.max($-i-1,1))+li)}
78
78
  ${p}
79
- ${y.default.gray(t$+Rr.repeat($+2)+r$)}
80
- `)},o$=(e="")=>{process.stdout.write(`${y.default.gray(a)} ${y.default.red(e)}
79
+ ${_.default.gray(fi+Rr.repeat($+2)+gi)}
80
+ `)},w$=(e="")=>{process.stdout.write(`${_.default.gray(D)} ${_.default.red(e)}
81
81
 
82
- `)},S$=(e="")=>{process.stdout.write(`${y.default.gray(fi)} ${e}
83
- `)},A$=(e="")=>{process.stdout.write(`${y.default.gray(N)}
84
- ${y.default.gray(a)} ${e}
82
+ `)},h$=(e="")=>{process.stdout.write(`${_.default.gray(ai)} ${e}
83
+ `)},A$=(e="")=>{process.stdout.write(`${_.default.gray(R)}
84
+ ${_.default.gray(D)} ${e}
85
85
 
86
- `)},Ae,k$=()=>{let e=Rt?["◒","◐","◓","◑"]:["•","o","O","0"],t=Rt?80:120,n,i,$=!1,p="",r=(b="")=>{$=!0,n=jr(),p=b.replace(/\.+$/,""),process.stdout.write(`${y.default.gray(N)}
87
- `);let w=0,u=0;i=setInterval(()=>{let k=y.default.magenta(e[w]),j=".".repeat(Math.floor(u)).slice(0,3);process.stdout.write(Je.cursor.move(-999,0)),process.stdout.write(Je.erase.down(1)),process.stdout.write(`${k} ${p}${j}`),w=w+1<e.length?w+1:0,u=u<e.length?u+0.125:0},t)},m=(b="",w=0)=>{p=b??p,$=!1,clearInterval(i);let u=w===0?y.default.green(Ee):w===1?y.default.red(Jr):y.default.red(Wr);process.stdout.write(Je.cursor.move(-999,0)),process.stdout.write(Je.erase.down(1)),process.stdout.write(`${u} ${p}
88
- `),n()},_=(b="")=>{p=b??p},x=(b)=>{let w=b>1?"Something went wrong":"Canceled";$&&m(w,b)};return process.on("uncaughtExceptionMonitor",()=>x(2)),process.on("unhandledRejection",()=>x(2)),process.on("SIGINT",()=>x(1)),process.on("SIGTERM",()=>x(1)),process.on("exit",x),{start:r,stop:m,message:_}},G$=async(e,t)=>{let n={},i=Object.keys(e);for(let $ of i){let p=e[$],r=await p({results:n})?.catch((m)=>{throw m});if(typeof t?.onCancel=="function"&&ve(r)){n[$]="canceled",t.onCancel({results:n});continue}n[$]=r}return n};var de=Pt(()=>{Nt();Nt();y=He(ut(),1),Je=He(bt(),1);Rt=li(),Di=I("◆","*"),Jr=I("■","x"),Wr=I("▲","x"),Ee=I("◇","o"),fi=I("┌","T"),N=I("│","|"),a=I("└","—"),Jt=I("●",">"),Wt=I("○"," "),Tt=I("◻","[•]"),ce=I("◼","[+]"),Tr=I("◻","[ ]"),gi=I("▪","•"),Rr=I("─","-"),e$=I("╮","+"),t$=I("├","+"),r$=I("╯","+"),n$=I("●","•"),i$=I("◆","*"),$$=I("▲","!"),p$=I("■","x"),Ae={message:(e="",{symbol:t=y.default.gray(N)}={})=>{let n=[`${y.default.gray(N)}`];if(e){let[i,...$]=e.split(`
89
- `);n.push(`${t} ${i}`,...$.map((p)=>`${y.default.gray(N)} ${p}`))}process.stdout.write(`${n.join(`
86
+ `)},oe,u$=()=>{let e=Rt?["◒","◐","◓","◑"]:["•","o","O","0"],t=Rt?80:120,n,i,$=!1,p="",r=(b="")=>{$=!0,n=jr(),p=b.replace(/\.+$/,""),process.stdout.write(`${_.default.gray(R)}
87
+ `);let w=0,S=0;i=setInterval(()=>{let q=_.default.magenta(e[w]),o=".".repeat(Math.floor(S)).slice(0,3);process.stdout.write(We.cursor.move(-999,0)),process.stdout.write(We.erase.down(1)),process.stdout.write(`${q} ${p}${o}`),w=w+1<e.length?w+1:0,S=S<e.length?S+0.125:0},t)},y=(b="",w=0)=>{p=b??p,$=!1,clearInterval(i);let S=w===0?_.default.green(Ue):w===1?_.default.red(Jr):_.default.red(Wr);process.stdout.write(We.cursor.move(-999,0)),process.stdout.write(We.erase.down(1)),process.stdout.write(`${S} ${p}
88
+ `),n()},m=(b="")=>{p=b??p},x=(b)=>{let w=b>1?"Something went wrong":"Canceled";$&&y(w,b)};return process.on("uncaughtExceptionMonitor",()=>x(2)),process.on("unhandledRejection",()=>x(2)),process.on("SIGINT",()=>x(1)),process.on("SIGTERM",()=>x(1)),process.on("exit",x),{start:r,stop:y,message:m}},k$=async(e,t)=>{let n={},i=Object.keys(e);for(let $ of i){let p=e[$],r=await p({results:n})?.catch((y)=>{throw y});if(typeof t?.onCancel=="function"&&ve(r)){n[$]="canceled",t.onCancel({results:n});continue}n[$]=r}return n};var Ye=Ot(()=>{Bt();Bt();_=ne(ht(),1),We=ne(bt(),1);Rt=si(),Fi=v("◆","*"),Jr=v("■","x"),Wr=v("▲","x"),Ue=v("◇","o"),ai=v("┌","T"),R=v("│","|"),D=v("└","—"),Jt=v("●",">"),Wt=v("○"," "),Tt=v("◻","[•]"),Xe=v("◼","[+]"),Tr=v("◻","[ ]"),Di=v("▪","•"),Rr=v("─","-"),li=v("╮","+"),fi=v("├","+"),gi=v("╯","+"),e$=v("●","•"),t$=v("◆","*"),r$=v("▲","!"),n$=v("■","x"),oe={message:(e="",{symbol:t=_.default.gray(R)}={})=>{let n=[`${_.default.gray(R)}`];if(e){let[i,...$]=e.split(`
89
+ `);n.push(`${t} ${i}`,...$.map((p)=>`${_.default.gray(R)} ${p}`))}process.stdout.write(`${n.join(`
90
90
  `)}
91
- `)},info:(e)=>{Ae.message(e,{symbol:y.default.blue(n$)})},success:(e)=>{Ae.message(e,{symbol:y.default.green(i$)})},step:(e)=>{Ae.message(e,{symbol:y.default.green(Ee)})},warn:(e)=>{Ae.message(e,{symbol:y.default.yellow($$)})},warning:(e)=>{Ae.warn(e)},error:(e)=>{Ae.message(e,{symbol:y.default.red(p$)})}}});var o={SUCCESS:0,GENERAL:1,USAGE:2,AUTH:3,QUOTA:4,TIMEOUT:5,NETWORK:6,CONTENT_FILTER:10};class S extends Error{exitCode;hint;constructor(e,t=o.GENERAL,n){super(e);this.name="CLIError",this.exitCode=t,this.hint=n}toJSON(){return{error:{code:this.exitCode,message:this.message,...this.hint?{hint:this.hint}:{}}}}}function fe(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function Un(e){let t=e.flag.match(/^--([a-z][a-z0-9-]*)/i);return t?fe(t[1]):null}function sn(e){if(e.type==="boolean")return!0;if(e.type==="string"||e.type==="number"||e.type==="array")return!1;return!e.flag.includes("<")&&!e.flag.includes("[")}function Yt(e){let t=new Set,n=new Set,i=new Set;for(let $ of e){let p=Un($);if(!p)continue;if(sn($))t.add(p);else if($.type==="number")n.add(p);else if($.type==="array")i.add(p)}return{booleans:t,numbers:n,arrays:i}}function Ct(e,t=[]){let n=Yt(t),i=[],$=0;while($<e.length){let p=e[$];if(p==="--")break;if(p.startsWith("--")){let r=p.indexOf("="),m=r!==-1?p.slice(2,r):p.slice(2),_=fe(m);if(!n.booleans.has(_)&&r===-1)$+=2;else $+=1;continue}if(p.startsWith("-")){$++;continue}i.push(p),$++}return i}function ge(e,t){let n=Yt(t),i={quiet:!1,verbose:!1,noColor:!1,yes:!1,dryRun:!1,help:!1,nonInteractive:!1,async:!1},$=0;while($<e.length){let p=e[$];if(p==="--help"||p==="-h"){i.help=!0,$++;continue}if(p==="--")break;if(p.startsWith("--")){let r=p.indexOf("="),m,_;if(r!==-1)m=p.slice(2,r),_=p.slice(r+1);else m=p.slice(2);let x=fe(m);if(n.booleans.has(x)){i[x]=!0,$++;continue}if(_===void 0)$++,_=e[$];if(_===void 0)throw new S(`Flag --${m} requires a value.`,o.USAGE);if(n.arrays.has(x)){let b=i[x];if(b)b.push(_);else i[x]=[_]}else if(n.numbers.has(x))i[x]=Number(_);else i[x]=_}$++}return i}var et={cn:"https://dashscope.aliyuncs.com",us:"https://dashscope-us.aliyuncs.com",intl:"https://dashscope-intl.aliyuncs.com"},Me={cn:"https://help.aliyun.com/zh/model-studio",us:"https://help.aliyun.com/zh/model-studio",intl:"https://help.aliyun.com/zh/model-studio"},Fn=new Set(["cn","us","intl"]),an=new Set(["text","json"]);function Lt(e){if(!e||typeof e!=="object"||Array.isArray(e))return{};let t=e,n={};if(typeof t.api_key==="string")n.api_key=t.api_key;if(typeof t.region==="string"&&Fn.has(t.region))n.region=t.region;if(typeof t.base_url==="string"&&t.base_url.startsWith("http"))n.base_url=t.base_url;if(typeof t.output==="string"&&an.has(t.output))n.output=t.output;if(typeof t.output_dir==="string"&&t.output_dir.length>0)n.output_dir=t.output_dir;if(typeof t.timeout==="number"&&t.timeout>0)n.timeout=t.timeout;if(typeof t.default_text_model==="string"&&t.default_text_model.length>0)n.default_text_model=t.default_text_model;if(typeof t.default_video_model==="string"&&t.default_video_model.length>0)n.default_video_model=t.default_video_model;if(typeof t.default_image_model==="string"&&t.default_image_model.length>0)n.default_image_model=t.default_image_model;if(typeof t.default_speech_model==="string"&&t.default_speech_model.length>0)n.default_speech_model=t.default_speech_model;if(typeof t.default_omni_model==="string"&&t.default_omni_model.length>0)n.default_omni_model=t.default_omni_model;if(typeof t.access_key_id==="string"&&t.access_key_id.length>0)n.access_key_id=t.access_key_id;if(typeof t.access_key_secret==="string"&&t.access_key_secret.length>0)n.access_key_secret=t.access_key_secret;if(typeof t.workspace_id==="string"&&t.workspace_id.length>0)n.workspace_id=t.workspace_id;return n}function q(e){return{name:e.name,description:e.description,usage:e.usage,options:e.options,examples:e.examples,apiDocs:e.apiDocs,execute:e.run}}var ze=[{flag:"--api-key <key>",description:"API key"},{flag:"--region <region>",description:"API region: cn (default), us, intl"},{flag:"--base-url <url>",description:"API base URL"},{flag:"--output <format>",description:"Output format: text, json"},{flag:"--timeout <seconds>",description:"Request timeout",type:"number"},{flag:"--quiet",description:"Suppress non-essential output"},{flag:"--verbose",description:"Print HTTP request/response details"},{flag:"--no-color",description:"Disable ANSI colors"},{flag:"--dry-run",description:"Dry run mode"},{flag:"--non-interactive",description:"Disable interactive prompts"},{flag:"--concurrent <n>",description:"Run N parallel requests (default: 1)",type:"number"},{flag:"--help",description:"Show help"},{flag:"--version",description:"Print version"}];async function L(e){if(e.apiKey)return{token:e.apiKey,method:"api-key",source:"flag"};if(e.fileApiKey)return{token:e.fileApiKey,method:"api-key",source:"config.json"};throw new S("No credentials found.",o.AUTH,`Log in: bl auth login --api-key sk-xxxxx
91
+ `)},info:(e)=>{oe.message(e,{symbol:_.default.blue(e$)})},success:(e)=>{oe.message(e,{symbol:_.default.green(t$)})},step:(e)=>{oe.message(e,{symbol:_.default.green(Ue)})},warn:(e)=>{oe.message(e,{symbol:_.default.yellow(r$)})},warning:(e)=>{oe.warn(e)},error:(e)=>{oe.message(e,{symbol:_.default.red(n$)})}}});var h={SUCCESS:0,GENERAL:1,USAGE:2,AUTH:3,QUOTA:4,TIMEOUT:5,NETWORK:6,CONTENT_FILTER:10};class u extends Error{exitCode;hint;constructor(e,t=h.GENERAL,n){super(e);this.name="CLIError",this.exitCode=t,this.hint=n}toJSON(){return{error:{code:this.exitCode,message:this.message,...this.hint?{hint:this.hint}:{}}}}}function fe(e){return e.replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function In(e){let t=e.flag.match(/^--([a-z][a-z0-9-]*)/i);return t?fe(t[1]):null}function vn(e){if(e.type==="boolean")return!0;if(e.type==="string"||e.type==="number"||e.type==="array")return!1;return!e.flag.includes("<")&&!e.flag.includes("[")}function ct(e){let t=new Set,n=new Set,i=new Set;for(let $ of e){let p=In($);if(!p)continue;if(vn($))t.add(p);else if($.type==="number")n.add(p);else if($.type==="array")i.add(p)}return{booleans:t,numbers:n,arrays:i}}function Ct(e,t=[]){let n=ct(t),i=[],$=0;while($<e.length){let p=e[$];if(p==="--")break;if(p.startsWith("--")){let r=p.indexOf("="),y=r!==-1?p.slice(2,r):p.slice(2),m=fe(y);if(!n.booleans.has(m)&&r===-1)$+=2;else $+=1;continue}if(p.startsWith("-")){$++;continue}i.push(p),$++}return i}function ge(e,t){let n=ct(t),i={quiet:!1,verbose:!1,noColor:!1,yes:!1,dryRun:!1,help:!1,nonInteractive:!1,async:!1},$=0;while($<e.length){let p=e[$];if(p==="--help"||p==="-h"){i.help=!0,$++;continue}if(p==="--")break;if(p.startsWith("--")){let r=p.indexOf("="),y,m;if(r!==-1)y=p.slice(2,r),m=p.slice(r+1);else y=p.slice(2);let x=fe(y);if(n.booleans.has(x)){i[x]=!0,$++;continue}if(m===void 0)$++,m=e[$];if(m===void 0)throw new u(`Flag --${y} requires a value.`,h.USAGE);if(n.arrays.has(x)){let b=i[x];if(b)b.push(m);else i[x]=[m]}else if(n.numbers.has(x)){let b=Number(m);if(!Number.isFinite(b))throw new u(`Flag --${y} requires a finite number.`,h.USAGE);i[x]=b}else i[x]=m}$++}return i}var et={cn:"https://dashscope.aliyuncs.com",us:"https://dashscope-us.aliyuncs.com",intl:"https://dashscope-intl.aliyuncs.com"},Qe={cn:"https://help.aliyun.com/zh/model-studio",us:"https://help.aliyun.com/zh/model-studio",intl:"https://help.aliyun.com/zh/model-studio"},Un=new Set(["cn","us","intl"]),dn=new Set(["text","json"]);function Lt(e){if(!e||typeof e!=="object"||Array.isArray(e))return{};let t=e,n={};if(typeof t.api_key==="string")n.api_key=t.api_key;if(typeof t.region==="string"&&Un.has(t.region))n.region=t.region;if(typeof t.base_url==="string"&&t.base_url.startsWith("http"))n.base_url=t.base_url;if(typeof t.output==="string"&&dn.has(t.output))n.output=t.output;if(typeof t.output_dir==="string"&&t.output_dir.length>0)n.output_dir=t.output_dir;if(typeof t.timeout==="number"&&t.timeout>0)n.timeout=t.timeout;if(typeof t.default_text_model==="string"&&t.default_text_model.length>0)n.default_text_model=t.default_text_model;if(typeof t.default_video_model==="string"&&t.default_video_model.length>0)n.default_video_model=t.default_video_model;if(typeof t.default_image_model==="string"&&t.default_image_model.length>0)n.default_image_model=t.default_image_model;if(typeof t.default_speech_model==="string"&&t.default_speech_model.length>0)n.default_speech_model=t.default_speech_model;if(typeof t.default_omni_model==="string"&&t.default_omni_model.length>0)n.default_omni_model=t.default_omni_model;if(typeof t.access_key_id==="string"&&t.access_key_id.length>0)n.access_key_id=t.access_key_id;if(typeof t.access_key_secret==="string"&&t.access_key_secret.length>0)n.access_key_secret=t.access_key_secret;if(typeof t.workspace_id==="string"&&t.workspace_id.length>0)n.workspace_id=t.workspace_id;return n}function K(e){return{name:e.name,description:e.description,usage:e.usage,options:e.options,examples:e.examples,apiDocs:e.apiDocs,execute:e.run}}var Oe=[{flag:"--api-key <key>",description:"API key"},{flag:"--region <region>",description:"API region: cn (default), us, intl"},{flag:"--base-url <url>",description:"API base URL"},{flag:"--output <format>",description:"Output format: text, json"},{flag:"--timeout <seconds>",description:"Request timeout",type:"number"},{flag:"--quiet",description:"Suppress non-essential output"},{flag:"--verbose",description:"Print HTTP request/response details"},{flag:"--no-color",description:"Disable ANSI colors"},{flag:"--dry-run",description:"Dry run mode"},{flag:"--non-interactive",description:"Disable interactive prompts"},{flag:"--concurrent <n>",description:"Run N parallel requests (default: 1)",type:"number"},{flag:"--help",description:"Show help"},{flag:"--version",description:"Print version"}];async function V(e){if(e.apiKey)return{token:e.apiKey,method:"api-key",source:"flag"};if(e.fileApiKey)return{token:e.fileApiKey,method:"api-key",source:"config.json"};if(process.env.DASHSCOPE_API_KEY)return{token:process.env.DASHSCOPE_API_KEY,method:"api-key",source:"DASHSCOPE_API_KEY"};throw new u("No credentials found.",h.AUTH,`Log in: bl auth login --api-key sk-xxxxx
92
92
  Pass directly: --api-key sk-xxxxx
93
93
  Set env var: export DASHSCOPE_API_KEY=sk-xxxxx
94
- Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`)}function tt(e,t,n){let i=t.error?.message||t.message||`HTTP ${e}`,$=t.error?.type||t.code;if(e===401||e===403||$==="InvalidApiKey"||$==="Unauthorized")return new S(`API key rejected (HTTP ${e}). ${i}`,o.AUTH,`Check status: bailian auth status
94
+ Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`)}function tt(e,t,n){let i=t.error?.message||t.message||`HTTP ${e}`,$=t.error?.type||t.code;if(e===401||e===403||$==="InvalidApiKey"||$==="Unauthorized")return new u(`API key rejected (HTTP ${e}). ${i}`,h.AUTH,`Check status: bailian auth status
95
95
  Re-authenticate: bailian auth login --api-key sk-xxxxx
96
- Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`);if(e===429||$==="Throttling"||$==="Throttling.RateQuota"||$==="Throttling.AllocationQuota")return new S(`Rate limit or quota exceeded. ${i}`,o.QUOTA,`Please wait and retry, or check your DashScope quota at
97
- https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`);if(e===408||e===504)return new S(`Request timed out (HTTP ${e}).`,o.TIMEOUT,"Try increasing --timeout or retry later.");if($==="InvalidParameter"||$==="BadRequest")return new S(`Invalid parameter: ${i}`,o.USAGE);if($==="ModelNotFound"||$==="AccessDenied")return new S(`Model access denied or not found: ${i}`,o.AUTH,"Check model availability at https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key");if($==="DataInspectionFailed")return new S(`Content flagged by safety filter: ${i}`,o.CONTENT_FILTER);return new S(`API error: ${i} (HTTP ${e}${$?`, code: ${$}`:""})`,o.GENERAL)}import{homedir as Vt}from"os";function g(e){return e.length>8?`${e.slice(0,4)}...${e.slice(-4)}`:"***"}var vt=!1;var ee="\x1B[0m",ye="\x1B[2m",ln="\x1B[1m",Dn="\x1B[38;2;43;82;255m",fn="\x1B[38;2;147;51;234m",gn="\x1B[38;2;6;184;212m",ei="\x1B[38;2;236;72;153m";function ti(e){return e.startsWith(Vt())?e.replace(Vt(),"~"):e}function Oe(e,t,n){if(e.quiet||vt||!process.stderr.isTTY)return;vt=!0;let i=e.configPath?ti(e.configPath):"~/.bailian/config.json",$=e.fileRegion?`${e.fileRegion} (file)`:"cn (default)",p=e.apiKey?"(flag)":"(file)",r=g(t),m=n?` ${ye}|${ee} ${ye}Model:${ee} ${fn}${n}${ee}`:"";process.stderr.write(`${ln}${Dn}BAILIAN${ee} ${ye}${i}${ee} ${ye}|${ee} ${ye}Region:${ee} ${gn}${$}${ee} ${ye}|${ee} ${ye}Key:${ee} ${ei}${r}${ee} ${ye}${p}${ee}${m}
98
- `)}var ri={t1:"public",t2:""},rt=JSON.stringify({channel:"bailian-cli",tags:ri});function d(){return{"x-dashscope-source-config":rt}}async function pe(e,t){let n=typeof FormData<"u"&&t.body instanceof FormData,i="0.1.0",$={"User-Agent":"bailian-cli/0.1.0",...d(),...t.headers};if(!n&&!$["Content-Type"])$["Content-Type"]="application/json";if(t.async)$["X-DashScope-Async"]="enable";if(t.ossResolve)$["X-DashScope-OssResourceResolve"]="enable";if(!t.noAuth){let _=await L(e);if($.Authorization=`Bearer ${_.token}`,e.verbose)process.stderr.write(`> ${t.method??"GET"} ${t.url}
99
- `),process.stderr.write(`> Auth: ${_.token.slice(0,8)}...
96
+ Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`);if(e===429||$==="Throttling"||$==="Throttling.RateQuota"||$==="Throttling.AllocationQuota")return new u(`Rate limit or quota exceeded. ${i}`,h.QUOTA,`Please wait and retry, or check your DashScope quota at
97
+ https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`);if(e===408||e===504)return new u(`Request timed out (HTTP ${e}).`,h.TIMEOUT,"Try increasing --timeout or retry later.");if($==="InvalidParameter"||$==="BadRequest")return new u(`Invalid parameter: ${i}`,h.USAGE);if($==="ModelNotFound"||$==="AccessDenied")return new u(`Model access denied or not found: ${i}`,h.AUTH,"Check model availability at https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key");if($==="DataInspectionFailed")return new u(`Content flagged by safety filter: ${i}`,h.CONTENT_FILTER);return new u(`API error: ${i} (HTTP ${e}${$?`, code: ${$}`:""})`,h.GENERAL)}import{homedir as Vt}from"os";function g(e){return e.length>8?`${e.slice(0,4)}...${e.slice(-4)}`:"***"}var Et=!1;var ee="\x1B[0m",xe="\x1B[2m",sn="\x1B[1m",Fn="\x1B[38;2;43;82;255m",an="\x1B[38;2;147;51;234m",Dn="\x1B[38;2;6;184;212m",ln="\x1B[38;2;236;72;153m";function fn(e){return e.startsWith(Vt())?e.replace(Vt(),"~"):e}function ce(e,t,n){if(e.quiet||Et||!process.stderr.isTTY)return;Et=!0;let i=e.configPath?fn(e.configPath):"~/.bailian/config.json",$=e.fileRegion?`${e.fileRegion} (file)`:"cn (default)",p=e.apiKey?"(flag)":"(file)",r=g(t),y=n?` ${xe}|${ee} ${xe}Model:${ee} ${an}${n}${ee}`:"";process.stderr.write(`${sn}${Fn}BAILIAN${ee} ${xe}${i}${ee} ${xe}|${ee} ${xe}Region:${ee} ${Dn}${$}${ee} ${xe}|${ee} ${xe}Key:${ee} ${ln}${r}${ee} ${xe}${p}${ee}${y}
98
+ `)}var gn={t1:"public",t2:""},rt=JSON.stringify({channel:"bailian-cli",tags:gn});function d(){return{"x-dashscope-source-config":rt}}async function ye(e,t){let n=typeof FormData<"u"&&t.body instanceof FormData,i="0.1.2-beta.0",$={"User-Agent":"bailian-cli/0.1.2-beta.0",...d(),...t.headers};if(!n&&!$["Content-Type"])$["Content-Type"]="application/json";if(t.async)$["X-DashScope-Async"]="enable";if(t.ossResolve)$["X-DashScope-OssResourceResolve"]="enable";if(!t.noAuth){let m=await V(e);if($.Authorization=`Bearer ${m.token}`,e.verbose)process.stderr.write(`> ${t.method??"GET"} ${t.url}
99
+ `),process.stderr.write(`> Auth: ${m.token.slice(0,8)}...
100
100
  `),process.stderr.write(`> x-dashscope-source-config: ${rt}
101
- `);let x=t.body&&typeof t.body==="object"&&"model"in t.body?String(t.body.model):void 0;Oe(e,_.token,x)}let p=(t.timeout??e.timeout)*1000,r=await fetch(t.url,{method:t.method??"GET",headers:$,body:t.body?n?t.body:JSON.stringify(t.body):void 0,signal:AbortSignal.timeout(p)}),m=r.headers.get("x-request-id");if(e.verbose)process.stderr.write(`< ${r.status} ${r.statusText}
102
- `);if(m&&!e.quiet)process.stderr.write(`request_id: ${m}
103
- `);if(!r.ok){let _={};try{_=await r.json()}catch{}throw tt(r.status,_,t.url)}return r}async function W(e,t){let n=await pe(e,t),i;try{i=await n.json()}catch{let $=n.headers.get("content-type")||"";throw new S(`API returned non-JSON response (${$||"unknown type"}). Server may be experiencing issues.`,o.GENERAL)}if(i.code&&typeof i.code==="string"&&i.code!=="200"&&i.code!=="Success")throw tt(200,{error:{message:i.message,type:i.code}},t.url);return i}var Xe="https://registry.npmjs.org",Ke="bailian-cli";function _e(e){return`${e}/compatible-mode/v1/chat/completions`}function Et(e){return`${e}/api/v1/services/aigc/image-generation/generation`}function Pe(e){return`${e}/api/v1/services/aigc/multimodal-generation/generation`}function Ne(e){return`${e}/api/v1/services/aigc/video-generation/video-synthesis`}function F(e,t){return`${e}/api/v1/tasks/${t}`}function nt(e,t){return`${e}/api/v1/apps/${t}/completion`}function it(e){return`${e}/api/v2/apps/memory/add`}function $t(e){return`${e}/api/v2/apps/memory/memory_nodes/search`}function It(e){return`${e}/api/v2/apps/memory/memory_nodes`}function Qe(e,t){return`${e}/api/v2/apps/memory/memory_nodes/${t}`}function dt(e){return`${e}/api/v1/services/aigc/multimodal-generation/generation`}function Ut(e){return`${e}/api/v1/services/audio/asr/transcription`}function pt(e){return`${e}/api/v2/apps/memory/profile_schemas`}function st(e,t){return`${e}/api/v2/apps/memory/profile_schemas/${t}/profiles`}function Ft(e){return`${e}/api/v1/mcps/WebSearch/mcp`}function at(e){if(e===null||e===void 0)return"";if(typeof e==="string")return e;if(typeof e==="number"||typeof e==="boolean")return String(e);if(Array.isArray(e)){if(e.length===0)return"(empty)";if(typeof e[0]==="object"&&e[0]!==null)return ni(e);return e.map(String).join(`
104
- `)}if(typeof e==="object")return mt(e);return String(e)}function mt(e,t=0){let n=" ".repeat(t),i=[];for(let[$,p]of Object.entries(e)){if(p===null||p===void 0)continue;if(Array.isArray(p)){i.push(`${n}${$}:`);for(let r of p)if(typeof r==="object"&&r!==null)i.push(`${n} - ${mt(r,t+4).trimStart()}`);else i.push(`${n} - ${String(r)}`)}else if(typeof p==="object")i.push(`${n}${$}:`),i.push(mt(p,t+2));else i.push(`${n}${$}: ${String(p)}`)}return i.join(`
105
- `)}function ni(e){if(e.length===0)return"(empty)";let t=Object.keys(e[0]),n=t.map((r)=>Math.max(r.length,...e.map((m)=>String(m[r]??"").length))),i=t.map((r,m)=>r.toUpperCase().padEnd(n[m])).join(" "),$=n.map((r)=>"-".repeat(r)).join(" "),p=e.map((r)=>t.map((m,_)=>String(r[m]??"").padEnd(n[_])).join(" "));return[i,$,...p].join(`
106
- `)}function lt(e){return JSON.stringify(e,null,2)}function B(e){if(e==="json"||e==="text")return e;if(!process.stdout.isTTY)return"json";return"text"}function ii(e,t){switch(t){case"json":return lt(e);case"text":return at(e)}}function h(e,t){process.stdout.write(ii(e,t)+`
107
- `)}function G(e){process.stdout.write(e+`
108
- `)}import{homedir as $i}from"os";import{join as Dt}from"path";var pi=".bailian";function je(){if(process.env.BAILIAN_CONFIG_DIR)return process.env.BAILIAN_CONFIG_DIR;return Dt($i(),pi)}function re(){return Dt(je(),"config.json")}async function yt(){let e=je();await(await import("fs/promises")).mkdir(e,{recursive:!0,mode:448})}import{readFileSync as mi,writeFileSync as yi,renameSync as _i,existsSync as xi}from"fs";function ne(){let e=re();if(!xi(e))return{};try{return Lt(JSON.parse(mi(e,"utf-8")))}catch(t){let n=t;if(n instanceof SyntaxError||n.message.includes("JSON"))process.stderr.write(`Warning: config file is corrupted. Run 'bl config set' to reset.
109
- `);return{}}}async function Re(e){await yt();let t=re(),n=t+".tmp";yi(n,JSON.stringify(e,null,2)+`
110
- `,{mode:384}),_i(n,t)}function _t(e){let t=ne(),n=e.apiKey||void 0,i=t.api_key,$=e.region||process.env.DASHSCOPE_REGION||void 0,p=t.region,r=$||p||"cn",m=e.baseUrl||process.env.DASHSCOPE_BASE_URL||t.base_url||et[r]||et.cn,_=B(e.output||process.env.DASHSCOPE_OUTPUT||t.output),x=process.env.DASHSCOPE_TIMEOUT?Number(process.env.DASHSCOPE_TIMEOUT):void 0,b=x!==void 0&&Number.isFinite(x)&&x>0?x:void 0,w=e.timeout??b??t.timeout??300;return{apiKey:n,fileApiKey:i,fileRegion:t.region,configPath:re(),region:r,baseUrl:m,output:_,outputDir:t.output_dir||void 0,timeout:w,defaultTextModel:t.default_text_model,defaultVideoModel:t.default_video_model,defaultImageModel:t.default_image_model,defaultSpeechModel:t.default_speech_model,defaultOmniModel:t.default_omni_model,accessKeyId:process.env.ALIBABA_CLOUD_ACCESS_KEY_ID||t.access_key_id||void 0,accessKeySecret:process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET||t.access_key_secret||void 0,workspaceId:process.env.BAILIAN_WORKSPACE_ID||t.workspace_id||void 0,verbose:e.verbose||process.env.DASHSCOPE_VERBOSE==="1",quiet:e.quiet||!1,noColor:e.noColor||process.env.NO_COLOR!==void 0||!process.stdout.isTTY,yes:e.yes||!1,dryRun:e.dryRun||!1,nonInteractive:e.nonInteractive||!1,async:e.async||!1}}function O(e){if(e?.nonInteractive===!0)return!1;if(process.env.CI)return!1;return process.stdout.isTTY===!0&&process.stdin.isTTY===!0}var Mr=q({name:"auth login",description:"Authenticate with API key",usage:"bl auth login --api-key <key>",options:[{flag:"--api-key <key>",description:"DashScope API key to store"}],examples:["bl auth login --api-key sk-xxxxx"],async run(e,t){let n=process.env.DASHSCOPE_API_KEY;if(n&&!t.apiKey){let $=g(n);if(O({nonInteractive:e.nonInteractive})){let{confirm:p}=await Promise.resolve().then(() => (de(),Ie));if(!await p({message:`Detected DASHSCOPE_API_KEY in environment (${$}).
101
+ `);let x=t.body&&typeof t.body==="object"&&"model"in t.body?String(t.body.model):void 0;ce(e,m.token,x)}let p=(t.timeout??e.timeout)*1000,r=await fetch(t.url,{method:t.method??"GET",headers:$,body:t.body?n?t.body:JSON.stringify(t.body):void 0,signal:AbortSignal.timeout(p)}),y=r.headers.get("x-request-id");if(e.verbose)process.stderr.write(`< ${r.status} ${r.statusText}
102
+ `);if(y&&!e.quiet)process.stderr.write(`request_id: ${y}
103
+ `);if(!r.ok){let m={};try{m=await r.json()}catch{}throw tt(r.status,m,t.url)}return r}async function Q(e,t){let n=await ye(e,t),i;try{i=await n.json()}catch{let $=n.headers.get("content-type")||"";throw new u(`API returned non-JSON response (${$||"unknown type"}). Server may be experiencing issues.`,h.GENERAL)}if(i.code&&typeof i.code==="string"&&i.code!=="200"&&i.code!=="Success")throw tt(200,{error:{message:i.message,type:i.code}},t.url);return i}var He="https://registry.npmjs.org",Be="bailian-cli";function be(e){return`${e}/compatible-mode/v1/chat/completions`}function It(e){return`${e}/api/v1/services/aigc/image-generation/generation`}function Ce(e){return`${e}/api/v1/services/aigc/multimodal-generation/generation`}function je(e){return`${e}/api/v1/services/aigc/video-generation/video-synthesis`}function a(e,t){return`${e}/api/v1/tasks/${t}`}function nt(e,t){return`${e}/api/v1/apps/${t}/completion`}function it(e){return`${e}/api/v2/apps/memory/add`}function $t(e){return`${e}/api/v2/apps/memory/memory_nodes/search`}function vt(e){return`${e}/api/v2/apps/memory/memory_nodes`}function Ze(e,t){return`${e}/api/v2/apps/memory/memory_nodes/${t}`}function Ut(e){return`${e}/api/v1/services/audio/tts/SpeechSynthesizer`}function dt(e){return`${e}/api/v1/services/audio/asr/transcription`}function pt(e){return`${e}/api/v2/apps/memory/profile_schemas`}function st(e,t){return`${e}/api/v2/apps/memory/profile_schemas/${t}/profiles`}function Ft(e){return`${e}/api/v1/mcps/WebSearch/mcp`}function at(e){if(e===null||e===void 0)return"";if(typeof e==="string")return e;if(typeof e==="number"||typeof e==="boolean")return String(e);if(Array.isArray(e)){if(e.length===0)return"(empty)";if(typeof e[0]==="object"&&e[0]!==null)return ei(e);return e.map(String).join(`
104
+ `)}if(typeof e==="object")return yt(e);return String(e)}function yt(e,t=0){let n=" ".repeat(t),i=[];for(let[$,p]of Object.entries(e)){if(p===null||p===void 0)continue;if(Array.isArray(p)){i.push(`${n}${$}:`);for(let r of p)if(typeof r==="object"&&r!==null)i.push(`${n} - ${yt(r,t+4).trimStart()}`);else i.push(`${n} - ${String(r)}`)}else if(typeof p==="object")i.push(`${n}${$}:`),i.push(yt(p,t+2));else i.push(`${n}${$}: ${String(p)}`)}return i.join(`
105
+ `)}function ei(e){if(e.length===0)return"(empty)";let t=Object.keys(e[0]),n=t.map((r)=>Math.max(r.length,...e.map((y)=>String(y[r]??"").length))),i=t.map((r,y)=>r.toUpperCase().padEnd(n[y])).join(" "),$=n.map((r)=>"-".repeat(r)).join(" "),p=e.map((r)=>t.map((y,m)=>String(r[y]??"").padEnd(n[m])).join(" "));return[i,$,...p].join(`
106
+ `)}function Dt(e){return JSON.stringify(e,null,2)}function B(e){if(e==="json"||e==="text")return e;if(!process.stdout.isTTY)return"json";return"text"}function ti(e,t){switch(t){case"json":return Dt(e);case"text":return at(e)}}function A(e,t){process.stdout.write(ti(e,t)+`
107
+ `)}function N(e){process.stdout.write(e+`
108
+ `)}import{homedir as ri}from"os";import{join as lt}from"path";var ni=".bailian";function Re(){if(process.env.BAILIAN_CONFIG_DIR)return process.env.BAILIAN_CONFIG_DIR;return lt(ri(),ni)}function ie(){return lt(Re(),"config.json")}async function _t(){let e=Re();await(await import("fs/promises")).mkdir(e,{recursive:!0,mode:448})}import{readFileSync as ii,writeFileSync as $i,renameSync as pi,existsSync as yi}from"fs";function te(){let e=ie();if(!yi(e))return{};try{return Lt(JSON.parse(ii(e,"utf-8")))}catch(t){let n=t;if(n instanceof SyntaxError||n.message.includes("JSON"))process.stderr.write(`Warning: config file is corrupted. Run 'bl config set' to reset.
109
+ `);return{}}}async function Je(e){await _t();let t=ie(),n=t+".tmp";$i(n,JSON.stringify(e,null,2)+`
110
+ `,{mode:384}),pi(n,t)}function mt(e){let t=te(),n=e.apiKey||void 0,i=t.api_key,$=e.region||process.env.DASHSCOPE_REGION||void 0,p=t.region,r=$||p||"cn",y=e.baseUrl||process.env.DASHSCOPE_BASE_URL||t.base_url||et[r]||et.cn,m=B(e.output||process.env.DASHSCOPE_OUTPUT||t.output),x=process.env.DASHSCOPE_TIMEOUT?Number(process.env.DASHSCOPE_TIMEOUT):void 0,b=x!==void 0&&Number.isFinite(x)&&x>0?x:void 0,w=e.timeout??b??t.timeout??300;if(!Number.isFinite(w)||w<=0)throw new u("Timeout must be a positive finite number.",h.USAGE);return{apiKey:n,fileApiKey:i,fileRegion:t.region,configPath:ie(),region:r,baseUrl:y,output:m,outputDir:t.output_dir||void 0,timeout:w,defaultTextModel:t.default_text_model,defaultVideoModel:t.default_video_model,defaultImageModel:t.default_image_model,defaultSpeechModel:t.default_speech_model,defaultOmniModel:t.default_omni_model,accessKeyId:process.env.ALIBABA_CLOUD_ACCESS_KEY_ID||t.access_key_id||void 0,accessKeySecret:process.env.ALIBABA_CLOUD_ACCESS_KEY_SECRET||t.access_key_secret||void 0,workspaceId:process.env.BAILIAN_WORKSPACE_ID||t.workspace_id||void 0,verbose:e.verbose||process.env.DASHSCOPE_VERBOSE==="1",quiet:e.quiet||!1,noColor:e.noColor||process.env.NO_COLOR!==void 0||!process.stdout.isTTY,yes:e.yes||!1,dryRun:e.dryRun||!1,nonInteractive:e.nonInteractive||!1,async:e.async||!1}}function Y(e){if(e?.nonInteractive===!0)return!1;if(process.env.CI)return!1;return process.stdout.isTTY===!0&&process.stdin.isTTY===!0}var Mr=K({name:"auth login",description:"Authenticate with API key",usage:"bl auth login --api-key <key>",options:[{flag:"--api-key <key>",description:"DashScope API key to store"}],examples:["bl auth login --api-key sk-xxxxx"],async run(e,t){let n=process.env.DASHSCOPE_API_KEY;if(n&&!t.apiKey){let $=g(n);if(Y({nonInteractive:e.nonInteractive})){let{confirm:p}=await Promise.resolve().then(() => (Ye(),Pe));if(!await p({message:`Detected DASHSCOPE_API_KEY in environment (${$}).
111
111
  You are already authenticated via env.
112
112
  Do you still want to configure local persistent credentials?`,initialValue:!1}))process.stdout.write(`Login skipped. Using environment variables.
113
113
  `),process.exit(0)}else process.stderr.write(`Warning: DASHSCOPE_API_KEY is already set in environment.
114
- `)}let i=t.apiKey||e.apiKey;if(!i)throw new S("--api-key is required.",o.USAGE,"bl auth login --api-key sk-xxxxx");if(!e.dryRun){process.stderr.write("Testing key... ");try{let w={...e,apiKey:i};await W(w,{url:_e(w.baseUrl),method:"POST",body:{model:"qwen3.6-plus",messages:[{role:"user",content:"hi"}],max_tokens:1}}),process.stderr.write(`Valid
115
- `)}catch{throw new S("API key validation failed.",o.AUTH,`Check that your key is valid.
116
- Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`)}let $=ne();$.api_key=i,await Re($),process.stderr.write(`API key saved to ${re()}
114
+ `)}let i=t.apiKey||e.apiKey;if(!i)throw new u("--api-key is required.",h.USAGE,"bl auth login --api-key sk-xxxxx");if(!e.dryRun){process.stderr.write("Testing key... ");try{let w={...e,apiKey:i};await Q(w,{url:be(w.baseUrl),method:"POST",body:{model:"qwen3.6-plus",messages:[{role:"user",content:"hi"}],max_tokens:1}}),process.stderr.write(`Valid
115
+ `)}catch{throw new u("API key validation failed.",h.AUTH,`Check that your key is valid.
116
+ Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`)}let $=te();$.api_key=i,await Je($),process.stderr.write(`API key saved to ${ie()}
117
117
 
118
118
  `);let p=g(i);process.stderr.write(`To make the key available to all tools in this shell, run:
119
119
 
@@ -123,150 +123,167 @@ Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliwa
123
123
 
124
124
  `),process.stderr.write(` echo 'export DASHSCOPE_API_KEY=${p}' >> ~/.zshrc
125
125
 
126
- `);let r=process.stderr.isTTY,m=r?"\x1B[38;2;147;51;234m":"",_=r?"\x1B[36m":"",x=r?"\x1B[2m":"",b=r?"\x1B[0m":"";process.stderr.write(`${m}You're all set!${b} Here are some things to try:
126
+ `);let r=process.stderr.isTTY,y=r?"\x1B[38;2;147;51;234m":"",m=r?"\x1B[36m":"",x=r?"\x1B[2m":"",b=r?"\x1B[0m":"";process.stderr.write(`${y}You're all set!${b} Here are some things to try:
127
127
 
128
- `),process.stderr.write(`${_}▸ Direct CLI usage:${b}
128
+ `),process.stderr.write(`${m}▸ Direct CLI usage:${b}
129
129
  `),process.stderr.write(` bl text chat --message "用中文写一首关于春天的诗"
130
130
  `),process.stderr.write(` bl image generate --prompt "A cat in space suit, digital art"
131
131
  `),process.stderr.write(` bl speech synthesize --text "你好世界" --voice zhiyan
132
132
 
133
- `),process.stderr.write(`${_}▸ In AI coding assistant ${x}(Qoder / Cursor / Claude Code / ...)${b}${_}, just say:${b}
133
+ `),process.stderr.write(`${m}▸ In AI coding assistant ${x}(Qoder / Cursor / Claude Code / ...)${b}${m}, just say:${b}
134
134
  `),process.stderr.write(` 帮我生成一套鸭舌帽的亚马逊电商主图(白底 + 场景图 + 模特上身图)
135
135
  `),process.stderr.write(` 帮我生成一段 3 分钟的幽默相声音频
136
136
  `),process.stderr.write(` 帮我生成一套小红帽故事绘本 PDF(含插图)
137
137
  `),process.stderr.write(` 帮我分析这个视频的内容并写一篇小红书文案
138
138
 
139
- `)}else G("Would validate and save API key.")}});var Qr=q({name:"auth status",description:"Show current authentication state",usage:"bl auth status",examples:["bl auth status","bl auth status --output json"],async run(e,t){try{let n=await L(e),i=B(e.output);if(i!=="text"){let $={method:n.method,source:n.source,key:g(n.token)};h($,i);return}G("Authentication Status:"),G(` Method: ${n.method}`),G(` Source: ${n.source}`),G(` Key: ${g(n.token)}`)}catch{let n=B(e.output);h({authenticated:!1,message:"Not authenticated.",hint:`Run: bailian auth login --api-key sk-xxxxx
139
+ `)}else N("Would validate and save API key.")}});var Qr=K({name:"auth status",description:"Show current authentication state",usage:"bl auth status",examples:["bl auth status","bl auth status --output json"],async run(e,t){try{let n=await V(e),i=B(e.output);if(i!=="text"){let $={method:n.method,source:n.source,key:g(n.token)};A($,i);return}N("Authentication Status:"),N(` Method: ${n.method}`),N(` Source: ${n.source}`),N(` Key: ${g(n.token)}`)}catch{let n=B(e.output);A({authenticated:!1,message:"Not authenticated.",hint:`Run: bailian auth login --api-key sk-xxxxx
140
140
  Or set $DASHSCOPE_API_KEY
141
- Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`},n)}}});import{readFileSync as Zr,writeFileSync as B$,renameSync as K$,existsSync as cr}from"fs";function Hr(){let e=re();if(!cr(e))return null;try{let t=Zr(e,"utf-8"),n=JSON.parse(t);if(typeof n.api_key==="string"&&n.api_key.length>0)return n.api_key;return null}catch{return null}}async function zr(){let e=re();if(!cr(e))return;try{let t=JSON.parse(Zr(e,"utf-8"));delete t.api_key;let n=e+".tmp";B$(n,JSON.stringify(t,null,2)+`
142
- `,{mode:384}),K$(n,e)}catch{}}var Or=q({name:"auth logout",description:"Clear stored credentials",usage:"bl auth logout [--yes] [--dry-run]",options:[{flag:"--yes",description:"Skip confirmation prompt"}],examples:["bl auth logout","bl auth logout --dry-run","bl auth logout --yes"],async run(e,t){let n=!!Hr();if(e.dryRun){if(n)G("Would clear api_key from ~/.bailian/config.json");else G("No credentials to clear.");G("No changes made.");return}if(n)await zr(),process.stderr.write(`Cleared api_key from ~/.bailian/config.json
141
+ Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`},n)}}});import{readFileSync as Hr,writeFileSync as q$,renameSync as o$,existsSync as Zr}from"fs";function zr(){let e=ie();if(!Zr(e))return null;try{let t=Hr(e,"utf-8"),n=JSON.parse(t);if(typeof n.api_key==="string"&&n.api_key.length>0)return n.api_key;return null}catch{return null}}async function Xr(){let e=ie();if(!Zr(e))return;try{let t=JSON.parse(Hr(e,"utf-8"));delete t.api_key;let n=e+".tmp";q$(n,JSON.stringify(t,null,2)+`
142
+ `,{mode:384}),o$(n,e)}catch{}}var Pr=K({name:"auth logout",description:"Clear stored credentials",usage:"bl auth logout [--yes] [--dry-run]",options:[{flag:"--yes",description:"Skip confirmation prompt"}],examples:["bl auth logout","bl auth logout --dry-run","bl auth logout --yes"],async run(e,t){let n=!!zr();if(e.dryRun){if(n)N("Would clear api_key from ~/.bailian/config.json");else N("No credentials to clear.");N("No changes made.");return}if(n)await Xr(),process.stderr.write(`Cleared api_key from ~/.bailian/config.json
143
143
  `);else process.stderr.write(`No credentials to clear.
144
- `)}});async function*we(e){let t=e.body?.getReader();if(!t)return;let n=new TextDecoder,i="";try{while(!0){let{done:$,value:p}=await t.read();if($)break;i+=n.decode(p,{stream:!0});let r=i.split(`
145
- `);i=r.pop()||"";let m={};for(let _ of r){if(_===""){if(m.data!==void 0)yield{data:m.data,event:m.event,id:m.id};m={};continue}if(_.startsWith(":"))continue;let x=_.indexOf(":");if(x===-1)continue;let b=_.slice(0,x),w=_.slice(x+1).trimStart();switch(b){case"data":m.data=m.data!==void 0?`${m.data}
146
- ${w}`:w;break;case"event":m.event=w;break;case"id":m.id=w;break}}}if(i.trim()&&i.includes("data:")){let $=i.indexOf(":");if($!==-1)yield{data:i.slice($+1).trimStart()}}}finally{t.releaseLock()}}import{readFileSync as Mt}from"fs";async function V(e){if(!O())return;let{defaultValue:t,message:n}=e,$=await(await Promise.resolve().then(() => (de(),Ie))).text({message:n,default:t,placeholder:t});if(typeof $==="symbol")return;return $}async function Xr(e){if(!O())return;let{message:t}=e,i=await(await Promise.resolve().then(() => (de(),Ie))).confirm({message:t});if(typeof i==="symbol")return;return i}function R(e,t){throw new S(`Missing required argument: --${e}
144
+ `)}});async function*Ae(e){let t=e.body?.getReader();if(!t)return;let n=new TextDecoder,i="";try{while(!0){let{done:$,value:p}=await t.read();if($)break;i+=n.decode(p,{stream:!0});let r=i.split(`
145
+ `);i=r.pop()||"";let y={};for(let m of r){if(m===""){if(y.data!==void 0)yield{data:y.data,event:y.event,id:y.id};y={};continue}if(m.startsWith(":"))continue;let x=m.indexOf(":");if(x===-1)continue;let b=m.slice(0,x),w=m.slice(x+1).trimStart();switch(b){case"data":y.data=y.data!==void 0?`${y.data}
146
+ ${w}`:w;break;case"event":y.event=w;break;case"id":y.id=w;break}}}if(i.trim()&&i.includes("data:")){let $=i.indexOf(":");if($!==-1)yield{data:i.slice($+1).trimStart()}}}finally{t.releaseLock()}}import{readFileSync as Mt}from"fs";async function L(e){if(!Y())return;let{defaultValue:t,message:n}=e,$=await(await Promise.resolve().then(() => (Ye(),Pe))).text({message:n,default:t,placeholder:t});if(typeof $==="symbol")return;return $}async function Yr(e){if(!Y())return;let{message:t}=e,i=await(await Promise.resolve().then(() => (Ye(),Pe))).confirm({message:t});if(typeof i==="symbol")return;return i}async function Or(e){if(!Y())return;let{message:t,choices:n,defaultValue:i}=e,p=await(await Promise.resolve().then(() => (Ye(),Pe))).select({message:t,initialValue:i,options:n});if(typeof p==="symbol")return;return p}function W(e,t){throw new u(`Missing required argument: --${e}
147
147
  Hint: In non-interactive (CI / agent) environments all required flags must be provided.
148
- In an interactive terminal, run without --${e} and the CLI will prompt for it.`,o.USAGE,t)}function N$(e){let t=[],n;if(e.system)n=e.system;if(e.messagesFile){let i=e.messagesFile,$=i==="-"?Mt("/dev/stdin","utf-8"):Mt(i,"utf-8"),p=JSON.parse($);for(let r of p)if(r.role==="system")n=typeof r.content==="string"?r.content:"";else t.push(r)}if(e.message){let i=new Set(["system","user","assistant"]),$=e.message;for(let p of $){let r=p.indexOf(":"),m=r!==-1?p.slice(0,r):"";if(i.has(m)){let _=p.slice(r+1);if(m==="system")n=_;else t.push({role:m,content:_})}else t.push({role:"user",content:p})}}return{system:n,messages:t}}var Pr=q({name:"text chat",description:"Send a chat completion (OpenAI compatible, DashScope)",apiDocs:"/compatibility-of-openai-with-dashscope",usage:"bl text chat --message <text> [flags]",options:[{flag:"--model <model>",description:"Model ID (default: qwen3.6-plus)"},{flag:"--message <text>",description:"Message text (repeatable, prefix role: to set role)",required:!0,type:"array"},{flag:"--messages-file <path>",description:"JSON file with messages array (use - for stdin)"},{flag:"--system <text>",description:"System prompt"},{flag:"--max-tokens <n>",description:"Maximum tokens to generate (default: 4096)",type:"number"},{flag:"--temperature <n>",description:"Sampling temperature (0.0, 2.0]",type:"number"},{flag:"--top-p <n>",description:"Nucleus sampling threshold",type:"number"},{flag:"--stream",description:"Stream response tokens (default: on in TTY)"},{flag:"--tool <json-or-path>",description:"Tool definition as JSON or file path (repeatable)",type:"array"},{flag:"--enable-thinking",description:"Enable thinking/reasoning mode (for qwen3/qwq models)"},{flag:"--thinking-budget <n>",description:"Max tokens for thinking (default: 4096)",type:"number"}],examples:['bl text chat --message "What is Qwen?"','bl text chat --model qwen-max --system "You are a coding assistant." --message "Write fizzbuzz in Python"','bl text chat --message "Hello" --message "assistant:Hi!" --message "How are you?"',"cat conversation.json | bl text chat --messages-file - --stream",'bl text chat --message "Hello" --output json','bl text chat --model qwq-plus --message "Solve 1+1" --enable-thinking'],async run(e,t){let{system:n,messages:i}=N$(t),$=i;if($.length===0)if(O({nonInteractive:e.nonInteractive})){let w=await V({message:"Enter your message:"});if(!w)process.stderr.write(`Chat cancelled.
149
- `),process.exit(1);$=[{role:"user",content:w}]}else R("message","bl text chat --message <text>");let p=t.model||e.defaultTextModel||"qwen3.6-plus",r=t.stream===!0||t.stream===void 0&&process.stdout.isTTY,m=B(e.output),_=[];if(n)_.push({role:"system",content:n});_.push(...$);let x={model:p,messages:_,max_tokens:t.maxTokens??4096,stream:r};if(t.temperature!==void 0)x.temperature=t.temperature;if(t.topP!==void 0)x.top_p=t.topP;if(t.enableThinking){if(x.enable_thinking=!0,t.thinkingBudget!==void 0)x.thinking_budget=t.thinkingBudget}if(t.tool){let w=t.tool.map((u)=>{try{return JSON.parse(u)}catch{let k=Mt(u,"utf-8");return JSON.parse(k)}});x.tools=w}if(e.dryRun){h({request:x},m);return}let b=_e(e.baseUrl);if(r){let w=await pe(e,{url:b,method:"POST",body:x,stream:!0}),u="",k=!1,j=e.noColor?"":"\x1B[2m",A=e.noColor?"":"\x1B[0m",Z=process.stdout.isTTY?process.stdout:process.stderr,X=process.stdout;for await(let H of we(w)){if(H.data==="[DONE]")break;try{let Q=JSON.parse(H.data);for(let T of Q.choices){let z=T.delta;if(z.reasoning_content){if(!k)k=!0,Z.write(`${j}Thinking:
150
- `);Z.write(z.reasoning_content)}if(z.content){if(k)Z.write(`${A}
148
+ In an interactive terminal, run without --${e} and the CLI will prompt for it.`,h.USAGE,t)}function G$(e){let t=[],n;if(e.system)n=e.system;if(e.messagesFile){let i=e.messagesFile,$=i==="-"?Mt("/dev/stdin","utf-8"):Mt(i,"utf-8"),p=JSON.parse($);for(let r of p)if(r.role==="system")n=typeof r.content==="string"?r.content:"";else t.push(r)}if(e.message){let i=new Set(["system","user","assistant"]),$=e.message;for(let p of $){let r=p.indexOf(":"),y=r!==-1?p.slice(0,r):"";if(i.has(y)){let m=p.slice(r+1);if(y==="system")n=m;else t.push({role:y,content:m})}else t.push({role:"user",content:p})}}return{system:n,messages:t}}var cr=K({name:"text chat",description:"Send a chat completion (OpenAI compatible, DashScope)",apiDocs:"/compatibility-of-openai-with-dashscope",usage:"bl text chat --message <text> [flags]",options:[{flag:"--model <model>",description:"Model ID (default: qwen3.6-plus)"},{flag:"--message <text>",description:"Message text (repeatable, prefix role: to set role)",required:!0,type:"array"},{flag:"--messages-file <path>",description:"JSON file with messages array (use - for stdin)"},{flag:"--system <text>",description:"System prompt"},{flag:"--max-tokens <n>",description:"Maximum tokens to generate (default: 4096)",type:"number"},{flag:"--temperature <n>",description:"Sampling temperature (0.0, 2.0]",type:"number"},{flag:"--top-p <n>",description:"Nucleus sampling threshold",type:"number"},{flag:"--stream",description:"Stream response tokens (default: on in TTY)"},{flag:"--tool <json-or-path>",description:"Tool definition as JSON or file path (repeatable)",type:"array"},{flag:"--enable-thinking",description:"Enable thinking/reasoning mode (for qwen3/qwq models)"},{flag:"--thinking-budget <n>",description:"Max tokens for thinking (default: 4096)",type:"number"}],examples:['bl text chat --message "What is Qwen?"','bl text chat --model qwen-max --system "You are a coding assistant." --message "Write fizzbuzz in Python"','bl text chat --message "Hello" --message "assistant:Hi!" --message "How are you?"',"cat conversation.json | bl text chat --messages-file - --stream",'bl text chat --message "Hello" --output json','bl text chat --model qwq-plus --message "Solve 1+1" --enable-thinking'],async run(e,t){let{system:n,messages:i}=G$(t),$=i;if($.length===0)if(Y({nonInteractive:e.nonInteractive})){let w=await L({message:"Enter your message:"});if(!w)process.stderr.write(`Chat cancelled.
149
+ `),process.exit(1);$=[{role:"user",content:w}]}else W("message","bl text chat --message <text>");let p=t.model||e.defaultTextModel||"qwen3.6-plus",r=t.stream===!0||t.stream===void 0&&process.stdout.isTTY,y=B(e.output),m=[];if(n)m.push({role:"system",content:n});m.push(...$);let x={model:p,messages:m,max_tokens:t.maxTokens??4096,stream:r};if(t.temperature!==void 0)x.temperature=t.temperature;if(t.topP!==void 0)x.top_p=t.topP;if(t.enableThinking){if(x.enable_thinking=!0,t.thinkingBudget!==void 0)x.thinking_budget=t.thinkingBudget}if(t.tool){let w=t.tool.map((S)=>{try{return JSON.parse(S)}catch{let q=Mt(S,"utf-8");return JSON.parse(q)}});x.tools=w}if(e.dryRun){A({request:x},y);return}let b=be(e.baseUrl);if(r){let w=await ye(e,{url:b,method:"POST",body:x,stream:!0}),S="",q=!1,o=y==="text",k=e.noColor?"":"\x1B[2m",G=e.noColor?"":"\x1B[0m",z=process.stdout.isTTY,J=y==="json"?process.stderr:z?process.stdout:process.stderr,Z=process.stdout;for await(let j of Ae(w)){if(j.data==="[DONE]")break;try{let T=JSON.parse(j.data);for(let X of T.choices){let U=X.delta;if(U.reasoning_content){if(o&&!q)q=!0,J.write(`${k}Thinking:
150
+ `);if(o)J.write(U.reasoning_content)}if(U.content){if(o&&q)J.write(`${G}
151
151
 
152
152
  Response:
153
- `),k=!1;u+=z.content,X.write(z.content)}}}catch{}}if(k)Z.write(A);if(X.write(`
154
- `),m==="json")h({content:u},m)}else{let w=await W(e,{url:b,method:"POST",body:x}),u=w.choices?.[0]?.message?.content??"";if(e.quiet||m==="text")G(u);else h(w,m)}}});import{writeFileSync as H$}from"fs";import{existsSync as j$,mkdirSync as R$}from"fs";import{join as Yr}from"path";import{homedir as J$}from"os";var W$=()=>Yr(J$(),"bailian-output");function l(e,t){let n=t?.flagDir||e.outputDir||W$(),i=t?.subDir?Yr(n,t.subDir):n;if(!j$(i))R$(i,{recursive:!0});return i}import{existsSync as Cr,readFileSync as T$,statSync as M$}from"fs";import{basename as Lr}from"path";var Q$="https://dashscope.aliyuncs.com/api/v1/uploads";async function Z$(e,t){let n=`${Q$}?action=getPolicy&model=${encodeURIComponent(t)}`,i=await fetch(n,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json",...d()},signal:AbortSignal.timeout(15000)});if(!i.ok){let p=await i.text().catch(()=>"");throw new S(`Failed to get upload policy (HTTP ${i.status}): ${p}`,o.GENERAL)}return(await i.json()).data}async function c$(e,t,n){let i=Lr(t),$=`${e.upload_dir}/${i}`,p=T$(t),r=new FormData;r.append("OSSAccessKeyId",e.oss_access_key_id),r.append("Signature",e.signature),r.append("policy",e.policy),r.append("x-oss-object-acl",e.x_oss_object_acl),r.append("x-oss-forbid-overwrite",e.x_oss_forbid_overwrite),r.append("key",$),r.append("success_action_status","200"),r.append("file",new Blob([p]),i);let m=await fetch(e.upload_host,{method:"POST",headers:{...d()},body:r,signal:AbortSignal.timeout(120000)});if(!m.ok){let _=await m.text().catch(()=>"");throw new S(`Failed to upload file to OSS (HTTP ${m.status}): ${_}`,o.GENERAL)}return`oss://${$}`}async function Qt(e){let{apiKey:t,model:n,filePath:i,quiet:$=!1}=e;if(!Cr(i))throw new S(`File not found: ${i}`,o.USAGE);let p=M$(i);if(!p.isFile())throw new S(`Not a file: ${i}`,o.USAGE);if(!$){let _=(p.size/1048576).toFixed(1);process.stderr.write(`Uploading ${Lr(i)} (${_} MB) for model ${n}...
155
- `)}let r=await Z$(t,n),m=await c$(r,i,$);if(!$)process.stderr.write(`Upload complete: ${m}
156
- `);return m}function Ue(e){if(e.startsWith("http://")||e.startsWith("https://"))return!1;if(e.startsWith("oss://"))return!1;if(e.startsWith("data:"))return!1;return Cr(e)}async function v(e,t,n,i){if(!Ue(e))return e;return Qt({apiKey:t,model:n,filePath:e,quiet:i})}var z$=["Chelsie","Cherry","Ethan","Serena","Tina"];function O$(e){let t=Buffer.alloc(44);return t.write("RIFF",0),t.writeUInt32LE(36+e,4),t.write("WAVE",8),t.write("fmt ",12),t.writeUInt32LE(16,16),t.writeUInt16LE(1,20),t.writeUInt16LE(1,22),t.writeUInt32LE(24000,24),t.writeUInt32LE(48000,28),t.writeUInt16LE(2,32),t.writeUInt16LE(16,34),t.write("data",36),t.writeUInt32LE(e,40),t}var Vr=q({name:"omni",description:"Multimodal chat with text + audio output (Qwen-Omni)",apiDocs:"/model-studio/qwen-omni",usage:"bl omni --message <text> [flags]",options:[{flag:"--message <text>",description:"Message text (repeatable, prefix role: to set role)",required:!0,type:"array"},{flag:"--model <model>",description:"Model ID (default: qwen3.5-omni-plus)"},{flag:"--system <text>",description:"System prompt"},{flag:"--image <url>",description:"Image URL or local file (repeatable)",type:"array"},{flag:"--audio <url>",description:"Audio URL or local file (repeatable)",type:"array"},{flag:"--video <url>",description:"Video file URL / local path, or comma-separated frame URLs",type:"array"},{flag:"--voice <voice>",description:`Output voice (default: Cherry). Options: ${z$.join(", ")}`},{flag:"--audio-format <fmt>",description:"Audio output format (default: wav)"},{flag:"--audio-out <path>",description:"Save audio to file (default: auto-generate)"},{flag:"--text-only",description:"Output text only, no audio generation"},{flag:"--max-tokens <n>",description:"Maximum tokens to generate",type:"number"},{flag:"--temperature <n>",description:"Sampling temperature (0.0, 2.0]",type:"number"}],examples:['bl omni --message "你好,你是谁?"','bl omni --message "描述这张图片" --image ./photo.jpg','bl omni --message "这段音频在说什么?" --audio https://example.com/audio.wav','bl omni --message "总结这个视频" --video https://example.com/video.mp4','bl omni --message "这个视频讲了什么" --video ./local-video.mp4 --text-only','bl omni --message "用四川话回答:今天天气怎么样" --voice Serena','bl omni --message "Hello" --text-only --output json','bl omni --message "朗读这段话" --audio-out greeting.wav'],async run(e,t){let n=[];if(t.message)n=t.message;if(n.length===0)if(O({nonInteractive:e.nonInteractive})){let J=await V({message:"Enter your message:"});if(!J)process.stderr.write(`Omni chat cancelled.
157
- `),process.exit(1);n=[J]}else R("message","bl text omni --message <text>");let i=t.model||e.defaultOmniModel||"qwen3.5-omni-plus",$=t.voice||"Cherry",p=t.audioFormat||"wav",r=t.textOnly===!0,m=B(e.output),_=[];if(t.system)_.push({role:"system",content:t.system});let x=new Set(["system","user","assistant"]);for(let J of n){let P=J.indexOf(":"),c=P!==-1?J.slice(0,P):"";if(x.has(c)){let E=J.slice(P+1);if(c==="system")_.push({role:"system",content:E});else _.push({role:c,content:E})}else _.push({role:"user",content:J})}let b=t.image||[],w=t.audio||[],u=t.video||[],k=!1,j=[],A=[],K=[];if(b.length>0||w.length>0||u.length>0){let J=await L(e);for(let P of b){let c=await v(P,J.token,i,e.quiet);if(c.startsWith("oss://"))k=!0;j.push(c)}for(let P of w){let c=await v(P,J.token,i,e.quiet);if(c.startsWith("oss://"))k=!0;A.push(c)}for(let P of u)if(P.includes(",")){let c=P.split(",").map((E)=>E.trim()).filter(Boolean);for(let E of c){let Be=await v(E,J.token,i,e.quiet);if(Be.startsWith("oss://"))k=!0;K.push(`frame:${Be}`)}}else{let c=await v(P,J.token,i,e.quiet);if(c.startsWith("oss://"))k=!0;K.push(c)}}if(j.length>0||A.length>0||K.length>0){for(let J=_.length-1;J>=0;J--)if(_[J].role==="user"){let P=_[J].content,c=[];if(typeof P==="string")c.push({type:"text",text:P});else if(Array.isArray(P))c.push(...P);for(let f of j)c.push({type:"image_url",image_url:{url:f}});for(let f of A)c.push({type:"audio_url",audio_url:{url:f}});let E=K.filter((f)=>f.startsWith("frame:")).map((f)=>f.slice(6)),Be=K.filter((f)=>!f.startsWith("frame:"));if(E.length>0)c.push({type:"video",video:E});for(let f of Be)c.push({type:"video_url",video_url:{url:f}});_[J]={role:"user",content:c};break}}let X={model:i,messages:_,stream:!0,stream_options:{include_usage:!0}};if(!r)X.modalities=["text","audio"],X.audio={voice:$,format:p};if(t.maxTokens!==void 0)X.max_tokens=t.maxTokens;if(t.temperature!==void 0)X.temperature=t.temperature;if(e.dryRun){h({request:X},m);return}if(!e.quiet){let J=r?"text-only":`text+audio, voice: ${$}`;process.stderr.write(`[Model: ${i}] [${J}]
158
- `)}let H=_e(e.baseUrl),Q=await pe(e,{url:H,method:"POST",body:X,stream:!0,ossResolve:k}),T="",z="",D=process.stdout.isTTY,Y=process.stdout;for await(let J of we(Q)){if(J.data==="[DONE]")break;try{let P=JSON.parse(J.data);for(let c of P.choices){let E=c.delta;if(E.content){if(T+=E.content,D)Y.write(E.content)}if(E.audio?.data)z+=E.audio.data}}catch{}}if(D&&T)Y.write(`
159
- `);let M;if(z&&!r){let J=Buffer.from(z,"base64"),P=O$(J.length),c=Buffer.concat([P,J]),E=t.audioOut;if(!E){let{join:Be}=await import("path"),f=l(e,{subDir:"omni"}),zn=Date.now();E=Be(f,`omni_${zn}.wav`)}if(H$(E,c),M=E,!e.quiet)process.stderr.write(`Audio saved: ${E}
160
- `)}if(!D||m==="json"){let J={content:T};if(M)J.audio_saved=M,J.voice=$;h(J,m)}}});var vr=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];function se(e){let t=process.stderr.isTTY,n=0,i=null,$=e;return{start(){if(!t)return;i=setInterval(()=>{process.stderr.write(`\r${vr[n%vr.length]} ${$}`),n++},80)},update(p){$=p},stop(p){if(i)clearInterval(i),i=null;if(t){if(process.stderr.write("\r\x1B[K"),p)process.stderr.write(`${p}
161
- `)}}}}function Er(e,t=""){let n=process.stderr.isTTY,i=30;return{update($){if(!n)return;let p=Math.min(1,$/e),r=Math.round(30*p),m=30-r,_="█".repeat(r)+"░".repeat(m),x=`${Math.round(p*100)}%`;process.stderr.write(`\r${t} ${_} ${x}`)},finish(){if(n)process.stderr.write(`
162
- `)}}}async function $e(e,t){let n=Date.now()+t.timeoutSec*1000,i=se("Polling...");if(!e.quiet)i.start();try{while(Date.now()<n){let $=await W(e,{url:t.url});if(t.getStatus&&!e.quiet)i.update(`Status: ${t.getStatus($)}`);if(t.isComplete($))return i.stop("Done."),$;if(t.isFailed($)){if(i.stop("Failed."),e.verbose)process.stderr.write(`[verbose] Task response: ${JSON.stringify($,null,2)}
163
- `);let p=t.getErrorMessage?.($);throw new S(p?`Task failed: ${p}`:"Task failed.",o.GENERAL,p?void 0:"Use --verbose to see full API response details.")}await new Promise((p)=>setTimeout(p,t.intervalSec*1000))}}finally{i.stop()}throw new S("Polling timed out.",o.TIMEOUT,"Try increasing --timeout or check task status manually.")}import{createWriteStream as X$,unlinkSync as P$}from"fs";async function U(e,t,n){let i=await fetch(e,{headers:d()});if(!i.ok)throw new S(`Download failed: HTTP ${i.status}`,o.GENERAL);let $=Number(i.headers.get("content-length")||0),p=i.body?.getReader();if(!p)throw new S("No response body",o.GENERAL);let r=X$(t),m=$>0&&!n?.quiet?Er($,"Downloading"):null,_=0,x=!1;try{let b=new Promise((w,u)=>{r.on("error",u)});while(!0){let{done:w,value:u}=await Promise.race([p.read(),b]);if(w)break;if(!r.write(u))await new Promise((j)=>r.once("drain",j));_+=u.byteLength,m?.update(_)}x=!0}finally{if(p.releaseLock(),m?.finish(),await new Promise((b,w)=>{r.on("finish",b),r.on("error",w),r.end()}),!x)try{P$(t)}catch{}}return{size:_}}function ue(e){if(e<1024)return`${e} B`;if(e<1048576)return`${(e/1024).toFixed(1)} KB`;if(e<1073741824)return`${(e/1048576).toFixed(1)} MB`;return`${(e/1073741824).toFixed(1)} GB`}import{join as dr}from"path";function he(e){let t=e.concurrent;return Math.max(1,t??1)}async function me(e,t,n,i="requests"){if(e<=1)return[await n(0)];if(!t.quiet)process.stderr.write(`[Concurrent: ${e} ${i}]
164
- `);let $=Array.from({length:e},(p,r)=>n(r));return Promise.all($)}async function We(e,t,n){return Promise.all(e.map(({url:i,destPath:$})=>t(i,$,n).then(()=>$)))}function Ir(e,t){return e.normalize("NFKC").replace(/[\\/:*?"<>|]/g,"_").replace(/\s+/g,"_").replace(/_+/g,"_").replace(/^_+|_+$/g,"")||t}function Fe(e,t){let n=Ir(e||"image","image"),i=Ir((t||"").substring(0,20),"untitled");return`${n}_${i}_${Date.now()}`}var Y$=["qwen-image-2.0","qwen-image-max"];function C$(e){return Y$.some((t)=>e.startsWith(t))}var L$={"16:9":"2688*1536","9:16":"1536*2688","1:1":"2048*2048","4:3":"2368*1728","3:4":"1728*2368"},V$={"16:9":"1664*928","4:3":"1472*1104","1:1":"1328*1328","3:4":"1104*1472","9:16":"928*1664"};function v$(e,t){let i=(t?L$:V$)[e];if(i)return i;return e}var Ur=q({name:"image generate",description:"Generate images (Qwen-Image / wan2.x)",apiDocs:"/best-practice/wanx/text-to-image",usage:"bl image generate --prompt <text> [flags]",options:[{flag:"--prompt <text>",description:"Image description",required:!0},{flag:"--model <model>",description:"Model ID (default: qwen-image-2.0)"},{flag:"--size <W*H>",description:"Image size: ratio (3:4, 16:9, 1:1) or pixels (2048*2048)"},{flag:"--n <count>",description:"Number of images per request (default: 1, max: 6)",type:"number"},{flag:"--seed <n>",description:"Random seed for reproducible generation",type:"number"},{flag:"--negative-prompt <text>",description:"Negative prompt to exclude unwanted content"},{flag:"--prompt-extend",description:"Automatically extend prompt for better results (default: true for qwen-image)"},{flag:"--no-prompt-extend",description:"Disable prompt extend"},{flag:"--watermark",description:"Add watermark to generated images"},{flag:"--no-wait",description:"Return task ID immediately without waiting (async models only)"},{flag:"--out-dir <dir>",description:"Download images to directory"},{flag:"--out-prefix <prefix>",description:"Filename prefix (default: image)"},{flag:"--poll-interval <seconds>",description:"Polling interval when waiting (default: 3)",type:"number"}],examples:['bl image generate --prompt "一只穿太空服的猫在火星上"','bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/','bl image generate --prompt "Mountain landscape" --size 2688*1536','bl image generate --prompt "A castle" --seed 42 --no-prompt-extend','bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet','bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro','bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel'],async run(e,t){let n=t.prompt??t._positional?.[0];if(!n)if(O({nonInteractive:e.nonInteractive})){let k=await V({message:"Enter your image prompt:"});if(!k)process.stderr.write(`Image generation cancelled.
165
- `),process.exit(1);n=k}else R("prompt","bl image generate --prompt <text>");let i=t.model||e.defaultImageModel||"qwen-image-2.0",$=C$(i),p=$?"1:1":"1:1",r=t.size||p,m=v$(r,$),_=t.n??1,x=he(t),b;if(t.noPromptExtend===!0)b=!1;else if(t.promptExtend===!0)b=!0;else if($)b=!0;let w={model:i,input:{messages:[{role:"user",content:[{text:n}]}]},parameters:{size:m,n:_,seed:t.seed,prompt_extend:b,watermark:t.watermark===!0?!0:void 0,negative_prompt:t.negativePrompt||void 0}},u=B(e.output);if(e.dryRun){h({request:w,mode:$?"sync":"async"},u);return}if(!e.quiet)process.stderr.write(`[Model: ${i}] [Mode: ${$?"sync":"async"}]
166
- `);if($)await E$(e,i,w,t,u,x);else await I$(e,i,w,t,u,x)}});async function E$(e,t,n,i,$,p){let r=Pe(e.baseUrl),_=(await me(p,e,()=>W(e,{url:r,method:"POST",body:n}))).flatMap((x)=>x.output.choices||[]).flatMap((x)=>x.message?.content||[]).map((x)=>x.image).filter(Boolean);if(_.length===0)throw new S("Generation completed but no images returned.",o.GENERAL);await sr(_,i,e,$)}async function I$(e,t,n,i,$,p){let r=Et(e.baseUrl),_=(await me(p,e,()=>W(e,{url:r,method:"POST",body:n,async:!0}),"tasks")).map((k)=>k.output.task_id);if(i.noWait||e.async){h({task_ids:_},$);return}let x=i.pollInterval??3,b=_.map((k)=>{let j=F(e.baseUrl,k);return $e(e,{url:j,intervalSec:x,timeoutSec:e.timeout,isComplete:(A)=>A.output.task_status==="SUCCEEDED",isFailed:(A)=>A.output.task_status==="FAILED",getStatus:(A)=>A.output.task_status,getErrorMessage:(A)=>{let K=A.output;return K.message||K.code||void 0}})}),w=await Promise.all(b),u=[];for(let k of w){if(k.output.choices){let j=k.output.choices.flatMap((A)=>A.message?.content||[]).map((A)=>A.image).filter(Boolean);u.push(...j)}if(k.output.results){let j=k.output.results.map((A)=>A.url).filter(Boolean);if(j.length>0&&u.length===0)u.push(...j)}}if(u.length===0)throw new S("All tasks completed but no images returned.",o.GENERAL);await sr(u,i,e,$,_.length===1?_[0]:void 0,_)}async function sr(e,t,n,i,$,p){let r=l(n,{flagDir:t.outDir,subDir:t.outDir?void 0:"images"}),m=t.prompt||t._positional?.[0]||"",_=t.outPrefix||Fe("image",m),x=e.length>1?e.map((w,u)=>{let k=`${_}_${String(u+1).padStart(3,"0")}.png`;return{url:w,destPath:dr(r,k)}}):[{url:e[0],destPath:dr(r,`${_}.png`)}],b=await We(x,U,{quiet:n.quiet});if(n.quiet)G(b.join(`
167
- `));else{let w={urls:e,saved:b,total:e.length};if($)w.task_id=$;if(p&&p.length>1)w.task_ids=p;h(w,i)}}import{join as Fr}from"path";function Te(e){for(let t of Object.keys(e))if(e[t]===void 0)delete e[t];return e}var d$={"16:9":"2688*1536","9:16":"1536*2688","1:1":"2048*2048","4:3":"2368*1728","3:4":"1728*2368"};function U$(e){if(!e)return;return d$[e]??e}var ar=q({name:"image edit",description:"Edit an existing image with text instructions (Qwen-Image)",apiDocs:"/developer-reference/qwen-image-edit-api",usage:"bl image edit --image <url> --prompt <text> [flags]",options:[{flag:"--image <url>",description:"Source image URL or local file path (repeatable for multi-image merge)",required:!0,type:"array"},{flag:"--prompt <text>",description:"Edit instruction text",required:!0},{flag:"--model <model>",description:"Model ID (default: qwen-image-2.0)"},{flag:"--size <W*H>",description:"Output image size: ratio (3:4, 16:9) or pixels (2048*2048)"},{flag:"--n <count>",description:"Number of images (default: 1, max: 6)",type:"number"},{flag:"--seed <n>",description:"Random seed for reproducible results",type:"number"},{flag:"--negative-prompt <text>",description:"Negative prompt to exclude unwanted content"},{flag:"--prompt-extend",description:"Enable prompt smart rewrite (default: true)"},{flag:"--no-prompt-extend",description:"Disable prompt extend"},{flag:"--watermark",description:"Add watermark to output images"},{flag:"--out-dir <dir>",description:"Download images to directory"},{flag:"--out-prefix <prefix>",description:"Filename prefix (default: edited)"}],examples:['bl image edit --image ./photo.png --prompt "把背景换成海滩"','bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3','bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"','bl image edit --image https://example.com/photo.png --prompt "Remove the person" --model qwen-image-2.0-pro'],async run(e,t){let n=[];if(Array.isArray(t.image))n=t.image;else if(typeof t.image==="string")n=[t.image];if(n.length===0)R("image","bl image edit --image <url> --prompt <text>");let i=t.prompt;if(!i)if(O({nonInteractive:e.nonInteractive})){let T=await V({message:"Enter your edit instruction:"});if(!T)process.stderr.write(`Image editing cancelled.
168
- `),process.exit(1);i=T}else R("prompt","bl image edit --image <url> --prompt <text>");let $=t.model||e.defaultImageModel||"qwen-image-2.0",p=await L(e),r=await Promise.all(n.map((T)=>v(T,p.token,$,e.quiet))),m=r.some((T)=>T.startsWith("oss://")),_=t.n??1,x;if(t.noPromptExtend===!0)x=!1;else if(t.promptExtend===!0)x=!0;else x=!0;let b=r.map((T)=>({image:T}));b.push({text:i});let w={model:$,input:{messages:[{role:"user",content:b}]},parameters:{size:U$(t.size)||void 0,n:_,seed:t.seed,prompt_extend:x,watermark:t.watermark===!0?!0:void 0,negative_prompt:t.negativePrompt||void 0}};Te(w.parameters);let u=B(e.output);if(e.dryRun){h({request:w},u);return}if(!e.quiet)process.stderr.write(`[Model: ${$}] [Mode: sync] [Images: ${r.length}]
169
- `);let k=Pe(e.baseUrl),j=he(t),K=(await me(j,e,()=>W(e,{url:k,method:"POST",body:w,ossResolve:m}))).flatMap((T)=>T.output.choices||[]).flatMap((T)=>T.message?.content||[]).map((T)=>T.image).filter(Boolean);if(K.length===0)throw new S("Edit completed but no images returned.",o.GENERAL);let Z=l(e,{flagDir:t.outDir,subDir:t.outDir?void 0:"images"}),X=t.outPrefix||Fe("edited",t?.prompt),H=K.length>1?K.map((T,z)=>{let D=`${X}_${String(z+1).padStart(3,"0")}.png`;return{url:T,destPath:Fr(Z,D)}}):[{url:K[0],destPath:Fr(Z,`${X}.png`)}],Q=await We(H,U,{quiet:e.quiet});if(e.quiet)G(Q.join(`
170
- `));else h({urls:K,saved:Q,total:K.length},u)}});var s$={"720p":"1280*720","1080p":"1920*1080","480p":"832*480"};function F$(e){if(!e)return;return s$[e.toLowerCase()]||e}var lr=q({name:"video generate",description:"Generate a video from text or image (wan2.7-t2v / wan2.7-i2v / wan2.6-t2v)",apiDocs:"/best-practice/wanx/text-to-video",usage:"bl video generate --prompt <text> [--image <url>] [flags]",options:[{flag:"--model <model>",description:"Model ID (default: wan2.7-t2v, or wan2.7-i2v with --image)"},{flag:"--prompt <text>",description:"Video description",required:!0},{flag:"--image <url>",description:"Input image URL for image-to-video generation"},{flag:"--negative-prompt <text>",description:"Negative prompt to exclude unwanted content"},{flag:"--resolution <res>",description:"Resolution (e.g. 1280*720, 960*960)"},{flag:"--ratio <ratio>",description:"Aspect ratio (e.g. 16:9, 1:1)"},{flag:"--duration <seconds>",description:"Video duration in seconds (default: 5)",type:"number"},{flag:"--prompt-extend",description:"Automatically extend prompt for better results"},{flag:"--watermark",description:"Add watermark to generated video"},{flag:"--seed <n>",description:"Random seed for reproducible generation",type:"number"},{flag:"--download <path>",description:"Save video to file on completion"},{flag:"--no-wait",description:"Return task ID immediately without waiting"},{flag:"--async",description:"Return task ID immediately (agent/CI mode, same as --no-wait)"},{flag:"--poll-interval <seconds>",description:"Polling interval when waiting (default: 5)",type:"number"}],examples:['bl video generate --prompt "一个人在读书,静态镜头"','bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4','bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"','bl video generate --prompt "Mountain landscape" --resolution 1280*720 --duration 5'],async run(e,t){let n=t.prompt;if(!n)if(O({nonInteractive:e.nonInteractive})){let Q=await V({message:"Enter your video prompt:"});if(!Q)process.stderr.write(`Video generation cancelled.
171
- `),process.exit(1);n=Q}else R("prompt","bl video generate --prompt <text>");let i=t.model||e.defaultVideoModel||(t.image?"wan2.7-i2v":"wan2.7-t2v"),$=B(e.output),p=t.image,r,m=!1;if(p){let Q=await L(e);r=await v(p,Q.token,i,e.quiet),m=r.startsWith("oss://")}let _={model:i,input:{prompt:n,negative_prompt:t.negativePrompt||void 0,...r?{media:[{type:"first_frame",url:r}]}:{}},parameters:{resolution:F$(t.resolution)||void 0,ratio:t.ratio||void 0,duration:t.duration||void 0,prompt_extend:t.promptExtend===!0?!0:void 0,watermark:t.watermark===!0?!0:void 0,seed:t.seed}};if(e.dryRun){h({request:_},$);return}let x=he(t),b=Ne(e.baseUrl),u=(await me(x,e,()=>W(e,{url:b,method:"POST",body:_,async:!0,ossResolve:m}),"tasks")).map((Q)=>Q.output.task_id);if(!e.quiet)process.stderr.write(`[Model: ${i}]
172
- `);if(t.noWait||e.async){h(u.length===1?{task_id:u[0]}:{task_ids:u},$);return}let k=t.pollInterval??5,j=u.map((Q)=>{let T=F(e.baseUrl,Q);return $e(e,{url:T,intervalSec:k,timeoutSec:e.timeout,isComplete:(z)=>z.output.task_status==="SUCCEEDED",isFailed:(z)=>z.output.task_status==="FAILED",getStatus:(z)=>z.output.task_status,getErrorMessage:(z)=>{let D=z.output;return D.message||D.code||void 0}})}),A=await Promise.all(j),K=[];for(let Q=0;Q<A.length;Q++){let T=A[Q],z=T.output.video_url||T.output.results&&T.output.results[0]?.url;if(z)K.push({taskId:u[Q],videoUrl:z})}if(K.length===0)throw new S("All tasks completed but no video URLs returned.",o.GENERAL);if(t.download){let Q=t.download,{size:T}=await U(K[0].videoUrl,Q,{quiet:e.quiet});if(e.quiet)G(Q);else h({task_id:K[0].taskId,video_url:K[0].videoUrl,status:"SUCCEEDED",saved:Q,size:ue(T)},$);return}let Z=l(e,{subDir:"videos"}),{join:X}=await import("path"),H=[];if(await Promise.all(K.map(async({taskId:Q,videoUrl:T})=>{let z=X(Z,`${Q}.mp4`);await U(T,z,{quiet:e.quiet}),H.push({task_id:Q,video_url:T,saved:z})})),H.length===1)h(H[0],$);else h({videos:H,total:H.length},$)}});var Dr=q({name:"video edit",description:"Edit a video with wan2.7-videoedit (style transfer, object replacement, etc.)",apiDocs:"/best-practice/wanx/video-edit",usage:"bl video edit --video <url> --prompt <text> [flags]",options:[{flag:"--model <model>",description:"Model ID (default: wan2.7-videoedit)"},{flag:"--video <url>",description:"Input video URL or local file (mp4/mov, 2-10s)",required:!0},{flag:"--prompt <text>",description:'Edit instruction (e.g. "将画面转换为黏土风格")'},{flag:"--ref-image <url>",description:"Reference image URL (up to 4, comma-separated)"},{flag:"--negative-prompt <text>",description:"Negative prompt to exclude unwanted content"},{flag:"--resolution <res>",description:"Resolution: 720P or 1080P (default: 1080P)"},{flag:"--ratio <ratio>",description:"Aspect ratio (16:9, 9:16, 1:1, 4:3, 3:4)"},{flag:"--duration <seconds>",description:"Output video duration in seconds (2-10)",type:"number"},{flag:"--audio-setting <mode>",description:"Audio: auto (default) or origin (keep original)"},{flag:"--prompt-extend",description:"Enable prompt intelligent rewriting (default: true)"},{flag:"--no-prompt-extend",description:"Disable prompt intelligent rewriting"},{flag:"--watermark",description:'Add "AI生成" watermark'},{flag:"--seed <n>",description:"Random seed for reproducible generation",type:"number"},{flag:"--download <path>",description:"Save video to file on completion"},{flag:"--no-wait",description:"Return task ID immediately without waiting"},{flag:"--async",description:"Return task ID immediately (agent/CI mode, same as --no-wait)"},{flag:"--poll-interval <seconds>",description:"Polling interval when waiting (default: 15)",type:"number"}],examples:['bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"','bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png','bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4'],async run(e,t){let n=t.video;if(!n)if(O({nonInteractive:e.nonInteractive})){let Y=await V({message:"Enter the video URL to edit:"});if(!Y)process.stderr.write(`Video editing cancelled.
173
- `),process.exit(1);n=Y}else R("video","bl video edit --video <url> --prompt <text>");let i=t.prompt;if(!i){if(O({nonInteractive:e.nonInteractive})){let Y=await V({message:"Enter your edit instruction:"});if(!Y)process.stderr.write(`Video editing cancelled.
174
- `),process.exit(1);i=Y}}let $=t.model||"wan2.7-videoedit",p=B(e.output),r=await L(e),m=await v(n,r.token,$,e.quiet),_=m.startsWith("oss://"),x=[{type:"video",url:m}],b=t.refImage;if(b){let Y=b.split(",").map((M)=>M.trim()).filter(Boolean);for(let M of Y){let J=await v(M,r.token,$,e.quiet);if(J.startsWith("oss://"))_=!0;x.push({type:"reference_image",url:J})}}let w=t.noPromptExtend===!0?!1:t.promptExtend===!0?!0:void 0,u={model:$,input:{prompt:i||void 0,negative_prompt:t.negativePrompt||void 0,media:x},parameters:{resolution:t.resolution||void 0,ratio:t.ratio||void 0,duration:t.duration||void 0,audio_setting:t.audioSetting||void 0,prompt_extend:w,watermark:t.watermark===!0?!0:void 0,seed:t.seed}};if(e.dryRun){h({request:u},p);return}let k=Ne(e.baseUrl),A=(await W(e,{url:k,method:"POST",body:u,async:!0,ossResolve:_})).output.task_id;if(!e.quiet)process.stderr.write(`[Model: ${$}]
153
+ `),q=!1;if(S+=U.content,o)Z.write(U.content)}}}catch{}}if(q)J.write(G);if(y==="json")A({content:S},y);else Z.write(`
154
+ `)}else{let w=await Q(e,{url:b,method:"POST",body:x}),S=w.choices?.[0]?.message?.content??"";if(e.quiet||y==="text")N(S);else A(w,y)}}});import{writeFileSync as Q$}from"fs";import{existsSync as K$,mkdirSync as N$}from"fs";import{join as Cr}from"path";import{homedir as B$}from"os";var j$=()=>Cr(B$(),"bailian-output");function l(e,t){let n=t?.flagDir||e.outputDir||j$(),i=t?.subDir?Cr(n,t.subDir):n;if(!K$(i))N$(i,{recursive:!0});return i}import{existsSync as Lr,readFileSync as R$,statSync as J$}from"fs";import{basename as Vr}from"path";var W$="https://dashscope.aliyuncs.com/api/v1/uploads";async function T$(e,t){let n=`${W$}?action=getPolicy&model=${encodeURIComponent(t)}`,i=await fetch(n,{headers:{Authorization:`Bearer ${e}`,"Content-Type":"application/json",...d()},signal:AbortSignal.timeout(15000)});if(!i.ok){let p=await i.text().catch(()=>"");throw new u(`Failed to get upload policy (HTTP ${i.status}): ${p}`,h.GENERAL)}return(await i.json()).data}async function M$(e,t,n){let i=Vr(t),$=`${e.upload_dir}/${i}`,p=R$(t),r=new FormData;r.append("OSSAccessKeyId",e.oss_access_key_id),r.append("Signature",e.signature),r.append("policy",e.policy),r.append("x-oss-object-acl",e.x_oss_object_acl),r.append("x-oss-forbid-overwrite",e.x_oss_forbid_overwrite),r.append("key",$),r.append("success_action_status","200"),r.append("file",new Blob([p]),i);let y=await fetch(e.upload_host,{method:"POST",headers:{...d()},body:r,signal:AbortSignal.timeout(120000)});if(!y.ok){let m=await y.text().catch(()=>"");throw new u(`Failed to upload file to OSS (HTTP ${y.status}): ${m}`,h.GENERAL)}return`oss://${$}`}async function Qt(e){let{apiKey:t,model:n,filePath:i,quiet:$=!1}=e;if(!Lr(i))throw new u(`File not found: ${i}`,h.USAGE);let p=J$(i);if(!p.isFile())throw new u(`Not a file: ${i}`,h.USAGE);if(!$){let m=(p.size/1048576).toFixed(1);process.stderr.write(`Uploading ${Vr(i)} (${m} MB) for model ${n}...
155
+ `)}let r=await T$(t,n),y=await M$(r,i,$);if(!$)process.stderr.write(`Upload complete: ${y}
156
+ `);return y}function de(e){if(e.startsWith("http://")||e.startsWith("https://"))return!1;if(e.startsWith("oss://"))return!1;if(e.startsWith("data:"))return!1;return Lr(e)}async function E(e,t,n,i){if(!de(e))return e;return Qt({apiKey:t,model:n,filePath:e,quiet:i})}var H$=["Chelsie","Cherry","Ethan","Serena","Tina"];function Z$(e){let t=Buffer.alloc(44);return t.write("RIFF",0),t.writeUInt32LE(36+e,4),t.write("WAVE",8),t.write("fmt ",12),t.writeUInt32LE(16,16),t.writeUInt16LE(1,20),t.writeUInt16LE(1,22),t.writeUInt32LE(24000,24),t.writeUInt32LE(48000,28),t.writeUInt16LE(2,32),t.writeUInt16LE(16,34),t.write("data",36),t.writeUInt32LE(e,40),t}var Er=K({name:"omni",description:"Multimodal chat with text + audio output (Qwen-Omni)",apiDocs:"/model-studio/qwen-omni",usage:"bl omni --message <text> [flags]",options:[{flag:"--message <text>",description:"Message text (repeatable, prefix role: to set role)",required:!0,type:"array"},{flag:"--model <model>",description:"Model ID (default: qwen3.5-omni-plus)"},{flag:"--system <text>",description:"System prompt"},{flag:"--image <url>",description:"Image URL or local file (repeatable)",type:"array"},{flag:"--audio <url>",description:"Audio URL or local file (repeatable)",type:"array"},{flag:"--video <url>",description:"Video file URL / local path, or comma-separated frame URLs",type:"array"},{flag:"--voice <voice>",description:`Output voice (default: Cherry). Options: ${H$.join(", ")}`},{flag:"--audio-format <fmt>",description:"Audio output format (default: wav)"},{flag:"--audio-out <path>",description:"Save audio to file (default: auto-generate)"},{flag:"--text-only",description:"Output text only, no audio generation"},{flag:"--max-tokens <n>",description:"Maximum tokens to generate",type:"number"},{flag:"--temperature <n>",description:"Sampling temperature (0.0, 2.0]",type:"number"}],examples:['bl omni --message "你好,你是谁?"','bl omni --message "描述这张图片" --image ./photo.jpg','bl omni --message "这段音频在说什么?" --audio https://example.com/audio.wav','bl omni --message "总结这个视频" --video https://example.com/video.mp4','bl omni --message "这个视频讲了什么" --video ./local-video.mp4 --text-only','bl omni --message "用四川话回答:今天天气怎么样" --voice Serena','bl omni --message "Hello" --text-only --output json','bl omni --message "朗读这段话" --audio-out greeting.wav'],async run(e,t){let n=[];if(t.message)n=t.message;if(n.length===0)if(Y({nonInteractive:e.nonInteractive})){let M=await L({message:"Enter your message:"});if(!M)process.stderr.write(`Omni chat cancelled.
157
+ `),process.exit(1);n=[M]}else W("message","bl text omni --message <text>");let i=t.model||e.defaultOmniModel||"qwen3.5-omni-plus",$=t.voice||"Cherry",p=t.audioFormat||"wav",r=t.textOnly===!0,y=B(e.output),m=[];if(t.system)m.push({role:"system",content:t.system});let x=new Set(["system","user","assistant"]);for(let M of n){let O=M.indexOf(":"),P=O!==-1?M.slice(0,O):"";if(x.has(P)){let I=M.slice(O+1);if(P==="system")m.push({role:"system",content:I});else m.push({role:P,content:I})}else m.push({role:"user",content:M})}let b=t.image||[],w=t.audio||[],S=t.video||[],q=!1,o=[],k=[],G=[];if(b.length>0||w.length>0||S.length>0){let M=await V(e);for(let O of b){let P=await E(O,M.token,i,e.quiet);if(P.startsWith("oss://"))q=!0;o.push(P)}for(let O of w){let P=await E(O,M.token,i,e.quiet);if(P.startsWith("oss://"))q=!0;k.push(P)}for(let O of S)if(O.includes(",")){let P=O.split(",").map((I)=>I.trim()).filter(Boolean);for(let I of P){let Ne=await E(I,M.token,i,e.quiet);if(Ne.startsWith("oss://"))q=!0;G.push(`frame:${Ne}`)}}else{let P=await E(O,M.token,i,e.quiet);if(P.startsWith("oss://"))q=!0;G.push(P)}}if(o.length>0||k.length>0||G.length>0){for(let M=m.length-1;M>=0;M--)if(m[M].role==="user"){let O=m[M].content,P=[];if(typeof O==="string")P.push({type:"text",text:O});else if(Array.isArray(O))P.push(...O);for(let f of o)P.push({type:"image_url",image_url:{url:f}});for(let f of k)P.push({type:"audio_url",audio_url:{url:f}});let I=G.filter((f)=>f.startsWith("frame:")).map((f)=>f.slice(6)),Ne=G.filter((f)=>!f.startsWith("frame:"));if(I.length>0)P.push({type:"video",video:I});for(let f of Ne)P.push({type:"video_url",video_url:{url:f}});m[M]={role:"user",content:P};break}}let J={model:i,messages:m,stream:!0,stream_options:{include_usage:!0}};if(!r)J.modalities=["text","audio"],J.audio={voice:$,format:p};if(t.maxTokens!==void 0)J.max_tokens=t.maxTokens;if(t.temperature!==void 0)J.temperature=t.temperature;if(e.dryRun){A({request:J},y);return}if(!e.quiet){let M=r?"text-only":`text+audio, voice: ${$}`;process.stderr.write(`[Model: ${i}] [${M}]
158
+ `)}let Z=be(e.baseUrl),j=await ye(e,{url:Z,method:"POST",body:J,stream:!0,ossResolve:q}),T="",X="",U=process.stdout.isTTY,c=process.stdout;for await(let M of Ae(j)){if(M.data==="[DONE]")break;try{let O=JSON.parse(M.data);for(let P of O.choices){let I=P.delta;if(I.content){if(T+=I.content,U)c.write(I.content)}if(I.audio?.data)X+=I.audio.data}}catch{}}if(U&&T)c.write(`
159
+ `);let H;if(X&&!r){let M=Buffer.from(X,"base64"),O=Z$(M.length),P=Buffer.concat([O,M]),I=t.audioOut;if(!I){let{join:Ne}=await import("path"),f=l(e,{subDir:"omni"}),Yn=Date.now();I=Ne(f,`omni_${Yn}.wav`)}if(Q$(I,P),H=I,!e.quiet)process.stderr.write(`Audio saved: ${I}
160
+ `)}if(!U||y==="json"){let M={content:T};if(H)M.audio_saved=H,M.voice=$;A(M,y)}}});var Ir=["⠋","⠙","⠹","⠸","⠼","⠴","⠦","⠧","⠇","⠏"];function se(e){let t=process.stderr.isTTY,n=0,i=null,$=e;return{start(){if(!t)return;i=setInterval(()=>{process.stderr.write(`\r${Ir[n%Ir.length]} ${$}`),n++},80)},update(p){$=p},stop(p){if(i)clearInterval(i),i=null;if(t){if(process.stderr.write("\r\x1B[K"),p)process.stderr.write(`${p}
161
+ `)}}}}function vr(e,t=""){let n=process.stderr.isTTY,i=30;return{update($){if(!n)return;let p=Math.min(1,$/e),r=Math.round(30*p),y=30-r,m="█".repeat(r)+"░".repeat(y),x=`${Math.round(p*100)}%`;process.stderr.write(`\r${t} ${m} ${x}`)},finish(){if(n)process.stderr.write(`
162
+ `)}}}async function pe(e,t){let n=Date.now()+t.timeoutSec*1000,i=se("Polling...");if(!e.quiet)i.start();try{while(Date.now()<n){let $=await Q(e,{url:t.url});if(t.getStatus&&!e.quiet)i.update(`Status: ${t.getStatus($)}`);if(t.isComplete($))return i.stop("Done."),$;if(t.isFailed($)){if(i.stop("Failed."),e.verbose)process.stderr.write(`[verbose] Task response: ${JSON.stringify($,null,2)}
163
+ `);let p=t.getErrorMessage?.($);throw new u(p?`Task failed: ${p}`:"Task failed.",h.GENERAL,p?void 0:"Use --verbose to see full API response details.")}await new Promise((p)=>setTimeout(p,t.intervalSec*1000))}}finally{i.stop()}throw new u("Polling timed out.",h.TIMEOUT,"Try increasing --timeout or check task status manually.")}import{createWriteStream as z$,mkdirSync as X$,unlinkSync as P$}from"fs";import{dirname as Y$}from"path";async function s(e,t,n){let i=await fetch(e,{headers:d()});if(!i.ok)throw new u(`Download failed: HTTP ${i.status}`,h.GENERAL);let $=Number(i.headers.get("content-length")||0),p=i.body?.getReader();if(!p)throw new u("No response body",h.GENERAL);X$(Y$(t),{recursive:!0});let r=z$(t),y=$>0&&!n?.quiet?vr($,"Downloading"):null,m=0,x=!1;try{let b=new Promise((w,S)=>{r.on("error",S)});while(!0){let{done:w,value:S}=await Promise.race([p.read(),b]);if(w)break;if(!r.write(S))await new Promise((o)=>r.once("drain",o));m+=S.byteLength,y?.update(m)}x=!0}finally{if(p.releaseLock(),y?.finish(),await new Promise((b,w)=>{r.on("finish",b),r.on("error",w),r.end()}),!x)try{P$(t)}catch{}}return{size:m}}function ue(e){if(e<1024)return`${e} B`;if(e<1048576)return`${(e/1024).toFixed(1)} KB`;if(e<1073741824)return`${(e/1048576).toFixed(1)} MB`;return`${(e/1073741824).toFixed(1)} GB`}import{join as dr}from"path";function Se(e){let t=e.concurrent;return Math.max(1,t??1)}async function _e(e,t,n,i="requests"){if(e<=1)return[await n(0)];if(!t.quiet)process.stderr.write(`[Concurrent: ${e} ${i}]
164
+ `);let $=Array.from({length:e},(p,r)=>n(r));return Promise.all($)}async function Te(e,t,n){return Promise.all(e.map(({url:i,destPath:$})=>t(i,$,n).then(()=>$)))}function Ur(e,t){return e.normalize("NFKC").replace(/[\\/:*?"<>|]/g,"_").replace(/\s+/g,"_").replace(/_+/g,"_").replace(/^_+|_+$/g,"")||t}function Fe(e,t){let n=Ur(e||"image","image"),i=Ur((t||"").substring(0,20),"untitled");return`${n}_${i}_${Date.now()}`}var O$=["qwen-image-2.0","qwen-image-max"];function c$(e){return O$.some((t)=>e.startsWith(t))}var C$={"16:9":"2688*1536","9:16":"1536*2688","1:1":"2048*2048","4:3":"2368*1728","3:4":"1728*2368"},L$={"16:9":"1664*928","4:3":"1472*1104","1:1":"1328*1328","3:4":"1104*1472","9:16":"928*1664"};function V$(e,t){let i=(t?C$:L$)[e];if(i)return i;return e}var sr=K({name:"image generate",description:"Generate images (Qwen-Image / wan2.x)",apiDocs:"/best-practice/wanx/text-to-image",usage:"bl image generate --prompt <text> [flags]",options:[{flag:"--prompt <text>",description:"Image description",required:!0},{flag:"--model <model>",description:"Model ID (default: qwen-image-2.0)"},{flag:"--size <W*H>",description:"Image size: ratio (3:4, 16:9, 1:1) or pixels (2048*2048)"},{flag:"--n <count>",description:"Number of images per request (default: 1, max: 6)",type:"number"},{flag:"--seed <n>",description:"Random seed for reproducible generation",type:"number"},{flag:"--negative-prompt <text>",description:"Negative prompt to exclude unwanted content"},{flag:"--prompt-extend",description:"Automatically extend prompt for better results (default: true for qwen-image)"},{flag:"--no-prompt-extend",description:"Disable prompt extend"},{flag:"--watermark",description:"Add watermark to generated images"},{flag:"--no-wait",description:"Return task ID immediately without waiting (async models only)"},{flag:"--out-dir <dir>",description:"Download images to directory"},{flag:"--out-prefix <prefix>",description:"Filename prefix (default: image)"},{flag:"--poll-interval <seconds>",description:"Polling interval when waiting (default: 3)",type:"number"}],examples:['bl image generate --prompt "一只穿太空服的猫在火星上"','bl image generate --prompt "Logo design" --n 3 --out-dir ./generated/','bl image generate --prompt "Mountain landscape" --size 2688*1536','bl image generate --prompt "A castle" --seed 42 --no-prompt-extend','bl image generate --prompt "sunset" --model wan2.6-t2i --no-wait --quiet','bl image generate --prompt "Pro quality" --model qwen-image-2.0-pro','bl image generate --prompt "Product shots" --n 2 --concurrent 3 # 6 images in parallel'],async run(e,t){let n=t.prompt??t._positional?.[0];if(!n)if(Y({nonInteractive:e.nonInteractive})){let q=await L({message:"Enter your image prompt:"});if(!q)process.stderr.write(`Image generation cancelled.
165
+ `),process.exit(1);n=q}else W("prompt","bl image generate --prompt <text>");let i=t.model||e.defaultImageModel||"qwen-image-2.0",$=c$(i),p=$?"1:1":"1:1",r=t.size||p,y=V$(r,$),m=t.n??1,x=Se(t),b;if(t.noPromptExtend===!0)b=!1;else if(t.promptExtend===!0)b=!0;else if($)b=!0;let w={model:i,input:{messages:[{role:"user",content:[{text:n}]}]},parameters:{size:y,n:m,seed:t.seed,prompt_extend:b,watermark:t.watermark===!0?!0:void 0,negative_prompt:t.negativePrompt||void 0}},S=B(e.output);if(e.dryRun){A({request:w,mode:$?"sync":"async"},S);return}if(!e.quiet)process.stderr.write(`[Model: ${i}] [Mode: ${$?"sync":"async"}]
166
+ `);if($)await E$(e,i,w,t,S,x);else await I$(e,i,w,t,S,x)}});async function E$(e,t,n,i,$,p){let r=Ce(e.baseUrl),m=(await _e(p,e,()=>Q(e,{url:r,method:"POST",body:n}))).flatMap((x)=>x.output.choices||[]).flatMap((x)=>x.message?.content||[]).map((x)=>x.image).filter(Boolean);if(m.length===0)throw new u("Generation completed but no images returned.",h.GENERAL);await Fr(m,i,e,$)}async function I$(e,t,n,i,$,p){let r=It(e.baseUrl),m=(await _e(p,e,()=>Q(e,{url:r,method:"POST",body:n,async:!0}),"tasks")).map((q)=>q.output.task_id);if(i.noWait||e.async){A({task_ids:m},$);return}let x=i.pollInterval??3,b=m.map((q)=>{let o=a(e.baseUrl,q);return pe(e,{url:o,intervalSec:x,timeoutSec:e.timeout,isComplete:(k)=>k.output.task_status==="SUCCEEDED",isFailed:(k)=>k.output.task_status==="FAILED",getStatus:(k)=>k.output.task_status,getErrorMessage:(k)=>{let G=k.output;return G.message||G.code||void 0}})}),w=await Promise.all(b),S=[];for(let q of w){if(q.output.choices){let o=q.output.choices.flatMap((k)=>k.message?.content||[]).map((k)=>k.image).filter(Boolean);S.push(...o)}if(q.output.results){let o=q.output.results.map((k)=>k.url).filter(Boolean);if(o.length>0&&S.length===0)S.push(...o)}}if(S.length===0)throw new u("All tasks completed but no images returned.",h.GENERAL);await Fr(S,i,e,$,m.length===1?m[0]:void 0,m)}async function Fr(e,t,n,i,$,p){let r=l(n,{flagDir:t.outDir,subDir:t.outDir?void 0:"images"}),y=t.prompt||t._positional?.[0]||"",m=t.outPrefix||Fe("image",y),x=e.length>1?e.map((w,S)=>{let q=`${m}_${String(S+1).padStart(3,"0")}.png`;return{url:w,destPath:dr(r,q)}}):[{url:e[0],destPath:dr(r,`${m}.png`)}],b=await Te(x,s,{quiet:n.quiet});if(n.quiet)N(b.join(`
167
+ `));else{let w={urls:e,saved:b,total:e.length};if($)w.task_id=$;if(p&&p.length>1)w.task_ids=p;A(w,i)}}import{join as ar}from"path";function Me(e){for(let t of Object.keys(e))if(e[t]===void 0)delete e[t];return e}var v$={"16:9":"2688*1536","9:16":"1536*2688","1:1":"2048*2048","4:3":"2368*1728","3:4":"1728*2368"};function U$(e){if(!e)return;return v$[e]??e}var Dr=K({name:"image edit",description:"Edit an existing image with text instructions (Qwen-Image)",apiDocs:"/developer-reference/qwen-image-edit-api",usage:"bl image edit --image <url> --prompt <text> [flags]",options:[{flag:"--image <url>",description:"Source image URL or local file path (repeatable for multi-image merge)",required:!0,type:"array"},{flag:"--prompt <text>",description:"Edit instruction text",required:!0},{flag:"--model <model>",description:"Model ID (default: qwen-image-2.0)"},{flag:"--size <W*H>",description:"Output image size: ratio (3:4, 16:9) or pixels (2048*2048)"},{flag:"--n <count>",description:"Number of images (default: 1, max: 6)",type:"number"},{flag:"--seed <n>",description:"Random seed for reproducible results",type:"number"},{flag:"--negative-prompt <text>",description:"Negative prompt to exclude unwanted content"},{flag:"--prompt-extend",description:"Enable prompt smart rewrite (default: true)"},{flag:"--no-prompt-extend",description:"Disable prompt extend"},{flag:"--watermark",description:"Add watermark to output images"},{flag:"--out-dir <dir>",description:"Download images to directory"},{flag:"--out-prefix <prefix>",description:"Filename prefix (default: edited)"}],examples:['bl image edit --image ./photo.png --prompt "把背景换成海滩"','bl image edit --image https://example.com/logo.png --prompt "Change color to blue" --n 3','bl image edit --image ./a.png --image ./b.png --prompt "把两张图合并成一张拼图"','bl image edit --image https://example.com/photo.png --prompt "Remove the person" --model qwen-image-2.0-pro'],async run(e,t){let n=[];if(Array.isArray(t.image))n=t.image;else if(typeof t.image==="string")n=[t.image];if(n.length===0)W("image","bl image edit --image <url> --prompt <text>");let i=t.prompt;if(!i)if(Y({nonInteractive:e.nonInteractive})){let T=await L({message:"Enter your edit instruction:"});if(!T)process.stderr.write(`Image editing cancelled.
168
+ `),process.exit(1);i=T}else W("prompt","bl image edit --image <url> --prompt <text>");let $=t.model||e.defaultImageModel||"qwen-image-2.0",p=await V(e),r=await Promise.all(n.map((T)=>E(T,p.token,$,e.quiet))),y=r.some((T)=>T.startsWith("oss://")),m=t.n??1,x;if(t.noPromptExtend===!0)x=!1;else if(t.promptExtend===!0)x=!0;else x=!0;let b=r.map((T)=>({image:T}));b.push({text:i});let w={model:$,input:{messages:[{role:"user",content:b}]},parameters:{size:U$(t.size)||void 0,n:m,seed:t.seed,prompt_extend:x,watermark:t.watermark===!0?!0:void 0,negative_prompt:t.negativePrompt||void 0}};Me(w.parameters);let S=B(e.output);if(e.dryRun){A({request:w},S);return}if(!e.quiet)process.stderr.write(`[Model: ${$}] [Mode: sync] [Images: ${r.length}]
169
+ `);let q=Ce(e.baseUrl),o=Se(t),G=(await _e(o,e,()=>Q(e,{url:q,method:"POST",body:w,ossResolve:y}))).flatMap((T)=>T.output.choices||[]).flatMap((T)=>T.message?.content||[]).map((T)=>T.image).filter(Boolean);if(G.length===0)throw new u("Edit completed but no images returned.",h.GENERAL);let z=l(e,{flagDir:t.outDir,subDir:t.outDir?void 0:"images"}),J=t.outPrefix||Fe("edited",t?.prompt),Z=G.length>1?G.map((T,X)=>{let U=`${J}_${String(X+1).padStart(3,"0")}.png`;return{url:T,destPath:ar(z,U)}}):[{url:G[0],destPath:ar(z,`${J}.png`)}],j=await Te(Z,s,{quiet:e.quiet});if(e.quiet)N(j.join(`
170
+ `));else A({urls:G,saved:j,total:G.length},S)}});var lr=K({name:"video generate",description:"Generate a video from text or image (happyhorse-1.0-t2v / happyhorse-1.0-i2v)",apiDocs:"/best-practice/wanx/text-to-video",usage:"bl video generate --prompt <text> [--image <url>] [flags]",options:[{flag:"--model <model>",description:"Model ID (default: happyhorse-1.0-t2v, or happyhorse-1.0-i2v with --image)"},{flag:"--prompt <text>",description:"Video description",required:!0},{flag:"--image <url>",description:"Input image URL for image-to-video generation"},{flag:"--negative-prompt <text>",description:"Negative prompt to exclude unwanted content"},{flag:"--resolution <res>",description:"Resolution (e.g. 720P, 1080P)"},{flag:"--ratio <ratio>",description:"Aspect ratio (e.g. 16:9, 1:1)"},{flag:"--duration <seconds>",description:"Video duration in seconds (default: 5)",type:"number"},{flag:"--prompt-extend",description:"Automatically extend prompt for better results"},{flag:"--watermark",description:"Add watermark to generated video"},{flag:"--seed <n>",description:"Random seed for reproducible generation",type:"number"},{flag:"--download <path>",description:"Save video to file on completion"},{flag:"--no-wait",description:"Return task ID immediately without waiting"},{flag:"--async",description:"Return task ID immediately (agent/CI mode, same as --no-wait)"},{flag:"--poll-interval <seconds>",description:"Polling interval when waiting (default: 5)",type:"number"}],examples:['bl video generate --prompt "一个人在读书,静态镜头"','bl video generate --prompt "Ocean waves at sunset." --download sunset.mp4','bl video generate --image https://example.com/cat.png --prompt "让画面中的猫动起来"','bl video generate --prompt "Mountain landscape" --resolution 720P --duration 5'],async run(e,t){let n=t.prompt;if(!n)if(Y({nonInteractive:e.nonInteractive})){let j=await L({message:"Enter your video prompt:"});if(!j)process.stderr.write(`Video generation cancelled.
171
+ `),process.exit(1);n=j}else W("prompt","bl video generate --prompt <text>");let i=t.model||e.defaultVideoModel||(t.image?"happyhorse-1.0-i2v":"happyhorse-1.0-t2v"),$=B(e.output),p=t.image,r,y=!1;if(p){let j=await V(e);r=await E(p,j.token,i,e.quiet),y=r.startsWith("oss://")}let m={model:i,input:{prompt:n,negative_prompt:t.negativePrompt||void 0,...r?{media:[{type:"first_frame",url:r}]}:{}},parameters:{resolution:t.resolution?.toUpperCase()||void 0,ratio:t.ratio||void 0,duration:t.duration||void 0,prompt_extend:t.promptExtend===!0?!0:void 0,watermark:t.watermark===!0?!0:void 0,seed:t.seed}};if(e.dryRun){A({request:m},$);return}let x=Se(t),b=je(e.baseUrl),S=(await _e(x,e,()=>Q(e,{url:b,method:"POST",body:m,async:!0,ossResolve:y}),"tasks")).map((j)=>j.output.task_id);if(!e.quiet)process.stderr.write(`[Model: ${i}]
172
+ `);if(t.noWait||e.async){A(S.length===1?{task_id:S[0]}:{task_ids:S},$);return}let q=t.pollInterval??5,o=S.map((j)=>{let T=a(e.baseUrl,j);return pe(e,{url:T,intervalSec:q,timeoutSec:e.timeout,isComplete:(X)=>X.output.task_status==="SUCCEEDED",isFailed:(X)=>X.output.task_status==="FAILED",getStatus:(X)=>X.output.task_status,getErrorMessage:(X)=>{let U=X.output;return U.message||U.code||void 0}})}),k=await Promise.all(o),G=[];for(let j=0;j<k.length;j++){let T=k[j],X=T.output.video_url||T.output.results&&T.output.results[0]?.url;if(X)G.push({taskId:S[j],videoUrl:X})}if(G.length===0)throw new u("All tasks completed but no video URLs returned.",h.GENERAL);if(t.download){let j=t.download,{size:T}=await s(G[0].videoUrl,j,{quiet:e.quiet});if(e.quiet)N(j);else A({task_id:G[0].taskId,video_url:G[0].videoUrl,status:"SUCCEEDED",saved:j,size:ue(T)},$);return}let z=l(e,{subDir:"videos"}),{join:J}=await import("path"),Z=[];if(await Promise.all(G.map(async({taskId:j,videoUrl:T})=>{let X=J(z,`${j}.mp4`);await s(T,X,{quiet:e.quiet}),Z.push({task_id:j,video_url:T,saved:X})})),Z.length===1)A(Z[0],$);else A({videos:Z,total:Z.length},$)}});var fr=K({name:"video edit",description:"Edit a video with happyhorse-1.0-video-edit (style transfer, object replacement, etc.)",apiDocs:"/best-practice/wanx/video-edit",usage:"bl video edit --video <url> --prompt <text> [flags]",options:[{flag:"--model <model>",description:"Model ID (default: happyhorse-1.0-video-edit)"},{flag:"--video <url>",description:"Input video URL or local file (mp4/mov, 2-10s)",required:!0},{flag:"--prompt <text>",description:'Edit instruction (e.g. "将画面转换为黏土风格")'},{flag:"--ref-image <url>",description:"Reference image URL (up to 4, comma-separated)"},{flag:"--negative-prompt <text>",description:"Negative prompt to exclude unwanted content"},{flag:"--resolution <res>",description:"Resolution: 720P or 1080P (default: 1080P)"},{flag:"--ratio <ratio>",description:"Aspect ratio (16:9, 9:16, 1:1, 4:3, 3:4)"},{flag:"--duration <seconds>",description:"Output video duration in seconds (2-10)",type:"number"},{flag:"--audio-setting <mode>",description:"Audio: auto (default) or origin (keep original)"},{flag:"--prompt-extend",description:"Enable prompt intelligent rewriting (default: true)"},{flag:"--no-prompt-extend",description:"Disable prompt intelligent rewriting"},{flag:"--watermark",description:'Add "AI生成" watermark'},{flag:"--seed <n>",description:"Random seed for reproducible generation",type:"number"},{flag:"--download <path>",description:"Save video to file on completion"},{flag:"--no-wait",description:"Return task ID immediately without waiting"},{flag:"--async",description:"Return task ID immediately (agent/CI mode, same as --no-wait)"},{flag:"--poll-interval <seconds>",description:"Polling interval when waiting (default: 15)",type:"number"}],examples:['bl video edit --video https://example.com/input.mp4 --prompt "将整个画面转换为黏土风格"','bl video edit --video https://example.com/input.mp4 --prompt "替换衣服为图片中的款式" --ref-image https://example.com/clothes.png','bl video edit --video https://example.com/input.mp4 --prompt "Convert to anime style" --resolution 720P --download output.mp4'],async run(e,t){let n=t.video;if(!n)if(Y({nonInteractive:e.nonInteractive})){let c=await L({message:"Enter the video URL to edit:"});if(!c)process.stderr.write(`Video editing cancelled.
173
+ `),process.exit(1);n=c}else W("video","bl video edit --video <url> --prompt <text>");let i=t.prompt;if(!i){if(Y({nonInteractive:e.nonInteractive})){let c=await L({message:"Enter your edit instruction:"});if(!c)process.stderr.write(`Video editing cancelled.
174
+ `),process.exit(1);i=c}}let $=t.model||"happyhorse-1.0-video-edit",p=B(e.output),r=await V(e),y=await E(n,r.token,$,e.quiet),m=y.startsWith("oss://"),x=[{type:"video",url:y}],b=t.refImage;if(b){let c=b.split(",").map((H)=>H.trim()).filter(Boolean);for(let H of c){let M=await E(H,r.token,$,e.quiet);if(M.startsWith("oss://"))m=!0;x.push({type:"reference_image",url:M})}}let w=t.noPromptExtend===!0?!1:t.promptExtend===!0?!0:void 0,S={model:$,input:{prompt:i||void 0,negative_prompt:t.negativePrompt||void 0,media:x},parameters:{resolution:t.resolution?.toUpperCase()||void 0,ratio:t.ratio||void 0,duration:t.duration||void 0,audio_setting:t.audioSetting||void 0,prompt_extend:w,watermark:t.watermark===!0?!0:void 0,seed:t.seed}};if(e.dryRun){A({request:S},p);return}let q=je(e.baseUrl),k=(await Q(e,{url:q,method:"POST",body:S,async:!0,ossResolve:m})).output.task_id;if(!e.quiet)process.stderr.write(`[Model: ${$}]
175
175
  `),process.stderr.write(`Note: Video editing typically takes 5-8 minutes. Please be patient.
176
- `);if(t.noWait||e.async){h({task_id:A},p);return}let K=t.pollInterval??15,Z=F(e.baseUrl,A),X=Math.max(e.timeout,600),H=await $e(e,{url:Z,intervalSec:K,timeoutSec:X,isComplete:(Y)=>Y.output.task_status==="SUCCEEDED",isFailed:(Y)=>Y.output.task_status==="FAILED",getStatus:(Y)=>Y.output.task_status,getErrorMessage:(Y)=>{let M=Y.output;return M.message||M.code||void 0}}),Q=H.output.video_url||H.output.results&&H.output.results[0]?.url;if(!Q)throw new S("Task completed but no video URL returned.",o.GENERAL);if(t.download){let Y=t.download,{size:M}=await U(Q,Y,{quiet:e.quiet});if(e.quiet)G(Y);else h({task_id:A,video_url:Q,status:"SUCCEEDED",saved:Y,size:ue(M)},p);return}let{join:T}=await import("path"),z=l(e,{subDir:"videos"}),D=T(z,`${A}.mp4`);await U(Q,D,{quiet:e.quiet}),h({task_id:A,video_url:Q,saved:D},p)}});var fr=q({name:"video ref",description:"Reference-to-video generation (wan2.7-r2v / wan2.6-r2v): multi-subject, multi-shot with voice",apiDocs:"/best-practice/wanx/video-reference",usage:"bl video ref --prompt <text> --image <url>... [--ref-video <url>...] [flags]",options:[{flag:"--model <model>",description:"Model ID (default: wan2.7-r2v)"},{flag:"--prompt <text>",description:"Video description with reference markers (图1, 视频1, etc.)",required:!0},{flag:"--image <url>",description:"Reference image URL or local file (repeatable for multiple subjects)",type:"array"},{flag:"--ref-video <url>",description:"Reference video URL or local file (repeatable)",type:"array"},{flag:"--image-voice <url>",description:"Voice URL for corresponding image (pairs by position)",type:"array"},{flag:"--video-voice <url>",description:"Voice URL for corresponding ref-video (pairs by position)",type:"array"},{flag:"--resolution <res>",description:"Resolution: 720P or 1080P (default: 720P)"},{flag:"--ratio <ratio>",description:"Aspect ratio (16:9, 9:16, 1:1)"},{flag:"--duration <seconds>",description:"Video duration in seconds (2-10, default: 5)",type:"number"},{flag:"--prompt-extend",description:"Enable prompt intelligent rewriting"},{flag:"--no-prompt-extend",description:"Disable prompt intelligent rewriting"},{flag:"--watermark",description:"Add watermark to generated video"},{flag:"--seed <n>",description:"Random seed for reproducible generation",type:"number"},{flag:"--download <path>",description:"Save video to file on completion"},{flag:"--no-wait",description:"Return task ID immediately without waiting"},{flag:"--async",description:"Return task ID immediately (agent/CI mode, same as --no-wait)"},{flag:"--poll-interval <seconds>",description:"Polling interval when waiting (default: 15)",type:"number"}],examples:['bl video ref --prompt "图1在草地上奔跑" --image person.jpg','bl video ref --prompt "视频1在弹吉他,图1走过来" --ref-video scene.mp4 --image person.jpg','bl video ref --prompt "图1说话" --image person.jpg --image-voice voice.mp3 --resolution 1080P','bl video ref --prompt "图1和图2在对话" --image a.jpg --image b.jpg --image-voice va.mp3 --image-voice vb.mp3'],async run(e,t){let n=t.prompt;if(!n)if(O({nonInteractive:e.nonInteractive})){let M=await V({message:"Enter your video prompt (use 图1, 视频1 to reference inputs):"});if(!M)process.stderr.write(`Video generation cancelled.
177
- `),process.exit(1);n=M}else R("prompt","bl video ref --prompt <text> --image <url>");let i=t.image||[],$=t.refVideo||[];if(i.length===0&&$.length===0)throw new S("At least one --image or --ref-video is required.",o.USAGE,'bl video ref --prompt "描述" --image person.jpg');let p=t.imageVoice||[],r=t.videoVoice||[],m=t.model||"wan2.7-r2v",_=B(e.output),x=await L(e),b=!1,w=[];for(let M=0;M<i.length;M++){let J=await v(i[M],x.token,m,e.quiet);if(J.startsWith("oss://"))b=!0;let P={type:"reference_image",url:J};if(p[M]){let c=await v(p[M],x.token,m,e.quiet);if(c.startsWith("oss://"))b=!0;P.reference_voice=c}w.push(P)}for(let M=0;M<$.length;M++){let J=await v($[M],x.token,m,e.quiet);if(J.startsWith("oss://"))b=!0;let P={type:"reference_video",url:J};if(r[M]){let c=await v(r[M],x.token,m,e.quiet);if(c.startsWith("oss://"))b=!0;P.reference_voice=c}w.push(P)}let u=t.noPromptExtend===!0?!1:t.promptExtend===!0?!0:void 0,k={model:m,input:{prompt:n,media:w},parameters:{resolution:t.resolution||void 0,ratio:t.ratio||void 0,duration:t.duration||void 0,prompt_extend:u,watermark:t.watermark===!0?!0:void 0,seed:t.seed}};if(e.dryRun){h({request:k},_);return}let j=Ne(e.baseUrl),K=(await W(e,{url:j,method:"POST",body:k,async:!0,ossResolve:b})).output.task_id;if(!e.quiet)process.stderr.write(`[Model: ${m}]
176
+ `);if(t.noWait||e.async){A({task_id:k},p);return}let G=t.pollInterval??15,z=a(e.baseUrl,k),J=Math.max(e.timeout,600),Z=await pe(e,{url:z,intervalSec:G,timeoutSec:J,isComplete:(c)=>c.output.task_status==="SUCCEEDED",isFailed:(c)=>c.output.task_status==="FAILED",getStatus:(c)=>c.output.task_status,getErrorMessage:(c)=>{let H=c.output;return H.message||H.code||void 0}}),j=Z.output.video_url||Z.output.results&&Z.output.results[0]?.url;if(!j)throw new u("Task completed but no video URL returned.",h.GENERAL);if(t.download){let c=t.download,{size:H}=await s(j,c,{quiet:e.quiet});if(e.quiet)N(c);else A({task_id:k,video_url:j,status:"SUCCEEDED",saved:c,size:ue(H)},p);return}let{join:T}=await import("path"),X=l(e,{subDir:"videos"}),U=T(X,`${k}.mp4`);await s(j,U,{quiet:e.quiet}),A({task_id:k,video_url:j,saved:U},p)}});var gr=K({name:"video ref",description:"Reference-to-video generation (happyhorse-1.0-r2v / wan2.6-r2v): multi-subject, multi-shot with voice",apiDocs:"/best-practice/wanx/video-reference",usage:"bl video ref --prompt <text> --image <url>... [--ref-video <url>...] [flags]",options:[{flag:"--model <model>",description:"Model ID (default: happyhorse-1.0-r2v)"},{flag:"--prompt <text>",description:"Video description with reference markers (图1, 视频1, etc.)",required:!0},{flag:"--image <url>",description:"Reference image URL or local file (repeatable for multiple subjects)",type:"array"},{flag:"--ref-video <url>",description:"Reference video URL or local file (repeatable)",type:"array"},{flag:"--image-voice <url>",description:"Voice URL for corresponding image (pairs by position)",type:"array"},{flag:"--video-voice <url>",description:"Voice URL for corresponding ref-video (pairs by position)",type:"array"},{flag:"--resolution <res>",description:"Resolution: 720P or 1080P (default: 720P)"},{flag:"--ratio <ratio>",description:"Aspect ratio (16:9, 9:16, 1:1)"},{flag:"--duration <seconds>",description:"Video duration in seconds (2-10, default: 5)",type:"number"},{flag:"--prompt-extend",description:"Enable prompt intelligent rewriting"},{flag:"--no-prompt-extend",description:"Disable prompt intelligent rewriting"},{flag:"--watermark",description:"Add watermark to generated video"},{flag:"--seed <n>",description:"Random seed for reproducible generation",type:"number"},{flag:"--download <path>",description:"Save video to file on completion"},{flag:"--no-wait",description:"Return task ID immediately without waiting"},{flag:"--async",description:"Return task ID immediately (agent/CI mode, same as --no-wait)"},{flag:"--poll-interval <seconds>",description:"Polling interval when waiting (default: 15)",type:"number"}],examples:['bl video ref --prompt "图1在草地上奔跑" --image person.jpg','bl video ref --prompt "视频1在弹吉他,图1走过来" --ref-video scene.mp4 --image person.jpg','bl video ref --prompt "图1说话" --image person.jpg --image-voice voice.mp3 --resolution 1080P','bl video ref --prompt "图1和图2在对话" --image a.jpg --image b.jpg --image-voice va.mp3 --image-voice vb.mp3'],async run(e,t){let n=t.prompt;if(!n)if(Y({nonInteractive:e.nonInteractive})){let H=await L({message:"Enter your video prompt (use 图1, 视频1 to reference inputs):"});if(!H)process.stderr.write(`Video generation cancelled.
177
+ `),process.exit(1);n=H}else W("prompt","bl video ref --prompt <text> --image <url>");let i=t.image||[],$=t.refVideo||[];if(i.length===0&&$.length===0)throw new u("At least one --image or --ref-video is required.",h.USAGE,'bl video ref --prompt "描述" --image person.jpg');let p=t.imageVoice||[],r=t.videoVoice||[],y=t.model||"happyhorse-1.0-r2v",m=B(e.output),x=await V(e),b=!1,w=[];for(let H=0;H<i.length;H++){let M=await E(i[H],x.token,y,e.quiet);if(M.startsWith("oss://"))b=!0;let O={type:"reference_image",url:M};if(p[H]){let P=await E(p[H],x.token,y,e.quiet);if(P.startsWith("oss://"))b=!0;O.reference_voice=P}w.push(O)}for(let H=0;H<$.length;H++){let M=await E($[H],x.token,y,e.quiet);if(M.startsWith("oss://"))b=!0;let O={type:"reference_video",url:M};if(r[H]){let P=await E(r[H],x.token,y,e.quiet);if(P.startsWith("oss://"))b=!0;O.reference_voice=P}w.push(O)}let S=t.noPromptExtend===!0?!1:t.promptExtend===!0?!0:void 0,q={model:y,input:{prompt:n,media:w},parameters:{resolution:t.resolution?.toUpperCase()||void 0,ratio:t.ratio||void 0,duration:t.duration||void 0,prompt_extend:S,watermark:t.watermark===!0?!0:void 0,seed:t.seed}};if(e.dryRun){A({request:q},m);return}let o=je(e.baseUrl),G=(await Q(e,{url:o,method:"POST",body:q,async:!0,ossResolve:b})).output.task_id;if(!e.quiet)process.stderr.write(`[Model: ${y}]
178
178
  `),process.stderr.write(`Note: Reference-to-video typically takes 5-10 minutes. Please be patient.
179
- `);if(t.noWait||e.async){h({task_id:K},_);return}let Z=t.pollInterval??15,X=F(e.baseUrl,K),H=Math.max(e.timeout,600),Q=await $e(e,{url:X,intervalSec:Z,timeoutSec:H,isComplete:(M)=>M.output.task_status==="SUCCEEDED",isFailed:(M)=>M.output.task_status==="FAILED",getStatus:(M)=>M.output.task_status,getErrorMessage:(M)=>{let J=M.output;return J.message||J.code||void 0}}),T=Q.output.video_url||Q.output.results&&Q.output.results[0]?.url;if(!T)throw new S("Task completed but no video URL returned.",o.GENERAL);if(t.download){let M=t.download,{size:J}=await U(T,M,{quiet:e.quiet});if(e.quiet)G(M);else h({task_id:K,video_url:T,status:"SUCCEEDED",saved:M,size:ue(J)},_);return}let{join:z}=await import("path"),D=l(e,{subDir:"videos"}),Y=z(D,`${K}.mp4`);await U(T,Y,{quiet:e.quiet}),h({task_id:K,video_url:T,saved:Y},_)}});var gr=q({name:"video task get",description:"Query async task status",usage:"bl video task get --task-id <id>",options:[{flag:"--task-id <id>",description:"Async task ID"}],examples:["bl video task get --task-id 3b256896-3e70-xxxx-xxxx-xxxxxxxxxxxx","bl video task get --task-id 3b256896-3e70-xxxx --output json"],async run(e,t){let n=t.taskId;if(!n)throw new S("--task-id is required.",o.USAGE,"bl video task get --task-id <id>");let i=B(e.output);if(e.dryRun){h({task_id:n},i);return}let $=F(e.baseUrl,n),p=await W(e,{url:$});if(e.quiet){G(p.output.task_status);return}h({task_id:p.output.task_id,task_status:p.output.task_status,video_url:p.output.video_url,results:p.output.results,submit_time:p.output.submit_time,end_time:p.output.end_time},i)}});var en=q({name:"video download",description:"Download a completed video by task ID",usage:"bl video download --task-id <id> --out <path>",options:[{flag:"--task-id <id>",description:"Task ID to download from"},{flag:"--out <path>",description:"Output file path"}],examples:["bl video download --task-id 3b256896-xxxx --out video.mp4","bl video download --task-id 3b256896-xxxx --out video.mp4 --quiet"],async run(e,t){let n=t.taskId;if(!n)throw new S("--task-id is required.",o.USAGE,"bl video download --task-id <id> --out <path>");let i=t.out;if(!i)throw new S("--out is required.",o.USAGE,`bl video download --task-id <id> --out video.mp4
180
- Or set output_dir: bl config set --key output_dir --value ~/my-output`);let $=B(e.output);if(e.dryRun){h({task_id:n,action:"download",out:i},$);return}let p=F(e.baseUrl,n),r=await W(e,{url:p});if(r.output.task_status!=="SUCCEEDED")throw new S(`Task is not complete (status: ${r.output.task_status}).`,o.GENERAL,"Wait for the task to complete before downloading.");let m=r.output.video_url||r.output.results&&r.output.results[0]?.url;if(!m)throw new S("No download URL available for this task.",o.GENERAL);let{size:_}=await U(m,i,{quiet:e.quiet});if(e.quiet){G(i);return}h({saved:i,size:ue(_)},$)}});import{readFileSync as a$,existsSync as rn}from"fs";import{extname as nn}from"path";var l$={".jpg":"image/jpeg",".jpeg":"image/jpeg",".png":"image/png",".webp":"image/webp"},D$=new Set([".mp4",".mov",".avi",".mkv",".webm",".flv",".wmv"]);function tn(e){let t=nn(e).toLowerCase().split("?")[0];if(D$.has(t))return!0;if(/\.(mp4|mov|avi|mkv|webm|flv|wmv)(\?|$)/i.test(e))return!0;return!1}async function f$(e){if(e.startsWith("data:"))return e;if(e.startsWith("http://")||e.startsWith("https://"))return e;if(e.startsWith("oss://"))return e;if(!rn(e))throw new S(`File not found: ${e}`,o.USAGE);let t=nn(e).toLowerCase(),n=l$[t];if(!n)throw new S(`Unsupported image format "${t}". Supported: jpg, jpeg, png, webp`,o.USAGE);let i=a$(e);return`data:${n};base64,${i.toString("base64")}`}var $n=q({name:"vision describe",description:"Describe an image or video using Qwen-VL",usage:"bl vision describe --image <path-or-url> [--video <url>] [--prompt <text>]",options:[{flag:"--image <path-or-url>",description:"Local image path or URL"},{flag:"--video <url>",description:"Video file URL or local path (mp4/mov/avi/mkv/webm)",type:"array"},{flag:"--prompt <text>",description:"Question about the content (default: auto-detected)"},{flag:"--model <model>",description:"Vision model (default: qwen-vl-max)"}],examples:["bl vision describe --image photo.jpg",'bl vision describe --image https://example.com/photo.jpg --prompt "这只狗是什么品种?"','bl vision describe --video https://example.com/video.mp4 --prompt "总结视频内容"',"bl vision describe --video ./local-video.mp4",'bl vision describe --image photo.png --prompt "Extract the text" --model qwen-vl-plus'],async run(e,t){let n=t.image??t._positional?.[0],i=t.video??[],$=t.model||"qwen-vl-max";if(n&&tn(n))i.push(n),n=void 0;let p=i.length>0,r=p?"Describe the video.":"Describe the image.",m=t.prompt||r;if(!n&&!p)if(O({nonInteractive:e.nonInteractive})){let A=await V({message:"Enter image/video path or URL:"});if(!A)process.stderr.write(`Vision describe cancelled.
181
- `),process.exit(1);if(tn(A))i.push(A);else n=A}else throw new S("Missing required argument --image or --video.",o.USAGE,`bl vision describe --image <path-or-url>
182
- bl vision describe --video <url-or-path>`);let _=B(e.output);if(e.dryRun){h({request:{prompt:m,image:n,video:i.length?i:void 0,model:$}},_);return}let x=[],b=!1;if(i.length>0)for(let A of i){let K=A;if(Ue(A)){if(!rn(A))throw new S(`Video file not found: ${A}`,o.USAGE);let Z=await L(e);if(K=await v(A,Z.token,$,e.quiet),K.startsWith("oss://"))b=!0}x.push({type:"video_url",video_url:{url:K}})}if(n){let A=await f$(n),K=A;if(Ue(n)&&A.startsWith("data:")){let{statSync:Z}=await import("fs");if(Z(n).size>5242880){let H=await L(e);if(K=await v(n,H.token,$,e.quiet),K.startsWith("oss://"))b=!0}}x.push({type:"image_url",image_url:{url:K}})}x.push({type:"text",text:m});let w={model:$,messages:[{role:"user",content:x}]},u=_e(e.baseUrl),k=await W(e,{url:u,method:"POST",body:w,ossResolve:b}),j=k.choices?.[0]?.message?.content;if(_!=="text"){h(k,_);return}G(j||"")}});var pn=q({name:"config show",description:"Display current configuration",usage:"bl config show",examples:["bl config show","bl config show --output json"],async run(e,t){let n=ne(),i=B(e.output),$={region:e.region,base_url:e.baseUrl,output:e.output,timeout:e.timeout,config_file:re()};if(n.api_key)$.api_key=g(n.api_key);if(n.default_text_model)$.default_text_model=n.default_text_model;if(n.default_video_model)$.default_video_model=n.default_video_model;if(n.default_image_model)$.default_image_model=n.default_image_model;h($,i)}});var mn=["region","base_url","output","output_dir","timeout","api_key","default_text_model","default_video_model","default_image_model","default_speech_model","default_omni_model","access_key_id","access_key_secret","workspace_id"],g$={"base-url":"base_url","output-dir":"output_dir","api-key":"api_key","default-text-model":"default_text_model","default-video-model":"default_video_model","default-image-model":"default_image_model","default-speech-model":"default_speech_model","default-omni-model":"default_omni_model","access-key-id":"access_key_id","access-key-secret":"access_key_secret","workspace-id":"workspace_id"},yn=q({name:"config set",description:"Set a config value",usage:"bl config set --key <key> --value <value>",options:[{flag:"--key <key>",description:"Config key (region, base_url, output, output_dir, timeout, api_key, default_*_model, access_key_id, access_key_secret, workspace_id)"},{flag:"--value <value>",description:"Value to set"}],examples:["bl config set --key output --value json","bl config set --key timeout --value 600","bl config set --key base_url --value https://dashscope.aliyuncs.com"],async run(e,t){let{key:n,value:i}=t;if(!n||i===void 0)throw new S("--key and --value are required.",o.USAGE,"bl config set --key <key> --value <value>");let $=g$[n]||n;if(!mn.includes($))throw new S(`Invalid config key "${n}". Valid keys: ${mn.join(", ")}`,o.USAGE);if($==="region"&&!["cn","us","intl"].includes(i))throw new S(`Invalid region "${i}". Valid values: cn, us, intl`,o.USAGE);if($==="output"&&!["text","json"].includes(i))throw new S(`Invalid output format "${i}". Valid values: text, json`,o.USAGE);if($==="timeout"){let m=Number(i);if(isNaN(m)||m<=0)throw new S(`Invalid timeout "${i}". Must be a positive number.`,o.USAGE)}let p=B(e.output);if(e.dryRun){h({would_set:{[$]:i}},p);return}let r=ne();if(r[$]=$==="timeout"?Number(i):i,await Re(r),!e.quiet)h({[$]:r[$]},p)}});function ep(e){let t=e.match(/^--([a-zA-Z0-9-]+)/),n=t?t[1]:"",i=n.replace(/-([a-zA-Z0-9])/g,(r,m)=>m.toUpperCase()),$="string",p=!1;if(!e.includes("<")&&!e.includes("["))$="boolean";else if(e.includes("<n>")||e.includes("<hz>")||e.includes("<bps>")||e.includes("<count>"))$="number";if(e.toLowerCase().includes("repeatable"))p=!0;return{name:i,kebabName:n,inferredType:$,isArray:p}}function Zt(e){let n={name:`bailian_${e.name.replace(/ /g,"_")}`,description:e.description,input_schema:{type:"object",properties:{},required:[]}};if(e.options)for(let i of e.options){let{name:$,inferredType:p,isArray:r}=ep(i.flag);if(!$)continue;let m=i.type,_=r?"array":m??p,x={description:i.description};if(_==="array")x.type="array",x.items={type:"string"};else x.type=_;let b=n.input_schema;if(b.properties[$]=x,i.required)b.required.push($)}return n}var tp=["auth ","config ","update"],_n=q({name:"config export-schema",description:"Export all (or one) CLI command(s) as Anthropic/OpenAI-compatible JSON tool schemas",usage:'bl config export-schema [--command "<name>"]',options:[{flag:"--command <name>",description:'Export schema for a specific command only (e.g. "image generate")'}],examples:["bl config export-schema",'bl config export-schema --command "video generate"'],async run(e,t){let n=t.command;if(n){try{let{command:p}=qe.resolve(n.split(" ")),r=Zt(p);process.stdout.write(JSON.stringify(r,null,2)+`
183
- `)}catch{throw new S(`Command "${n}" not found.`,o.USAGE)}return}let $=qe.getAllCommands().filter((p)=>!tp.some((r)=>p.name.startsWith(r))).map((p)=>Zt(p));process.stdout.write(JSON.stringify($,null,2)+`
184
- `)}});import{execSync as xn}from"child_process";import{writeFileSync as rp}from"fs";import{join as np}from"path";var ae="0.1.0";async function ip(){try{let e=Ke.replace("/","%2f"),t=await fetch(`${Xe}/${e}/latest`,{headers:{Accept:"application/json",...d()},signal:AbortSignal.timeout(5000)});if(!t.ok)return null;return(await t.json()).version??null}catch{return null}}function $p(){return{cmd:`npm install -g ${Ke}@latest`,label:"npm"}}var bn=q({name:"update",description:"Update bl to the latest version",usage:"bl update",examples:["bl update"],async run(){let e=process.stderr.isTTY,t=e?"\x1B[32m":"",n=e?"\x1B[33m":"",i=e?"\x1B[0m":"";process.stderr.write(`Current version: ${n}${ae}${i}
179
+ `);if(t.noWait||e.async){A({task_id:G},m);return}let z=t.pollInterval??15,J=a(e.baseUrl,G),Z=Math.max(e.timeout,600),j=await pe(e,{url:J,intervalSec:z,timeoutSec:Z,isComplete:(H)=>H.output.task_status==="SUCCEEDED",isFailed:(H)=>H.output.task_status==="FAILED",getStatus:(H)=>H.output.task_status,getErrorMessage:(H)=>{let M=H.output;return M.message||M.code||void 0}}),T=j.output.video_url||j.output.results&&j.output.results[0]?.url;if(!T)throw new u("Task completed but no video URL returned.",h.GENERAL);if(t.download){let H=t.download,{size:M}=await s(T,H,{quiet:e.quiet});if(e.quiet)N(H);else A({task_id:G,video_url:T,status:"SUCCEEDED",saved:H,size:ue(M)},m);return}let{join:X}=await import("path"),U=l(e,{subDir:"videos"}),c=X(U,`${G}.mp4`);await s(T,c,{quiet:e.quiet}),A({task_id:G,video_url:T,saved:c},m)}});var en=K({name:"video task get",description:"Query async task status",usage:"bl video task get --task-id <id>",options:[{flag:"--task-id <id>",description:"Async task ID"}],examples:["bl video task get --task-id 3b256896-3e70-xxxx-xxxx-xxxxxxxxxxxx","bl video task get --task-id 3b256896-3e70-xxxx --output json"],async run(e,t){let n=t.taskId;if(!n)throw new u("--task-id is required.",h.USAGE,"bl video task get --task-id <id>");let i=B(e.output);if(e.dryRun){A({task_id:n},i);return}let $=a(e.baseUrl,n),p=await Q(e,{url:$});if(e.quiet){N(p.output.task_status);return}A({task_id:p.output.task_id,task_status:p.output.task_status,video_url:p.output.video_url,results:p.output.results,submit_time:p.output.submit_time,end_time:p.output.end_time},i)}});var tn=K({name:"video download",description:"Download a completed video by task ID",usage:"bl video download --task-id <id> --out <path>",options:[{flag:"--task-id <id>",description:"Task ID to download from"},{flag:"--out <path>",description:"Output file path"}],examples:["bl video download --task-id 3b256896-xxxx --out video.mp4","bl video download --task-id 3b256896-xxxx --out video.mp4 --quiet"],async run(e,t){let n=t.taskId;if(!n)throw new u("--task-id is required.",h.USAGE,"bl video download --task-id <id> --out <path>");let i=t.out;if(!i)throw new u("--out is required.",h.USAGE,`bl video download --task-id <id> --out video.mp4
180
+ Or set output_dir: bl config set --key output_dir --value ~/my-output`);let $=B(e.output);if(e.dryRun){A({task_id:n,action:"download",out:i},$);return}let p=a(e.baseUrl,n),r=await Q(e,{url:p});if(r.output.task_status!=="SUCCEEDED")throw new u(`Task is not complete (status: ${r.output.task_status}).`,h.GENERAL,"Wait for the task to complete before downloading.");let y=r.output.video_url||r.output.results&&r.output.results[0]?.url;if(!y)throw new u("No download URL available for this task.",h.GENERAL);let{size:m}=await s(y,i,{quiet:e.quiet});if(e.quiet){N(i);return}A({saved:i,size:ue(m)},$)}});import{readFileSync as d$,existsSync as nn}from"fs";import{extname as $n}from"path";var s$={".jpg":"image/jpeg",".jpeg":"image/jpeg",".png":"image/png",".webp":"image/webp"},F$=new Set([".mp4",".mov",".avi",".mkv",".webm",".flv",".wmv"]);function rn(e){let t=$n(e).toLowerCase().split("?")[0];if(F$.has(t))return!0;if(/\.(mp4|mov|avi|mkv|webm|flv|wmv)(\?|$)/i.test(e))return!0;return!1}async function a$(e){if(e.startsWith("data:"))return e;if(e.startsWith("http://")||e.startsWith("https://"))return e;if(e.startsWith("oss://"))return e;if(!nn(e))throw new u(`File not found: ${e}`,h.USAGE);let t=$n(e).toLowerCase(),n=s$[t];if(!n)throw new u(`Unsupported image format "${t}". Supported: jpg, jpeg, png, webp`,h.USAGE);let i=d$(e);return`data:${n};base64,${i.toString("base64")}`}var pn=K({name:"vision describe",description:"Describe an image or video using Qwen-VL",usage:"bl vision describe --image <path-or-url> [--video <url>] [--prompt <text>]",options:[{flag:"--image <path-or-url>",description:"Local image path or URL"},{flag:"--video <url>",description:"Video file URL or local path (mp4/mov/avi/mkv/webm)",type:"array"},{flag:"--prompt <text>",description:"Question about the content (default: auto-detected)"},{flag:"--model <model>",description:"Vision model (default: qwen-vl-max)"}],examples:["bl vision describe --image photo.jpg",'bl vision describe --image https://example.com/photo.jpg --prompt "这只狗是什么品种?"','bl vision describe --video https://example.com/video.mp4 --prompt "总结视频内容"',"bl vision describe --video ./local-video.mp4",'bl vision describe --image photo.png --prompt "Extract the text" --model qwen-vl-plus'],async run(e,t){let n=t.image??t._positional?.[0],i=t.video??[],$=t.model||"qwen-vl-max";if(n&&rn(n))i.push(n),n=void 0;let p=i.length>0,r=p?"Describe the video.":"Describe the image.",y=t.prompt||r;if(!n&&!p)if(Y({nonInteractive:e.nonInteractive})){let k=await L({message:"Enter image/video path or URL:"});if(!k)process.stderr.write(`Vision describe cancelled.
181
+ `),process.exit(1);if(rn(k))i.push(k);else n=k}else throw new u("Missing required argument --image or --video.",h.USAGE,`bl vision describe --image <path-or-url>
182
+ bl vision describe --video <url-or-path>`);let m=B(e.output);if(e.dryRun){A({request:{prompt:y,image:n,video:i.length?i:void 0,model:$}},m);return}let x=[],b=!1;if(i.length>0)for(let k of i){let G=k;if(de(k)){if(!nn(k))throw new u(`Video file not found: ${k}`,h.USAGE);let z=await V(e);if(G=await E(k,z.token,$,e.quiet),G.startsWith("oss://"))b=!0}x.push({type:"video_url",video_url:{url:G}})}if(n){let k=await a$(n),G=k;if(de(n)&&k.startsWith("data:")){let{statSync:z}=await import("fs");if(z(n).size>5242880){let Z=await V(e);if(G=await E(n,Z.token,$,e.quiet),G.startsWith("oss://"))b=!0}}x.push({type:"image_url",image_url:{url:G}})}x.push({type:"text",text:y});let w={model:$,messages:[{role:"user",content:x}]},S=be(e.baseUrl),q=await Q(e,{url:S,method:"POST",body:w,ossResolve:b}),o=q.choices?.[0]?.message?.content;if(m!=="text"){A(q,m);return}N(o||"")}});var yn=K({name:"config show",description:"Display current configuration",usage:"bl config show",examples:["bl config show","bl config show --output json"],async run(e,t){let n=te(),i=B(e.output),$={region:e.region,base_url:e.baseUrl,output:e.output,timeout:e.timeout,config_file:ie()};if(n.api_key)$.api_key=g(n.api_key);if(n.default_text_model)$.default_text_model=n.default_text_model;if(n.default_video_model)$.default_video_model=n.default_video_model;if(n.default_image_model)$.default_image_model=n.default_image_model;A($,i)}});var _n=["region","base_url","output","output_dir","timeout","api_key","default_text_model","default_video_model","default_image_model","default_speech_model","default_omni_model","access_key_id","access_key_secret","workspace_id"],D$={"base-url":"base_url","output-dir":"output_dir","api-key":"api_key","default-text-model":"default_text_model","default-video-model":"default_video_model","default-image-model":"default_image_model","default-speech-model":"default_speech_model","default-omni-model":"default_omni_model","access-key-id":"access_key_id","access-key-secret":"access_key_secret","workspace-id":"workspace_id"},mn=K({name:"config set",description:"Set a config value",usage:"bl config set --key <key> --value <value>",options:[{flag:"--key <key>",description:"Config key (region, base_url, output, output_dir, timeout, api_key, default_*_model, access_key_id, access_key_secret, workspace_id)"},{flag:"--value <value>",description:"Value to set"}],examples:["bl config set --key output --value json","bl config set --key timeout --value 600","bl config set --key base_url --value https://dashscope.aliyuncs.com"],async run(e,t){let{key:n,value:i}=t;if(!n||i===void 0)throw new u("--key and --value are required.",h.USAGE,"bl config set --key <key> --value <value>");let $=D$[n]||n;if(!_n.includes($))throw new u(`Invalid config key "${n}". Valid keys: ${_n.join(", ")}`,h.USAGE);if($==="region"&&!["cn","us","intl"].includes(i))throw new u(`Invalid region "${i}". Valid values: cn, us, intl`,h.USAGE);if($==="output"&&!["text","json"].includes(i))throw new u(`Invalid output format "${i}". Valid values: text, json`,h.USAGE);if($==="timeout"){let y=Number(i);if(isNaN(y)||y<=0)throw new u(`Invalid timeout "${i}". Must be a positive number.`,h.USAGE)}let p=B(e.output);if(e.dryRun){A({would_set:{[$]:i}},p);return}let r=te();if(r[$]=$==="timeout"?Number(i):i,await Je(r),!e.quiet)A({[$]:r[$]},p)}});function l$(e){let t=e.match(/^--([a-zA-Z0-9-]+)/),n=t?t[1]:"",i=n.replace(/-([a-zA-Z0-9])/g,(r,y)=>y.toUpperCase()),$="string",p=!1;if(!e.includes("<")&&!e.includes("["))$="boolean";else if(e.includes("<n>")||e.includes("<hz>")||e.includes("<bps>")||e.includes("<count>"))$="number";if(e.toLowerCase().includes("repeatable"))p=!0;return{name:i,kebabName:n,inferredType:$,isArray:p}}function Ht(e){let n={name:`bailian_${e.name.replace(/ /g,"_")}`,description:e.description,input_schema:{type:"object",properties:{},required:[]}};if(e.options)for(let i of e.options){let{name:$,inferredType:p,isArray:r}=l$(i.flag);if(!$)continue;let y=i.type,m=r?"array":y??p,x={description:i.description};if(m==="array")x.type="array",x.items={type:"string"};else x.type=m;let b=n.input_schema;if(b.properties[$]=x,i.required)b.required.push($)}return n}var f$=["auth ","config ","update"],xn=K({name:"config export-schema",description:"Export all (or one) CLI command(s) as Anthropic/OpenAI-compatible JSON tool schemas",usage:'bl config export-schema [--command "<name>"]',options:[{flag:"--command <name>",description:'Export schema for a specific command only (e.g. "image generate")'}],examples:["bl config export-schema",'bl config export-schema --command "video generate"'],async run(e,t){let n=t.command;if(n){try{let{command:p}=me.resolve(n.split(" ")),r=Ht(p);process.stdout.write(JSON.stringify(r,null,2)+`
183
+ `)}catch{throw new u(`Command "${n}" not found.`,h.USAGE)}return}let $=me.getAllCommands().filter((p)=>!f$.some((r)=>p.name.startsWith(r))).map((p)=>Ht(p));process.stdout.write(JSON.stringify($,null,2)+`
184
+ `)}});import{execSync as bn}from"child_process";import{writeFileSync as g$}from"fs";import{join as ep}from"path";var ae="0.1.2-beta.0";async function tp(){try{let e=Be.replace("/","%2f"),t=await fetch(`${He}/${e}/latest`,{headers:{Accept:"application/json",...d()},signal:AbortSignal.timeout(5000)});if(!t.ok)return null;return(await t.json()).version??null}catch{return null}}function rp(e="latest"){return{cmd:`npm install -g ${Be}@${e} --registry=${He}`,label:"npm"}}var wn=K({name:"update",description:"Update bl to the latest version",usage:"bl update",examples:["bl update"],async run(){let e=process.stderr.isTTY,t=e?"\x1B[32m":"",n=e?"\x1B[33m":"",i=e?"\x1B[0m":"";process.stderr.write(`Current version: ${n}${ae}${i}
185
185
  `),process.stderr.write(`Checking for updates...
186
- `);let $=await ip();if($&&$===ae){process.stderr.write(`${t}✓ Already up to date (${ae}).${i}
186
+ `);let $=await tp();if($&&$===ae){process.stderr.write(`${t}✓ Already up to date (${ae}).${i}
187
187
  `);return}if($)process.stderr.write(`Latest version: ${t}${$}${i}
188
188
 
189
- `);let{cmd:p,label:r}=$p();process.stderr.write(`Updating ${Ke} via ${r}...
189
+ `);let{cmd:p,label:r}=rp($||"latest");process.stderr.write(`Updating ${Be} via ${r}...
190
190
 
191
- `);try{xn(p,{stdio:"inherit"});try{let _=xn("bl --version 2>/dev/null",{encoding:"utf-8"}).trim().replace(/^bl\s+/,"");process.stderr.write(`
192
- ${t}✓ Update complete: ${ae} → ${_}${i}
193
- `);try{let x=np(je(),"update-state.json");rp(x,JSON.stringify({lastChecked:Date.now(),latestVersion:_}))}catch{}}catch{process.stderr.write(`
191
+ `);try{bn(p,{stdio:"inherit"});try{let m=bn("bl --version 2>/dev/null",{encoding:"utf-8"}).trim().replace(/^bl\s+/,"");process.stderr.write(`
192
+ ${t}✓ Update complete: ${ae} → ${m}${i}
193
+ `);try{let x=ep(Re(),"update-state.json");g$(x,JSON.stringify({lastChecked:Date.now(),latestVersion:m}))}catch{}}catch{process.stderr.write(`
194
194
  ${t}✓ Update complete.${i}
195
195
  `)}}catch{process.stderr.write(`
196
196
  Automatic update failed. Please run manually:
197
197
  `),process.stderr.write(` ${p}
198
198
 
199
- `)}}});var pp=[{command:"bl text chat",title:"Text Generation (Chat Completion)",path:"/best-practice/qwen/chat"},{command:"bl image generate",title:"Image Generation (万相文生图)",path:"/best-practice/wanx/text-to-image"},{command:"bl video generate",title:"Video Generation (万相文生视频)",path:"/best-practice/wanx/text-to-video"},{command:"bl vision describe",title:"Vision (Image Understanding)",path:"/best-practice/qwen/qwen-vl"}],wn=q({name:"help",description:"Show Bailian API documentation links",usage:"bl help",async run(e,t){let n=Me[e.region]||Me.cn;process.stdout.write(`
199
+ `)}}});var np=[{command:"bl text chat",title:"Text Generation (Chat Completion)",path:"/best-practice/qwen/chat"},{command:"bl image generate",title:"Image Generation (万相文生图)",path:"/best-practice/wanx/text-to-image"},{command:"bl video generate",title:"Video Generation (万相文生视频)",path:"/best-practice/wanx/text-to-video"},{command:"bl vision describe",title:"Vision (Image Understanding)",path:"/best-practice/qwen/qwen-vl"}],hn=K({name:"help",description:"Show Bailian API documentation links",usage:"bl help",async run(e,t){let n=Qe[e.region]||Qe.cn;process.stdout.write(`
200
200
  Bailian (百炼) API Documentation Links
201
201
 
202
202
  Official docs: ${n}
203
203
  Console: https://bailian.console.aliyun.com/
204
204
  Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key
205
205
 
206
- `);for(let i of pp)process.stdout.write(` ${i.command.padEnd(30)} ${i.title}
206
+ `);for(let i of np)process.stdout.write(` ${i.command.padEnd(30)} ${i.title}
207
207
  `),process.stdout.write(` ${" ".repeat(30)} ${n}${i.path}
208
208
 
209
- `)}});var un=q({name:"app call",description:"Call a Bailian application (agent or workflow)",usage:"bl app call --app-id <id> --prompt <text> [flags]",options:[{flag:"--app-id <id>",description:"Application ID (required)",required:!0},{flag:"--prompt <text>",description:"Input prompt text",required:!0},{flag:"--image <url>",description:"Image URL(s) to pass to the app (repeatable)",type:"array"},{flag:"--file-id <id>",description:"Pre-uploaded file ID(s) (repeatable)",type:"array"},{flag:"--session-id <id>",description:"Session ID for multi-turn conversation"},{flag:"--stream",description:"Stream response (default: on in TTY)"},{flag:"--pipeline-ids <ids>",description:"Knowledge base pipeline IDs (comma-separated)"},{flag:"--memory-id <id>",description:"Memory ID for long-term memory"},{flag:"--biz-params <json>",description:"Business parameters JSON (workflow variables)"},{flag:"--has-thoughts",description:"Show agent thinking process"}],examples:['bl app call --app-id abc123 --prompt "你好"','bl app call --app-id abc123 --prompt "描述这张图片" --image https://example.com/photo.jpg','bl app call --app-id abc123 --prompt "分析图片" --image img1.jpg --image img2.jpg','bl app call --app-id abc123 --prompt "继续" --session-id sess_xxx --stream','bl app call --app-id abc123 --prompt "搜索资料" --pipeline-ids pipe1,pipe2',`bl app call --app-id abc123 --prompt "开始" --biz-params '{"key":"value"}'`],async run(e,t){let n=t.appId;if(!n)R("app-id","bl app call --app-id <id> --prompt <text>");let i=t.prompt;if(!i)R("prompt","bl app call --app-id <id> --prompt <text>");let $=t.stream===!0||t.stream===void 0&&process.stdout.isTTY,p=B(e.output),r={input:{prompt:i},parameters:{incremental_output:$}};if(t.sessionId)r.input.session_id=t.sessionId;let m=t.image;if(m&&m.length>0)r.input.image_list=m;let _=t.fileId;if(_&&_.length>0)r.input.file_ids=_;if(t.hasThoughts)r.parameters.has_thoughts=!0;if(t.pipelineIds){let b=t.pipelineIds.split(",").map((w)=>w.trim()).filter(Boolean);r.parameters.rag_options={pipeline_ids:b}}if(t.memoryId)r.parameters.memory_id=t.memoryId;if(t.bizParams)try{r.input.biz_params=JSON.parse(t.bizParams)}catch{process.stderr.write(`Error: --biz-params must be valid JSON
210
- `),process.exit(1)}if(e.dryRun){h({endpoint:nt(e.baseUrl,n),request:r},p);return}let x=nt(e.baseUrl,n);if($){let w=await pe(e,{url:x,method:"POST",body:r,headers:{"X-DashScope-SSE":"enable"},stream:!0}),u="",k="",j=e.noColor?"":"\x1B[2m",A=e.noColor?"":"\x1B[0m";for await(let K of we(w)){if(K.data==="[DONE]")break;try{let Z=JSON.parse(K.data),X=Z.output?.text;if(X)process.stdout.write(X),u+=X;if(Z.output?.session_id)k=Z.output.session_id;if(Z.output?.thoughts&&t.hasThoughts)for(let H of Z.output.thoughts){if(H.thought)process.stderr.write(`${j}[Thinking] ${H.thought}${A}
211
- `);if(H.action_name)process.stderr.write(`${j}[Action] ${H.action_name}: ${H.action_input||""}${A}
212
- `);if(H.observation)process.stderr.write(`${j}[Observation] ${H.observation}${A}
213
- `)}}catch{}}if(process.stdout.write(`
214
- `),k&&!e.quiet)process.stderr.write(`${j}Session ID: ${k}${A}
215
- `);if(p==="json")h({text:u,session_id:k},p)}else{let b=await W(e,{url:x,method:"POST",body:r}),w=b.output?.text??"";if(e.quiet||p==="text")G(w);else h(b,p)}}});var hn=q({name:"memory add",description:"Add memory from messages or custom content",usage:"bl memory add --user-id <id> [--messages <json>] [--content <text>] [flags]",options:[{flag:"--user-id <id>",description:"User ID (required)",required:!0},{flag:"--messages <json>",description:'Messages JSON array: [{"role":"user","content":"..."},...]'},{flag:"--content <text>",description:"Custom content text to memorize"},{flag:"--profile-schema <id>",description:"Profile schema ID for user profiling"},{flag:"--memory-library-id <id>",description:"Memory library ID (isolate memory space)"}],examples:['bl memory add --user-id user1 --content "用户喜欢Python编程"',`bl memory add --user-id user1 --messages '[{"role":"user","content":"我喜欢旅行"}]'`,'bl memory add --user-id user1 --content "住在北京" --profile-schema schema_xxx'],async run(e,t){let n=t.userId;if(!n)R("user-id","bl memory add --user-id <id>");let i={user_id:n};if(t.messages)try{i.messages=JSON.parse(t.messages)}catch{process.stderr.write(`Error: --messages must be valid JSON array
209
+ `)}});var An=K({name:"app call",description:"Call a Bailian application (agent or workflow)",usage:"bl app call --app-id <id> --prompt <text> [flags]",options:[{flag:"--app-id <id>",description:"Application ID (required)",required:!0},{flag:"--prompt <text>",description:"Input prompt text",required:!0},{flag:"--image <url>",description:"Image URL(s) to pass to the app (repeatable)",type:"array"},{flag:"--file-id <id>",description:"Pre-uploaded file ID(s) (repeatable)",type:"array"},{flag:"--session-id <id>",description:"Session ID for multi-turn conversation"},{flag:"--stream",description:"Stream response (default: on in TTY)"},{flag:"--pipeline-ids <ids>",description:"Knowledge base pipeline IDs (comma-separated)"},{flag:"--memory-id <id>",description:"Memory ID for long-term memory"},{flag:"--biz-params <json>",description:"Business parameters JSON (workflow variables)"},{flag:"--has-thoughts",description:"Show agent thinking process"}],examples:['bl app call --app-id abc123 --prompt "你好"','bl app call --app-id abc123 --prompt "描述这张图片" --image https://example.com/photo.jpg','bl app call --app-id abc123 --prompt "分析图片" --image img1.jpg --image img2.jpg','bl app call --app-id abc123 --prompt "继续" --session-id sess_xxx --stream','bl app call --app-id abc123 --prompt "搜索资料" --pipeline-ids pipe1,pipe2',`bl app call --app-id abc123 --prompt "开始" --biz-params '{"key":"value"}'`],async run(e,t){let n=t.appId;if(!n)W("app-id","bl app call --app-id <id> --prompt <text>");let i=t.prompt;if(!i)W("prompt","bl app call --app-id <id> --prompt <text>");let $=t.stream===!0||t.stream===void 0&&process.stdout.isTTY,p=B(e.output),r={input:{prompt:i},parameters:{incremental_output:$}};if(t.sessionId)r.input.session_id=t.sessionId;let y=t.image;if(y&&y.length>0)r.input.image_list=y;let m=t.fileId;if(m&&m.length>0)r.input.file_ids=m;if(t.hasThoughts)r.parameters.has_thoughts=!0;if(t.pipelineIds){let b=t.pipelineIds.split(",").map((w)=>w.trim()).filter(Boolean);r.parameters.rag_options={pipeline_ids:b}}if(t.memoryId)r.parameters.memory_id=t.memoryId;if(t.bizParams)try{r.input.biz_params=JSON.parse(t.bizParams)}catch{process.stderr.write(`Error: --biz-params must be valid JSON
210
+ `),process.exit(1)}if(e.dryRun){A({endpoint:nt(e.baseUrl,n),request:r},p);return}let x=nt(e.baseUrl,n);if($){let w=await ye(e,{url:x,method:"POST",body:r,headers:{"X-DashScope-SSE":"enable"},stream:!0}),S="",q="",o=p==="text",k=e.noColor?"":"\x1B[2m",G=e.noColor?"":"\x1B[0m";for await(let z of Ae(w)){if(z.data==="[DONE]")break;try{let J=JSON.parse(z.data),Z=J.output?.text;if(Z){if(o)process.stdout.write(Z);S+=Z}if(J.output?.session_id)q=J.output.session_id;if(J.output?.thoughts&&t.hasThoughts)for(let j of J.output.thoughts){if(j.thought)process.stderr.write(`${k}[Thinking] ${j.thought}${G}
211
+ `);if(j.action_name)process.stderr.write(`${k}[Action] ${j.action_name}: ${j.action_input||""}${G}
212
+ `);if(j.observation)process.stderr.write(`${k}[Observation] ${j.observation}${G}
213
+ `)}}catch{}}if(q&&!e.quiet)process.stderr.write(`${k}Session ID: ${q}${G}
214
+ `);if(p==="json")A({text:S,session_id:q},p);else process.stdout.write(`
215
+ `)}else{let b=await Q(e,{url:x,method:"POST",body:r}),w=b.output?.text??"";if(e.quiet||p==="text")N(w);else A(b,p)}}});var un=K({name:"memory add",description:"Add memory from messages or custom content",usage:"bl memory add --user-id <id> [--messages <json>] [--content <text>] [flags]",options:[{flag:"--user-id <id>",description:"User ID (required)",required:!0},{flag:"--messages <json>",description:'Messages JSON array: [{"role":"user","content":"..."},...]'},{flag:"--content <text>",description:"Custom content text to memorize"},{flag:"--profile-schema <id>",description:"Profile schema ID for user profiling"},{flag:"--memory-library-id <id>",description:"Memory library ID (isolate memory space)"}],examples:['bl memory add --user-id user1 --content "用户喜欢Python编程"',`bl memory add --user-id user1 --messages '[{"role":"user","content":"我喜欢旅行"}]'`,'bl memory add --user-id user1 --content "住在北京" --profile-schema schema_xxx'],async run(e,t){let n=t.userId;if(!n)W("user-id","bl memory add --user-id <id>");let i={user_id:n};if(t.messages)try{i.messages=JSON.parse(t.messages)}catch{process.stderr.write(`Error: --messages must be valid JSON array
216
216
  `),process.exit(1)}if(t.content)i.custom_content=t.content;if(!i.messages&&!i.custom_content)process.stderr.write(`Error: at least one of --messages or --content is required
217
- `),process.exit(1);if(t.profileSchema)i.profile_schema=t.profileSchema;if(t.memoryLibraryId)i.memory_library_id=t.memoryLibraryId;let $=B(e.output);if(e.dryRun){h({endpoint:it(e.baseUrl),request:i},$);return}let p=it(e.baseUrl),r=await W(e,{url:p,method:"POST",body:i});if(e.quiet||$==="text"){let m=r.memory_ids?.join(", ")||"none";G(`Memory added. IDs: ${m}`)}else h(r,$)}});var on=q({name:"memory search",description:"Search memory nodes by query or messages",usage:"bl memory search --user-id <id> [--query <text>] [flags]",options:[{flag:"--user-id <id>",description:"User ID (required)",required:!0},{flag:"--query <text>",description:"Search query text"},{flag:"--messages <json>",description:"Messages JSON array for context-based search"},{flag:"--top-k <n>",description:"Number of results to return (default: 10)",type:"number"},{flag:"--memory-library-id <id>",description:"Memory library ID"}],examples:['bl memory search --user-id user1 --query "编程偏好"',`bl memory search --user-id user1 --messages '[{"role":"user","content":"推荐一本书"}]' --top-k 5`],async run(e,t){let n=t.userId;if(!n)R("user-id","bl memory search --user-id <id>");let i={user_id:n};if(t.query)i.query=t.query;if(t.messages)try{i.messages=JSON.parse(t.messages)}catch{process.stderr.write(`Error: --messages must be valid JSON array
217
+ `),process.exit(1);if(t.profileSchema)i.profile_schema=t.profileSchema;if(t.memoryLibraryId)i.memory_library_id=t.memoryLibraryId;let $=B(e.output);if(e.dryRun){A({endpoint:it(e.baseUrl),request:i},$);return}let p=it(e.baseUrl),r=await Q(e,{url:p,method:"POST",body:i});if(e.quiet||$==="text"){let y=r.memory_ids?.join(", ")||"none";N(`Memory added. IDs: ${y}`)}else A(r,$)}});var Sn=K({name:"memory search",description:"Search memory nodes by query or messages",usage:"bl memory search --user-id <id> [--query <text>] [flags]",options:[{flag:"--user-id <id>",description:"User ID (required)",required:!0},{flag:"--query <text>",description:"Search query text"},{flag:"--messages <json>",description:"Messages JSON array for context-based search"},{flag:"--top-k <n>",description:"Number of results to return (default: 10)",type:"number"},{flag:"--memory-library-id <id>",description:"Memory library ID"}],examples:['bl memory search --user-id user1 --query "编程偏好"',`bl memory search --user-id user1 --messages '[{"role":"user","content":"推荐一本书"}]' --top-k 5`],async run(e,t){let n=t.userId;if(!n)W("user-id","bl memory search --user-id <id>");let i={user_id:n};if(t.query)i.query=t.query;if(t.messages)try{i.messages=JSON.parse(t.messages)}catch{process.stderr.write(`Error: --messages must be valid JSON array
218
218
  `),process.exit(1)}if(!i.messages&&i.query)i.messages=[{role:"user",content:i.query}];if(!i.query&&!i.messages)process.stderr.write(`Error: at least one of --query or --messages is required
219
- `),process.exit(1);if(t.topK!==void 0)i.top_k=t.topK;if(t.memoryLibraryId)i.memory_library_id=t.memoryLibraryId;let $=B(e.output);if(e.dryRun){h({endpoint:$t(e.baseUrl),request:i},$);return}let p=$t(e.baseUrl),r=await W(e,{url:p,method:"POST",body:i});if(e.quiet||$==="text")if(!r.memory_nodes||r.memory_nodes.length===0)G("No memory nodes found.");else for(let m of r.memory_nodes)G(`[${m.memory_node_id}] ${m.content}`);else h(r,$)}});var Sn=q({name:"memory list",description:"List memory nodes for a user",usage:"bl memory list --user-id <id> [flags]",options:[{flag:"--user-id <id>",description:"User ID (required)",required:!0},{flag:"--page-size <n>",description:"Results per page (default: 10)",type:"number"},{flag:"--page-num <n>",description:"Page number (default: 1)",type:"number"},{flag:"--memory-library-id <id>",description:"Memory library ID"}],examples:["bl memory list --user-id user1","bl memory list --user-id user1 --page-size 20 --page-num 2"],async run(e,t){let n=t.userId;if(!n)R("user-id","bl memory list --user-id <id>");let i=B(e.output),$=new URLSearchParams;if($.set("user_id",n),t.pageSize!==void 0)$.set("page_size",String(t.pageSize));if(t.pageNum!==void 0)$.set("page_num",String(t.pageNum));if(t.memoryLibraryId)$.set("memory_library_id",t.memoryLibraryId);let p=`${It(e.baseUrl)}?${$.toString()}`;if(e.dryRun){h({endpoint:p,method:"GET"},i);return}let r=await W(e,{url:p,method:"GET"});if(e.quiet||i==="text")if(!r.memory_nodes||r.memory_nodes.length===0)G("No memory nodes found.");else{for(let m of r.memory_nodes)G(`[${m.memory_node_id}] ${m.content}`);if(r.total!==void 0)G(`
220
- Total: ${r.total}`)}else h(r,i)}});var An=q({name:"memory update",description:"Update a memory node content",usage:"bl memory update --node-id <id> --user-id <id> --content <text>",options:[{flag:"--node-id <id>",description:"Memory node ID (required)",required:!0},{flag:"--user-id <id>",description:"User ID (required)",required:!0},{flag:"--content <text>",description:"New content for the memory node (required)",required:!0}],examples:['bl memory update --node-id node_xxx --user-id user1 --content "更新后的记忆内容"'],async run(e,t){let n=t.nodeId;if(!n)R("node-id","bl memory update --node-id <id> --user-id <id> --content <text>");let i=t.userId;if(!i)R("user-id","bl memory update --node-id <id> --user-id <id> --content <text>");let $=t.content;if(!$)R("content","bl memory update --node-id <id> --user-id <id> --content <text>");let p={user_id:i,custom_content:$},r=B(e.output);if(e.dryRun){h({endpoint:Qe(e.baseUrl,n),method:"PATCH",request:p},r);return}let m=Qe(e.baseUrl,n),_=await W(e,{url:m,method:"PATCH",body:p});if(e.quiet||r==="text")G(`Memory node ${n} updated.`);else h(_,r)}});var kn=q({name:"memory delete",description:"Delete a memory node",usage:"bl memory delete --node-id <id> --user-id <id>",options:[{flag:"--node-id <id>",description:"Memory node ID (required)",required:!0},{flag:"--user-id <id>",description:"User ID (required)",required:!0}],examples:["bl memory delete --node-id node_xxx --user-id user1"],async run(e,t){let n=t.nodeId;if(!n)R("node-id","bl memory delete --node-id <id> --user-id <id>");let i=t.userId;if(!i)R("user-id","bl memory delete --node-id <id> --user-id <id>");let $=B(e.output),p=new URLSearchParams({user_id:i}),r=`${Qe(e.baseUrl,n)}?${p.toString()}`;if(e.dryRun){h({endpoint:r,method:"DELETE"},$);return}let m=await W(e,{url:r,method:"DELETE"});if(e.quiet||$==="text")G(`Memory node ${n} deleted.`);else h(m,$)}});var qn=q({name:"memory profile create",description:"Create a user profile schema for memory profiling",usage:"bl memory profile create --name <name> --attributes <json> [flags]",options:[{flag:"--name <name>",description:"Schema name (required)",required:!0},{flag:"--description <text>",description:"Schema description"},{flag:"--attributes <json>",description:'Attributes JSON array: [{"name":"age","description":"年龄"}]',required:!0}],examples:[`bl memory profile create --name "user_basic" --attributes '[{"name":"age","description":"年龄"},{"name":"hobby","description":"爱好"}]'`],async run(e,t){let n=t.name;if(!n)R("name","bl memory profile create --name <name> --attributes <json>");let i=t.attributes;if(!i)R("attributes","bl memory profile create --name <name> --attributes <json>");let $;try{$=JSON.parse(i)}catch{process.stderr.write(`Error: --attributes must be valid JSON array
221
- `),process.exit(1)}let p={name:n,attributes:$};if(t.description)p.description=t.description;let r=B(e.output);if(e.dryRun){h({endpoint:pt(e.baseUrl),request:p},r);return}let m=pt(e.baseUrl),_=await W(e,{url:m,method:"POST",body:p});if(e.quiet||r==="text")G(`Profile schema created: ${_.profile_schema_id}`);else h(_,r)}});var Gn=q({name:"memory profile get",description:"Get user profile by schema ID and user ID",usage:"bl memory profile get --schema-id <id> --user-id <id>",options:[{flag:"--schema-id <id>",description:"Profile schema ID (required)",required:!0},{flag:"--user-id <id>",description:"User ID (required)",required:!0}],examples:["bl memory profile get --schema-id schema_xxx --user-id user1"],async run(e,t){let n=t.schemaId;if(!n)R("schema-id","bl memory profile get --schema-id <id> --user-id <id>");let i=t.userId;if(!i)R("user-id","bl memory profile get --schema-id <id> --user-id <id>");let $=B(e.output),p=new URLSearchParams({user_id:i}),r=`${st(e.baseUrl,n)}?${p.toString()}`;if(e.dryRun){h({endpoint:r,method:"GET"},$);return}let m=await W(e,{url:r,method:"GET"});if(e.quiet||$==="text")if(m.profile?.attributes)for(let _ of m.profile.attributes)G(`${_.name}: ${_.value??"(empty)"}`);else G("No profile data found.");else h(m,$)}});import{createHmac as mp,createHash as yp,randomUUID as _p}from"crypto";function Kn(e){let t=e.method??"POST",i=new Date().toISOString().replace(/\.\d{3}Z$/,"Z"),$=_p(),p=Bn(e.body),r={host:e.host,"x-acs-action":e.action,"x-acs-version":e.version,"x-acs-date":i,"x-acs-signature-nonce":$,"x-acs-content-sha256":p,"content-type":"application/json"},m=Object.keys(r).filter((A)=>A==="host"||A==="content-type"||A.startsWith("x-acs-")).sort(),_=m.map((A)=>`${A}:${r[A]}`).join(`
219
+ `),process.exit(1);if(t.topK!==void 0)i.top_k=t.topK;if(t.memoryLibraryId)i.memory_library_id=t.memoryLibraryId;let $=B(e.output);if(e.dryRun){A({endpoint:$t(e.baseUrl),request:i},$);return}let p=$t(e.baseUrl),r=await Q(e,{url:p,method:"POST",body:i});if(e.quiet||$==="text")if(!r.memory_nodes||r.memory_nodes.length===0)N("No memory nodes found.");else for(let y of r.memory_nodes)N(`[${y.memory_node_id}] ${y.content}`);else A(r,$)}});var kn=K({name:"memory list",description:"List memory nodes for a user",usage:"bl memory list --user-id <id> [flags]",options:[{flag:"--user-id <id>",description:"User ID (required)",required:!0},{flag:"--page-size <n>",description:"Results per page (default: 10)",type:"number"},{flag:"--page-num <n>",description:"Page number (default: 1)",type:"number"},{flag:"--memory-library-id <id>",description:"Memory library ID"}],examples:["bl memory list --user-id user1","bl memory list --user-id user1 --page-size 20 --page-num 2"],async run(e,t){let n=t.userId;if(!n)W("user-id","bl memory list --user-id <id>");let i=B(e.output),$=new URLSearchParams;if($.set("user_id",n),t.pageSize!==void 0)$.set("page_size",String(t.pageSize));if(t.pageNum!==void 0)$.set("page_num",String(t.pageNum));if(t.memoryLibraryId)$.set("memory_library_id",t.memoryLibraryId);let p=`${vt(e.baseUrl)}?${$.toString()}`;if(e.dryRun){A({endpoint:p,method:"GET"},i);return}let r=await Q(e,{url:p,method:"GET"});if(e.quiet||i==="text")if(!r.memory_nodes||r.memory_nodes.length===0)N("No memory nodes found.");else{for(let y of r.memory_nodes)N(`[${y.memory_node_id}] ${y.content}`);if(r.total!==void 0)N(`
220
+ Total: ${r.total}`)}else A(r,i)}});var qn=K({name:"memory update",description:"Update a memory node content",usage:"bl memory update --node-id <id> --user-id <id> --content <text>",options:[{flag:"--node-id <id>",description:"Memory node ID (required)",required:!0},{flag:"--user-id <id>",description:"User ID (required)",required:!0},{flag:"--content <text>",description:"New content for the memory node (required)",required:!0}],examples:['bl memory update --node-id node_xxx --user-id user1 --content "更新后的记忆内容"'],async run(e,t){let n=t.nodeId;if(!n)W("node-id","bl memory update --node-id <id> --user-id <id> --content <text>");let i=t.userId;if(!i)W("user-id","bl memory update --node-id <id> --user-id <id> --content <text>");let $=t.content;if(!$)W("content","bl memory update --node-id <id> --user-id <id> --content <text>");let p={user_id:i,custom_content:$},r=B(e.output);if(e.dryRun){A({endpoint:Ze(e.baseUrl,n),method:"PATCH",request:p},r);return}let y=Ze(e.baseUrl,n),m=await Q(e,{url:y,method:"PATCH",body:p});if(e.quiet||r==="text")N(`Memory node ${n} updated.`);else A(m,r)}});var on=K({name:"memory delete",description:"Delete a memory node",usage:"bl memory delete --node-id <id> --user-id <id>",options:[{flag:"--node-id <id>",description:"Memory node ID (required)",required:!0},{flag:"--user-id <id>",description:"User ID (required)",required:!0}],examples:["bl memory delete --node-id node_xxx --user-id user1"],async run(e,t){let n=t.nodeId;if(!n)W("node-id","bl memory delete --node-id <id> --user-id <id>");let i=t.userId;if(!i)W("user-id","bl memory delete --node-id <id> --user-id <id>");let $=B(e.output),p=new URLSearchParams({user_id:i}),r=`${Ze(e.baseUrl,n)}?${p.toString()}`;if(e.dryRun){A({endpoint:r,method:"DELETE"},$);return}let y=await Q(e,{url:r,method:"DELETE"});if(e.quiet||$==="text")N(`Memory node ${n} deleted.`);else A(y,$)}});var Gn=K({name:"memory profile create",description:"Create a user profile schema for memory profiling",usage:"bl memory profile create --name <name> --attributes <json> [flags]",options:[{flag:"--name <name>",description:"Schema name (required)",required:!0},{flag:"--description <text>",description:"Schema description"},{flag:"--attributes <json>",description:'Attributes JSON array: [{"name":"age","description":"年龄"}]',required:!0}],examples:[`bl memory profile create --name "user_basic" --attributes '[{"name":"age","description":"年龄"},{"name":"hobby","description":"爱好"}]'`],async run(e,t){let n=t.name;if(!n)W("name","bl memory profile create --name <name> --attributes <json>");let i=t.attributes;if(!i)W("attributes","bl memory profile create --name <name> --attributes <json>");let $;try{$=JSON.parse(i)}catch{process.stderr.write(`Error: --attributes must be valid JSON array
221
+ `),process.exit(1)}let p={name:n,attributes:$};if(t.description)p.description=t.description;let r=B(e.output);if(e.dryRun){A({endpoint:pt(e.baseUrl),request:p},r);return}let y=pt(e.baseUrl),m=await Q(e,{url:y,method:"POST",body:p});if(e.quiet||r==="text")N(`Profile schema created: ${m.profile_schema_id}`);else A(m,r)}});var Kn=K({name:"memory profile get",description:"Get user profile by schema ID and user ID",usage:"bl memory profile get --schema-id <id> --user-id <id>",options:[{flag:"--schema-id <id>",description:"Profile schema ID (required)",required:!0},{flag:"--user-id <id>",description:"User ID (required)",required:!0}],examples:["bl memory profile get --schema-id schema_xxx --user-id user1"],async run(e,t){let n=t.schemaId;if(!n)W("schema-id","bl memory profile get --schema-id <id> --user-id <id>");let i=t.userId;if(!i)W("user-id","bl memory profile get --schema-id <id> --user-id <id>");let $=B(e.output),p=new URLSearchParams({user_id:i}),r=`${st(e.baseUrl,n)}?${p.toString()}`;if(e.dryRun){A({endpoint:r,method:"GET"},$);return}let y=await Q(e,{url:r,method:"GET"});if(e.quiet||$==="text")if(y.profile?.attributes)for(let m of y.profile.attributes)N(`${m.name}: ${m.value??"(empty)"}`);else N("No profile data found.");else A(y,$)}});import{createHmac as ip,createHash as $p,randomUUID as pp}from"crypto";function Bn(e){let t=e.method??"POST",i=new Date().toISOString().replace(/\.\d{3}Z$/,"Z"),$=pp(),p=Nn(e.body),r={host:e.host,"x-acs-action":e.action,"x-acs-version":e.version,"x-acs-date":i,"x-acs-signature-nonce":$,"x-acs-content-sha256":p,"content-type":"application/json"},y=Object.keys(r).filter((k)=>k==="host"||k==="content-type"||k.startsWith("x-acs-")).sort(),m=y.map((k)=>`${k}:${r[k]}`).join(`
222
222
  `)+`
223
- `,x=m.join(";"),b=[t,e.pathname,"",_,x,p].join(`
224
- `),w="ACS3-HMAC-SHA256",k=`ACS3-HMAC-SHA256
225
- ${Bn(b)}`,j=xp(e.accessKeySecret,k);return r.authorization=`ACS3-HMAC-SHA256 Credential=${e.accessKeyId},SignedHeaders=${x},Signature=${j}`,r}function Bn(e){return yp("sha256").update(e,"utf8").digest("hex")}function xp(e,t){return mp("sha256",e).update(t,"utf8").digest("hex")}var ct="bailian.cn-beijing.aliyuncs.com",Nn=q({name:"knowledge retrieve",description:"Retrieve from a Bailian knowledge base (requires AK/SK)",usage:"bl knowledge retrieve --index-id <id> --query <text> [flags]",options:[{flag:"--index-id <id>",description:"Knowledge base index ID (required)",required:!0},{flag:"--query <text>",description:"Search query (required)",required:!0},{flag:"--workspace-id <id>",description:"Bailian workspace ID (or env BAILIAN_WORKSPACE_ID)"},{flag:"--top-k <n>",description:"Number of results (default: 10)",type:"number"},{flag:"--rerank",description:"Enable rerank"},{flag:"--rerank-top-n <n>",description:"Rerank top N results",type:"number"},{flag:"--access-key-id <key>",description:"Alibaba Cloud Access Key ID (or env)"},{flag:"--access-key-secret <key>",description:"Alibaba Cloud Access Key Secret (or env)"}],examples:['bl knowledge retrieve --index-id idx_xxx --query "如何使用百炼" --workspace-id ws_xxx','bl knowledge retrieve --index-id idx_xxx --query "API限流" --top-k 5 --rerank'],async run(e,t){let n=t.indexId;if(!n)R("index-id","bl knowledge retrieve --index-id <id> --query <text>");let i=t.query;if(!i)R("query","bl knowledge retrieve --index-id <id> --query <text>");let $=t.accessKeyId||e.accessKeyId,p=t.accessKeySecret||e.accessKeySecret,r=t.workspaceId||e.workspaceId;if(!$||!p)throw new S(`Knowledge retrieve requires Alibaba Cloud AK/SK.
223
+ `,x=y.join(";"),b=[t,e.pathname,"",m,x,p].join(`
224
+ `),w="ACS3-HMAC-SHA256",q=`ACS3-HMAC-SHA256
225
+ ${Nn(b)}`,o=yp(e.accessKeySecret,q);return r.authorization=`ACS3-HMAC-SHA256 Credential=${e.accessKeyId},SignedHeaders=${x},Signature=${o}`,r}function Nn(e){return $p("sha256").update(e,"utf8").digest("hex")}function yp(e,t){return ip("sha256",e).update(t,"utf8").digest("hex")}var Zt="bailian.cn-beijing.aliyuncs.com",jn=K({name:"knowledge retrieve",description:"Retrieve from a Bailian knowledge base (requires AK/SK)",usage:"bl knowledge retrieve --index-id <id> --query <text> [flags]",options:[{flag:"--index-id <id>",description:"Knowledge base index ID (required)",required:!0},{flag:"--query <text>",description:"Search query (required)",required:!0},{flag:"--workspace-id <id>",description:"Bailian workspace ID (or env BAILIAN_WORKSPACE_ID)"},{flag:"--top-k <n>",description:"Number of results (default: 10)",type:"number"},{flag:"--rerank",description:"Enable rerank"},{flag:"--rerank-top-n <n>",description:"Rerank top N results",type:"number"},{flag:"--access-key-id <key>",description:"Alibaba Cloud Access Key ID (or env)"},{flag:"--access-key-secret <key>",description:"Alibaba Cloud Access Key Secret (or env)"}],examples:['bl knowledge retrieve --index-id idx_xxx --query "如何使用百炼" --workspace-id ws_xxx','bl knowledge retrieve --index-id idx_xxx --query "API限流" --top-k 5 --rerank'],async run(e,t){let n=t.indexId;if(!n)W("index-id","bl knowledge retrieve --index-id <id> --query <text>");let i=t.query;if(!i)W("query","bl knowledge retrieve --index-id <id> --query <text>");let $=t.accessKeyId||e.accessKeyId,p=t.accessKeySecret||e.accessKeySecret,r=t.workspaceId||e.workspaceId;if(!$||!p)throw new u(`Knowledge retrieve requires Alibaba Cloud AK/SK.
226
226
  Set via: --access-key-id / --access-key-secret flags,
227
227
  or env: ALIBABA_CLOUD_ACCESS_KEY_ID / ALIBABA_CLOUD_ACCESS_KEY_SECRET,
228
- or config: bl config set access_key_id <key>`,o.AUTH);if(!r)throw new S(`Knowledge retrieve requires a workspace ID.
229
- Set via: --workspace-id flag, or env: BAILIAN_WORKSPACE_ID, or config: bl config set workspace_id <id>`,o.USAGE);let m={IndexId:n,Query:i};if(t.topK!==void 0)m.TopK=t.topK;if(t.rerank)m.Rerank=!0;if(t.rerankTopN!==void 0)m.RerankTopN=t.rerankTopN;let _=B(e.output),x=`/${r}/index/retrieve`;if(e.dryRun){h({endpoint:`https://${ct}${x}`,workspaceId:r,request:m},_);return}let b=JSON.stringify(m),w=Kn({accessKeyId:$,accessKeySecret:p,action:"Retrieve",version:"2023-12-29",body:b,host:ct,pathname:x}),u=`https://${ct}${x}`;if(e.verbose)process.stderr.write(`> POST ${u}
228
+ or config: bl config set access_key_id <key>`,h.AUTH);if(!r)throw new u(`Knowledge retrieve requires a workspace ID.
229
+ Set via: --workspace-id flag, or env: BAILIAN_WORKSPACE_ID, or config: bl config set workspace_id <id>`,h.USAGE);let y={IndexId:n,Query:i};if(t.topK!==void 0)y.TopK=t.topK;if(t.rerank)y.Rerank=!0;if(t.rerankTopN!==void 0)y.RerankTopN=t.rerankTopN;let m=B(e.output),x=`/${r}/index/retrieve`;if(e.dryRun){A({endpoint:`https://${Zt}${x}`,workspaceId:r,request:y},m);return}let b=JSON.stringify(y),w=Bn({accessKeyId:$,accessKeySecret:p,action:"Retrieve",version:"2023-12-29",body:b,host:Zt,pathname:x}),S=`https://${Zt}${x}`;if(e.verbose)process.stderr.write(`> POST ${S}
230
230
  `),process.stderr.write(`> AK: ${$.slice(0,8)}...
231
- `);let k=e.timeout*1000,j=await fetch(u,{method:"POST",headers:{...w,...d()},body:b,signal:AbortSignal.timeout(k)});if(e.verbose)process.stderr.write(`< ${j.status} ${j.statusText}
232
- `);let A=await j.json();if(!j.ok||A.Code&&A.Code!=="Success")throw new S(`Knowledge retrieve failed: ${A.Code||j.status} - ${A.Message||j.statusText}`,o.GENERAL);if(e.quiet||_==="text"){let K=A.Data?.Nodes||[];if(K.length===0)G("No results found.");else for(let Z=0;Z<K.length;Z++){let X=K[Z];G(`[${Z+1}] (score: ${X.Score.toFixed(4)})`),G(X.Text),G("")}}else h(A,_)}});class le{baseUrl;sessionId;nextId=1;config;authToken;constructor(e,t){this.config=e,this.baseUrl=t}async initialize(){let e=await L(this.config);this.authToken=e.token,Oe(this.config,e.token,void 0);let t=await this.rpc("initialize",{protocolVersion:"2025-03-26",capabilities:{},clientInfo:{name:"bailian-cli",version:"0.1.0"}});if(this.config.verbose)process.stderr.write(`[MCP] Session initialized: ${this.sessionId??"no session"}
231
+ `);let q=e.timeout*1000,o=await fetch(S,{method:"POST",headers:{...w,...d()},body:b,signal:AbortSignal.timeout(q)});if(e.verbose)process.stderr.write(`< ${o.status} ${o.statusText}
232
+ `);let k=await o.json();if(!o.ok||k.Code&&k.Code!=="Success")throw new u(`Knowledge retrieve failed: ${k.Code||o.status} - ${k.Message||o.statusText}`,h.GENERAL);if(e.quiet||m==="text"){let G=k.Data?.Nodes||[];if(G.length===0)N("No results found.");else for(let z=0;z<G.length;z++){let J=G[z];N(`[${z+1}] (score: ${J.Score.toFixed(4)})`),N(J.Text),N("")}}else A(k,m)}});class De{baseUrl;sessionId;nextId=1;config;authToken;constructor(e,t){this.config=e,this.baseUrl=t}async initialize(){let e=await V(this.config);this.authToken=e.token,ce(this.config,e.token,void 0);let t=await this.rpc("initialize",{protocolVersion:"2025-03-26",capabilities:{},clientInfo:{name:"bailian-cli",version:"0.1.2-beta.0"}});if(this.config.verbose)process.stderr.write(`[MCP] Session initialized: ${this.sessionId??"no session"}
233
233
  `),process.stderr.write(`[MCP] Server: ${JSON.stringify(t)}
234
- `);await this.notify("notifications/initialized")}async listTools(){return(await this.rpc("tools/list")).tools||[]}async callTool(e,t){return await this.rpc("tools/call",{name:e,arguments:t})}async rpc(e,t){let i={jsonrpc:"2.0",id:this.nextId++,method:e,...t?{params:t}:{}},p=await(await this.send(i)).json();if(p.error)throw new S(`MCP error (${p.error.code}): ${p.error.message}`,o.GENERAL);return p.result}async notify(e,t){let n={jsonrpc:"2.0",method:e,...t?{params:t}:{}};await this.send(n)}async send(e){let t={"Content-Type":"application/json",Accept:"application/json, text/event-stream","User-Agent":"bailian-cli/0.1.0",...d()};if(this.authToken)t.Authorization=`Bearer ${this.authToken}`;if(this.sessionId)t["Mcp-Session-Id"]=this.sessionId;if(this.config.verbose)process.stderr.write(`> POST ${this.baseUrl}
234
+ `);await this.notify("notifications/initialized")}async listTools(){return(await this.rpc("tools/list")).tools||[]}async callTool(e,t){return await this.rpc("tools/call",{name:e,arguments:t})}async rpc(e,t){let i={jsonrpc:"2.0",id:this.nextId++,method:e,...t?{params:t}:{}},p=await(await this.send(i)).json();if(p.error)throw new u(`MCP error (${p.error.code}): ${p.error.message}`,h.GENERAL);return p.result}async notify(e,t){let n={jsonrpc:"2.0",method:e,...t?{params:t}:{}};await this.send(n)}async send(e){let t={"Content-Type":"application/json",Accept:"application/json, text/event-stream","User-Agent":"bailian-cli/0.1.2-beta.0",...d()};if(this.authToken)t.Authorization=`Bearer ${this.authToken}`;if(this.sessionId)t["Mcp-Session-Id"]=this.sessionId;if(this.config.verbose)process.stderr.write(`> POST ${this.baseUrl}
235
235
  `),process.stderr.write(`> Method: ${e.method}
236
236
  `);let n=this.config.timeout*1000,i=await fetch(this.baseUrl,{method:"POST",headers:t,body:JSON.stringify(e),signal:AbortSignal.timeout(n)});if(this.config.verbose)process.stderr.write(`< ${i.status} ${i.statusText}
237
- `);let $=i.headers.get("Mcp-Session-Id")||i.headers.get("mcp-session-id");if($)this.sessionId=$;if(!i.ok){let p=`MCP request failed: ${i.status} ${i.statusText}`;try{let r=await i.text();if(r)p+=` - ${r.slice(0,500)}`}catch{}throw new S(p,o.GENERAL)}return i}}var jn=q({name:"search web",description:"Search the web using DashScope MCP WebSearch service",usage:"bl search web --query <text> [flags]",options:[{flag:"--query <text>",description:"Search query text",required:!0},{flag:"--count <n>",description:"Number of search results (default: 10)",type:"number"},{flag:"--list-tools",description:"List available MCP tools and exit"}],examples:['bl search web --query "阿里云百炼最新功能"','bl search web --query "TypeScript 5.9 new features" --count 5','bl search web --query "今日新闻"',"bl search web --list-tools"],async run(e,t){let n=Ft(e.baseUrl),i=B(e.output);if(t.listTools){if(e.dryRun){h({endpoint:n,action:"tools/list"},i);return}let m=new le(e,n);await m.initialize();let _=await m.listTools();h({tools:_},i);return}let $=t.query;if(!$)if(O({nonInteractive:e.nonInteractive})){let m=await V({message:"Enter your search query:"});if(!m)process.stderr.write(`Search cancelled.
238
- `),process.exit(1);$=m}else R("query","bl search web --query <text>");if(e.dryRun){h({endpoint:n,action:"tools/call",tool:"bailian_web_search",arguments:{query:$,count:t.count||void 0}},i);return}let p=new le(e,n),r=se("Initializing search...");if(!e.quiet)r.start();try{if(await p.initialize(),!e.quiet)r.update("Searching...");let m={query:$};if(t.count)m.count=t.count;let _=await p.callTool("bailian_web_search",m);if(!e.quiet)r.stop("Done.");if(_.isError){let x=_.content.map((b)=>b.text||"").join(`
237
+ `);let $=i.headers.get("Mcp-Session-Id")||i.headers.get("mcp-session-id");if($)this.sessionId=$;if(!i.ok){let p=`MCP request failed: ${i.status} ${i.statusText}`;try{let r=await i.text();if(r)p+=` - ${r.slice(0,500)}`}catch{}throw new u(p,h.GENERAL)}return i}}var Rn=K({name:"search web",description:"Search the web using DashScope MCP WebSearch service",usage:"bl search web --query <text> [flags]",options:[{flag:"--query <text>",description:"Search query text",required:!0},{flag:"--count <n>",description:"Number of search results (default: 10)",type:"number"},{flag:"--list-tools",description:"List available MCP tools and exit"}],examples:['bl search web --query "阿里云百炼最新功能"','bl search web --query "TypeScript 5.9 new features" --count 5','bl search web --query "今日新闻"',"bl search web --list-tools"],async run(e,t){let n=Ft(e.baseUrl),i=B(e.output);if(t.listTools){if(e.dryRun){A({endpoint:n,action:"tools/list"},i);return}let y=new De(e,n);await y.initialize();let m=await y.listTools();A({tools:m},i);return}let $=t.query;if(!$)if(Y({nonInteractive:e.nonInteractive})){let y=await L({message:"Enter your search query:"});if(!y)process.stderr.write(`Search cancelled.
238
+ `),process.exit(1);$=y}else W("query","bl search web --query <text>");if(e.dryRun){A({endpoint:n,action:"tools/call",tool:"bailian_web_search",arguments:{query:$,count:t.count||void 0}},i);return}let p=new De(e,n),r=se("Initializing search...");if(!e.quiet)r.start();try{if(await p.initialize(),!e.quiet)r.update("Searching...");let y={query:$};if(t.count)y.count=t.count;let m=await p.callTool("bailian_web_search",y);if(!e.quiet)r.stop("Done.");if(m.isError){let x=m.content.map((b)=>b.text||"").join(`
239
239
  `);process.stderr.write(`Search error: ${x}
240
- `),process.exit(1)}if(i==="json")h(_,i);else for(let x of _.content)if(x.type==="text"&&x.text)try{let b=JSON.parse(x.text);if(b.pages&&Array.isArray(b.pages))h({pages:b.pages,total:b.pages.length},i);else h(b,i)}catch{h({text:x.text},i)}}catch(m){throw r.stop("Failed."),m}}});import{readFileSync as bp}from"fs";import{createWriteStream as wp}from"fs";var up=["Cherry","Serena","Ethan","Chelsie"],Rn=q({name:"speech synthesize",description:"Synthesize speech from text (Qwen TTS)",apiDocs:"/developer-reference/qwen-tts",usage:"bl speech synthesize --text <text> [flags]",options:[{flag:"--text <text>",description:"Text to synthesize into speech",required:!0},{flag:"--text-file <path>",description:"Read text from a file instead of --text"},{flag:"--model <model>",description:"Model ID (default: qwen3-tts-flash)"},{flag:"--voice <voice>",description:`Voice name (default: Cherry). System voices: ${up.join(", ")}`},{flag:"--language <lang>",description:"Language type (e.g. Chinese, English, Japanese)"},{flag:"--instructions <text>",description:"Natural language instructions to control speech style (requires qwen3-tts-instruct-flash)"},{flag:"--optimize-instructions",description:"Optimize instructions for better results"},{flag:"--out <path>",description:"Save audio to file (default: auto-generate in temp dir)"},{flag:"--stream",description:"Stream raw PCM audio to stdout (pipe to player)"}],examples:['bl speech synthesize --text "你好,我是千问"','bl speech synthesize --text "Hello world" --voice Serena --language English',"bl speech synthesize --text-file script.txt --out speech.wav",'bl speech synthesize --text "今天天气真好" --model qwen3-tts-instruct-flash --instructions "语速较慢,温柔的语调"',"# Stream to audio player (macOS)",'bl speech synthesize --text "你好" --stream | afplay -',"# Pipe to ffplay",'bl speech synthesize --text "Hello" --stream | ffplay -nodisp -autoexit -f s16le -ar 24000 -ac 1 -'],async run(e,t){let n=t.text;if(!n&&t.textFile){let u=t.textFile;try{n=bp(u,"utf-8").trim()}catch{throw new S(`Cannot read text file: ${u}`,o.USAGE)}}if(!n)if(O({nonInteractive:e.nonInteractive})){let u=await V({message:"Enter text to synthesize:"});if(!u)process.stderr.write(`Speech synthesis cancelled.
241
- `),process.exit(1);n=u}else R("text","bl speech synthesize --text <text>");let i=t.model||e.defaultSpeechModel||"qwen3-tts-flash",$=t.voice||"Cherry",p=t.language||void 0,r=t.instructions||void 0,m=t.optimizeInstructions===!0?!0:void 0,_=t.stream===!0,x=B(e.output),b={model:i,input:{text:n,voice:$,language_type:p,instructions:r,optimize_instructions:m}};if(Te(b.input),e.dryRun){h({request:b},x);return}if(!e.quiet)process.stderr.write(`[Model: ${i}] [Voice: ${$}]
242
- `);let w=dt(e.baseUrl);if(_)await op(e,w,b,t,x);else await hp(e,w,b,t,x)}});async function hp(e,t,n,i,$){let p=he(i),r=await me(p,e,()=>W(e,{url:t,method:"POST",body:n})),m=r.map((u)=>u.output?.audio?.url).filter(Boolean);if(m.length===0)throw new S("API returned no audio URL.",o.GENERAL);let{join:_}=await import("path"),x=l(e,{subDir:"speech"}),b=m.map((u,k)=>{let j=i.out;if(j&&m.length===1);else{let A=Date.now(),K=m.length>1?`_${String(k+1).padStart(3,"0")}`:"";j=_(x,`tts_${A}${K}.wav`)}return{url:u,destPath:j}}),w=await We(b,U,{quiet:e.quiet});if(e.quiet)G(w.join(`
243
- `));else if(w.length===1){let u=r[0].output?.audio?.expires_at;h({saved:w[0],audio_url:m[0],model:n.model,voice:n.input.voice,...u?{url_expires_at:u}:{}},$)}else h({saved:w,audio_urls:m,total:w.length,model:n.model,voice:n.input.voice},$)}async function op(e,t,n,i,$){let p=await pe(e,{url:t,method:"POST",body:n,stream:!0,headers:{Accept:"text/event-stream","X-DashScope-SSE":"enable"}}),r=i.out,m=r?wp(r):null,_;try{for await(let x of we(p)){if(!x.data||x.data==="[DONE]")continue;let b;try{b=JSON.parse(x.data)}catch{continue}let w=b.output?.audio?.data;if(w){let u=Buffer.from(w,"base64");if(m){if(!m.write(u))await new Promise((j)=>m.once("drain",j))}else process.stdout.write(u)}if(b.output?.finish_reason==="stop"){if(_=b.output?.audio?.url,_&&!e.quiet)process.stderr.write(`
244
- Full audio URL: ${_}
245
- `);break}}}finally{if(m){if(await new Promise((x,b)=>{m.on("finish",x),m.on("error",b),m.end()}),!e.quiet&&r)process.stderr.write(`Saved: ${r}
246
- `)}}if(r)h({saved:r,..._?{audio_url:_}:{},model:n.model,voice:n.input.voice},$)}import{writeFileSync as Ht}from"fs";var Sp=["qwen3-asr-flash-filetrans"];function Ap(e){return Sp.some((t)=>e.startsWith(t))}var Jn=q({name:"speech recognize",description:"Recognize speech from audio (Qwen ASR)",apiDocs:"/developer-reference/qwen-asr",usage:"bl speech recognize --url <audio-url> [flags]",options:[{flag:"--url <url>",description:"Audio file URL or local file path",required:!0},{flag:"--model <model>",description:"Model ID (default: qwen3-asr-flash)"},{flag:"--language <lang>",description:"Language hint (e.g. zh, en, ja, auto)"},{flag:"--enable-itn",description:"Enable inverse text normalization (format numbers/dates)"},{flag:"--enable-words",description:"Enable word-level timestamps"},{flag:"--enable-emotion",description:"Enable emotion recognition"},{flag:"--channel-id <n>",description:"Audio channel ID (default: 0)",type:"number"},{flag:"--out <path>",description:"Save full result to JSON file"},{flag:"--no-wait",description:"Return task ID immediately (async mode only)"},{flag:"--poll-interval <seconds>",description:"Polling interval in seconds (default: 2)",type:"number"}],examples:["bl speech recognize --url https://example.com/audio.mp3","bl speech recognize --url https://example.com/meeting.wav --enable-words --enable-emotion","bl speech recognize --url https://example.com/short.wav --model qwen3-asr-flash","bl speech recognize --url https://example.com/audio.mp3 --out result.json","bl speech recognize --url https://example.com/audio.mp3 --no-wait --quiet","bl speech recognize --url https://example.com/audio.mp3 --language zh --enable-itn"],async run(e,t){let n=t.url;if(!n)R("url","bl speech recognize --url <audio-url>");let i=t.model||"qwen3-asr-flash",$=B(e.output),p=Ap(i),r=await L(e),m=await v(n,r.token,i,e.quiet),_=m.startsWith("oss://"),x=t.channelId,b={model:i,input:{file_url:m},parameters:{channel_id:x!==void 0?[x]:[0],language:t.language||void 0,enable_itn:t.enableItn===!0?!0:void 0,enable_words:t.enableWords===!0?!0:void 0,enable_emotion:t.enableEmotion===!0?!0:void 0}};if(Te(b.parameters),e.dryRun){h({request:b,mode:p?"async":"sync"},$);return}if(!e.quiet)process.stderr.write(`[Model: ${i}] [Mode: ${p?"async":"sync"}]
247
- `);let w=Ut(e.baseUrl);if(p)await kp(e,w,b,t,$,_);else await qp(e,w,b,t,$,_)}});async function kp(e,t,n,i,$,p){let m=(await W(e,{url:t,method:"POST",body:n,async:!0,ossResolve:p})).output.task_id;if(i.noWait||e.async){h({task_id:m},$);return}let _=i.pollInterval??2,x=F(e.baseUrl,m),b=await $e(e,{url:x,intervalSec:_,timeoutSec:e.timeout,isComplete:(u)=>u.output.task_status==="SUCCEEDED",isFailed:(u)=>u.output.task_status==="FAILED",getStatus:(u)=>u.output.task_status,getErrorMessage:(u)=>{return u.output.message}}),w=b.output.result?.transcription_url||b.output.results?.[0]?.transcription_url;if(w){let u=await fetch(w,{headers:d()});if(!u.ok)throw new S(`Failed to download transcription: HTTP ${u.status}`,o.GENERAL);let k=await u.json();if(i.out){let A=i.out;if(Ht(A,JSON.stringify(k,null,2)+`
248
- `),!e.quiet)process.stderr.write(`Full result saved to: ${A}
249
- `)}let j=k.transcripts;if(j&&j.length>0){for(let A of j)if(A.sentences)for(let K of A.sentences){let Z=K.emotion?` [${K.emotion}]`:"";process.stdout.write(`${K.text}${Z}
250
- `)}else if(A.text)process.stdout.write(A.text+`
251
- `)}else h(k,$)}else{if(i.out){let u=i.out;if(Ht(u,JSON.stringify(b,null,2)+`
252
- `),!e.quiet)process.stderr.write(`Full result saved to: ${u}
253
- `)}h({task_id:m,status:b.output.task_status},$)}}async function qp(e,t,n,i,$,p){let r=await W(e,{url:t,method:"POST",body:n,ossResolve:p});if(i.out){let m=i.out;if(Ht(m,JSON.stringify(r,null,2)+`
254
- `),!e.quiet)process.stderr.write(`Full result saved to: ${m}
255
- `)}if(r.output.sentences&&r.output.sentences.length>0)for(let m of r.output.sentences){let _=m.emotion?` [${m.emotion}]`:"";process.stdout.write(`${m.text}${_}
256
- `)}else if(r.output.text)process.stdout.write(r.output.text+`
257
- `);else h(r,$)}var Wn=q({name:"file upload",description:"Upload a local file to DashScope temporary storage (48h)",apiDocs:"/developer-reference/get-temporary-file-url",usage:"bl file upload --file <path> --model <model>",options:[{flag:"--file <path>",description:"Local file to upload (image, video, audio)",required:!0},{flag:"--model <model>",description:"Target model name (file is bound to this model)",required:!0}],examples:["bl file upload --file photo.jpg --model qwen-vl-max","bl file upload --file video.mp4 --model wan2.1-t2v-plus","bl file upload --file audio.wav --model qwen3-asr-flash","bl file upload --file cat.png --model qwen-image-2.0"],async run(e,t){let n=t.file;if(!n)R("file","bl file upload --file <path> --model <model>");let i=t.model;if(!i)R("model","bl file upload --file <path> --model <model>");let $=B(e.output);if(e.dryRun){h({action:"upload",file:n,model:i},$);return}let p=await L(e),r=await Qt({apiKey:p.token,model:i,filePath:n,quiet:e.quiet});if(e.quiet)G(r);else h({url:r,model:i,expires_in:"48 hours",note:"When using this URL in API calls, add header: X-DashScope-OssResourceResolve: enable"},$)}});class Tn{root={children:new Map};constructor(e){for(let[t,n]of Object.entries(e))this.register(t,n)}register(e,t){let n=e.split(" "),i=this.root;for(let $ of n){if(!i.children.has($))i.children.set($,{children:new Map});i=i.children.get($)}i.command=t}getAllCommands(){let e=[],t=(n)=>{if(n.command)e.push(n.command);for(let i of n.children.values())t(i)};return t(this.root),e}resolve(e){let t=this.root,n=[];for(let i of e){let $=t.children.get(i);if(!$)break;t=$,n.push(i)}if(t.command)return{command:t.command,extra:e.slice(n.length)};if(n.length>0&&t.children.size===1){let[,i]=t.children.entries().next().value;if(i.command)return{command:i.command,extra:e.slice(n.length)}}if(n.length>0&&t.children.size>0){let i=Array.from(t.children.entries()).map(([$,p])=>{if(p.command)return` ${n.join(" ")} ${$} ${p.command.description}`;let r=Array.from(p.children.keys()).join(", ");return` ${n.join(" ")} ${$} [${r}]`}).join(`
258
- `);throw new S(`Unknown command: bl ${e.join(" ")}
240
+ `),process.exit(1)}if(i==="json")A(m,i);else for(let x of m.content)if(x.type==="text"&&x.text)try{let b=JSON.parse(x.text);if(b.pages&&Array.isArray(b.pages))A({pages:b.pages,total:b.pages.length},i);else A(b,i)}catch{A({text:x.text},i)}}catch(y){throw r.stop("Failed."),y}}});import{readFileSync as _p}from"fs";import{createWriteStream as mp}from"fs";var Jn=[{voice:"longanyang",name:"龙安洋",desc:"阳光大男孩",lang:"中文/英文"},{voice:"longanhuan",name:"龙安欢",desc:"欢脱元气女",lang:"中文/英文"},{voice:"longantai_v3",name:"龙安台",desc:"嗲甜台湾女",lang:"中文/英文"},{voice:"longhua_v3",name:"龙华",desc:"元气甜美女",lang:"中文/英文"},{voice:"longcheng_v3",name:"龙橙",desc:"智慧青年男",lang:"中文/英文"},{voice:"longze_v3",name:"龙泽",desc:"温暖元气男",lang:"中文/英文"},{voice:"longzhe_v3",name:"龙哲",desc:"呆板大暖男",lang:"中文/英文"},{voice:"longyan_v3",name:"龙颜",desc:"温暖春风女",lang:"中文/英文"},{voice:"longxing_v3",name:"龙星",desc:"温婉邻家女",lang:"中文/英文"},{voice:"longtian_v3",name:"龙天",desc:"磁性理智男",lang:"中文/英文"},{voice:"longwan_v3",name:"龙婉",desc:"细腻柔声女",lang:"中文/英文"},{voice:"longqiang_v3",name:"龙嫱",desc:"浪漫风情女",lang:"中文/英文"},{voice:"longfeifei_v3",name:"龙菲菲",desc:"甜美娇气女",lang:"中文/英文"},{voice:"longhao_v3",name:"龙浩",desc:"多情忧郁男",lang:"中文/英文"},{voice:"longanrou_v3",name:"龙安柔",desc:"温柔娴静女",lang:"中文/英文"},{voice:"longxiaochun_v3",name:"龙小淳",desc:"知性积极女",lang:"中文/英文"},{voice:"longxiaoxia_v3",name:"龙小夏",desc:"沉稳权威女",lang:"中文/英文"},{voice:"longyumi_v3",name:"YUMI",desc:"正经青年女",lang:"中文/英文"},{voice:"longanyun_v3",name:"龙安昀",desc:"居家暖男",lang:"中文/英文"},{voice:"longanwen_v3",name:"龙安温",desc:"优雅知性女",lang:"中文/英文"},{voice:"longanli_v3",name:"龙安莉",desc:"利落从容女",lang:"中文/英文"},{voice:"longanlang_v3",name:"龙安朗",desc:"清爽利落男",lang:"中文/英文"},{voice:"longyingmu_v3",name:"龙应沐",desc:"优雅知性女",lang:"中文/英文"},{voice:"longyingxun_v3",name:"龙应询",desc:"年轻青涩男",lang:"中文/英文"},{voice:"longyingjing_v3",name:"龙应静",desc:"低调冷静女",lang:"中文/英文"},{voice:"longyingling_v3",name:"龙应聆",desc:"温和共情女",lang:"中文/英文"},{voice:"longyingtao_v3",name:"龙应桃",desc:"温柔淡定女",lang:"中文/英文"},{voice:"longyingxiao_v3",name:"龙应笑",desc:"清甜推销女",lang:"中文/英文"},{voice:"longfei_v3",name:"龙飞",desc:"热血磁性男",lang:"中文/英文"},{voice:"longhuhu_v3",name:"龙呼呼",desc:"天真烂漫女童",lang:"中文/英文"},{voice:"longpaopao_v3",name:"龙泡泡",desc:"飞天泡泡音",lang:"中文/英文"},{voice:"longjielidou_v3",name:"龙杰力豆",desc:"阳光顽皮男",lang:"中文/英文"},{voice:"longxian_v3",name:"龙仙",desc:"豪放可爱女",lang:"中文/英文"},{voice:"longling_v3",name:"龙铃",desc:"稚气呆板女",lang:"中文/英文"},{voice:"longshanshan_v3",name:"龙闪闪",desc:"戏剧化童声",lang:"中文/英文"},{voice:"longniuniu_v3",name:"龙牛牛",desc:"阳光男童声",lang:"中文/英文"},{voice:"longjiaxin_v3",name:"龙嘉欣",desc:"优雅粤语女",lang:"粤语/英文"},{voice:"longjiayi_v3",name:"龙嘉怡",desc:"知性粤语女",lang:"粤语/英文"},{voice:"longanyue_v3",name:"龙安粤",desc:"欢脱粤语男",lang:"粤语/英文"},{voice:"longlaotie_v3",name:"龙老铁",desc:"东北直率男",lang:"东北话/英文"},{voice:"longshange_v3",name:"龙陕哥",desc:"原味陕北男",lang:"陕西话/英文"},{voice:"longanmin_v3",name:"龙安闽",desc:"清纯萝莉女",lang:"闽南话/英文"},{voice:"loongabby_v3",name:"loongabby",desc:"美式英文女",lang:"美式英语"},{voice:"loongandy_v3",name:"loongandy",desc:"美式英文男",lang:"美式英语"},{voice:"loongannie_v3",name:"loongannie",desc:"美式英文女",lang:"美式英语"},{voice:"loongava_v3",name:"loongava",desc:"美式英文女",lang:"美式英语"},{voice:"loongbeth_v3",name:"loongbeth",desc:"美式英文女",lang:"美式英语"},{voice:"loongbetty_v3",name:"loongbetty",desc:"美式英文女",lang:"美式英语"},{voice:"loongcally_v3",name:"loongcally",desc:"美式英文女",lang:"美式英语"},{voice:"loongcindy_v3",name:"loongcindy",desc:"美式英文女",lang:"美式英语"},{voice:"loongdavid_v3",name:"loongdavid",desc:"美式英文男",lang:"美式英语"},{voice:"loongdonna_v3",name:"loongdonna",desc:"美式英文女",lang:"美式英语"},{voice:"loongemily_v3",name:"loongemily",desc:"英式英文女",lang:"英式英语"},{voice:"loongeric_v3",name:"loongeric",desc:"英式英文男",lang:"英式英语"},{voice:"loongluna_v3",name:"loongluna",desc:"英式英文女",lang:"英式英语"},{voice:"loongluca_v3",name:"loongluca",desc:"英式英文男",lang:"英式英语"},{voice:"loongriko_v3",name:"Riko",desc:"二次元霓虹女",lang:"日语"},{voice:"loongtomoka_v3",name:"loongtomoka",desc:"日语女",lang:"日语"},{voice:"loongtomoya_v3",name:"loongtomoya",desc:"日语男",lang:"日语"},{voice:"loongyuuna_v3",name:"Yuuna",desc:"日语女",lang:"日语"},{voice:"loongyuuma_v3",name:"Yuuma",desc:"日语男",lang:"日语"},{voice:"loongkyong_v3",name:"loongkyong",desc:"韩语女",lang:"韩语"},{voice:"loongjihun_v3",name:"Jihun",desc:"韩语男",lang:"韩语"},{voice:"loongindah_v3",name:"loongindah",desc:"印尼女",lang:"印尼语"}],zt={"cosyvoice-v3-flash":Jn,"cosyvoice-v3-plus":Jn,"cosyvoice-v3.5-flash":[],"cosyvoice-v3.5-plus":[],"cosyvoice-v2":[]};function xp(e){let t=zt[e];if(!t){process.stdout.write(`No built-in voice list available for model: ${e}
241
+ `);return}if(t.length===0){process.stdout.write(`Model ${e} has no system voices.
242
+ `),process.stdout.write(`Use clone or design voices created via the CosyVoice API.
243
+ `),process.stdout.write(`See: https://help.aliyun.com/zh/model-studio/cosyvoice-clone-design-api
244
+ `);return}let n=(i,$)=>i.padEnd($);process.stdout.write(`
245
+ System voices for ${e}:
246
+ `),process.stdout.write(`${n("VOICE ID",26)} ${n("NAME",10)} ${n("DESCRIPTION",16)} LANGUAGE
247
+ `),process.stdout.write(`${"-".repeat(26)} ${"-".repeat(10)} ${"-".repeat(16)} ${"-".repeat(12)}
248
+ `);for(let i of t)process.stdout.write(`${n(i.voice,26)} ${n(i.name,10)} ${n(i.desc,16)} ${i.lang}
249
+ `);process.stdout.write(`
250
+ Total: ${t.length} voices
251
+ `)}var Wn=K({name:"speech synthesize",description:"Synthesize speech from text (CosyVoice TTS)",apiDocs:"/developer-reference/cosyvoice",usage:"bl speech synthesize --text <text> [flags]",options:[{flag:"--text <text>",description:"Text to synthesize into speech",required:!0},{flag:"--text-file <path>",description:"Read text from a file instead of --text"},{flag:"--model <model>",description:"Model ID (default: cosyvoice-v3-flash). System voices available for cosyvoice-v3-flash"},{flag:"--voice <voice>",description:"Voice ID. Use --list-voices to see system voices for cosyvoice-v3-flash; for v3.5-flash provide a clone/design voice ID"},{flag:"--list-voices",description:"List available system voices for the selected model and exit"},{flag:"--format <format>",description:"Audio format: mp3, pcm, wav, opus (default: mp3)"},{flag:"--sample-rate <rate>",description:"Audio sample rate in Hz (e.g. 24000)"},{flag:"--volume <volume>",description:"Volume 0-100 (default: 50)"},{flag:"--rate <rate>",description:"Speech rate 0.5-2.0 (default: 1.0)"},{flag:"--pitch <pitch>",description:"Pitch multiplier 0.5-2.0 (default: 1.0)"},{flag:"--seed <seed>",description:"Random seed 0-65535 for reproducible synthesis"},{flag:"--language <lang>",description:"Language hint (e.g. zh, en, ja, ko, fr, de)"},{flag:"--instruction <text>",description:'Natural language instruction to control speech style (e.g. "请用温柔的语调")'},{flag:"--enable-ssml",description:"Enable SSML markup parsing in input text"},{flag:"--out <path>",description:"Save audio to file (default: auto-generate in temp dir)"},{flag:"--stream",description:"Stream raw PCM audio to stdout (pipe to player)"}],examples:["bl speech synthesize --list-voices --model cosyvoice-v3-flash",'bl speech synthesize --text "你好,我是千问" --voice <voice_id>','bl speech synthesize --text "Hello world" --voice <voice_id> --language en',"bl speech synthesize --text-file script.txt --out speech.wav --voice <voice_id>",'bl speech synthesize --text "今天天气真好" --voice <voice_id> --instruction "请用温柔的语调说话"','bl speech synthesize --text "Hello" --voice <voice_id> --format wav --sample-rate 24000',"# Stream to audio player (macOS)",'bl speech synthesize --text "你好" --voice <voice_id> --stream | afplay -',"# Pipe to ffplay",'bl speech synthesize --text "Hello" --voice <voice_id> --stream | ffplay -nodisp -autoexit -f s16le -ar 24000 -ac 1 -'],async run(e,t){let n=t.model||e.defaultSpeechModel||"cosyvoice-v3-flash";if(t.listVoices){xp(n);return}let i=t.text;if(!i&&t.textFile){let J=t.textFile;try{i=_p(J,"utf-8").trim()}catch{throw new u(`Cannot read text file: ${J}`,h.USAGE)}}if(!i)if(Y({nonInteractive:e.nonInteractive})){let J=await L({message:"Enter text to synthesize:"});if(!J)process.stderr.write(`Speech synthesis cancelled.
252
+ `),process.exit(1);i=J}else W("text","bl speech synthesize --text <text>");let $=t.voice||void 0;if(!$)if(Y({nonInteractive:e.nonInteractive})){let J=zt[n];if(J&&J.length>0){let Z=J[0].voice,j=J.map((X)=>({value:X.voice,label:`${X.name} (${X.voice})`,hint:`${X.desc} · ${X.lang}`})),T=await Or({message:`Select a voice (default: ${Z}):`,choices:j,defaultValue:Z});if(!T)process.stderr.write(`Speech synthesis cancelled.
253
+ `),process.exit(1);$=T}else{let Z=await L({message:"Enter voice ID (clone/design voice):"});if(!Z)process.stderr.write(`Speech synthesis cancelled.
254
+ `),process.exit(1);$=Z}}else{let J=zt[n];if(J&&J.length>0)throw new u(`--voice is required.
255
+ Run the following to see available voices:
256
+ bl speech synthesize --list-voices --model ${n}`,h.USAGE);else throw new u(`--voice is required. Model ${n} has no built-in system voices.
257
+ Create a clone or design voice first, then pass its ID via --voice <voice_id>.
258
+ See: https://help.aliyun.com/zh/model-studio/cosyvoice-clone-design-api`,h.USAGE)}let p=t.language||void 0,r=t.instruction||void 0,y=t.format||void 0,m=t.sampleRate!==void 0?Number(t.sampleRate):void 0,x=t.volume!==void 0?Number(t.volume):void 0,b=t.rate!==void 0?Number(t.rate):void 0,w=t.pitch!==void 0?Number(t.pitch):void 0,S=t.seed!==void 0?Number(t.seed):void 0,q=t.enableSsml===!0?!0:void 0,o=t.stream===!0,k=B(e.output),G={model:n,input:{text:i,voice:$,format:y,sample_rate:m,volume:x,rate:b,pitch:w,seed:S,language_hints:p?[p]:void 0,instruction:r,enable_ssml:q}};if(Me(G.input),e.dryRun){A({request:G},k);return}if(!e.quiet)process.stderr.write(`[Model: ${n}] [Voice: ${$}]
259
+ `);let z=Ut(e.baseUrl);if(o)await wp(e,z,G,t,k);else await bp(e,z,G,t,k)}});async function bp(e,t,n,i,$){let p=Se(i),r=await _e(p,e,()=>Q(e,{url:t,method:"POST",body:n})),y=r.map((S)=>S.output?.audio?.url).filter(Boolean);if(y.length===0)throw new u("API returned no audio URL.",h.GENERAL);let{join:m}=await import("path"),x=l(e,{subDir:"speech"}),b=y.map((S,q)=>{let o=i.out;if(o&&y.length===1);else{let k=Date.now(),G=y.length>1?`_${String(q+1).padStart(3,"0")}`:"",z=n.input.format??"mp3";o=m(x,`tts_${k}${G}.${z}`)}return{url:S,destPath:o}}),w=await Te(b,s,{quiet:e.quiet});if(e.quiet)N(w.join(`
260
+ `));else if(w.length===1){let S=r[0].output?.audio?.expires_at;A({saved:w[0],audio_url:y[0],model:n.model,voice:n.input.voice,...S?{url_expires_at:S}:{}},$)}else A({saved:w,audio_urls:y,total:w.length,model:n.model,voice:n.input.voice},$)}async function wp(e,t,n,i,$){let p=await ye(e,{url:t,method:"POST",body:n,stream:!0,headers:{Accept:"text/event-stream","X-DashScope-SSE":"enable"}}),r=i.out,y=r?mp(r):null,m;try{for await(let x of Ae(p)){if(!x.data||x.data==="[DONE]")continue;let b;try{b=JSON.parse(x.data)}catch{continue}let w=b.output?.audio?.data;if(w){let S=Buffer.from(w,"base64");if(y){if(!y.write(S))await new Promise((o)=>y.once("drain",o))}else process.stdout.write(S)}if(b.output?.finish_reason==="stop"){if(m=b.output?.audio?.url,m&&!e.quiet)process.stderr.write(`
261
+ Full audio URL: ${m}
262
+ `);break}}}finally{if(y){if(await new Promise((x,b)=>{y.on("finish",x),y.on("error",b),y.end()}),!e.quiet&&r)process.stderr.write(`Saved: ${r}
263
+ `)}}if(r)A({saved:r,...m?{audio_url:m}:{},model:n.model,voice:n.input.voice},$)}import{writeFileSync as hp}from"fs";var Tn=K({name:"speech recognize",description:"Recognize speech from audio files (FunAudio-ASR)",apiDocs:"/developer-reference/recording-file-recognition",usage:"bl speech recognize --url <audio-url> [flags]",options:[{flag:"--url <url>",description:"Audio file URL or local file path (repeatable, max 100)",required:!0,type:"array"},{flag:"--model <model>",description:"Model ID (default: fun-asr)"},{flag:"--language <lang>",description:"Language hint (e.g. zh, en, ja)"},{flag:"--diarization",description:"Enable automatic speaker diarization"},{flag:"--speaker-count <n>",description:"Expected number of speakers (requires --diarization)",type:"number"},{flag:"--vocabulary-id <id>",description:"Hot-word vocabulary ID for improved accuracy"},{flag:"--channel-id <n>",description:"Audio channel ID (default: 0)",type:"number"},{flag:"--out <path>",description:"Save full transcription result to JSON file"},{flag:"--no-wait",description:"Return task ID immediately without polling"},{flag:"--poll-interval <seconds>",description:"Polling interval in seconds (default: 2)",type:"number"}],examples:["bl speech recognize --url https://example.com/audio.mp3","bl speech recognize --url https://example.com/a.mp3 --url https://example.com/b.mp3","bl speech recognize --url https://example.com/meeting.wav --diarization --speaker-count 3","bl speech recognize --url https://example.com/audio.mp3 --language zh","bl speech recognize --url https://example.com/audio.mp3 --vocabulary-id vocab-abc123","bl speech recognize --url https://example.com/audio.mp3 --out result.json","bl speech recognize --url https://example.com/audio.mp3 --no-wait --quiet"],async run(e,t){let n=[];if(Array.isArray(t.url))n=t.url;else if(typeof t.url==="string")n=[t.url];if(n.length===0)W("url","bl speech recognize --url <audio-url>");let i=t.speakerCount,$=t.diarization===!0;if(i!==void 0&&!$)throw new u(`--speaker-count requires --diarization to be enabled.
264
+ Hint: Add --diarization flag to enable speaker separation.`,h.USAGE);let p=t.model||"fun-asr",r=B(e.output),y=await V(e),m=await Promise.all(n.map((k)=>E(k,y.token,p,e.quiet))),x=m.some((k)=>k.startsWith("oss://")),b=t.channelId,w=t.language,S=t.vocabularyId,q={model:p,input:{file_urls:m},parameters:{channel_id:b!==void 0?[b]:[0],language_hints:w?[w]:void 0,diarization_enabled:$?!0:void 0,speaker_count:i,vocabulary_id:S}};if(Me(q.parameters),e.dryRun){A({request:q,mode:"async"},r);return}if(!e.quiet)process.stderr.write(`[Model: ${p}] [Mode: async] [Files: ${m.length}]
265
+ `);let o=dt(e.baseUrl);await Ap(e,o,q,t,r,m.length,x)}});async function Ap(e,t,n,i,$,p,r){let m=(await Q(e,{url:t,method:"POST",body:n,async:!0,ossResolve:r})).output.task_id;if(i.noWait||e.async){A({task_id:m},$);return}let x=i.pollInterval??2,b=a(e.baseUrl,m),w=await pe(e,{url:b,intervalSec:x,timeoutSec:e.timeout,isComplete:(o)=>o.output.task_status==="SUCCEEDED",isFailed:(o)=>o.output.task_status==="FAILED",getStatus:(o)=>o.output.task_status,getErrorMessage:(o)=>{return o.output.message}}),S=w.output.results??[];if(S.length===0){A({task_id:m,status:w.output.task_status},$);return}let q=[];for(let o=0;o<S.length;o++){let k=S[o],G=p>1;if(G)process.stdout.write(`=== [${o+1}/${S.length}] ${k.file_url??""} ===
266
+ `);if(k.subtask_status==="FAILED"){let j=k.message??k.code??"unknown error";if(process.stdout.write(`[FAILED] ${k.file_url??""} — ${j}
267
+ `),G)process.stdout.write(`
268
+ `);continue}if(!k.transcription_url){if(G)process.stdout.write(`
269
+ `);continue}let z=await fetch(k.transcription_url,{headers:d()});if(!z.ok)throw new u(`Failed to download transcription: HTTP ${z.status}`,h.GENERAL);let J=await z.json();q.push(J);let Z=J.transcripts;if(Z&&Z.length>0){for(let j of Z)if(j.sentences&&j.sentences.length>0)for(let T of j.sentences){let X=T.speaker_id!==void 0?` [Speaker ${T.speaker_id}]`:"";process.stdout.write(`${T.text}${X}
270
+ `)}else if(j.text)process.stdout.write(j.text+`
271
+ `)}else N(JSON.stringify(J));if(G)process.stdout.write(`
272
+ `)}if(i.out){let o=i.out,k=q.length===1?q[0]:q;if(hp(o,JSON.stringify(k,null,2)+`
273
+ `),!e.quiet)process.stderr.write(`Full result saved to: ${o}
274
+ `)}}var Mn=K({name:"file upload",description:"Upload a local file to DashScope temporary storage (48h)",apiDocs:"/developer-reference/get-temporary-file-url",usage:"bl file upload --file <path> --model <model>",options:[{flag:"--file <path>",description:"Local file to upload (image, video, audio)",required:!0},{flag:"--model <model>",description:"Target model name (file is bound to this model)",required:!0}],examples:["bl file upload --file photo.jpg --model qwen-vl-max","bl file upload --file video.mp4 --model wan2.1-t2v-plus","bl file upload --file audio.wav --model qwen3-asr-flash","bl file upload --file cat.png --model qwen-image-2.0"],async run(e,t){let n=t.file;if(!n)W("file","bl file upload --file <path> --model <model>");let i=t.model;if(!i)W("model","bl file upload --file <path> --model <model>");let $=B(e.output);if(e.dryRun){A({action:"upload",file:n,model:i},$);return}let p=await V(e),r=await Qt({apiKey:p.token,model:i,filePath:n,quiet:e.quiet});if(e.quiet)N(r);else A({url:r,model:i,expires_in:"48 hours",note:"When using this URL in API calls, add header: X-DashScope-OssResourceResolve: enable"},$)}});class Qn{root={children:new Map};constructor(e){for(let[t,n]of Object.entries(e))this.register(t,n)}register(e,t){let n=e.split(" "),i=this.root;for(let $ of n){if(!i.children.has($))i.children.set($,{children:new Map});i=i.children.get($)}i.command=t}getAllCommands(){let e=[],t=(n)=>{if(n.command)e.push(n.command);for(let i of n.children.values())t(i)};return t(this.root),e}isGroupPath(e){let t=this.root;for(let n of e){let i=t.children.get(n);if(!i)return!1;t=i}return!t.command&&t.children.size>0}resolve(e){let t=this.root,n=[];for(let i of e){let $=t.children.get(i);if(!$)break;t=$,n.push(i)}if(t.command)return{command:t.command,extra:e.slice(n.length)};if(n.length>0&&t.children.size===1){let[,i]=t.children.entries().next().value;if(i.command)return{command:i.command,extra:e.slice(n.length)}}if(n.length>0&&t.children.size>0){let i=Array.from(t.children.entries()).map(([$,p])=>{if(p.command)return` ${n.join(" ")} ${$} ${p.command.description}`;let r=Array.from(p.children.keys()).join(", ");return` ${n.join(" ")} ${$} [${r}]`}).join(`
275
+ `);throw new u(`Unknown command: bl ${e.join(" ")}
259
276
 
260
277
  Available commands:
261
- ${i}`,o.USAGE,`bl ${n.join(" ")} --help`)}throw new S(`Unknown command: bl ${e.join(" ")}`,o.USAGE,"bl --help")}bold=(e,t)=>t.isTTY?`\x1B[1m${e}\x1B[0m`:e;accent=(e,t)=>t.isTTY?`\x1B[38;2;59;130;246m${e}\x1B[0m`:e;dim=(e,t)=>t.isTTY?`\x1B[2m${e}\x1B[0m`:e;printHelp(e,t=process.stdout,n="cn"){if(e.length===0){this.printRootHelp(t);return}let i=this.root;for(let p of e){let r=i.children.get(p);if(!r){this.printRootHelp(t);return}i=r}if(i.command){this.printCommandHelp(i.command,t,n);return}let $=e.join(" ");t.write(`
278
+ ${i}`,h.USAGE,`bl ${n.join(" ")} --help`)}throw new u(`Unknown command: bl ${e.join(" ")}`,h.USAGE,"bl --help")}bold=(e,t)=>t.isTTY?`\x1B[1m${e}\x1B[0m`:e;accent=(e,t)=>t.isTTY?`\x1B[38;2;59;130;246m${e}\x1B[0m`:e;dim=(e,t)=>t.isTTY?`\x1B[2m${e}\x1B[0m`:e;printHelp(e,t=process.stdout,n="cn"){if(e.length===0){this.printRootHelp(t);return}let i=this.root;for(let p of e){let r=i.children.get(p);if(!r){this.printRootHelp(t);return}i=r}if(i.command){this.printCommandHelp(i.command,t,n);return}let $=e.join(" ");t.write(`
262
279
  ${this.bold("Usage:",t)} bl ${$} <command> [flags]
263
280
 
264
281
  `),t.write(`${this.bold("Commands:",t)}
265
282
  `),this.printChildren(i,$,t),t.write(`
266
283
  `)}printRootHelp(e){let t=["██████╗ █████╗ ██╗██╗ ██╗ █████╗ ███╗ ██╗","██╔══██╗██╔══██╗██║██║ ██║██╔══██╗████╗ ██║","██████╔╝███████║██║██║ ██║███████║██╔██╗ ██║","██╔══██╗██╔══██║██║██║ ██║██╔══██║██║╚██╗██║","██████╔╝██║ ██║██║███████╗██║██║ ██║██║ ╚████║","╚═════╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝"],n="\x1B[1;35m",i="\x1B[0m";e.write(`
267
- `);for(let m of t)if(e.isTTY)e.write(`\x1B[1;35m${m}\x1B[0m
268
- `);else e.write(m+`
269
- `);let $=(m)=>this.bold(m,e),p=(m)=>this.accent(m,e),r=(m)=>this.dim(m,e);e.write(`
284
+ `);for(let y of t)if(e.isTTY)e.write(`\x1B[1;35m${y}\x1B[0m
285
+ `);else e.write(y+`
286
+ `);let $=(y)=>this.bold(y,e),p=(y)=>this.accent(y,e),r=(y)=>this.dim(y,e);e.write(`
270
287
  ${$("Usage:")} bl <resource> <command> [flags]
271
288
 
272
289
  ${$("Resources:")}
@@ -306,19 +323,19 @@ ${$("Getting Help:")}
306
323
  `)}printCommandHelp(e,t,n="cn"){let i=(r)=>this.bold(r,t),$=(r)=>this.accent(r,t),p=(r)=>this.dim(r,t);if(t.write(`
307
324
  ${e.description}
308
325
  `),e.usage)t.write(`${i("Usage:")} ${e.usage}
309
- `);if(e.options&&e.options.length>0){let r=Math.max(...e.options.map((m)=>m.flag.length));t.write(`
326
+ `);if(e.options&&e.options.length>0){let r=Math.max(...e.options.map((y)=>y.flag.length));t.write(`
310
327
  ${i("Options:")}
311
- `);for(let m of e.options)t.write(` ${$(m.flag.padEnd(r+2))} ${p(m.description)}
328
+ `);for(let y of e.options)t.write(` ${$(y.flag.padEnd(r+2))} ${p(y.description)}
312
329
  `)}if(e.examples&&e.examples.length>0){t.write(`
313
330
  ${i("Examples:")}
314
331
  `);for(let r of e.examples)t.write(` ${p(r)}
315
332
  `)}if(e.apiDocs)t.write(`
316
- ${i("API Reference:")} ${p(Me[n]+e.apiDocs)}
333
+ ${i("API Reference:")} ${p(Qe[n]+e.apiDocs)}
317
334
  `);t.write(`
318
335
  ${p("Global flags (--api-key, --output, --quiet, etc.) are always available.")}
319
336
  `),t.write(`${p("Run")} bl --help ${p("for the full list.")}
320
- `)}printChildren(e,t,n){let i=[],$=(r,m)=>{for(let[_,x]of r.children){if(x.command)i.push({fullName:`${m} ${_}`,description:x.command.description});if(x.children.size>0)$(x,`${m} ${_}`)}};$(e,t);let p=Math.max(...i.map((r)=>r.fullName.length));for(let{fullName:r,description:m}of i)n.write(` ${this.accent(r.padEnd(p),n)} ${this.dim(m,n)}
321
- `)}}var qe=new Tn({"auth login":Mr,"auth status":Qr,"auth logout":Or,"text chat":Pr,omni:Vr,"image generate":Ur,"image edit":ar,"video generate":lr,"video edit":Dr,"video ref":fr,"video task get":gr,"video download":en,"vision describe":$n,"app call":un,"memory add":hn,"memory search":on,"memory list":Sn,"memory update":An,"memory delete":kn,"memory profile create":qn,"memory profile get":Gn,"knowledge retrieve":Nn,"search web":jn,"speech synthesize":Rn,"speech recognize":Jn,"file upload":Wn,"config show":pn,"config set":yn,"config export-schema":_n,update:bn,help:wn});function Ge(e){if(e instanceof S){if(B(process.env.DASHSCOPE_OUTPUT)==="json")process.stderr.write(JSON.stringify(e.toJSON(),null,2)+`
337
+ `)}printChildren(e,t,n){let i=[],$=(r,y)=>{for(let[m,x]of r.children){if(x.command)i.push({fullName:`${y} ${m}`,description:x.command.description});if(x.children.size>0)$(x,`${y} ${m}`)}};$(e,t);let p=Math.max(...i.map((r)=>r.fullName.length));for(let{fullName:r,description:y}of i)n.write(` ${this.accent(r.padEnd(p),n)} ${this.dim(y,n)}
338
+ `)}}var me=new Qn({"auth login":Mr,"auth status":Qr,"auth logout":Pr,"text chat":cr,omni:Er,"image generate":sr,"image edit":Dr,"video generate":lr,"video edit":fr,"video ref":gr,"video task get":en,"video download":tn,"vision describe":pn,"app call":An,"memory add":un,"memory search":Sn,"memory list":kn,"memory update":qn,"memory delete":on,"memory profile create":Gn,"memory profile get":Kn,"knowledge retrieve":jn,"search web":Rn,"speech synthesize":Wn,"speech recognize":Tn,"file upload":Mn,"config show":yn,"config set":mn,"config export-schema":xn,update:wn,help:hn});function up(e=process.argv.slice(2),t=process.env.DASHSCOPE_OUTPUT){for(let n=0;n<e.length;n++){let i=e[n];if(i==="--output")return B(e[n+1]||t);if(i?.startsWith("--output="))return B(i.slice(9))}return B(t)}function Ke(e){if(e instanceof u){if(up()==="json")process.stderr.write(JSON.stringify(e.toJSON(),null,2)+`
322
339
  `);else{if(process.stderr.write(`
323
340
  Error: ${e.message}
324
341
  `),e.hint)process.stderr.write(`
@@ -326,34 +343,34 @@ Error: ${e.message}
326
343
  `).join(`
327
344
  `)}
328
345
  `);process.stderr.write(` (exit code ${e.exitCode})
329
- `)}process.exit(e.exitCode)}if(e instanceof Error){if(e.name==="AbortError"||e.name==="TimeoutError"||e.message.includes("timed out")){let $=new S("Request timed out.",o.TIMEOUT,`Try increasing --timeout (e.g. --timeout 60).
346
+ `)}process.exit(e.exitCode)}if(e instanceof Error){if(e.name==="AbortError"||e.name==="TimeoutError"||e.message.includes("timed out")){let $=new u("Request timed out.",h.TIMEOUT,`Try increasing --timeout (e.g. --timeout 60).
330
347
  If this happens on every request with a valid API key, you may be hitting the wrong region.
331
348
  `+`Run: bl auth status — to check your credentials and region.
332
- `+"Run: bl config set --key region --value cn — to override the region.");return Ge($)}if(e instanceof TypeError&&e.message==="fetch failed"){let $=new S("Network request failed.",o.NETWORK,"Check your network connection and proxy settings. Also verify DASHSCOPE_BASE_URL is a valid URL.");return Ge($)}let t=e.message.toLowerCase();if(t.includes("failed to fetch")||t.includes("connection refused")||t.includes("econnrefused")||t.includes("connection reset")||t.includes("econnreset")||t.includes("network error")||t.includes("enotfound")||t.includes("getaddrinfo")||t.includes("proxy")||t.includes("socket")||t.includes("etimedout")||t.includes("timeout")||t.includes("eai_AGAIN")){let $="Check your network connection and proxy settings.";if(t.includes("proxy"))$="Proxy error — check HTTP_PROXY / HTTPS_PROXY environment variables and proxy authentication.";let p=new S("Network request failed.",o.NETWORK,$);return Ge(p)}let i=e.code;if(i==="ENOENT"||i==="EACCES"||i==="ENOSPC"||i==="ENOTDIR"||i==="EISDIR"||i==="EPERM"||i==="EBUSY"){let $="Check the file path and permissions.";if(i==="ENOENT")$="File or directory not found.";if(i==="EACCES"||i==="EPERM")$="Permission denied — check file or directory permissions.";if(i==="ENOSPC")$="Disk full — free up space and try again.";let p=new S(`File system error: ${e.message}`,o.GENERAL,$);return Ge(p)}else if(typeof i==="string"&&i.startsWith("E")){let $=new S(`File system error: ${e.message}`,o.GENERAL,"Check the file path and permissions.");return Ge($)}if(process.stderr.write(`
349
+ `+"Run: bl config set --key region --value cn — to override the region.");return Ke($)}if(e instanceof TypeError&&e.message==="fetch failed"){let $=new u("Network request failed.",h.NETWORK,"Check your network connection and proxy settings. Also verify DASHSCOPE_BASE_URL is a valid URL.");return Ke($)}let t=e.message.toLowerCase();if(t.includes("failed to fetch")||t.includes("connection refused")||t.includes("econnrefused")||t.includes("connection reset")||t.includes("econnreset")||t.includes("network error")||t.includes("enotfound")||t.includes("getaddrinfo")||t.includes("proxy")||t.includes("socket")||t.includes("etimedout")||t.includes("timeout")||t.includes("eai_AGAIN")){let $="Check your network connection and proxy settings.";if(t.includes("proxy"))$="Proxy error — check HTTP_PROXY / HTTPS_PROXY environment variables and proxy authentication.";let p=new u("Network request failed.",h.NETWORK,$);return Ke(p)}let i=e.code;if(i==="ENOENT"||i==="EACCES"||i==="ENOSPC"||i==="ENOTDIR"||i==="EISDIR"||i==="EPERM"||i==="EBUSY"){let $="Check the file path and permissions.";if(i==="ENOENT")$="File or directory not found.";if(i==="EACCES"||i==="EPERM")$="Permission denied — check file or directory permissions.";if(i==="ENOSPC")$="Disk full — free up space and try again.";let p=new u(`File system error: ${e.message}`,h.GENERAL,$);return Ke(p)}else if(typeof i==="string"&&i.startsWith("E")){let $=new u(`File system error: ${e.message}`,h.GENERAL,"Check the file path and permissions.");return Ke($)}if(process.stderr.write(`
333
350
  Error: ${e.message}
334
351
  `),process.env.DASHSCOPE_VERBOSE==="1")process.stderr.write(`${e.stack}
335
352
  `)}else process.stderr.write(`
336
353
  Error: ${String(e)}
337
- `);process.exit(o.GENERAL)}import{join as Gp}from"path";import{readFileSync as Bp,writeFileSync as Kp}from"fs";var Qn=()=>Gp(je(),"update-state.json"),Np=14400000,jp=3000;function Mn(e,t){let n=e.split(".").map(Number),i=t.split(".").map(Number);for(let $=0;$<3;$++){if((n[$]??0)>(i[$]??0))return!0;if((n[$]??0)<(i[$]??0))return!1}return!1}function Rp(){try{let e=Bp(Qn(),"utf-8");return JSON.parse(e)}catch{return null}}function Jp(e){try{Kp(Qn(),JSON.stringify(e))}catch{}}async function Wp(){try{let e=Ke.replace("/","%2f"),t=await fetch(`${Xe}/${e}/latest`,{headers:{Accept:"application/json",...d()},signal:AbortSignal.timeout(jp)});if(!t.ok)return null;return(await t.json()).version??null}catch{return null}}var zt=null;function Zn(){return zt}async function cn(e){if(process.env.CI||!process.stderr.isTTY)return;let t=Rp(),n=Date.now();if(t&&n-t.lastChecked<Np){if(t.latestVersion&&Mn(t.latestVersion,e))zt=t.latestVersion;return}let i=await Wp();if(!i)return;if(Jp({lastChecked:n,latestVersion:i}),i&&Mn(i,e))zt=i}async function Hn(e){if(e.apiKey||e.fileApiKey)return;let t=process.env.DASHSCOPE_API_KEY,n;if(t){if(!O({nonInteractive:e.nonInteractive}))n=t;else if(await Xr({message:`Found DASHSCOPE_API_KEY in environment (${g(t)}). Save it to config file?`}))n=t}if(!n){if(!O({nonInteractive:e.nonInteractive}))throw new S("No API key found.",o.AUTH,`Set env var: export DASHSCOPE_API_KEY=sk-xxxxx
354
+ `);process.exit(h.GENERAL)}import{join as Sp}from"path";import{readFileSync as kp,writeFileSync as qp}from"fs";var Zn=()=>Sp(Re(),"update-state.json"),op=14400000,Gp=3000;function Hn(e,t){let n=e.split(".").map(Number),i=t.split(".").map(Number);for(let $=0;$<3;$++){if((n[$]??0)>(i[$]??0))return!0;if((n[$]??0)<(i[$]??0))return!1}return!1}function Kp(){try{let e=kp(Zn(),"utf-8");return JSON.parse(e)}catch{return null}}function Np(e){try{qp(Zn(),JSON.stringify(e))}catch{}}async function Bp(){try{let e=Be.replace("/","%2f"),t=await fetch(`${He}/${e}/latest`,{headers:{Accept:"application/json",...d()},signal:AbortSignal.timeout(Gp)});if(!t.ok)return null;return(await t.json()).version??null}catch{return null}}var Xt=null;function zn(){return Xt}async function Xn(e){if(process.env.CI||!process.stderr.isTTY)return;let t=Kp(),n=Date.now();if(t&&n-t.lastChecked<op){if(t.latestVersion&&Hn(t.latestVersion,e))Xt=t.latestVersion;return}let i=await Bp();if(!i)return;if(Np({lastChecked:n,latestVersion:i}),i&&Hn(i,e))Xt=i}async function Pn(e){if(e.apiKey||e.fileApiKey)return;let t=process.env.DASHSCOPE_API_KEY,n;if(t){if(!Y({nonInteractive:e.nonInteractive}))n=t;else if(await Yr({message:`Found DASHSCOPE_API_KEY in environment (${g(t)}). Save it to config file?`}))n=t}if(!n){if(!Y({nonInteractive:e.nonInteractive}))throw new u("No API key found.",h.AUTH,`Set env var: export DASHSCOPE_API_KEY=sk-xxxxx
338
355
  Pass directly: --api-key sk-xxxxx
339
- Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`);let p=await V({message:"Enter your DashScope API key:"});if(!p)throw new S("API key is required.",o.AUTH);n=p}let i={...ne(),api_key:n};await Re(i),e.fileApiKey=n;let $=e.configPath??"~/.bailian/config.json";process.stderr.write(`API key saved to ${$}
340
- `)}var Ot="0.1.0";process.on("SIGINT",()=>{process.stderr.write(`
356
+ Get API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key`);let p=await L({message:"Enter your DashScope API key:"});if(!p)throw new u("API key is required.",h.AUTH);n=p}let i={...te(),api_key:n};await Je(i),e.fileApiKey=n;let $=e.configPath??"~/.bailian/config.json";process.stderr.write(`API key saved to ${$}
357
+ `)}var Pt="0.1.2-beta.0";process.on("SIGINT",()=>{process.stderr.write(`
341
358
  Interrupted. Exiting.
342
- `),process.exit(130)});process.stdout.on("error",(e)=>{if(e.code==="EPIPE")process.exit(0);else throw e});var Tp=[["auth","login"],["auth","logout"],["config","show"],["config","set"],["config","export-schema"],["update"],["knowledge","retrieve"]];async function Mp(){let e=process.argv.slice(2);if(e.includes("--version")||e.includes("-v"))process.stdout.write(`bl ${Ot}
343
- `),process.exit(0);let t=Ct(e,ze);if(e.includes("--help")||e.includes("-h")){let b=e.indexOf("--region"),w=b>=0&&e[b+1]||process.env.DASHSCOPE_REGION||ne().region||"cn";qe.printHelp(t,process.stderr,w),process.exit(0)}if(t.length===0){qe.printHelp([],process.stderr);let b=ge(e,ze),w=_t(b);if(!(w.apiKey||w.fileApiKey)){let k=process.stderr.isTTY,j=k?"\x1B[38;2;147;51;234m":"",A=k?"\x1B[0m":"";process.stderr.write(`
344
- Welcome to ${j}Bailian${A} CLI!
359
+ `),process.exit(130)});process.stdout.on("error",(e)=>{if(e.code==="EPIPE")process.exit(0);else throw e});var jp=[["auth","login"],["auth","logout"],["config","show"],["config","set"],["config","export-schema"],["update"],["knowledge","retrieve"]];async function Rp(){let e=process.argv.slice(2);if(e.includes("--version")||e.includes("-v"))process.stdout.write(`bl ${Pt}
360
+ `),process.exit(0);let t=Ct(e,Oe);if(e.includes("--help")||e.includes("-h")){let b=e.indexOf("--region"),w=b>=0&&e[b+1]||process.env.DASHSCOPE_REGION||te().region||"cn";me.printHelp(t,process.stderr,w),process.exit(0)}if(t.length===0){me.printHelp([],process.stderr);let b=ge(e,Oe),w=mt(b);if(!(w.apiKey||w.fileApiKey)){let q=process.stderr.isTTY,o=q?"\x1B[38;2;147;51;234m":"",k=q?"\x1B[0m":"";process.stderr.write(`
361
+ Welcome to ${o}Bailian${k} CLI!
345
362
 
346
363
  `),process.stderr.write(` Get started in 2 steps:
347
364
  `),process.stderr.write(` 1. Get your API Key: https://bailian.console.aliyun.com/cn-beijing/?source_channel=aliway&tab=app#/api-key
348
365
  `),process.stderr.write(` 2. Login: bl auth login --api-key <your-key>
349
366
 
350
- `)}else{let k=process.stderr.isTTY,j=k?"\x1B[38;2;147;51;234m":"",A=k?"\x1B[2m":"",K=k?"\x1B[0m":"";process.stderr.write(`
351
- ${j}Quick Start${K} — try these with your AI coding assistant:
367
+ `)}else{let q=process.stderr.isTTY,o=q?"\x1B[38;2;147;51;234m":"",k=q?"\x1B[2m":"",G=q?"\x1B[0m":"";process.stderr.write(`
368
+ ${o}Quick Start${G} — try these with your AI coding assistant:
352
369
 
353
- `),["帮我生成一套鸭舌帽的亚马逊电商主图(白底 + 场景图 + 模特上身图)","帮我生成一段 3 分钟的幽默相声音频","帮我生成一套小红帽故事绘本 PDF(含插图)","帮我分析这个视频的内容并写一篇小红书文案"].forEach((X,H)=>{process.stderr.write(` ${A}${H+1}${K} ${X}
370
+ `),["帮我生成一套鸭舌帽的亚马逊电商主图(白底 + 场景图 + 模特上身图)","帮我生成一段 3 分钟的幽默相声音频","帮我生成一套小红帽故事绘本 PDF(含插图)","帮我分析这个视频的内容并写一篇小红书文案"].forEach((J,Z)=>{process.stderr.write(` ${k}${Z+1}${G} ${J}
354
371
  `)}),process.stderr.write(`
355
- `)}process.exit(0)}let{command:n,extra:i}=qe.resolve(t),$=ge(e,[...ze,...n.options??[]]);if(i.length>0)$._positional=i;let p=_t($);if(!Tp.some((b)=>b.every((w,u)=>t[u]===w)))await Hn(p);let m=cn(Ot).catch(()=>{});await n.execute(p,$),await m;let _=t.length===1&&t[0]==="update",x=Zn();if(x&&!p.quiet&&!_){let b=process.stderr.isTTY,w=b?"\x1B[33m":"",u=b?"\x1B[36m":"",k=b?"\x1B[0m":"";process.stderr.write(`
356
- ${w}Update available: ${Ot} → ${x}${k}
357
- `),process.stderr.write(` Run ${u}bl update${k} to upgrade
372
+ `)}process.exit(0)}if(me.isGroupPath(t)){let b=e.indexOf("--region"),w=b>=0&&e[b+1]||process.env.DASHSCOPE_REGION||te().region||"cn";me.printHelp(t,process.stderr,w),process.exit(0)}let{command:n,extra:i}=me.resolve(t),$=ge(e,[...Oe,...n.options??[]]);if(i.length>0)$._positional=i;let p=mt($);if(!jp.some((b)=>b.every((w,S)=>t[S]===w)))await Pn(p);let y=Xn(Pt).catch(()=>{});await n.execute(p,$),await y;let m=t.length===1&&t[0]==="update",x=zn();if(x&&!p.quiet&&!m){let b=process.stderr.isTTY,w=b?"\x1B[33m":"",S=b?"\x1B[36m":"",q=b?"\x1B[0m":"";process.stderr.write(`
373
+ ${w}Update available: ${Pt} → ${x}${q}
374
+ `),process.stderr.write(` Run ${S}bl update${q} to upgrade
358
375
 
359
- `)}}Mp().catch(Ge);
376
+ `)}}Rp().catch(Ke);