Skip to content

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.

refactor(backend): give the four colliding response models unambiguous names (#14481)

Reinier van der Leerfa098cfc9b24
diff --git a/autogpt_platform/backend/backend/api/features/blocks/routes.py b/autogpt_platform/backend/backend/api/features/blocks/routes.py
index 4f69d88179..e20abc5fe7 100644
--- a/autogpt_platform/backend/backend/api/features/blocks/routes.py
+++ b/autogpt_platform/backend/backend/api/features/blocks/routes.py
@@ -18,7 +18,7 @@ from fastapi.concurrency import run_in_threadpool
from pydantic import BaseModel
from starlette.status import HTTP_402_PAYMENT_REQUIRED
-from backend.api.model import UploadFileResponse
+from backend.api.model import CloudStorageUploadResponse
from backend.blocks import get_block, get_blocks
from backend.copilot.rate_limit import enforce_payment_paywall
from backend.data.block import BlockInput, CompletedBlockOutput
@@ -181,7 +181,7 @@ async def upload_file(
ctx: Annotated[RequestContext, Security(get_request_context)],
file: UploadFile = File(...),
expiration_hours: int = 24,
-) -> UploadFileResponse:
+) -> CloudStorageUploadResponse:
"""
Upload a file to cloud storage and return a storage key that can be used
with FileStoreBlock and AgentFileInputBlock.
@@ -229,7 +229,7 @@ async def upload_file(
base64_content = base64.b64encode(content).decode("utf-8")
data_uri = f"data:{content_type};base64,{base64_content}"
- return UploadFileResponse(
+ return CloudStorageUploadResponse(
file_uri=data_uri,
file_name=file_name,
size=content_size,
@@ -245,7 +245,7 @@ async def upload_file(
user_id=user_id,
)
- return UploadFileResponse(
+ return CloudStorageUploadResponse(
file_uri=storage_path,
file_name=file_name,
size=content_size,
diff --git a/autogpt_platform/backend/backend/api/features/chat/share.py b/autogpt_platform/backend/backend/api/features/chat/share.py
index 60f7c5dfcc..c4fa1b8401 100644
--- a/autogpt_platform/backend/backend/api/features/chat/share.py
+++ b/autogpt_platform/backend/backend/api/features/chat/share.py
@@ -70,7 +70,7 @@ class EnableShareRequest(BaseModel):
auto_share_executions: bool = False
-class ShareResponse(BaseModel):
+class ChatShareResponse(BaseModel):
share_url: str
share_token: str
@@ -107,7 +107,7 @@ async def enable_chat_sharing(
session_id: Annotated[str, Path],
user_id: Annotated[str, Security(auth.get_user_id)],
body: EnableShareRequest = Body(default_factory=EnableShareRequest),
-) -> ShareResponse:
+) -> ChatShareResponse:
"""Enable sharing for a chat session.
Flag-gated: refuses with 403 when ``chat-sharing`` is off so a stale
@@ -136,7 +136,7 @@ async def enable_chat_sharing(
except ValueError as exc:
raise HTTPException(status_code=404, detail=str(exc))
- return ShareResponse(
+ return ChatShareResponse(
share_url=f"{base_url}/share/chat/{share_token}",
share_token=share_token,
)
diff --git a/autogpt_platform/backend/backend/api/features/graph_executions/model.py b/autogpt_platform/backend/backend/api/features/graph_executions/model.py
index c1a7b6b9f6..5eeb84481b 100644
--- a/autogpt_platform/backend/backend/api/features/graph_executions/model.py
+++ b/autogpt_platform/backend/backend/api/features/graph_executions/model.py
@@ -1,13 +1,13 @@
import pydantic
-class ShareRequest(pydantic.BaseModel):
+class ExecutionShareRequest(pydantic.BaseModel):
"""Optional request body for share endpoint."""
pass # Empty body is fine
-class ShareResponse(pydantic.BaseModel):
+class ExecutionShareResponse(pydantic.BaseModel):
"""Response from share endpoints."""
share_url: str
diff --git a/autogpt_platform/backend/backend/api/features/graph_executions/routes.py b/autogpt_platform/backend/backend/api/features/graph_executions/routes.py
index c958da7680..813b1d1102 100644
--- a/autogpt_platform/backend/backend/api/features/graph_executions/routes.py
+++ b/autogpt_platform/backend/backend/api/features/graph_executions/routes.py
@@ -11,7 +11,10 @@ from backend.api.features.graph_executions.activity_gate import (
hide_activity_summaries_if_disabled,
hide_activity_summary_if_disabled,
)
-from backend.api.features.graph_executions.model import ShareRequest, ShareResponse
+from backend.api.features.graph_executions.model import (
+ ExecutionShareRequest,
+ ExecutionShareResponse,
+)
from backend.api.features.workspace.routes import create_file_download_response
from backend.data import execution as execution_db
from backend.data import graph as graph_db
@@ -252,8 +255,8 @@ async def enable_execution_sharing(
graph_exec_id: Annotated[str, Path],
user_id: Annotated[str, Security(get_user_id)],
ctx: Annotated[RequestContext, Security(get_request_context)],
- _body: ShareRequest = Body(default=ShareRequest()),
-) -> ShareResponse:
+ _body: ExecutionShareRequest = Body(default=ExecutionShareRequest()),
+) -> ExecutionShareResponse:
"""Enable sharing for a graph execution."""
# Verify the execution belongs to the user
execution = await execution_db.get_graph_execution(
@@ -296,7 +299,7 @@ async def enable_execution_sharing(
frontend_url = settings.config.frontend_base_url or "http://localhost:3000"
share_url = f"{frontend_url}/share/{share_token}"
- return ShareResponse(share_url=share_url, share_token=share_token)
+ return ExecutionShareResponse(share_url=share_url, share_token=share_token)
@router.delete(
diff --git a/autogpt_platform/backend/backend/api/features/user/routes_test.py b/autogpt_platform/backend/backend/api/features/user/routes_test.py
index 4d6805f5dd..5ac2387f1d 100644
--- a/autogpt_platform/backend/backend/api/features/user/routes_test.py
+++ b/autogpt_platform/backend/backend/api/features/user/routes_test.py
@@ -6,36 +6,15 @@ import fastapi
import fastapi.testclient
import pytest
import pytest_mock
-from autogpt_libs.auth.models import RequestContext
from fastapi.routing import APIRoute
from pytest_snapshot.plugin import Snapshot
from backend.api.rest_api import app as real_app
-from backend.api.rest_api import handle_internal_http_error
-from backend.integrations.webhooks.graph_lifecycle_hooks import GraphActivationError
from .routes import router
-
-def _test_ctx(user_id: str) -> RequestContext:
- return RequestContext(
- user_id=user_id,
- org_id="test-org",
- team_id="test-workspace",
- is_org_owner=True,
- is_org_admin=True,
- is_org_billing_manager=False,
- is_team_admin=True,
- is_team_billing_manager=False,
- seat_status="ACTIVE",
- )
-
-
app = fastapi.FastAPI()
app.include_router(router)
-# Mirror rest_api.py's GraphActivationError → 400 mapping so the atomicity
-# tests below verify the same behaviour the real app exposes.
-app.add_exception_handler(GraphActivationError, handle_internal_http_error(400))
client = fastapi.testclient.TestClient(app)
diff --git a/autogpt_platform/backend/backend/api/features/workspace/routes.py b/autogpt_platform/backend/backend/api/features/workspace/routes.py
index 545c169566..69456fded4 100644
--- a/autogpt_platform/backend/backend/api/features/workspace/routes.py
+++ b/autogpt_platform/backend/backend/api/features/workspace/routes.py
@@ -132,7 +132,7 @@ async def create_file_download_response(
raise
-class UploadFileResponse(BaseModel):
+class WorkspaceFileUploadResponse(BaseModel):
file_id: str
name: str
path: str
@@ -316,7 +316,7 @@ async def upload_file(
file: UploadFile,
session_id: str | None = Query(default=None),
overwrite: bool = Query(default=False),
-) -> UploadFileResponse:
+) -> WorkspaceFileUploadResponse:
"""
Upload a file to the user's workspace.
@@ -391,7 +391,7 @@ async def upload_file(
),
)
- return UploadFileResponse(
+ return WorkspaceFileUploadResponse(
file_id=workspace_file.id,
name=workspace_file.name,
path=workspace_file.path,
diff --git a/autogpt_platform/backend/backend/api/model.py b/autogpt_platform/backend/backend/api/model.py
index ad247fb2e3..b69340cc44 100644
--- a/autogpt_platform/backend/backend/api/model.py
+++ b/autogpt_platform/backend/backend/api/model.py
@@ -52,7 +52,7 @@ class RequestTopUp(pydantic.BaseModel):
credit_amount: int
-class UploadFileResponse(pydantic.BaseModel):
+class CloudStorageUploadResponse(pydantic.BaseModel):
file_uri: str
file_name: str
size: int
diff --git a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/ShareRunButton/useShareRunButton.ts b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/ShareRunButton/useShareRunButton.ts
index f39dd56b26..d719299033 100644
--- a/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/ShareRunButton/useShareRunButton.ts
+++ b/autogpt_platform/frontend/src/app/(platform)/library/agents/[id]/components/NewAgentLibraryView/components/selected-views/ShareRunButton/useShareRunButton.ts
@@ -44,7 +44,7 @@ export function useShareRunButton({
const response = await enableSharing({
graphId,
graphExecId: executionId,
- data: {}, // Empty ShareRequest
+ data: {}, // Empty ExecutionShareRequest
});
if (response.status === 200) {
diff --git a/autogpt_platform/frontend/src/app/api/openapi.json b/autogpt_platform/frontend/src/app/api/openapi.json
index 6231c622cc..03194fa706 100644
--- a/autogpt_platform/frontend/src/app/api/openapi.json
+++ b/autogpt_platform/frontend/src/app/api/openapi.json
@@ -4605,9 +4605,7 @@
"description": "Successful Response",
"content": {
"application/json": {
- "schema": {
- "$ref": "#/components/schemas/backend__api__features__chat__share__ShareResponse"
- }
+ "schema": { "$ref": "#/components/schemas/ChatShareResponse" }
}
}
},
@@ -7609,7 +7607,7 @@
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/backend__api__model__UploadFileResponse"
+ "$ref": "#/components/schemas/CloudStorageUploadResponse"
}
}
}
@@ -8065,7 +8063,7 @@
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/ShareRequest",
+ "$ref": "#/components/schemas/ExecutionShareRequest",
"default": {}
}
}
@@ -8077,7 +8075,7 @@
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/backend__api__features__graph_executions__model__ShareResponse"
+ "$ref": "#/components/schemas/ExecutionShareResponse"
}
}
}
@@ -16341,7 +16339,7 @@
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/backend__api__features__workspace__routes__UploadFileResponse"
+ "$ref": "#/components/schemas/WorkspaceFileUploadResponse"
}
}
}
@@ -18852,6 +18850,15 @@
"title": "ChatSessionMetadata",
"description": "Typed metadata stored in the ``metadata`` JSON column of ChatSession.\n\nAdd new session-level flags here instead of adding DB columns —\nno migration required for new fields as long as a default is provided."
},
+ "ChatShareResponse": {
+ "properties": {
+ "share_url": { "type": "string", "title": "Share Url" },
+ "share_token": { "type": "string", "title": "Share Token" }
+ },
+ "type": "object",
+ "required": ["share_url", "share_token"],
+ "title": "ChatShareResponse"
+ },
"ChatShareStateResponse": {
"properties": {
"is_shared": {
@@ -18966,6 +18973,24 @@
"title": "ClarifyingQuestion",
"description": "A question that needs user clarification."
},
+ "CloudStorageUploadResponse": {
+ "properties": {
+ "file_uri": { "type": "string", "title": "File Uri" },
+ "file_name": { "type": "string", "title": "File Name" },
+ "size": { "type": "integer", "title": "Size" },
+ "content_type": { "type": "string", "title": "Content Type" },
+ "expires_in_hours": { "type": "integer", "title": "Expires In Hours" }
+ },
+ "type": "object",
+ "required": [
+ "file_uri",
+ "file_name",
+ "size",
+ "content_type",
+ "expires_in_hours"
+ ],
+ "title": "CloudStorageUploadResponse"
+ },
"CoPilotUsagePublic": {
"properties": {
"daily": {
@@ -21296,6 +21321,22 @@
"title": "ExecutionOutputInfo",
"description": "Summary of a single execution's outputs."
},
+ "ExecutionShareRequest": {
+ "properties": {},
+ "type": "object",
+ "title": "ExecutionShareRequest",
+ "description": "Optional request body for share endpoint."
+ },
+ "ExecutionShareResponse": {
+ "properties": {
+ "share_url": { "type": "string", "title": "Share Url" },
+ "share_token": { "type": "string", "title": "Share Token" }
+ },
+ "type": "object",
+ "required": ["share_url", "share_token"],
+ "title": "ExecutionShareResponse",
+ "description": "Response from share endpoints."
+ },
"ExecutionStartedResponse": {
"properties": {
"type": {
@@ -28634,12 +28675,6 @@
"title": "SetupRequirementsResponse",
"description": "Response for validate action."
},
- "ShareRequest": {
- "properties": {},
- "type": "object",
- "title": "ShareRequest",
- "description": "Optional request body for share endpoint."
- },
"SharedChatLinkedExecution": {
"properties": {
"execution_id": { "type": "string", "title": "Execution Id" },
@@ -32898,6 +32933,18 @@
],
"title": "WorkspaceFileItem"
},
+ "WorkspaceFileUploadResponse": {
+ "properties": {
+ "file_id": { "type": "string", "title": "File Id" },
+ "name": { "type": "string", "title": "Name" },
+ "path": { "type": "string", "title": "Path" },
+ "mime_type": { "type": "string", "title": "Mime Type" },
+ "size_bytes": { "type": "integer", "title": "Size Bytes" }
+ },
+ "type": "object",
+ "required": ["file_id", "name", "path", "mime_type", "size_bytes"],
+ "title": "WorkspaceFileUploadResponse"
+ },
"WorkspaceFolder": {
"properties": {
"id": { "type": "string", "title": "Id" },
@@ -33011,55 +33058,6 @@
"required": ["content"],
"title": "WriteSummary",
"description": "One line per envelope written by apply.py.\n\nCarries the durable Graphiti edge uuid so the eval / admin UI / the\nfuture inline chat-stream `dream.operations` event (P9 daydreaming)\ncan render or audit individual operations. ``edge_uuid`` is None\nwhen the underlying ``enqueue_episode`` call did not return one\n(FalkorDB unreachable, etc.) — we still record the attempted write."
- },
- "backend__api__features__chat__share__ShareResponse": {
- "properties": {
- "share_url": { "type": "string", "title": "Share Url" },
- "share_token": { "type": "string", "title": "Share Token" }
- },
- "type": "object",
- "required": ["share_url", "share_token"],
- "title": "ShareResponse"
- },
- "backend__api__features__graph_executions__model__ShareResponse": {
- "properties": {
- "share_url": { "type": "string", "title": "Share Url" },
- "share_token": { "type": "string", "title": "Share Token" }
- },
- "type": "object",
- "required": ["share_url", "share_token"],
- "title": "ShareResponse",
- "description": "Response from share endpoints."
- },
- "backend__api__features__workspace__routes__UploadFileResponse": {
- "properties": {
- "file_id": { "type": "string", "title": "File Id" },
- "name": { "type": "string", "title": "Name" },
- "path": { "type": "string", "title": "Path" },
- "mime_type": { "type": "string", "title": "Mime Type" },
- "size_bytes": { "type": "integer", "title": "Size Bytes" }
- },
- "type": "object",
- "required": ["file_id", "name", "path", "mime_type", "size_bytes"],
- "title": "UploadFileResponse"
- },
- "backend__api__model__UploadFileResponse": {
- "properties": {
- "file_uri": { "type": "string", "title": "File Uri" },
- "file_name": { "type": "string", "title": "File Name" },
- "size": { "type": "integer", "title": "Size" },
- "content_type": { "type": "string", "title": "Content Type" },
- "expires_in_hours": { "type": "integer", "title": "Expires In Hours" }
- },
- "type": "object",
- "required": [
- "file_uri",
- "file_name",
- "size",
- "content_type",
- "expires_in_hours"
- ],
- "title": "UploadFileResponse"
}
},
"securitySchemes": {