- Extend Document model with reasoning_type, confidence, reasoning_steps, model_source, tiptap_content fields
- Add new endpoints:
- GET /documents/{id}/reasoning - Get reasoning metadata
- PATCH /documents/{id}/reasoning - Update reasoning metadata
- GET /documents/{id}/reasoning-panel - Get reasoning panel data for UI
- POST /documents/{id}/reasoning-steps - Add reasoning step
- DELETE /documents/{id}/reasoning-steps/{step} - Delete reasoning step
- GET /documents/{id}/content?format=tiptap|markdown - Get content in TipTap or Markdown
- PUT /documents/{id}/content - Update content (supports both TipTap JSON and Markdown)
- Add TipTap to Markdown conversion
- Update database schema with new columns
- Add comprehensive tests for all new endpoints
- All 37 tests passing
42 lines
1.9 KiB
Python
42 lines
1.9 KiB
Python
import uuid
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.database import Base
|
|
|
|
|
|
def generate_uuid() -> str:
|
|
return str(uuid.uuid4())
|
|
|
|
|
|
class ReasoningType(str, Enum):
|
|
CHAIN = "chain"
|
|
IDEA = "idea"
|
|
CONTEXT = "context"
|
|
REFLECTION = "reflection"
|
|
|
|
|
|
class Document(Base):
|
|
__tablename__ = "documents"
|
|
|
|
id: Mapped[str] = mapped_column(String(36), primary_key=True, default=generate_uuid)
|
|
title: Mapped[str] = mapped_column(String(500), nullable=False)
|
|
content: Mapped[str] = mapped_column(Text, nullable=False, default="")
|
|
project_id: Mapped[str] = mapped_column(String(36), ForeignKey("projects.id", ondelete="CASCADE"), nullable=False)
|
|
folder_id: Mapped[str | None] = mapped_column(String(36), ForeignKey("folders.id", ondelete="SET NULL"), nullable=True)
|
|
path: Mapped[str] = mapped_column(Text, nullable=False)
|
|
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
deleted_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
deleted_by: Mapped[str | None] = mapped_column(String(36), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
# Phase 2: Reasoning fields
|
|
reasoning_type: Mapped[str | None] = mapped_column(String(20), nullable=True)
|
|
confidence: Mapped[str | None] = mapped_column(String(10), nullable=True) # Store as string to handle JSON serialization
|
|
reasoning_steps: Mapped[str | None] = mapped_column(Text, nullable=True) # JSON array as text
|
|
model_source: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
tiptap_content: Mapped[str | None] = mapped_column(Text, nullable=True) # JSON object as text
|