skillmkt 0.3.13 → 0.3.15
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/serve.js +1 -0
- package/client/public/app.js +19 -10
- package/package.json +1 -1
package/client/commands/serve.js
CHANGED
|
@@ -183,6 +183,7 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
183
183
|
}
|
|
184
184
|
if (!fs.existsSync(file) || fs.statSync(file).isDirectory()) { res.writeHead(404); return res.end('nf'); }
|
|
185
185
|
res.setHeader('content-type', MIME[path.extname(file)] || 'application/octet-stream');
|
|
186
|
+
res.setHeader('cache-control', 'no-store'); // 每次请求都读磁盘——迭代期不让浏览器拿缓存旧 app.js
|
|
186
187
|
fs.createReadStream(file).pipe(res);
|
|
187
188
|
});
|
|
188
189
|
|
package/client/public/app.js
CHANGED
|
@@ -164,12 +164,19 @@ async function render() {
|
|
|
164
164
|
const modelMap = new Map(); // model → base_url(选中模型自动回填地址)
|
|
165
165
|
const loadedModels = new Map(); // 密钥端点拉到的模型——重扫后保留
|
|
166
166
|
let epsList = [], lastScan = 0, scanning = false;
|
|
167
|
+
// localhost / 127.0.0.1 / ::1 视为同一台——配置和扫描报的写法可能不同
|
|
168
|
+
const LOOP = new Set(['localhost', '127.0.0.1', '::1', '[::1]']);
|
|
169
|
+
const sameBase = (a, b) => {
|
|
170
|
+
try { const x = new URL(a), y = new URL(b); return x.protocol === y.protocol && x.port === y.port && (x.hostname === y.hostname || (LOOP.has(x.hostname) && LOOP.has(y.hostname))); }
|
|
171
|
+
catch { return a === b; }
|
|
172
|
+
};
|
|
167
173
|
// 模型下拉按当前服务地址过滤:地址匹配已扫描端点→只给它的模型;不匹配→给全部
|
|
168
174
|
let curOpts = [];
|
|
169
175
|
const refreshOpts = () => {
|
|
170
176
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
171
|
-
const known = epsList.some((e) => e.base_url
|
|
172
|
-
curOpts = [...modelMap.keys()].filter((m) => !known || modelMap.get(m)
|
|
177
|
+
const known = epsList.some((e) => sameBase(e.base_url, cur));
|
|
178
|
+
curOpts = [...modelMap.keys()].filter((m) => !known || sameBase(modelMap.get(m), cur));
|
|
179
|
+
renderDrop(); // 数组变了 DOM 也要重建——verifyKey 等只调 refreshOpts 的路径才不会漏渲染
|
|
173
180
|
return curOpts.length;
|
|
174
181
|
};
|
|
175
182
|
// 自绘搜索下拉(Safari 不支持 <datalist>,会把 option 当文本渲染盖住布局)
|
|
@@ -199,7 +206,7 @@ async function render() {
|
|
|
199
206
|
for (const e of eps) for (const m of e.models) if (!modelMap.has(m)) modelMap.set(m, e.base_url);
|
|
200
207
|
for (const [m, b] of loadedModels) modelMap.set(m, b);
|
|
201
208
|
if (cfg.llm?.model) modelMap.set(cfg.llm.model, cfg.llm?.base_url || ''); // 当前模型始终留在下拉里
|
|
202
|
-
const curEp = eps.find((e) => e.base_url
|
|
209
|
+
const curEp = eps.find((e) => sameBase(e.base_url, app.querySelector('#murl').value.trim().replace(/\/+$/, '')));
|
|
203
210
|
if (curEp?.needs_key && realKey()) verifyKey(); // 配置的端点要密钥→自动用已存密钥拉模型回来
|
|
204
211
|
refreshOpts(); renderDrop();
|
|
205
212
|
app.querySelector('#eps').innerHTML = eps.map((e) => e.needs_key
|
|
@@ -211,7 +218,7 @@ async function render() {
|
|
|
211
218
|
app.querySelectorAll('#eps .ep').forEach((x) => x.classList.remove('sel'));
|
|
212
219
|
d.classList.add('sel');
|
|
213
220
|
app.querySelector('#murl').value = d.dataset.b;
|
|
214
|
-
const ep = epsList.find((e) => e.base_url
|
|
221
|
+
const ep = epsList.find((e) => sameBase(e.base_url, d.dataset.b));
|
|
215
222
|
if (ep?.needs_key && realKey()) verifyKey();
|
|
216
223
|
else markKeyNeed(ep?.needs_key);
|
|
217
224
|
refreshOpts();
|
|
@@ -242,11 +249,13 @@ async function render() {
|
|
|
242
249
|
if (!key) return;
|
|
243
250
|
const out = app.querySelector('#smoke-out');
|
|
244
251
|
out.textContent = '验证密钥…';
|
|
245
|
-
|
|
252
|
+
let r;
|
|
253
|
+
try { r = await api('/models', { method: 'POST', body: JSON.stringify({ base_url: cur, api_key: key }) }); }
|
|
254
|
+
catch (e) { out.textContent = `请求失败:${e.message}`; return; }
|
|
246
255
|
if (r.models?.length) {
|
|
247
256
|
keyOk = true; keyFailed = false;
|
|
248
257
|
for (const m of r.models) { modelMap.set(m, cur); loadedModels.set(m, cur); }
|
|
249
|
-
const ep = epsList.find((e) => e.base_url
|
|
258
|
+
const ep = epsList.find((e) => sameBase(e.base_url, cur));
|
|
250
259
|
if (ep) { ep.needs_key = false; ep.models = r.models; }
|
|
251
260
|
markKeyNeed(true); refreshOpts();
|
|
252
261
|
out.textContent = `密钥有效,已加载 ${r.models.length} 个模型`;
|
|
@@ -259,7 +268,7 @@ async function render() {
|
|
|
259
268
|
app.querySelector('#murl').addEventListener('input', () => {
|
|
260
269
|
keyOk = false; keyFailed = false;
|
|
261
270
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
262
|
-
markKeyNeed(epsList.find((e) => e.base_url
|
|
271
|
+
markKeyNeed(epsList.find((e) => sameBase(e.base_url, cur))?.needs_key);
|
|
263
272
|
refreshOpts(); renderDrop();
|
|
264
273
|
});
|
|
265
274
|
app.querySelector('#mmodel').addEventListener('input', () => { renderDrop(); app.querySelector('#model-drop').style.display = 'block'; });
|
|
@@ -273,11 +282,11 @@ async function render() {
|
|
|
273
282
|
app.querySelector('#mkey').addEventListener('input', () => {
|
|
274
283
|
keyOk = false; keyFailed = false; // 密钥改动→回到未验证态,模型框收起
|
|
275
284
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
276
|
-
markKeyNeed(epsList.find((e) => e.base_url
|
|
285
|
+
markKeyNeed(epsList.find((e) => sameBase(e.base_url, cur))?.needs_key);
|
|
277
286
|
});
|
|
278
287
|
app.querySelector('#murl').addEventListener('change', async () => {
|
|
279
288
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
280
|
-
const ep = epsList.find((e) => e.base_url
|
|
289
|
+
const ep = epsList.find((e) => sameBase(e.base_url, cur));
|
|
281
290
|
const key = realKey();
|
|
282
291
|
if (ep) {
|
|
283
292
|
if (ep.needs_key && key) return verifyKey();
|
|
@@ -292,7 +301,7 @@ async function render() {
|
|
|
292
301
|
// 需要密钥的端点:密钥填完自动验证
|
|
293
302
|
app.querySelector('#mkey').addEventListener('change', async () => {
|
|
294
303
|
const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
|
|
295
|
-
const ep = epsList.find((e) => e.base_url
|
|
304
|
+
const ep = epsList.find((e) => sameBase(e.base_url, cur));
|
|
296
305
|
const key = realKey();
|
|
297
306
|
if (!key || !(ep?.needs_key || (!ep && /^https?:\/\//.test(cur)))) return;
|
|
298
307
|
await verifyKey();
|