Brain Service: - Playwright stealth crawler replacing browserless (og:image, Readability, Reddit JSON API) - AI classification with tag definitions and folder assignment - YouTube video download via yt-dlp - Karakeep migration complete (96 items) - Taxonomy management (folders with icons/colors, tags) - Discovery shuffle, sort options, search (Meilisearch + pgvector) - Item tag/folder editing, card color accents RSS Reader Service: - Custom FastAPI reader replacing Miniflux - Feed management (add/delete/refresh), category support - Full article extraction via Readability - Background content fetching for new entries - Mark all read with confirmation - Infinite scroll, retention cleanup (30/60 day) - 17 feeds migrated from Miniflux iOS App (SwiftUI): - Native iOS 17+ app with @Observable architecture - Cookie-based auth, configurable gateway URL - Dashboard with custom background photo + frosted glass widgets - Full fitness module (today/templates/goals/food library) - AI assistant chat (fitness + brain, raw JSON state management) - 120fps ProMotion support AI Assistants (Gateway): - Unified dispatcher with fitness/brain domain detection - Fitness: natural language food logging, photo analysis, multi-item splitting - Brain: save/append/update/delete notes, search & answer, undo support - Madiha user gets fitness-only (brain disabled) Firefox Extension: - One-click save to Brain from any page - Login with platform credentials - Right-click context menu (save page/link/image) - Notes field for URL saves - Signed and published on AMO Other: - Reader bookmark button routes to Brain (was Karakeep) - Fitness food library with "Add" button + add-to-meal popup - Kindle send file size check (25MB SMTP2GO limit) - Atelier UI as default (useAtelierShell=true) - Mobile upload box in nav drawer Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
104 lines
4.4 KiB
Python
104 lines
4.4 KiB
Python
"""SQLAlchemy models for the brain service."""
|
|
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
from pgvector.sqlalchemy import Vector
|
|
from sqlalchemy import (
|
|
Column, String, Text, Integer, Float, DateTime, ForeignKey, Index, text
|
|
)
|
|
from sqlalchemy.dialects.postgresql import JSONB, UUID, ARRAY
|
|
from sqlalchemy.orm import relationship
|
|
|
|
from app.config import OPENAI_EMBED_DIM
|
|
from app.database import Base
|
|
|
|
|
|
def new_id():
|
|
return str(uuid.uuid4())
|
|
|
|
|
|
class Item(Base):
|
|
__tablename__ = "items"
|
|
|
|
id = Column(UUID(as_uuid=False), primary_key=True, default=new_id)
|
|
user_id = Column(String(64), nullable=False, index=True)
|
|
type = Column(String(32), nullable=False, default="link") # link|note|pdf|image|document|file
|
|
title = Column(Text, nullable=True)
|
|
url = Column(Text, nullable=True)
|
|
raw_content = Column(Text, nullable=True) # original user input (note body, etc.)
|
|
extracted_text = Column(Text, nullable=True) # full extracted text from page/doc
|
|
folder_id = Column(UUID(as_uuid=False), ForeignKey("folders.id", ondelete="SET NULL"), nullable=True)
|
|
folder = Column(String(64), nullable=True) # denormalized folder name for fast reads
|
|
tags = Column(ARRAY(String), nullable=True, default=list) # denormalized tag names for fast reads
|
|
summary = Column(Text, nullable=True)
|
|
confidence = Column(Float, nullable=True)
|
|
metadata_json = Column(JSONB, nullable=True, default=dict)
|
|
processing_status = Column(String(32), nullable=False, default="pending") # pending|processing|ready|failed
|
|
processing_error = Column(Text, nullable=True)
|
|
|
|
# Embedding (pgvector)
|
|
embedding = Column(Vector(OPENAI_EMBED_DIM), nullable=True)
|
|
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
# Relationships
|
|
assets = relationship("ItemAsset", back_populates="item", cascade="all, delete-orphan")
|
|
additions = relationship(
|
|
"ItemAddition",
|
|
back_populates="item",
|
|
cascade="all, delete-orphan",
|
|
order_by="ItemAddition.created_at",
|
|
)
|
|
|
|
__table_args__ = (
|
|
Index("ix_items_user_status", "user_id", "processing_status"),
|
|
Index("ix_items_user_folder", "user_id", "folder"),
|
|
Index("ix_items_created", "created_at"),
|
|
)
|
|
|
|
|
|
class ItemAsset(Base):
|
|
__tablename__ = "item_assets"
|
|
|
|
id = Column(UUID(as_uuid=False), primary_key=True, default=new_id)
|
|
item_id = Column(UUID(as_uuid=False), ForeignKey("items.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
asset_type = Column(String(32), nullable=False) # screenshot|archived_html|original_upload|extracted_file
|
|
filename = Column(String(512), nullable=False)
|
|
content_type = Column(String(128), nullable=True)
|
|
size_bytes = Column(Integer, nullable=True)
|
|
storage_path = Column(String(1024), nullable=False) # relative path in storage
|
|
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
# Relationships
|
|
item = relationship("Item", back_populates="assets")
|
|
|
|
|
|
class AppLink(Base):
|
|
"""Placeholder for future cross-app linking (e.g. link a saved item to a trip or task)."""
|
|
__tablename__ = "app_links"
|
|
|
|
id = Column(UUID(as_uuid=False), primary_key=True, default=new_id)
|
|
item_id = Column(UUID(as_uuid=False), ForeignKey("items.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
app = Column(String(64), nullable=False) # trips|tasks|fitness|inventory
|
|
app_entity_id = Column(String(128), nullable=False)
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
|
|
|
|
class ItemAddition(Base):
|
|
__tablename__ = "item_additions"
|
|
|
|
id = Column(UUID(as_uuid=False), primary_key=True, default=new_id)
|
|
item_id = Column(UUID(as_uuid=False), ForeignKey("items.id", ondelete="CASCADE"), nullable=False, index=True)
|
|
user_id = Column(String(64), nullable=False, index=True)
|
|
source = Column(String(32), nullable=False, default="assistant") # assistant|manual
|
|
kind = Column(String(32), nullable=False, default="append") # append
|
|
content = Column(Text, nullable=False)
|
|
metadata_json = Column(JSONB, nullable=True, default=dict)
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
item = relationship("Item", back_populates="additions")
|