h-message-bus 0.0.30__py3-none-any.whl → 0.0.32__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.
@@ -48,6 +48,10 @@ class RequestMessageTopic(str, Enum):
48
48
  WEB_FIND_RELATED = "hai.tools.web.find.related"
49
49
  WEB_FIND_RELATED_RESPONSE = "hai.tools.web.find.related.response"
50
50
 
51
+ INIT_KNOWLEDGE_BASE = "hai.tools.init.knowledge.base"
52
+ INIT_KNOWLEDGE_BASE_RESPONSE = "hai.tools.init.knowledge.base.response"
53
+
54
+ # graph database
51
55
  GRAPH_NODE_ADD = "hai.graph.node.add"
52
56
  GRAPH_NODE_UPDATE = "hai.graph.node.update"
53
57
  GRAPH_NODE_GET = "hai.graph.node.get"
@@ -59,6 +63,9 @@ class RequestMessageTopic(str, Enum):
59
63
  GRAPH_GET_ALL = "hai.graph.get.all"
60
64
  GRAPH_NODES_BY_PROPERTY = "hai.graph.nodes.by.property"
61
65
 
66
+ GRAPH_QUERY_OPERATION = "hai.graph.query.operation"
67
+ GRAPH_QUERY_OPERATION_RESPONSE = "hai.graph.query.operation.response"
68
+
62
69
  GRAPH_NODE_ADD_RESPONSE = "hai.graph.node.add.response"
63
70
  GRAPH_NODE_UPDATE_RESPONSE = "hai.graph.node.update.response"
64
71
  GRAPH_NODE_GET_RESPONSE = "hai.graph.node.get.response"
@@ -0,0 +1,114 @@
1
+ import json
2
+ from typing import Dict, Any, Type, TypeVar
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
+
10
+ class GraphQueryOperationRequestMessage(HaiMessage):
11
+ """Message to request graph query operations"""
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,
20
+ operation_type: str,
21
+ anchor_node: str,
22
+ relationship_direction: str = None,
23
+ relationship_type: str = None,
24
+ limit: int = None,
25
+ traversal_depth: int = None) -> 'GraphQueryOperationRequestMessage':
26
+ """
27
+ Create a message requesting a graph query operation
28
+
29
+ Args:
30
+ operation_type: One of 'FIND_RELATED_NODES', 'GET_NODE_INFO', 'COUNT_RELATIONSHIPS'
31
+ anchor_node: The central node in the query (e.g., 'hyperliquid')
32
+ relationship_direction: One of 'INCOMING', 'OUTGOING', or 'BOTH'
33
+ relationship_type: The relationship type to traverse (e.g., 'BUILDS_ON')
34
+ limit: Numerical limit of results to return
35
+ traversal_depth: How many relationship hops to traverse
36
+
37
+ Returns:
38
+ A new GraphQueryOperationRequestMessage
39
+ """
40
+ # Build the query operation dictionary
41
+ query_operation = {
42
+ "operation_type": operation_type,
43
+ "anchor_node": anchor_node,
44
+ }
45
+
46
+ # Add optional parameters if provided
47
+ if relationship_direction is not None:
48
+ query_operation["relationship_direction"] = relationship_direction
49
+
50
+ if relationship_type is not None:
51
+ query_operation["relationship_type"] = relationship_type
52
+
53
+ if limit is not None:
54
+ query_operation["limit"] = f"{limit}"
55
+
56
+ if traversal_depth is not None:
57
+ query_operation["traversal_depth"] = f"{traversal_depth}"
58
+
59
+ return cls.create(
60
+ topic=RequestMessageTopic.GRAPH_QUERY_OPERATION,
61
+ payload={"query_operation": json.dumps(query_operation)},
62
+ )
63
+
64
+ @property
65
+ def query_operation(self) -> Dict[str, Any]:
66
+ """Get the query operation from the payload"""
67
+ query_operation_payload = self.payload.get("query_operation", "{}")
68
+ return json.loads(query_operation_payload)
69
+
70
+ @property
71
+ def operation_type(self) -> str:
72
+ """Get the operation type from the query operation"""
73
+ return self.query_operation.get("operation_type", "")
74
+
75
+ @property
76
+ def anchor_node(self) -> str:
77
+ """Get the anchor node from the query operation"""
78
+ return self.query_operation.get("anchor_node", "")
79
+
80
+ @property
81
+ def relationship_direction(self) -> str:
82
+ """Get the relationship direction from the query operation"""
83
+ return self.query_operation.get("relationship_direction", "BOTH")
84
+
85
+ @property
86
+ def relationship_type(self) -> str:
87
+ """Get the relationship type from the query operation"""
88
+ return self.query_operation.get("relationship_type", "")
89
+
90
+ @property
91
+ def limit(self) -> int:
92
+ """Get the limit from the query operation"""
93
+ return int(self.query_operation.get("limit", 10))
94
+
95
+ @property
96
+ def traversal_depth(self) -> int:
97
+ """Get the traversal depth from the query operation"""
98
+ return int(self.query_operation.get("traversal_depth", 1))
99
+
100
+ @classmethod
101
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphQueryOperationRequestMessage':
102
+ """Create a GraphQueryOperationRequestMessage from a HaiMessage"""
103
+ payload = message.payload
104
+ query_operation_str = payload.get("query_operation", "{}")
105
+ query_operation = json.loads(query_operation_str)
106
+
107
+ return cls.create_message(
108
+ operation_type=query_operation.get("operation_type", ""),
109
+ anchor_node=query_operation.get("anchor_node", ""),
110
+ relationship_direction=query_operation.get("relationship_direction"),
111
+ relationship_type=query_operation.get("relationship_type"),
112
+ limit=query_operation.get("limit"),
113
+ traversal_depth=query_operation.get("traversal_depth")
114
+ )
@@ -0,0 +1,85 @@
1
+ import json
2
+ from typing import Dict, Any, TypeVar, Type
3
+
4
+ from ...domain.models.hai_message import HaiMessage
5
+ from ..models.request_message_topic import RequestMessageTopic
6
+
7
+ T = TypeVar('T', bound='HaiMessage')
8
+
9
+ class GraphQueryOperationResponseMessage(HaiMessage):
10
+ """Message with results from graph query operations"""
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,
19
+ operation_type: str,
20
+ result: Dict[str, Any],
21
+ success: bool = True,
22
+ error_message: str = None) -> 'GraphQueryOperationResponseMessage':
23
+ """
24
+ Create a response message with graph query operation results
25
+
26
+ Args:
27
+ operation_type: The type of operation that was performed
28
+ result: Dictionary containing the operation results
29
+ success: Whether the operation was successful
30
+ error_message: Error message if the operation failed
31
+
32
+ Returns:
33
+ A new GraphQueryOperationResponseMessage
34
+ """
35
+ payload = {
36
+ "operation_type": operation_type,
37
+ "result": json.dumps(result),
38
+ "success": success
39
+ }
40
+
41
+ if error_message:
42
+ payload["error_message"] = error_message
43
+
44
+ return cls.create(
45
+ topic=RequestMessageTopic.GRAPH_QUERY_OPERATION_RESPONSE,
46
+ payload=payload,
47
+ )
48
+
49
+ @property
50
+ def operation_type(self) -> str:
51
+ """Get the operation type from the payload"""
52
+ return self.payload.get("operation_type", "")
53
+
54
+ @property
55
+ def result(self) -> Dict[str, Any]:
56
+ """Get the result from the payload"""
57
+ result_str = self.payload.get("result", "{}")
58
+ return json.loads(result_str)
59
+
60
+ @property
61
+ def success(self) -> bool:
62
+ """Get the success status from the payload"""
63
+ return self.payload.get("success", False)
64
+
65
+ @property
66
+ def error_message(self) -> str:
67
+ """Get the error message from the payload"""
68
+ return self.payload.get("error_message", "")
69
+
70
+ @classmethod
71
+ def from_hai_message(cls, message: HaiMessage) -> 'GraphQueryOperationResponseMessage':
72
+ """Create a GraphQueryOperationResponseMessage from a HaiMessage"""
73
+ payload = message.payload
74
+ operation_type = payload.get("operation_type", "")
75
+ result_str = payload.get("result", "{}")
76
+ result = json.loads(result_str)
77
+ success = payload.get("success", False)
78
+ error_message = payload.get("error_message")
79
+
80
+ return cls.create_message(
81
+ operation_type=operation_type,
82
+ result=result,
83
+ success=success,
84
+ error_message=error_message
85
+ )
@@ -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 InitKnowledgeBaseRequestMessage(HaiMessage):
9
+
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) -> 'InitKnowledgeBaseRequestMessage':
18
+ """Create a message requesting to clear the graph"""
19
+ return cls.create(
20
+ topic=RequestMessageTopic.INIT_KNOWLEDGE_BASE,
21
+ payload={}
22
+ )
23
+
24
+ @classmethod
25
+ def from_hai_message(cls, message: HaiMessage) -> 'InitKnowledgeBaseRequestMessage':
26
+ return cls.create_message()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: h_message_bus
3
- Version: 0.0.30
3
+ Version: 0.0.32
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,7 +13,7 @@ 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=JA8BXe4-cjyrfhLyu_y22AUx2QPLUNi3k-8QYGff_Jo,2851
16
+ h_message_bus/domain/models/request_message_topic.py,sha256=Ec9ilhsR0ylcSqz0Uv11Eim-q9sBVm4JH8yg4IVh9lE,3145
17
17
  h_message_bus/domain/models/twitter_message_metadata.py,sha256=Cj0dSVQi0Com9nPlJeEM0c-ZAQKGqIq_txvdzYg0myw,1203
18
18
  h_message_bus/domain/models/twitter_user_metadata.py,sha256=N7GVyn2txmlMQ19aatNh7lvzO6FNSj4dKVujestha9o,2827
19
19
  h_message_bus/domain/models/vector_collection_metadata.py,sha256=fSy3ZQ-zkYISTpc-_M6XWf1JkufVAlzlS2ZT60TzA2s,891
@@ -30,8 +30,11 @@ h_message_bus/domain/request_messages/graph_node_update_request_message.py,sha25
30
30
  h_message_bus/domain/request_messages/graph_node_update_response_message.py,sha256=VMCOF4FnKNvTItex8daeR2BSwN9juubj0ksHPHh0BT4,2424
31
31
  h_message_bus/domain/request_messages/graph_nodes_by_property_request_message.py,sha256=L-oZfZqsI9DG-CFL0G7r-2A-6wTqFuMNkDww2JUR73s,1712
32
32
  h_message_bus/domain/request_messages/graph_nodes_by_property_response_message.py,sha256=UDCA769I14BNP2Qmfwg5c6m98nBNVSZ10Kpi8Z8AGAQ,3051
33
+ h_message_bus/domain/request_messages/graph_query_operation_request_message.py,sha256=vc0NZQpjFDJT4ms0zsoSluBOZxePVuXuZZSDHlCKHPU,4568
34
+ h_message_bus/domain/request_messages/graph_query_operation_response_message.py,sha256=-rML2iTebOmkN-_UczA4VZd6kMHbgeqjMtuPypRVuuY,3004
33
35
  h_message_bus/domain/request_messages/graph_query_request_message.py,sha256=UXs_m6pgPkYRSRHrhI-c3WAQ31Yj1idZBgavufm32s0,1635
34
36
  h_message_bus/domain/request_messages/graph_relationship_added_request_message.py,sha256=a2hJyF78ITCjkvdR_v_NbnUvxFkolnCyN1-71rF-J2I,2388
37
+ h_message_bus/domain/request_messages/init_knowledgebase_request.py,sha256=ydX5J784wW0aoXosffSJBAQ6xFmKY5Y8bsWITaIJqbY,891
35
38
  h_message_bus/domain/request_messages/tg_message_request_message.py,sha256=bta24fXwwxTMCwdDHlbB20T-0SNkNWdPwNsQbo_OGN0,1447
36
39
  h_message_bus/domain/request_messages/tg_user_message_reply_request_message.py,sha256=desDxVddPTp7iOYq7126zDEyaJF1bu9LWEamj-e87IA,1767
37
40
  h_message_bus/domain/request_messages/tg_user_message_request_message.py,sha256=pHmmGJpMEnwzbTVVvoD6UOMflQOuQKgErZA9MyRwWt8,3121
@@ -51,7 +54,7 @@ h_message_bus/domain/request_messages/web_search_request_message.py,sha256=ZoB4i
51
54
  h_message_bus/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
52
55
  h_message_bus/infrastructure/nats_client_repository.py,sha256=bhaWRK94h2EmFIef2DALnoBJKnuTnx6-iU7IXO2S_EU,3642
53
56
  h_message_bus/infrastructure/nats_config.py,sha256=Yzqqd1bCfmUv_4FOnA1dvqIpakzV0BUL2_nXQcndWvo,1304
54
- h_message_bus-0.0.30.dist-info/METADATA,sha256=rg9Z6lf9ukHebwDXUxmSq52eFtwdATGhXn8afJkmU80,8834
55
- h_message_bus-0.0.30.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
56
- h_message_bus-0.0.30.dist-info/top_level.txt,sha256=BArjhm_lwFR9yJJEIf-LT_X64psuLkXFdbpQRJUreFE,23
57
- h_message_bus-0.0.30.dist-info/RECORD,,
57
+ h_message_bus-0.0.32.dist-info/METADATA,sha256=EDqM6sULqdLtkUqAgf_4S2SDXeD78CPorlnl9GbK72o,8834
58
+ h_message_bus-0.0.32.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
59
+ h_message_bus-0.0.32.dist-info/top_level.txt,sha256=BArjhm_lwFR9yJJEIf-LT_X64psuLkXFdbpQRJUreFE,23
60
+ h_message_bus-0.0.32.dist-info/RECORD,,