From 60744ddfacc051c5f17cff37beaf8ebaa37042de Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Sun, 8 Feb 2026 21:17:26 +0530 Subject: [PATCH] refactor: clean up code formatting and improve readability across multiple files --- backend/app/api/agents.py | 4 +- backend/app/api/board_group_memory.py | 2 +- backend/app/api/board_groups.py | 4 +- backend/app/api/boards.py | 4 +- backend/app/api/deps.py | 4 +- backend/app/api/gateway.py | 2 +- backend/app/api/organizations.py | 12 +- .../app/models/organization_board_access.py | 4 +- .../organization_invite_board_access.py | 4 +- backend/app/services/organizations.py | 7 +- frontend/README.md | 1 + frontend/src/app/agents/[agentId]/page.tsx | 357 +++++++++--------- frontend/src/app/agents/new/page.tsx | 305 +++++++-------- frontend/src/app/agents/page.tsx | 160 ++++---- .../src/app/board-groups/[groupId]/page.tsx | 15 +- frontend/src/app/boards/[boardId]/page.tsx | 21 +- frontend/src/app/boards/new/page.tsx | 2 +- .../app/gateways/[gatewayId]/edit/page.tsx | 204 +++++----- frontend/src/app/gateways/new/page.tsx | 200 +++++----- frontend/src/app/gateways/page.tsx | 170 ++++----- frontend/src/app/invite/page.tsx | 11 +- frontend/src/app/organization/page.tsx | 82 ++-- .../components/organisms/DashboardSidebar.tsx | 7 +- .../src/components/organisms/OrgSwitcher.tsx | 7 +- 24 files changed, 811 insertions(+), 778 deletions(-) diff --git a/backend/app/api/agents.py b/backend/app/api/agents.py index 6d8e5f1e..cf06d1da 100644 --- a/backend/app/api/agents.py +++ b/backend/app/api/agents.py @@ -229,9 +229,7 @@ async def _fetch_agent_events( return list(await session.exec(statement)) -async def _require_user_context( - session: AsyncSession, user: User | None -) -> OrganizationContext: +async def _require_user_context(session: AsyncSession, user: User | None) -> OrganizationContext: if user is None: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) member = await get_active_membership(session, user) diff --git a/backend/app/api/board_group_memory.py b/backend/app/api/board_group_memory.py index 66379ac4..975ebb10 100644 --- a/backend/app/api/board_group_memory.py +++ b/backend/app/api/board_group_memory.py @@ -33,6 +33,7 @@ from app.models.gateways import Gateway from app.models.users import User from app.schemas.board_group_memory import BoardGroupMemoryCreate, BoardGroupMemoryRead from app.schemas.pagination import DefaultLimitOffsetPage +from app.services.mentions import extract_mentions, matches_agent_mention from app.services.organizations import ( OrganizationContext, is_org_admin, @@ -40,7 +41,6 @@ from app.services.organizations import ( member_all_boards_read, member_all_boards_write, ) -from app.services.mentions import extract_mentions, matches_agent_mention router = APIRouter(tags=["board-group-memory"]) diff --git a/backend/app/api/board_groups.py b/backend/app/api/board_groups.py index ccd80d19..71a5d4b5 100644 --- a/backend/app/api/board_groups.py +++ b/backend/app/api/board_groups.py @@ -83,9 +83,7 @@ async def list_board_groups( ctx=Depends(require_org_member), ) -> DefaultLimitOffsetPage[BoardGroupRead]: if member_all_boards_read(ctx.member): - statement = select(BoardGroup).where( - col(BoardGroup.organization_id) == ctx.organization.id - ) + statement = select(BoardGroup).where(col(BoardGroup.organization_id) == ctx.organization.id) else: accessible_boards = select(Board.board_group_id).where( board_access_filter(ctx.member, write=False) diff --git a/backend/app/api/boards.py b/backend/app/api/boards.py index b236de0f..1d97ad93 100644 --- a/backend/app/api/boards.py +++ b/backend/app/api/boards.py @@ -129,7 +129,9 @@ async def _apply_board_update( ) -> Board: updates = payload.model_dump(exclude_unset=True) if "gateway_id" in updates: - await _require_gateway(session, updates["gateway_id"], organization_id=board.organization_id) + await _require_gateway( + session, updates["gateway_id"], organization_id=board.organization_id + ) if "board_group_id" in updates and updates["board_group_id"] is not None: await _require_board_group( session, diff --git a/backend/app/api/deps.py b/backend/app/api/deps.py index 6f9b135f..d76c9f18 100644 --- a/backend/app/api/deps.py +++ b/backend/app/api/deps.py @@ -11,9 +11,10 @@ from app.core.auth import AuthContext, get_auth_context, get_auth_context_option from app.db.session import get_session from app.models.agents import Agent from app.models.boards import Board +from app.models.organizations import Organization from app.models.tasks import Task from app.models.users import User -from app.models.organizations import Organization +from app.services.admin_access import require_admin from app.services.organizations import ( OrganizationContext, ensure_member_for_user, @@ -21,7 +22,6 @@ from app.services.organizations import ( is_org_admin, require_board_access, ) -from app.services.admin_access import require_admin def require_admin_auth(auth: AuthContext = Depends(get_auth_context)) -> AuthContext: diff --git a/backend/app/api/gateway.py b/backend/app/api/gateway.py index cbed4bbb..83dcd6dd 100644 --- a/backend/app/api/gateway.py +++ b/backend/app/api/gateway.py @@ -21,7 +21,6 @@ from app.integrations.openclaw_gateway_protocol import ( ) from app.models.boards import Board from app.models.gateways import Gateway -from app.services.organizations import OrganizationContext, require_board_access from app.schemas.common import OkResponse from app.schemas.gateway_api import ( GatewayCommandsResponse, @@ -32,6 +31,7 @@ from app.schemas.gateway_api import ( GatewaySessionsResponse, GatewaysStatusResponse, ) +from app.services.organizations import OrganizationContext, require_board_access router = APIRouter(prefix="/gateways", tags=["gateways"]) diff --git a/backend/app/api/organizations.py b/backend/app/api/organizations.py index 73940f00..84195c7e 100644 --- a/backend/app/api/organizations.py +++ b/backend/app/api/organizations.py @@ -23,6 +23,7 @@ from app.models.organizations import Organization from app.models.users import User from app.schemas.organizations import ( OrganizationActiveUpdate, + OrganizationBoardAccessRead, OrganizationCreate, OrganizationInviteAccept, OrganizationInviteCreate, @@ -31,7 +32,6 @@ from app.schemas.organizations import ( OrganizationMemberAccessUpdate, OrganizationMemberRead, OrganizationMemberUpdate, - OrganizationBoardAccessRead, OrganizationRead, OrganizationUserRead, ) @@ -39,8 +39,8 @@ from app.schemas.pagination import DefaultLimitOffsetPage from app.services.organizations import ( OrganizationContext, accept_invite, - apply_invite_to_member, apply_invite_board_access, + apply_invite_to_member, apply_member_access_update, get_active_membership, get_member, @@ -298,9 +298,7 @@ async def create_org_invite( raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY) existing_user = ( - await session.exec( - select(User).where(func.lower(col(User.email)) == email) - ) + await session.exec(select(User).where(func.lower(col(User.email)) == email)) ).first() if existing_user is not None: existing_member = await get_member( @@ -380,7 +378,9 @@ async def accept_org_invite( if invite is None: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND) if invite.invited_email and auth.user.email: - if normalize_invited_email(invite.invited_email) != normalize_invited_email(auth.user.email): + if normalize_invited_email(invite.invited_email) != normalize_invited_email( + auth.user.email + ): raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) existing = await get_member( diff --git a/backend/app/models/organization_board_access.py b/backend/app/models/organization_board_access.py index 720edd05..a846a4f4 100644 --- a/backend/app/models/organization_board_access.py +++ b/backend/app/models/organization_board_access.py @@ -20,9 +20,7 @@ class OrganizationBoardAccess(SQLModel, table=True): ) id: UUID = Field(default_factory=uuid4, primary_key=True) - organization_member_id: UUID = Field( - foreign_key="organization_members.id", index=True - ) + organization_member_id: UUID = Field(foreign_key="organization_members.id", index=True) board_id: UUID = Field(foreign_key="boards.id", index=True) can_read: bool = Field(default=True) can_write: bool = Field(default=False) diff --git a/backend/app/models/organization_invite_board_access.py b/backend/app/models/organization_invite_board_access.py index f164df68..3c85019f 100644 --- a/backend/app/models/organization_invite_board_access.py +++ b/backend/app/models/organization_invite_board_access.py @@ -20,9 +20,7 @@ class OrganizationInviteBoardAccess(SQLModel, table=True): ) id: UUID = Field(default_factory=uuid4, primary_key=True) - organization_invite_id: UUID = Field( - foreign_key="organization_invites.id", index=True - ) + organization_invite_id: UUID = Field(foreign_key="organization_invites.id", index=True) board_id: UUID = Field(foreign_key="boards.id", index=True) can_read: bool = Field(default=True) can_write: bool = Field(default=False) diff --git a/backend/app/services/organizations.py b/backend/app/services/organizations.py index 132a38f6..08468e2a 100644 --- a/backend/app/services/organizations.py +++ b/backend/app/services/organizations.py @@ -79,9 +79,7 @@ async def set_active_organization( user: User, organization_id: UUID, ) -> OrganizationMember: - member = await get_member( - session, user_id=user.id, organization_id=organization_id - ) + member = await get_member(session, user_id=user.id, organization_id=organization_id) if member is None: raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="No org access") if user.active_organization_id != organization_id: @@ -199,8 +197,7 @@ async def ensure_member_for_user(session: AsyncSession, user: User) -> Organizat now = utcnow() member_count = ( await session.exec( - select(func.count()) - .where(col(OrganizationMember.organization_id) == org.id) + select(func.count()).where(col(OrganizationMember.organization_id) == org.id) ) ).one() is_first = int(member_count or 0) == 0 diff --git a/frontend/README.md b/frontend/README.md index 0f0a32f7..45654440 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -162,6 +162,7 @@ Clerk should be **off** unless you set a real `pk_test_...` or `pk_live_...` pub If you see repeated proxy errors (often `ECONNRESET`), make sure your dev server hostname and browser URL match (e.g. `localhost` vs `127.0.0.1`), and that your origin is included in `allowedDevOrigins`. Notes: + - Local dev should work via `http://localhost:3000` and `http://127.0.0.1:3000`. - LAN dev should work via the configured LAN IP (e.g. `http://192.168.1.101:3000`) **only** if you bind the dev server to all interfaces (`npm run dev:lan`). - If you bind Next to `127.0.0.1` only, remote LAN clients won’t connect. diff --git a/frontend/src/app/agents/[agentId]/page.tsx b/frontend/src/app/agents/[agentId]/page.tsx index e2daf9f7..ca9dfe81 100644 --- a/frontend/src/app/agents/[agentId]/page.tsx +++ b/frontend/src/app/agents/[agentId]/page.tsx @@ -212,190 +212,193 @@ export default function AgentDetailPage() { ) : (
-
-
-

- Agents -

-

- {agent?.name ?? "Agent"} -

-

- Review agent health, session binding, and recent activity. -

-
-
- - {agent ? ( - - Edit - - ) : null} - {agent ? ( - - ) : null} -
-
- - {error ? ( -
- {error} -
- ) : null} - - {isLoading ? ( -
- Loading agent details… -
- ) : agent ? ( -
-
-
-
-
-

- Overview -

-

- {agent.name} -

-
- -
-
-
-

- Agent ID -

-

{agent.id}

-
-
-

- Session key -

-

- {agent.openclaw_session_id ?? "—"} -

-
-
-

- Board -

- {agent.is_gateway_main ? ( -

- Gateway main (no board) -

- ) : linkedBoard ? ( - - {linkedBoard.name} - - ) : ( -

- )} -
-
-

- Last seen -

-

- {formatRelative(agent.last_seen_at)} -

-

- {formatTimestamp(agent.last_seen_at)} -

-
-
-

- Updated -

-

- {formatTimestamp(agent.updated_at)} -

-
-
-

- Created -

-

- {formatTimestamp(agent.created_at)} -

-
-
-
- -
-
-

- Health -

- -
-
-
- Heartbeat window - {formatRelative(agent.last_seen_at)} -
-
- Session binding - - {agent.openclaw_session_id ? "Bound" : "Unbound"} - -
-
- Status - {agentStatus} -
-
-
+
+
+

+ Agents +

+

+ {agent?.name ?? "Agent"} +

+

+ Review agent health, session binding, and recent activity. +

+
+ + {agent ? ( + + Edit + + ) : null} + {agent ? ( + + ) : null} +
+
-
-
-

- Activity -

-

- {agentEvents.length} events -

-
-
- {agentEvents.length === 0 ? ( -
- No activity yet for this agent. -
- ) : ( - agentEvents.map((event) => ( -
-

- {event.message ?? event.event_type} + {error ? ( +

+ {error} +
+ ) : null} + + {isLoading ? ( +
+ Loading agent details… +
+ ) : agent ? ( +
+
+
+
+
+

+ Overview

-

- {formatTimestamp(event.created_at)} +

+ {agent.name}

- )) - )} + +
+
+
+

+ Agent ID +

+

{agent.id}

+
+
+

+ Session key +

+

+ {agent.openclaw_session_id ?? "—"} +

+
+
+

+ Board +

+ {agent.is_gateway_main ? ( +

+ Gateway main (no board) +

+ ) : linkedBoard ? ( + + {linkedBoard.name} + + ) : ( +

+ )} +
+
+

+ Last seen +

+

+ {formatRelative(agent.last_seen_at)} +

+

+ {formatTimestamp(agent.last_seen_at)} +

+
+
+

+ Updated +

+

+ {formatTimestamp(agent.updated_at)} +

+
+
+

+ Created +

+

+ {formatTimestamp(agent.created_at)} +

+
+
+
+ +
+
+

+ Health +

+ +
+
+
+ Heartbeat window + {formatRelative(agent.last_seen_at)} +
+
+ Session binding + + {agent.openclaw_session_id ? "Bound" : "Unbound"} + +
+
+ Status + {agentStatus} +
+
+
+
+ +
+
+

+ Activity +

+

+ {agentEvents.length} events +

+
+
+ {agentEvents.length === 0 ? ( +
+ No activity yet for this agent. +
+ ) : ( + agentEvents.map((event) => ( +
+

+ {event.message ?? event.event_type} +

+

+ {formatTimestamp(event.created_at)} +

+
+ )) + )} +
-
- ) : ( -
- Agent not found. -
- )} + ) : ( +
+ Agent not found. +
+ )}
)} diff --git a/frontend/src/app/agents/new/page.tsx b/frontend/src/app/agents/new/page.tsx index 57caa47f..cbf81435 100644 --- a/frontend/src/app/agents/new/page.tsx +++ b/frontend/src/app/agents/new/page.tsx @@ -214,184 +214,189 @@ export default function NewAgentPage() { Basic configuration

-
-
- - setName(event.target.value)} - placeholder="e.g. Deploy bot" - disabled={isLoading} - /> +
+
+ + setName(event.target.value)} + placeholder="e.g. Deploy bot" + disabled={isLoading} + /> +
+
+ + + setIdentityProfile((current) => ({ + ...current, + role: event.target.value, + })) + } + placeholder="e.g. Founder, Social Media Manager" + disabled={isLoading} + /> +
+
+
+ + + {boards.length === 0 ? ( +

+ Create a board before adding agents. +

+ ) : null} +
+
+ + +
+
+
+
+ +
+

+ Personality & behavior +

+
setIdentityProfile((current) => ({ ...current, - role: event.target.value, + communication_style: event.target.value, })) } - placeholder="e.g. Founder, Social Media Manager" + disabled={isLoading} + /> +
+
+ +