mmx-cli 1.0.22 → 1.0.25
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/index.d.ts +14 -1
- package/dist/mmx.mjs +781 -270
- package/dist/sdk.mjs +76 -22
- package/package.json +8 -3
package/dist/sdk.mjs
CHANGED
|
@@ -534,10 +534,15 @@ var package_default = {
|
|
|
534
534
|
"test:watch": "bun test --watch"
|
|
535
535
|
},
|
|
536
536
|
dependencies: {
|
|
537
|
-
"@clack/
|
|
537
|
+
"@clack/core": "1.0.0",
|
|
538
|
+
"@clack/prompts": "1.0.0",
|
|
538
539
|
"bun-plugin-dts": "^0.4.0",
|
|
539
540
|
"es-toolkit": "^1.46.1",
|
|
540
|
-
|
|
541
|
+
"jsonc-parser": "^3.3.1",
|
|
542
|
+
picocolors: "^1.1.1",
|
|
543
|
+
"smol-toml": "^1.8.0",
|
|
544
|
+
undici: "^6.21.1",
|
|
545
|
+
yaml: "^2.9.0"
|
|
541
546
|
},
|
|
542
547
|
devDependencies: {
|
|
543
548
|
"@eslint/js": "^9.0.0",
|
|
@@ -834,6 +839,24 @@ function vlmEndpoint(baseUrl) {
|
|
|
834
839
|
function quotaEndpoint(baseUrl) {
|
|
835
840
|
return `${baseUrl}/v1/token_plan/remains`;
|
|
836
841
|
}
|
|
842
|
+
function accountBalanceEndpoint(baseUrl) {
|
|
843
|
+
return `${baseUrl}/account/query_balance`;
|
|
844
|
+
}
|
|
845
|
+
function isSecretApiKey(apiKey) {
|
|
846
|
+
return apiKey.startsWith("sk-api-");
|
|
847
|
+
}
|
|
848
|
+
function selectUsageEndpoint(baseUrl, credential) {
|
|
849
|
+
if (credential.method === "api-key" && isSecretApiKey(credential.token)) {
|
|
850
|
+
return {
|
|
851
|
+
url: accountBalanceEndpoint(baseUrl),
|
|
852
|
+
kind: "account-balance"
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
return {
|
|
856
|
+
url: quotaEndpoint(baseUrl),
|
|
857
|
+
kind: "quota"
|
|
858
|
+
};
|
|
859
|
+
}
|
|
837
860
|
function fileUploadEndpoint(baseUrl) {
|
|
838
861
|
return `${baseUrl}/v1/files/upload`;
|
|
839
862
|
}
|
|
@@ -2105,34 +2128,63 @@ class VisionSDK extends Client {
|
|
|
2105
2128
|
}
|
|
2106
2129
|
|
|
2107
2130
|
// src/sdk/quota/index.ts
|
|
2131
|
+
function isQuotaResponse(response) {
|
|
2132
|
+
return "model_remains" in response;
|
|
2133
|
+
}
|
|
2134
|
+
function isAccountBalanceResponse(response) {
|
|
2135
|
+
return "available_amount" in response;
|
|
2136
|
+
}
|
|
2137
|
+
|
|
2108
2138
|
class QuotaSDK extends Client {
|
|
2109
2139
|
async info() {
|
|
2110
|
-
const
|
|
2111
|
-
const
|
|
2112
|
-
|
|
2140
|
+
const credential = await resolveCredential(this.config);
|
|
2141
|
+
const endpoint = selectUsageEndpoint(this.config.baseUrl, credential);
|
|
2142
|
+
if (endpoint.kind === "account-balance") {
|
|
2143
|
+
return this.requestJson({ url: endpoint.url });
|
|
2144
|
+
}
|
|
2145
|
+
return this.requestJson({ url: endpoint.url });
|
|
2113
2146
|
}
|
|
2114
2147
|
}
|
|
2115
2148
|
|
|
2116
|
-
// src/
|
|
2149
|
+
// src/files/upload.ts
|
|
2117
2150
|
import { existsSync as existsSync5 } from "node:fs";
|
|
2118
2151
|
import { readFile } from "node:fs/promises";
|
|
2119
|
-
import { resolve as resolve3
|
|
2152
|
+
import { basename, resolve as resolve3 } from "node:path";
|
|
2153
|
+
function resolveFileUploadPath(filePath, createFileNotFoundError) {
|
|
2154
|
+
const fullPath = resolve3(filePath);
|
|
2155
|
+
if (!existsSync5(fullPath)) {
|
|
2156
|
+
throw createFileNotFoundError(fullPath);
|
|
2157
|
+
}
|
|
2158
|
+
return fullPath;
|
|
2159
|
+
}
|
|
2160
|
+
async function uploadFile({
|
|
2161
|
+
filePath,
|
|
2162
|
+
purpose,
|
|
2163
|
+
baseUrl,
|
|
2164
|
+
requestJson: requestJson2,
|
|
2165
|
+
createFileNotFoundError
|
|
2166
|
+
}) {
|
|
2167
|
+
const fullPath = resolveFileUploadPath(filePath, createFileNotFoundError);
|
|
2168
|
+
const fileData = await readFile(fullPath);
|
|
2169
|
+
const formData = new FormData;
|
|
2170
|
+
formData.append("file", new Blob([fileData]), basename(fullPath));
|
|
2171
|
+
formData.append("purpose", purpose);
|
|
2172
|
+
return requestJson2({
|
|
2173
|
+
url: fileUploadEndpoint(baseUrl),
|
|
2174
|
+
method: "POST",
|
|
2175
|
+
body: formData
|
|
2176
|
+
});
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2179
|
+
// src/sdk/file/index.ts
|
|
2120
2180
|
class FileSDK extends Client {
|
|
2121
2181
|
async upload(filePath, purpose = "retrieval") {
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
const formData = new FormData;
|
|
2129
|
-
formData.append("file", new Blob([fileData]), fileName);
|
|
2130
|
-
formData.append("purpose", purpose);
|
|
2131
|
-
const url = fileUploadEndpoint(this.config.baseUrl);
|
|
2132
|
-
return this.requestJson({
|
|
2133
|
-
url,
|
|
2134
|
-
method: "POST",
|
|
2135
|
-
body: formData
|
|
2182
|
+
return uploadFile({
|
|
2183
|
+
filePath,
|
|
2184
|
+
purpose,
|
|
2185
|
+
baseUrl: this.config.baseUrl,
|
|
2186
|
+
requestJson: (opts) => this.requestJson(opts),
|
|
2187
|
+
createFileNotFoundError: (fullPath) => new SDKError(`File not found: ${fullPath}`, ExitCode.USAGE)
|
|
2136
2188
|
});
|
|
2137
2189
|
}
|
|
2138
2190
|
async list() {
|
|
@@ -2176,5 +2228,7 @@ class MiniMaxSDK extends Client {
|
|
|
2176
2228
|
}
|
|
2177
2229
|
}
|
|
2178
2230
|
export {
|
|
2179
|
-
MiniMaxSDK
|
|
2231
|
+
MiniMaxSDK,
|
|
2232
|
+
isAccountBalanceResponse,
|
|
2233
|
+
isQuotaResponse
|
|
2180
2234
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mmx-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"description": "CLI for the MiniMax AI Platform",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -40,10 +40,15 @@
|
|
|
40
40
|
"test:watch": "bun test --watch"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@clack/
|
|
43
|
+
"@clack/core": "1.0.0",
|
|
44
|
+
"@clack/prompts": "1.0.0",
|
|
44
45
|
"bun-plugin-dts": "^0.4.0",
|
|
45
46
|
"es-toolkit": "^1.46.1",
|
|
46
|
-
"
|
|
47
|
+
"jsonc-parser": "^3.3.1",
|
|
48
|
+
"picocolors": "^1.1.1",
|
|
49
|
+
"smol-toml": "^1.8.0",
|
|
50
|
+
"undici": "^6.21.1",
|
|
51
|
+
"yaml": "^2.9.0"
|
|
47
52
|
},
|
|
48
53
|
"devDependencies": {
|
|
49
54
|
"@eslint/js": "^9.0.0",
|