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

Function get_chat_session

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

Return a chat session with ordered messages.

(user_id: str, session_id: str)

Source from the content-addressed store, hash-verified

447 """
448 UPDATE chat_sessions
449 SET updated_at = ?
450 WHERE user_id = ? AND session_id = ?
451 """,
452 (now, normalized_user_id, normalized_session_id),
453 )
454 cursor.execute(
455 """
456 UPDATE chat_sessions
457 SET message_count = (
458 SELECT COUNT(*)
459 FROM chat_messages
460 WHERE user_id = ? AND session_id = ?
461 )
462 WHERE user_id = ? AND session_id = ?
463 """,
464 (normalized_user_id, normalized_session_id, normalized_user_id, normalized_session_id),
465 )
466 cursor.execute(
467 """
468 SELECT id, session_id, user_id, role, content, metadata, created_at
469 FROM chat_messages
470 WHERE id = ?
471 """,
472 (message_id,),
473 )
474 row = cursor.fetchone()
475 conn.commit()
476 conn.close()
477 message = dict(row)
478 message["metadata"] = _load_json_metadata(message.get("metadata"))
479 return message
480
481
482def list_chat_sessions(user_id: str, days: int = 30, limit: int = 80) -> Dict[str, Any]:
483 """List a user's chat sessions grouped by updated local date."""
484 normalized_user_id = _normalize_identifier(user_id)
485 if not normalized_user_id:
486 raise ValueError("user_id is required")
487
488 ensure_chat_tables()
489 safe_days = max(1, int(days or 30))

Callers

nothing calls this directly

Calls 10

_normalize_identifierFunction · 0.85
ensure_chat_tablesFunction · 0.85
_load_json_metadataFunction · 0.85
_chat_session_rowFunction · 0.85
cursorMethod · 0.80
getMethod · 0.80
get_connectionFunction · 0.70
executeMethod · 0.45
closeMethod · 0.45
fetchallMethod · 0.45

Tested by

no test coverage detected