MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / create_chat_session

Function create_chat_session

skills/storage-helper/scripts/db_ops.py:289–326  ·  view source on GitHub ↗

Create or return a persistent GUI chat session.

(
    user_id: str,
    title: str = "",
    session_id: Optional[str] = None,
)

Source from the content-addressed store, hash-verified

287 timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
288 metadata TEXT,
289 FOREIGN KEY (paper_id) REFERENCES papers(id)
290 )
291 """)
292
293 # Create task_status table
294 cursor.execute("""
295 CREATE TABLE IF NOT EXISTS task_status (
296 id INTEGER PRIMARY KEY AUTOINCREMENT,
297 task_id TEXT UNIQUE NOT NULL,
298 task_type TEXT NOT NULL,
299 user_id TEXT,
300 status TEXT NOT NULL,
301 progress_json TEXT,
302 started_at TIMESTAMP,
303 completed_at TIMESTAMP,
304 error_message TEXT
305 )
306 """)
307
308 _create_chat_tables(cursor)
309
310 # Create indexes
311 cursor.execute("CREATE INDEX IF NOT EXISTS idx_papers_arxiv ON papers(arxiv_id)")
312 cursor.execute("CREATE INDEX IF NOT EXISTS idx_papers_doi ON papers(doi)")
313 cursor.execute("CREATE INDEX IF NOT EXISTS idx_papers_pushed ON papers(pushed) WHERE pushed = FALSE")
314 cursor.execute("CREATE INDEX IF NOT EXISTS idx_behavior_user ON behavior_logs(user_id)")
315 cursor.execute("CREATE INDEX IF NOT EXISTS idx_behavior_push ON behavior_logs(push_id)")
316 cursor.execute("CREATE INDEX IF NOT EXISTS idx_behavior_timestamp ON behavior_logs(timestamp)")
317
318 conn.commit()
319 conn.close()
320 print("Database tables created successfully.")
321
322
323# ============== Chat History Operations ==============
324
325def ensure_chat_tables() -> None:
326 """Ensure persistent GUI chat history tables exist for upgraded databases."""
327 conn = get_connection()
328 cursor = conn.cursor()
329 _create_chat_tables(cursor)

Callers 1

save_chat_messageFunction · 0.70

Calls 10

_normalize_identifierFunction · 0.85
ensure_chat_tablesFunction · 0.85
_chat_title_from_contentFunction · 0.85
_chat_nowFunction · 0.85
_chat_session_rowFunction · 0.85
nowMethod · 0.80
cursorMethod · 0.80
get_connectionFunction · 0.70
executeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected