feat(chat): 上下文用量环与可靠手动压缩 - #426
Open
su-fen wants to merge 3 commits into
Open
Conversation
composer 发送按钮上方新增上下文用量环:<50% 绿 / 50-80% 黄 / >80% 红, 占用 ≥50%(变黄)起可点击,确认后手动压缩上下文。GUI 与 WebUI 完整对齐。 - 共享层 lib/chat/contextUsage.ts:阈值/读数单一真源。倒扫 transcript 取 最近 assistant 轮次真实 usage;压缩后回退检查点摘要的 CJK 感知估算 (自 tokenLedger 迁入共享层,re-export 保持旧调用方不动),环不归零。 - 共享层 ContextUsageRing:Base UI Meter 语义 + SVG 环 + 既有 RuntimeControlTooltip 视觉 + ConfirmActionPopover 确认,两端同构。 - 桌面端执行:decideCompaction 增 bypassThresholdAndCooldown(手动仅跳过 阈值/冷却,disabled 等硬守卫保留);controller.compactManually 空闲单飞、 临时绑定复用 compactDuringRun 主流程;useManualCompaction 收纳 sinks/ providerConfig/bridge 装配单点,检查点与压缩状态经既有 bridge 通道镜像。 - WebUI 手动压缩:chat_queue.compact_now 全透传中继(零 proto/Go/Rust 改动),GUI 侧受理即回包后 fire-and-forget 调同一 handleManualCompact; 进行中反馈复用 tool_status_is_compaction。 - i18n 两宿主 zh/en 补 manualCompact* 4 key;WebUI 镜像 confirm popover 动画 CSS。 - 测试:contextUsage 阈值/读数/估算迁移 7 例;compactManually 空闲强制 压缩/busy/硬守卫 3 例。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked issue
Closes #359
Summary
在最新
main和当前共享 UI 架构上实现 GUI / WebUI 上下文用量环,并补齐手动压缩的完整可靠性闭环:liveAgentContextUsage: { totalTokens, fixedTokens },动态校正 System Prompt、Skills、MCP 和 Tools 固定开销;contextRelevant: false从上下文账本中整轮排除;manual_compaction_result终态,并处理后台订阅、五分钟超时、迟到回包和跨会话错误隔离。相关早期方案:#358。本 PR 不改写外部贡献者的 fork 分支,基于最新主线独立提交完整双宿主实现和 P1/P2 可靠性修复。
Change scope
agent-ui/agent-gui/agent-gateway/webcrates/agent-ui/src/lib/chat/contextUsage.tscrates/agent-ui/src/components/chat/ContextUsageRing.tsxcrates/agent-gui/src/lib/chat/compaction/crates/agent-gui/src/pages/chat/runtime/useManualCompaction.tscrates/agent-gui/src/pages/chat/turns/crates/agent-gateway/web/src/app/GatewayApp.tsxcrates/agent-gateway/web/src/lib/chat/transcript/Screenshots / preview
Issue #359 中的目标交互预览;本 PR 保留用量环与确认压缩交互,并扩展到 GUI / WebUI 双端:
Verification
pnpm --filter liveagent exec tsc --noEmit:通过pnpm --filter @liveagent/gateway-webui exec tsc --noEmit:通过pnpm test:webui:546/546 通过pnpm test:gui:1531/1532 通过;唯一失败为test/settings/normalization.test.mjs:425的 Gemini 档位目录断言,已在纯origin/main@24e268f9独立复现pnpm build:gui:通过pnpm build:webui:通过pnpm lint:gui/pnpm lint:webui:通过pnpm lint:ui的 6 个既有 import 排序错误已在纯origin/main@24e268f9复现pnpm check:ui-boundaries:通过git diff --check:通过Pre-submit checklist
Closes #359.