jimeng-cli 0.3.2 → 0.3.3
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/{chunk-FAXTAAQO.js → chunk-ZMTQQZFH.js} +309 -281
- package/dist/{chunk-FAXTAAQO.js.map → chunk-ZMTQQZFH.js.map} +1 -1
- package/dist/cli/index.cjs +389 -343
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +87 -65
- package/dist/cli/index.js.map +1 -1
- package/dist/mcp/index.cjs +147 -122
- package/dist/mcp/index.cjs.map +1 -1
- package/dist/mcp/index.js +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -11,13 +11,14 @@ import {
|
|
|
11
11
|
getTaskResponse,
|
|
12
12
|
getTokenLiveStatus,
|
|
13
13
|
logger_default,
|
|
14
|
+
maskToken,
|
|
14
15
|
parseRegionCode,
|
|
15
16
|
receiveCredit,
|
|
16
17
|
refreshAllTokenModels,
|
|
17
18
|
session_pool_default,
|
|
18
19
|
upscaleImage,
|
|
19
20
|
waitForTaskResponse
|
|
20
|
-
} from "../chunk-
|
|
21
|
+
} from "../chunk-ZMTQQZFH.js";
|
|
21
22
|
|
|
22
23
|
// src/cli/app.ts
|
|
23
24
|
import process2 from "process";
|
|
@@ -27,10 +28,6 @@ import { constants as fsConstants } from "fs";
|
|
|
27
28
|
import path from "path";
|
|
28
29
|
import { access, readFile } from "fs/promises";
|
|
29
30
|
import minimist from "minimist";
|
|
30
|
-
function maskToken(token) {
|
|
31
|
-
if (token.length <= 10) return "***";
|
|
32
|
-
return `${token.slice(0, 4)}...${token.slice(-4)}`;
|
|
33
|
-
}
|
|
34
31
|
function formatUnixMs(value) {
|
|
35
32
|
if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) return "-";
|
|
36
33
|
return new Date(value).toISOString();
|
|
@@ -132,29 +129,28 @@ function createTokenSubcommands(deps) {
|
|
|
132
129
|
if (!args.json) {
|
|
133
130
|
console.log(`Checking ${pairs.length} token(s)`);
|
|
134
131
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
132
|
+
const results = await Promise.all(
|
|
133
|
+
pairs.map(async ({ token, region }) => {
|
|
134
|
+
const masked = maskToken(token);
|
|
135
|
+
try {
|
|
136
|
+
const live = await getTokenLiveStatus(token, buildRegionInfo(region));
|
|
137
|
+
await session_pool_default.syncTokenCheckResult(token, live);
|
|
138
|
+
if (live) {
|
|
139
|
+
if (!args.json) console.log(`[OK] ${masked} (${region}) live=true`);
|
|
140
|
+
return { token_masked: masked, region, live: true };
|
|
141
|
+
} else {
|
|
142
|
+
if (!args.json) console.log(`[FAIL] ${masked} (${region}) live=false`);
|
|
143
|
+
return { token_masked: masked, region, live: false };
|
|
144
|
+
}
|
|
145
|
+
} catch (error) {
|
|
146
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
147
|
+
if (!args.json) console.log(`[ERROR] ${masked} (${region}) ${message}`);
|
|
148
|
+
return { token_masked: masked, region, error: message };
|
|
150
149
|
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
results.push({ token_masked: masked, region, error: message });
|
|
156
|
-
}
|
|
157
|
-
}
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
const invalid = results.filter((r) => r.live === false).length;
|
|
153
|
+
const requestErrors = results.filter((r) => r.error).length;
|
|
158
154
|
if (args.json) {
|
|
159
155
|
deps.printCommandJson("token.check", results, {
|
|
160
156
|
total: pairs.length,
|
|
@@ -202,27 +198,37 @@ function createTokenSubcommands(deps) {
|
|
|
202
198
|
await deps.ensureTokenPoolReady();
|
|
203
199
|
const explicitTokens = await collectTokensFromArgs(args, usage, deps, false);
|
|
204
200
|
const pairs = resolveTokenRegionPairs(explicitTokens, regionCode, deps);
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
201
|
+
const toErrorResult = (token, region, error) => ({
|
|
202
|
+
token_masked: maskToken(token),
|
|
203
|
+
region,
|
|
204
|
+
error: error instanceof Error ? error.message : String(error)
|
|
205
|
+
});
|
|
206
|
+
const fetchPoints = async ({ token, region }) => {
|
|
207
|
+
try {
|
|
208
|
+
return { token_masked: maskToken(token), region, points: await getCredit(token, buildRegionInfo(region)) };
|
|
209
|
+
} catch (error) {
|
|
210
|
+
return toErrorResult(token, region, error);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
const processReceive = async ({ token, region }) => {
|
|
214
|
+
const regionInfo = buildRegionInfo(region);
|
|
215
|
+
try {
|
|
213
216
|
const currentCredit = await getCredit(token, regionInfo);
|
|
214
|
-
if (currentCredit.totalCredit
|
|
215
|
-
|
|
216
|
-
await receiveCredit(token, regionInfo);
|
|
217
|
-
const updatedCredit = await getCredit(token, regionInfo);
|
|
218
|
-
return { token, credits: updatedCredit, received: true };
|
|
219
|
-
} catch (error) {
|
|
220
|
-
return { token, credits: currentCredit, received: false, error: (error == null ? void 0 : error.message) || String(error) };
|
|
221
|
-
}
|
|
217
|
+
if (currentCredit.totalCredit > 0) {
|
|
218
|
+
return { token_masked: maskToken(token), region, credits: currentCredit, received: false };
|
|
222
219
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
220
|
+
try {
|
|
221
|
+
await receiveCredit(token, regionInfo);
|
|
222
|
+
const updatedCredit = await getCredit(token, regionInfo);
|
|
223
|
+
return { token_masked: maskToken(token), region, credits: updatedCredit, received: true };
|
|
224
|
+
} catch (error) {
|
|
225
|
+
return { token_masked: maskToken(token), region, credits: currentCredit, received: false, ...toErrorResult(token, region, error) };
|
|
226
|
+
}
|
|
227
|
+
} catch (error) {
|
|
228
|
+
return toErrorResult(token, region, error);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const payload = action === "points" ? await Promise.all(pairs.map(fetchPoints)) : await Promise.all(pairs.map(processReceive));
|
|
226
232
|
if (args.json) {
|
|
227
233
|
deps.printCommandJson(`token.${action}`, payload);
|
|
228
234
|
return;
|
|
@@ -310,10 +316,13 @@ function createTokenSubcommands(deps) {
|
|
|
310
316
|
return;
|
|
311
317
|
}
|
|
312
318
|
await deps.ensureTokenPoolReady();
|
|
313
|
-
|
|
319
|
+
let payload;
|
|
320
|
+
if (action === "pool-check") {
|
|
321
|
+
payload = { ...await session_pool_default.runHealthCheck(), summary: session_pool_default.getSummary() };
|
|
322
|
+
} else {
|
|
314
323
|
session_pool_default.reloadFromDisk();
|
|
315
|
-
|
|
316
|
-
}
|
|
324
|
+
payload = { reloaded: true, summary: session_pool_default.getSummary(), items: buildTokenPoolSnapshot().items };
|
|
325
|
+
}
|
|
317
326
|
if (args.json) {
|
|
318
327
|
deps.printCommandJson(`token.${action}`, deps.unwrapBody(payload));
|
|
319
328
|
return;
|
|
@@ -534,7 +543,6 @@ function printModelIds(models) {
|
|
|
534
543
|
}
|
|
535
544
|
}
|
|
536
545
|
function printModelVerbose(models) {
|
|
537
|
-
console.log("id type desc capabilities");
|
|
538
546
|
for (const item of models) {
|
|
539
547
|
if (!item || typeof item !== "object") continue;
|
|
540
548
|
const m = item;
|
|
@@ -543,7 +551,17 @@ function printModelVerbose(models) {
|
|
|
543
551
|
const type = typeof m.model_type === "string" ? m.model_type : "-";
|
|
544
552
|
const desc = typeof m.description === "string" ? m.description : "-";
|
|
545
553
|
const caps = Array.isArray(m.capabilities) ? m.capabilities.filter((c) => typeof c === "string").join(",") : "-";
|
|
546
|
-
console.log(`${id}
|
|
554
|
+
console.log(`${id} [${type}] ${desc}`);
|
|
555
|
+
console.log(` capabilities: ${caps}`);
|
|
556
|
+
const params = m.params;
|
|
557
|
+
if (params && typeof params === "object") {
|
|
558
|
+
for (const [key, vals] of Object.entries(params)) {
|
|
559
|
+
if (Array.isArray(vals)) {
|
|
560
|
+
console.log(` ${key}: ${vals.join(", ")}`);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
console.log("");
|
|
547
565
|
}
|
|
548
566
|
}
|
|
549
567
|
function createQueryCommandHandlers(deps) {
|
|
@@ -594,20 +612,22 @@ function createQueryCommandHandlers(deps) {
|
|
|
594
612
|
if (entries.length === 0) {
|
|
595
613
|
deps.fail("No enabled+live tokens with region found in pool.");
|
|
596
614
|
}
|
|
597
|
-
const results =
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
615
|
+
const results = await Promise.all(
|
|
616
|
+
entries.map(async (entry) => {
|
|
617
|
+
const masked = maskToken(entry.token);
|
|
618
|
+
try {
|
|
619
|
+
const direct2 = await getLiveModels(`Bearer ${entry.token}`, entry.region);
|
|
620
|
+
return {
|
|
621
|
+
token: masked,
|
|
622
|
+
region: entry.region,
|
|
623
|
+
source: direct2.source,
|
|
624
|
+
models: isVerbose ? direct2.data : direct2.data.map((m) => m.id)
|
|
625
|
+
};
|
|
626
|
+
} catch (error) {
|
|
627
|
+
return { token: masked, region: entry.region, error: error instanceof Error ? error.message : String(error) };
|
|
628
|
+
}
|
|
629
|
+
})
|
|
630
|
+
);
|
|
611
631
|
if (isJson) {
|
|
612
632
|
deps.printCommandJson("models.list", results);
|
|
613
633
|
return;
|
|
@@ -616,6 +636,8 @@ function createQueryCommandHandlers(deps) {
|
|
|
616
636
|
console.log(`[${r.region}] ${r.token}`);
|
|
617
637
|
if (r.error) {
|
|
618
638
|
console.log(` error: ${r.error}`);
|
|
639
|
+
} else if (isVerbose) {
|
|
640
|
+
printModelVerbose(r.models);
|
|
619
641
|
} else {
|
|
620
642
|
for (const id of r.models) console.log(` ${id}`);
|
|
621
643
|
}
|