Coverage for src / harness_utils / models / conversation.py: 93%

15 statements  

« prev     ^ index     » next       coverage.py v7.13.2, created at 2026-01-31 13:47 -0600

1"""Conversation model.""" 

2 

3from dataclasses import dataclass, field 

4from typing import Any 

5 

6 

7@dataclass 

8class Conversation: 

9 """A conversation containing multiple messages. 

10 

11 Conversations track the overall context and metadata for a series 

12 of messages between user and assistant. 

13 """ 

14 

15 id: str 

16 project_id: str | None = None 

17 created: int | None = None # Unix timestamp in milliseconds 

18 updated: int | None = None # Unix timestamp in milliseconds 

19 pending_summarization: bool = False 

20 metadata: dict[str, Any] = field(default_factory=dict) 

21 

22 def to_dict(self) -> dict[str, Any]: 

23 """Convert conversation to dictionary for storage. 

24 

25 Returns: 

26 Dictionary representation 

27 """ 

28 return { 

29 "id": self.id, 

30 "project_id": self.project_id, 

31 "created": self.created, 

32 "updated": self.updated, 

33 "pending_summarization": self.pending_summarization, 

34 "metadata": self.metadata, 

35 } 

36 

37 @classmethod 

38 def from_dict(cls, data: dict[str, Any]) -> "Conversation": 

39 """Create conversation from dictionary. 

40 

41 Args: 

42 data: Dictionary representation 

43 

44 Returns: 

45 Conversation instance 

46 """ 

47 return cls( 

48 id=data["id"], 

49 project_id=data.get("project_id"), 

50 created=data.get("created"), 

51 updated=data.get("updated"), 

52 pending_summarization=data.get("pending_summarization", False), 

53 metadata=data.get("metadata", {}), 

54 )