feat: chat folders, attachments, treeview backend - migration, models, routes

This commit is contained in:
Agent Zero
2026-07-17 09:15:39 +02:00
parent 50650f5b17
commit 9a29206190
6 changed files with 343 additions and 3 deletions
@@ -176,3 +176,58 @@ class AIChatMessage(Base, TenantMixin):
tool_results: Mapped[dict | None] = mapped_column(JSONB, nullable=True)
tokens: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
model_used: Mapped[str] = mapped_column(String(200), nullable=False, default="")
# --- Chat Folders ---
class AIChatFolder(Base, TenantMixin):
"""Folder for organizing chat sessions."""
__tablename__ = "ai_chat_folders"
__table_args__ = (
Index("ix_ai_folders_user", "user_id"),
Index("ix_ai_folders_tenant", "tenant_id"),
Index("ix_ai_folders_parent", "parent_id"),
)
id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
)
name: Mapped[str] = mapped_column(String(255), nullable=False)
parent_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True),
ForeignKey("ai_chat_folders.id", ondelete="CASCADE"),
nullable=True,
)
user_id: Mapped[uuid.UUID] = mapped_column(PGUUID(as_uuid=True), nullable=False)
# --- Chat Attachments ---
class AIChatAttachment(Base, TenantMixin):
"""File attached to a chat message."""
__tablename__ = "ai_chat_attachments"
__table_args__ = (
Index("ix_ai_attachments_message", "message_id"),
Index("ix_ai_attachments_session", "session_id"),
Index("ix_ai_attachments_tenant", "tenant_id"),
)
id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True), primary_key=True, default=uuid.uuid4
)
message_id: Mapped[uuid.UUID | None] = mapped_column(
PGUUID(as_uuid=True),
ForeignKey("ai_chat_messages.id", ondelete="CASCADE"),
nullable=True,
)
session_id: Mapped[uuid.UUID] = mapped_column(
PGUUID(as_uuid=True),
ForeignKey("ai_chat_sessions.id", ondelete="CASCADE"),
nullable=False,
)
filename: Mapped[str] = mapped_column(String(255), nullable=False)
mime_type: Mapped[str] = mapped_column(String(255), nullable=False, default="application/octet-stream")
size_bytes: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
storage_path: Mapped[str] = mapped_column(String(1024), nullable=False)