skillmkt 0.3.5 → 0.3.7
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/public/app.js +42 -18
- package/package.json +1 -1
package/client/public/app.js
CHANGED
|
@@ -204,7 +204,9 @@ async function render() {
|
|
|
204
204
|
app.querySelectorAll('#eps .ep').forEach((x) => x.classList.remove('sel'));
|
|
205
205
|
d.classList.add('sel');
|
|
206
206
|
app.querySelector('#murl').value = d.dataset.b;
|
|
207
|
-
|
|
207
|
+
const ep = epsList.find((e) => e.base_url === d.dataset.b);
|
|
208
|
+
if (ep?.needs_key && app.querySelector('#mkey').value.trim()) verifyKey();
|
|
209
|
+
else markKeyNeed(ep?.needs_key);
|
|
208
210
|
refreshOpts();
|
|
209
211
|
});
|
|
210
212
|
};
|
|
@@ -214,51 +216,73 @@ async function render() {
|
|
|
214
216
|
if (b) { app.querySelector('#murl').value = b; refreshOpts(); }
|
|
215
217
|
});
|
|
216
218
|
// 填完服务地址自动检测是否需要密钥:已知端点直接看 needs_key,手输地址真发 /models 探
|
|
219
|
+
let keyOk = !!app.querySelector('#mkey').value.trim(); // 已保存的密钥视为已验证;改动地址/密钥后回到未验证
|
|
220
|
+
let keyFailed = false; // 验证真失败过→显示「密钥错误」而非「未验证」
|
|
217
221
|
const markKeyNeed = (need) => {
|
|
218
222
|
const has = !!app.querySelector('#mkey').value.trim();
|
|
219
223
|
const hasUrl = !!app.querySelector('#murl').value.trim();
|
|
220
|
-
const want = !!need && !
|
|
221
|
-
app.querySelector('#key-row').style.display = (need || has) ? '' : 'none';
|
|
224
|
+
const want = !!need && !keyOk; // 要密钥且尚未验证通过
|
|
225
|
+
app.querySelector('#key-row').style.display = (need || has) ? '' : 'none';
|
|
222
226
|
app.querySelector('#mkey').classList.toggle('req', want);
|
|
223
|
-
app.querySelector('#key-hint').textContent = want
|
|
224
|
-
|
|
227
|
+
app.querySelector('#key-hint').textContent = want
|
|
228
|
+
? (keyFailed ? '← 密钥错误' : (has ? '← 待验证' : '← 需要密钥')) : '';
|
|
229
|
+
app.querySelector('#model-box').style.display = (hasUrl && !want) ? '' : 'none'; // 验证通过才出现
|
|
230
|
+
};
|
|
231
|
+
// 拿密钥真发 /models——通过才收录模型并放出模型框;失败保持隐藏
|
|
232
|
+
const verifyKey = async () => {
|
|
233
|
+
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
234
|
+
const key = app.querySelector('#mkey').value.trim();
|
|
235
|
+
if (!key) return;
|
|
236
|
+
const out = app.querySelector('#smoke-out');
|
|
237
|
+
out.textContent = '验证密钥…';
|
|
238
|
+
const r = await api('/models', { method: 'POST', body: JSON.stringify({ base_url: cur, api_key: key }) });
|
|
239
|
+
if (r.models?.length) {
|
|
240
|
+
keyOk = true; keyFailed = false;
|
|
241
|
+
for (const m of r.models) { modelMap.set(m, cur); loadedModels.set(m, cur); }
|
|
242
|
+
const ep = epsList.find((e) => e.base_url === cur);
|
|
243
|
+
if (ep) { ep.needs_key = false; ep.models = r.models; }
|
|
244
|
+
markKeyNeed(true); refreshOpts();
|
|
245
|
+
out.textContent = `密钥有效,已加载 ${r.models.length} 个模型`;
|
|
246
|
+
} else {
|
|
247
|
+
keyOk = false; keyFailed = true; markKeyNeed(true); // 模型框保持隐藏
|
|
248
|
+
out.textContent = r.error ? `密钥错误:${r.error}` : '密钥通了,但没读到模型';
|
|
249
|
+
}
|
|
225
250
|
};
|
|
226
251
|
markKeyNeed(false); // 初始:无密钥需求→藏密钥行
|
|
227
252
|
app.querySelector('#murl').addEventListener('input', () => {
|
|
253
|
+
keyOk = false; keyFailed = false;
|
|
228
254
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
229
255
|
markKeyNeed(epsList.find((e) => e.base_url === cur)?.needs_key);
|
|
230
256
|
refreshOpts(); renderDrop();
|
|
231
257
|
});
|
|
232
258
|
app.querySelector('#mmodel').addEventListener('input', () => { renderDrop(); app.querySelector('#model-drop').style.display = 'block'; });
|
|
233
259
|
app.querySelector('#mmodel').addEventListener('blur', () => setTimeout(() => { app.querySelector('#model-drop').style.display = 'none'; }, 120));
|
|
234
|
-
app.querySelector('#mkey').addEventListener('input', () => {
|
|
260
|
+
app.querySelector('#mkey').addEventListener('input', () => {
|
|
261
|
+
keyOk = false; keyFailed = false; // 密钥改动→回到未验证态,模型框收起
|
|
235
262
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
236
263
|
markKeyNeed(epsList.find((e) => e.base_url === cur)?.needs_key);
|
|
237
264
|
});
|
|
238
265
|
app.querySelector('#murl').addEventListener('change', async () => {
|
|
239
266
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
240
267
|
const ep = epsList.find((e) => e.base_url === cur);
|
|
241
|
-
|
|
268
|
+
const key = app.querySelector('#mkey').value.trim();
|
|
269
|
+
if (ep) {
|
|
270
|
+
if (ep.needs_key && key) return verifyKey();
|
|
271
|
+
return markKeyNeed(ep.needs_key);
|
|
272
|
+
}
|
|
242
273
|
if (!/^https?:\/\//.test(cur)) return markKeyNeed(false);
|
|
274
|
+
if (key) return verifyKey(); // 手输地址+有密钥→顺便验真伪
|
|
243
275
|
const r = await api('/models', { method: 'POST', body: JSON.stringify({ base_url: cur, api_key: '' }) });
|
|
244
276
|
markKeyNeed(!!r.error && /401|403/.test(r.error));
|
|
277
|
+
if (r.models?.length) { for (const m of r.models) { modelMap.set(m, cur); loadedModels.set(m, cur); } refreshOpts(); }
|
|
245
278
|
});
|
|
246
|
-
//
|
|
279
|
+
// 需要密钥的端点:密钥填完自动验证
|
|
247
280
|
app.querySelector('#mkey').addEventListener('change', async () => {
|
|
248
281
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
249
282
|
const ep = epsList.find((e) => e.base_url === cur);
|
|
250
283
|
const key = app.querySelector('#mkey').value.trim();
|
|
251
284
|
if (!key || !(ep?.needs_key || (!ep && /^https?:\/\//.test(cur)))) return;
|
|
252
|
-
|
|
253
|
-
out.textContent = '读取模型列表…';
|
|
254
|
-
const r = await api('/models', { method: 'POST', body: JSON.stringify({ base_url: cur, api_key: key }) });
|
|
255
|
-
if (r.models?.length) {
|
|
256
|
-
for (const m of r.models) { modelMap.set(m, cur); loadedModels.set(m, cur); }
|
|
257
|
-
if (ep) { ep.needs_key = false; ep.models = r.models; }
|
|
258
|
-
markKeyNeed(false);
|
|
259
|
-
refreshOpts();
|
|
260
|
-
out.textContent = `已加载 ${r.models.length} 个模型`;
|
|
261
|
-
} else out.textContent = r.error ? `读取失败:${r.error}` : '密钥通了,但没读到模型';
|
|
285
|
+
await verifyKey();
|
|
262
286
|
});
|
|
263
287
|
// 点进模型框时自动重扫——下载了新模型不用先点「扫描」
|
|
264
288
|
app.querySelector('#mmodel').addEventListener('focus', () => {
|