feat(roundtable): 增强多智能体 Step2 流式推理与产物展示
提交内容:将 roundtable 的流式消息拆分为文本与 think 推理,支持思考内容以 <think> 形式内联渲染,解决仅返回 reasoning token 时的内容空洞问题。新增 stream-reasoning 工具与单元测试,保证 reasoning 首包到正文的闭合行为稳定。 交互与预览修正:write_file/str_replace 工具的沙箱打开策略改为更接近实时席位行为,不再因为文件后缀限制阻塞临时脚本写入可视化;通过新增 streaming-artifacts 工具统一处理可预览路径、最终交付产物过滤与目录快照比对,支持 bash/脚本直接落盘场景在流式阶段自动发现新增文档。 体验细节:步骤面板文件卡片从工具路径与最终 artifact 统一收敛,避免 read_file 点击误触发;自动滚动逻辑新增布局高度抖动识别,防止模型推理渲染导致的误判向上滚动。
This commit is contained in:
1 parent
fbf9031e25
commit
f0ddade8a7
9 files changed
+600
-106
No files matched your search
@@ -53,16 +53,22 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
// - currentScrollTop < lastObservedScrollTopRef → 用户主动向上滚 → 退出跟随
|
||||
// - currentScrollTop 不变,但 scrollHeight 暴涨(如澄清卡片渲染) → 继续跟随
|
||||
const lastObservedScrollTopRef = useRef(0);
|
||||
// 思考块 / Markdown 代码块完成重排时,浏览器可能在没有用户输入的情况下
|
||||
// clamp scrollTop。记录高度后可把这种布局变化与真实向上滚动区分开。
|
||||
const lastObservedScrollHeightRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
const el = ref.current;
|
||||
if (!el) return;
|
||||
let prevScrollTop = el.scrollTop;
|
||||
lastObservedScrollTopRef.current = prevScrollTop;
|
||||
lastObservedScrollHeightRef.current = el.scrollHeight;
|
||||
const onScroll = () => {
|
||||
const currentScrollTop = el.scrollTop;
|
||||
const currentScrollHeight = el.scrollHeight;
|
||||
const distanceFromBottom = el.scrollHeight - currentScrollTop - el.clientHeight;
|
||||
const isAtBottom = distanceFromBottom <= threshold;
|
||||
const layoutChanged = currentScrollHeight !== lastObservedScrollHeightRef.current;
|
||||
|
||||
const programmaticTarget = programmaticScrollTargetRef.current;
|
||||
if (
|
||||
@@ -73,6 +79,7 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
programmaticScrollTargetRef.current = null;
|
||||
prevScrollTop = currentScrollTop;
|
||||
lastObservedScrollTopRef.current = currentScrollTop;
|
||||
lastObservedScrollHeightRef.current = currentScrollHeight;
|
||||
// 程序滚动后通常落在底部,把 atBottom 维持 true。
|
||||
if (!atBottomRef.current && isAtBottom) {
|
||||
atBottomRef.current = true;
|
||||
@@ -86,7 +93,7 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
|
||||
// 用户主动滚动:**任何向上滚的 scrollTop 减少都立刻退出自动跟随**,
|
||||
// 不等位置算到底部 32px 之外才翻。这是按钮"滚动一点点就显示"的核心。
|
||||
if (currentScrollTop < prevScrollTop && atBottomRef.current) {
|
||||
if (currentScrollTop < prevScrollTop && atBottomRef.current && !layoutChanged) {
|
||||
atBottomRef.current = false;
|
||||
setAtBottom(false);
|
||||
} else if (isAtBottom && !atBottomRef.current) {
|
||||
@@ -99,6 +106,7 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
// 此时用户并没有滚走,应当继续跟随,由下面的 effect 把视口拉到新底部。
|
||||
prevScrollTop = currentScrollTop;
|
||||
lastObservedScrollTopRef.current = currentScrollTop;
|
||||
lastObservedScrollHeightRef.current = currentScrollHeight;
|
||||
};
|
||||
el.addEventListener("scroll", onScroll, { passive: true });
|
||||
// 初次测量
|
||||
@@ -116,21 +124,25 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
const el = ref.current;
|
||||
if (!el) return;
|
||||
const currentScrollTop = el.scrollTop;
|
||||
const currentScrollHeight = el.scrollHeight;
|
||||
const distanceFromBottom = el.scrollHeight - currentScrollTop - el.clientHeight;
|
||||
// 1px 容忍滚动条像素抖动 / 浏览器自身的次像素回弹。
|
||||
const userScrolledUp = currentScrollTop < lastObservedScrollTopRef.current - 1;
|
||||
if (userScrolledUp && distanceFromBottom > threshold) {
|
||||
const layoutChanged = currentScrollHeight !== lastObservedScrollHeightRef.current;
|
||||
if (userScrolledUp && !layoutChanged && distanceFromBottom > threshold) {
|
||||
// 用户主动向上滚 → 退出自动跟随 (兜底 ref 滞后于刚刚的拖动事件)。
|
||||
if (atBottomRef.current) {
|
||||
atBottomRef.current = false;
|
||||
setAtBottom(false);
|
||||
}
|
||||
lastObservedScrollTopRef.current = currentScrollTop;
|
||||
lastObservedScrollHeightRef.current = currentScrollHeight;
|
||||
return;
|
||||
}
|
||||
if (!atBottomRef.current) {
|
||||
// 之前已退出自动跟随,不要因为内容增长又把用户拽回去。
|
||||
lastObservedScrollTopRef.current = currentScrollTop;
|
||||
lastObservedScrollHeightRef.current = currentScrollHeight;
|
||||
return;
|
||||
}
|
||||
// 在底部 (或仅是内容刚增长) → 同步拉到新底部。
|
||||
@@ -140,6 +152,7 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
);
|
||||
el.scrollTop = el.scrollHeight;
|
||||
lastObservedScrollTopRef.current = el.scrollTop;
|
||||
lastObservedScrollHeightRef.current = el.scrollHeight;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, deps);
|
||||
|
||||
@@ -165,6 +178,7 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
);
|
||||
el.scrollTop = el.scrollHeight;
|
||||
lastObservedScrollTopRef.current = el.scrollTop;
|
||||
lastObservedScrollHeightRef.current = el.scrollHeight;
|
||||
});
|
||||
});
|
||||
observer.observe(content);
|
||||
@@ -185,6 +199,7 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
el.scrollHeight - el.clientHeight,
|
||||
);
|
||||
el.scrollTo({ top: el.scrollHeight, behavior: "smooth" });
|
||||
lastObservedScrollHeightRef.current = el.scrollHeight;
|
||||
atBottomRef.current = true;
|
||||
setAtBottom(true);
|
||||
}, [ref]);
|
||||
@@ -201,6 +216,7 @@ export function useAutoScroll<T extends HTMLElement>(
|
||||
);
|
||||
el.scrollTop = el.scrollHeight;
|
||||
lastObservedScrollTopRef.current = el.scrollTop;
|
||||
lastObservedScrollHeightRef.current = el.scrollHeight;
|
||||
atBottomRef.current = true;
|
||||
setAtBottom(true);
|
||||
}, [ref]);
|
||||
|
||||
Reference in new issue
Block a user