skillmkt 0.4.10 → 0.4.12

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.
@@ -89,40 +89,57 @@ export async function run(ctx) {
89
89
  catch (e) { if (/401|403/.test(e.message)) needKey = true; }
90
90
  }
91
91
 
92
- // 密钥:只在需要时问;粘贴的密钥用本机机器码加密存 config.yml
92
+ // 密钥:只在需要时问;失败不默默继续——给"换个方式 / 退出向导"选择
93
93
  let api_key = null, keyPlain = '';
94
94
  if (base_url && needKey) {
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 读', 'Read env var SKILLMKT_API_KEY'), v: 'env:SKILLMKT_API_KEY' },
98
- { label: L('从别的环境变量读(自己填变量名)', 'Read another env var (type the name yourself)'), v: 'env-custom' },
99
- { label: L('不需要密钥', 'No key needed'), v: null },
100
- ]);
101
- if (ks.v === 'paste') {
102
- for (;;) { // 粘贴后真验证:错密钥报"密钥错误"可重输,对了才放行
103
- keyPlain = (await askSecret(L(' 密钥 > ', ' Key > '))).trim();
104
- if (!keyPlain) break; // 留空放弃
95
+ for (;;) { // 密钥来源循环:任何一步失败都回到这里重选
96
+ const ks = await choose(L('这个服务需要访问密钥,怎么提供?', 'This service needs an access key — how should it be provided?'), [
97
+ { label: L('现在粘贴进来(只输一次,自动加密保存)', 'Paste it now (entered once, saved encrypted)'), v: 'paste' },
98
+ { label: L('从环境变量 SKILLMKT_API_KEY 读', 'Read env var SKILLMKT_API_KEY'), v: 'env:SKILLMKT_API_KEY' },
99
+ { label: L('不需要密钥', 'No key needed'), v: null },
100
+ ]);
101
+ if (!ks.v) break; // 不需要密钥 → 出循环
102
+ if (ks.v === 'paste') {
103
+ for (;;) { // 粘贴后真验证:错密钥可重输,留空回上一步
104
+ keyPlain = (await askSecret(L(' 密钥 > ', ' Key > '))).trim();
105
+ if (!keyPlain) break;
106
+ try {
107
+ models = await listModels(base_url, keyPlain);
108
+ api_key = encryptSecret(keyPlain);
109
+ ok(L(`密钥有效,已加载 ${models.length} 个模型`, `Key valid — loaded ${models.length} models`));
110
+ break;
111
+ } catch (e) {
112
+ warn(L(`密钥错误(${e.message})——重输,或留空返回上一步`, `Wrong key (${e.message}) — re-enter, or leave empty to go back`));
113
+ keyPlain = '';
114
+ }
115
+ }
116
+ if (api_key) break;
117
+ continue;
118
+ }
119
+ // env:VAR —— 没设/验证失败时给明确指引:本进程读不到事后 export 的值,只能换方式或退出
120
+ const vn = ks.v.slice(4);
121
+ keyPlain = process.env[vn] ?? '';
122
+ if (!keyPlain) {
123
+ warn(L(`环境变量 ${vn} 没设置——本向导运行中设了也读不到(环境变量只在启动时继承)`, `env var ${vn} is not set — exporting it now won't reach this wizard (env is inherited at launch)`));
124
+ } else {
105
125
  try {
106
126
  models = await listModels(base_url, keyPlain);
107
- api_key = encryptSecret(keyPlain);
108
- ok(L(`密钥有效,已加载 ${models.length} 个模型`, `Key valid — loaded ${models.length} models`));
127
+ api_key = `env:${vn}`;
128
+ ok(L(`已用 ${vn} 验证,加载 ${models.length} 个模型`, `verified with ${vn} — loaded ${models.length} models`));
109
129
  break;
110
130
  } catch (e) {
111
- warn(L(`密钥错误(${e.message})——重输,或留空改手填`, `Wrong key (${e.message}) — re-enter, or leave empty to type the model yourself`));
112
- keyPlain = '';
131
+ warn(L(`用 ${vn} 验证失败(${e.message})`, `key in ${vn} failed verification (${e.message})`));
113
132
  }
114
133
  }
115
- } else if (ks.v) {
116
- const vn = ks.v === 'env-custom' ? (await ask(L(' 环境变量名 > ', ' Env var name > '))).trim() : ks.v.slice(4);
117
- if (vn) {
118
- api_key = `env:${vn}`;
119
- keyPlain = process.env[vn] ?? '';
120
- if (!keyPlain) warn(L(`环境变量 ${vn} 现在没设置——配置照存,export 之后就能用`, `env var ${vn} is not set — config saved anyway; works once you export it`));
121
- else {
122
- try { models = await listModels(base_url, keyPlain); }
123
- catch (e) { warn(L(`用 ${vn} 验证失败(${e.message})——配置照存,模型手填`, `key in ${vn} failed verification (${e.message}) — config saved anyway, type the model manually`)); }
124
- }
134
+ const act = await choose(L('接下来怎么办?', 'What next?'), [
135
+ { label: L('换个方式(回上一步)', 'Pick another way (back)'), v: 'back' },
136
+ { label: L('退出向导,配好后重跑', 'Quit wizard — fix it, then rerun'), v: 'quit' },
137
+ ]);
138
+ if (act.v === 'quit') {
139
+ info(L(`终端里先执行 export ${vn}=你的key,再重跑:skillmkt init`, `run: export ${vn}=your-key, then rerun: skillmkt init`));
140
+ return 0;
125
141
  }
142
+ // back → 回到外圈重选密钥来源
126
143
  }
127
144
  }
128
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skillmkt",
3
- "version": "0.4.10",
3
+ "version": "0.4.12",
4
4
  "type": "module",
5
5
  "description": "Local-first agent skill manager: install, audit, merge, distribute.",
6
6
  "license": "MIT",