mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-06 22:12:12 +02:00
Hard cutover of the HTTP surface: collapse the three legacy spellings
(/searchspaces, /search-spaces, /search-space/{id}) onto canonical
/workspaces/{workspace_id}/..., rename the gateway field-setter sub-actions to
singular /workspace, rename search_spaces_routes.py -> workspaces_routes.py and the
search_spaces_router -> workspaces_router include, and flip search_space_id ->
workspace_id in bodies/params. No alias routers: the old URLs now 404 by design.
Full app constructs with zero legacy path spellings.
77 lines
2.3 KiB
Python
77 lines
2.3 KiB
Python
"""Routes for workspace team memory."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from pydantic import BaseModel
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.auth.context import AuthContext
|
|
from app.db import get_async_session
|
|
from app.services.memory import (
|
|
MemoryRead,
|
|
MemoryScope,
|
|
memory_limits,
|
|
read_memory,
|
|
reset_memory,
|
|
save_memory,
|
|
)
|
|
from app.users import get_auth_context
|
|
from app.utils.rbac import check_workspace_access
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class TeamMemoryUpdate(BaseModel):
|
|
memory_md: str
|
|
|
|
|
|
@router.get("/workspaces/{workspace_id}/memory", response_model=MemoryRead)
|
|
async def get_team_memory(
|
|
workspace_id: int,
|
|
session: AsyncSession = Depends(get_async_session),
|
|
auth: AuthContext = Depends(get_auth_context),
|
|
):
|
|
await check_workspace_access(session, auth, workspace_id)
|
|
memory_md = await read_memory(
|
|
scope=MemoryScope.TEAM,
|
|
target_id=workspace_id,
|
|
session=session,
|
|
)
|
|
return MemoryRead(memory_md=memory_md, limits=memory_limits())
|
|
|
|
|
|
@router.put("/workspaces/{workspace_id}/memory", response_model=MemoryRead)
|
|
async def update_team_memory(
|
|
workspace_id: int,
|
|
body: TeamMemoryUpdate,
|
|
session: AsyncSession = Depends(get_async_session),
|
|
auth: AuthContext = Depends(get_auth_context),
|
|
):
|
|
await check_workspace_access(session, auth, workspace_id)
|
|
result = await save_memory(
|
|
scope=MemoryScope.TEAM,
|
|
target_id=workspace_id,
|
|
content=body.memory_md,
|
|
session=session,
|
|
)
|
|
if result.status == "error":
|
|
raise HTTPException(status_code=400, detail=result.message)
|
|
return MemoryRead(memory_md=result.memory_md, limits=memory_limits())
|
|
|
|
|
|
@router.post("/workspaces/{workspace_id}/memory/reset", response_model=MemoryRead)
|
|
async def reset_team_memory(
|
|
workspace_id: int,
|
|
session: AsyncSession = Depends(get_async_session),
|
|
auth: AuthContext = Depends(get_auth_context),
|
|
):
|
|
await check_workspace_access(session, auth, workspace_id)
|
|
result = await reset_memory(
|
|
scope=MemoryScope.TEAM,
|
|
target_id=workspace_id,
|
|
session=session,
|
|
)
|
|
if result.status == "error":
|
|
raise HTTPException(status_code=400, detail=result.message)
|
|
return MemoryRead(memory_md=result.memory_md, limits=memory_limits())
|