mmx-cli 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/mmx.mjs +3 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://
|
|
2
|
+
<img src="https://filecdn.minimax.chat/public/6335add6-5bff-42c8-89bf-0a505aa61c5a.png" alt="MiniMax" width="320" />
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
package/dist/mmx.mjs
CHANGED
|
@@ -109,7 +109,7 @@ Music-2.5 requires the Max plan or above.`;return""}function Re(t){return`${t?.i
|
|
|
109
109
|
Re-authenticate: mmx auth login`);if(t===429)return new c(`Rate limit or quota exceeded. ${r}`,l.QUOTA,"Check usage: mmx quota show");if(t===408||t===504)return new c(`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 c(`Input content flagged by sensitivity filter (${s}).`,l.CONTENT_FILTER)}if(o===1028||o===1030){let s=Se(i);return new c(`Quota exhausted. ${r}`,l.QUOTA,`Check usage: mmx quota show${s}
|
|
110
110
|
Upgrade plan: ${Re(i)}`)}if(o===2061){let s=Se(i);return new c(`This model is not available on your current Token Plan. ${r}`,l.QUOTA,`Check usage: mmx quota show${s}
|
|
111
111
|
Upgrade plan: ${Re(i)}`)}return new c(`API error: ${r} (HTTP ${t})`,l.GENERAL)}import{homedir as ke}from"os";function I(t){return t.length>8?`${t.slice(0,4)}...${t.slice(-4)}`:"***"}var ge=!1;var G="\x1B[0m",V="\x1B[2m",Ri="\x1B[1m",ki="\x1B[38;2;43;82;255m",gi="\x1B[38;2;147;51;234m",Ai="\x1B[38;2;6;184;212m",ji="\x1B[38;2;236;72;153m";function Mi(t){return t.startsWith(ke())?t.replace(ke(),"~"):t}function Ae(t,e,i){if(t.quiet||ge||!process.stderr.isTTY)return;ge=!0;let r=t.configPath?Mi(t.configPath):"~/.mmx/config.json",o=t.fileRegion?`${t.fileRegion} (file)`:"global (default)",s=t.apiKey?"(flag)":"(file)",n=I(e),m=i?` ${V}|${G} ${V}Model:${G} ${gi}${i}${G}`:"";process.stderr.write(`${Ri}${ki}MINIMAX${G} ${V}${r}${G} ${V}|${G} ${V}Region:${G} ${Ai}${o}${G} ${V}|${G} ${V}Key:${G} ${ji}${n}${G} ${V}${s}${G}${m}
|
|
112
|
-
`)}async function E(t,e){let i=typeof FormData<"u"&&e.body instanceof FormData,r="1.0.
|
|
112
|
+
`)}async function E(t,e){let i=typeof FormData<"u"&&e.body instanceof FormData,r="1.0.2",o={"User-Agent":"mmx-cli/1.0.2",...e.headers};if(!i&&!o["Content-Type"])o["Content-Type"]="application/json";if(!e.noAuth){let m=await dt(t);if(e.authStyle==="x-api-key")o["x-api-key"]=m.token;else o.Authorization=`Bearer ${m.token}`;if(t.verbose)process.stderr.write(`> ${e.method??"GET"} ${e.url}
|
|
113
113
|
`),process.stderr.write(`> Auth: ${m.token.slice(0,8)}...
|
|
114
114
|
`);let a=e.body&&typeof e.body==="object"&&"model"in e.body?String(e.body.model):void 0;Ae(t,m.token,a)}let s=(e.timeout??t.timeout)*1000,n=await fetch(e.url,{method:e.method??"GET",headers:o,body:e.body?i?e.body:JSON.stringify(e.body):void 0,signal:AbortSignal.timeout(s)});if(t.verbose)process.stderr.write(`< ${n.status} ${n.statusText}
|
|
115
115
|
`);if(!n.ok){let m={};try{m=await n.json()}catch{}throw Xt(n.status,m,e.url)}return n}async function v(t,e){let i=await E(t,e),r;try{r=await i.json()}catch{let o=i.headers.get("content-type")||"";throw new c(`API returned non-JSON response (${o||"unknown type"}). Server may be experiencing issues.`,l.GENERAL)}if(r.base_resp?.status_code&&r.base_resp.status_code!==0)throw Xt(200,{base_resp:r.base_resp},e.url);return r}function je(t){return`${t}/anthropic/v1/messages`}function Me(t){return`${t}/v1/t2a_v2`}function qe(t){return`${t}/v1/get_voice`}function Te(t){return`${t}/v1/image_generation`}function Oe(t){return`${t}/v1/video_generation`}function _t(t,e){return`${t}/v1/query/video_generation?task_id=${e}`}function vt(t,e){return`${t}/v1/files/retrieve?file_id=${e}`}function Ge(t){return`${t}/v1/music_generation`}function Ne(t){return`${t}/v1/coding_plan/search`}function Be(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 Je(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 qi={dashboard:"Quota Dashboard",week:"Week",weekly:"Weekly",resetsIn:"Resets in",noData:"No quota data available.",now:"now"},Ti={dashboard:"配额面板",week:"周期",weekly:"每周",resetsIn:"重置于",noData:"暂无配额数据",now:"即将"};function Oi(t,e){if(t<=0)return e;let i=Math.floor(t/3600000),r=Math.floor(t%3600000/60000);return i>0?`${i}h ${r}m`:`${r}m`}function Ie(t){return new Date(t).toISOString().slice(0,10)}function Gi(t){return t>=11904&&t<=40959||t>=63744&&t<=64255||t>=65072&&t<=65103||t>=65281&&t<=65376||t>=131072&&t<=195103}function Z(t){let e=t.replace(/\x1b\[[0-9;]*m/g,""),i=0;for(let r of e)i+=Gi(r.codePointAt(0))?2:1;return i}var St=16;function ze(t,e){let i=Math.max(0,Math.min(100,t))/100,r=Math.round(St*i),o=St-r,s=`${t}%`.padStart(4);if(!e)return`[${"█".repeat(r)}${".".repeat(o)}] ${s}`;let[n,m]=Je(t);return`${m}${" ".repeat(r)}\x1B[0m\x1B[48;2;55;65;81m${" ".repeat(o)}\x1B[0m ${n}\x1B[1m${s}\x1B[0m`}function ft(t,e,i,r,o){return o?`\x1B[2m${e}${i.repeat(t)}${r}\x1B[0m`:`+${"-".repeat(t)}+`}function Qt(t,e,i,r){let o=Math.max(0,e-2-i);return r?`${"\x1B[2m"}│${"\x1B[0m"} ${t}${" ".repeat(o)} ${"\x1B[2m"}│${"\x1B[0m"}`:`| ${t}${" ".repeat(o)} |`}function ot(t,e){let i=!e.noColor&&process.stdout.isTTY===!0,r=e.region==="cn"?Ti:qi,o=t.length>0?Math.max(...t.map((b)=>b.model_name.length)):16,s=i?St+5:St+7,n=Math.max(68,o+2+15+2+s+2),m=t.length>0?`${Ie(t[0].weekly_start_time)} — ${Ie(t[0].weekly_end_time)}`:"",a=`MINIMAX ${r.dashboard}`,u=`${r.week}: ${m}`,y=Math.max(2,n-2-Z(a)-Z(u)),$=i?`\x1B[1m\x1B[38;2;43;82;255mMINIMAX\x1B[0m \x1B[2m${r.dashboard}\x1B[0m${" ".repeat(y)}\x1B[2m${r.week}:\x1B[0m \x1B[38;2;6;184;212m${m}\x1B[0m`:`${a}${" ".repeat(y)}${u}`,h=Z(a)+y+Z(u);if(console.log(""),console.log(ft(n,"╭","─","╮",i)),console.log(Qt($,n,h,i)),t.length===0){console.log(ft(n,"╰","─","╯",i)),console.log(`
|
|
@@ -160,7 +160,7 @@ Response:
|
|
|
160
160
|
`);return}process.stdout.write(a.content+`
|
|
161
161
|
`)}});var Xn=d({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 i=P(t.baseUrl),r=await v(t,{url:i}),o=r.model_remains||[],s=_(e.output);if(s!=="text"){console.log(w(r,s));return}if(t.quiet){for(let n of o){let m=n.current_interval_total_count-n.current_interval_usage_count;console.log(`${n.model_name} ${n.current_interval_usage_count} ${n.current_interval_total_count} ${m}`)}return}ot(o,t)}});var Qn=d({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 i=O(),r=_(t.output),o={region:t.region,base_url:t.baseUrl,output:t.output,timeout:t.timeout,config_file:Q()};if(i.api_key)o.api_key=I(i.api_key);console.log(w(o,r))}});var Vn=["region","base_url","output","timeout","api_key"],Zn=d({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:i,value:r}=e;if(!i||r===void 0)throw new c("--key and --value are required.",l.USAGE,"mmx config set --key <key> --value <value>");if(!Vn.includes(i))throw new c(`Invalid config key "${i}". Valid keys: ${Vn.join(", ")}`,l.USAGE);if(i==="region"&&!["global","cn"].includes(r))throw new c(`Invalid region "${r}". Valid values: global, cn`,l.USAGE);if(i==="output"&&!["text","json"].includes(r))throw new c(`Invalid output format "${r}". Valid values: text, json`,l.USAGE);if(i==="timeout"){let n=Number(r);if(isNaN(n)||n<=0)throw new c(`Invalid timeout "${r}". Must be a positive number.`,l.USAGE)}let o=_(t.output);if(t.dryRun){console.log(w({would_set:{[i]:r}},o));return}let s=O();if(s[i]=i==="timeout"?Number(r):r,await K(s),!t.quiet)console.log(w({[i]:s[i]},o))}});function vo(t){let e=t.match(/^--([a-zA-Z0-9-]+)/),i=e?e[1]:"",r=i.replace(/-([a-zA-Z0-9])/g,(n,m)=>m.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:r,kebabName:i,inferredType:o,isArray:s}}function $e(t){let i={name:`mmx_${t.name.replace(/ /g,"_")}`,description:t.description,input_schema:{type:"object",properties:{},required:[]}};if(t.options)for(let r of t.options){let{name:o,inferredType:s,isArray:n}=vo(r.flag);if(!o)continue;let m=r.type,a=n?"array":m??s,u={description:r.description};if(a==="array")u.type="array",u.items={type:"string"};else u.type=a;let y=i.input_schema;if(y.properties[o]=u,r.required)y.required.push(o)}return i}var fo=["auth ","config ","update"],Wn=d({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 i=e.command;if(i){try{let{command:s}=C.resolve(i.split(" ")),n=$e(s);process.stdout.write(JSON.stringify(n,null,2)+`
|
|
162
162
|
`)}catch{throw new c(`Command "${i}" not found.`,l.USAGE)}return}let o=C.getAllCommands().filter((s)=>!fo.some((n)=>s.name.startsWith(n))).map((s)=>$e(s));process.stdout.write(JSON.stringify(o,null,2)+`
|
|
163
|
-
`)}});var So="1.0.
|
|
163
|
+
`)}});var So="1.0.2",Hn=d({name:"update",description:"Update mmx to the latest version",usage:"mmx update",examples:["mmx update"],async run(){process.stderr.write(`Current version: ${So}
|
|
164
164
|
|
|
165
165
|
`),process.stderr.write(`Run:
|
|
166
166
|
`),process.stderr.write(` npm update -g mmx-cli
|
|
@@ -243,7 +243,7 @@ Error: ${String(t)}
|
|
|
243
243
|
`),"global";let o=r.region;return process.stderr.write(` ${o}
|
|
244
244
|
`),o}async function En(t){let e=O();e.region=t,await K(e)}import{join as Ao}from"path";import{readFileSync as jo,writeFileSync as Mo}from"fs";var Pn=()=>Ao(at(),"update-state.json"),qo=86400000,To=3000,Oo="MiniMax-AI-Dev/minimax-cli";function Go(){try{let t=jo(Pn(),"utf-8");return JSON.parse(t)}catch{return null}}function No(t){try{Mo(Pn(),JSON.stringify(t))}catch{}}async function Bo(){try{let t=await fetch(`https://api.github.com/repos/${Oo}/releases/latest`,{headers:{Accept:"application/vnd.github+json","X-GitHub-Api-Version":"2022-11-28"},signal:AbortSignal.timeout(To)});if(!t.ok)return null;return(await t.json()).tag_name??null}catch{return null}}var le=null;function Ln(){return le}async function Fn(t){if(process.env.CI||!process.stderr.isTTY)return;let e=Go(),i=Date.now();if(e&&i-e.lastChecked<qo){if(e.latestVersion&&e.latestVersion!==`v${t}`)le=e.latestVersion;return}let r=await Bo();if(!r)return;if(No({lastChecked:i,latestVersion:r}),r!==`v${t}`)le=r}async function Dn(t){if(t.apiKey||t.fileApiKey)return;let e=process.env.MINIMAX_API_KEY,i;if(e){if(!A({nonInteractive:t.nonInteractive}))i=e;else if(await gn({message:`Found MINIMAX_API_KEY in environment (${I(e)}). Save it to config file?`}))i=e}if(!i){if(!A({nonInteractive:t.nonInteractive}))throw new c("No API key found.",l.AUTH,`Set env var: export MINIMAX_API_KEY=sk-xxxxx
|
|
245
245
|
Pass directly: --api-key sk-xxxxx`);let s=await X({message:"Enter your MiniMax API key:"});if(!s)throw new c("API key is required.",l.AUTH);i=s}let r={...O(),api_key:i};await K(r),t.fileApiKey=i;let o=t.configPath??"~/.mmx/config.json";process.stderr.write(`API key saved to ${o}
|
|
246
|
-
`)}var ti="1.0.
|
|
246
|
+
`)}var ti="1.0.2";process.on("SIGINT",()=>{process.stderr.write(`
|
|
247
247
|
Interrupted. Exiting.
|
|
248
248
|
`),process.exit(130)});var Io=[["auth","login"],["auth","logout"],["config","show"],["config","set"],["config","export-schema"],["update"]];async function zo(){let t=process.argv.slice(2);if(t.includes("--version")||t.includes("-v"))console.log(`mmx ${ti}`),process.exit(0);let e=he(t,ht);if(t.includes("--help")||t.includes("-h"))C.printHelp(e,process.stderr),process.exit(0);if(e.length===0){C.printHelp([],process.stderr);let{command:u}=C.resolve(["quota","show"]),y=Jt(t,[...ht,...u.options??[]]),$=Zt(y),h=!!($.apiKey||$.fileApiKey),b=!!await B();if(h||b)await u.execute($,y);else process.stderr.write(` Not logged in.
|
|
249
249
|
`),process.stderr.write(` mmx auth login --api-key sk-xxxxx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mmx-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "CLI for the MiniMax AI Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "bun run src/main.ts",
|
|
17
17
|
"build": "bun run build.ts",
|
|
18
|
-
"build:dev": "bun build src/main.ts --outfile dist/mmx.mjs --target node --minify --define \"process.env.CLI_VERSION='1.0.
|
|
18
|
+
"build:dev": "bun build src/main.ts --outfile dist/mmx.mjs --target node --minify --define \"process.env.CLI_VERSION='1.0.2'\" && printf '#!/usr/bin/env node\\n' | cat - dist/mmx.mjs > dist/tmp && mv dist/tmp dist/mmx.mjs && chmod +x dist/mmx.mjs",
|
|
19
19
|
"prepublishOnly": "bun run build",
|
|
20
20
|
"lint": "eslint src/ test/",
|
|
21
21
|
"typecheck": "tsc --noEmit",
|