mmx-cli 1.0.6 → 1.0.7
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/mmx.mjs +3 -3
- package/package.json +1 -1
package/dist/mmx.mjs
CHANGED
|
@@ -109,7 +109,7 @@ Music-2.6 requires the Max plan or above.`;return""}function je(t){return`${t?.i
|
|
|
109
109
|
Re-authenticate: mmx auth login`);if(t===429)return new $(`Rate limit or quota exceeded. ${i}`,l.QUOTA,"Check usage: mmx quota show");if(t===408||t===504)return new $(`Request timed out (HTTP ${t}).`,l.TIMEOUT,"Try increasing --timeout or retry later.");if(o===1002||o===1039){let s=e.base_resp?.status_msg||"content sensitivity";return new $(`Input content flagged by sensitivity filter (${s}).`,l.CONTENT_FILTER)}if(o===1028||o===1030){let s=Ae(n);return new $(`Quota exhausted. ${i}`,l.QUOTA,`Check usage: mmx quota show${s}
|
|
110
110
|
Upgrade plan: ${je(n)}`)}if(o===2061){let s=Ae(n);return new $(`This model is not available on your current Token Plan. ${i}`,l.QUOTA,`Check usage: mmx quota show${s}
|
|
111
111
|
Upgrade plan: ${je(n)}`)}return new $(`API error: ${i} (HTTP ${t})`,l.GENERAL)}import{homedir as qe}from"os";function J(t){return t.length>8?`${t.slice(0,4)}...${t.slice(-4)}`:"***"}var Me=!1;var N="\x1B[0m",Z="\x1B[2m",Bn="\x1B[1m",In="\x1B[38;2;43;82;255m",Jn="\x1B[38;2;147;51;234m",zn="\x1B[38;2;6;184;212m",Yn="\x1B[38;2;236;72;153m";function Kn(t){return t.startsWith(qe())?t.replace(qe(),"~"):t}function Te(t,e,n){if(t.quiet||Me||!process.stderr.isTTY)return;Me=!0;let i=t.configPath?Kn(t.configPath):"~/.mmx/config.json",o=t.fileRegion?`${t.fileRegion} (file)`:"global (default)",s=t.apiKey?"(flag)":"(file)",r=J(e),a=n?` ${Z}|${N} ${Z}Model:${N} ${Jn}${n}${N}`:"";process.stderr.write(`${Bn}${In}MINIMAX${N} ${Z}${i}${N} ${Z}|${N} ${Z}Region:${N} ${zn}${o}${N} ${Z}|${N} ${Z}Key:${N} ${Yn}${r}${N} ${Z}${s}${N}${a}
|
|
112
|
-
`)}async function X(t,e){let n=typeof FormData<"u"&&e.body instanceof FormData,i="1.0.
|
|
112
|
+
`)}async function X(t,e){let n=typeof FormData<"u"&&e.body instanceof FormData,i="1.0.7",o={"User-Agent":"mmx-cli/1.0.7",...e.headers};if(!n&&!o["Content-Type"])o["Content-Type"]="application/json";if(!e.noAuth){let a=await vt(t);if(e.authStyle==="x-api-key")o["x-api-key"]=a.token;else o.Authorization=`Bearer ${a.token}`;if(t.verbose)process.stderr.write(`> ${e.method??"GET"} ${e.url}
|
|
113
113
|
`),process.stderr.write(`> Auth: ${a.token.slice(0,8)}...
|
|
114
114
|
`);let p=e.body&&typeof e.body==="object"&&"model"in e.body?String(e.body.model):void 0;Te(t,a.token,p)}let s=(e.timeout??t.timeout)*1000,r=await fetch(e.url,{method:e.method??"GET",headers:o,body:e.body?n?e.body:JSON.stringify(e.body):void 0,signal:AbortSignal.timeout(s)});if(t.verbose)process.stderr.write(`< ${r.status} ${r.statusText}
|
|
115
115
|
`);if(!r.ok){let a={};try{a=await r.json()}catch{}throw Ut(r.status,a,e.url)}return r}async function v(t,e){let n=await X(t,e),i;try{i=await n.json()}catch{let o=n.headers.get("content-type")||"";throw new $(`API returned non-JSON response (${o||"unknown type"}). Server may be experiencing issues.`,l.GENERAL)}if(i.base_resp?.status_code&&i.base_resp.status_code!==0)throw Ut(200,{base_resp:i.base_resp},e.url);return i}function Oe(t){return`${t}/anthropic/v1/messages`}function Ge(t){return`${t}/v1/t2a_v2`}function Ne(t){return`${t}/v1/get_voice`}function Be(t){return`${t}/v1/image_generation`}function Ie(t){return`${t}/v1/video_generation`}function _t(t,e){return`${t}/v1/query/video_generation?task_id=${e}`}function St(t,e){return`${t}/v1/files/retrieve?file_id=${e}`}function Rt(t){return`${t}/v1/music_generation`}function Je(t){return`${t}/v1/coding_plan/search`}function ze(t){return`${t}/v1/coding_plan/vlm`}function P(t){return`${t.includes("minimaxi.com")?"https://api.minimaxi.com":"https://api.minimax.io"}/v1/api/openplatform/coding_plan/remains`}function Xe(t){if(t<50)return["\x1B[38;2;74;222;128m","\x1B[48;2;22;163;74m"];if(t<=80)return["\x1B[38;2;250;204;21m","\x1B[48;2;202;138;4m"];return["\x1B[38;2;248;113;113m","\x1B[48;2;220;38;38m"]}var Xn={dashboard:"TokenPlan Quota",week:"Week",weekly:"Weekly",resetsIn:"Resets in",noData:"No quota data available.",now:"now"},Qn={dashboard:"TokenPlan 配额面板",week:"周期",weekly:"每周",resetsIn:"重置于",noData:"暂无配额数据",now:"即将"};function Vn(t,e){if(t<=0)return e;let n=Math.floor(t/3600000),i=Math.floor(t%3600000/60000);return n>0?`${n}h ${i}m`:`${i}m`}function Ye(t){return new Date(t).toISOString().slice(0,10)}function Zn(t){return t>=11904&&t<=40959||t>=63744&&t<=64255||t>=65072&&t<=65103||t>=65281&&t<=65376||t>=131072&&t<=195103}function U(t){let e=t.replace(/\x1b\[[0-9;]*m/g,""),n=0;for(let i of e)n+=Zn(i.codePointAt(0))?2:1;return n}var gt=16;function Ke(t,e){let n=Math.max(0,Math.min(100,t))/100,i=Math.round(gt*n),o=gt-i,s=`${t}%`.padStart(4);if(!e)return`[${"█".repeat(i)}${".".repeat(o)}] ${s}`;let[r,a]=Xe(t);return`${a}${" ".repeat(i)}\x1B[0m\x1B[48;2;55;65;81m${" ".repeat(o)}\x1B[0m ${r}\x1B[1m${s}\x1B[0m`}function kt(t,e,n,i,o){return o?`\x1B[2m${e}${n.repeat(t)}${i}\x1B[0m`:`+${"-".repeat(t)}+`}function Wt(t,e,n,i){let o=Math.max(0,e-2-n);return i?`${"\x1B[2m"}│${"\x1B[0m"} ${t}${" ".repeat(o)} ${"\x1B[2m"}│${"\x1B[0m"}`:`| ${t}${" ".repeat(o)} |`}function it(t,e){let n=!e.noColor&&process.stdout.isTTY===!0,i=e.region==="cn"?Qn:Xn,o=t.length>0?Math.max(...t.map((w)=>w.model_name.length)):16,s=n?gt+5:gt+7,r=Math.max(68,o+2+15+2+s+2),a=t.length>0?`${Ye(t[0].weekly_start_time)} — ${Ye(t[0].weekly_end_time)}`:"",p=`MINIMAX ${i.dashboard}`,u=`${i.week}: ${a}`,y=Math.max(2,r-2-U(p)-U(u)),c=n?`\x1B[1m\x1B[38;2;43;82;255mMINIMAX\x1B[0m \x1B[2m${i.dashboard}\x1B[0m${" ".repeat(y)}\x1B[2m${i.week}:\x1B[0m \x1B[38;2;6;184;212m${a}\x1B[0m`:`${p}${" ".repeat(y)}${u}`,x=U(p)+y+U(u);if(console.log(""),console.log(kt(r,"╭","─","╮",n)),console.log(Wt(c,r,x,n)),t.length===0){console.log(kt(r,"╰","─","╯",n)),console.log(`
|
|
@@ -161,7 +161,7 @@ Response:
|
|
|
161
161
|
`);return}process.stdout.write(p.content+`
|
|
162
162
|
`)}});var Hr=b({name:"quota show",description:"Display Token Plan usage and remaining quotas",usage:"mmx quota show",examples:["mmx quota show","mmx quota show --output json"],async run(t,e){if(t.dryRun){console.log("Would fetch quota information.");return}let n=P(t.baseUrl),i=await v(t,{url:n}),o=i.model_remains||[],s=f(e.output);if(s!=="text"){console.log(h(i,s));return}if(t.quiet){for(let r of o){let a=r.current_interval_total_count-r.current_interval_usage_count;console.log(`${r.model_name} ${r.current_interval_usage_count} ${r.current_interval_total_count} ${a}`)}return}it(o,t)}});var Cr=b({name:"config show",description:"Display current configuration",usage:"mmx config show",examples:["mmx config show","mmx config show --output json"],async run(t,e){let n=G(),i=f(t.output),o={region:t.region,base_url:t.baseUrl,output:t.output,timeout:t.timeout,config_file:V()};if(n.api_key)o.api_key=J(n.api_key);console.log(h(o,i))}});var Er=["region","base_url","output","timeout","api_key"],Pr=b({name:"config set",description:"Set a config value",usage:"mmx config set --key <key> --value <value>",options:[{flag:"--key <key>",description:"Config key (region, base_url, output, timeout, api_key)"},{flag:"--value <value>",description:"Value to set"}],examples:["mmx config set --key output --value json","mmx config set --key timeout --value 600","mmx config set --key base_url --value https://api-uw.minimax.io"],async run(t,e){let{key:n,value:i}=e;if(!n||i===void 0)throw new $("--key and --value are required.",l.USAGE,"mmx config set --key <key> --value <value>");if(!Er.includes(n))throw new $(`Invalid config key "${n}". Valid keys: ${Er.join(", ")}`,l.USAGE);if(n==="region"&&!["global","cn"].includes(i))throw new $(`Invalid region "${i}". Valid values: global, cn`,l.USAGE);if(n==="output"&&!["text","json"].includes(i))throw new $(`Invalid output format "${i}". Valid values: text, json`,l.USAGE);if(n==="timeout"){let r=Number(i);if(isNaN(r)||r<=0)throw new $(`Invalid timeout "${i}". Must be a positive number.`,l.USAGE)}let o=f(t.output);if(t.dryRun){console.log(h({would_set:{[n]:i}},o));return}let s=G();if(s[n]=n==="timeout"?Number(i):i,await Y(s),!t.quiet)console.log(h({[n]:s[n]},o))}});function Go(t){let e=t.match(/^--([a-zA-Z0-9-]+)/),n=e?e[1]:"",i=n.replace(/-([a-zA-Z0-9])/g,(r,a)=>a.toUpperCase()),o="string",s=!1;if(!t.includes("<")&&!t.includes("["))o="boolean";else if(t.includes("<n>")||t.includes("<hz>")||t.includes("<bps>")||t.includes("<count>"))o="number";if(t.toLowerCase().includes("repeatable"))s=!0;return{name:i,kebabName:n,inferredType:o,isArray:s}}function xe(t){let n={name:`mmx_${t.name.replace(/ /g,"_")}`,description:t.description,input_schema:{type:"object",properties:{},required:[]}};if(t.options)for(let i of t.options){let{name:o,inferredType:s,isArray:r}=Go(i.flag);if(!o)continue;let a=i.type,p=r?"array":a??s,u={description:i.description};if(p==="array")u.type="array",u.items={type:"string"};else u.type=p;let y=n.input_schema;if(y.properties[o]=u,i.required)y.required.push(o)}return n}var No=["auth ","config ","update"],Lr=b({name:"config export-schema",description:"Export all (or one) CLI command(s) as Anthropic/OpenAI-compatible JSON tool schemas",usage:'mmx config export-schema [--command "<name>"]',options:[{flag:"--command <name>",description:'Export schema for a specific command only (e.g. "image generate")'}],examples:["mmx config export-schema",'mmx config export-schema --command "video generate"'],async run(t,e){let n=e.command;if(n){try{let{command:s}=E.resolve(n.split(" ")),r=xe(s);process.stdout.write(JSON.stringify(r,null,2)+`
|
|
163
163
|
`)}catch{throw new $(`Command "${n}" not found.`,l.USAGE)}return}let o=E.getAllCommands().filter((s)=>!No.some((r)=>s.name.startsWith(r))).map((s)=>xe(s));process.stdout.write(JSON.stringify(o,null,2)+`
|
|
164
|
-
`)}});var Bo="1.0.
|
|
164
|
+
`)}});var Bo="1.0.7",Fr=b({name:"update",description:"Update mmx to the latest version",usage:"mmx update",examples:["mmx update"],async run(){process.stderr.write(`Current version: ${Bo}
|
|
165
165
|
|
|
166
166
|
`),process.stderr.write(`Run:
|
|
167
167
|
`),process.stderr.write(` npm update -g mmx-cli
|
|
@@ -242,7 +242,7 @@ Error: ${String(t)}
|
|
|
242
242
|
`),"global";let o=i.region;return process.stderr.write(` ${o}
|
|
243
243
|
`),o}async function en(t){let e=G();e.region=t,await Y(e)}import{join as Yo}from"path";import{readFileSync as Ko,writeFileSync as Xo}from"fs";var rn=()=>Yo(pt(),"update-state.json"),Qo=86400000,Vo=3000,Zo="MiniMax-AI-Dev/minimax-cli";function Uo(){try{let t=Ko(rn(),"utf-8");return JSON.parse(t)}catch{return null}}function Wo(t){try{Xo(rn(),JSON.stringify(t))}catch{}}async function Ho(){try{let t=await fetch(`https://api.github.com/repos/${Zo}/releases/latest`,{headers:{Accept:"application/vnd.github+json","X-GitHub-Api-Version":"2022-11-28"},signal:AbortSignal.timeout(Vo)});if(!t.ok)return null;return(await t.json()).tag_name??null}catch{return null}}var de=null;function nn(){return de}async function on(t){if(process.env.CI||!process.stderr.isTTY)return;let e=Uo(),n=Date.now();if(e&&n-e.lastChecked<Qo){if(e.latestVersion&&e.latestVersion!==`v${t}`)de=e.latestVersion;return}let i=await Ho();if(!i)return;if(Wo({lastChecked:n,latestVersion:i}),i!==`v${t}`)de=i}async function sn(t){if(t.apiKey||t.fileApiKey)return;let e=process.env.MINIMAX_API_KEY,n;if(e){if(!j({nonInteractive:t.nonInteractive}))n=e;else if(await Ar({message:`Found MINIMAX_API_KEY in environment (${J(e)}). Save it to config file?`}))n=e}if(!n){if(!j({nonInteractive:t.nonInteractive}))throw new $("No API key found.",l.AUTH,`Set env var: export MINIMAX_API_KEY=sk-xxxxx
|
|
244
244
|
Pass directly: --api-key sk-xxxxx`);let s=await K({message:"Enter your MiniMax API key:"});if(!s)throw new $("API key is required.",l.AUTH);n=s}let i={...G(),api_key:n};await Y(i),t.fileApiKey=n;let o=t.configPath??"~/.mmx/config.json";process.stderr.write(`API key saved to ${o}
|
|
245
|
-
`)}var an="1.0.
|
|
245
|
+
`)}var an="1.0.7";process.on("SIGINT",()=>{process.stderr.write(`
|
|
246
246
|
Interrupted. Exiting.
|
|
247
247
|
`),process.exit(130)});process.stdout.on("error",(t)=>{if(t.code==="EPIPE")process.exit(0);else throw t});var Co=[["auth","login"],["auth","logout"],["config","show"],["config","set"],["config","export-schema"],["update"]];async function Eo(){let t=process.argv.slice(2);if(t.includes("--version")||t.includes("-v"))console.log(`mmx ${an}`),process.exit(0);let e=fe(t,wt);if(t.includes("--help")||t.includes("-h"))E.printHelp(e,process.stderr),process.exit(0);if(e.length===0){E.printHelp([],process.stderr);let{command:u}=E.resolve(["quota","show"]),y=Qt(t,[...wt,...u.options??[]]),c=Ct(y),x=!!(c.apiKey||c.fileApiKey),w=!!await I();if(x||w)await u.execute(c,y);else process.stderr.write(` Not logged in.
|
|
248
248
|
`),process.stderr.write(` mmx auth login --api-key sk-xxxxx
|