@wendongfly/myhi 1.3.28 → 1.3.30
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/daemon.js +6 -3
- package/dist/chat.html +79 -0
- package/package.json +1 -1
package/bin/daemon.js
CHANGED
|
@@ -21,6 +21,7 @@ writeFileSync(pidFile, String(process.pid));
|
|
|
21
21
|
|
|
22
22
|
let child = null;
|
|
23
23
|
let restarting = false;
|
|
24
|
+
let stopping = false;
|
|
24
25
|
let crashCount = 0;
|
|
25
26
|
let lastCrash = 0;
|
|
26
27
|
const startTime = Date.now();
|
|
@@ -46,7 +47,7 @@ function startServer() {
|
|
|
46
47
|
const thisChild = child;
|
|
47
48
|
child.on('exit', (code, signal) => {
|
|
48
49
|
if (child === thisChild) child = null; // 只清自己的引用
|
|
49
|
-
if (restarting) return; //
|
|
50
|
+
if (restarting || stopping) return; // 主动重启或正在停止,不自动恢复
|
|
50
51
|
|
|
51
52
|
// 防止崩溃循环:10秒内连续崩溃超过5次则退出
|
|
52
53
|
const now = Date.now();
|
|
@@ -113,16 +114,18 @@ function cleanup() {
|
|
|
113
114
|
// 信号处理
|
|
114
115
|
process.on('SIGTERM', () => {
|
|
115
116
|
log('收到 SIGTERM,停止...');
|
|
117
|
+
stopping = true;
|
|
116
118
|
if (child) child.kill('SIGTERM');
|
|
117
119
|
cleanup();
|
|
118
|
-
setTimeout(() => process.exit(0),
|
|
120
|
+
setTimeout(() => process.exit(0), 2000);
|
|
119
121
|
});
|
|
120
122
|
|
|
121
123
|
process.on('SIGINT', () => {
|
|
122
124
|
log('收到 SIGINT,停止...');
|
|
125
|
+
stopping = true;
|
|
123
126
|
if (child) child.kill('SIGTERM');
|
|
124
127
|
cleanup();
|
|
125
|
-
setTimeout(() => process.exit(0),
|
|
128
|
+
setTimeout(() => process.exit(0), 2000);
|
|
126
129
|
});
|
|
127
130
|
|
|
128
131
|
// Windows: 通过 stdin 消息(无 SIGUSR2 支持)
|
package/dist/chat.html
CHANGED
|
@@ -452,6 +452,20 @@
|
|
|
452
452
|
</div>
|
|
453
453
|
</div>
|
|
454
454
|
|
|
455
|
+
<!-- AskUserQuestion 弹窗 -->
|
|
456
|
+
<div id="ask-sheet" class="action-sheet">
|
|
457
|
+
<div class="action-sheet-backdrop" onclick="closeAskSheet()"></div>
|
|
458
|
+
<div class="action-sheet-box" style="max-height:70vh;display:flex;flex-direction:column">
|
|
459
|
+
<div class="action-sheet-title" id="ask-sheet-title">提问</div>
|
|
460
|
+
<div id="ask-sheet-body" style="flex:1;overflow-y:auto;padding:0.3rem 0;scrollbar-width:thin"></div>
|
|
461
|
+
<div style="padding:0.3rem 0.2rem">
|
|
462
|
+
<input id="ask-sheet-input" class="slash-inp" placeholder="输入自定义回答(可选)" autocomplete="off">
|
|
463
|
+
</div>
|
|
464
|
+
<button class="action-sheet-cancel" style="background:#7c3aed;color:#fff;font-weight:600;margin-bottom:0.4rem" onclick="submitAskReply()">发送自定义回答</button>
|
|
465
|
+
<button class="action-sheet-cancel" onclick="closeAskSheet()">取消</button>
|
|
466
|
+
</div>
|
|
467
|
+
</div>
|
|
468
|
+
|
|
455
469
|
<div id="skill-sheet" class="action-sheet">
|
|
456
470
|
<div class="action-sheet-backdrop" onclick="closeSkillSheet()"></div>
|
|
457
471
|
<div class="action-sheet-box" style="max-height:85vh;display:flex;flex-direction:column">
|
|
@@ -1232,6 +1246,9 @@
|
|
|
1232
1246
|
} else if (block.type === 'text' && block.text) {
|
|
1233
1247
|
addAssistantMessage(block.text);
|
|
1234
1248
|
} else if (block.type === 'tool_use') {
|
|
1249
|
+
if (block.name === 'AskUserQuestion' && block.input) {
|
|
1250
|
+
openAskSheet(block.input);
|
|
1251
|
+
}
|
|
1235
1252
|
addToolMessage(JSON.stringify(block.input || {}, null, 2), block.name || '工具');
|
|
1236
1253
|
} else if (block.type === 'tool_result') {
|
|
1237
1254
|
const content = typeof block.content === 'string' ? block.content : JSON.stringify(block.content);
|
|
@@ -1282,6 +1299,9 @@
|
|
|
1282
1299
|
break;
|
|
1283
1300
|
case 'tool_use':
|
|
1284
1301
|
// 独立工具调用消息
|
|
1302
|
+
if (msg.name === 'AskUserQuestion' && msg.input) {
|
|
1303
|
+
openAskSheet(msg.input);
|
|
1304
|
+
}
|
|
1285
1305
|
addToolMessage(JSON.stringify(msg.input || {}, null, 2), msg.name || '工具');
|
|
1286
1306
|
setWorkState('working');
|
|
1287
1307
|
break;
|
|
@@ -1822,6 +1842,65 @@
|
|
|
1822
1842
|
];
|
|
1823
1843
|
let currentModelId = '';
|
|
1824
1844
|
|
|
1845
|
+
// ── AskUserQuestion 弹窗 ──
|
|
1846
|
+
window.openAskSheet = function(input) {
|
|
1847
|
+
const questions = input?.questions || input?.question;
|
|
1848
|
+
const sheet = document.getElementById('ask-sheet');
|
|
1849
|
+
const title = document.getElementById('ask-sheet-title');
|
|
1850
|
+
const body = document.getElementById('ask-sheet-body');
|
|
1851
|
+
const inp = document.getElementById('ask-sheet-input');
|
|
1852
|
+
body.innerHTML = '';
|
|
1853
|
+
inp.value = '';
|
|
1854
|
+
|
|
1855
|
+
// 支持单个 question 或 questions 数组
|
|
1856
|
+
const qList = Array.isArray(questions) ? questions : [{ question: questions || input?.question || '请选择', options: input?.options }];
|
|
1857
|
+
|
|
1858
|
+
qList.forEach(q => {
|
|
1859
|
+
const qText = q.question || q.text || '';
|
|
1860
|
+
title.textContent = q.header || '提问';
|
|
1861
|
+
// 问题描述
|
|
1862
|
+
if (qText) {
|
|
1863
|
+
const desc = document.createElement('div');
|
|
1864
|
+
desc.style.cssText = 'padding:0.5rem 0.3rem;font-size:0.82rem;color:#c9d1d9;line-height:1.5;white-space:pre-wrap';
|
|
1865
|
+
desc.textContent = qText;
|
|
1866
|
+
body.appendChild(desc);
|
|
1867
|
+
}
|
|
1868
|
+
// 选项列表
|
|
1869
|
+
if (q.options?.length) {
|
|
1870
|
+
q.options.forEach(opt => {
|
|
1871
|
+
const item = document.createElement('div');
|
|
1872
|
+
item.className = 'action-sheet-item';
|
|
1873
|
+
item.innerHTML = `<div><div>${escHtml(opt.label || opt.value || opt)}</div>${opt.description ? `<div class="desc">${escHtml(opt.description)}</div>` : ''}</div>`;
|
|
1874
|
+
item.onclick = () => {
|
|
1875
|
+
closeAskSheet();
|
|
1876
|
+
const reply = opt.label || opt.value || String(opt);
|
|
1877
|
+
addInputMessage(reply);
|
|
1878
|
+
socket.emit('agent:query', { prompt: reply });
|
|
1879
|
+
showThinking();
|
|
1880
|
+
};
|
|
1881
|
+
body.appendChild(item);
|
|
1882
|
+
});
|
|
1883
|
+
}
|
|
1884
|
+
});
|
|
1885
|
+
sheet.classList.add('open');
|
|
1886
|
+
inp.focus();
|
|
1887
|
+
};
|
|
1888
|
+
window.closeAskSheet = function() {
|
|
1889
|
+
document.getElementById('ask-sheet').classList.remove('open');
|
|
1890
|
+
};
|
|
1891
|
+
window.submitAskReply = function() {
|
|
1892
|
+
const inp = document.getElementById('ask-sheet-input');
|
|
1893
|
+
const text = inp.value.trim();
|
|
1894
|
+
if (!text) return;
|
|
1895
|
+
closeAskSheet();
|
|
1896
|
+
addInputMessage(text);
|
|
1897
|
+
socket.emit('agent:query', { prompt: text });
|
|
1898
|
+
showThinking();
|
|
1899
|
+
};
|
|
1900
|
+
document.getElementById('ask-sheet-input').addEventListener('keydown', (e) => {
|
|
1901
|
+
if (e.key === 'Enter') { e.preventDefault(); submitAskReply(); }
|
|
1902
|
+
});
|
|
1903
|
+
|
|
1825
1904
|
window.openModelSheet = function() {
|
|
1826
1905
|
const list = document.getElementById('model-list');
|
|
1827
1906
|
list.innerHTML = '';
|