skillmkt 0.4.4 → 0.4.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.
- package/client/commands/init.js +2 -2
- package/client/lib/prompt.js +26 -0
- package/client/public/app.js +1 -1
- package/package.json +1 -1
package/client/commands/init.js
CHANGED
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import { ensureHub, writeConfig, readConfig } from '../lib/hub.js';
|
|
4
4
|
import { probeEndpoints, chat, encryptSecret, listModels } from '../lib/llm.js';
|
|
5
5
|
import { openURL, readDaemon, pidAlive } from '../lib/daemon.js';
|
|
6
|
-
import { choose, confirm, ask } from '../lib/prompt.js';
|
|
6
|
+
import { choose, confirm, ask, askSecret } from '../lib/prompt.js';
|
|
7
7
|
import { ok, warn, fail, info } from '../lib/render.js';
|
|
8
8
|
import { L, lang, setUILang } from '../lib/i18n.js';
|
|
9
9
|
|
|
@@ -99,7 +99,7 @@ export async function run(ctx) {
|
|
|
99
99
|
{ label: L('无需 key', 'No key needed'), v: null },
|
|
100
100
|
]);
|
|
101
101
|
if (ks.v === 'paste') {
|
|
102
|
-
keyPlain = (await
|
|
102
|
+
keyPlain = (await askSecret(L(' 密钥 > ', ' Key > '))).trim();
|
|
103
103
|
if (keyPlain) api_key = encryptSecret(keyPlain);
|
|
104
104
|
} else if (ks.v) api_key = ks.v;
|
|
105
105
|
if (!keyPlain && api_key?.startsWith('env:')) keyPlain = process.env[api_key.slice(4)] ?? '';
|
package/client/lib/prompt.js
CHANGED
|
@@ -31,6 +31,32 @@ export async function ask(question) {
|
|
|
31
31
|
return ans;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// 密钥输入:raw 模式逐字符读,回显 *(粘贴整块也不回显真值);非 TTY 返回空串
|
|
35
|
+
export async function askSecret(question) {
|
|
36
|
+
if (!process.stdin.isTTY) return '';
|
|
37
|
+
process.stderr.write(question);
|
|
38
|
+
return new Promise((res) => {
|
|
39
|
+
const stdin = process.stdin;
|
|
40
|
+
const wasRaw = stdin.isRaw;
|
|
41
|
+
let buf = '';
|
|
42
|
+
stdin.setRawMode(true);
|
|
43
|
+
stdin.resume();
|
|
44
|
+
stdin.setEncoding('utf8');
|
|
45
|
+
const onData = (ch) => {
|
|
46
|
+
if (ch === '\u0003') { cleanup(); process.stderr.write('\n'); process.exit(130); }
|
|
47
|
+
if (ch === '\r' || ch === '\n') { cleanup(); process.stderr.write('\n'); return res(buf); }
|
|
48
|
+
if (ch === '\u007f' || ch === '\b') {
|
|
49
|
+
if (buf.length) { buf = buf.slice(0, -1); process.stderr.write('\b \b'); }
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
buf += ch;
|
|
53
|
+
process.stderr.write('*'.repeat([...ch].length)); // 粘贴一次来整块→按字符数回星
|
|
54
|
+
};
|
|
55
|
+
const cleanup = () => { stdin.off('data', onData); stdin.setRawMode(wasRaw ?? false); stdin.pause(); };
|
|
56
|
+
stdin.on('data', onData);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
34
60
|
// 多选:序号逗号/空格分隔;回车=保持预勾选;0/none=全不选。返回选中的下标数组
|
|
35
61
|
export async function multiChoose(question, options, { checked = [] } = {}) {
|
|
36
62
|
if (!process.stdin.isTTY) return checked;
|
package/client/public/app.js
CHANGED
|
@@ -321,7 +321,7 @@ async function render() {
|
|
|
321
321
|
<div class="row"><button id="probe">${t('probe_btn')}</button><span id="probe-out" class="mut"></span></div>
|
|
322
322
|
<div id="eps"></div>
|
|
323
323
|
<div class="frow"><span class="lab" style="width:96px">${t('l_url')}</span><input type="text" id="murl" autocomplete="off" placeholder="http://localhost:1234/v1" value="${esc(cfg.llm?.base_url || '')}"></div>
|
|
324
|
-
<div class="frow" id="key-row" style="display:none"><span class="lab" style="width:96px">${t('l_key')}</span><input type="
|
|
324
|
+
<div class="frow" id="key-row" style="display:none"><span class="lab" style="width:96px">${t('l_key')}</span><input type="password" id="mkey" autocomplete="new-password" autocorrect="off" autocapitalize="off" spellcheck="false" data-1p-ignore data-lpignore="true" data-form-type="other" value="${esc(cfg.llm?.api_key?.startsWith('enc:') ? t('enc_disp') : (cfg.llm?.api_key || ''))}"><span class="fhint" id="key-hint"></span>
|
|
325
325
|
<div class="fsub">${t('key_sub')}</div></div>
|
|
326
326
|
<div class="frow" id="model-box"><span class="lab" style="width:96px">${t('l_model')}</span>
|
|
327
327
|
<div class="combo"><input type="text" id="mmodel" autocomplete="off" placeholder="${t('model_ph')}" value="${esc(cfg.llm?.model || '')}">
|