@@ -3,7 +3,7 @@ import { Copy, Send } from "@/coral/imports/bundleicons";
33import ChatInput from "@/coral/modules/ChatInput" ;
44import remarkGfm from "remark-gfm" ;
55import rehypePrism from "rehype-prism" ;
6- import { AgentType , PlanChatProps , role } from "@/models" ;
6+ import { AgentType , ChatMessage , PlanChatProps , role } from "@/models" ;
77import { StreamingPlanUpdate } from "@/services/WebSocketService" ;
88import {
99 Body1 ,
@@ -14,6 +14,11 @@ import {
1414} from "@fluentui/react-components" ;
1515import { DiamondRegular , HeartRegular } from "@fluentui/react-icons" ;
1616import { useEffect , useRef , useState } from "react" ;
17+
18+ // Type guard to check if a message has streaming properties
19+ const hasStreamingProperties = ( msg : ChatMessage ) : msg is ChatMessage & { streaming ?: boolean ; status ?: string ; message_type ?: string ; } => {
20+ return 'streaming' in msg || 'status' in msg || 'message_type' in msg ;
21+ } ;
1722import ReactMarkdown from "react-markdown" ;
1823import "../../styles/PlanChat.css" ;
1924import "../../styles/Chat.css" ;
@@ -94,7 +99,7 @@ const PlanChat: React.FC<PlanChatProps> = ({
9499 ] ;
95100
96101 // Merge streaming messages with existing messages
97- const allMessages = [ ...displayMessages ] ;
102+ const allMessages : ChatMessage [ ] = [ ...displayMessages ] ;
98103
99104 // Add streaming messages as assistant messages
100105 streamingMessages . forEach ( streamMsg => {
@@ -136,7 +141,7 @@ const PlanChat: React.FC<PlanChatProps> = ({
136141 return (
137142 < div
138143 key = { index }
139- className = { `message ${ isHuman ? role . user : role . assistant } ${ ( msg as any ) . streaming ? 'streaming-message' : '' } ` }
144+ className = { `message ${ isHuman ? role . user : role . assistant } ${ hasStreamingProperties ( msg ) && msg . streaming ? 'streaming-message' : '' } ` }
140145 >
141146 { ! isHuman && (
142147 < div className = "plan-chat-header" >
@@ -152,16 +157,16 @@ const PlanChat: React.FC<PlanChatProps> = ({
152157 >
153158 BOT
154159 </ Tag >
155- { ( msg as any ) . streaming && (
160+ { hasStreamingProperties ( msg ) && msg . streaming && (
156161 < Tag
157162 size = "extra-small"
158163 shape = "rounded"
159164 appearance = "outline"
160165 icon = { < Spinner size = "extra-tiny" /> }
161166 >
162- { ( msg as any ) . message_type === 'thinking' ? 'Thinking...' :
163- ( msg as any ) . message_type === 'action' ? 'Acting...' :
164- ( msg as any ) . status === 'in_progress' ? 'Working...' : 'Live' }
167+ { msg . message_type === 'thinking' ? 'Thinking...' :
168+ msg . message_type === 'action' ? 'Acting...' :
169+ msg . status === 'in_progress' ? 'Working...' : 'Live' }
165170 </ Tag >
166171 ) }
167172 </ div >
0 commit comments