@wendongfly/myhi 1.3.153 → 1.3.154
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/dist/chat.html +55 -0
- package/dist/index.js +1 -1
- package/dist/index.min.js +3 -3
- package/package.json +1 -1
package/dist/chat.html
CHANGED
|
@@ -402,6 +402,7 @@
|
|
|
402
402
|
<button class="top-btn" onclick="openSettings()" title="设置">
|
|
403
403
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 01-2.83 2.83l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 012.83-2.83l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"/></svg>
|
|
404
404
|
</button>
|
|
405
|
+
<button class="top-btn" id="ctx-chip" onclick="doCompact()" title="上下文水位(点击压缩释放空间)" style="display:none;font-size:0.7rem;color:var(--muted)">上下文</button>
|
|
405
406
|
<button class="top-btn" onclick="showUsage()" title="用量" style="font-size:0.7rem;color:var(--muted)">用量</button>
|
|
406
407
|
<button class="top-btn" onclick="openFilePanel()" title="文件" style="font-size:0.7rem;color:var(--muted)">文件</button>
|
|
407
408
|
<button class="top-btn" onclick="openSwitchSheet()" title="切换会话" style="font-size:0.7rem;color:var(--muted)">切换</button>
|
|
@@ -2167,6 +2168,7 @@
|
|
|
2167
2168
|
claudeSession = isClaudeSession(session) || session.mode === 'agent';
|
|
2168
2169
|
updateShortcutBar();
|
|
2169
2170
|
updatePlanButton();
|
|
2171
|
+
ctxUpdate(session.contextTokens || 0);
|
|
2170
2172
|
|
|
2171
2173
|
// 更新输入框占位符
|
|
2172
2174
|
cmdInput.placeholder = session.mode === 'agent' ? '输入消息...' : '输入命令...';
|
|
@@ -2242,6 +2244,11 @@
|
|
|
2242
2244
|
break;
|
|
2243
2245
|
case 'assistant':
|
|
2244
2246
|
removeThinking();
|
|
2247
|
+
if (msg.message?.usage) {
|
|
2248
|
+
const cu = msg.message.usage;
|
|
2249
|
+
const ct = (cu.input_tokens || 0) + (cu.cache_read_input_tokens || 0) + (cu.cache_creation_input_tokens || 0);
|
|
2250
|
+
if (ct > 0) ctxUpdate(ct);
|
|
2251
|
+
}
|
|
2245
2252
|
if (msg.message?.content) {
|
|
2246
2253
|
// 进入 loop 前快照:同一 assistant 事件里所有 text 块统一按入口时刻的 call 标志决定,
|
|
2247
2254
|
// 避免渲染完第一段 text 后置位标志,导致同事件内 [text, tool_use, text] 的第二段被跳过
|
|
@@ -2286,6 +2293,12 @@
|
|
|
2286
2293
|
// 关键:idle 放最后——渲染最终答复的 addAssistantMessage 会把状态置回 'working',
|
|
2287
2294
|
// 若在其之前置 idle 会被顶回「执行中」+ 取消按钮不复位。渲染全部完成后再回 idle。
|
|
2288
2295
|
setWorkState('idle');
|
|
2296
|
+
// 收尾水位提示:assistant 流中已实时更新 chip,这里按最终 usage 补一次提示(80/90 档各一次)
|
|
2297
|
+
{
|
|
2298
|
+
const ru = msg.usage;
|
|
2299
|
+
const ct = ru ? (ru.input_tokens || 0) + (ru.cache_read_input_tokens || 0) + (ru.cache_creation_input_tokens || 0) : 0;
|
|
2300
|
+
if (ct > 0) { ctxUpdate(ct); ctxMaybeNudge(ct); }
|
|
2301
|
+
}
|
|
2289
2302
|
break;
|
|
2290
2303
|
case 'content_block_start':
|
|
2291
2304
|
// 流式内容块开始:thinking 时创建占位,由 thinking_delta 增量填充;
|
|
@@ -2608,6 +2621,46 @@
|
|
|
2608
2621
|
|
|
2609
2622
|
// ── 输入处理 ──────────────────────────────────
|
|
2610
2623
|
window.sendCommand = sendCommand;
|
|
2624
|
+
// ── 上下文水位指示 ──────────────────────────────
|
|
2625
|
+
// 数据源:claude 每条 assistant/result 消息的 usage(input + cache 读/写)≈ 当前上下文 token 总量。
|
|
2626
|
+
// claude 满 ~90% 会 auto-compact;myhi 显示水位 + 过阈值提示,让用户在任务节点**主动**压缩更可控。
|
|
2627
|
+
const CTX_WARN = 0.75, CTX_URGENT = 0.9;
|
|
2628
|
+
function ctxLimit(tokens) {
|
|
2629
|
+
// 200k 窗口装不下 >200k,超过即证明是 1M 上下文模型
|
|
2630
|
+
return tokens > 200_000 ? 1_000_000 : 200_000;
|
|
2631
|
+
}
|
|
2632
|
+
function ctxUpdate(tokens) {
|
|
2633
|
+
const chip = document.getElementById('ctx-chip');
|
|
2634
|
+
if (!chip) return;
|
|
2635
|
+
if (!tokens || tokens <= 0) { chip.style.display = 'none'; return; }
|
|
2636
|
+
const limit = ctxLimit(tokens);
|
|
2637
|
+
const pct = Math.min(100, Math.round(tokens / limit * 100));
|
|
2638
|
+
chip.style.display = '';
|
|
2639
|
+
chip.textContent = `上下文 ${pct}%`;
|
|
2640
|
+
chip.style.color = pct >= 90 ? 'var(--red)' : pct >= 75 ? 'var(--yellow)' : 'var(--muted)';
|
|
2641
|
+
// 压缩快捷按钮同步高亮(agent 栏是 doSlashCmd('/compact'),PTY 栏是 doCompact())
|
|
2642
|
+
for (const sel of [
|
|
2643
|
+
'#sk-claude-agent button[onclick*="/compact"]',
|
|
2644
|
+
'#sk-claude-pty button[onclick*="compact"]',
|
|
2645
|
+
]) {
|
|
2646
|
+
const cbtn = document.querySelector(sel);
|
|
2647
|
+
if (cbtn) cbtn.style.color = pct >= 75 ? (pct >= 90 ? 'var(--red)' : 'var(--yellow)') : '';
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
let _ctxNudgeLevel = 0; // 已提示过的档位:0 无 / 1 警告 / 2 紧急
|
|
2651
|
+
function ctxMaybeNudge(tokens) {
|
|
2652
|
+
const pct = tokens / ctxLimit(tokens) * 100;
|
|
2653
|
+
const level = pct >= 90 ? 2 : pct >= 75 ? 1 : 0;
|
|
2654
|
+
if (level <= _ctxNudgeLevel) return;
|
|
2655
|
+
_ctxNudgeLevel = level;
|
|
2656
|
+
const msg = level === 2
|
|
2657
|
+
? `⚠️ 上下文已用约 ${Math.round(pct)}%,快满了——claude 即将自动压缩(可能丢细节)。建议现在就在任务节点点「压缩」主动收尾,或 /clear 重开干净会话。`
|
|
2658
|
+
: `💡 上下文已用约 ${Math.round(pct)}%。建议在当前任务收尾后点「压缩」(/compact)释放空间,长对话越往后越慢越贵。`;
|
|
2659
|
+
addStatusMessage(msg);
|
|
2660
|
+
}
|
|
2661
|
+
window.ctxUpdate = ctxUpdate; // 惯例挂 window(同 doClear/doCompact),便于外部/测试驱动
|
|
2662
|
+
window.ctxMaybeNudge = ctxMaybeNudge;
|
|
2663
|
+
|
|
2611
2664
|
// 服务端本地处理的 slash 命令(agent.js 拦截后只回一条 system/info、不 spawn claude、
|
|
2612
2665
|
// 永远等不到 result)—— 这些不能进 thinking/working 态,否则没人把它清回来:
|
|
2613
2666
|
// 切模型后输入框永远「运行中」(1.3.152 用户实测)。
|
|
@@ -3710,6 +3763,8 @@
|
|
|
3710
3763
|
if (!isController && canTakeControl()) socket.emit('take-control', { sessionId: SESSION_ID });
|
|
3711
3764
|
socket.emit('agent:query', { prompt: '/clear' });
|
|
3712
3765
|
addStatusMessage('已清除对话和 Claude 上下文');
|
|
3766
|
+
_ctxNudgeLevel = 0;
|
|
3767
|
+
ctxUpdate(0); // 上下文已清空,水位指示复位
|
|
3713
3768
|
} else {
|
|
3714
3769
|
addStatusMessage('聊天记录已清除');
|
|
3715
3770
|
}
|