skillmkt 0.4.3 → 0.4.4
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 +45 -24
- package/client/commands/serve.js +2 -8
- package/client/lib/llm.js +11 -0
- package/package.json +1 -1
package/client/commands/init.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// init — 交互式初始化:形态选择(Web/终端)→ LLM 探测→选模型→冒烟→写配置→harness 默认目标
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import { ensureHub, writeConfig, readConfig } from '../lib/hub.js';
|
|
4
|
-
import { probeEndpoints, chat } from '../lib/llm.js';
|
|
4
|
+
import { probeEndpoints, chat, encryptSecret, listModels } from '../lib/llm.js';
|
|
5
5
|
import { openURL, readDaemon, pidAlive } from '../lib/daemon.js';
|
|
6
6
|
import { choose, confirm, ask } from '../lib/prompt.js';
|
|
7
7
|
import { ok, warn, fail, info } from '../lib/render.js';
|
|
@@ -61,45 +61,66 @@ export async function run(ctx) {
|
|
|
61
61
|
// LLM 端点探测(只在用户进入配置步骤时探测——铁律)
|
|
62
62
|
info(L('探测本地 LLM 服务…', 'Probing local LLM services…'));
|
|
63
63
|
const found = await probeEndpoints(400, { extraBases: [ctx.config.llm?.base_url] });
|
|
64
|
-
let base_url = null, model = null;
|
|
64
|
+
let base_url = null, model = null, ep = null;
|
|
65
65
|
|
|
66
66
|
if (found.length) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
// 与 web 同构:先选服务(每端点一行)→ 需要密钥才问密钥 → 再选模型
|
|
68
|
+
const epOpts = [
|
|
69
|
+
...found.map((f) => ({
|
|
70
|
+
label: `${f.name}:${f.port} — ${f.needs_key ? L('需要密钥', 'key required') : L(`${f.models.length} 个模型`, `${f.models.length} models`)}`,
|
|
71
|
+
v: f,
|
|
72
|
+
})),
|
|
71
73
|
{ label: L('手动输入端点', 'Enter endpoint manually'), v: 'manual' },
|
|
72
74
|
{ label: L('跳过(确定性功能照常用)', 'Skip (deterministic features still work)'), v: 'skip' },
|
|
73
75
|
];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
const sel = await choose(L('选择模型端点:', 'Choose a model endpoint:'), opts);
|
|
78
|
-
if (sel.v === 'manual') {
|
|
79
|
-
base_url = (await ask(L(' 服务地址 > ', ' Service URL > '))).trim() || null;
|
|
80
|
-
if (base_url) model = (await ask(L(' 模型名称 > ', ' Model name > '))).trim() || null;
|
|
81
|
-
} else if (sel.v !== 'skip') {
|
|
82
|
-
({ base_url, model } = sel.v);
|
|
83
|
-
}
|
|
76
|
+
const sel = await choose(L('选择服务:', 'Choose a service:'), epOpts);
|
|
77
|
+
if (sel.v === 'manual') base_url = (await ask(L(' 服务地址 > ', ' Service URL > '))).trim() || null;
|
|
78
|
+
else if (sel.v !== 'skip') { ep = sel.v; base_url = ep.base_url; }
|
|
84
79
|
} else {
|
|
85
80
|
info(L('未发现本地 LLM 服务(已扫本机所有监听端口)', 'No local LLM service found (all listening ports probed)'));
|
|
86
81
|
base_url = (await ask(L(' 服务地址(留空跳过)> ', ' Service URL (empty to skip) > '))).trim() || null;
|
|
87
|
-
if (base_url) model = (await ask(L(' 模型名称 > ', ' Model name > '))).trim() || null;
|
|
88
82
|
}
|
|
89
83
|
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
// 模型探测:已知端点给列表;手输地址先裸探——401/403 → 需要密钥(和 web 的自动检测一致)
|
|
85
|
+
let models = ep?.models || [];
|
|
86
|
+
let needKey = !!ep?.needs_key;
|
|
87
|
+
if (base_url && !models.length && !ep?.needs_key) {
|
|
88
|
+
try { models = await listModels(base_url, ''); }
|
|
89
|
+
catch (e) { if (/401|403/.test(e.message)) needKey = true; }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 密钥:只在需要时问;粘贴的密钥用本机机器码加密存 config.yml
|
|
93
|
+
let api_key = null, keyPlain = '';
|
|
94
|
+
if (base_url && needKey) {
|
|
95
|
+
const ks = await choose(L('API key 来源?', 'API key source?'), [
|
|
96
|
+
{ label: L('粘贴密钥(机器码加密后存入 config.yml)', 'Paste a key (encrypted into config.yml with this machine’s ID)'), v: 'paste' },
|
|
94
97
|
{ label: 'SKILLMKT_API_KEY', v: 'env:SKILLMKT_API_KEY' },
|
|
95
98
|
{ label: 'OMLX_API_KEY', v: 'env:OMLX_API_KEY' },
|
|
99
|
+
{ label: L('无需 key', 'No key needed'), v: null },
|
|
96
100
|
]);
|
|
97
|
-
|
|
101
|
+
if (ks.v === 'paste') {
|
|
102
|
+
keyPlain = (await ask(L(' 密钥 > ', ' Key > '))).trim();
|
|
103
|
+
if (keyPlain) api_key = encryptSecret(keyPlain);
|
|
104
|
+
} else if (ks.v) api_key = ks.v;
|
|
105
|
+
if (!keyPlain && api_key?.startsWith('env:')) keyPlain = process.env[api_key.slice(4)] ?? '';
|
|
106
|
+
if (keyPlain) { try { models = await listModels(base_url, keyPlain); } catch { /* 密钥无效→手填模型 */ } }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 模型:拉到了就列出来选,拉不到手填
|
|
110
|
+
if (base_url && !model) {
|
|
111
|
+
if (models.length) {
|
|
112
|
+
model = (await choose(L('选择模型:', 'Choose a model:'), models.map((m) => ({ label: m, v: m })))).v;
|
|
113
|
+
} else {
|
|
114
|
+
model = (await ask(L(' 模型名称 > ', ' Model name > '))).trim() || null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (base_url) {
|
|
119
|
+
raw.llm = { base_url, model, ...(api_key ? { api_key } : {}), concurrency: 2, timeout_ms: 60000 };
|
|
98
120
|
|
|
99
121
|
// 冒烟:真实 chat 调用
|
|
100
122
|
try {
|
|
101
|
-
const
|
|
102
|
-
const reply = await chat(probe, { user: 'Reply with exactly: OK', maxTokens: 64 });
|
|
123
|
+
const reply = await chat({ base_url, model, api_key: keyPlain, timeout_ms: 15000 }, { user: 'Reply with exactly: OK', maxTokens: 64 });
|
|
103
124
|
ok(`llm smoke: ${reply.trim().slice(0, 40) || '(empty reply)'}`);
|
|
104
125
|
} catch (e) {
|
|
105
126
|
warn(L(`llm smoke failed: ${e.message}(配置已写入,功能将降级)`, `llm smoke failed: ${e.message} (config saved; features will degrade)`));
|
package/client/commands/serve.js
CHANGED
|
@@ -10,7 +10,7 @@ import { readLibrary, readLock, readConfig, writeConfig, registerSkill, updateLo
|
|
|
10
10
|
import { readUpstream } from '../lib/state.js';
|
|
11
11
|
import { readYAML } from '../../pipeline/lib/util.js';
|
|
12
12
|
import { detectHarnesses } from '../lib/scanner.js';
|
|
13
|
-
import { probeEndpoints, chat, encryptSecret, resolveKeyRef } from '../lib/llm.js';
|
|
13
|
+
import { probeEndpoints, chat, encryptSecret, resolveKeyRef, listModels } from '../lib/llm.js';
|
|
14
14
|
import { projectSkill, unproject, targetDirFor } from '../lib/project.js';
|
|
15
15
|
import { treeHash } from '../lib/package.js';
|
|
16
16
|
import { ok, info } from '../lib/render.js';
|
|
@@ -129,13 +129,7 @@ export async function startServer(ctx, { quiet = false, port = 0 } = {}) {
|
|
|
129
129
|
if (u.pathname === '/api/models') { // 指定端点+密钥拉模型列表
|
|
130
130
|
const key = resolveKeyRef(b.api_key, ctx);
|
|
131
131
|
try {
|
|
132
|
-
|
|
133
|
-
headers: key ? { authorization: `Bearer ${key}` } : {},
|
|
134
|
-
signal: AbortSignal.timeout(8000),
|
|
135
|
-
});
|
|
136
|
-
if (!r.ok) return res.end(JSON.stringify({ models: [], error: `http ${r.status}` }));
|
|
137
|
-
const d = await r.json();
|
|
138
|
-
return res.end(JSON.stringify({ models: (d.data || []).map((m) => m.id) }));
|
|
132
|
+
return res.end(JSON.stringify({ models: await listModels(b.base_url, key) }));
|
|
139
133
|
} catch (e) { return res.end(JSON.stringify({ models: [], error: e.message.slice(0, 80) })); }
|
|
140
134
|
}
|
|
141
135
|
if (u.pathname === '/api/targets') { // web 改投影目标
|
package/client/lib/llm.js
CHANGED
|
@@ -112,6 +112,17 @@ export async function chat(llm, { system = '', user, maxTokens = 64, temperature
|
|
|
112
112
|
} finally { clearTimeout(t); }
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
// OpenAI 兼容 /models 列表(指定端点+密钥)——web 与 init 向导共用
|
|
116
|
+
export async function listModels(baseUrl, apiKey = '') {
|
|
117
|
+
const r = await fetch(`${String(baseUrl || '').replace(/\/+$/, '')}/models`, {
|
|
118
|
+
headers: apiKey ? { authorization: `Bearer ${apiKey}` } : {},
|
|
119
|
+
signal: AbortSignal.timeout(8000),
|
|
120
|
+
});
|
|
121
|
+
if (!r.ok) throw new Error(`http ${r.status}`);
|
|
122
|
+
const d = await r.json();
|
|
123
|
+
return (d.data || []).map((m) => m.id);
|
|
124
|
+
}
|
|
125
|
+
|
|
115
126
|
export const LLM_PROBES = [8001, 11434, 1234, 8000, 8080, 1337, 5000];
|
|
116
127
|
|
|
117
128
|
// 本机所有 LISTEN 端口(lsof)——模型服务换任意端口都能被扫到;拿不到就只用固定列表
|