skillmkt 0.3.4 → 0.3.6

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.
@@ -85,7 +85,7 @@ export async function run(ctx) {
85
85
  // 冒烟:真实 chat 调用
86
86
  try {
87
87
  const probe = { base_url, model, api_key: keyEnv.v ? process.env[keyEnv.v.slice(4)] ?? '' : '', timeout_ms: 15000 };
88
- const reply = await chat(probe, { user: 'Reply with exactly: OK', maxTokens: 8 });
88
+ const reply = await chat(probe, { user: 'Reply with exactly: OK', maxTokens: 64 });
89
89
  ok(`llm smoke: ${reply.trim().slice(0, 40) || '(empty reply)'}`);
90
90
  } catch (e) {
91
91
  warn(`llm smoke failed: ${e.message}(配置已写入,功能将降级)`);
@@ -103,8 +103,9 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
103
103
  }
104
104
  if (u.pathname === '/api/llm-smoke') { // init 冒烟
105
105
  const key = resolveKeyRef(b.api_key, ctx); // env: 引用走 hub/.env 等解析链
106
- const r = await chat({ base_url: b.base_url, model: b.model, api_key: key, timeout_ms: 15000 }, { user: 'Reply with exactly: OK', maxTokens: 8 });
107
- return res.end(JSON.stringify({ ok: true, reply: r.trim().slice(0, 80) }));
106
+ const sent = 'Reply with exactly: OK';
107
+ const r = await chat({ base_url: b.base_url, model: b.model, api_key: key, timeout_ms: 15000 }, { user: sent, maxTokens: 64 });
108
+ return res.end(JSON.stringify({ ok: true, sent, reply: r.trim().slice(0, 200) }));
108
109
  }
109
110
  if (u.pathname === '/api/models') { // 指定端点+密钥拉模型列表
110
111
  const key = resolveKeyRef(b.api_key, ctx);
package/client/lib/llm.js CHANGED
@@ -106,7 +106,8 @@ export async function chat(llm, { system = '', user, maxTokens = 64, temperature
106
106
  });
107
107
  if (!res.ok) throw new Error(`llm ${res.status}: ${(await res.text()).slice(0, 200)}`);
108
108
  const data = await res.json();
109
- return data.choices?.[0]?.message?.content ?? '';
109
+ const msg = data.choices?.[0]?.message;
110
+ return msg?.content ?? msg?.reasoning_content ?? ''; // 思考型模型可能只回 reasoning_content
110
111
  } finally { clearTimeout(t); }
111
112
  }
112
113
 
@@ -148,12 +148,13 @@ async function render() {
148
148
  <div class="row"><button id="probe">扫描本机模型服务</button><span id="probe-out" class="mut"></span></div>
149
149
  <div id="eps"></div>
150
150
  <div class="frow"><span class="lab">服务地址</span><input type="text" id="murl" placeholder="http://localhost:1234/v1" value="${esc(cfg.llm?.base_url || '')}"></div>
151
- <div class="frow" id="key-row" style="display:none"><span class="lab">访问密钥</span><input type="text" id="mkey" value="${esc(cfg.llm?.api_key || '')}"><span class="fhint" id="key-hint"></span></div>
152
- <p class="mut" style="margin:8px 0 0">本机服务一般留空。填了密钥会用本机机器码加密后存入 config.yml——文件拷到别的机器解不开,换机需重填。</p>
151
+ <div class="frow" id="key-row" style="display:none"><span class="lab">访问密钥</span><input type="text" id="mkey" value="${esc(cfg.llm?.api_key || '')}"><span class="fhint" id="key-hint"></span>
152
+ <div class="fsub">填了密钥会用本机机器码加密后存入 config.yml——文件拷到别的机器解不开,换机需重填。</div></div>
153
153
  <div class="frow" id="model-box"><span class="lab">模型名称</span>
154
154
  <div class="combo"><input type="text" id="mmodel" autocomplete="off" placeholder="可输入关键字搜索,扫描后自动列出发现的模型" value="${esc(cfg.llm?.model || '')}">
155
155
  <div class="combo-list" id="model-drop" style="display:none"></div></div>
156
- <button id="smoke">测试连接</button><span id="smoke-out" class="mut"></span></div></div>
156
+ <button id="smoke">测试连接</button>
157
+ <div id="smoke-out" class="fsub"></div></div></div>
157
158
  <div class="card"><h3>第 2 步 · skill 默认安装位置</h3>
158
159
  <p class="mut">勾选的 AI 工具会在你安装新 skill 时自动收到一份副本。已勾过的话保存即生效。</p>
159
160
  ${h.map((x) => `<label class="check"><input type="checkbox" data-h="${esc(x.id)}" ${sel.has(x.id) ? 'checked' : ''} ${x.state === 'absent' ? 'disabled' : ''}> ${esc(x.id)} ${pill(x.state)} <span class="mut">${esc(x.primaryDir || '')}</span></label>`).join('')}</div>
@@ -203,7 +204,9 @@ async function render() {
203
204
  app.querySelectorAll('#eps .ep').forEach((x) => x.classList.remove('sel'));
204
205
  d.classList.add('sel');
205
206
  app.querySelector('#murl').value = d.dataset.b;
206
- markKeyNeed(epsList.find((e) => e.base_url === d.dataset.b)?.needs_key);
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);
207
210
  refreshOpts();
208
211
  });
209
212
  };
@@ -213,51 +216,71 @@ async function render() {
213
216
  if (b) { app.querySelector('#murl').value = b; refreshOpts(); }
214
217
  });
215
218
  // 填完服务地址自动检测是否需要密钥:已知端点直接看 needs_key,手输地址真发 /models 探
219
+ let keyOk = !!app.querySelector('#mkey').value.trim(); // 已保存的密钥视为已验证;改动地址/密钥后回到未验证
216
220
  const markKeyNeed = (need) => {
217
221
  const has = !!app.querySelector('#mkey').value.trim();
218
222
  const hasUrl = !!app.querySelector('#murl').value.trim();
219
- const want = !!need && !has;
220
- app.querySelector('#key-row').style.display = (need || has) ? '' : 'none'; // 无需密钥→整行不显示
223
+ const want = !!need && !keyOk; // 要密钥且尚未验证通过
224
+ app.querySelector('#key-row').style.display = (need || has) ? '' : 'none';
221
225
  app.querySelector('#mkey').classList.toggle('req', want);
222
- app.querySelector('#key-hint').textContent = want ? '← 需要密钥' : '';
223
- app.querySelector('#model-box').style.display = (hasUrl && !want) ? '' : 'none'; // 先选/填服务地址才出现
226
+ app.querySelector('#key-hint').textContent = want ? (has ? '← 密钥未验证' : '← 需要密钥') : '';
227
+ app.querySelector('#model-box').style.display = (hasUrl && !want) ? '' : 'none'; // 验证通过才出现
228
+ };
229
+ // 拿密钥真发 /models——通过才收录模型并放出模型框;失败保持隐藏
230
+ const verifyKey = async () => {
231
+ const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
232
+ const key = app.querySelector('#mkey').value.trim();
233
+ if (!key) return;
234
+ const out = app.querySelector('#smoke-out');
235
+ out.textContent = '验证密钥…';
236
+ const r = await api('/models', { method: 'POST', body: JSON.stringify({ base_url: cur, api_key: key }) });
237
+ if (r.models?.length) {
238
+ keyOk = true;
239
+ for (const m of r.models) { modelMap.set(m, cur); loadedModels.set(m, cur); }
240
+ const ep = epsList.find((e) => e.base_url === cur);
241
+ if (ep) { ep.needs_key = false; ep.models = r.models; }
242
+ markKeyNeed(true); refreshOpts();
243
+ out.textContent = `密钥有效,已加载 ${r.models.length} 个模型`;
244
+ } else {
245
+ keyOk = false; markKeyNeed(true); // 模型框保持隐藏
246
+ out.textContent = r.error ? `密钥无效:${r.error}` : '密钥通了,但没读到模型';
247
+ }
224
248
  };
225
249
  markKeyNeed(false); // 初始:无密钥需求→藏密钥行
226
250
  app.querySelector('#murl').addEventListener('input', () => {
251
+ keyOk = false;
227
252
  const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
228
253
  markKeyNeed(epsList.find((e) => e.base_url === cur)?.needs_key);
229
254
  refreshOpts(); renderDrop();
230
255
  });
231
256
  app.querySelector('#mmodel').addEventListener('input', () => { renderDrop(); app.querySelector('#model-drop').style.display = 'block'; });
232
257
  app.querySelector('#mmodel').addEventListener('blur', () => setTimeout(() => { app.querySelector('#model-drop').style.display = 'none'; }, 120));
233
- app.querySelector('#mkey').addEventListener('input', () => { // 密钥开始填了就别挡模型框
258
+ app.querySelector('#mkey').addEventListener('input', () => {
259
+ keyOk = false; // 密钥改动→回到未验证态,模型框收起
234
260
  const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
235
261
  markKeyNeed(epsList.find((e) => e.base_url === cur)?.needs_key);
236
262
  });
237
263
  app.querySelector('#murl').addEventListener('change', async () => {
238
264
  const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
239
265
  const ep = epsList.find((e) => e.base_url === cur);
240
- if (ep) return markKeyNeed(ep.needs_key);
266
+ const key = app.querySelector('#mkey').value.trim();
267
+ if (ep) {
268
+ if (ep.needs_key && key) return verifyKey();
269
+ return markKeyNeed(ep.needs_key);
270
+ }
241
271
  if (!/^https?:\/\//.test(cur)) return markKeyNeed(false);
272
+ if (key) return verifyKey(); // 手输地址+有密钥→顺便验真伪
242
273
  const r = await api('/models', { method: 'POST', body: JSON.stringify({ base_url: cur, api_key: '' }) });
243
274
  markKeyNeed(!!r.error && /401|403/.test(r.error));
275
+ if (r.models?.length) { for (const m of r.models) { modelMap.set(m, cur); loadedModels.set(m, cur); } refreshOpts(); }
244
276
  });
245
- // 需要密钥的端点:密钥填完自动拉它的模型列表
277
+ // 需要密钥的端点:密钥填完自动验证
246
278
  app.querySelector('#mkey').addEventListener('change', async () => {
247
279
  const cur = app.querySelector('#murl').value.trim().replace(/\/+$/, '');
248
280
  const ep = epsList.find((e) => e.base_url === cur);
249
281
  const key = app.querySelector('#mkey').value.trim();
250
282
  if (!key || !(ep?.needs_key || (!ep && /^https?:\/\//.test(cur)))) return;
251
- const out = app.querySelector('#smoke-out');
252
- out.textContent = '读取模型列表…';
253
- const r = await api('/models', { method: 'POST', body: JSON.stringify({ base_url: cur, api_key: key }) });
254
- if (r.models?.length) {
255
- for (const m of r.models) { modelMap.set(m, cur); loadedModels.set(m, cur); }
256
- if (ep) { ep.needs_key = false; ep.models = r.models; }
257
- markKeyNeed(false);
258
- refreshOpts();
259
- out.textContent = `已加载 ${r.models.length} 个模型`;
260
- } else out.textContent = r.error ? `读取失败:${r.error}` : '密钥通了,但没读到模型';
283
+ await verifyKey();
261
284
  });
262
285
  // 点进模型框时自动重扫——下载了新模型不用先点「扫描」
263
286
  app.querySelector('#mmodel').addEventListener('focus', () => {
@@ -265,9 +288,12 @@ async function render() {
265
288
  renderDrop(); app.querySelector('#model-drop').style.display = 'block';
266
289
  });
267
290
  app.querySelector('#smoke').onclick = async () => {
268
- app.querySelector('#smoke-out').textContent = '测试中…';
291
+ const out = app.querySelector('#smoke-out');
292
+ out.textContent = '测试中…';
269
293
  const r = await api('/llm-smoke', { method: 'POST', body: JSON.stringify({ base_url: app.querySelector('#murl').value, model: app.querySelector('#mmodel').value, api_key: app.querySelector('#mkey').value }) });
270
- app.querySelector('#smoke-out').textContent = r.ok ? `连接成功,模型回复:${r.reply}` : `连接失败:${r.error}`;
294
+ out.innerHTML = r.ok
295
+ ? `连接成功<br>发送:${esc(r.sent)}<br>回复:${esc(r.reply || '(空回复)')}`
296
+ : `连接失败:${esc(r.error)}`;
271
297
  };
272
298
  app.querySelector('#save').onclick = async () => {
273
299
  const targets = [...app.querySelectorAll('[data-h]:checked')].map((x) => x.dataset.h);
@@ -87,6 +87,7 @@ datalist { display: none; }
87
87
  .frow input[type=text], .frow input:not([type]), .frow .combo { flex: 1; min-width: 0; }
88
88
  .frow button { flex: none; }
89
89
  .fhint { flex: none; font-size: 14px; color: var(--color-accent); font-weight: 600; }
90
+ .fsub { flex-basis: 100%; margin: 2px 0 0 88px; font-size: 13.5px; color: var(--color-ink-mut); line-height: 1.55; }
90
91
  label.check { display: flex; gap: 10px; align-items: center; padding: 7px 4px; cursor: pointer; border-radius: 6px; }
91
92
  label.check:hover { background: color-mix(in oklch, var(--color-ink) 4%, var(--color-surface)); }
92
93
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skillmkt",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "type": "module",
5
5
  "description": "Local-first agent skill manager: install, audit, merge, distribute.",
6
6
  "license": "MIT",