AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Merge commit from fork
Reinier van der Leer309114a727ba
diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.pyindex e2a8abb295..8fd910ebf4 100644--- a/autogpt_platform/backend/backend/data/execution.py+++ b/autogpt_platform/backend/backend/data/execution.py@@ -372,6 +372,7 @@ async def get_graph_executions(created_time_lte: datetime | None = None,limit: int | None = None,) -> list[GraphExecutionMeta]:+ """⚠️ **Optional `user_id` check**: MUST USE check in user-facing endpoints."""where_filter: AgentGraphExecutionWhereInput = {"isDeleted": False,}@@ -737,6 +738,7 @@ async def delete_graph_execution(async def get_node_execution(node_exec_id: str) -> NodeExecutionResult | None:+ """⚠️ No `user_id` check: DO NOT USE without check in user-facing endpoints."""execution = await AgentNodeExecution.prisma().find_first(where={"id": node_exec_id},include=EXECUTION_RESULT_INCLUDE,@@ -756,6 +758,7 @@ async def get_node_executions(created_time_lte: datetime | None = None,include_exec_data: bool = True,) -> list[NodeExecutionResult]:+ """⚠️ No `user_id` check: DO NOT USE without check in user-facing endpoints."""where_clause: AgentNodeExecutionWhereInput = {}if graph_exec_id:where_clause["agentGraphExecutionId"] = graph_exec_id@@ -789,6 +792,7 @@ async def get_node_executions(async def get_latest_node_execution(node_id: str, graph_eid: str) -> NodeExecutionResult | None:+ """⚠️ No `user_id` check: DO NOT USE without check in user-facing endpoints."""execution = await AgentNodeExecution.prisma().find_first(where={"agentGraphExecutionId": graph_eid,diff --git a/autogpt_platform/backend/backend/server/external/routes/v1.py b/autogpt_platform/backend/backend/server/external/routes/v1.pyindex baf77c0e75..5d8d366f77 100644--- a/autogpt_platform/backend/backend/server/external/routes/v1.py+++ b/autogpt_platform/backend/backend/server/external/routes/v1.py@@ -1,6 +1,6 @@import loggingfrom collections import defaultdict-from typing import Annotated, Any, Dict, List, Optional, Sequence+from typing import Annotated, Any, Optional, Sequencefrom fastapi import APIRouter, Body, Depends, HTTPExceptionfrom prisma.enums import AgentExecutionStatus, APIKeyPermission@@ -11,7 +11,6 @@ from backend.data import execution as execution_dbfrom backend.data import graph as graph_dbfrom backend.data.api_key import APIKeyfrom backend.data.block import BlockInput, CompletedBlockOutput-from backend.data.execution import NodeExecutionResultfrom backend.executor.utils import add_graph_executionfrom backend.server.external.middleware import require_permissionfrom backend.util.settings import Settings@@ -30,30 +29,19 @@ class NodeOutput(TypedDict):class ExecutionNode(TypedDict):node_id: strinput: Any- output: Dict[str, Any]+ output: dict[str, Any]class ExecutionNodeOutput(TypedDict):node_id: str- outputs: List[NodeOutput]+ outputs: list[NodeOutput]class GraphExecutionResult(TypedDict):execution_id: strstatus: str- nodes: List[ExecutionNode]- output: Optional[List[Dict[str, str]]]---def get_outputs_with_names(results: list[NodeExecutionResult]) -> list[dict[str, str]]:- outputs = []- for result in results:- if "output" in result.output_data:- output_value = result.output_data["output"][0]- name = result.output_data.get("name", [None])[0]- if output_value and name:- outputs.append({name: output_value})- return outputs+ nodes: list[ExecutionNode]+ output: Optional[list[dict[str, str]]]@v1_router.get(@@ -122,23 +110,34 @@ async def get_graph_execution_results(if not graph:raise HTTPException(status_code=404, detail=f"Graph #{graph_id} not found.")- results = await execution_db.get_node_executions(graph_exec_id)- last_result = results[-1] if results else None- execution_status = (- last_result.status if last_result else AgentExecutionStatus.INCOMPLETE+ graph_exec = await execution_db.get_graph_execution(+ user_id=api_key.user_id,+ execution_id=graph_exec_id,+ include_node_executions=True,)- outputs = get_outputs_with_names(results)+ if not graph_exec:+ raise HTTPException(+ status_code=404, detail=f"Graph execution #{graph_exec_id} not found."+ )return GraphExecutionResult(execution_id=graph_exec_id,- status=execution_status,+ status=graph_exec.status.value,nodes=[ExecutionNode(- node_id=result.node_id,- input=result.input_data.get("value", result.input_data),- output={k: v for k, v in result.output_data.items()},+ node_id=node_exec.node_id,+ input=node_exec.input_data.get("value", node_exec.input_data),+ output={k: v for k, v in node_exec.output_data.items()},)- for result in results+ for node_exec in graph_exec.node_executions],- output=outputs if execution_status == AgentExecutionStatus.COMPLETED else None,+ output=(+ [+ {name: value}+ for name, values in graph_exec.outputs.items()+ for value in values+ ]+ if graph_exec.status == AgentExecutionStatus.COMPLETED+ else None+ ),)diff --git a/autogpt_platform/backend/backend/server/routers/v1.py b/autogpt_platform/backend/backend/server/routers/v1.pyindex 2fb5e6a857..933ad64d3a 100644--- a/autogpt_platform/backend/backend/server/routers/v1.py+++ b/autogpt_platform/backend/backend/server/routers/v1.py@@ -680,22 +680,6 @@ async def stop_graph_run(return res[0]-@v1_router.post(- path="/executions",- summary="Stop graph executions",- tags=["graphs"],- dependencies=[Depends(auth_middleware)],-)-async def stop_graph_runs(- graph_id: str, graph_exec_id: str, user_id: Annotated[str, Depends(get_user_id)]-) -> list[execution_db.GraphExecutionMeta]:- return await _stop_graph_run(- user_id=user_id,- graph_id=graph_id,- graph_exec_id=graph_exec_id,- )--async def _stop_graph_run(user_id: str,graph_id: Optional[str] = None,