Skip to content

Commit 9244519

Browse files
authored
Merge pull request #510 from microsoft/macae-v3-fr-dev-92
Macae v3 fr dev 92
2 parents 520dfb6 + ca51d21 commit 9244519

File tree

7 files changed

+62
-72
lines changed

7 files changed

+62
-72
lines changed

src/backend/v3/api/router.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,7 @@ async def process_request(
235235
)
236236
raise HTTPException(
237237
status_code=400,
238-
detail={
239-
"error_type": "RAI_VALIDATION_FAILED",
240-
"message": "Content Safety Check Failed",
241-
"description": "Your request contains content that doesn't meet our safety guidelines. Please modify your request to ensure it's appropriate and try again.",
242-
"suggestions": [
243-
"Remove any potentially harmful, inappropriate, or unsafe content",
244-
"Use more professional and constructive language",
245-
"Focus on legitimate business or educational objectives",
246-
"Ensure your request complies with content policies",
247-
],
248-
"user_action": "Please revise your request and try again",
249-
},
238+
detail="Request contains content that doesn't meet our safety guidelines, try again.",
250239
)
251240

252241
authenticated_user = get_authenticated_user_details(request_headers=request.headers)
@@ -256,7 +245,7 @@ async def process_request(
256245
track_event_if_configured(
257246
"UserIdNotFound", {"status_code": 400, "detail": "no user"}
258247
)
259-
raise HTTPException(status_code=400, detail="no user")
248+
raise HTTPException(status_code=400, detail="no user found")
260249

261250
# if not input_task.team_id:
262251
# track_event_if_configured(

src/frontend/src/components/content/HomeInput.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,19 @@ const HomeInput: React.FC<HomeInputProps> = ({
114114
dismissToast(id);
115115
}
116116
} catch (error: any) {
117+
console.log("Error creating plan:", error);
118+
let errorMessage = "Unable to create plan. Please try again.";
117119
dismissToast(id);
118120
// Check if this is an RAI validation error
119-
let errorDetail = null;
120121
try {
121-
// Try to parse the error detail if it's a string
122-
if (typeof error?.response?.data?.detail === 'string') {
123-
errorDetail = JSON.parse(error.response.data.detail);
124-
} else {
125-
errorDetail = error?.response?.data?.detail;
126-
}
122+
// errorDetail = JSON.parse(error);
123+
errorMessage = error?.message || errorMessage;
127124
} catch (parseError) {
128-
// If parsing fails, use the original error
129-
errorDetail = error?.response?.data?.detail;
125+
console.error("Error parsing error detail:", parseError);
130126
}
131127

132-
// Handle RAI validation errors - just show description as toast
133-
if (errorDetail?.error_type === 'RAI_VALIDATION_FAILED') {
134-
const description = errorDetail.description ||
135-
"Your request contains content that doesn't meet our safety guidelines. Please try rephrasing.";
136-
showToast(description, "error");
137-
} else {
138-
// Handle other errors with toast messages
139-
const errorMessage = errorDetail?.description ||
140-
errorDetail?.message ||
141-
error?.response?.data?.message ||
142-
error?.message ||
143-
"Something went wrong. Please try again.";
144-
145-
showToast(errorMessage, "error");
146-
}
128+
129+
showToast(errorMessage, "error");
147130
} finally {
148131
setInput("");
149132
setSubmitting(false);

src/frontend/src/components/content/PlanChatBody.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ const PlanChatBody: React.FC<SimplifiedPlanChatProps> = ({
4141
onChange={setInput}
4242
onEnter={() => OnChatSubmit(input)}
4343
disabledChat={submittingChatDisableInput}
44-
placeholder={
45-
waitingForPlan
46-
? "Creating plan..."
47-
: "Type your message here..."
48-
}
44+
placeholder="Type your message here..."
4945
style={{
5046
fontSize: '16px',
5147
borderRadius: '8px',
@@ -68,7 +64,7 @@ const PlanChatBody: React.FC<SimplifiedPlanChatProps> = ({
6864
backgroundColor: 'transparent',
6965
border: 'none',
7066
color: (submittingChatDisableInput || !input.trim())
71-
? 'var(--colorNeutralForegroundDisabled)'
67+
? 'var(--colorNeutralForegroundDisabled)'
7268
: 'var(--colorBrandForeground1)',
7369
flexShrink: 0,
7470
}}

src/frontend/src/components/content/PlanPanelLeft.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ const PlanPanelLeft: React.FC<PlanPanelLefProps> = ({
7979
setUserInfo(getUserInfoGlobal());
8080
}, [loadPlansData, setUserInfo]);
8181

82+
83+
useEffect(() => {
84+
console.log("Reload tasks changed:", reloadTasks);
85+
if (reloadTasks) {
86+
loadPlansData();
87+
}
88+
}, [loadPlansData, setUserInfo, reloadTasks]);
8289
useEffect(() => {
8390
if (plans) {
8491
const { inProgress, completed } =
@@ -215,7 +222,7 @@ const PlanPanelLeft: React.FC<PlanPanelLefProps> = ({
215222
<div style={{ display: 'flex', flexDirection: 'column', gap: '12px', width: '100%' }}>
216223
{/* User Card */}
217224
<PanelUserCard
218-
name={userInfo ? userInfo.user_first_last_name : "Guest"}
225+
name={userInfo?.user_first_last_name || "Guest"}
219226
// alias={userInfo ? userInfo.user_email : ""}
220227
size={32}
221228
/>

src/frontend/src/pages/PlanPage.tsx

Lines changed: 22 additions & 3 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, WebsocketMessageType, MPlanData, AgentMessageData, AgentMessageType, ParsedUserClarification, AgentType, PlanStatus, FinalMessage } from "../models";
5+
import { ProcessedPlanData, WebsocketMessageType, MPlanData, AgentMessageData, AgentMessageType, ParsedUserClarification, AgentType, PlanStatus, FinalMessage, TeamConfig } from "../models";
66
import PlanChat from "../components/content/PlanChat";
77
import PlanPanelRight from "../components/content/PlanPanelRight";
88
import PlanPanelLeft from "../components/content/PlanPanelLeft";
@@ -48,6 +48,7 @@ const PlanPage: React.FC = () => {
4848
const [showProcessingPlanSpinner, setShowProcessingPlanSpinner] = useState<boolean>(false);
4949
const [showApprovalButtons, setShowApprovalButtons] = useState<boolean>(true);
5050
const [continueWithWebsocketFlow, setContinueWithWebsocketFlow] = useState<boolean>(false);
51+
const [selectedTeam, setSelectedTeam] = useState<TeamConfig | null>(null);
5152
// WebSocket connection state
5253
const [wsConnected, setWsConnected] = useState<boolean>(false);
5354
const [streamingMessages, setStreamingMessages] = useState<StreamingPlanUpdate[]>([]);
@@ -261,6 +262,7 @@ const PlanPage: React.FC = () => {
261262
setShowBufferingText(true);
262263
setShowProcessingPlanSpinner(false);
263264
setAgentMessages(prev => [...prev, agentMessageData]);
265+
setSelectedTeam(planData?.team || null);
264266
scrollToBottom();
265267
// Persist the agent message
266268
const is_final = true;
@@ -270,13 +272,19 @@ const PlanPage: React.FC = () => {
270272
}
271273

272274
processAgentMessage(agentMessageData, planData, is_final, streamingMessageBuffer);
275+
276+
setTimeout(() => {
277+
console.log('✅ Plan completed, refreshing left list');
278+
setReloadLeftList(true);
279+
}, 1000);
280+
273281
}
274282

275283

276284
});
277285

278286
return () => unsubscribe();
279-
}, [scrollToBottom, planData, processAgentMessage, streamingMessageBuffer]);
287+
}, [scrollToBottom, planData, processAgentMessage, streamingMessageBuffer, setSelectedTeam, setReloadLeftList]);
280288

281289
//WebsocketMessageType.AGENT_MESSAGE
282290
useEffect(() => {
@@ -409,6 +417,8 @@ const PlanPage: React.FC = () => {
409417
return planResult;
410418
} catch (err) {
411419
console.log("Failed to load plan data:", err);
420+
setErrorLoading(true);
421+
setPlanData(null);
412422
return null;
413423
} finally {
414424
setLoading(false);
@@ -564,6 +574,15 @@ const PlanPage: React.FC = () => {
564574
return (
565575
<CoralShellColumn>
566576
<CoralShellRow>
577+
<PlanPanelLeft
578+
reloadTasks={reloadLeftList}
579+
onNewTaskButton={handleNewTaskButton}
580+
restReload={resetReload}
581+
onTeamSelect={() => { }}
582+
onTeamUpload={async () => { }}
583+
isHomePage={false}
584+
selectedTeam={selectedTeam}
585+
/>
567586
<Content>
568587
<div style={{
569588
textAlign: "center",
@@ -591,7 +610,7 @@ const PlanPage: React.FC = () => {
591610
onTeamSelect={() => { }}
592611
onTeamUpload={async () => { }}
593612
isHomePage={false}
594-
selectedTeam={null}
613+
selectedTeam={selectedTeam}
595614
/>
596615

597616
<Content>

src/frontend/src/services/PlanDataService.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -893,16 +893,30 @@ export class PlanDataService {
893893
}
894894

895895
// Capture the inside of UserClarificationResponse(...)
896-
const outerMatch = line.match(/Human clarification:\s*UserClarificationResponse\((.*?)\)/s);
896+
const outerMatch = line.match(/Human clarification:\s*UserClarificationResponse\((.*)\)$/s);
897897
if (!outerMatch) return line;
898898

899899
const inner = outerMatch[1];
900900

901-
// Find answer= '...' | "..."
902-
const answerMatch = inner.match(/answer=(?:"((?:\\.|[^"])*)"|'((?:\\.|[^'])*)')/);
903-
if (!answerMatch) return line;
901+
// Find answer= '...' | "..." - Updated regex to handle the full content properly
902+
const answerMatch = inner.match(/answer='([^']*(?:''[^']*)*)'/);
903+
if (!answerMatch) {
904+
// Try double quotes if single quotes don't work
905+
const doubleQuoteMatch = inner.match(/answer="([^"]*(?:""[^"]*)*)"/);
906+
if (!doubleQuoteMatch) return line;
904907

905-
let answer = answerMatch[1] ?? answerMatch[2] ?? '';
908+
let answer = doubleQuoteMatch[1];
909+
answer = answer
910+
.replace(/\\n/g, '\n')
911+
.replace(/\\'/g, "'")
912+
.replace(/\\"/g, '"')
913+
.replace(/\\\\/g, '\\')
914+
.trim();
915+
916+
return `Human clarification: ${answer}`;
917+
}
918+
919+
let answer = answerMatch[1];
906920
// Unescape common sequences
907921
answer = answer
908922
.replace(/\\n/g, '\n')

src/frontend/src/services/TaskService.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,28 +195,10 @@ export class TaskService {
195195
try {
196196
return await apiService.createPlan(inputTask);
197197
} catch (error: any) {
198+
198199
// You can customize this logic as needed
199200
let message = "Unable to create plan. Please try again.";
200-
if (error?.response?.data?.detail) {
201-
const detail = error.response.data.detail;
202-
if (typeof detail === 'string' && detail.includes('RAI_VALIDATION_FAILED')) {
203-
message = "Your request contains content that doesn't meet our safety guidelines. Please rephrase and try again.";
204-
} else if (detail.includes('quota') || detail.includes('limit')) {
205-
message = "Service is currently at capacity. Please try again in a few minutes.";
206-
} else if (detail.includes('unauthorized') || detail.includes('forbidden')) {
207-
message = "You don't have permission to create plans. Please contact your administrator.";
208-
} else {
209-
message = detail;
210-
}
211-
} else if (error?.response?.data?.message) {
212-
message = error.response.data.message;
213-
} else if (error?.message) {
214-
if (error.message.includes('Network Error') || error.message.includes('fetch')) {
215-
message = "Network error. Please check your connection and try again.";
216-
} else {
217-
message = error.message;
218-
}
219-
}
201+
220202
throw new Error(message);
221203
}
222204
}

0 commit comments

Comments
 (0)