skillmkt 0.4.6 → 0.4.8
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/client/commands/init.js +27 -10
- package/package.json +1 -1
package/client/commands/init.js
CHANGED
|
@@ -92,18 +92,35 @@ export async function run(ctx) {
|
|
|
92
92
|
// 密钥:只在需要时问;粘贴的密钥用本机机器码加密存 config.yml
|
|
93
93
|
let api_key = null, keyPlain = '';
|
|
94
94
|
if (base_url && needKey) {
|
|
95
|
-
const ks = await choose(L('
|
|
96
|
-
{ label: L('
|
|
97
|
-
{ label: 'SKILLMKT_API_KEY', v: 'env:SKILLMKT_API_KEY' },
|
|
98
|
-
{ label: 'OMLX_API_KEY', v: 'env:OMLX_API_KEY' },
|
|
99
|
-
{ label: L('
|
|
95
|
+
const ks = await choose(L('这个服务需要访问密钥,怎么提供?', 'This service needs an access key — how should it be provided?'), [
|
|
96
|
+
{ label: L('现在粘贴进来(只输一次,自动加密保存)', 'Paste it now (entered once, saved encrypted)'), v: 'paste' },
|
|
97
|
+
{ label: L('从环境变量 SKILLMKT_API_KEY 读(key 已在 shell 里时选)', 'Read env var SKILLMKT_API_KEY (if the key is already in your shell)'), v: 'env:SKILLMKT_API_KEY' },
|
|
98
|
+
{ label: L('从环境变量 OMLX_API_KEY 读', 'Read env var OMLX_API_KEY'), v: 'env:OMLX_API_KEY' },
|
|
99
|
+
{ label: L('不需要密钥', 'No key needed'), v: null },
|
|
100
100
|
]);
|
|
101
101
|
if (ks.v === 'paste') {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
102
|
+
for (;;) { // 粘贴后真验证:错密钥报"密钥错误"可重输,对了才放行
|
|
103
|
+
keyPlain = (await askSecret(L(' 密钥 > ', ' Key > '))).trim();
|
|
104
|
+
if (!keyPlain) break; // 留空放弃
|
|
105
|
+
try {
|
|
106
|
+
models = await listModels(base_url, keyPlain);
|
|
107
|
+
api_key = encryptSecret(keyPlain);
|
|
108
|
+
ok(L(`密钥有效,已加载 ${models.length} 个模型`, `Key valid — loaded ${models.length} models`));
|
|
109
|
+
break;
|
|
110
|
+
} catch (e) {
|
|
111
|
+
warn(L(`密钥错误(${e.message})——重输,或留空改手填`, `Wrong key (${e.message}) — re-enter, or leave empty to type the model yourself`));
|
|
112
|
+
keyPlain = '';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} else if (ks.v) {
|
|
116
|
+
api_key = ks.v;
|
|
117
|
+
keyPlain = process.env[api_key.slice(4)] ?? '';
|
|
118
|
+
if (!keyPlain) warn(L(`环境变量 ${api_key.slice(4)} 没设置——先 export 再重跑,或改选粘贴`, `env var ${api_key.slice(4)} is not set — export it first, or pick paste instead`));
|
|
119
|
+
else {
|
|
120
|
+
try { models = await listModels(base_url, keyPlain); }
|
|
121
|
+
catch (e) { warn(L(`用 ${api_key.slice(4)} 验证失败(${e.message})——配置照存,模型手填`, `key in ${api_key.slice(4)} failed verification (${e.message}) — config saved anyway, type the model manually`)); }
|
|
122
|
+
}
|
|
123
|
+
}
|
|
107
124
|
}
|
|
108
125
|
|
|
109
126
|
// 模型:拉到了就列出来选,拉不到手填
|