瀏覽代碼

feat(chat): integrate AgentToolCallMessage and thinking indicator in assistant messages

Mochocyang 3 月之前
父節點
當前提交
2c72607608
共有 2 個文件被更改,包括 24 次插入 和 2 次删除
  1. 21 2
      src/components/chat/chat-message.tsx
  2. 3 0
      src/stores/chat-store.ts

+ 21 - 2
src/components/chat/chat-message.tsx

@@ -7,7 +7,7 @@ import "katex/dist/katex.min.css"
 import {
   Bot, User, FileText, ChevronDown, ChevronRight, RefreshCw, Copy, Check,
   Users, Lightbulb, BookOpen, HelpCircle, GitMerge, BarChart3, Layout, Globe,
-  Image as ImageIcon,
+  Image as ImageIcon, Loader2,
 } from "lucide-react"
 import { useWikiStore } from "@/stores/wiki-store"
 import { readFile } from "@/commands/fs"
@@ -15,6 +15,7 @@ import { normalizePath, getFileName } from "@/lib/path-utils"
 import { refreshProjectState } from "@/lib/project-refresh"
 import { getLastQueryPages } from "@/components/chat/chat-shared"
 import { FileEditPreview } from "@/components/chat/file-edit-preview"
+import { AgentToolCallMessage } from "@/components/chat/agent-tool-call-message"
 import type { DisplayMessage } from "@/stores/chat-store"
 
 import { convertLatexToUnicode } from "@/lib/latex-to-unicode"
@@ -82,7 +83,16 @@ export function ChatMessage({ message, isLastAssistant, onRegenerate, novelMode,
           ) : isUser ? (
             <p dir="auto" className="whitespace-pre-wrap break-words">{message.content}</p>
           ) : (
-            <AgentAwareContent content={message.content} projectPath={projectPath} />
+            <>
+              {message.agentToolCalls && message.agentToolCalls.length > 0 && (
+                <AgentToolCallMessage toolCalls={message.agentToolCalls} />
+              )}
+              {message.isAgentRunning && !message.content ? (
+                <AgentThinkingIndicator />
+              ) : (
+                <AgentAwareContent content={message.content} projectPath={projectPath} />
+              )}
+            </>
           )}
         </div>
         {isAssistant && !message.discarded && <CitedReferencesPanel content={message.content} savedReferences={message.references} />}
@@ -550,6 +560,15 @@ export function StreamingMessage({ content }: StreamingMessageProps) {
   )
 }
 
+function AgentThinkingIndicator() {
+  return (
+    <div className="flex items-center gap-1.5 text-xs text-muted-foreground">
+      <Loader2 className="h-3.5 w-3.5 animate-spin" />
+      <span>正在生成中...</span>
+    </div>
+  )
+}
+
 function AgentAwareContent({ content, projectPath }: { content: string; projectPath?: string | null }) {
   const [applied, setApplied] = useState(false)
   const [results, setResults] = useState<import("@/lib/novel/agent-tools").FileEditResult[]>([])

+ 3 - 0
src/stores/chat-store.ts

@@ -1,5 +1,6 @@
 import { create } from "zustand"
 import type { ChatMessage } from "@/lib/llm-client"
+import type { AgentRunRecord } from "@/lib/agent/types"
 import i18n from "@/i18n"
 
 export interface Conversation {
@@ -25,6 +26,8 @@ export interface DisplayMessage {
   conversationId: string
   references?: MessageReference[]  // pages cited in this response, saved at creation time
   discarded?: boolean
+  agentToolCalls?: AgentRunRecord["toolCalls"]
+  isAgentRunning?: boolean
 }
 
 interface ChatState {