重构 Agent 聊天,支持分支管理与消息克隆
This commit is contained in:
@@ -22,18 +22,33 @@ export function useChatToolActionHandler(
|
||||
handler: (action: ChatToolAction) => void,
|
||||
) {
|
||||
const handlerRef = useRef(handler);
|
||||
const lastHandledSeqRef = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
handlerRef.current = handler;
|
||||
}, [handler]);
|
||||
|
||||
useEffect(() => {
|
||||
const initialState = useChatToolStore.getState();
|
||||
if (
|
||||
initialState.lastAction &&
|
||||
initialState.actionSeq > lastHandledSeqRef.current &&
|
||||
Date.now() - initialState.lastActionAt < 5000
|
||||
) {
|
||||
lastHandledSeqRef.current = initialState.actionSeq;
|
||||
handlerRef.current(initialState.lastAction);
|
||||
} else {
|
||||
lastHandledSeqRef.current = initialState.actionSeq;
|
||||
}
|
||||
|
||||
const unsubscribe = useChatToolStore.subscribe(
|
||||
(state, prevState) => {
|
||||
if (
|
||||
state.actionSeq !== prevState.actionSeq &&
|
||||
state.lastAction
|
||||
state.lastAction &&
|
||||
state.actionSeq > lastHandledSeqRef.current
|
||||
) {
|
||||
lastHandledSeqRef.current = state.actionSeq;
|
||||
handlerRef.current(state.lastAction);
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user