Skip to content

Commit db901bd

Browse files
ui ws wip
2 parents 6a20981 + ba12990 commit db901bd

File tree

12 files changed

+360
-292
lines changed

12 files changed

+360
-292
lines changed

src/backend/app_kernel.py

Lines changed: 116 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -87,63 +87,6 @@
8787
app.include_router(app_v3)
8888
logging.info("Added health check middleware")
8989

90-
91-
# WebSocket streaming endpoint
92-
# @app.websocket("/ws/streaming")
93-
# async def websocket_endpoint(websocket: WebSocket):
94-
# """WebSocket endpoint for real-time plan execution streaming"""
95-
# await websocket_streaming_endpoint(websocket)
96-
97-
# @app.websocket("/socket/{process_id}")
98-
# async def process_outputs(websocket: WebSocket, process_id: str):
99-
# """ Web-Socket endpoint for real-time process status updates. """
100-
101-
# # Always accept the WebSocket connection first
102-
# await websocket.accept()
103-
# connection_config.add_connection(process_id=process_id, connection=websocket)
104-
105-
@app.websocket("/socket/{process_id}")
106-
async def start_comms(websocket: WebSocket, process_id: str):
107-
""" Web-Socket endpoint for real-time process status updates. """
108-
109-
# Always accept the WebSocket connection first
110-
await websocket.accept()
111-
112-
user_id = None
113-
try:
114-
# WebSocket headers are different, try to get user info
115-
headers = dict(websocket.headers)
116-
authenticated_user = get_authenticated_user_details(request_headers=headers)
117-
user_id = authenticated_user.get("user_principal_id")
118-
if not user_id:
119-
user_id = f"anonymous_{process_id}"
120-
except Exception as e:
121-
logging.warning(f"Could not extract user from WebSocket headers: {e}")
122-
user_id = f"anonymous_{user_id}"
123-
124-
# Add to the connection manager for backend updates
125-
126-
connection_config.add_connection(user_id, websocket)
127-
track_event_if_configured("WebSocketConnectionAccepted", {"process_id": "user_id"})
128-
129-
# Keep the connection open - FastAPI will close the connection if this returns
130-
while True:
131-
# no expectation that we will receive anything from the client but this keeps
132-
# the connection open and does not take cpu cycle
133-
try:
134-
await websocket.receive_text()
135-
except asyncio.TimeoutError:
136-
pass
137-
138-
except WebSocketDisconnect:
139-
track_event_if_configured("WebSocketDisconnect", {"process_id": process_id})
140-
logging.info(f"Client disconnected from batch {process_id}")
141-
await connection_config.close_connection(user_id)
142-
except Exception as e:
143-
logging.error("Error in WebSocket connection", error=str(e))
144-
await connection_config.close_connection(user_id)
145-
146-
14790
@app.post("/api/user_browser_language")
14891
async def user_browser_language_endpoint(user_language: UserLanguage, request: Request):
14992
"""
@@ -176,128 +119,128 @@ async def user_browser_language_endpoint(user_language: UserLanguage, request: R
176119
return {"status": "Language received successfully"}
177120

178121

179-
@app.post("/api/input_task")
180-
async def input_task_endpoint(input_task: InputTask, request: Request):
181-
"""
182-
Receive the initial input task from the user.
183-
"""
184-
# Fix 1: Properly await the async rai_success function
185-
if not await rai_success(input_task.description, True):
186-
print("RAI failed")
187-
188-
track_event_if_configured(
189-
"RAI failed",
190-
{
191-
"status": "Plan not created - RAI validation failed",
192-
"description": input_task.description,
193-
"session_id": input_task.session_id,
194-
},
195-
)
196-
197-
return {
198-
"status": "RAI_VALIDATION_FAILED",
199-
"message": "Content Safety Check Failed",
200-
"detail": "Your request contains content that doesn't meet our safety guidelines. Please modify your request to ensure it's appropriate and try again.",
201-
"suggestions": [
202-
"Remove any potentially harmful, inappropriate, or unsafe content",
203-
"Use more professional and constructive language",
204-
"Focus on legitimate business or educational objectives",
205-
"Ensure your request complies with content policies",
206-
],
207-
}
208-
authenticated_user = get_authenticated_user_details(request_headers=request.headers)
209-
user_id = authenticated_user["user_principal_id"]
210-
211-
if not user_id:
212-
track_event_if_configured(
213-
"UserIdNotFound", {"status_code": 400, "detail": "no user"}
214-
)
215-
raise HTTPException(status_code=400, detail="no user")
216-
217-
# Generate session ID if not provided
218-
if not input_task.session_id:
219-
input_task.session_id = str(uuid.uuid4())
220-
221-
try:
222-
# Create all agents instead of just the planner agent
223-
# This ensures other agents are created first and the planner has access to them
224-
memory_store = await DatabaseFactory.get_database(user_id=user_id)
225-
client = None
226-
try:
227-
client = config.get_ai_project_client()
228-
except Exception as client_exc:
229-
logging.error(f"Error creating AIProjectClient: {client_exc}")
230-
231-
agents = await AgentFactory.create_all_agents(
232-
session_id=input_task.session_id,
233-
user_id=user_id,
234-
memory_store=memory_store,
235-
client=client,
236-
)
237-
238-
group_chat_manager = agents[AgentType.GROUP_CHAT_MANAGER.value]
122+
# @app.post("/api/input_task")
123+
# async def input_task_endpoint(input_task: InputTask, request: Request):
124+
# """
125+
# Receive the initial input task from the user.
126+
# """
127+
# # Fix 1: Properly await the async rai_success function
128+
# if not await rai_success(input_task.description, True):
129+
# print("RAI failed")
130+
131+
# track_event_if_configured(
132+
# "RAI failed",
133+
# {
134+
# "status": "Plan not created - RAI validation failed",
135+
# "description": input_task.description,
136+
# "session_id": input_task.session_id,
137+
# },
138+
# )
239139

240-
# Convert input task to JSON for the kernel function, add user_id here
140+
# return {
141+
# "status": "RAI_VALIDATION_FAILED",
142+
# "message": "Content Safety Check Failed",
143+
# "detail": "Your request contains content that doesn't meet our safety guidelines. Please modify your request to ensure it's appropriate and try again.",
144+
# "suggestions": [
145+
# "Remove any potentially harmful, inappropriate, or unsafe content",
146+
# "Use more professional and constructive language",
147+
# "Focus on legitimate business or educational objectives",
148+
# "Ensure your request complies with content policies",
149+
# ],
150+
# }
151+
# authenticated_user = get_authenticated_user_details(request_headers=request.headers)
152+
# user_id = authenticated_user["user_principal_id"]
241153

242-
# Use the planner to handle the task
243-
await group_chat_manager.handle_input_task(input_task)
154+
# if not user_id:
155+
# track_event_if_configured(
156+
# "UserIdNotFound", {"status_code": 400, "detail": "no user"}
157+
# )
158+
# raise HTTPException(status_code=400, detail="no user")
244159

245-
# Get plan from memory store
246-
plan = await memory_store.get_plan_by_session(input_task.session_id)
160+
# # Generate session ID if not provided
161+
# if not input_task.session_id:
162+
# input_task.session_id = str(uuid.uuid4())
247163

248-
if not plan: # If the plan is not found, raise an error
249-
track_event_if_configured(
250-
"PlanNotFound",
251-
{
252-
"status": "Plan not found",
253-
"session_id": input_task.session_id,
254-
"description": input_task.description,
255-
},
256-
)
257-
raise HTTPException(status_code=404, detail="Plan not found")
258-
# Log custom event for successful input task processing
259-
track_event_if_configured(
260-
"InputTaskProcessed",
261-
{
262-
"status": f"Plan created with ID: {plan.id}",
263-
"session_id": input_task.session_id,
264-
"plan_id": plan.id,
265-
"description": input_task.description,
266-
},
267-
)
268-
if client:
269-
try:
270-
client.close()
271-
except Exception as e:
272-
logging.error(f"Error sending to AIProjectClient: {e}")
273-
return {
274-
"status": f"Plan created with ID: {plan.id}",
275-
"session_id": input_task.session_id,
276-
"plan_id": plan.id,
277-
"description": input_task.description,
278-
}
164+
# try:
165+
# # Create all agents instead of just the planner agent
166+
# # This ensures other agents are created first and the planner has access to them
167+
# memory_store = await DatabaseFactory.get_database(user_id=user_id)
168+
# client = None
169+
# try:
170+
# client = config.get_ai_project_client()
171+
# except Exception as client_exc:
172+
# logging.error(f"Error creating AIProjectClient: {client_exc}")
173+
174+
# agents = await AgentFactory.create_all_agents(
175+
# session_id=input_task.session_id,
176+
# user_id=user_id,
177+
# memory_store=memory_store,
178+
# client=client,
179+
# )
279180

280-
except Exception as e:
281-
# Extract clean error message for rate limit errors
282-
error_msg = str(e)
283-
if "Rate limit is exceeded" in error_msg:
284-
match = re.search(
285-
r"Rate limit is exceeded\. Try again in (\d+) seconds?\.", error_msg
286-
)
287-
if match:
288-
error_msg = "Application temporarily unavailable due to quota limits. Please try again later."
181+
# group_chat_manager = agents[AgentType.GROUP_CHAT_MANAGER.value]
182+
183+
# # Convert input task to JSON for the kernel function, add user_id here
184+
185+
# # Use the planner to handle the task
186+
# await group_chat_manager.handle_input_task(input_task)
187+
188+
# # Get plan from memory store
189+
# plan = await memory_store.get_plan_by_session(input_task.session_id)
190+
191+
# if not plan: # If the plan is not found, raise an error
192+
# track_event_if_configured(
193+
# "PlanNotFound",
194+
# {
195+
# "status": "Plan not found",
196+
# "session_id": input_task.session_id,
197+
# "description": input_task.description,
198+
# },
199+
# )
200+
# raise HTTPException(status_code=404, detail="Plan not found")
201+
# # Log custom event for successful input task processing
202+
# track_event_if_configured(
203+
# "InputTaskProcessed",
204+
# {
205+
# "status": f"Plan created with ID: {plan.id}",
206+
# "session_id": input_task.session_id,
207+
# "plan_id": plan.id,
208+
# "description": input_task.description,
209+
# },
210+
# )
211+
# if client:
212+
# try:
213+
# client.close()
214+
# except Exception as e:
215+
# logging.error(f"Error sending to AIProjectClient: {e}")
216+
# return {
217+
# "status": f"Plan created with ID: {plan.id}",
218+
# "session_id": input_task.session_id,
219+
# "plan_id": plan.id,
220+
# "description": input_task.description,
221+
# }
289222

290-
track_event_if_configured(
291-
"InputTaskError",
292-
{
293-
"session_id": input_task.session_id,
294-
"description": input_task.description,
295-
"error": str(e),
296-
},
297-
)
298-
raise HTTPException(
299-
status_code=400, detail=f"Error creating plan: {error_msg}"
300-
) from e
223+
# except Exception as e:
224+
# # Extract clean error message for rate limit errors
225+
# error_msg = str(e)
226+
# if "Rate limit is exceeded" in error_msg:
227+
# match = re.search(
228+
# r"Rate limit is exceeded\. Try again in (\d+) seconds?\.", error_msg
229+
# )
230+
# if match:
231+
# error_msg = "Application temporarily unavailable due to quota limits. Please try again later."
232+
233+
# track_event_if_configured(
234+
# "InputTaskError",
235+
# {
236+
# "session_id": input_task.session_id,
237+
# "description": input_task.description,
238+
# "error": str(e),
239+
# },
240+
# )
241+
# raise HTTPException(
242+
# status_code=400, detail=f"Error creating plan: {error_msg}"
243+
# ) from e
301244

302245

303246
@app.post("/api/human_feedback")
@@ -783,21 +726,6 @@ async def get_plans(
783726
# list_of_plans_with_steps.append(plan_with_steps)
784727

785728
return []
786-
787-
@app.get("/api/init_team")
788-
async def init_team(
789-
request: Request,
790-
):
791-
""" Initialize the team of agents """
792-
authenticated_user = get_authenticated_user_details(request_headers=request.headers)
793-
user_id = authenticated_user["user_principal_id"]
794-
if not user_id:
795-
track_event_if_configured(
796-
"UserIdNotFound", {"status_code": 400, "detail": "no user"}
797-
)
798-
raise HTTPException(status_code=400, detail="no user")
799-
# Initialize agent team for this user session
800-
await OrchestrationManager.get_current_orchestration(user_id=user_id)
801729

802730
@app.get("/api/steps/{plan_id}", response_model=List[Step])
803731
async def get_steps_by_plan(plan_id: str, request: Request) -> List[Step]:

src/backend/common/database/database_factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import logging
44
from typing import Optional
55

6+
from common.config.app_config import config
7+
68
from .cosmosdb import CosmosDBClient
79
from .database_base import DatabaseBase
8-
from common.config.app_config import config
910

1011

1112
class DatabaseFactory:

src/backend/common/models/messages_kernel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,15 @@ class TeamAgent(KernelBaseModel):
156156
input_key: str
157157
type: str
158158
name: str
159+
deployment_name: str
159160
system_message: str = ""
160161
description: str = ""
161162
icon: str
162163
index_name: str = ""
163164
use_rag: bool = False
164165
use_mcp: bool = False
166+
use_bing: bool = False
167+
use_reasoning: bool = False
165168
coding_tools: bool = False
166169

167170

0 commit comments

Comments
 (0)