Skip to content

Commit adcac82

Browse files
fix: update PlanMessage interface to include streaming properties
1 parent c2037d6 commit adcac82

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

src/frontend/src/components/content/PlanChat.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Copy, Send } from "@/coral/imports/bundleicons";
33
import ChatInput from "@/coral/modules/ChatInput";
44
import remarkGfm from "remark-gfm";
55
import rehypePrism from "rehype-prism";
6-
import { AgentType, PlanChatProps, role } from "@/models";
6+
import { AgentType, ChatMessage, PlanChatProps, role } from "@/models";
77
import { StreamingPlanUpdate } from "@/services/WebSocketService";
88
import {
99
Body1,
@@ -14,6 +14,11 @@ import {
1414
} from "@fluentui/react-components";
1515
import { DiamondRegular, HeartRegular } from "@fluentui/react-icons";
1616
import { 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+
};
1722
import ReactMarkdown from "react-markdown";
1823
import "../../styles/PlanChat.css";
1924
import "../../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>

src/frontend/src/models/plan.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,19 @@ export interface PlanMessage extends BaseModel {
7676
source: string;
7777
/** Step identifier */
7878
step_id: string;
79+
/** Whether this is a streaming message */
80+
streaming?: boolean;
81+
/** Status of the streaming message */
82+
status?: string;
83+
/** Type of message (thinking, action, etc.) */
84+
message_type?: string;
7985
}
86+
87+
/**
88+
* Union type for chat messages - can be either a regular plan message or a temporary streaming message
89+
*/
90+
export type ChatMessage = PlanMessage | { source: string; content: string; timestamp: string; streaming?: boolean; status?: string; message_type?: string; };
91+
8092
/**
8193
* Represents a plan that includes its associated steps.
8294
*/

0 commit comments

Comments
 (0)