Skip to content

Agread#59

Closed
Sskift wants to merge 2 commits intodevfrom
agread
Closed

Agread#59
Sskift wants to merge 2 commits intodevfrom
agread

Conversation

@Sskift
Copy link
Copy Markdown
Collaborator

@Sskift Sskift commented Dec 18, 2025

No description provided.

Copilot AI review requested due to automatic review settings December 18, 2025 10:53
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements several improvements to the smart reading interface including editor reset functionality, better conversation state tracking, enhanced error handling for missing conversations, and fixes for SSR hydration mismatches.

  • Added resetEditor method to NoteEditorPanel for clearing editor state
  • Enhanced conversation history loading with 404 error recovery and state tracking
  • Fixed hydration mismatches in notes pages by deferring token reads to client-side

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
frontend/src/components/note-editor/NoteEditorPanel.tsx Added resetEditor method to ref interface and implementation to clear all editor state
frontend/src/components/ai-agent/AgentChatPanel.tsx Added savedConversationRef tracking, improved 404 error handling with cache cleanup, and conditional auto-summary prevention
frontend/src/app/smart-reading/page.tsx Updated ref type to include resetEditor, removed obsolete state setters, and added editor reset on PDF close
frontend/src/app/notes/page.tsx Fixed SSR hydration mismatch by deferring token read to useEffect with loading state
frontend/src/app/notes/new/page.tsx Applied same hydration fix as notes page
frontend/package-lock.json Removed peer dependency flags from several packages
Files not reviewed (1)
  • frontend/package-lock.json: Language not supported
Comments suppressed due to low confidence (1)

frontend/src/components/ai-agent/AgentChatPanel.tsx:146

  • The loadConversationHistory callback uses paperId on line 128 but doesn't include it in the dependency array. This could lead to stale closure issues where the callback references an outdated paperId value. Add paperId to the dependency array.
  const loadConversationHistory = useCallback(async (convId: number) => {
    if (!convId) return;
    
    setIsLoadingHistory(true);
    try {
      const token = getAccessToken();
      if (!token) {
        console.warn("未登录,无法加载对话历史");
        return;
      }

      const conversation = await getConversationHistory(token, convId, "reading");
      if (conversation.messages && conversation.messages.length > 0) {
        const historyMessages: AgentMessage[] = conversation.messages.map((msg) => ({
          id: createId(),
          role: msg.role,
          content: msg.content,
          timestamp: new Date(msg.created_at),
        }));
        setMessages(historyMessages);
        savedConversationRef.current = true;
      }
    } catch (error) {
      console.error("加载对话历史失败:", error);
      // 后端会在类别不匹配或不存在时返回 404;清理本地缓存以便重新创建对话
      const message = error instanceof Error ? error.message : "";
      if (message.includes("不存在") || message.toLowerCase().includes("not found")) {
        if (paperId) {
          localStorage.removeItem(`conversation_${paperId}`);
        }
        setConversationId(null);
        setMessages([
          {
            id: createId(),
            role: "assistant",
            content: "对话不存在,已为当前文档重置。可以继续提问,我会新建对话并保存历史。",
            timestamp: new Date(),
          },
        ]);
        savedConversationRef.current = false;
      }
      // 其他错误不影响新对话
    } finally {
      setIsLoadingHistory(false);
    }
  }, []);

@Sskift
Copy link
Copy Markdown
Collaborator Author

Sskift commented Dec 23, 2025

these changes have been merged to release, not dev

@Sskift Sskift closed this Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants