diff --git a/src/fabledassistant/models/note.py b/src/fabledassistant/models/note.py index cfdd318..ca12310 100644 --- a/src/fabledassistant/models/note.py +++ b/src/fabledassistant/models/note.py @@ -54,7 +54,8 @@ class Note(Base, TimestampMixin): # Entity type — 'note' (default), 'person', 'place', 'list' note_type: Mapped[str] = mapped_column(Text, default="note", server_default="note") # Structured metadata for entity types (person/place/list) - metadata: Mapped[dict | None] = mapped_column(JSONB, nullable=True) + # Named 'entity_meta' to avoid collision with SQLAlchemy's reserved 'metadata' attribute + entity_meta: Mapped[dict | None] = mapped_column("metadata", JSONB, nullable=True) __table_args__ = ( Index("ix_notes_tags", "tags", postgresql_using="gin"), @@ -97,7 +98,7 @@ class Note(Base, TimestampMixin): ), "is_task": self.is_task, "note_type": self.entity_type, - "metadata": self.metadata or {}, + "metadata": self.entity_meta or {}, "created_at": self.created_at.isoformat(), "updated_at": self.updated_at.isoformat(), } diff --git a/src/fabledassistant/services/knowledge.py b/src/fabledassistant/services/knowledge.py index 14c22ce..11c2d1e 100644 --- a/src/fabledassistant/services/knowledge.py +++ b/src/fabledassistant/services/knowledge.py @@ -12,7 +12,7 @@ _SNIPPET_LEN = 200 def _note_to_item(note: Note) -> dict: - meta = note.metadata or {} + meta = note.entity_meta or {} item: dict = { "id": note.id, "note_type": note.entity_type, @@ -184,14 +184,14 @@ async def get_people_and_places_context(user_id: int) -> str: if people: parts = [] for p in people: - meta = p.metadata or {} + meta = p.entity_meta or {} rel = meta.get("relationship", "") parts.append(f"{p.title}" + (f" ({rel})" if rel else "")) lines.append("Known people: " + ", ".join(parts)) if places: parts = [] for p in places: - meta = p.metadata or {} + meta = p.entity_meta or {} addr = meta.get("address", "") parts.append(f"{p.title}" + (f" – {addr}" if addr else "")) lines.append("Known places: " + "; ".join(parts)) diff --git a/src/fabledassistant/services/notes.py b/src/fabledassistant/services/notes.py index 0ab3788..bcf6323 100644 --- a/src/fabledassistant/services/notes.py +++ b/src/fabledassistant/services/notes.py @@ -58,7 +58,7 @@ async def create_note( due_date: date | None = None, recurrence_rule: dict | None = None, note_type: str = "note", - metadata: dict | None = None, + entity_meta: dict | None = None, ) -> Note: # Auto-populate project_id from milestone when not explicitly provided if milestone_id is not None and project_id is None: @@ -85,7 +85,7 @@ async def create_note( due_date=due_date, recurrence_rule=recurrence_rule, note_type=note_type, - metadata=metadata, + entity_meta=entity_meta, ) session.add(note) await session.commit() diff --git a/src/fabledassistant/services/tools.py b/src/fabledassistant/services/tools.py index fdfe565..4e8b297 100644 --- a/src/fabledassistant/services/tools.py +++ b/src/fabledassistant/services/tools.py @@ -2043,7 +2043,7 @@ async def execute_tool( body="\n".join(body_lines), tags=["person"], note_type="person", - metadata=meta, + entity_meta=meta, ) _schedule_embedding(note.id, user_id, name, note.body) return {"success": True, "type": "person", "data": {"id": note.id, "name": name}} @@ -2075,7 +2075,7 @@ async def execute_tool( body="\n".join(body_lines), tags=["place"], note_type="place", - metadata=meta, + entity_meta=meta, ) _schedule_embedding(note.id, user_id, name, note.body) return {"success": True, "type": "place", "data": {"id": note.id, "name": name}} @@ -2101,7 +2101,7 @@ async def execute_tool( body=body, tags=tags, note_type="list", - metadata=meta, + entity_meta=meta, ) _schedule_embedding(note.id, user_id, name, body) return {"success": True, "type": "list", "data": {"id": note.id, "name": name, "item_count": len(items)}}