pbesa 2.1__py3-none-any.whl → 4.0.0__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 (75) hide show
  1. pbesa/__init__.py +4 -3
  2. pbesa/cognitive.py +475 -0
  3. pbesa/kernel/__init__.py +4 -6
  4. pbesa/kernel/adapter.py +165 -0
  5. pbesa/kernel/agent.py +558 -0
  6. pbesa/kernel/io/__init__.py +2 -2
  7. pbesa/kernel/io/system_file.py +38 -0
  8. pbesa/kernel/io/tcp_server.py +23 -0
  9. pbesa/kernel/util.py +217 -0
  10. pbesa/kernel/world.py +43 -0
  11. pbesa/mas.py +565 -0
  12. pbesa/remote/__init__.py +5 -0
  13. pbesa/remote/adm_listener.py +44 -0
  14. pbesa/{middleware/remote/AdmListenerHandler.py → remote/adm_listener_handler.py} +74 -57
  15. pbesa/remote/exceptions.py +18 -0
  16. pbesa/remote/remote_adm.py +42 -0
  17. pbesa/{middleware/remote/RemoteAdmHandler.py → remote/remote_adm_handler.py} +109 -83
  18. pbesa/social/__init__.py +4 -0
  19. pbesa/social/collaborative_team.py +299 -0
  20. pbesa/social/delegator.py +81 -0
  21. pbesa/social/delegator_team.py +334 -0
  22. pbesa/social/dialog.py +153 -0
  23. pbesa/social/dispatcher_team.py +319 -0
  24. pbesa/social/templates.py +18 -0
  25. pbesa/social/worker.py +188 -0
  26. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/LICENSE +21 -21
  27. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/LICENSE.txt +21 -21
  28. pbesa-4.0.0.dist-info/METADATA +8 -0
  29. pbesa-4.0.0.dist-info/RECORD +32 -0
  30. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/WHEEL +5 -5
  31. {pbesa-2.1.dist-info → pbesa-4.0.0.dist-info}/top_level.txt +0 -0
  32. pbesa/engine/__init__.py +0 -2
  33. pbesa/engine/bdi/BDIAg.py +0 -42
  34. pbesa/engine/bdi/BDILevel.py +0 -10
  35. pbesa/engine/bdi/BDIMachine.py +0 -116
  36. pbesa/engine/bdi/Goal.py +0 -28
  37. pbesa/engine/bdi/GoalExe.py +0 -36
  38. pbesa/engine/bdi/__init__.py +0 -5
  39. pbesa/engine/rational/ActionExe.py +0 -35
  40. pbesa/engine/rational/Brain.py +0 -10
  41. pbesa/engine/rational/RationalAg.py +0 -43
  42. pbesa/engine/rational/__init__.py +0 -3
  43. pbesa/kernel/adapter/Adapter.py +0 -26
  44. pbesa/kernel/adapter/FileAdapter.py +0 -23
  45. pbesa/kernel/adapter/__init__.py +0 -2
  46. pbesa/kernel/agent/Action.py +0 -19
  47. pbesa/kernel/agent/Agent.py +0 -91
  48. pbesa/kernel/agent/BehaviorExe.py +0 -33
  49. pbesa/kernel/agent/Channel.py +0 -10
  50. pbesa/kernel/agent/World.py +0 -15
  51. pbesa/kernel/agent/__init__.py +0 -5
  52. pbesa/kernel/io/SystemFile.py +0 -13
  53. pbesa/kernel/io/TCPServer.py +0 -4
  54. pbesa/kernel/system/Adm.py +0 -189
  55. pbesa/kernel/system/Directory.py +0 -36
  56. pbesa/kernel/system/__init__.py +0 -2
  57. pbesa/kernel/util/HashTable.py +0 -62
  58. pbesa/kernel/util/Queue.py +0 -231
  59. pbesa/kernel/util/__init__.py +0 -2
  60. pbesa/middleware/__init__.py +0 -3
  61. pbesa/middleware/adapter/GameAdapter.py +0 -64
  62. pbesa/middleware/adapter/MongoAdapter.py +0 -47
  63. pbesa/middleware/adapter/RESTAdapter.py +0 -52
  64. pbesa/middleware/adapter/SubProcessAdapter.py +0 -30
  65. pbesa/middleware/adapter/WSSAdapter.py +0 -89
  66. pbesa/middleware/adapter/WSSNJAdapter.py +0 -51
  67. pbesa/middleware/adapter/WSSNJHandler.py +0 -23
  68. pbesa/middleware/adapter/__init__.py +0 -7
  69. pbesa/middleware/remote/AdmListener.py +0 -17
  70. pbesa/middleware/remote/RemoteAdm.py +0 -17
  71. pbesa/middleware/remote/__init__.py +0 -4
  72. pbesa/middleware/web/WebAgTK.py +0 -15
  73. pbesa/middleware/web/__init__.py +0 -0
  74. pbesa-2.1.dist-info/METADATA +0 -25
  75. pbesa-2.1.dist-info/RECORD +0 -54
pbesa/kernel/util.py ADDED
@@ -0,0 +1,217 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ----------------------------------------------------------
4
+ ------------------------- PBESA --------------------------
5
+ ----------------------------------------------------------
6
+
7
+ @autor AKEN & SIDRE
8
+ @version 4.0.0
9
+ @date 09/08/24
10
+ """
11
+
12
+ # --------------------------------------------------------
13
+ # Define resources
14
+ # --------------------------------------------------------
15
+
16
+ import uuid
17
+ import base64
18
+ import requests
19
+
20
+ # --------------------------------------------------------
21
+ # Define generate short uuid
22
+ # --------------------------------------------------------
23
+
24
+ def generate_short_uuid(length=5):
25
+ # Generate a UUID
26
+ uuid_str = str(uuid.uuid4())
27
+
28
+ # Encode UUID to bytes
29
+ uuid_bytes = uuid.UUID(uuid_str).bytes
30
+
31
+ # Encode bytes to base64 and strip non-alphanumeric characters
32
+ base64_str = base64.urlsafe_b64encode(uuid_bytes).decode('utf-8').rstrip('=')
33
+
34
+ # Return a substring of the desired length
35
+ short_uuid = base64_str[:length]
36
+ short_uuid.replace('_', 'A')
37
+ short_uuid.replace('-', 'B')
38
+ short_uuid.replace('=', 'C')
39
+ return short_uuid.lower()
40
+
41
+ # --------------------------------------------------------
42
+ # Define API interface
43
+ # --------------------------------------------------------
44
+
45
+ class APIClient:
46
+ """API Client"""
47
+
48
+ def __init__(self, base_url, headers=None, timeout=120, access_token=None) -> None:
49
+ """ Initialize the API client with the given base URL, headers, and timeout.
50
+ @param base_url: Base URL for the API.
51
+ @param headers: Headers to include in the API requests.
52
+ @param timeout: Timeout for the API requests.
53
+ @param access_token: Access token to include in the headers.
54
+ """
55
+ self.base_url = base_url
56
+ self.headers = headers if headers else {
57
+ 'Content-Type': 'application/json',
58
+ }
59
+ self.timeout = timeout
60
+ if access_token:
61
+ self.headers['Authorization'] = f'Bearer {access_token}'
62
+
63
+ def post(self, endpoint, payload) -> dict:
64
+ """
65
+ Make a POST request to the specified endpoint with the given data.
66
+ :param endpoint: Endpoint to send the POST request to.
67
+ :param payload: Data to include in the POST request.
68
+ :return: Response object if the request is successful, None otherwise.
69
+ """
70
+ response = None
71
+ try:
72
+ response = requests.post(
73
+ url=f"{self.base_url}/{endpoint}",
74
+ headers=self.headers,
75
+ json=payload,
76
+ timeout=self.timeout
77
+ )
78
+ response.raise_for_status()
79
+ print(f"POST request to {endpoint} succeeded: {response.status_code}")
80
+ res = {
81
+ "status": True,
82
+ "message": response.json()
83
+ }
84
+ return res
85
+ except requests.exceptions.HTTPError as http_err:
86
+ print(f"HTTP error occurred: {http_err}")
87
+ except requests.exceptions.ConnectionError as conn_err:
88
+ print(f"Connection error occurred: {conn_err}")
89
+ except requests.exceptions.Timeout as timeout_err:
90
+ print(f"Timeout error occurred: {timeout_err}")
91
+ except requests.exceptions.RequestException as req_err:
92
+ print(f"An error occurred: {req_err}")
93
+ if response is not None:
94
+ return {
95
+ "status": False,
96
+ "message": response.text
97
+ }
98
+ return {
99
+ "status": False,
100
+ "message": "An error occurred while making the POST request."
101
+ }
102
+
103
+ def get(self, endpoint) -> dict:
104
+ """
105
+ Make a GET request to the specified endpoint.
106
+ :param endpoint: Endpoint to send the GET request to.
107
+ :return: Response object if the request is successful, None otherwise.
108
+ """
109
+ response = None
110
+ try:
111
+ response = requests.get(
112
+ url=f"{self.base_url}/{endpoint}",
113
+ headers=self.headers,
114
+ timeout=self.timeout
115
+ )
116
+ response.raise_for_status()
117
+ print(f"GET request to {endpoint} succeeded: {response.status_code}")
118
+ res = {
119
+ "status": True,
120
+ "message": response.json()
121
+ }
122
+ return res
123
+ except requests.exceptions.HTTPError as http_err:
124
+ print(f"HTTP error occurred: {http_err}")
125
+ except requests.exceptions.ConnectionError as conn_err:
126
+ print(f"Connection error occurred: {conn_err}")
127
+ except requests.exceptions.Timeout as timeout_err:
128
+ print(f"Timeout error occurred: {timeout_err}")
129
+ except requests.exceptions.RequestException as req_err:
130
+ print(f"An error occurred: {req_err}")
131
+ if response is not None:
132
+ return {
133
+ "status": False,
134
+ "message": response.text
135
+ }
136
+ return {
137
+ "status": False,
138
+ "message": "An error occurred while making the GET request."
139
+ }
140
+
141
+ def put(self, endpoint, payload) -> dict:
142
+ """
143
+ Make a PUT request to the specified endpoint with the given data.
144
+ :param endpoint: Endpoint to send the PUT request to.
145
+ :param payload: Data to include in the PUT request.
146
+ :return: Response object if the request is successful, None otherwise.
147
+ """
148
+ response = None
149
+ try:
150
+ response = requests.put(
151
+ url=f"{self.base_url}/{endpoint}",
152
+ headers=self.headers,
153
+ json=payload,
154
+ timeout=self.timeout
155
+ )
156
+ response.raise_for_status()
157
+ print(f"PUT request to {endpoint} succeeded: {response.status_code}")
158
+ res = {
159
+ "status": True,
160
+ "message": response.json()
161
+ }
162
+ return res
163
+ except requests.exceptions.HTTPError as http_err:
164
+ print(f"HTTP error occurred: {http_err}")
165
+ except requests.exceptions.ConnectionError as conn_err:
166
+ print(f"Connection error occurred: {conn_err}")
167
+ except requests.exceptions.Timeout as timeout_err:
168
+ print(f"Timeout error occurred: {timeout_err}")
169
+ except requests.exceptions.RequestException as req_err:
170
+ print(f"An error occurred: {req_err}")
171
+ if response is not None:
172
+ return {
173
+ "status": False,
174
+ "message": response.text
175
+ }
176
+ return {
177
+ "status": False,
178
+ "message": "An error occurred while making the PUT request."
179
+ }
180
+
181
+ def delete(self, endpoint) -> dict:
182
+ """
183
+ Make a DELETE request to the specified endpoint.
184
+ :param endpoint: Endpoint to send the DELETE request to.
185
+ :return: Response object if the request is successful, None otherwise.
186
+ """
187
+ response = None
188
+ try:
189
+ response = requests.delete(
190
+ url=f"{self.base_url}/{endpoint}",
191
+ headers=self.headers,
192
+ timeout=self.timeout
193
+ )
194
+ response.raise_for_status()
195
+ print(f"DELETE request to {endpoint} succeeded: {response.status_code}")
196
+ res = {
197
+ "status": True,
198
+ "message": response.json()
199
+ }
200
+ return res
201
+ except requests.exceptions.HTTPError as http_err:
202
+ print(f"HTTP error occurred: {http_err}")
203
+ except requests.exceptions.ConnectionError as conn_err:
204
+ print(f"Connection error occurred: {conn_err}")
205
+ except requests.exceptions.Timeout as timeout_err:
206
+ print(f"Timeout error occurred: {timeout_err}")
207
+ except requests.exceptions.RequestException as req_err:
208
+ print(f"An error occurred: {req_err}")
209
+ if response is not None:
210
+ return {
211
+ "status": False,
212
+ "message": response.text
213
+ }
214
+ return {
215
+ "status": False,
216
+ "message": "An error occurred while making the DELETE request."
217
+ }
pbesa/kernel/world.py ADDED
@@ -0,0 +1,43 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ ----------------------------------------------------------
4
+ -------------------------- PBESA -------------------------
5
+ ----------------------------------------------------------
6
+
7
+ @autor AKEN
8
+ @version 4.0.0
9
+ @date 08/08/24
10
+ """
11
+
12
+ # --------------------------------------------------------
13
+ # Define resources
14
+ # --------------------------------------------------------
15
+
16
+ from .agent import Agent
17
+ from abc import ABC, abstractmethod
18
+
19
+ # --------------------------------------------------------
20
+ # Define component
21
+ # --------------------------------------------------------
22
+
23
+ class World(ABC):
24
+ """ World class """
25
+
26
+ def __init__(self) -> None:
27
+ """ Constructor """
28
+ self.agent = None
29
+ super().__init__()
30
+
31
+ @abstractmethod
32
+ def update(self, event, data) -> None:
33
+ """ Update world
34
+ :param event: Event
35
+ :param data: Data
36
+ """
37
+ pass
38
+
39
+ def set_agent(self, agent:Agent) -> None:
40
+ """ Set agent
41
+ :param agent: Agent
42
+ """
43
+ self.agent = agent