73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
"""Participant model - unified participant for users and agents."""
|
|
from datetime import datetime
|
|
from typing import Optional, Dict, Any, TYPE_CHECKING
|
|
from dataclasses import dataclass
|
|
from enum import Enum
|
|
|
|
if TYPE_CHECKING:
|
|
from luxx.models.user import User
|
|
|
|
|
|
class ParticipantType(Enum):
|
|
USER = "user"
|
|
AGENT = "agent"
|
|
|
|
|
|
@dataclass
|
|
class Participant:
|
|
"""Unified participant abstraction for users and agents."""
|
|
participant_id: str
|
|
name: str
|
|
participant_type: ParticipantType
|
|
avatar: Optional[str] = None
|
|
role: Optional[str] = None # ChatRoom role: owner/admin/member
|
|
permission_level: int = 1
|
|
is_active: bool = True
|
|
created_at: Optional[datetime] = None
|
|
|
|
@property
|
|
def is_agent(self) -> bool:
|
|
return self.participant_type == ParticipantType.AGENT
|
|
|
|
@property
|
|
def is_user(self) -> bool:
|
|
return self.participant_type == ParticipantType.USER
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return {
|
|
"id": self.participant_id,
|
|
"name": self.name,
|
|
"type": self.participant_type.value,
|
|
"avatar": self.avatar,
|
|
"role": self.role,
|
|
"permission_level": self.permission_level,
|
|
"is_active": self.is_active,
|
|
"created_at": self.created_at.isoformat() if self.created_at else None
|
|
}
|
|
|
|
@classmethod
|
|
def from_user(cls, user: "User") -> "Participant":
|
|
return cls(
|
|
participant_id=f"user:{user.id}",
|
|
name=user.username,
|
|
participant_type=ParticipantType.USER,
|
|
permission_level=user.permission_level,
|
|
is_active=user.is_active,
|
|
created_at=user.created_at
|
|
)
|
|
|
|
@classmethod
|
|
def from_agent(
|
|
cls, agent_id: str, name: str, role: str = None,
|
|
avatar: str = None, permission_level: int = 1, is_active: bool = True
|
|
) -> "Participant":
|
|
return cls(
|
|
participant_id=f"agent:{agent_id}",
|
|
name=name,
|
|
participant_type=ParticipantType.AGENT,
|
|
role=role,
|
|
avatar=avatar,
|
|
permission_level=permission_level,
|
|
is_active=is_active
|
|
)
|