refactor(api): remove JSON-RPC method verification from task handling endpoints

This commit is contained in:
Davidson Gomes 2025-04-29 20:48:19 -03:00
parent 465efc6936
commit 16ef6fcc63

View File

@ -229,18 +229,6 @@ async def handle_task(
): ):
"""Endpoint to clients A2A send a new task (with an initial user message).""" """Endpoint to clients A2A send a new task (with an initial user message)."""
try: try:
# Verify JSON-RPC method
if request.method != "tasks/send":
return {
"jsonrpc": "2.0",
"id": request.id,
"error": {
"code": -32601,
"message": "Method not found",
"data": {"detail": f"Method '{request.method}' not found"},
},
}
# Verify agent # Verify agent
agent = agent_service.get_agent(db, agent_id) agent = agent_service.get_agent(db, agent_id)
if agent is None: if agent is None:
@ -253,10 +241,11 @@ async def handle_task(
# Verify API key # Verify API key
agent_config = agent.config agent_config = agent.config
if agent_config.get("api_key") != x_api_key: if agent_config.get("api_key") != x_api_key:
raise HTTPException( return {
status_code=status.HTTP_401_UNAUTHORIZED, "jsonrpc": "2.0",
detail="Invalid API key for this agent", "id": request.id,
) "error": {"code": 401, "message": "Invalid API key", "data": None},
}
# Extract task request from JSON-RPC params # Extract task request from JSON-RPC params
task_request = request.params task_request = request.params
@ -497,18 +486,6 @@ async def subscribe_task_streaming(
Returns: Returns:
StreamingResponse com eventos SSE StreamingResponse com eventos SSE
""" """
# Verify JSON-RPC method
if request.method != "tasks/sendSubscribe":
return {
"jsonrpc": "2.0",
"id": request.id,
"error": {
"code": -32601,
"message": "Method not found",
"data": {"detail": f"Method '{request.method}' not found"},
},
}
if not x_api_key: if not x_api_key:
return { return {
"jsonrpc": "2.0", "jsonrpc": "2.0",