Get a conversation with all its messages.
(project_dir: Path, conversation_id: int)
| 199 | |
| 200 | |
| 201 | def get_conversation(project_dir: Path, conversation_id: int) -> Optional[dict]: |
| 202 | """Get a conversation with all its messages.""" |
| 203 | session = get_session(project_dir) |
| 204 | try: |
| 205 | conversation = session.query(Conversation).filter(Conversation.id == conversation_id).first() |
| 206 | if not conversation: |
| 207 | return None |
| 208 | return { |
| 209 | "id": conversation.id, |
| 210 | "project_name": conversation.project_name, |
| 211 | "title": conversation.title, |
| 212 | "created_at": conversation.created_at.isoformat() if conversation.created_at else None, |
| 213 | "updated_at": conversation.updated_at.isoformat() if conversation.updated_at else None, |
| 214 | "messages": [ |
| 215 | { |
| 216 | "id": m.id, |
| 217 | "role": m.role, |
| 218 | "content": m.content, |
| 219 | "timestamp": m.timestamp.isoformat() if m.timestamp else None, |
| 220 | } |
| 221 | for m in sorted(conversation.messages, key=lambda x: x.timestamp or datetime.min) |
| 222 | ], |
| 223 | } |
| 224 | finally: |
| 225 | session.close() |
| 226 | |
| 227 | |
| 228 | def delete_conversation(project_dir: Path, conversation_id: int) -> bool: |
no test coverage detected