Add edit/delete history, named sessions, scroll fix, systemd service
- Edit/delete individual messages from session context with inline editing
(Ctrl+Enter saves, Escape cancels); changes sync to backend via PUT /history
- PUT /history/{session_id} endpoint to replace full message list
- Named sessions: readable slugs (e.g. quiet-spring) instead of UUID fragments
- Scroll no longer snaps to bottom when user has scrolled up to read history
- cortex.service: systemd unit for auto-start and restart-on-failure
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import asyncio
|
||||
import json
|
||||
import uuid
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel
|
||||
from context_loader import load_context
|
||||
from llm_client import complete
|
||||
from session_logger import log_turn
|
||||
from session_store import load as load_session, save as save_session, list_all
|
||||
from session_store import load as load_session, save as save_session, list_all, generate_session_id
|
||||
from config import settings
|
||||
|
||||
|
||||
@@ -30,6 +29,10 @@ class NoteRequest(BaseModel):
|
||||
note: str
|
||||
|
||||
|
||||
class HistoryUpdate(BaseModel):
|
||||
messages: list[dict]
|
||||
|
||||
|
||||
async def _stream_chat(req: ChatRequest):
|
||||
"""
|
||||
SSE generator: sends keepalive events every 3s while the LLM works,
|
||||
@@ -42,7 +45,7 @@ async def _stream_chat(req: ChatRequest):
|
||||
"backend": "...", "fallback_used": bool}
|
||||
data: {"type": "error", "message": "..."}
|
||||
"""
|
||||
session_id = req.session_id or str(uuid.uuid4())[:8]
|
||||
session_id = req.session_id or generate_session_id()
|
||||
tier = req.tier or settings.default_tier
|
||||
|
||||
system_prompt = load_context(tier)
|
||||
@@ -131,6 +134,13 @@ async def list_sessions() -> dict:
|
||||
return {"sessions": list_all()}
|
||||
|
||||
|
||||
@router.put("/history/{session_id}")
|
||||
async def replace_history(session_id: str, req: HistoryUpdate) -> dict:
|
||||
"""Replace the full message list for a session (used by edit/delete UI)."""
|
||||
save_session(session_id, req.messages)
|
||||
return {"ok": True, "session_id": session_id}
|
||||
|
||||
|
||||
@router.post("/note")
|
||||
async def add_note(req: NoteRequest) -> dict:
|
||||
"""Inject a public note into session history so the LLM sees it next turn."""
|
||||
|
||||
Reference in New Issue
Block a user