h-message-bus 0.0.26__py3-none-any.whl → 0.0.27__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. h_message_bus/domain/models/request_message_topic.py +23 -1
  2. h_message_bus/domain/models/twitter_message_metadata.py +31 -0
  3. h_message_bus/domain/request_messages/graph_clear_request_message.py +26 -0
  4. h_message_bus/domain/request_messages/graph_get_all_request_message.py +27 -0
  5. h_message_bus/domain/request_messages/graph_get_all_result_response_message.py +45 -0
  6. h_message_bus/domain/request_messages/graph_node_add_request_message.py +64 -0
  7. h_message_bus/domain/request_messages/graph_node_added_response_message.py +69 -0
  8. h_message_bus/domain/request_messages/graph_node_get_request_message.py +39 -0
  9. h_message_bus/domain/request_messages/graph_node_get_result_response_message.py +70 -0
  10. h_message_bus/domain/request_messages/graph_node_update_request_message.py +56 -0
  11. h_message_bus/domain/request_messages/graph_nodes_by_property_request_message.py +45 -0
  12. h_message_bus/domain/request_messages/graph_nodes_by_property_response_message.py +80 -0
  13. h_message_bus/domain/request_messages/graph_query_request_message.py +48 -0
  14. h_message_bus/domain/request_messages/graph_relationship_added_request_message.py +63 -0
  15. h_message_bus/domain/request_messages/tg_message_request_message.py +1 -1
  16. h_message_bus/domain/request_messages/tg_user_message_reply_request_message.py +1 -1
  17. h_message_bus/domain/request_messages/twitter_user_tweets_request_message.py +63 -0
  18. h_message_bus/domain/request_messages/twitter_user_tweets_response_message.py +89 -0
  19. {h_message_bus-0.0.26.dist-info → h_message_bus-0.0.27.dist-info}/METADATA +1 -1
  20. {h_message_bus-0.0.26.dist-info → h_message_bus-0.0.27.dist-info}/RECORD +22 -7
  21. {h_message_bus-0.0.26.dist-info → h_message_bus-0.0.27.dist-info}/WHEEL +0 -0
  22. {h_message_bus-0.0.26.dist-info → h_message_bus-0.0.27.dist-info}/top_level.txt +0 -0
@@ -32,6 +32,8 @@ class RequestMessageTopic(str, Enum):
32
32
  TWITTER_GET_USER_RESPONSE = "hai.twitter.get.user.response"
33
33
  TWITTER_GET_USERS = "hai.twitter.get.users"
34
34
  TWITTER_GET_USERS_RESPONSE = "hai.twitter.get.users.response"
35
+ TWITTER_GET_USER_TWEETS = "hai.twitter.get.user.tweets"
36
+ TWITTER_GET_USER_TWEETS_RESPONSE = "hai.twitter.get.user.tweets.response"
35
37
 
36
38
  TWITTER_USER_SEND_AI_CHAT_SEND = "hai.twitter.user.chat.send"
37
39
  TWITTER_USER_SEND_AI_CHAT_SEND_RESPONSE = "hai.twitter.user.chat.send.response"
@@ -44,4 +46,24 @@ class RequestMessageTopic(str, Enum):
44
46
  WEB_GET_DOCS_RESPONSE = "hai.tools.web.get.docs.response"
45
47
 
46
48
  WEB_FIND_RELATED = "hai.tools.web.find.related"
47
- WEB_FIND_RELATED_RESPONSE = "hai.tools.web.find.related.response"
49
+ WEB_FIND_RELATED_RESPONSE = "hai.tools.web.find.related.response"
50
+
51
+ GRAPH_NODE_ADD = "hai.graph.node.add"
52
+ GRAPH_NODE_UPDATE = "hai.graph.node.update"
53
+ GRAPH_NODE_GET = "hai.graph.node.get"
54
+ GRAPH_NODE_DELETE = "hai.graph.node.delete"
55
+ GRAPH_RELATIONSHIP_ADD = "hai.graph.relationship.add"
56
+ GRAPH_RELATIONSHIP_DELETE = "hai.graph.relationship.delete"
57
+ GRAPH_QUERY = "hai.graph.query"
58
+ GRAPH_CLEAR = "hai.graph.clear"
59
+ GRAPH_GET_ALL = "hai.graph.get.all"
60
+ GRAPH_NODES_BY_PROPERTY = "hai.graph.nodes.by.property"
61
+
62
+ GRAPH_NODE_ADD_RESPONSE = "hai.graph.node.add.response"
63
+ GRAPH_NODE_UPDATE_RESPONSE = "hai.graph.node.update.response"
64
+ GRAPH_NODE_GET_RESPONSE = "hai.graph.node.get.response"
65
+ GRAPH_RELATIONSHIP_ADD_RESPONSE = "hai.graph.relationship.add.response"
66
+ GRAPH_QUERY_RESPONSE = "hai.graph.query.response"
67
+ GRAPH_CLEAR_RESPONSE = "hai.graph.clear.response"
68
+ GRAPH_GET_ALL_RESPONSE = "hai.graph.get.all.response"
69
+ GRAPH_NODES_BY_PROPERTY_RESPONSE = "hai.graph.nodes.by.property.response"
@@ -0,0 +1,31 @@
1
+ from src.h_message_bus.domain.models.twitter_user_metadata import TwitterUserMetadata
2
+
3
+
4
+ class TwitterMessageMetaData:
5
+ def __init__(self, tweet_id: str, user: TwitterUserMetadata, message: str, created_at: str, view_count: int, retweet_count: int, reply_count: int):
6
+ self.tweet_id = tweet_id
7
+ self.message = message
8
+ self.user = user
9
+ self.created_at = created_at,
10
+ self.view_count = view_count
11
+ self.retweet_count = retweet_count
12
+ self.reply_count = reply_count
13
+
14
+ def to_dict(self) -> dict:
15
+ """
16
+ Convert TwitterMessage instance to a dictionary.
17
+
18
+ Returns:
19
+ dict: A dictionary representation of the TwitterMessage instance.
20
+ If the user attribute is a TwitterUser instance, it will be converted
21
+ to a dictionary using its __dict__ attribute.
22
+ """
23
+ return {
24
+ 'tweet_id': self.tweet_id,
25
+ 'message': self.message,
26
+ 'created_at': self.created_at,
27
+ 'view_count': self.view_count,
28
+ 'retweet_count': self.retweet_count,
29
+ 'reply_count': self.reply_count,
30
+ 'user': self.user.to_dict()
31
+ }
@@ -0,0 +1,26 @@
1
+ from typing import TypeVar, Dict, Any, Type
2
+
3
+ from ..models.request_message_topic import RequestMessageTopic
4
+ from ...domain.models.hai_message import HaiMessage
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphClearRequestMessage(HaiMessage):
9
+ """Message to clear all nodes and relationships from the graph"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls) -> 'GraphClearRequestMessage':
18
+ """Create a message requesting to clear the graph"""
19
+ return cls.create(
20
+ topic=RequestMessageTopic.GRAPH_CLEAR,
21
+ payload={}
22
+ )
23
+
24
+ @classmethod
25
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphClearRequestMessage':
26
+ return cls.create_message()
@@ -0,0 +1,27 @@
1
+
2
+ from typing import TypeVar, Dict, Any, Type, List
3
+
4
+ from ..models.request_message_topic import RequestMessageTopic
5
+ from ...domain.models.hai_message import HaiMessage
6
+
7
+ T = TypeVar('T', bound='HaiMessage')
8
+
9
+ class GraphGetAllRequestMessage(HaiMessage):
10
+ """Message to get all nodes and relationships from the graph"""
11
+
12
+ @classmethod
13
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
14
+ """Create a message - inherited from HaiMessage"""
15
+ return super().create(topic=topic, payload=payload)
16
+
17
+ @classmethod
18
+ def create_message(cls) -> 'GraphGetAllRequestMessage':
19
+ """Create a message requesting to get all nodes and relationships"""
20
+ return cls.create(
21
+ topic=RequestMessageTopic.GRAPH_GET_ALL,
22
+ payload={}
23
+ )
24
+
25
+ @classmethod
26
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphGetAllRequestMessage':
27
+ return cls.create_message()
@@ -0,0 +1,45 @@
1
+ from typing import TypeVar, Dict, Any, Type, List
2
+
3
+ from ..models.request_message_topic import RequestMessageTopic
4
+ from ...domain.models.hai_message import HaiMessage
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphGetAllResultResponseMessage(HaiMessage):
9
+ """Message containing all nodes and relationships from the graph"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls, nodes: List[Dict], relationships: List[Dict]) -> 'GraphGetAllResultResponseMessage':
18
+ """Create a message with all nodes and relationships"""
19
+ return cls.create(
20
+ topic=RequestMessageTopic.GRAPH_GET_ALL_RESPONSE,
21
+ payload={
22
+ "nodes": nodes,
23
+ "relationships": relationships
24
+ },
25
+ )
26
+
27
+ @property
28
+ def nodes(self) -> List[Dict]:
29
+ """Get the list of nodes from the payload"""
30
+ return self.payload.get("nodes", [])
31
+
32
+ @property
33
+ def relationships(self) -> List[Dict]:
34
+ """Get the list of relationships from the payload"""
35
+ return self.payload.get("relationships", [])
36
+
37
+ @classmethod
38
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphGetAllResultResponseMessage':
39
+ # Extract the necessary fields from the message payload
40
+ payload = message.payload
41
+
42
+ return cls.create_message(
43
+ nodes=payload.get("nodes", []),
44
+ relationships=payload.get("relationships", [])
45
+ )
@@ -0,0 +1,64 @@
1
+ from typing import TypeVar, Dict, Any, Type, Optional
2
+
3
+ from ..models.request_message_topic import RequestMessageTopic
4
+ from ...domain.models.hai_message import HaiMessage
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+
9
+ class GraphNodeAddRequestMessage(HaiMessage):
10
+ """Message to add a node to the graph"""
11
+
12
+ @classmethod
13
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
14
+ """Create a message - inherited from HaiMessage"""
15
+ return super().create(topic=topic, payload=payload)
16
+
17
+ @classmethod
18
+ def create_message(cls, node_id: str, label: str, properties: dict = None,
19
+ description: str = None) -> 'GraphNodeAddRequestMessage':
20
+ """Create a message requesting to add a node to the graph"""
21
+ if properties is None:
22
+ properties = {}
23
+
24
+ return cls.create(
25
+ topic=RequestMessageTopic.GRAPH_NODE_ADD,
26
+ payload={
27
+ "node_id": node_id,
28
+ "label": label,
29
+ "properties": properties,
30
+ "description": description
31
+ },
32
+ )
33
+
34
+ @property
35
+ def node_id(self) -> str:
36
+ """Get the node ID from the payload"""
37
+ return self.payload.get("node_id")
38
+
39
+ @property
40
+ def label(self) -> str:
41
+ """Get the label from the payload"""
42
+ return self.payload.get("label")
43
+
44
+ @property
45
+ def properties(self) -> dict:
46
+ """Get the properties from the payload"""
47
+ return self.payload.get("properties", {})
48
+
49
+ @property
50
+ def description(self) -> Optional[str]:
51
+ """Get the description from the payload"""
52
+ return self.payload.get("description")
53
+
54
+ @classmethod
55
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphNodeAddRequestMessage':
56
+ # Extract the necessary fields from the message payload
57
+ payload = message.payload
58
+
59
+ return cls.create_message(
60
+ node_id=payload.get("node_id", ''),
61
+ label=payload.get("label", ''),
62
+ properties=payload.get("properties", {}),
63
+ description=payload.get("description")
64
+ )
@@ -0,0 +1,69 @@
1
+ from typing import TypeVar, Dict, Any, Type, Optional
2
+
3
+ from ..models.request_message_topic import RequestMessageTopic
4
+ from ...domain.models.hai_message import HaiMessage
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphNodeAddedResponseMessage(HaiMessage):
9
+ """Message indicating a node was successfully added to the graph"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls, node_id: str, label: str, properties: dict = None,
18
+ description: str = None) -> 'GraphNodeAddedResponseMessage':
19
+ """Create a message confirming a node was added"""
20
+ if properties is None:
21
+ properties = {}
22
+
23
+ return cls.create(
24
+ topic=RequestMessageTopic.GRAPH_NODE_ADD_RESPONSE,
25
+ payload={
26
+ "node_id": node_id,
27
+ "label": label,
28
+ "properties": properties,
29
+ "description": description,
30
+ "success": True
31
+ },
32
+ )
33
+
34
+ @property
35
+ def node_id(self) -> str:
36
+ """Get the node ID from the payload"""
37
+ return self.payload.get("node_id")
38
+
39
+ @property
40
+ def label(self) -> str:
41
+ """Get the label from the payload"""
42
+ return self.payload.get("label")
43
+
44
+ @property
45
+ def properties(self) -> dict:
46
+ """Get the properties from the payload"""
47
+ return self.payload.get("properties", {})
48
+
49
+ @property
50
+ def description(self) -> Optional[str]:
51
+ """Get the description from the payload"""
52
+ return self.payload.get("description")
53
+
54
+ @property
55
+ def success(self) -> bool:
56
+ """Check if the operation was successful"""
57
+ return self.payload.get("success", False)
58
+
59
+ @classmethod
60
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphNodeAddedResponseMessage':
61
+ # Extract the necessary fields from the message payload
62
+ payload = message.payload
63
+
64
+ return cls.create_message(
65
+ node_id=payload.get("node_id", ''),
66
+ label=payload.get("label", ''),
67
+ properties=payload.get("properties", {}),
68
+ description=payload.get("description")
69
+ )
@@ -0,0 +1,39 @@
1
+
2
+ from typing import TypeVar, Dict, Any, Type
3
+
4
+ from ..models.request_message_topic import RequestMessageTopic
5
+ from ...domain.models.hai_message import HaiMessage
6
+
7
+ T = TypeVar('T', bound='HaiMessage')
8
+
9
+ class GraphNodeGetRequestMessage(HaiMessage):
10
+ """Message to get a node from the graph by ID"""
11
+
12
+ @classmethod
13
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
14
+ """Create a message - inherited from HaiMessage"""
15
+ return super().create(topic=topic, payload=payload)
16
+
17
+ @classmethod
18
+ def create_message(cls, node_id: str) -> 'GraphNodeGetRequestMessage':
19
+ """Create a message requesting to get a node from the graph"""
20
+ return cls.create(
21
+ topic=RequestMessageTopic.GRAPH_NODE_GET,
22
+ payload={
23
+ "node_id": node_id
24
+ },
25
+ )
26
+
27
+ @property
28
+ def node_id(self) -> str:
29
+ """Get the node ID from the payload"""
30
+ return self.payload.get("node_id")
31
+
32
+ @classmethod
33
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphNodeGetRequestMessage':
34
+ # Extract the necessary fields from the message payload
35
+ payload = message.payload
36
+
37
+ return cls.create_message(
38
+ node_id=payload.get("node_id", '')
39
+ )
@@ -0,0 +1,70 @@
1
+ from typing import TypeVar, Dict, Any, Type, Optional
2
+
3
+ from ..models.request_message_topic import RequestMessageTopic
4
+ from ...domain.models.hai_message import HaiMessage
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphNodeGetResultResponseMessage(HaiMessage):
9
+ """Message containing a requested node from the graph"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls, node_id: str, label: str, properties: dict = None,
18
+ description: str = None, found: bool = True) -> 'GraphNodeGetResultResponseMessage':
19
+ """Create a message with the requested node information"""
20
+ if properties is None:
21
+ properties = {}
22
+
23
+ return cls.create(
24
+ topic=RequestMessageTopic.GRAPH_NODE_GET_RESPONSE,
25
+ payload={
26
+ "node_id": node_id,
27
+ "label": label,
28
+ "properties": properties,
29
+ "description": description,
30
+ "found": found
31
+ },
32
+ )
33
+
34
+ @property
35
+ def node_id(self) -> str:
36
+ """Get the node ID from the payload"""
37
+ return self.payload.get("node_id")
38
+
39
+ @property
40
+ def label(self) -> str:
41
+ """Get the label from the payload"""
42
+ return self.payload.get("label")
43
+
44
+ @property
45
+ def properties(self) -> dict:
46
+ """Get the properties from the payload"""
47
+ return self.payload.get("properties", {})
48
+
49
+ @property
50
+ def description(self) -> Optional[str]:
51
+ """Get the description from the payload"""
52
+ return self.payload.get("description")
53
+
54
+ @property
55
+ def found(self) -> bool:
56
+ """Check if the node was found"""
57
+ return self.payload.get("found", False)
58
+
59
+ @classmethod
60
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphNodeGetResultResponseMessage':
61
+ # Extract the necessary fields from the message payload
62
+ payload = message.payload
63
+
64
+ return cls.create_message(
65
+ node_id=payload.get("node_id", ''),
66
+ label=payload.get("label", ''),
67
+ properties=payload.get("properties", {}),
68
+ description=payload.get("description"),
69
+ found=payload.get("found", False)
70
+ )
@@ -0,0 +1,56 @@
1
+ from typing import TypeVar, Dict, Any, Type, Optional
2
+
3
+ from ..models.request_message_topic import RequestMessageTopic
4
+ from ...domain.models.hai_message import HaiMessage
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphNodeUpdateRequestMessage(HaiMessage):
9
+ """Message to update an existing node in the graph"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls, node_id: str, properties: dict = None,
18
+ description: str = None) -> 'GraphNodeUpdateRequestMessage':
19
+ """Create a message requesting to update a node in the graph"""
20
+ if properties is None:
21
+ properties = {}
22
+
23
+ return cls.create(
24
+ topic=RequestMessageTopic.GRAPH_NODE_UPDATE,
25
+ payload={
26
+ "node_id": node_id,
27
+ "properties": properties,
28
+ "description": description
29
+ },
30
+ )
31
+
32
+ @property
33
+ def node_id(self) -> str:
34
+ """Get the node ID from the payload"""
35
+ return self.payload.get("node_id")
36
+
37
+ @property
38
+ def properties(self) -> dict:
39
+ """Get the properties from the payload"""
40
+ return self.payload.get("properties", {})
41
+
42
+ @property
43
+ def description(self) -> Optional[str]:
44
+ """Get the description from the payload"""
45
+ return self.payload.get("description")
46
+
47
+ @classmethod
48
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphNodeUpdateRequestMessage':
49
+ # Extract the necessary fields from the message payload
50
+ payload = message.payload
51
+
52
+ return cls.create_message(
53
+ node_id=payload.get("node_id", ''),
54
+ properties=payload.get("properties", {}),
55
+ description=payload.get("description")
56
+ )
@@ -0,0 +1,45 @@
1
+ from typing import TypeVar, Dict, Any, Type
2
+
3
+ from ..models.request_message_topic import RequestMessageTopic
4
+ from ...domain.models.hai_message import HaiMessage
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphNodesByPropertyRequestMessage(HaiMessage):
9
+ """Message to get nodes with a specific property value and their relationships"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls, property_name: str, property_value: any) -> 'GraphNodesByPropertyRequestMessage':
18
+ """Create a message requesting nodes with a specific property value"""
19
+ return cls.create(
20
+ topic=RequestMessageTopic.GRAPH_NODES_BY_PROPERTY,
21
+ payload={
22
+ "property_name": property_name,
23
+ "property_value": property_value
24
+ },
25
+ )
26
+
27
+ @property
28
+ def property_name(self) -> str:
29
+ """Get the property name from the payload"""
30
+ return self.payload.get("property_name")
31
+
32
+ @property
33
+ def property_value(self) -> any:
34
+ """Get the property value from the payload"""
35
+ return self.payload.get("property_value")
36
+
37
+ @classmethod
38
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphNodesByPropertyRequestMessage':
39
+ # Extract the necessary fields from the message payload
40
+ payload = message.payload
41
+
42
+ return cls.create_message(
43
+ property_name=payload.get("property_name", ''),
44
+ property_value=payload.get("property_value")
45
+ )
@@ -0,0 +1,80 @@
1
+ from typing import TypeVar, Dict, Any, Type, List
2
+
3
+ from ...domain.models.hai_message import HaiMessage
4
+ from ..models.request_message_topic import RequestMessageTopic
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphNodesByPropertyResponseMessage(HaiMessage):
9
+ """Response message containing nodes with a specific property value and their relationships"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls, property_name: str, property_value: any,
18
+ nodes: List[Dict], relationships: List[Dict],
19
+ success: bool = True) -> 'GraphNodesByPropertyResponseMessage':
20
+ """
21
+ Create a response message with nodes having a specific property value and their relationships
22
+
23
+ Args:
24
+ property_name: The property name that was queried
25
+ property_value: The property value that was queried
26
+ nodes: List of node dictionaries
27
+ relationships: List of relationship dictionaries
28
+ success: Whether the operation was successful
29
+
30
+ Returns:
31
+ A response message with the query results
32
+ """
33
+ return cls.create(
34
+ topic=RequestMessageTopic.GRAPH_NODES_BY_PROPERTY_RESPONSE,
35
+ payload={
36
+ "property_name": property_name,
37
+ "property_value": property_value,
38
+ "nodes": nodes,
39
+ "relationships": relationships,
40
+ "success": success
41
+ },
42
+ )
43
+
44
+ @property
45
+ def property_name(self) -> str:
46
+ """Get the property name from the payload"""
47
+ return self.payload.get("property_name")
48
+
49
+ @property
50
+ def property_value(self) -> any:
51
+ """Get the property value from the payload"""
52
+ return self.payload.get("property_value")
53
+
54
+ @property
55
+ def nodes(self) -> List[Dict]:
56
+ """Get the list of nodes from the payload"""
57
+ return self.payload.get("nodes", [])
58
+
59
+ @property
60
+ def relationships(self) -> List[Dict]:
61
+ """Get the list of relationships from the payload"""
62
+ return self.payload.get("relationships", [])
63
+
64
+ @property
65
+ def success(self) -> bool:
66
+ """Check if the query was successful"""
67
+ return self.payload.get("success", False)
68
+
69
+ @classmethod
70
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphNodesByPropertyResponseMessage':
71
+ # Extract the necessary fields from the message payload
72
+ payload = message.payload
73
+
74
+ return cls.create_message(
75
+ property_name=payload.get("property_name", ''),
76
+ property_value=payload.get("property_value"),
77
+ nodes=payload.get("nodes", []),
78
+ relationships=payload.get("relationships", []),
79
+ success=payload.get("success", False)
80
+ )
@@ -0,0 +1,48 @@
1
+ from typing import TypeVar, Dict, Any, Type
2
+
3
+ from ..models.request_message_topic import RequestMessageTopic
4
+ from ...domain.models.hai_message import HaiMessage
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphQueryRequestMessage(HaiMessage):
9
+ """Message to perform a custom query on the graph"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls, query: str, parameters: dict = None) -> 'GraphQueryRequestMessage':
18
+ """Create a message requesting to perform a custom query on the graph"""
19
+ if parameters is None:
20
+ parameters = {}
21
+
22
+ return cls.create(
23
+ topic=RequestMessageTopic.GRAPH_QUERY,
24
+ payload={
25
+ "query": query,
26
+ "parameters": parameters
27
+ },
28
+ )
29
+
30
+ @property
31
+ def query(self) -> str:
32
+ """Get the query from the payload"""
33
+ return self.payload.get("query")
34
+
35
+ @property
36
+ def parameters(self) -> dict:
37
+ """Get the query parameters from the payload"""
38
+ return self.payload.get("parameters", {})
39
+
40
+ @classmethod
41
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphQueryRequestMessage':
42
+ # Extract the necessary fields from the message payload
43
+ payload = message.payload
44
+
45
+ return cls.create_message(
46
+ query=payload.get("query", ''),
47
+ parameters=payload.get("parameters", {})
48
+ )
@@ -0,0 +1,63 @@
1
+ from typing import TypeVar, Dict, Any, Type
2
+
3
+ from ...domain.models.hai_message import HaiMessage
4
+ from ..models.request_message_topic import RequestMessageTopic
5
+
6
+ T = TypeVar('T', bound='HaiMessage')
7
+
8
+ class GraphRelationshipAddRequestMessage(HaiMessage):
9
+ """Message to add a relationship between nodes in the graph"""
10
+
11
+ @classmethod
12
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
13
+ """Create a message - inherited from HaiMessage"""
14
+ return super().create(topic=topic, payload=payload)
15
+
16
+ @classmethod
17
+ def create_message(cls, source_node_id: str, target_node_id: str,
18
+ relationship_type: str, properties: dict = None) -> 'GraphRelationshipAddRequestMessage':
19
+ """Create a message requesting to add a relationship to the graph"""
20
+ if properties is None:
21
+ properties = {}
22
+
23
+ return cls.create(
24
+ topic=RequestMessageTopic.GRAPH_RELATIONSHIP_ADD,
25
+ payload={
26
+ "source_node_id": source_node_id,
27
+ "target_node_id": target_node_id,
28
+ "relationship_type": relationship_type,
29
+ "properties": properties
30
+ },
31
+ )
32
+
33
+ @property
34
+ def source_node_id(self) -> str:
35
+ """Get the source node ID from the payload"""
36
+ return self.payload.get("source_node_id")
37
+
38
+ @property
39
+ def target_node_id(self) -> str:
40
+ """Get the target node ID from the payload"""
41
+ return self.payload.get("target_node_id")
42
+
43
+ @property
44
+ def relationship_type(self) -> str:
45
+ """Get the relationship type from the payload"""
46
+ return self.payload.get("relationship_type")
47
+
48
+ @property
49
+ def properties(self) -> dict:
50
+ """Get the properties from the payload"""
51
+ return self.payload.get("properties", {})
52
+
53
+ @classmethod
54
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphRelationshipAddRequestMessage':
55
+ # Extract the necessary fields from the message payload
56
+ payload = message.payload
57
+
58
+ return cls.create_message(
59
+ source_node_id=payload.get("source_node_id", ''),
60
+ target_node_id=payload.get("target_node_id", ''),
61
+ relationship_type=payload.get("relationship_type", ''),
62
+ properties=payload.get("properties", {})
63
+ )
@@ -1,4 +1,4 @@
1
- from typing import Type, TypeVar, Dict, Any, Optional
1
+ from typing import Type, TypeVar, Dict, Any
2
2
 
3
3
  from ..models.request_message_topic import RequestMessageTopic
4
4
  from ...domain.models.hai_message import HaiMessage
@@ -1,4 +1,4 @@
1
- from typing import Type, TypeVar, Dict, Any, Optional
1
+ from typing import Type, TypeVar, Dict, Any
2
2
 
3
3
  from ..models.request_message_topic import RequestMessageTopic
4
4
  from ...domain.models.hai_message import HaiMessage
@@ -0,0 +1,63 @@
1
+ from dataclasses import dataclass
2
+ from typing import TypeVar, Dict, Any, Type
3
+
4
+ from ..models.request_message_topic import RequestMessageTopic
5
+ from ...domain.models.hai_message import HaiMessage
6
+
7
+ T = TypeVar('T', bound='HaiMessage')
8
+
9
+ @dataclass
10
+ class TwitterUserTweetsRequestMessage(HaiMessage):
11
+ """Message to request tweets from a Twitter user"""
12
+
13
+ @classmethod
14
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
15
+ """Create a message - inherited from HaiMessage"""
16
+ return super().create(topic=topic, payload=payload)
17
+
18
+ @classmethod
19
+ def create_message(cls, user_id: str, max_results: int = 100,
20
+ include_replies: bool = False,
21
+ include_retweets: bool = False) -> 'TwitterUserTweetsRequestMessage':
22
+ """Create a message requesting tweets from a Twitter user"""
23
+ return cls.create(
24
+ topic=RequestMessageTopic.TWITTER_GET_USER_TWEETS,
25
+ payload={
26
+ "user_id": user_id,
27
+ "max_results": max_results,
28
+ "include_replies": include_replies,
29
+ "include_retweets": include_retweets
30
+ },
31
+ )
32
+
33
+ @property
34
+ def user_id(self) -> str:
35
+ """Get the user ID from the payload"""
36
+ return self.payload.get("user_id")
37
+
38
+ @property
39
+ def max_results(self) -> int:
40
+ """Get the maximum number of results from the payload"""
41
+ return self.payload.get("max_results", 100)
42
+
43
+ @property
44
+ def include_replies(self) -> bool:
45
+ """Get whether to include replies from the payload"""
46
+ return self.payload.get("include_replies", False)
47
+
48
+ @property
49
+ def include_retweets(self) -> bool:
50
+ """Get whether to include retweets from the payload"""
51
+ return self.payload.get("include_retweets", False)
52
+
53
+ @classmethod
54
+ def from_hai_message(cls, message: HaiMessage) -> 'TwitterUserTweetsRequestMessage':
55
+ """Create a TwitterUserTweetsRequestMessage from a HaiMessage"""
56
+ payload = message.payload
57
+
58
+ return cls.create_message(
59
+ user_id=payload.get("user_id", ""),
60
+ max_results=payload.get("max_results", 100),
61
+ include_replies=payload.get("include_replies", False),
62
+ include_retweets=payload.get("include_retweets", False)
63
+ )
@@ -0,0 +1,89 @@
1
+ from dataclasses import dataclass
2
+ from typing import TypeVar, Dict, Any, Type, List
3
+
4
+ from ..models.request_message_topic import RequestMessageTopic
5
+ from ..models.twitter_message_metadata import TwitterMessageMetaData
6
+ from ...domain.models.hai_message import HaiMessage
7
+
8
+ T = TypeVar('T', bound='HaiMessage')
9
+ @dataclass
10
+ class TwitterUserTweetsResponseMessage(HaiMessage):
11
+ """Message containing tweets from a Twitter user"""
12
+
13
+ @classmethod
14
+ def create(cls: Type[T], topic: str, payload: Dict[Any, Any]) -> T:
15
+ """Create a message - inherited from HaiMessage"""
16
+ return super().create(topic=topic, payload=payload)
17
+
18
+ @classmethod
19
+ def create_message(cls, user_id: str, tweets: List[Dict[str, Any]],
20
+ success: bool = True, error: str = None) -> 'TwitterUserTweetsResponseMessage':
21
+ """Create a message with tweets from a Twitter user"""
22
+ return cls.create(
23
+ topic=RequestMessageTopic.TWITTER_GET_USER_TWEETS_RESPONSE,
24
+ payload={
25
+ "user_id": user_id,
26
+ "tweets": tweets,
27
+ "success": success,
28
+ "error": error
29
+ },
30
+ )
31
+
32
+ @property
33
+ def user_id(self) -> str:
34
+ """Get the user ID from the payload"""
35
+ return self.payload.get("user_id")
36
+
37
+ @property
38
+ def tweets(self) -> List[Dict[str, Any]]:
39
+ """Get the tweets from the payload"""
40
+ return self.payload.get("tweets", [])
41
+
42
+ @property
43
+ def success(self) -> bool:
44
+ """Get whether the request was successful"""
45
+ return self.payload.get("success", False)
46
+
47
+ @property
48
+ def error(self) -> str:
49
+ """Get any error message"""
50
+ return self.payload.get("error")
51
+
52
+ @classmethod
53
+ def from_hai_message(cls, message: HaiMessage) -> 'TwitterUserTweetsResponseMessage':
54
+ """Create a TwitterUserTweetsResponseMessage from a HaiMessage"""
55
+ payload = message.payload
56
+
57
+ return cls.create_message(
58
+ user_id=payload.get("user_id", ""),
59
+ tweets=payload.get("tweets", []),
60
+ success=payload.get("success", False),
61
+ error=payload.get("error")
62
+ )
63
+
64
+ @classmethod
65
+ def from_twitter_messages(cls, user_id: str,
66
+ twitter_messages: List[TwitterMessageMetaData]) -> 'TwitterUserTweetsResponseMessage':
67
+ """Create a response message from a list of TwitterMessage objects"""
68
+ tweets = []
69
+
70
+ for message in twitter_messages:
71
+ user = message.user
72
+
73
+ tweet_data = {
74
+ "tweet_id": str(message.tweet_id),
75
+ "message": message.message,
76
+ "created_at": message.created_at.isoformat() if message.created_at else None,
77
+ "view_count": message.view_count,
78
+ "retweet_count": message.retweet_count,
79
+ "reply_count": message.reply_count,
80
+ "user": message.user.to_dict() if user else None,
81
+ }
82
+
83
+ tweets.append(tweet_data)
84
+
85
+ return cls.create_message(
86
+ user_id=user_id,
87
+ tweets=tweets,
88
+ success=True
89
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: h_message_bus
3
- Version: 0.0.26
3
+ Version: 0.0.27
4
4
  Summary: Message bus integration for HAI
5
5
  Author-email: shoebill <shoebill.hai@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -13,18 +13,33 @@ h_message_bus/domain/event_messages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQ
13
13
  h_message_bus/domain/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  h_message_bus/domain/models/event_message_topic.py,sha256=fSjRMBwMD2RE9GBUud38XMrgLZcngURERrbuoAhQ0Hk,717
15
15
  h_message_bus/domain/models/hai_message.py,sha256=b5CfX7hi5uNq77IVnZzEi9iotc4b_U2MNYwV6JY7JcU,2146
16
- h_message_bus/domain/models/request_message_topic.py,sha256=xcbqdL24vgQR04CXvv8pqLIjIYSNpE5OxDcs7LsvmQg,1707
16
+ h_message_bus/domain/models/request_message_topic.py,sha256=JA8BXe4-cjyrfhLyu_y22AUx2QPLUNi3k-8QYGff_Jo,2851
17
+ h_message_bus/domain/models/twitter_message_metadata.py,sha256=f3Ui-Zz5AnU5nQx9BOAVPCV6cg9UUZnBB1-oJtZPRSc,1218
17
18
  h_message_bus/domain/models/twitter_user_metadata.py,sha256=N7GVyn2txmlMQ19aatNh7lvzO6FNSj4dKVujestha9o,2827
18
19
  h_message_bus/domain/models/vector_collection_metadata.py,sha256=fSy3ZQ-zkYISTpc-_M6XWf1JkufVAlzlS2ZT60TzA2s,891
19
20
  h_message_bus/domain/models/vector_query_answer.py,sha256=V1JR5Di7kIVbRF_eq2uPOhDnkZpQvo9pxD41V7MNV7Q,551
20
21
  h_message_bus/domain/request_messages/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
- h_message_bus/domain/request_messages/tg_message_request_message.py,sha256=0J_PUA9wr0wZEjVBwgAA5YN-RiNEE54bnzyCvheLkmc,1457
22
- h_message_bus/domain/request_messages/tg_user_message_reply_request_message.py,sha256=XQ4IfaPVaKoagCASxuDHvsqH4nIWE0mAKan_Z6_kba8,1777
22
+ h_message_bus/domain/request_messages/graph_clear_request_message.py,sha256=mhYpSlsN_gweNY3r80_fXRkIUVk8NwHgqADLn0EMGb4,933
23
+ h_message_bus/domain/request_messages/graph_get_all_request_message.py,sha256=n0EhFQTszxJ1PW5zXL8TJPgJcYMaprGV16X-oBdYXVQ,960
24
+ h_message_bus/domain/request_messages/graph_get_all_result_response_message.py,sha256=_ixF85i6LxiIBp1SLdUCL9a6ksyGELrsw2OBsQZEMiw,1668
25
+ h_message_bus/domain/request_messages/graph_node_add_request_message.py,sha256=T7k-ACl5JwSdy_H8wCVPM_UUKGA27ny9e7wBwR2pGFQ,2175
26
+ h_message_bus/domain/request_messages/graph_node_added_response_message.py,sha256=0oN0hJJU2Da8uoK9JvlHosssWCPsY4hqUPJhgd6Pd5Q,2395
27
+ h_message_bus/domain/request_messages/graph_node_get_request_message.py,sha256=G_JlCnwU6a9HEU0gFt8ilOwx1KF-FJC0EqpWw1C4km8,1302
28
+ h_message_bus/domain/request_messages/graph_node_get_result_response_message.py,sha256=kzde_K65UezKm2NLSFehiLrDAVTHXZM9Gd-GDYUZ1dg,2457
29
+ h_message_bus/domain/request_messages/graph_node_update_request_message.py,sha256=gNXcQmpPF6Ut6M8wtRx7Xi7XdpCT9ZJvqPzNoSdwUZQ,1977
30
+ h_message_bus/domain/request_messages/graph_nodes_by_property_request_message.py,sha256=L-oZfZqsI9DG-CFL0G7r-2A-6wTqFuMNkDww2JUR73s,1712
31
+ h_message_bus/domain/request_messages/graph_nodes_by_property_response_message.py,sha256=UDCA769I14BNP2Qmfwg5c6m98nBNVSZ10Kpi8Z8AGAQ,3051
32
+ h_message_bus/domain/request_messages/graph_query_request_message.py,sha256=UXs_m6pgPkYRSRHrhI-c3WAQ31Yj1idZBgavufm32s0,1635
33
+ h_message_bus/domain/request_messages/graph_relationship_added_request_message.py,sha256=a2hJyF78ITCjkvdR_v_NbnUvxFkolnCyN1-71rF-J2I,2388
34
+ h_message_bus/domain/request_messages/tg_message_request_message.py,sha256=bta24fXwwxTMCwdDHlbB20T-0SNkNWdPwNsQbo_OGN0,1447
35
+ h_message_bus/domain/request_messages/tg_user_message_reply_request_message.py,sha256=desDxVddPTp7iOYq7126zDEyaJF1bu9LWEamj-e87IA,1767
23
36
  h_message_bus/domain/request_messages/tg_user_message_request_message.py,sha256=pHmmGJpMEnwzbTVVvoD6UOMflQOuQKgErZA9MyRwWt8,3121
24
37
  h_message_bus/domain/request_messages/twitter_get_user_request_message.py,sha256=OfC93X1M0vgMU26BBrpA7AdlY32IFdVG_vRT8BdhQOc,1209
25
38
  h_message_bus/domain/request_messages/twitter_get_user_response_message.py,sha256=dXhK_JN3Sz6hN8EpDcj7gq6htJ8Yu5G-Cal73XXcEng,3299
26
39
  h_message_bus/domain/request_messages/twitter_get_users_request_message.py,sha256=y2Bh77py9RPtKfdPrPi0mv3LVIujne107y8vkPydirs,1545
27
40
  h_message_bus/domain/request_messages/twitter_get_users_response_message.py,sha256=UaSFqX_GgBFKWXtxSohdTstsr2HFzZvbcGwCaDyicic,1580
41
+ h_message_bus/domain/request_messages/twitter_user_tweets_request_message.py,sha256=9vAhRxbCCDTqQNNKgp5cDIkiGIsnHwRSOwc6PK6TmcA,2397
42
+ h_message_bus/domain/request_messages/twitter_user_tweets_response_message.py,sha256=DAQauYnUEnKX6AGKF6-zFd0X-j4BNfAMwBMLr5JLEwI,3243
28
43
  h_message_bus/domain/request_messages/vector_query_collection_request_message.py,sha256=x1J8SLVBlNS4TFzVJY9UG7mo94l9i4azndwzAlyktZw,1800
29
44
  h_message_bus/domain/request_messages/vector_query_collection_response_message.py,sha256=Q589JT_QE-oVsTh1GEmK__3Hct7ijfM1UTcPi0YTGn8,1767
30
45
  h_message_bus/domain/request_messages/vector_read_metadata_request_message.py,sha256=P9t6pcynS112F9_Jmbvw8wlfXhs5NOnV48SUVq92xt8,873
@@ -35,7 +50,7 @@ h_message_bus/domain/request_messages/web_search_request_message.py,sha256=ZoB4i
35
50
  h_message_bus/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
51
  h_message_bus/infrastructure/nats_client_repository.py,sha256=bhaWRK94h2EmFIef2DALnoBJKnuTnx6-iU7IXO2S_EU,3642
37
52
  h_message_bus/infrastructure/nats_config.py,sha256=Yzqqd1bCfmUv_4FOnA1dvqIpakzV0BUL2_nXQcndWvo,1304
38
- h_message_bus-0.0.26.dist-info/METADATA,sha256=cml2BaoERKhEs5LPN8Ln3d2DfDLAjDxAAcSdrWm-_rU,8834
39
- h_message_bus-0.0.26.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
40
- h_message_bus-0.0.26.dist-info/top_level.txt,sha256=BArjhm_lwFR9yJJEIf-LT_X64psuLkXFdbpQRJUreFE,23
41
- h_message_bus-0.0.26.dist-info/RECORD,,
53
+ h_message_bus-0.0.27.dist-info/METADATA,sha256=DF655DI4JK6ZVPQXGYRbO0lr-d9-n7ebHVx1q1MstzI,8834
54
+ h_message_bus-0.0.27.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
55
+ h_message_bus-0.0.27.dist-info/top_level.txt,sha256=BArjhm_lwFR9yJJEIf-LT_X64psuLkXFdbpQRJUreFE,23
56
+ h_message_bus-0.0.27.dist-info/RECORD,,