feat(editor): implement viewer mode for large documents, switching between 'plate' and 'monaco' editors based on document size

This commit is contained in:
Anish Sarkar 2026-06-05 14:23:18 +05:30
parent c2b8b3ac5e
commit cf8a2d0759
4 changed files with 100 additions and 71 deletions

View file

@ -38,6 +38,8 @@ logger = logging.getLogger(__name__)
router = APIRouter()
EDITOR_PLATE_MAX_BYTES = 2 * 1024 * 1024
@router.get("/search-spaces/{search_space_id}/documents/{document_id}/editor-content")
async def get_editor_content(
@ -84,6 +86,7 @@ async def get_editor_content(
def _build_response(md: str) -> dict:
size_bytes = len(md.encode("utf-8"))
viewer_mode = "monaco" if size_bytes > EDITOR_PLATE_MAX_BYTES else "plate"
truncated = False
output_md = md
if max_length is not None and size_bytes > max_length:
@ -97,6 +100,7 @@ async def get_editor_content(
"content_size_bytes": size_bytes,
"chunk_count": chunk_count,
"truncated": truncated,
"viewer_mode": viewer_mode,
"updated_at": document.updated_at.isoformat()
if document.updated_at
else None,