@wendongfly/myhi 1.3.94 → 1.3.96
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/bin/myhi.js +12 -0
- package/dist/chat.html +149 -126
- package/dist/index.js +1 -1
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
package/bin/myhi.js
CHANGED
|
@@ -24,6 +24,18 @@ for (let i = 0; i < args.length; i++) {
|
|
|
24
24
|
}
|
|
25
25
|
if (!cmd) cmd = args[0];
|
|
26
26
|
|
|
27
|
+
// --version / -v:只打印版本号就退出,绝不启动 server(否则会起孤儿进程霸占端口)
|
|
28
|
+
if (cmd === '--version' || cmd === '-v' || cmd === 'version') {
|
|
29
|
+
try {
|
|
30
|
+
const pkg = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '../package.json'), 'utf8'));
|
|
31
|
+
console.log(pkg.version);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error('读取版本失败:', e.message);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
process.exit(0);
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
const configDir = join(homedir(), '.myhi');
|
|
28
40
|
const pidFile = join(configDir, 'daemon.pid');
|
|
29
41
|
const logFile = join(configDir, 'daemon.log');
|
package/dist/chat.html
CHANGED
|
@@ -2431,132 +2431,155 @@
|
|
|
2431
2431
|
];
|
|
2432
2432
|
let currentModelId = '';
|
|
2433
2433
|
|
|
2434
|
-
// ── AskUserQuestion
|
|
2435
|
-
//
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
const
|
|
2443
|
-
const
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
qList
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
if (
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2434
|
+
// ── AskUserQuestion 弹窗(累加多题)──
|
|
2435
|
+
// AI 一轮里可能连发多个 AskUserQuestion 调用;旧逻辑每次 openAskSheet 都清空覆盖,
|
|
2436
|
+
// 导致只看到最后一题、其余被顶掉无法回答。改为把本轮所有提问累加进同一弹窗,
|
|
2437
|
+
// 多题一次答完;跨重渲染保留已选答案;去重防同一题被 assistant 事件+独立 tool_use 事件各触发一次。
|
|
2438
|
+
let _askQuestions = [];
|
|
2439
|
+
let askMultiState = null; // { answers: [{question,label}|null] },下标与 _askQuestions 对齐
|
|
2440
|
+
|
|
2441
|
+
function _normalizeAsk(input) {
|
|
2442
|
+
const q = input?.questions || input?.question;
|
|
2443
|
+
const list = Array.isArray(q)
|
|
2444
|
+
? q
|
|
2445
|
+
: [{ question: (typeof q === 'string' ? q : '') || input?.question || '请选择', options: input?.options, header: input?.header }];
|
|
2446
|
+
return list.map((x) => ({
|
|
2447
|
+
question: x.question || x.text || '',
|
|
2448
|
+
options: x.options || x.choices || [],
|
|
2449
|
+
header: x.header,
|
|
2450
|
+
}));
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2453
|
+
window.openAskSheet = function(input) {
|
|
2454
|
+
for (const q of _normalizeAsk(input)) {
|
|
2455
|
+
if (!q.question || !_askQuestions.some((e) => e.question === q.question)) _askQuestions.push(q);
|
|
2456
|
+
}
|
|
2457
|
+
if (!_askQuestions.length) return;
|
|
2458
|
+
_renderAskSheet();
|
|
2459
|
+
};
|
|
2460
|
+
|
|
2461
|
+
function _renderAskSheet() {
|
|
2462
|
+
const sheet = document.getElementById('ask-sheet');
|
|
2463
|
+
const title = document.getElementById('ask-sheet-title');
|
|
2464
|
+
const body = document.getElementById('ask-sheet-body');
|
|
2465
|
+
const inp = document.getElementById('ask-sheet-input');
|
|
2466
|
+
const inputWrap = document.getElementById('ask-sheet-input-wrap');
|
|
2467
|
+
const btnMulti = document.getElementById('ask-sheet-submit-multi');
|
|
2468
|
+
const btnSingle = document.getElementById('ask-sheet-submit-single');
|
|
2469
|
+
|
|
2470
|
+
const qList = _askQuestions;
|
|
2471
|
+
const isMulti = qList.length > 1;
|
|
2472
|
+
if (!askMultiState) askMultiState = { answers: [] };
|
|
2473
|
+
while (askMultiState.answers.length < qList.length) askMultiState.answers.push(null);
|
|
2474
|
+
|
|
2475
|
+
title.textContent = (qList[0] && qList[0].header) || (isMulti ? '提问(' + qList.length + ' 题)' : '提问');
|
|
2476
|
+
if (isMulti) {
|
|
2477
|
+
inputWrap.style.display = 'none';
|
|
2478
|
+
btnSingle.style.display = 'none';
|
|
2479
|
+
btnMulti.style.display = '';
|
|
2480
|
+
} else {
|
|
2481
|
+
inputWrap.style.display = '';
|
|
2482
|
+
btnSingle.style.display = '';
|
|
2483
|
+
btnMulti.style.display = 'none';
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
body.innerHTML = '';
|
|
2487
|
+
qList.forEach((q, qIdx) => {
|
|
2488
|
+
const qText = q.question || '';
|
|
2489
|
+
const block = document.createElement('div');
|
|
2490
|
+
block.className = isMulti ? 'ask-q-block' : '';
|
|
2491
|
+
if (isMulti) {
|
|
2492
|
+
const label = document.createElement('div');
|
|
2493
|
+
label.className = 'ask-q-label';
|
|
2494
|
+
label.textContent = 'Q' + (qIdx + 1);
|
|
2495
|
+
block.appendChild(label);
|
|
2496
|
+
}
|
|
2497
|
+
if (qText) {
|
|
2498
|
+
const desc = document.createElement('div');
|
|
2499
|
+
if (isMulti) { desc.className = 'ask-q-text'; desc.textContent = qText; }
|
|
2500
|
+
else { desc.style.cssText = 'padding:0.5rem 0.3rem;font-size:0.82rem;color:#c9d1d9;line-height:1.5;white-space:pre-wrap'; desc.textContent = qText; }
|
|
2501
|
+
block.appendChild(desc);
|
|
2502
|
+
}
|
|
2503
|
+
if (q.options?.length) {
|
|
2504
|
+
q.options.forEach((opt) => {
|
|
2505
|
+
const item = document.createElement('div');
|
|
2506
|
+
item.className = 'action-sheet-item';
|
|
2507
|
+
const label = opt.label || opt.value || String(opt);
|
|
2508
|
+
item.innerHTML = '<div><div>' + escHtml(label) + '</div>' + (opt.description ? '<div class="desc">' + escHtml(opt.description) + '</div>' : '') + '</div><span class="check" style="display:none">✓</span>';
|
|
2509
|
+
if (isMulti && askMultiState.answers[qIdx]?.label === label) {
|
|
2510
|
+
item.classList.add('ask-opt-selected');
|
|
2511
|
+
const c = item.querySelector('.check'); if (c) c.style.display = '';
|
|
2512
|
+
}
|
|
2513
|
+
item.onclick = () => {
|
|
2514
|
+
if (isMulti) {
|
|
2515
|
+
Array.from(block.querySelectorAll('.action-sheet-item')).forEach((el) => {
|
|
2516
|
+
el.classList.remove('ask-opt-selected');
|
|
2517
|
+
const c = el.querySelector('.check'); if (c) c.style.display = 'none';
|
|
2518
|
+
});
|
|
2519
|
+
item.classList.add('ask-opt-selected');
|
|
2520
|
+
const c = item.querySelector('.check'); if (c) c.style.display = '';
|
|
2521
|
+
askMultiState.answers[qIdx] = { question: qText, label };
|
|
2522
|
+
refreshAskMultiSubmit();
|
|
2523
|
+
} else {
|
|
2524
|
+
_clearAsk();
|
|
2525
|
+
addInputMessage(label);
|
|
2526
|
+
socket.emit('agent:query', { prompt: label });
|
|
2527
|
+
showThinking();
|
|
2528
|
+
}
|
|
2529
|
+
};
|
|
2530
|
+
block.appendChild(item);
|
|
2531
|
+
});
|
|
2532
|
+
}
|
|
2533
|
+
body.appendChild(block);
|
|
2534
|
+
});
|
|
2535
|
+
|
|
2536
|
+
if (isMulti) refreshAskMultiSubmit();
|
|
2537
|
+
sheet.classList.add('open');
|
|
2538
|
+
if (!isMulti) inp.focus();
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
function refreshAskMultiSubmit() {
|
|
2542
|
+
const btn = document.getElementById('ask-sheet-submit-multi');
|
|
2543
|
+
if (!askMultiState) return;
|
|
2544
|
+
const n = _askQuestions.length;
|
|
2545
|
+
const remaining = n - askMultiState.answers.slice(0, n).filter(Boolean).length;
|
|
2546
|
+
btn.disabled = remaining > 0;
|
|
2547
|
+
btn.textContent = remaining > 0 ? '还剩 ' + remaining + ' 题未答' : '提交回答';
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
function _clearAsk() {
|
|
2551
|
+
_askQuestions = [];
|
|
2552
|
+
askMultiState = null;
|
|
2553
|
+
const inp = document.getElementById('ask-sheet-input');
|
|
2554
|
+
if (inp) inp.value = '';
|
|
2555
|
+
document.getElementById('ask-sheet').classList.remove('open');
|
|
2556
|
+
}
|
|
2557
|
+
|
|
2558
|
+
window.submitAskMulti = function() {
|
|
2559
|
+
if (!askMultiState) return;
|
|
2560
|
+
const n = _askQuestions.length;
|
|
2561
|
+
const answers = askMultiState.answers.slice(0, n);
|
|
2562
|
+
if (answers.some((a) => !a)) return;
|
|
2563
|
+
const reply = answers.map((a, i) => 'Q' + (i + 1) + ': ' + a.question + '\nA: ' + a.label).join('\n\n');
|
|
2564
|
+
_clearAsk();
|
|
2565
|
+
addInputMessage(reply);
|
|
2566
|
+
socket.emit('agent:query', { prompt: reply });
|
|
2567
|
+
showThinking();
|
|
2568
|
+
};
|
|
2569
|
+
window.closeAskSheet = function() { _clearAsk(); };
|
|
2570
|
+
window.submitAskReply = function() {
|
|
2571
|
+
const inp = document.getElementById('ask-sheet-input');
|
|
2572
|
+
const text = inp.value.trim();
|
|
2573
|
+
if (!text) return;
|
|
2574
|
+
_clearAsk();
|
|
2575
|
+
addInputMessage(text);
|
|
2576
|
+
socket.emit('agent:query', { prompt: text });
|
|
2577
|
+
showThinking();
|
|
2578
|
+
};
|
|
2579
|
+
document.getElementById('ask-sheet-input').addEventListener('keydown', (e) => {
|
|
2580
|
+
if (e.key === 'Enter') { e.preventDefault(); submitAskReply(); }
|
|
2581
|
+
});
|
|
2582
|
+
|
|
2560
2583
|
window.openModelSheet = function() {
|
|
2561
2584
|
const list = document.getElementById('model-list');
|
|
2562
2585
|
list.innerHTML = '';
|