replicate-token-verification 1.0.0 → 1.0.1
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 +9 -2
- package/bin/replicate-token-verification.js +20 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ rtv
|
|
|
40
40
|
rtv
|
|
41
41
|
rtv --token <token>
|
|
42
42
|
rtv <token>
|
|
43
|
-
|
|
43
|
+
rtv --token-from-env REPLICATE_API_TOKEN
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
## 可用选项
|
|
@@ -49,6 +49,7 @@ REPLICATE_API_TOKEN=<token> rtv
|
|
|
49
49
|
--json 输出 JSON,适合脚本调用
|
|
50
50
|
--quiet 仅输出最终结果
|
|
51
51
|
--no-loop 交互模式下只校验一次后退出
|
|
52
|
+
--token-from-env <name> 从指定环境变量读取 Token
|
|
52
53
|
--no-model-test 跳过调用测试,只检查认证状态和账号状态
|
|
53
54
|
```
|
|
54
55
|
|
|
@@ -74,7 +75,7 @@ rtv --no-loop
|
|
|
74
75
|
```bash
|
|
75
76
|
rtv --token r8_xxx
|
|
76
77
|
rtv r8_xxx
|
|
77
|
-
REPLICATE_API_TOKEN=r8_xxx rtv
|
|
78
|
+
REPLICATE_API_TOKEN=r8_xxx rtv --token-from-env REPLICATE_API_TOKEN
|
|
78
79
|
rtv --token r8_xxx --quiet
|
|
79
80
|
```
|
|
80
81
|
|
|
@@ -86,6 +87,12 @@ rtv --token r8_xxx --quiet
|
|
|
86
87
|
rtv --token r8_xxx --json
|
|
87
88
|
```
|
|
88
89
|
|
|
90
|
+
如果你明确希望从环境变量取值:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
REPLICATE_API_TOKEN=r8_xxx rtv --token-from-env REPLICATE_API_TOKEN
|
|
94
|
+
```
|
|
95
|
+
|
|
89
96
|
`--json` 模式下会输出这些核心字段:
|
|
90
97
|
|
|
91
98
|
- `usabilityStatus`:当前 Token 是否可直接使用
|
|
@@ -22,6 +22,7 @@ program
|
|
|
22
22
|
.description("检查 Replicate API Token 当前是否可直接使用")
|
|
23
23
|
.argument("[token]", "要检查的 Replicate API Token")
|
|
24
24
|
.option("-t, --token <token>", "要检查的 Replicate API Token")
|
|
25
|
+
.option("--token-from-env <name>", "从指定环境变量读取 Token,例如 REPLICATE_API_TOKEN")
|
|
25
26
|
.option("--json", "输出 JSON 结果,便于脚本调用")
|
|
26
27
|
.option("-q, --quiet", "仅输出最终结果")
|
|
27
28
|
.option("--no-loop", "交互模式下只校验一次后退出")
|
|
@@ -491,6 +492,7 @@ function printSummary(report, outputJson) {
|
|
|
491
492
|
|
|
492
493
|
if (outputJson) {
|
|
493
494
|
console.log(JSON.stringify({
|
|
495
|
+
token: report.token,
|
|
494
496
|
usabilityStatus: usabilityClassification.usabilityStatus,
|
|
495
497
|
authStatus: accountClassification.authStatus,
|
|
496
498
|
accountStatus: accountClassification.accountStatus,
|
|
@@ -510,6 +512,7 @@ function printSummary(report, outputJson) {
|
|
|
510
512
|
}
|
|
511
513
|
|
|
512
514
|
console.log(paint("校验摘要", COLOR.bold));
|
|
515
|
+
console.log(`被测 Token:${paint(report.token, COLOR.cyan)}`);
|
|
513
516
|
console.log(`${formatStatusLabel(usabilityClassification.usabilityStatus === "usable" || usabilityClassification.usabilityStatus === "probably_usable" ? "valid" : usabilityClassification.usabilityStatus === "unusable" ? "invalid" : "unknown")}:当前 Token ${formatUsabilitySummary(usabilityClassification)}`);
|
|
514
517
|
console.log("");
|
|
515
518
|
printAccountDetails(report.account, report.accountError);
|
|
@@ -526,8 +529,20 @@ function printSummary(report, outputJson) {
|
|
|
526
529
|
}
|
|
527
530
|
}
|
|
528
531
|
|
|
529
|
-
function resolveToken(positionalToken, optionsToken) {
|
|
530
|
-
|
|
532
|
+
function resolveToken(positionalToken, optionsToken, tokenFromEnv) {
|
|
533
|
+
if (optionsToken) {
|
|
534
|
+
return optionsToken;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
if (positionalToken) {
|
|
538
|
+
return positionalToken;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if (tokenFromEnv) {
|
|
542
|
+
return process.env[tokenFromEnv] || null;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return null;
|
|
531
546
|
}
|
|
532
547
|
|
|
533
548
|
function exitCodeForReport(report) {
|
|
@@ -564,6 +579,7 @@ async function runVerification(token, options) {
|
|
|
564
579
|
const modelPromise = modelSkipped ? Promise.resolve(null) : verifyModelInvocation(token);
|
|
565
580
|
const [accountResult, modelResult] = await Promise.allSettled([accountPromise, modelPromise]);
|
|
566
581
|
const report = {
|
|
582
|
+
token,
|
|
567
583
|
account: accountResult.status === "fulfilled" ? accountResult.value : null,
|
|
568
584
|
accountError: accountResult.status === "rejected" ? accountResult.reason : null,
|
|
569
585
|
model: modelResult.status === "fulfilled" ? modelResult.value : null,
|
|
@@ -636,7 +652,7 @@ async function main() {
|
|
|
636
652
|
|
|
637
653
|
const options = program.opts();
|
|
638
654
|
const positionalToken = program.args[0];
|
|
639
|
-
const token = resolveToken(positionalToken, options.token);
|
|
655
|
+
const token = resolveToken(positionalToken, options.token, options.tokenFromEnv);
|
|
640
656
|
|
|
641
657
|
if (token) {
|
|
642
658
|
if (!options.json && !options.quiet) {
|
|
@@ -650,7 +666,7 @@ async function main() {
|
|
|
650
666
|
}
|
|
651
667
|
|
|
652
668
|
if (!process.stdin.isTTY || !process.stdout.isTTY) {
|
|
653
|
-
console.error("缺少 Replicate API Token
|
|
669
|
+
console.error("缺少 Replicate API Token。请通过位置参数、--token、--token-from-env 或交互模式提供。");
|
|
654
670
|
process.exitCode = 1;
|
|
655
671
|
return;
|
|
656
672
|
}
|