diff --git a/backend/app/api/activity.py b/backend/app/api/activity.py index 53286364a..354e29d58 100644 --- a/backend/app/api/activity.py +++ b/backend/app/api/activity.py @@ -1,3 +1,4 @@ +from typing import Any """Activity log API — view agent work history.""" import uuid @@ -18,7 +19,7 @@ async def get_agent_activity( agent_id: uuid.UUID, limit: int = Query(50, le=200), current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get recent activity logs for an agent.""" await check_agent_access(db, current_user, agent_id) @@ -44,7 +45,7 @@ async def get_agent_activity( async def list_conversations( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all conversation partners for this agent (web users + other agents).""" await check_agent_access(db, current_user, agent_id) @@ -58,7 +59,7 @@ async def get_conversation_messages( conv_id: str, limit: int = Query(100, le=500), current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get messages for a specific conversation.""" await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/admin.py b/backend/app/api/admin.py index c496f1832..691deb2a3 100644 --- a/backend/app/api/admin.py +++ b/backend/app/api/admin.py @@ -4,6 +4,7 @@ and control platform-level settings. """ +from typing import Any import secrets import uuid from datetime import datetime @@ -69,7 +70,7 @@ class PlatformSettingsUpdate(BaseModel): @router.get("/companies", response_model=list[CompanyStats]) async def list_companies( current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all companies with stats.""" tenants = await query_dao.execute(db, select(Tenant).order_by(Tenant.created_at.desc())) @@ -142,7 +143,7 @@ async def list_companies( async def create_company( data: CompanyCreateRequest, current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new company and generate an admin invitation code (max_uses=1).""" import re @@ -183,7 +184,7 @@ async def create_company( async def toggle_company( company_id: uuid.UUID, current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Enable or disable a company.""" result = await query_dao.execute(db, select(Tenant).where(Tenant.id == company_id)) @@ -220,7 +221,7 @@ async def get_platform_timeseries( start_date: datetime, end_date: datetime, current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get daily platform metrics within a date range. @@ -385,7 +386,7 @@ async def get_platform_timeseries( @router.get("/metrics/leaderboards") async def get_platform_leaderboards( current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get Top 20 token consuming companies and agents.""" # Top 20 Companies by total tokens @@ -437,7 +438,7 @@ async def get_platform_leaderboards( @router.get("/metrics/enhanced") async def get_enhanced_metrics( current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Enhanced platform metrics: retention, avg tokens/session, channel distribution, tool categories, and churn warnings. @@ -588,7 +589,7 @@ async def get_enhanced_metrics( @router.get("/platform-settings", response_model=PlatformSettingsOut) async def get_platform_settings( current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get platform-level settings.""" settings: dict[str, bool] = {} @@ -609,7 +610,7 @@ async def get_platform_settings( async def update_platform_settings( data: PlatformSettingsUpdate, current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update platform-level settings.""" updates = data.model_dump(exclude_unset=True) diff --git a/backend/app/api/advanced.py b/backend/app/api/advanced.py index 295e39bb5..3cdc29801 100644 --- a/backend/app/api/advanced.py +++ b/backend/app/api/advanced.py @@ -1,3 +1,4 @@ +from typing import Any """Agent collaboration and template market API routes.""" import uuid @@ -36,7 +37,7 @@ class InterAgentMessage(BaseModel): async def list_collaborators( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List agents that can collaborate with this agent.""" await check_agent_access(db, current_user, agent_id) @@ -48,7 +49,7 @@ async def delegate_task( agent_id: uuid.UUID, data: DelegateRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Delegate a task from one agent to another.""" await check_agent_access(db, current_user, agent_id) @@ -66,7 +67,7 @@ async def send_inter_agent_message( agent_id: uuid.UUID, data: InterAgentMessage, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Send a message between agents.""" await check_agent_access(db, current_user, agent_id) @@ -163,7 +164,7 @@ async def handover_agent( agent_id: uuid.UUID, data: HandoverRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Transfer ownership of a digital employee to another user.""" from app.models.audit import AuditLog @@ -205,7 +206,7 @@ async def handover_agent( async def get_agent_metrics( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get observability metrics for an agent.""" agent, _access = await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/agent_credentials.py b/backend/app/api/agent_credentials.py index 2c11d27ea..706e1b05d 100644 --- a/backend/app/api/agent_credentials.py +++ b/backend/app/api/agent_credentials.py @@ -1,3 +1,4 @@ +from typing import Any """Agent Credentials CRUD API routes. Provides endpoints for managing encrypted session cookies @@ -52,7 +53,7 @@ def _to_response(cred: AgentCredential) -> dict: async def list_credentials( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all credentials for an agent (sensitive data excluded).""" # Verify the user has manage-level access to this agent @@ -72,7 +73,7 @@ async def create_credential( agent_id: uuid.UUID, data: AgentCredentialCreate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new credential for an agent. @@ -121,7 +122,7 @@ async def update_credential( credential_id: uuid.UUID, data: AgentCredentialUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update an existing credential. @@ -177,7 +178,7 @@ async def delete_credential( agent_id: uuid.UUID, credential_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Delete a credential.""" _agent, access_level = await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/agentbay_control.py b/backend/app/api/agentbay_control.py index 5a7daa0f2..413860b1c 100644 --- a/backend/app/api/agentbay_control.py +++ b/backend/app/api/agentbay_control.py @@ -14,7 +14,7 @@ import time import uuid from datetime import datetime, timezone -from typing import Optional +from typing import Any, Optional from fastapi import APIRouter, Depends, HTTPException, status from pydantic import BaseModel @@ -626,7 +626,7 @@ async def control_current_url( agent_id: uuid.UUID, data: CurrentUrlRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get the current page URL from the active browser session via CDP. @@ -676,7 +676,7 @@ async def control_click( agent_id: uuid.UUID, data: ClickRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Forward a mouse click to the AgentBay session. @@ -709,7 +709,7 @@ async def control_type( agent_id: uuid.UUID, data: TypeRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Forward text input to the AgentBay session.""" _agent, _access = await check_agent_access(db, current_user, agent_id) @@ -736,7 +736,7 @@ async def control_press_keys( agent_id: uuid.UUID, data: PressKeysRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Forward keyboard key presses to the AgentBay session.""" _agent, _access = await check_agent_access(db, current_user, agent_id) @@ -763,7 +763,7 @@ async def control_drag( agent_id: uuid.UUID, data: DragRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Simulate a human-like mouse drag in the AgentBay session. @@ -799,7 +799,7 @@ async def control_screenshot( agent_id: uuid.UUID, data: ScreenshotRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get an immediate screenshot from the AgentBay session. @@ -846,7 +846,7 @@ async def control_lock( agent_id: uuid.UUID, data: LockRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Enter Take Control mode — locks the session against automatic tool execution. @@ -888,7 +888,7 @@ async def control_unlock( agent_id: uuid.UUID, data: UnlockRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Exit Take Control mode — unlock session and optionally export cookies. diff --git a/backend/app/api/agents.py b/backend/app/api/agents.py index e7da1a80d..8a8cc1cf8 100644 --- a/backend/app/api/agents.py +++ b/backend/app/api/agents.py @@ -1,3 +1,4 @@ +from typing import Any """Agent (Digital Employee) API routes.""" import hashlib @@ -136,7 +137,7 @@ def _serialize_agent_out(agent: Agent, unread_count: int = 0) -> AgentOut: @router.get("/templates") async def list_templates( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all available agent templates.""" from app.models.agent import AgentTemplate @@ -195,7 +196,7 @@ async def _agents_to_out( @router.get("/", response_model=list[AgentOut]) async def list_agents( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all agents the current user has access to.""" stmt = build_visible_agents_query( @@ -390,7 +391,7 @@ async def create_agent( data: AgentCreate, background_tasks: BackgroundTasks, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new digital employee (any authenticated user).""" # Check agent creation quota @@ -573,7 +574,7 @@ async def create_agent( async def get_agent( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get agent details.""" agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -607,7 +608,7 @@ async def get_agent( async def get_agent_permissions( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get agent permission scope.""" agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -705,7 +706,7 @@ async def update_agent_permissions( agent_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update agent permission scope (owner or platform_admin only).""" agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -803,7 +804,7 @@ async def get_agent_permission_candidates( agent_id: uuid.UUID, search: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return org members that can be granted custom access. @@ -884,7 +885,7 @@ async def update_agent( agent_id: uuid.UUID, data: AgentUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update agent settings (creator or admin).""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -1000,7 +1001,7 @@ async def update_agent( async def delete_agent( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Logically delete an Agent while retaining its history and Workspace.""" agent, _access = await check_agent_access( @@ -1091,7 +1092,7 @@ async def delete_agent( async def start_agent( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Start an agent's container.""" agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -1109,7 +1110,7 @@ async def start_agent( async def stop_agent( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Stop an agent's container.""" agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -1131,7 +1132,7 @@ async def list_agent_approvals( agent_id: uuid.UUID, status_filter: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List approval requests for a specific agent. Only creator or admin can view.""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -1170,7 +1171,7 @@ async def resolve_agent_approval( approval_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Approve or reject a pending approval for a specific agent.""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -1198,7 +1199,7 @@ async def resolve_agent_approval( async def generate_or_reset_api_key( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Generate or regenerate API key for an OpenClaw agent.""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -1218,7 +1219,7 @@ async def generate_or_reset_api_key( async def list_gateway_messages( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List recent gateway messages for an OpenClaw agent.""" agent, _access = await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/atlassian.py b/backend/app/api/atlassian.py index dc0bef29a..fe0517b02 100644 --- a/backend/app/api/atlassian.py +++ b/backend/app/api/atlassian.py @@ -1,3 +1,4 @@ +from typing import Any """Atlassian Rovo MCP Channel API routes. Provides per-agent Atlassian integration configuration. @@ -31,7 +32,7 @@ async def configure_atlassian_channel( agent_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Configure Atlassian Rovo MCP for an agent. @@ -90,7 +91,7 @@ async def configure_atlassian_channel( async def get_atlassian_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) result = await query_dao.execute(db, @@ -109,7 +110,7 @@ async def get_atlassian_channel( async def delete_atlassian_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -131,7 +132,7 @@ async def delete_atlassian_channel( async def test_atlassian_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Test connectivity to Atlassian Rovo MCP and list available tools.""" await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/chat_sessions.py b/backend/app/api/chat_sessions.py index 31f3eb148..aadc6cae6 100644 --- a/backend/app/api/chat_sessions.py +++ b/backend/app/api/chat_sessions.py @@ -6,7 +6,7 @@ import re import uuid from datetime import UTC, datetime -from typing import Annotated, Literal +from typing import Any, Annotated, Literal from fastapi import APIRouter, Depends, HTTPException, Query from pydantic import BaseModel, ConfigDict, Field @@ -218,7 +218,7 @@ async def list_sessions( agent_id: uuid.UUID, scope: Annotated[str, Query(description="'mine' or 'all'")] = "mine", current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List active sessions on the legacy Agent session surface.""" agent, tenant_id = await _check_direct_agent_access(db, current_user, agent_id) @@ -360,7 +360,7 @@ async def create_session( agent_id: uuid.UUID, body: CreateSessionIn = CreateSessionIn(), current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a direct session for the active current-tenant User.""" _, tenant_id = await _check_direct_agent_access(db, current_user, agent_id) @@ -402,7 +402,7 @@ async def get_session_runtime_state( agent_id: uuid.UUID, session_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ) -> SessionRuntimeStateOut: """Return the one exact Direct Chat lane holder, if one exists.""" _agent, tenant_id = await _check_direct_agent_access( @@ -570,7 +570,7 @@ async def reconcile_direct_tool_execution( execution_id: uuid.UUID, body: ReconcileToolExecutionIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ) -> ReconcileToolExecutionOut: """Settle a Direct Chat unknown receipt before the user resumes its Run.""" agent, tenant_id = await _check_direct_agent_access(db, current_user, agent_id) @@ -673,7 +673,7 @@ async def rename_session( session_id: uuid.UUID, body: PatchSessionIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Rename one active direct session.""" agent, tenant_id = await _check_direct_agent_access(db, current_user, agent_id) @@ -699,7 +699,7 @@ async def delete_session( agent_id: uuid.UUID, session_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Soft-delete a direct session and cancel only its foreground collaboration.""" agent, tenant_id = await _check_direct_agent_access(db, current_user, agent_id) @@ -799,7 +799,7 @@ async def get_session_messages( Query(description="Cursor '|' for the first excluded position"), ] = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return associated session messages by authoritative `(created_at, id)` position.""" agent, tenant_id = await _check_direct_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/dingtalk.py b/backend/app/api/dingtalk.py index 5160c6e33..75449df56 100644 --- a/backend/app/api/dingtalk.py +++ b/backend/app/api/dingtalk.py @@ -1,3 +1,4 @@ +from typing import Any """DingTalk Channel API routes. Provides Config CRUD and message handling for DingTalk bots using Stream mode. @@ -31,7 +32,7 @@ async def configure_dingtalk_channel( agent_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Configure DingTalk bot for an agent. Fields: app_key, app_secret, agent_id (optional).""" agent, _ = await check_agent_access(db, current_user, agent_id) @@ -99,7 +100,7 @@ async def configure_dingtalk_channel( async def get_dingtalk_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) result = await db.execute( @@ -118,7 +119,7 @@ async def get_dingtalk_channel( async def delete_dingtalk_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -271,7 +272,7 @@ async def process_dingtalk_message( async def dingtalk_callback( authCode: str, # DingTalk uses authCode parameter state: str = None, - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Callback for DingTalk OAuth2 login.""" from app.models.identity import SSOScanSession diff --git a/backend/app/api/directory.py b/backend/app/api/directory.py index 3ee062a44..7aff3b5e6 100644 --- a/backend/app/api/directory.py +++ b/backend/app/api/directory.py @@ -1,3 +1,4 @@ +from typing import Any """Read-only agent directory API.""" import uuid @@ -55,7 +56,7 @@ async def get_agent_directory( limit: int = 50, offset: int = 0, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return the people and agents the source agent can currently contact.""" await check_agent_access(db, current_user, agent_id) @@ -78,7 +79,7 @@ async def get_agent_directory( async def get_custom_directory_humans( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return explicitly authorized human members in a custom Directory.""" agent = await _require_custom_directory_manager(db, current_user, agent_id) @@ -126,7 +127,7 @@ async def get_custom_directory_human_candidates( limit: int = 50, offset: int = 0, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return paginated human candidates that can be added to a custom Directory.""" _validate_pagination(limit, offset) @@ -183,7 +184,7 @@ async def add_custom_directory_human( agent_id: uuid.UUID, payload: CustomHumanDirectoryIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Add a human platform user to a custom Directory with use access.""" agent = await _require_custom_directory_manager(db, current_user, agent_id) @@ -215,7 +216,7 @@ async def remove_custom_directory_human( agent_id: uuid.UUID, user_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Remove a use-level human from a custom Directory.""" await _require_custom_directory_manager(db, current_user, agent_id) @@ -242,7 +243,7 @@ async def remove_custom_directory_human( async def get_custom_directory_agents( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return explicitly linked digital employees in a custom Directory.""" await _require_custom_directory_manager(db, current_user, agent_id) @@ -274,7 +275,7 @@ async def get_custom_directory_agent_candidates( limit: int = 50, offset: int = 0, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return paginated digital employee candidates for a custom Directory.""" _validate_pagination(limit, offset) @@ -320,7 +321,7 @@ async def add_custom_directory_agent( agent_id: uuid.UUID, payload: CustomAgentDirectoryIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Add a digital employee to a custom Directory.""" agent = await _require_custom_directory_manager(db, current_user, agent_id) @@ -360,7 +361,7 @@ async def remove_custom_directory_agent( agent_id: uuid.UUID, target_agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Remove a digital employee from a custom Directory.""" await _require_custom_directory_manager(db, current_user, agent_id) diff --git a/backend/app/api/discord_bot.py b/backend/app/api/discord_bot.py index ad00c5490..4c37bd05e 100644 --- a/backend/app/api/discord_bot.py +++ b/backend/app/api/discord_bot.py @@ -1,3 +1,4 @@ +from typing import Any """Discord Bot Channel API routes (slash command interactions).""" import uuid @@ -27,7 +28,7 @@ async def configure_discord_channel( agent_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Configure Discord bot for an agent. @@ -97,7 +98,7 @@ async def configure_discord_channel( async def get_discord_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) result = await db.execute( @@ -113,7 +114,7 @@ async def get_discord_channel( @router.get("/agents/{agent_id}/discord-channel/webhook-url") -async def get_discord_webhook_url(agent_id: uuid.UUID, request: Request, db: AsyncSession = Depends(get_db)): +async def get_discord_webhook_url(agent_id: uuid.UUID, request: Request, db: Any = None): from app.services.platform_service import platform_service public_base = await platform_service.get_public_base_url(db, request) return {"webhook_url": f"{public_base}/api/channel/discord/{agent_id}/webhook"} @@ -123,7 +124,7 @@ async def get_discord_webhook_url(agent_id: uuid.UUID, request: Request, db: Asy async def delete_discord_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -198,7 +199,7 @@ def _verify_discord_signature(public_key: str, body: bytes, headers: dict) -> bo async def discord_interaction_webhook( agent_id: uuid.UUID, request: Request, - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Handle Discord Interaction webhooks (PING + slash commands).""" body_bytes = await request.body() diff --git a/backend/app/api/enterprise.py b/backend/app/api/enterprise.py index 86eef7afd..2c4892db5 100644 --- a/backend/app/api/enterprise.py +++ b/backend/app/api/enterprise.py @@ -1,3 +1,4 @@ +from typing import Any """Enterprise management API routes: LLM pool, enterprise info, approvals, audit logs.""" import uuid @@ -92,7 +93,7 @@ class CheckEmailRequest(BaseModel): @router.post("/check-email-exists") async def check_email_exists( data: CheckEmailRequest, - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Public endpoint — check if an email address is already registered on this platform. @@ -365,7 +366,7 @@ async def test_llm_model( async def list_llm_models( tenant_id: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List LLM models scoped to the selected tenant.""" # Authorization: non-platform admins can only see their own tenant's models @@ -397,7 +398,7 @@ async def add_llm_model( data: LLMModelCreate, tenant_id: str | None = None, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Add a new LLM model to the tenant's pool (admin).""" tid = tenant_id or (str(current_user.tenant_id) if current_user.tenant_id else None) @@ -434,7 +435,7 @@ async def add_llm_model( async def set_default_llm_model( model_id: uuid.UUID, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Mark this model as the tenant's default for new agents.""" result = await db.execute( @@ -488,7 +489,7 @@ async def set_default_llm_model( async def remove_llm_model( model_id: uuid.UUID, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Logically delete an LLM model while retaining every historical reference.""" query = select(LLMModel).where(LLMModel.id == model_id) @@ -523,7 +524,7 @@ async def update_llm_model( model_id: uuid.UUID, data: LLMModelUpdate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update an existing LLM model in the pool (admin).""" result = await db.execute( @@ -582,7 +583,7 @@ async def update_llm_model( @router.get("/info", response_model=list[EnterpriseInfoOut]) async def list_enterprise_info( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all enterprise information entries.""" result = await db.execute(select(EnterpriseInfo).order_by(EnterpriseInfo.info_type)) @@ -594,7 +595,7 @@ async def update_enterprise_info( info_type: str, data: EnterpriseInfoUpdate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create or update enterprise information. Triggers sync to agents.""" info = await enterprise_sync_service.update_enterprise_info( @@ -612,7 +613,7 @@ async def list_approvals( tenant_id: str | None = None, status_filter: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List approval requests scoped to a tenant.""" query = select(ApprovalRequest) @@ -653,7 +654,7 @@ async def resolve_approval( approval_id: uuid.UUID, data: ApprovalAction, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Approve or reject a pending approval request.""" try: @@ -673,7 +674,7 @@ async def list_audit_logs( tenant_id: str | None = None, limit: int = 50, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List audit logs scoped to a tenant (admin only).""" query = select(AuditLog).order_by(AuditLog.created_at.desc()).limit(limit) @@ -694,7 +695,7 @@ async def list_audit_logs( async def get_enterprise_stats( tenant_id: str | None = None, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get enterprise dashboard statistics, optionally scoped to a tenant.""" # Determine which tenant to filter by @@ -754,7 +755,7 @@ class TenantQuotaUpdate(BaseModel): @router.get("/tenant-quotas") async def get_tenant_quotas( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get tenant quota defaults and heartbeat settings.""" if not current_user.tenant_id: @@ -780,7 +781,7 @@ async def get_tenant_quotas( async def update_tenant_quotas( data: TenantQuotaUpdate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update tenant quota defaults (admin only). Enforces heartbeat floor on existing agents.""" if not current_user.tenant_id: @@ -837,7 +838,7 @@ class TestEmailRequest(BaseModel): async def send_test_email_endpoint( data: TestEmailRequest, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Send a test email to verify SMTP configuration (admin only).""" import smtplib @@ -873,7 +874,7 @@ async def send_test_email_endpoint( @router.get("/email-templates") async def get_email_templates_endpoint( current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get email templates (current values + available variables per scenario).""" from app.services.system_email_service import ( @@ -898,7 +899,7 @@ class EmailTemplatesUpdate(BaseModel): async def update_email_templates_endpoint( data: EmailTemplatesUpdate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Save email templates (admin only).""" from app.services.system_email_service import EMAIL_TEMPLATE_VARIABLES @@ -995,7 +996,7 @@ async def _runtime_model_settings_payload(db: AsyncSession, *, tenant_id: uuid.U async def get_runtime_model_settings( tenant_id: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return the selected tenant's eligible Group Runtime model choices.""" resolved_tenant_id = _runtime_settings_tenant_id(current_user, tenant_id) @@ -1007,7 +1008,7 @@ async def update_runtime_model_settings( data: RuntimeModelSettingsUpdate, tenant_id: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Persist tenant-scoped Group Runtime models, effective immediately.""" resolved_tenant_id = _runtime_settings_tenant_id(current_user, tenant_id) @@ -1048,7 +1049,7 @@ async def update_runtime_model_settings( @router.get("/system-settings/notification_bar/public") async def get_notification_bar_public( - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Public (no auth) endpoint to read the notification bar config.""" result = await db.execute( @@ -1068,7 +1069,7 @@ async def get_notification_bar_public( async def get_system_setting( key: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get a system setting by key.""" result = await db.execute(select(SystemSetting).where(SystemSetting.key == key)) @@ -1083,7 +1084,7 @@ async def update_system_setting( key: str, data: SettingUpdate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create or update a system setting.""" # Platform-level settings (e.g. PUBLIC_BASE_URL) require platform_admin @@ -1203,7 +1204,7 @@ async def list_identity_providers( tenant_id: str | None = None, global_only: bool = False, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List identity providers configured for the tenant.""" # Authorization: non-platform admins can only see their own tenant's providers @@ -1357,7 +1358,7 @@ def _identity_provider_response(provider: IdentityProvider, sso_domain: str | No async def create_identity_provider( data: IdentityProviderCreate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new identity provider (Admin only).""" from app.services.auth_registry import auth_provider_registry @@ -1408,7 +1409,7 @@ async def create_identity_provider( async def create_oauth2_provider( data: IdentityProviderOAuth2Create, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new OAuth2 identity provider with simplified fields (app_id, app_secret, authorize_url, etc.).""" from app.services.auth_registry import auth_provider_registry @@ -1474,7 +1475,7 @@ async def update_oauth2_provider( provider_id: uuid.UUID, data: OAuth2ConfigUpdate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update an OAuth2 identity provider with simplified fields.""" from app.services.auth_registry import auth_provider_registry @@ -1542,7 +1543,7 @@ async def update_identity_provider( provider_id: uuid.UUID, data: IdentityProviderUpdate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update an existing identity provider.""" from app.services.auth_registry import auth_provider_registry @@ -1599,7 +1600,7 @@ async def update_identity_provider( async def delete_identity_provider( provider_id: uuid.UUID, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Delete an identity provider.""" result = await db.execute(select(IdentityProvider).where(IdentityProvider.id == provider_id)) @@ -1638,7 +1639,7 @@ async def list_org_departments( tenant_id: str | None = None, provider_id: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all departments, optionally filtered by tenant or provider.""" # Tenant isolation rules: @@ -1705,7 +1706,7 @@ async def list_org_members( tenant_id: str | None = None, provider_id: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List org members, optionally filtered by department, search, tenant, or provider.""" # Tenant isolation rules: @@ -1788,7 +1789,7 @@ async def list_org_members( async def trigger_org_sync( provider_id: str | None = None, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Manually trigger org structure sync from a specific identity provider.""" from app.services.org_sync_service import org_sync_service @@ -1822,7 +1823,7 @@ async def wecom_org_sync_verify( timestamp: str = "", nonce: str = "", echostr: str = "", - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Handle WeCom receive-message-server URL verification for the org sync app. @@ -1967,7 +1968,7 @@ async def _ensure_invitation_email_enabled(db: AsyncSession) -> None: async def create_invitation_codes( data: InvitationCodeCreate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Batch-create invitation codes for the current user's company.""" _require_tenant_admin(current_user) @@ -1996,7 +1997,7 @@ async def invite_users( data: UserInviteRequest, background_tasks: BackgroundTasks, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Batch-invite users via email to the current user's company.""" _require_tenant_admin(current_user) @@ -2062,7 +2063,7 @@ async def list_invitation_codes( page_size: int = 20, search: str = "", current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List invitation codes for the current user's company.""" _require_tenant_admin(current_user) @@ -2106,7 +2107,7 @@ async def list_invitation_codes( @router.get("/invitation-codes/export") async def export_invitation_codes_csv( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Export invitation codes for the current user's company as CSV.""" _require_tenant_admin(current_user) @@ -2145,7 +2146,7 @@ async def export_invitation_codes_csv( async def deactivate_invitation_code( code_id: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Deactivate an invitation code (must belong to current user's company).""" _require_tenant_admin(current_user) diff --git a/backend/app/api/feishu.py b/backend/app/api/feishu.py index fbc91041d..4d08b8b37 100644 --- a/backend/app/api/feishu.py +++ b/backend/app/api/feishu.py @@ -1,3 +1,4 @@ +from typing import Any """Feishu OAuth and Channel API routes.""" import uuid @@ -38,7 +39,7 @@ async def feishu_oauth_callback( code: str, state: str = None, - db: AsyncSession = Depends(get_db) + db: Any = None ): """Handle Feishu OAuth callback — exchange code for user session.""" # Parse state if it's a UUID (session ID) or other context @@ -132,7 +133,7 @@ async def configure_channel( agent_id: uuid.UUID, data: ChannelConfigCreate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Configure Feishu bot credentials for a digital employee (wizard step 5).""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -192,7 +193,7 @@ async def configure_channel( async def get_channel_config( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get Feishu channel configuration for an agent.""" await check_agent_access(db, current_user, agent_id) @@ -207,7 +208,7 @@ async def get_channel_config( @router.get("/agents/{agent_id}/channel/webhook-url") -async def get_webhook_url(agent_id: uuid.UUID, request: Request, db: AsyncSession = Depends(get_db)): +async def get_webhook_url(agent_id: uuid.UUID, request: Request, db: Any = None): """Get the webhook URL for this agent's Feishu bot.""" from app.services.platform_service import platform_service public_base = await platform_service.get_public_base_url(db, request) @@ -218,7 +219,7 @@ async def get_webhook_url(agent_id: uuid.UUID, request: Request, db: AsyncSessio async def delete_channel_config( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Remove Feishu bot configuration for an agent.""" agent, _access = await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/files.py b/backend/app/api/files.py index faf130ed7..1d3265cf3 100644 --- a/backend/app/api/files.py +++ b/backend/app/api/files.py @@ -1,3 +1,4 @@ +from typing import Any """File management API routes for agent workspaces.""" import asyncio @@ -226,7 +227,7 @@ async def list_files( agent_id: uuid.UUID, path: str = "", current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List files and directories in an agent's file system.""" await check_agent_access(db, current_user, agent_id) @@ -292,7 +293,7 @@ async def read_file( agent_id: uuid.UUID, path: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Read the content of a file.""" await check_agent_access(db, current_user, agent_id) @@ -431,7 +432,7 @@ async def preview_file( agent_id: uuid.UUID, path: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return a browser-friendly preview payload for Workspace files.""" await check_agent_access(db, current_user, agent_id) @@ -562,7 +563,7 @@ async def download_file( token: str = "", inline: bool = False, credentials: HTTPAuthorizationCredentials | None = Depends(HTTPBearer(auto_error=False)), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Download / serve a file from the agent workspace (browser-friendly). @@ -623,7 +624,7 @@ async def write_file( path: str, data: FileWrite, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Write content to a file (create or overwrite).""" await check_agent_access(db, current_user, agent_id) @@ -668,7 +669,7 @@ async def lock_file( agent_id: uuid.UUID, data: FileLockBody, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Acquire or refresh a short-lived human editing lock for a file.""" await check_agent_access(db, current_user, agent_id) @@ -690,7 +691,7 @@ async def unlock_file( agent_id: uuid.UUID, path: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Release the current user's edit lock for a file.""" await check_agent_access(db, current_user, agent_id) @@ -704,7 +705,7 @@ async def get_file_revisions( agent_id: uuid.UUID, path: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List version history for the currently opened Workspace file.""" await check_agent_access(db, current_user, agent_id) @@ -735,7 +736,7 @@ async def restore_file_revision( agent_id: uuid.UUID, data: RestoreRevisionBody, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Restore a file to a previous revision's after-content.""" await check_agent_access(db, current_user, agent_id) @@ -775,7 +776,7 @@ async def delete_file( path: str, expected_version_token: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Delete a file.""" await _require_agent_file_delete_access(db, current_user, agent_id) @@ -815,7 +816,7 @@ async def import_skill_to_agent( agent_id: uuid.UUID, body: ImportSkillBody, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Import a global skill into this agent's skills/ workspace folder. @@ -865,7 +866,7 @@ async def upload_file_to_workspace( file: UploadFileType = FastFile(...), path: str = "workspace/knowledge_base", current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Upload a binary file to agent workspace.""" await check_agent_access(db, current_user, agent_id) @@ -1078,7 +1079,7 @@ async def agent_import_from_clawhub( agent_id: uuid.UUID, body: ClawhubImportBody, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Import a skill from ClawHub directly into this agent's skills/ workspace.""" await check_agent_access(db, current_user, agent_id) @@ -1133,7 +1134,7 @@ async def agent_import_from_url( agent_id: uuid.UUID, body: UrlImportBody, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Import a skill from a GitHub URL directly into this agent's skills/ workspace.""" await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/focus.py b/backend/app/api/focus.py index 9e05d6c69..1848f27f2 100644 --- a/backend/app/api/focus.py +++ b/backend/app/api/focus.py @@ -1,3 +1,4 @@ +from typing import Any """Structured Focus API for Aware.""" import uuid @@ -47,7 +48,7 @@ async def list_agent_focus( agent_id: uuid.UUID, include_completed: bool = True, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) return await list_focus_items(agent_id, include_completed=include_completed) @@ -58,7 +59,7 @@ async def upsert_agent_focus( agent_id: uuid.UUID, body: FocusUpsertBody, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) if body.status not in {"in_progress", "completed"}: @@ -82,7 +83,7 @@ async def complete_agent_focus( agent_id: uuid.UUID, key: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) item = await complete_focus_item(agent_id, key=key) diff --git a/backend/app/api/gateway.py b/backend/app/api/gateway.py index 98079efe2..12206ea79 100644 --- a/backend/app/api/gateway.py +++ b/backend/app/api/gateway.py @@ -1,3 +1,4 @@ +from typing import Any """Gateway API for OpenClaw agent communication. OpenClaw agents authenticate via X-Api-Key header and use these endpoints @@ -74,7 +75,7 @@ async def _get_agent_by_key(api_key: str, db: AsyncSession) -> Agent: @router.get("/poll", response_model=GatewayPollResponse) async def poll_messages( x_api_key: str = Header(..., alias="X-Api-Key"), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """OpenClaw agent polls for pending messages. @@ -230,7 +231,7 @@ async def poll_messages( async def report_result( body: GatewayReportRequest, x_api_key: str = Header(None, alias="X-Api-Key"), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """OpenClaw agent reports the result of a processed message.""" if not x_api_key: @@ -355,7 +356,7 @@ async def report_result( @router.post("/heartbeat") async def heartbeat( x_api_key: str = Header(..., alias="X-Api-Key"), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Pure heartbeat ping — keeps the OpenClaw agent marked as online.""" agent = await _get_agent_by_key(x_api_key, db) @@ -371,7 +372,7 @@ async def heartbeat( async def send_message( body: GatewaySendMessageRequest, x_api_key: str = Header(..., alias="X-Api-Key"), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """OpenClaw agent sends a message to a person or another agent. @@ -583,7 +584,7 @@ async def get_setup_guide( agent_id: uuid.UUID, x_api_key: str = Header(..., alias="X-Api-Key"), accept_language: str | None = Header(None, alias="Accept-Language"), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return the pre-filled Skill file and Heartbeat instruction for this agent.""" agent = await _get_agent_by_key(x_api_key, db) diff --git a/backend/app/api/google_workspace.py b/backend/app/api/google_workspace.py index af3ee3010..d0270dd1a 100644 --- a/backend/app/api/google_workspace.py +++ b/backend/app/api/google_workspace.py @@ -1,3 +1,4 @@ +from typing import Any """Google Workspace OAuth callback routes.""" import uuid @@ -38,7 +39,7 @@ async def get_google_workspace_sync_authorize_url( provider_id: uuid.UUID, request: Request, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): provider = await get_google_provider(db, provider_id) if current_user.role != "platform_admin" and provider.tenant_id != current_user.tenant_id: @@ -194,7 +195,7 @@ async def google_workspace_callback( code: str, state: str | None = None, request: Request = None, - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Unified callback for Google Workspace SSO login and admin authorization.""" parsed_state = parse_google_oauth_state(state) if state else None diff --git a/backend/app/api/groups.py b/backend/app/api/groups.py index 8ec2cb233..ae5f63eb0 100644 --- a/backend/app/api/groups.py +++ b/backend/app/api/groups.py @@ -512,7 +512,7 @@ async def _message_outputs( async def create_group( body: CreateGroupIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -545,7 +545,7 @@ async def create_group( @router.get("", response_model=list[GroupOut]) async def list_groups( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -562,7 +562,7 @@ async def list_tenant_member_candidates( participant_type: Annotated[Literal["user", "agent"], Query()], limit: Annotated[int, Query(ge=1, le=100)] = 100, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Candidates for the create-group flow, before any group exists.""" tenant_id = _tenant_id(current_user) @@ -586,7 +586,7 @@ async def list_tenant_member_candidates( async def get_group( group_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -606,7 +606,7 @@ async def patch_group( group_id: uuid.UUID, body: PatchGroupIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): if "name" not in body.model_fields_set and "description" not in body.model_fields_set: raise HTTPException(status_code=400, detail="At least one field must be supplied") @@ -639,7 +639,7 @@ async def patch_group( async def delete_group( group_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -666,7 +666,7 @@ async def delete_group( async def list_group_members( group_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -691,7 +691,7 @@ async def list_group_member_candidates( participant_type: Annotated[Literal["user", "agent"], Query()], limit: Annotated[int, Query(ge=1, le=100)] = 100, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -722,7 +722,7 @@ async def invite_group_member( group_id: uuid.UUID, body: InviteGroupMemberIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -755,7 +755,7 @@ async def remove_group_member( group_id: uuid.UUID, member_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -784,7 +784,7 @@ async def remove_group_member( async def list_group_sessions( group_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -819,7 +819,7 @@ async def create_group_session( group_id: uuid.UUID, body: CreateGroupSessionIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -850,7 +850,7 @@ async def patch_group_session( session_id: uuid.UUID, body: PatchGroupSessionIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -884,7 +884,7 @@ async def delete_group_session( group_id: uuid.UUID, session_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -924,7 +924,7 @@ async def mark_group_session_read( session_id: uuid.UUID, body: MarkGroupSessionReadIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -963,7 +963,7 @@ async def list_group_messages( Query(description="Cursor '|' for the last seen position"), ] = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -994,7 +994,7 @@ async def create_group_message( body: CreateGroupMessageIn, request: Request, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1052,7 +1052,7 @@ async def list_active_group_runs( group_id: uuid.UUID, session_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return exact non-terminal Runs that should animate this group Session.""" tenant_id = _tenant_id(current_user) @@ -1119,7 +1119,7 @@ async def get_group_run_state( session_id: uuid.UUID, run_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1158,7 +1158,7 @@ async def cancel_group_run( session_id: uuid.UUID, run_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1203,7 +1203,7 @@ async def cancel_group_run( async def get_group_announcement( group_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1226,7 +1226,7 @@ async def put_group_announcement( group_id: uuid.UUID, body: GroupTextFileIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1259,7 +1259,7 @@ async def get_group_agent_memory( group_id: uuid.UUID, agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1284,7 +1284,7 @@ async def put_group_agent_memory( agent_id: uuid.UUID, body: GroupTextFileIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1325,7 +1325,7 @@ async def delete_group_agent_memory( agent_id: uuid.UUID, expected_version_token: Annotated[str | None, Query()] = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1361,7 +1361,7 @@ async def get_group_session_summary( group_id: uuid.UUID, session_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1394,7 +1394,7 @@ async def list_group_workspace( group_id: uuid.UUID, path: Annotated[str, Query(max_length=500)] = "", current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1418,7 +1418,7 @@ async def get_group_workspace_file( group_id: uuid.UUID, path: Annotated[str, Query(min_length=1, max_length=500)], current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1443,7 +1443,7 @@ async def put_group_workspace_file( body: GroupWorkspaceFileIn, path: Annotated[str, Query(min_length=1, max_length=500)], current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) @@ -1484,7 +1484,7 @@ async def upload_group_workspace_file( expected_version_token: Annotated[str | None, Query()] = None, require_absent: Annotated[bool, Query()] = False, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Upload one group workspace file without converting binary bytes to text.""" tenant_id = _tenant_id(current_user) @@ -1561,7 +1561,7 @@ async def download_group_workspace_file( token: str = "", inline: bool = False, credentials: HTTPAuthorizationCredentials | None = Depends(HTTPBearer(auto_error=False)), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Download a group workspace file with membership authorization.""" current_user = await _download_user(token=token, credentials=credentials, db=db) @@ -1613,7 +1613,7 @@ async def delete_group_workspace_file( path: Annotated[str, Query(min_length=1, max_length=500)], expected_version_token: Annotated[str | None, Query()] = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): tenant_id = _tenant_id(current_user) participant = await _current_participant(db, current_user) diff --git a/backend/app/api/messages.py b/backend/app/api/messages.py index 39f4ea220..73356a56a 100644 --- a/backend/app/api/messages.py +++ b/backend/app/api/messages.py @@ -1,3 +1,4 @@ +from typing import Any """Messages API — inbox, unread count, mark as read. After the Participant abstraction migration, agent-to-agent messages are stored @@ -26,7 +27,7 @@ async def get_inbox( limit: int = Query(50, le=200), current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get agent-to-agent messages for agents the current user manages. @@ -84,7 +85,7 @@ async def get_inbox( @router.get("/messages/unread-count") async def get_unread_count( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get count of unread agent-to-agent messages for the current user's agents.""" agent_ids_q = await query_dao.execute(db, select(Agent.id).where(Agent.creator_id == current_user.id)) diff --git a/backend/app/api/notification.py b/backend/app/api/notification.py index b0d560e30..bd32c89b7 100644 --- a/backend/app/api/notification.py +++ b/backend/app/api/notification.py @@ -1,7 +1,7 @@ """Notification API — list, count, mark-read, and broadcast.""" import uuid -from typing import Optional +from typing import Any, Optional from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Query from pydantic import BaseModel, Field @@ -39,7 +39,7 @@ async def list_notifications( unread_only: bool = Query(False), category: Optional[str] = Query(None), current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List notifications for the current user, newest first.""" query = select(Notification).where(Notification.user_id == current_user.id) @@ -69,7 +69,7 @@ async def list_notifications( async def get_unread_count( category: Optional[str] = Query(None), current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get the number of unread notifications for the current user.""" query = select(func.count(Notification.id)).where( @@ -85,7 +85,7 @@ async def get_unread_count( async def mark_read( notification_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Mark a single notification as read.""" await query_dao.execute(db, @@ -100,7 +100,7 @@ async def mark_read( @router.post("/notifications/read-all") async def mark_all_read( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Mark all notifications as read for the current user.""" await query_dao.execute(db, @@ -125,7 +125,7 @@ async def broadcast_notification( req: BroadcastRequest, background_tasks: BackgroundTasks, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Send a notification to all users and agents in the current tenant. Requires org_admin or platform_admin role.""" diff --git a/backend/app/api/onboarding.py b/backend/app/api/onboarding.py index 291e159b0..03e0df572 100644 --- a/backend/app/api/onboarding.py +++ b/backend/app/api/onboarding.py @@ -1,3 +1,4 @@ +from typing import Any """Company onboarding APIs.""" import uuid @@ -176,7 +177,7 @@ async def _create_personal_assistant( @router.get("/status") async def get_onboarding_status( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return onboarding state for the current user/company.""" return _status_payload(await _get_row(db, current_user)) @@ -186,7 +187,7 @@ async def get_onboarding_status( async def start_onboarding( data: OnboardingStartRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Start or resume onboarding for the current user/company.""" row = await _ensure_row(db, current_user, data.entry_mode) @@ -198,7 +199,7 @@ async def start_onboarding( async def create_personal_assistant( data: PersonalAssistantRequest, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create the user's private assistant and advance onboarding.""" row = await _ensure_row(db, current_user, "join") @@ -227,7 +228,7 @@ async def create_personal_assistant( @router.post("/complete") async def complete_onboarding( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Mark the current user/company onboarding as completed.""" row = await _get_row(db, current_user) diff --git a/backend/app/api/organization.py b/backend/app/api/organization.py index ad81c0a51..744f03bee 100644 --- a/backend/app/api/organization.py +++ b/backend/app/api/organization.py @@ -1,3 +1,4 @@ +from typing import Any """Organization management API routes (users only).""" import uuid @@ -23,7 +24,7 @@ async def list_users( tenant_id: uuid.UUID | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List users, optionally filtered by tenant.""" query = ( @@ -48,7 +49,7 @@ async def admin_update_user( user_id: uuid.UUID, data: UserUpdate, current_user: User = Depends(get_current_admin), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Admin update user profile.""" result = await query_dao.execute(db, diff --git a/backend/app/api/pages.py b/backend/app/api/pages.py index af2d350fa..39d1f1972 100644 --- a/backend/app/api/pages.py +++ b/backend/app/api/pages.py @@ -1,3 +1,4 @@ +from typing import Any """Public pages API — serves published HTML without authentication.""" import uuid @@ -23,7 +24,7 @@ # ── Public render (NO auth) ──────────────────────────── @public_router.get("/p/{short_id}") -async def render_page(short_id: str, db: AsyncSession = Depends(get_db)): +async def render_page(short_id: str, db: Any = None): """Serve a published HTML page. No authentication required.""" result = await query_dao.execute(db, select(PublishedPage).where(PublishedPage.short_id == short_id) @@ -63,7 +64,7 @@ async def render_page(short_id: str, db: AsyncSession = Depends(get_db)): async def list_pages( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List published pages for an agent.""" from app.core.permissions import check_agent_access diff --git a/backend/app/api/relationships.py b/backend/app/api/relationships.py index 0a43be35b..708b9ccbe 100644 --- a/backend/app/api/relationships.py +++ b/backend/app/api/relationships.py @@ -1,3 +1,4 @@ +from typing import Any """Legacy agent relationship management API. These endpoints are retained for OKR, gateway, and historical compatibility. @@ -129,7 +130,7 @@ def _dedupe_agent_relationships(items: list[AgentRelationshipIn], agent_id: uuid async def get_relationships( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Legacy: get manually stored human relationship rows for this agent.""" from app.models.identity import IdentityProvider @@ -187,7 +188,7 @@ async def search_human_relationship_candidates( agent_id: uuid.UUID, search: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Legacy: search org members that can be stored as relationship rows.""" from app.models.identity import IdentityProvider @@ -297,7 +298,7 @@ async def save_relationships( agent_id: uuid.UUID, data: RelationshipBatchIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Legacy: replace all manually stored human relationship rows.""" _agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -379,7 +380,7 @@ async def delete_relationship( agent_id: uuid.UUID, rel_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Delete a single human relationship.""" _agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -405,7 +406,7 @@ async def search_visible_agents( agent_id: uuid.UUID, search: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Search manageable agent candidates for relationship creation.""" source_agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -445,7 +446,7 @@ async def search_visible_agents( async def get_agent_relationships( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Legacy: get manually stored agent-to-agent relationship rows.""" await check_agent_access(db, current_user, agent_id) @@ -480,7 +481,7 @@ async def get_agent_relationships( async def get_agent_relationship_candidates( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Legacy: backward-compatible alias for searchable agent candidates.""" return await search_visible_agents( @@ -496,7 +497,7 @@ async def save_agent_relationships( agent_id: uuid.UUID, data: AgentRelationshipBatchIn, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Legacy: replace all manually stored agent-to-agent relationship rows.""" source_agent, access_level = await check_agent_access(db, current_user, agent_id) @@ -541,7 +542,7 @@ async def delete_agent_relationship( agent_id: uuid.UUID, rel_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Legacy: delete a single manually stored agent-to-agent relationship row.""" _agent, access_level = await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/schedules.py b/backend/app/api/schedules.py index 43f899350..8faf6a83b 100644 --- a/backend/app/api/schedules.py +++ b/backend/app/api/schedules.py @@ -1,3 +1,4 @@ +from typing import Any """Schedule API — CRUD for agent cron jobs.""" import uuid @@ -55,7 +56,7 @@ class ScheduleOut(BaseModel): async def list_schedules( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all schedules for an agent.""" await check_agent_access(db, current_user, agent_id) @@ -84,7 +85,7 @@ async def create_schedule( agent_id: uuid.UUID, data: ScheduleCreate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new schedule for an agent.""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -116,7 +117,7 @@ async def update_schedule( schedule_id: uuid.UUID, data: ScheduleUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update a schedule.""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -150,7 +151,7 @@ async def delete_schedule( agent_id: uuid.UUID, schedule_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Delete a schedule.""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -173,7 +174,7 @@ async def trigger_schedule( agent_id: uuid.UUID, schedule_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Manually trigger a schedule execution.""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -216,7 +217,7 @@ async def get_schedule_history( agent_id: uuid.UUID, schedule_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get execution history for a schedule from activity logs.""" await check_agent_access(db, current_user, agent_id) diff --git a/backend/app/api/slack.py b/backend/app/api/slack.py index 4f8156de7..170290e62 100644 --- a/backend/app/api/slack.py +++ b/backend/app/api/slack.py @@ -1,3 +1,4 @@ +from typing import Any """Slack Bot Channel API routes.""" import hashlib @@ -34,7 +35,7 @@ async def configure_slack_channel( agent_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Configure Slack bot for an agent. Fields: bot_token, signing_secret.""" agent, _ = await check_agent_access(db, current_user, agent_id) @@ -77,7 +78,7 @@ async def configure_slack_channel( async def get_slack_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) result = await db.execute( @@ -93,7 +94,7 @@ async def get_slack_channel( @router.get("/agents/{agent_id}/slack-channel/webhook-url") -async def get_slack_webhook_url(agent_id: uuid.UUID, request: Request, db: AsyncSession = Depends(get_db)): +async def get_slack_webhook_url(agent_id: uuid.UUID, request: Request, db: Any = None): from app.services.platform_service import platform_service public_base = await platform_service.get_public_base_url(db, request) return {"webhook_url": f"{public_base}/api/channel/slack/{agent_id}/webhook"} @@ -103,7 +104,7 @@ async def get_slack_webhook_url(agent_id: uuid.UUID, request: Request, db: Async async def delete_slack_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -156,7 +157,7 @@ async def _send_slack_messages(bot_token: str, channel: str, text: str) -> None: async def slack_event_webhook( agent_id: uuid.UUID, request: Request, - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Handle Slack Event API callbacks.""" body_bytes = await request.body() diff --git a/backend/app/api/sso.py b/backend/app/api/sso.py index 8dc045336..5cfa18610 100644 --- a/backend/app/api/sso.py +++ b/backend/app/api/sso.py @@ -1,3 +1,4 @@ +from typing import Any import uuid from datetime import datetime, timedelta, timezone from urllib.parse import quote @@ -16,7 +17,7 @@ @router.post("/sso/session") async def create_sso_session( tenant_id: uuid.UUID | None = None, - db: AsyncSession = Depends(get_db) + db: Any = None ): """Create a new SSO scan session for QR code login.""" session = SSOScanSession( @@ -30,7 +31,7 @@ async def create_sso_session( return {"session_id": str(session.id), "expires_at": session.expires_at} @router.get("/sso/session/{sid}/status") -async def get_sso_session_status(sid: uuid.UUID, db: AsyncSession = Depends(get_db)): +async def get_sso_session_status(sid: uuid.UUID, db: Any = None): """Check the status of an SSO scan session.""" result = await query_dao.execute(db, select(SSOScanSession).where(SSOScanSession.id == sid)) session = result.scalar_one_or_none() @@ -71,7 +72,7 @@ async def get_sso_session_status(sid: uuid.UUID, db: AsyncSession = Depends(get_ return response @router.put("/sso/session/{sid}/scan") -async def mark_sso_session_scanned(sid: uuid.UUID, db: AsyncSession = Depends(get_db)): +async def mark_sso_session_scanned(sid: uuid.UUID, db: Any = None): """Optional: Mark session as 'scanned' when the landing page loads on mobile.""" result = await query_dao.execute(db, select(SSOScanSession).where(SSOScanSession.id == sid)) session = result.scalar_one_or_none() @@ -81,7 +82,7 @@ async def mark_sso_session_scanned(sid: uuid.UUID, db: AsyncSession = Depends(ge return {"status": "ok"} @router.get("/sso/config") -async def get_sso_config(sid: uuid.UUID, request: Request, db: AsyncSession = Depends(get_db)): +async def get_sso_config(sid: uuid.UUID, request: Request, db: Any = None): """List active SSO providers with their redirect URLs for the specified session ID.""" # 1. Resolve session to get tenant context res = await query_dao.execute(db, select(SSOScanSession).where(SSOScanSession.id == sid)) diff --git a/backend/app/api/tasks.py b/backend/app/api/tasks.py index d2e0f73e5..14a7364e4 100644 --- a/backend/app/api/tasks.py +++ b/backend/app/api/tasks.py @@ -1,3 +1,4 @@ +from typing import Any """Task management API routes.""" import uuid @@ -34,7 +35,7 @@ async def list_tasks( status_filter: str | None = None, type_filter: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List tasks for an agent.""" await check_agent_access(db, current_user, agent_id) @@ -65,7 +66,7 @@ async def create_task( agent_id: uuid.UUID, data: TaskCreate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new task for an agent.""" agent, _access = await check_agent_access(db, current_user, agent_id) @@ -114,7 +115,7 @@ async def update_task( task_id: uuid.UUID, data: TaskUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update a task.""" await check_agent_access(db, current_user, agent_id) @@ -134,7 +135,7 @@ async def get_task_logs( agent_id: uuid.UUID, task_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get progress logs for a task.""" await check_agent_access(db, current_user, agent_id) @@ -150,7 +151,7 @@ async def add_task_log( task_id: uuid.UUID, data: TaskLogCreate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Add a progress log entry to a task.""" await check_agent_access(db, current_user, agent_id) @@ -165,7 +166,7 @@ async def trigger_task( agent_id: uuid.UUID, task_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Manually trigger a supervision task execution (for testing).""" from app.core.permissions import is_agent_expired diff --git a/backend/app/api/teams.py b/backend/app/api/teams.py index 5c2690aef..d7e951e82 100644 --- a/backend/app/api/teams.py +++ b/backend/app/api/teams.py @@ -1,3 +1,4 @@ +from typing import Any """Microsoft Teams Bot Channel API routes.""" import json @@ -218,7 +219,7 @@ async def configure_teams_channel( agent_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Configure Microsoft Teams bot for an agent. Fields: app_id, app_secret.""" agent, _ = await check_agent_access(db, current_user, agent_id) @@ -280,7 +281,7 @@ async def configure_teams_channel( async def get_teams_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get Microsoft Teams channel configuration for an agent.""" await check_agent_access(db, current_user, agent_id) @@ -301,7 +302,7 @@ async def get_teams_webhook_url( agent_id: uuid.UUID, request: Request, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get the Microsoft Teams webhook URL for an agent.""" await check_agent_access(db, current_user, agent_id) @@ -314,7 +315,7 @@ async def get_teams_webhook_url( async def delete_teams_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Delete Microsoft Teams channel configuration for an agent.""" agent, _ = await check_agent_access(db, current_user, agent_id) @@ -342,7 +343,7 @@ async def delete_teams_channel( async def teams_event_webhook( agent_id: uuid.UUID, request: Request, - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Handle Microsoft Teams Bot Framework callbacks.""" try: diff --git a/backend/app/api/tenants.py b/backend/app/api/tenants.py index 7206fc585..cee8aa859 100644 --- a/backend/app/api/tenants.py +++ b/backend/app/api/tenants.py @@ -1,3 +1,4 @@ +from typing import Any """Tenant (Company) management API. Public endpoints for self-service company creation and joining. @@ -153,7 +154,7 @@ class SelfCreateResponse(BaseModel): async def self_create_company( data: TenantCreate, current_user: User = Depends(get_authenticated_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new company (self-service). The creator becomes org_admin. @@ -254,7 +255,7 @@ class JoinResponse(BaseModel): async def join_company( data: JoinRequest, current_user: User = Depends(get_authenticated_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Join an existing company using an invitation code. @@ -376,7 +377,7 @@ async def join_company( # ─── Registration Config ─────────────────────────────── @router.get("/registration-config") -async def get_registration_config(db: AsyncSession = Depends(get_db)): +async def get_registration_config(db: Any = None): """Public — returns whether self-creation of companies is allowed.""" from app.models.system_settings import SystemSetting result = await query_dao.execute(db, @@ -392,7 +393,7 @@ async def get_registration_config(db: AsyncSession = Depends(get_db)): @router.get("/resolve-by-domain") async def resolve_tenant_by_domain( domain: str, - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Resolve a tenant by its sso_domain or subdomain slug. @@ -460,7 +461,7 @@ async def resolve_tenant_by_domain( @router.get("/", response_model=list[TenantOut]) async def list_tenants( current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all tenants (platform_admin only).""" result = await query_dao.execute(db, select(Tenant).order_by(Tenant.created_at.desc())) @@ -470,7 +471,7 @@ async def list_tenants( @router.get("/me", response_model=TenantOut) async def get_my_tenant( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return the current user's own tenant. Any authenticated member can read this — the wizard and the chat model switcher need default_model_id, which @@ -488,7 +489,7 @@ async def get_my_tenant( @router.get("/me/token-usage") async def get_my_tenant_token_usage( current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Return aggregate token and prompt-cache usage for the current company.""" if not current_user.tenant_id: @@ -529,7 +530,7 @@ def bucket(total: int, cache_read: int, cache_creation: int) -> dict: async def get_tenant( tenant_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get tenant details. Platform admins can view any; org_admins only their own.""" if current_user.role not in ("platform_admin", "org_admin"): @@ -551,7 +552,7 @@ async def update_tenant( tenant_id: uuid.UUID, data: TenantUpdate, current_user: User = Depends(require_role("org_admin", "platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update tenant settings. Platform admins can update any; org_admins only their own.""" if current_user.role == "org_admin": @@ -594,7 +595,7 @@ async def upload_tenant_logo( tenant_id: uuid.UUID, file: UploadFile = File(...), current_user: User = Depends(require_role("org_admin", "platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Upload a cropped square company logo. @@ -636,7 +637,7 @@ async def upload_tenant_logo( async def delete_tenant_logo( tenant_id: uuid.UUID, current_user: User = Depends(require_role("org_admin", "platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Remove a custom company logo and fall back to the generated default.""" tenant = await _get_updateable_tenant(tenant_id, current_user, db) @@ -659,7 +660,7 @@ async def assign_user_to_tenant( user_id: uuid.UUID, role: str = "member", current_user: User = Depends(require_role("platform_admin")), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Assign a user to a tenant with a specific role.""" # Verify tenant @@ -688,7 +689,7 @@ async def assign_user_to_tenant( async def delete_tenant( tenant_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Permanently delete a company and ALL its data. diff --git a/backend/app/api/tools.py b/backend/app/api/tools.py index 8afaf141e..2edcb8d4c 100644 --- a/backend/app/api/tools.py +++ b/backend/app/api/tools.py @@ -1,3 +1,4 @@ +from typing import Any """Tool management API — CRUD for tools and per-agent assignments.""" import uuid @@ -228,7 +229,7 @@ class CategoryConfigUpdate(BaseModel): async def list_tools( tenant_id: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List platform tools scoped by tenant (builtin + tenant-specific).""" _require_tool_manager(current_user) @@ -273,7 +274,7 @@ async def list_tools( async def create_tool( data: ToolCreate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Create a new tool (typically MCP). @@ -326,7 +327,7 @@ class BulkToolUpdateItem(BaseModel): async def update_tools_bulk( updates: list[BulkToolUpdateItem], current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Bulk update the enabled status of multiple tools.""" _require_tool_manager(current_user) @@ -350,7 +351,7 @@ async def update_tool( tool_id: uuid.UUID, data: ToolUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update a tool.""" _require_tool_manager(current_user) @@ -385,7 +386,7 @@ async def update_tool( async def delete_tool( tool_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Delete a tool (only non-builtin).""" _require_tool_manager(current_user) @@ -408,7 +409,7 @@ async def delete_tool( async def get_agent_tools( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get tools for a specific agent with their enabled status.""" # Determine if this is a system agent (e.g. OKR Agent). @@ -497,7 +498,7 @@ async def update_agent_tools( agent_id: uuid.UUID, updates: list[AgentToolUpdate], current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update tool assignments for an agent.""" agent_obj = await _require_agent_tool_manager(db, current_user, agent_id) @@ -541,7 +542,7 @@ async def get_mcp_authorization_status( tool_id: uuid.UUID, response: Response, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Read one assigned Smithery connection for an authorized manager.""" response.headers["Cache-Control"] = "no-store" @@ -652,7 +653,7 @@ class MCPServerUpdate(BaseModel): async def update_mcp_server( data: MCPServerUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Bulk-update the Server URL and API Key for all tools from an MCP server. @@ -704,7 +705,7 @@ async def update_mcp_server( async def list_agent_installed_tools( tenant_id: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Admin endpoint: list user-installed tools scoped by tenant.""" _require_tool_manager(current_user) @@ -756,7 +757,7 @@ async def list_agent_installed_tools( async def delete_agent_tool( agent_tool_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Admin: remove an agent-tool assignment. Also deletes the tool record if no other agents use it.""" _require_tool_manager(current_user) @@ -790,7 +791,7 @@ async def get_agent_tool_config( agent_id: uuid.UUID, tool_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get merged tool config (global defaults + agent overrides) and config_schema. @@ -835,7 +836,7 @@ async def update_agent_tool_config( tool_id: uuid.UUID, data: AgentToolConfigUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Save per-agent config override for a tool.""" agent = await _require_agent_tool_manager(db, current_user, agent_id) @@ -873,7 +874,7 @@ async def update_agent_tool_config( async def get_agent_tools_with_config( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get agent's enabled tools with per-agent config info and config_schema for settings UI. @@ -1016,7 +1017,7 @@ async def get_category_config( agent_id: uuid.UUID, category: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Get shared configuration for a tool category. @@ -1099,7 +1100,7 @@ async def update_category_config( category: str, data: CategoryConfigUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update or create shared configuration for a tool category.""" from app.core.permissions import is_agent_creator @@ -1156,7 +1157,7 @@ async def delete_category_config( agent_id: uuid.UUID, category: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Remove shared configuration for a tool category.""" from app.core.permissions import is_agent_creator @@ -1180,7 +1181,7 @@ async def test_category_config( agent_id: uuid.UUID, category: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Test connectivity for a tool category.""" await _require_agent_tool_manager(db, current_user, agent_id) diff --git a/backend/app/api/users.py b/backend/app/api/users.py index eed9cf409..f3d259b34 100644 --- a/backend/app/api/users.py +++ b/backend/app/api/users.py @@ -1,3 +1,4 @@ +from typing import Any import uuid from fastapi import APIRouter, Depends, HTTPException, status @@ -51,7 +52,7 @@ class UserOut(BaseModel): async def list_users( tenant_id: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """List all users in the specified tenant (admin only).""" if current_user.role not in ("platform_admin", "org_admin"): @@ -106,7 +107,7 @@ async def update_user_quota( user_id: uuid.UUID, data: UserQuotaUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Update a user's quota settings (admin only).""" if current_user.role not in ("platform_admin", "org_admin"): @@ -168,7 +169,7 @@ async def update_user_role( user_id: uuid.UUID, data: RoleUpdate, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Change a user's role within the same company. diff --git a/backend/app/api/wechat.py b/backend/app/api/wechat.py index aa3b87d2c..e9d16bf9b 100644 --- a/backend/app/api/wechat.py +++ b/backend/app/api/wechat.py @@ -1,6 +1,7 @@ """WeChat iLink Bot channel API routes.""" from __future__ import annotations +from typing import Any import asyncio import uuid @@ -57,7 +58,7 @@ async def create_wechat_qrcode( agent_id: uuid.UUID, data: dict | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -84,7 +85,7 @@ async def get_wechat_qrcode_status( qrcode: str, route_tag: str | None = None, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -157,7 +158,7 @@ async def get_wechat_qrcode_image( agent_id: uuid.UUID, url: str, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -177,7 +178,7 @@ async def get_wechat_qrcode_image( async def get_wechat_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) result = await query_dao.execute(db, @@ -196,7 +197,7 @@ async def get_wechat_channel( async def delete_wechat_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): diff --git a/backend/app/api/wecom.py b/backend/app/api/wecom.py index 6876e40c1..5b916f8e6 100644 --- a/backend/app/api/wecom.py +++ b/backend/app/api/wecom.py @@ -1,3 +1,4 @@ +from typing import Any """WeCom (企业微信) Channel API routes. Provides Config CRUD and webhook-based message handling with AES encryption. @@ -111,7 +112,7 @@ def _verify_signature(token: str, timestamp: str, nonce: str, encrypt: str) -> s @router.get("/wecom-verify/{filename}") async def serve_wecom_verify_file( filename: str, - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Serve a WeCom domain verification file. @@ -155,7 +156,7 @@ async def configure_wecom_channel( agent_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Configure WeCom bot for an agent. @@ -246,7 +247,7 @@ async def configure_wecom_channel( async def get_wecom_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) result = await db.execute( @@ -271,7 +272,7 @@ async def get_wecom_channel( async def get_wecom_webhook_url( agent_id: uuid.UUID, request: Request, - db: AsyncSession = Depends(get_db), + db: Any = None, ): public_base = await platform_service.get_public_base_url(db, request) return {"webhook_url": f"{public_base}/api/channel/wecom/{agent_id}/webhook"} @@ -281,7 +282,7 @@ async def get_wecom_webhook_url( async def delete_wecom_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -313,7 +314,7 @@ async def wecom_verify_webhook( timestamp: str = "", nonce: str = "", echostr: str = "", - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Handle WeCom callback URL verification (GET request).""" result = await db.execute( @@ -351,7 +352,7 @@ async def wecom_event_webhook( msg_signature: str = "", timestamp: str = "", nonce: str = "", - db: AsyncSession = Depends(get_db), + db: Any = None, ): """Handle WeCom message callback (POST request with encrypted XML).""" body_bytes = await request.body() @@ -607,7 +608,7 @@ async def _process_wecom_text( async def wecom_callback( code: str, state: str = None, - db: AsyncSession = Depends(get_db), + db: Any = None, ): # 1. Resolve session to get tenant context tenant_id = None diff --git a/backend/app/api/whatsapp.py b/backend/app/api/whatsapp.py index a8d088adc..68fd08c24 100644 --- a/backend/app/api/whatsapp.py +++ b/backend/app/api/whatsapp.py @@ -1,6 +1,7 @@ """WhatsApp Cloud API channel routes.""" from __future__ import annotations +from typing import Any import hashlib import hmac @@ -53,7 +54,7 @@ async def configure_whatsapp_channel( agent_id: uuid.UUID, data: dict, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -105,7 +106,7 @@ async def configure_whatsapp_channel( async def get_whatsapp_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): await check_agent_access(db, current_user, agent_id) result = await db.execute( @@ -121,7 +122,7 @@ async def get_whatsapp_channel( @router.get("/agents/{agent_id}/whatsapp-channel/webhook-url") -async def get_whatsapp_webhook_url(agent_id: uuid.UUID, request: Request, db: AsyncSession = Depends(get_db)): +async def get_whatsapp_webhook_url(agent_id: uuid.UUID, request: Request, db: Any = None): from app.services.platform_service import platform_service public_base = await platform_service.get_public_base_url(db, request) @@ -132,7 +133,7 @@ async def get_whatsapp_webhook_url(agent_id: uuid.UUID, request: Request, db: As async def delete_whatsapp_channel( agent_id: uuid.UUID, current_user: User = Depends(get_current_user), - db: AsyncSession = Depends(get_db), + db: Any = None, ): agent, _ = await check_agent_access(db, current_user, agent_id) if not is_agent_creator(current_user, agent): @@ -156,7 +157,7 @@ async def whatsapp_verify_webhook( hub_mode: str = Query("", alias="hub.mode"), hub_verify_token: str = Query("", alias="hub.verify_token"), hub_challenge: str = Query("", alias="hub.challenge"), - db: AsyncSession = Depends(get_db), + db: Any = None, ): result = await db.execute( select(ChannelConfig).where( @@ -177,7 +178,7 @@ async def whatsapp_verify_webhook( async def whatsapp_event_webhook( agent_id: uuid.UUID, request: Request, - db: AsyncSession = Depends(get_db), + db: Any = None, ): body = await request.body() result = await db.execute(