Skip to content

Commit d750021

Browse files
committed
Add WebSocket job status endpoint and update team config
Introduces a WebSocket endpoint in the backend for job status updates, enabling real-time plan approval and rejection. Updates the default_team.json to include a new 'use_bing' property for agents. Refactors HomePage.tsx to use InlineToaster for team selection and upload notifications, improving user feedback.
1 parent 963c782 commit d750021

File tree

3 files changed

+65
-47
lines changed

3 files changed

+65
-47
lines changed

data/agent_teams/default_team.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"index_name": "",
1818
"use_rag": false,
1919
"use_mcp": false,
20-
"coding_tools": false
20+
"coding_tools": false,
21+
"use_bing": false
2122
},
2223
{
2324
"input_key": "tech-support-001",
@@ -30,7 +31,8 @@
3031
"index_name": "",
3132
"use_rag": false,
3233
"use_mcp": false,
33-
"coding_tools": false
34+
"coding_tools": false,
35+
"use_bing": false
3436
},
3537
{
3638
"input_key": "procurement-001",
@@ -43,7 +45,8 @@
4345
"index_name": "",
4446
"use_rag": false,
4547
"use_mcp": false,
46-
"coding_tools": false
48+
"coding_tools": false,
49+
"use_bing": false
4750
},
4851
{
4952
"input_key": "marketing-001",
@@ -56,7 +59,8 @@
5659
"index_name": "",
5760
"use_rag": false,
5861
"use_mcp": false,
59-
"coding_tools": false
62+
"coding_tools": false,
63+
"use_bing": false
6064
},
6165
{
6266
"input_key": "generic-001",
@@ -69,7 +73,8 @@
6973
"index_name": "",
7074
"use_rag": false,
7175
"use_mcp": false,
72-
"coding_tools": false
76+
"coding_tools": false,
77+
"use_bing": false
7378
}
7479
],
7580
"description": "Business Operations team handles employee onboarding, telecommunications support, procurement, and marketing tasks for comprehensive business operations management.",

src/backend/v3/api/router.py

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,24 @@
55
from auth.auth_utils import get_authenticated_user_details
66
from common.config.app_config import config
77
from common.database.database_factory import DatabaseFactory
8-
from common.models.messages_kernel import (GeneratePlanRequest, InputTask,
9-
Plan, PlanStatus)
8+
from common.models.messages_kernel import (
9+
GeneratePlanRequest,
10+
InputTask,
11+
Plan,
12+
PlanStatus,
13+
)
1014
from common.utils.event_utils import track_event_if_configured
1115
from common.utils.utils_kernel import rai_success, rai_validate_team_config
12-
from fastapi import (APIRouter, Depends, File, HTTPException, Request,
13-
UploadFile)
16+
from fastapi import (
17+
APIRouter,
18+
Depends,
19+
File,
20+
HTTPException,
21+
Request,
22+
UploadFile,
23+
WebSocket,
24+
WebSocketDisconnect,
25+
)
1426
from kernel_agents.agent_factory import AgentFactory
1527
from semantic_kernel.agents.runtime import InProcessRuntime
1628
from v3.common.services.team_service import TeamService
@@ -23,6 +35,7 @@
2335
responses={404: {"description": "Not found"}},
2436
)
2537

38+
2639
# To do: change endpoint to process request
2740
@app_v3.post("/create_plan")
2841
async def process_request(input_task: InputTask, request: Request):
@@ -135,13 +148,17 @@ async def process_request(input_task: InputTask, request: Request):
135148
# )
136149

137150
# setup and call the magentic orchestration
138-
magentic_orchestration = await orchestration_config.get_current_orchestration(user_id)
151+
magentic_orchestration = await orchestration_config.get_current_orchestration(
152+
user_id
153+
)
139154

140155
runtime = InProcessRuntime()
141156
runtime.start()
142157

143158
# invoke returns immediately, wait on result.get
144-
orchestration_result = await magentic_orchestration.invoke(task=input_task.description,runtime=runtime)
159+
orchestration_result = await magentic_orchestration.invoke(
160+
task=input_task.description, runtime=runtime
161+
)
145162
team_result = await orchestration_result.get()
146163

147164
# Save the plan to the database
@@ -637,3 +654,28 @@ async def get_search_indexes_endpoint(request: Request):
637654
except Exception as e:
638655
logging.error(f"Error retrieving search indexes: {str(e)}")
639656
raise HTTPException(status_code=500, detail="Internal server error occurred")
657+
658+
659+
# WebSocket endpoint for job status updates
660+
plans = {} # job_id -> current plan
661+
approvals = {} # job_id -> True/False/None
662+
sockets = {} # job_id -> WebSocket
663+
664+
665+
@app_v3.websocket("/ws/{job_id}")
666+
async def ws(job_id: str, websocket: WebSocket):
667+
await websocket.accept()
668+
sockets[job_id] = websocket
669+
try:
670+
if job_id in plans:
671+
await websocket.send_json({"type": "plan_ready", "plan": plans[job_id]})
672+
while True:
673+
msg = await websocket.receive_json()
674+
if msg.get("type") == "approve":
675+
approvals[job_id] = True
676+
await websocket.send_json({"type": "ack", "message": "approved"})
677+
elif msg.get("type") == "reject":
678+
approvals[job_id] = False
679+
await websocket.send_json({"type": "ack", "message": "rejected"})
680+
except WebSocketDisconnect:
681+
sockets.pop(job_id, None)

src/frontend/src/pages/HomePage.tsx

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import ContentToolbar from '@/coral/components/Content/ContentToolbar';
2525
import { TaskService } from '../services/TaskService';
2626
import { TeamConfig } from '../models/Team';
2727
import { TeamService } from '../services/TeamService';
28-
28+
import InlineToaster, { useInlineToaster } from "../components/toast/InlineToaster";
2929
/**
3030
* HomePage component - displays task lists and provides navigation
3131
* Accessible via the route "/"
@@ -35,7 +35,7 @@ const HomePage: React.FC = () => {
3535
const { dispatchToast } = useToastController("toast");
3636
const [selectedTeam, setSelectedTeam] = useState<TeamConfig | null>(null);
3737
const [isLoadingTeam, setIsLoadingTeam] = useState(true);
38-
38+
const { showToast, dismissToast } = useInlineToaster();
3939
/**
4040
* Load teams and set default team on component mount
4141
*/
@@ -91,31 +91,11 @@ const HomePage: React.FC = () => {
9191
const handleTeamSelect = useCallback((team: TeamConfig | null) => {
9292
setSelectedTeam(team);
9393
if (team) {
94-
95-
showToast(`{team.name} team has been selected with {team.agents.length} agents`, "success");
96-
// dispatchToast(
97-
// <Toast>
98-
// <ToastTitle>Team Selected</ToastTitle>
99-
// <ToastBody>
100-
// {team.name} team has been selected with {team.agents.length} agents
101-
// </ToastBody>
102-
// </Toast>,
103-
// { intent: "success" }
104-
// );
94+
showToast(`${team.name} team has been selected with ${team.agents.length} agents`, "success");
10595
} else {
106-
10796
showToast(`No team is currently selected`, "info");
108-
// dispatchToast(
109-
// <Toast>
110-
// <ToastTitle>Team Deselected</ToastTitle>
111-
// <ToastBody>
112-
// No team is currently selected
113-
// </ToastBody>
114-
// </Toast>,
115-
// { intent: "info" }
116-
// );
11797
}
118-
}, [dispatchToast]);
98+
}, [showToast]);
11999

120100
/**
121101
* Handle team upload completion - refresh team list and keep Business Operations Team as default
@@ -132,22 +112,13 @@ const HomePage: React.FC = () => {
132112
setSelectedTeam(defaultTeam);
133113
console.log('Default team after upload:', defaultTeam.name);
134114
console.log('Business Operations Team remains default');
135-
showToast(`Team uploaded. {defaultTeam.name} remains your default team.`, "success");
136-
// Show a toast notification about the upload success
137-
// dispatchToast(
138-
// <Toast>
139-
// <ToastTitle>Team Uploaded Successfully!</ToastTitle>
140-
// <ToastBody>
141-
// Team uploaded. {defaultTeam.name} remains your default team.
142-
// </ToastBody>
143-
// </Toast>,
144-
// { intent: "success" }
145-
// );
115+
showToast(`Team uploaded. ${defaultTeam.name} remains your default team.`, "success");
116+
146117
}
147118
} catch (error) {
148119
console.error('Error refreshing teams after upload:', error);
149120
}
150-
}, [dispatchToast]);
121+
}, [showToast]);
151122

152123

153124
return (

0 commit comments

Comments
 (0)