fromtypingimportAny,Literal,CallableimportjsonfrompydanticimportBaseModel,Fieldfromdatetimeimportdatetime,timezonefrompynostr.metadataimportMetadata# noqa: F401classTool(BaseModel):"""Represents a tool that an agent can use to perform a specific action."""fn:Callable[...,Any]name:strdescription:strinput_schema:dict[str,Any]satoshis:int|None=None
[docs]classNoteFilters(BaseModel):"""Filters for filtering Nostr notes/events."""nostr_pubkeys:list[str]|None=None#: Filter by specific public keysnostr_tags:list[str]|None=None#: Filter by specific tagsfollowing_only:bool=False#: Only show notes from followed users (not implemented)
[docs]classSkill(BaseModel):"""Represents a specific capability or service that an agent can perform. A Skill defines a discrete unit of functionality that an agent can provide to other agents or users. Skills are the building blocks of an agent's service offerings and can be priced individually to create a market for agent capabilities. """name:strdescription:strsatoshis:int|None=None
[docs]classAgentCard(BaseModel):"""Represents an agent's profile and capabilities in the Nostr network. An AgentCard is the public identity and capabilities card for an agent in the Nostr network. It contains essential information about the agent's services, pricing, and communication endpoints. """name:strdescription:strskills:list[Skill]=[]satoshis:int|None=Nonenostr_pubkey:str|None=Nonenostr_relays:list[str]=[]
[docs]classUser(BaseModel):"""Simple user model persisted by the database layer."""user_id:stravailable_balance:int=0current_thread_id:str|None=None
[docs]classMessage(BaseModel):"""Represents a message in a chat interaction. This should only be retrieved from the Database, not created manually."""agent_name:strthread_id:struser_id:stridx:intmessage:strcontent:strrole:Literal["user","agent","tool"]kind:Literal["request","requires_payment","tool_message","requires_input","final_response","error"]satoshis:int|None=Noneextra_inputs:dict[str,Any]={}extra_outputs:dict[str,Any]={}created_at:datetime=Field(default_factory=lambda:datetime.now(timezone.utc))
[docs]@classmethoddeffrom_row(cls,row:Any)->"Message":ifrowisNone:raiseValueError("Row cannot be None")defparse_json_field(val):ifvalisNoneorval=="":return{}ifisinstance(val,dict):returnvaltry:returnjson.loads(val)exceptException:return{}created_at=row["created_at"]ifisinstance(created_at,str):try:created_at=datetime.fromisoformat(created_at)exceptException:created_at=datetime.now(timezone.utc)returncls(agent_name=row["agent_name"],thread_id=row["thread_id"],idx=row["idx"],user_id=row["user_id"],role=row["role"],message=row.get("message",""),content=row.get("content",""),kind=row.get("kind","request"),satoshis=row.get("satoshis"),extra_inputs=parse_json_field(row.get("extra_inputs")),extra_outputs=parse_json_field(row.get("extra_outputs")),created_at=created_at.astimezone(timezone.utc)ifhasattr(created_at,"astimezone")elsecreated_at,)
[docs]classChatInput(BaseModel):"""Represents input data for an agent chat interaction."""message:strthread_id:str|None=Noneuser_id:str|None=Noneextra_inputs:dict[str,Any]={}history:list[Message]=[]
[docs]classChatOutput(BaseModel):"""Represents output data for an agent chat interaction."""message:strcontent:strthread_id:str|None=Noneuser_id:str|None=Nonerole:Literal["agent","tool"]="agent"kind:Literal["requires_payment","tool_message","requires_input","final_response","error"]="final_response"satoshis:int|None=Noneextra_outputs:dict[str,Any]={}