MVP 0.9
This commit is contained in:
1 parent
a8caeb0dd4
commit
fd7102e3b3
95 files changed
+16520
-193
No files matched your search
+127
-4
@@ -81,19 +81,36 @@ def thread_snapshot(profile_id: str) -> list[dict]:
|
||||
return [row_to_dict(row) for row in rows]
|
||||
|
||||
|
||||
def create_conversation(profile_id: str, usage_session_id: str | None = None, title: str = "") -> dict:
|
||||
def create_conversation(
|
||||
profile_id: str,
|
||||
usage_session_id: str | None = None,
|
||||
title: str = "",
|
||||
space_id: str | None = None,
|
||||
journal_day_id: str | None = None,
|
||||
) -> dict:
|
||||
conversation_id = str(uuid.uuid4())
|
||||
with get_db() as conn:
|
||||
if usage_session_id:
|
||||
session = _owned(conn, "usage_sessions", usage_session_id, profile_id)
|
||||
if not session:
|
||||
raise StoreError("not_found", "Nutzungssitzung nicht gefunden", 404)
|
||||
if space_id and not _owned(conn, "spaces", space_id, profile_id):
|
||||
raise StoreError("not_found", "Reflection Space nicht gefunden", 404)
|
||||
if journal_day_id:
|
||||
day = _owned(conn, "journal_days", journal_day_id, profile_id)
|
||||
if not day:
|
||||
raise StoreError("not_found", "Journal Day nicht gefunden", 404)
|
||||
if space_id and day["space_id"] != space_id:
|
||||
raise StoreError("assignment_mismatch", "Journal Day gehört zu einem anderen Space")
|
||||
space_id = space_id or day["space_id"]
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO conversations (id, profile_id, usage_session_id, title)
|
||||
VALUES (?, ?, ?, ?)
|
||||
INSERT INTO conversations
|
||||
(id, profile_id, usage_session_id, title, space_id, journal_day_id,
|
||||
narrative_mode, reflection_depth, current_focus)
|
||||
VALUES (?, ?, ?, ?, ?, ?, '', '', '')
|
||||
""",
|
||||
(conversation_id, profile_id, usage_session_id, title or ""),
|
||||
(conversation_id, profile_id, usage_session_id, title or "", space_id, journal_day_id),
|
||||
)
|
||||
return row_to_dict(conn.execute("SELECT * FROM conversations WHERE id = ?", (conversation_id,)).fetchone())
|
||||
|
||||
@@ -106,6 +123,29 @@ def get_conversation(profile_id: str, conversation_id: str) -> dict:
|
||||
return conv
|
||||
|
||||
|
||||
def update_conversation_signals(profile_id: str, conversation_id: str, signals: dict) -> dict:
|
||||
get_conversation(profile_id, conversation_id)
|
||||
with get_db() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE conversations
|
||||
SET narrative_mode = ?, reflection_depth = ?, current_focus = ?,
|
||||
emotional_intensity = ?, long_story = ?, updated = datetime('now')
|
||||
WHERE id = ? AND profile_id = ?
|
||||
""",
|
||||
(
|
||||
(signals.get("narrative_mode") or "")[:40],
|
||||
(signals.get("reflection_depth") or "")[:40],
|
||||
(signals.get("current_focus") or "")[:200],
|
||||
(signals.get("emotional_intensity") or "")[:40],
|
||||
1 if signals.get("long_story") else 0,
|
||||
conversation_id,
|
||||
profile_id,
|
||||
),
|
||||
)
|
||||
return get_conversation(profile_id, conversation_id)
|
||||
|
||||
|
||||
def list_conversations(profile_id: str) -> list[dict]:
|
||||
with get_db() as conn:
|
||||
rows = conn.execute(
|
||||
@@ -223,6 +263,89 @@ def create_space(profile_id: str, title: str = "", visibility: str = "internal")
|
||||
return row_to_dict(conn.execute("SELECT * FROM spaces WHERE id = ?", (space_id,)).fetchone())
|
||||
|
||||
|
||||
def get_space(profile_id: str, space_id: str) -> dict:
|
||||
with get_db() as conn:
|
||||
space = _owned(conn, "spaces", space_id, profile_id)
|
||||
if not space:
|
||||
raise StoreError("not_found", "Reflection Space nicht gefunden", 404)
|
||||
return space
|
||||
|
||||
|
||||
def list_spaces(profile_id: str, visibility: str | None = "user") -> list[dict]:
|
||||
with get_db() as conn:
|
||||
if visibility:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT * FROM spaces
|
||||
WHERE profile_id = ? AND visibility = ?
|
||||
ORDER BY updated DESC, created DESC
|
||||
""",
|
||||
(profile_id, visibility),
|
||||
).fetchall()
|
||||
else:
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM spaces WHERE profile_id = ? ORDER BY updated DESC, created DESC",
|
||||
(profile_id,),
|
||||
).fetchall()
|
||||
return [row_to_dict(row) for row in rows]
|
||||
|
||||
|
||||
def rename_space(profile_id: str, space_id: str, title: str) -> dict:
|
||||
if not (title or "").strip():
|
||||
raise StoreError("empty_title", "Space-Name darf nicht leer sein")
|
||||
with get_db() as conn:
|
||||
if not _owned(conn, "spaces", space_id, profile_id):
|
||||
raise StoreError("not_found", "Reflection Space nicht gefunden", 404)
|
||||
conn.execute(
|
||||
"UPDATE spaces SET title = ?, updated = datetime('now') WHERE id = ? AND profile_id = ?",
|
||||
(title.strip(), space_id, profile_id),
|
||||
)
|
||||
return row_to_dict(
|
||||
conn.execute("SELECT * FROM spaces WHERE id = ? AND profile_id = ?", (space_id, profile_id)).fetchone()
|
||||
)
|
||||
|
||||
|
||||
def delete_conversation(profile_id: str, conversation_id: str) -> dict:
|
||||
with get_db() as conn:
|
||||
conv = _owned(conn, "conversations", conversation_id, profile_id)
|
||||
if not conv:
|
||||
raise StoreError("not_found", "Conversation nicht gefunden", 404)
|
||||
conn.execute(
|
||||
"""
|
||||
UPDATE handoffs SET source_conversation_id = NULL
|
||||
WHERE profile_id = ? AND source_conversation_id = ?
|
||||
""",
|
||||
(profile_id, conversation_id),
|
||||
)
|
||||
conn.execute(
|
||||
"""
|
||||
DELETE FROM derived_records
|
||||
WHERE profile_id = ? AND subject_type = 'conversation' AND subject_id = ?
|
||||
""",
|
||||
(profile_id, conversation_id),
|
||||
)
|
||||
conn.execute(
|
||||
"DELETE FROM conversations WHERE id = ? AND profile_id = ?",
|
||||
(conversation_id, profile_id),
|
||||
)
|
||||
return {"id": conversation_id, "deleted": True}
|
||||
|
||||
|
||||
def list_conversations_for_day(profile_id: str, journal_day_id: str) -> list[dict]:
|
||||
with get_db() as conn:
|
||||
rows = conn.execute(
|
||||
"""
|
||||
SELECT c.*,
|
||||
(SELECT COUNT(*) FROM messages m WHERE m.conversation_id = c.id) AS message_count
|
||||
FROM conversations c
|
||||
WHERE c.profile_id = ? AND c.journal_day_id = ?
|
||||
ORDER BY c.created
|
||||
""",
|
||||
(profile_id, journal_day_id),
|
||||
).fetchall()
|
||||
return [row_to_dict(row) for row in rows]
|
||||
|
||||
|
||||
def link_thread_space(profile_id: str, thread_id: str, space_id: str, confidence: float | None = None) -> dict:
|
||||
with get_db() as conn:
|
||||
if not _owned(conn, "threads", thread_id, profile_id):
|
||||
|
||||
Reference in new issue
Block a user