mirror of
https://github.com/basketikun/infinite-canvas.git
synced 2026-07-31 05:31:13 +08:00
feat(agent): enhance Codex reasoning summary with Markdown rendering and improve message history merging
This commit is contained in:
@@ -121,7 +121,9 @@ function AgentReasoningSummary({ text, detail, theme }: { text: string; detail?:
|
||||
<ChevronRight className="size-3.5 shrink-0 transition-transform group-open:rotate-90" />
|
||||
</div>
|
||||
</summary>
|
||||
<div className="whitespace-pre-wrap break-words pb-1 pl-6 pr-2 text-xs leading-5" style={{ color: theme.node.muted }}>{text}</div>
|
||||
<div className="break-words pb-1 pl-6 pr-2 text-xs leading-5 [&_code]:rounded [&_code]:px-1 [&_p]:my-1 [&_pre]:my-2" style={{ color: theme.node.muted }}>
|
||||
<Streamdown animated isAnimating={running}>{text}</Streamdown>
|
||||
</div>
|
||||
</details>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -487,3 +487,15 @@ export function mergeHistoryAttachments(messages: AgentChatItem[], currentMessag
|
||||
})
|
||||
.reverse();
|
||||
}
|
||||
|
||||
export function mergeHistoryMessages(historyMessages: AgentChatItem[], currentMessages: AgentChatItem[]) {
|
||||
if (!currentMessages.length) return historyMessages;
|
||||
const remaining = [...historyMessages];
|
||||
const messages = currentMessages.map((current) => {
|
||||
const index = remaining.findIndex((history) => history.id === current.id || ((current.role === "user" || current.role === "assistant") && history.role === current.role && history.text === current.text));
|
||||
if (index < 0) return current;
|
||||
const history = remaining.splice(index, 1)[0];
|
||||
return { ...current, ...history, id: current.id, attachments: current.attachments || history.attachments };
|
||||
});
|
||||
return [...messages, ...remaining];
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import {
|
||||
isConnectionErrorMessage,
|
||||
isCurrentThreadEvent,
|
||||
mergeHistoryAttachments,
|
||||
mergeHistoryMessages,
|
||||
mergeAgentText,
|
||||
normalizeHistoryMessages,
|
||||
normalizeText,
|
||||
@@ -131,7 +132,8 @@ export function LocalAgentPanel({ embedded, headless, autoConnect }: { embedded?
|
||||
let thread = await currentThreadRequest;
|
||||
thread ||= await fetchAgentJson<AgentThreadResponse>(endpoint, token, `/agent/codex/threads/${encodeURIComponent(currentThreadId)}`);
|
||||
const storedMessages = (await storedMessagesRequest) || [];
|
||||
nextMessages = mergeHistoryAttachments(normalizeHistoryMessages(thread.messages || []), [...storedMessages, ...useAgentStore.getState().messages]);
|
||||
const currentMessages = useAgentStore.getState().messages;
|
||||
nextMessages = mergeHistoryMessages(mergeHistoryAttachments(normalizeHistoryMessages(thread.messages || []), [...storedMessages, ...currentMessages]), currentMessages);
|
||||
}
|
||||
if (sequence !== loadThreadsSequenceRef.current) return;
|
||||
setAgentState({ threads: data.data || [], workspacePath: data.workspace?.workspacePath || "", ...(skipHistory ? {} : { messages: nextMessages }) });
|
||||
|
||||
Reference in New Issue
Block a user