skillmkt 0.1.9 → 0.2.1
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 +3 -0
- package/client/lib/llm.js +37 -22
- package/client/public/app.js +4 -1
- package/client/public/index.html +6 -6
- package/package.json +1 -1
package/client/commands/init.js
CHANGED
|
@@ -58,6 +58,9 @@ export async function run(ctx) {
|
|
|
58
58
|
{ label: '手动输入端点', v: 'manual' },
|
|
59
59
|
{ label: '跳过(确定性功能照常用)', v: 'skip' },
|
|
60
60
|
];
|
|
61
|
+
for (const f of found.filter((x) => x.needs_key)) {
|
|
62
|
+
info(`发现 ${f.name}:${f.port}(需要密钥,模型列表读不出)——选"手动输入端点"后填 ${f.base_url}`);
|
|
63
|
+
}
|
|
61
64
|
const sel = await choose('选择模型端点:', opts);
|
|
62
65
|
if (sel.v === 'manual') {
|
|
63
66
|
// 手动输入交给 config set 提示
|
package/client/lib/llm.js
CHANGED
|
@@ -55,31 +55,46 @@ export async function chat(llm, { system = '', user, maxTokens = 64, temperature
|
|
|
55
55
|
} finally { clearTimeout(t); }
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export const LLM_PROBES = [
|
|
59
|
-
{ port: 8001, name: 'OMLX' },
|
|
60
|
-
{ port: 11434, name: 'Ollama', probe: '/api/version' },
|
|
61
|
-
{ port: 1234, name: 'LM Studio' },
|
|
62
|
-
{ port: 8000, name: 'vLLM' },
|
|
63
|
-
{ port: 8080, name: 'mlx-lm/llama.cpp' },
|
|
64
|
-
{ port: 1337, name: 'Jan' },
|
|
65
|
-
{ port: 5000, name: 'text-gen-webui' },
|
|
66
|
-
];
|
|
58
|
+
export const LLM_PROBES = [8001, 11434, 1234, 8000, 8080, 1337, 5000];
|
|
67
59
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const base = `http://localhost:${port}/v1`;
|
|
60
|
+
// 识别服务实现——有特征端点才冠名,认不出如实标"OpenAI 兼容服务"(oMLX 跑在 1234 时不该叫 LM Studio)
|
|
61
|
+
async function identifyImpl(port, timeoutMs) {
|
|
62
|
+
const get = async (p) => {
|
|
72
63
|
const ctrl = new AbortController();
|
|
73
64
|
const t = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
74
|
-
try {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
65
|
+
try { const r = await fetch(`http://localhost:${port}${p}`, { signal: ctrl.signal }); return r.ok ? await r.json() : null; }
|
|
66
|
+
catch { return null; } finally { clearTimeout(t); }
|
|
67
|
+
};
|
|
68
|
+
if ((await get('/api/version'))?.version) return 'Ollama'; // Ollama 原生 API
|
|
69
|
+
if (await get('/api/v0/models')) return 'LM Studio API'; // 说 LM Studio 协议——也可能是 oMLX 等兼容实现
|
|
70
|
+
return 'OpenAI 兼容服务';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 仅 init/config 使用——并发扫端口。/v1/models 通了即收录;
|
|
74
|
+
// 401/403 时用已知环境 key 重试,仍不通则标 needs_key 保留(别静默漏掉 oMLX 这类要 key 的本地服务)
|
|
75
|
+
export async function probeEndpoints(timeoutMs = 400) {
|
|
76
|
+
const envKeys = ['SKILLMKT_LLM_API_KEY', 'OMLX_API_KEY'].map((v) => process.env[v]).filter(Boolean);
|
|
77
|
+
const results = await Promise.allSettled(LLM_PROBES.map(async (port) => {
|
|
78
|
+
const base = `http://localhost:${port}/v1`;
|
|
79
|
+
const tryModels = async (key) => {
|
|
80
|
+
const ctrl = new AbortController();
|
|
81
|
+
const t = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
82
|
+
try {
|
|
83
|
+
return await fetch(`${base}/models`, {
|
|
84
|
+
signal: ctrl.signal,
|
|
85
|
+
headers: key ? { authorization: `Bearer ${key}` } : {},
|
|
86
|
+
});
|
|
87
|
+
} catch { return null; } finally { clearTimeout(t); }
|
|
88
|
+
};
|
|
89
|
+
let res = await tryModels(null);
|
|
90
|
+
if (!res) return null;
|
|
91
|
+
if (res.status === 401 || res.status === 403) {
|
|
92
|
+
for (const k of envKeys) { res = await tryModels(k); if (res?.ok) break; }
|
|
93
|
+
}
|
|
94
|
+
const name = await identifyImpl(port, timeoutMs);
|
|
95
|
+
if (!res.ok) return { name, port, base_url: base, models: [], needs_key: true };
|
|
96
|
+
const data = await res.json();
|
|
97
|
+
return { name, port, base_url: base, models: (data.data || []).map((m) => m.id) };
|
|
83
98
|
}));
|
|
84
99
|
return results.map((r) => r.value).filter(Boolean);
|
|
85
100
|
}
|
package/client/public/app.js
CHANGED
|
@@ -160,7 +160,10 @@ async function render() {
|
|
|
160
160
|
app.querySelector('#probe').onclick = async () => {
|
|
161
161
|
app.querySelector('#probe-out').textContent = '扫描中…';
|
|
162
162
|
const eps = await api('/probe');
|
|
163
|
-
app.querySelector('#eps').innerHTML = eps.flatMap((e) => e.
|
|
163
|
+
app.querySelector('#eps').innerHTML = eps.flatMap((e) => e.needs_key
|
|
164
|
+
? [`<div class="ep" data-b="${esc(e.base_url)}" data-m="">${esc(e.name)}:${e.port} — <span class="mut">需要密钥(先点这行填地址,再填密钥、测试连接)</span></div>`]
|
|
165
|
+
: e.models.slice(0, 6).map((m) => `<div class="ep" data-b="${esc(e.base_url)}" data-m="${esc(m)}">${esc(e.name)}:${e.port} — <code>${esc(m)}</code></div>`)).join('')
|
|
166
|
+
|| '<p class="mut" style="margin-top:8px">没扫到——请确认模型服务已启动(会检查 8001 / 11434 / 1234 / 8000 / 8080 / 1337 / 5000 端口)</p>';
|
|
164
167
|
app.querySelector('#probe-out').textContent = `发现 ${eps.length} 个服务,点击条目自动填入`;
|
|
165
168
|
app.querySelectorAll('#eps [data-b]').forEach((d) => d.onclick = () => {
|
|
166
169
|
app.querySelectorAll('#eps .ep').forEach((x) => x.classList.remove('sel'));
|
package/client/public/index.html
CHANGED
|
@@ -5,13 +5,13 @@
|
|
|
5
5
|
/* skillmkt panel — 依 skill/SKILL.md 规则:light-first、OKLCH 角色 token、单强调色、
|
|
6
6
|
无玻璃/渐变/emoji 图标、可见标签、focus-visible ring、每屏至多一个填充主按钮 */
|
|
7
7
|
:root {
|
|
8
|
-
--color-paper: oklch(0.
|
|
9
|
-
--color-surface: oklch(0
|
|
10
|
-
--color-ink: oklch(0.
|
|
11
|
-
--color-ink-mut: oklch(0.50 0.
|
|
12
|
-
--color-line: oklch(0.
|
|
8
|
+
--color-paper: oklch(0.985 0.001 260);
|
|
9
|
+
--color-surface: oklch(1 0 0);
|
|
10
|
+
--color-ink: oklch(0.25 0.01 260);
|
|
11
|
+
--color-ink-mut: oklch(0.50 0.01 260);
|
|
12
|
+
--color-line: oklch(0.90 0.004 260);
|
|
13
13
|
--color-accent: oklch(0.52 0.14 55); /* 烧橙——唯一强调色 */
|
|
14
|
-
--color-accent-ink: oklch(0.
|
|
14
|
+
--color-accent-ink: oklch(0.995 0.003 260);
|
|
15
15
|
--color-ok: oklch(0.52 0.11 155);
|
|
16
16
|
--color-warn: oklch(0.55 0.13 80);
|
|
17
17
|
--color-bad: oklch(0.50 0.17 28);
|