mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 22:32:27 +08:00
Persist processed tool calls to prevent replay after chat restore (#224)
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
X,
|
||||
} from "lucide-react"
|
||||
import Image from "next/image"
|
||||
import type { MutableRefObject } from "react"
|
||||
import { useCallback, useEffect, useRef, useState } from "react"
|
||||
import ReactMarkdown from "react-markdown"
|
||||
import {
|
||||
@@ -169,6 +170,7 @@ interface ChatMessageDisplayProps {
|
||||
messages: UIMessage[]
|
||||
setInput: (input: string) => void
|
||||
setFiles: (files: File[]) => void
|
||||
processedToolCallsRef: MutableRefObject<Set<string>>
|
||||
sessionId?: string
|
||||
onRegenerate?: (messageIndex: number) => void
|
||||
onEditMessage?: (messageIndex: number, newText: string) => void
|
||||
@@ -179,6 +181,7 @@ export function ChatMessageDisplay({
|
||||
messages,
|
||||
setInput,
|
||||
setFiles,
|
||||
processedToolCallsRef,
|
||||
sessionId,
|
||||
onRegenerate,
|
||||
onEditMessage,
|
||||
@@ -187,7 +190,7 @@ export function ChatMessageDisplay({
|
||||
const { chartXML, loadDiagram: onDisplayChart } = useDiagram()
|
||||
const messagesEndRef = useRef<HTMLDivElement>(null)
|
||||
const previousXML = useRef<string>("")
|
||||
const processedToolCalls = useRef<Set<string>>(new Set())
|
||||
const processedToolCalls = processedToolCallsRef
|
||||
const [expandedTools, setExpandedTools] = useState<Record<string, boolean>>(
|
||||
{},
|
||||
)
|
||||
|
||||
@@ -189,6 +189,9 @@ export default function ChatPanel({
|
||||
// Ref to track consecutive auto-retry count (reset on user action)
|
||||
const autoRetryCountRef = useRef(0)
|
||||
|
||||
// Persist processed tool call IDs so collapsing the chat doesn't replay old tool outputs
|
||||
const processedToolCallsRef = useRef<Set<string>>(new Set())
|
||||
|
||||
const {
|
||||
messages,
|
||||
sendMessage,
|
||||
@@ -1081,6 +1084,7 @@ Please retry with an adjusted search pattern or use display_diagram if retries a
|
||||
messages={messages}
|
||||
setInput={setInput}
|
||||
setFiles={handleFileChange}
|
||||
processedToolCallsRef={processedToolCallsRef}
|
||||
sessionId={sessionId}
|
||||
onRegenerate={handleRegenerate}
|
||||
status={status}
|
||||
|
||||
Reference in New Issue
Block a user