rusticai-api 1.0.0__tar.gz → 1.2.0__tar.gz

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 (29) hide show
  1. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/PKG-INFO +5 -5
  2. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/pyproject.toml +7 -7
  3. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/api_dependency_manager.py +10 -1
  4. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/guilds/comms_manager.py +57 -4
  5. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/README.md +0 -0
  6. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/__init__.py +0 -0
  7. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/addons/__init__.py +0 -0
  8. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/addons/boards/__init__.py +0 -0
  9. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/addons/boards/board_store.py +0 -0
  10. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/addons/boards/models.py +0 -0
  11. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/addons/boards/router.py +0 -0
  12. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/addons/boards/schema.py +0 -0
  13. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/addons/router.py +0 -0
  14. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/catalog/__init__.py +0 -0
  15. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/catalog/catalog_store.py +0 -0
  16. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/catalog/models.py +0 -0
  17. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/catalog/router.py +0 -0
  18. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/guilds/__init__.py +0 -0
  19. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/guilds/models.py +0 -0
  20. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/guilds/router.py +0 -0
  21. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/guilds/schema.py +0 -0
  22. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/guilds/service.py +0 -0
  23. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/guilds/socket.py +0 -0
  24. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/guilds/system_comms_manager.py +0 -0
  25. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/logging/__init__.py +0 -0
  26. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/logging/config.py +0 -0
  27. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/logging/format.py +0 -0
  28. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/main.py +0 -0
  29. {rusticai_api-1.0.0 → rusticai_api-1.2.0}/src/rustic_ai/api_server/main_debug.py +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rusticai-api
3
- Version: 1.0.0
3
+ Version: 1.2.0
4
4
  Summary: API Server for Rustic AI
5
5
  License-Expression: Apache-2.0
6
6
  Author: Dragonscale Industries Inc.
7
7
  Author-email: dev@dragonscale.ai
8
- Requires-Python: >=3.12,<3.13
8
+ Requires-Python: >=3.13,<3.14
9
9
  Classifier: Programming Language :: Python :: 3
10
- Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
11
  Provides-Extra: test
12
12
  Requires-Dist: fastapi (>=0.115.8,<0.116.0)
13
13
  Requires-Dist: griffe (>=1.7.2,<2.0.0)
@@ -16,8 +16,8 @@ Requires-Dist: psycopg (>=3.2.6,<4.0.0)
16
16
  Requires-Dist: ptvsd (>=4.3.2,<5.0.0)
17
17
  Requires-Dist: python-json-logger (>=3.3.0,<4.0.0)
18
18
  Requires-Dist: python-multipart (>=0.0.20,<0.0.21)
19
- Requires-Dist: rusticai-core (>=1.0.0,<1.1.0)
20
- Requires-Dist: rusticai-ray (>=1.0.0,<1.1.0)
19
+ Requires-Dist: rusticai-core (>=1.2.0,<1.3.0)
20
+ Requires-Dist: rusticai-ray (>=1.2.0,<1.3.0)
21
21
  Requires-Dist: starlette (>=0.45.3,<0.46.0)
22
22
  Requires-Dist: uvicorn (>=0.34.0,<0.35.0)
23
23
  Requires-Dist: websockets (>=15.0.1,<16.0.0)
@@ -5,12 +5,12 @@ build-backend = "poetry.core.masonry.api"
5
5
 
6
6
  [project]
7
7
  name = "rusticai-api"
8
- version = "1.0.0"
8
+ version = "1.2.0"
9
9
  description = "API Server for Rustic AI"
10
10
  authors = [{name = "Dragonscale Industries Inc.", email = "dev@dragonscale.ai"}]
11
11
  license = "Apache-2.0"
12
12
  readme = "README.md"
13
- requires-python = ">=3.12,<3.13"
13
+ requires-python = ">=3.13,<3.14"
14
14
  dynamic = ["dependencies"]
15
15
  urls = { Homepage = "https://www.rustic.ai/", Repository = "https://github.com/rustic-ai/rustic-ai", "Rustic AI Core" = "https://pypi.org/project/rusticai-core/" }
16
16
 
@@ -19,8 +19,8 @@ urls = { Homepage = "https://www.rustic.ai/", Repository = "https://github.com/r
19
19
  packages = [{ include = "rustic_ai", from = "src" }]
20
20
 
21
21
  [tool.poetry.dependencies]
22
- rusticai-core = { version = "1.0.0"}
23
- rusticai-ray = { version = "1.0.0"}
22
+ rusticai-core = { version = "1.2.0"}
23
+ rusticai-ray = { version = "1.2.0"}
24
24
  fastapi = "^0.115.8"
25
25
  starlette = "^0.45.3"
26
26
  uvicorn = "^0.34.0"
@@ -47,14 +47,14 @@ isort = "^6.0.0"
47
47
  mypy = "^1.15.0"
48
48
  pytest-asyncio = "^0.25.3"
49
49
  httpx = "^0.28.1"
50
- rusticai-testing = { version = "1.0.0"}
50
+ rusticai-testing = { version = "1.2.0"}
51
51
 
52
52
  [tool.poetry.extras]
53
53
  test = ["pytest", "pytest-asyncio", "httpx", "rusticai-testing"]
54
54
 
55
55
  [tool.black]
56
56
  line-length = 120
57
- target-version = ['py312']
57
+ target-version = ['py313']
58
58
  include = '\.pyi?$'
59
59
  exclude = '''
60
60
  /(
@@ -70,7 +70,7 @@ exclude = '''
70
70
  '''
71
71
 
72
72
  [tool.mypy]
73
- python_version = "3.12"
73
+ python_version = "3.13"
74
74
  ignore_missing_imports = true
75
75
  check_untyped_defs = true
76
76
  plugins = "pydantic.mypy"
@@ -26,6 +26,7 @@ class ApiDependencyManager:
26
26
  if not hasattr(self, "initialized"):
27
27
  self.dependency_map_cache: Dict[str, Dict[str, DependencySpec]] = {}
28
28
  self.dependency_resolver_cache: Dict[str, Dict[str, DependencyResolver]] = {}
29
+ self.org_id_cache: Dict[str, str] = {}
29
30
  self.initialized = True
30
31
 
31
32
  def get_dependency(self, dependency_name: str, engine: Engine, guild_id: str, agent_id: Optional[str] = None):
@@ -57,6 +58,7 @@ class ApiDependencyManager:
57
58
  guild_spec = guild_model.to_guild_spec()
58
59
 
59
60
  self.dependency_map_cache[guild_id] = GuildHelper.get_guild_dependency_map(guild_spec)
61
+ self.org_id_cache[guild_id] = guild_model.organization_id
60
62
 
61
63
  if dependency_name not in self.dependency_map_cache[guild_id]: # pragma: no cover
62
64
  raise HTTPException(
@@ -71,7 +73,14 @@ class ApiDependencyManager:
71
73
  )
72
74
 
73
75
  resolver = self.dependency_resolver_cache[guild_id][dependency_name]
74
- dependency = resolver.get_or_resolve(guild_id, agent_id)
76
+ # Get org_id from cache, or load it if not available
77
+ if guild_id not in self.org_id_cache:
78
+ guild_store = GuildStore(engine)
79
+ guild_model = guild_store.get_guild(guild_id)
80
+ if guild_model:
81
+ self.org_id_cache[guild_id] = guild_model.organization_id
82
+ org_id = self.org_id_cache.get(guild_id, guild_id) # Fallback to guild_id if still not available
83
+ dependency = resolver.get_or_resolve(org_id, guild_id, agent_id)
75
84
 
76
85
  return dependency
77
86
 
@@ -92,7 +92,14 @@ class GuildCommunicationManager:
92
92
  loop: asyncio.AbstractEventLoop,
93
93
  ) -> Callable[[Message], None]:
94
94
  def on_message(message: Message) -> None:
95
- logging.debug(f"Received message: {message}")
95
+ logging.debug(
96
+ "Websocket delivery candidate guild=%s user=%s message_id=%s topic=%s sender=%s",
97
+ guild_id,
98
+ user_id,
99
+ message.id,
100
+ message.topic_published_to,
101
+ message.sender.id if message.sender else None,
102
+ )
96
103
 
97
104
  try:
98
105
  coroutine = self.send_message(guild_id, user_id, message, websocket)
@@ -155,9 +162,22 @@ class GuildCommunicationManager:
155
162
  messaging: MessagingInterface = await self.get_or_create_messaging_interface(guild_spec)
156
163
  guild_client: Client = await self.create_guild_client(guild_id, user_id, messaging, websocket, loop)
157
164
  messaging.subscribe(UserProxyAgent.get_user_notifications_topic(user_id), guild_client)
165
+ logging.debug(
166
+ "Registered websocket client id=%s guild=%s user=%s notifications_topic=%s",
167
+ guild_client.id,
168
+ guild_id,
169
+ user_id,
170
+ UserProxyAgent.get_user_notifications_topic(user_id),
171
+ )
158
172
 
159
173
  user_agent_tag = AgentTag(id=self.get_socket_agent_id(user_id), name=user_name)
160
174
 
175
+ logging.debug(
176
+ "Publishing user agent creation request guild=%s user=%s topic=%s",
177
+ guild_id,
178
+ user_id,
179
+ GuildTopics.SYSTEM_TOPIC,
180
+ )
161
181
  guild_client.publish(
162
182
  Message(
163
183
  self._gemstone.get_id(Priority.NORMAL),
@@ -220,7 +240,15 @@ class GuildCommunicationManager:
220
240
  message_history = [ProcessEntry.model_validate(entry) for entry in history]
221
241
 
222
242
  try:
223
- logging.debug(f"Received message: {data}")
243
+ logging.debug(
244
+ "Websocket ingress guild=%s user=%s normalized_id=%s inbox_topic=%s thread=%s format=%s",
245
+ guild_id,
246
+ user_id,
247
+ data["id"],
248
+ UserProxyAgent.get_user_inbox_topic(user_id),
249
+ data["thread"],
250
+ data.get("format", "UNKNOWN"),
251
+ )
224
252
  message = Message(
225
253
  idg,
226
254
  topics=UserProxyAgent.get_user_inbox_topic(user_id),
@@ -232,7 +260,13 @@ class GuildCommunicationManager:
232
260
  message_history=message_history,
233
261
  )
234
262
 
235
- logging.debug(f"Publishing message: {message.model_dump_json()}")
263
+ logging.debug(
264
+ "Publishing websocket ingress message guild=%s user=%s message_id=%s topic=%s",
265
+ guild_id,
266
+ user_id,
267
+ message.id,
268
+ UserProxyAgent.get_user_inbox_topic(user_id),
269
+ )
236
270
 
237
271
  if message:
238
272
  guild_client.publish(message)
@@ -258,6 +292,25 @@ class GuildCommunicationManager:
258
292
  result = True
259
293
  return result
260
294
 
295
+ @staticmethod
296
+ def historical_message_sort_key(message: Message) -> tuple[int, int, bool, int, int]:
297
+ """
298
+ Prefer chronological ordering, but keep messages from the same interaction in causal order.
299
+
300
+ Different agents can generate IDs in the same millisecond with different machine IDs, which can
301
+ invert user-message/agent-response pairs if we sort purely by message ID.
302
+ """
303
+ # Any message that explicitly responds to an earlier message should come after
304
+ # the user-originated entry for that interaction, even if it shares the same root.
305
+ is_follow_up = message.in_response_to is not None
306
+ return (
307
+ message.timestamp,
308
+ message.root_thread_id,
309
+ is_follow_up,
310
+ len(message.message_history),
311
+ message.id,
312
+ )
313
+
261
314
  async def get_historical_user_notifications(self, guild_id: str, user_id: str, engine: Engine) -> List[Message]:
262
315
  guild_spec = await self.get_or_fetch_guild_spec(guild_id, engine)
263
316
 
@@ -279,7 +332,7 @@ class GuildCommunicationManager:
279
332
  ]
280
333
  # Combine and sort messages
281
334
  all_messages = user_msgs + filtered_broadcast_msgs
282
- result = sorted(all_messages, key=lambda msg: msg.id)
335
+ result = sorted(all_messages, key=self.historical_message_sort_key)
283
336
  logging.debug(f"Retrieved {len(result)} messages")
284
337
  return result
285
338
 
File without changes