Skip to content

Commit 91a9aa8

Browse files
committed
Refactor plan approval request event to use enum
Replaced hardcoded 'parsed_plan_approval_request' string with WebsocketMessageType.PLAN_APPROVAL_REQUEST enum across components, models, and services for improved type safety and maintainability.
1 parent c915021 commit 91a9aa8

File tree

5 files changed

+11
-9
lines changed

5 files changed

+11
-9
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import ChatInput from "../../coral/modules/ChatInput";
2424
import InlineToaster, {
2525
useInlineToaster,
2626
} from "../toast/InlineToaster";
27+
import { WebsocketMessageType } from "@/models";
2728
interface SimplifiedPlanChatProps extends PlanChatProps {
2829
onPlanReceived?: (planData: MPlanData) => void;
2930
initialTask?: string;
@@ -60,7 +61,7 @@ const PlanChat: React.FC<SimplifiedPlanChatProps> = ({
6061

6162
// Listen for m_plan streaming
6263
useEffect(() => {
63-
const unsubscribe = webSocketService.on('parsed_plan_approval_request', (approvalRequest: any) => {
64+
const unsubscribe = webSocketService.on(WebsocketMessageType.PLAN_APPROVAL_REQUEST, (approvalRequest: any) => {
6465
console.log('📋 Plan received:', approvalRequest);
6566

6667
let mPlanData: MPlanData | null = null;

src/frontend/src/models/messages.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export interface PlanApprovalResponseData {
164164

165165
// Structured plan approval request
166166
export interface ParsedPlanApprovalRequest {
167-
type: 'parsed_plan_approval_request';
167+
type: WebsocketMessageType.PLAN_APPROVAL_REQUEST;
168168
plan_id: string;
169169
parsedData: MPlanData;
170170
rawData: string;

src/frontend/src/pages/PlanPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useRef, useState, useMemo } from "react"
22
import { useParams, useNavigate } from "react-router-dom";
33
import { Spinner, Text } from "@fluentui/react-components";
44
import { PlanDataService } from "../services/PlanDataService";
5-
import { ProcessedPlanData, PlanWithSteps } from "../models";
5+
import { ProcessedPlanData, PlanWithSteps, WebsocketMessageType } from "../models";
66
import PlanChat from "../components/content/PlanChat";
77
import PlanPanelRight from "../components/content/PlanPanelRight";
88
import PlanPanelLeft from "../components/content/PlanPanelLeft";
@@ -131,7 +131,7 @@ const PlanPage: React.FC = () => {
131131
const unsubscribeStreaming = webSocketService.on('agent_message', handleStreamingMessage);
132132
const unsubscribePlanApproval = webSocketService.on('plan_approval_response', handlePlanApprovalResponse);
133133
const unsubscribePlanApprovalRequest = webSocketService.on('plan_approval_request', handlePlanApprovalRequest);
134-
const unsubscribeParsedPlanApprovalRequest = webSocketService.on('parsed_plan_approval_request', handlePlanApprovalRequest);
134+
const unsubscribeParsedPlanApprovalRequest = webSocketService.on(WebsocketMessageType.PLAN_APPROVAL_REQUEST, handlePlanApprovalRequest);
135135

136136
return () => {
137137
console.log('🔌 Cleaning up WebSocket connections');

src/frontend/src/services/PlanDataService.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
ProcessedPlanData,
66
PlanMessage,
77
MPlanData,
8-
StepStatus
8+
StepStatus,
9+
WebsocketMessageType
910
} from "@/models";
1011
import { apiService } from "@/api";
1112

@@ -156,7 +157,7 @@ export class PlanDataService {
156157
console.log('🔍 Parsing plan approval request:', rawData, 'Type:', typeof rawData);
157158

158159
// Already parsed object passthrough
159-
if (rawData && typeof rawData === 'object' && rawData.type === 'parsed_plan_approval_request') {
160+
if (rawData && typeof rawData === 'object' && rawData.type === WebsocketMessageType.PLAN_APPROVAL_REQUEST) {
160161
return rawData.parsedData || null;
161162
}
162163

src/frontend/src/services/WebSocketService.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class WebSocketService {
139139
}
140140

141141
onPlanApprovalRequest(callback: (approvalRequest: ParsedPlanApprovalRequest) => void): () => void {
142-
return this.on('parsed_plan_approval_request', (message: StreamMessage) => {
142+
return this.on(WebsocketMessageType.PLAN_APPROVAL_REQUEST, (message: StreamMessage) => {
143143
if (message.data) callback(message.data);
144144
});
145145
}
@@ -174,12 +174,12 @@ class WebSocketService {
174174
const parsedData = PlanDataService.parsePlanApprovalRequest(message.data);
175175
if (parsedData) {
176176
const structuredMessage: ParsedPlanApprovalRequest = {
177-
type: 'parsed_plan_approval_request',
177+
type: WebsocketMessageType.PLAN_APPROVAL_REQUEST,
178178
plan_id: parsedData.id,
179179
parsedData,
180180
rawData: message.data
181181
};
182-
this.emit('parsed_plan_approval_request', structuredMessage);
182+
this.emit(WebsocketMessageType.PLAN_APPROVAL_REQUEST, structuredMessage);
183183
} else {
184184
this.emit('error', { error: 'Failed to parse plan approval request' });
185185
}

0 commit comments

Comments
 (0)