neuro-simulator 0.2.1__py3-none-any.whl → 0.2.2__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.
@@ -33,7 +33,7 @@ async def start_stream():
33
33
  async def stop_stream():
34
34
  """Stops the live stream processes."""
35
35
  if process_manager.is_running:
36
- process_manager.stop_live_processes()
36
+ await process_manager.stop_live_processes()
37
37
  return {"status": "success", "message": "Stream stopped"}
38
38
  else:
39
39
  return {"status": "info", "message": "Stream is not running"}
@@ -41,7 +41,7 @@ async def stop_stream():
41
41
  @router.post("/restart", dependencies=[Depends(get_api_token)])
42
42
  async def restart_stream():
43
43
  """Restarts the live stream processes."""
44
- process_manager.stop_live_processes()
44
+ await process_manager.stop_live_processes()
45
45
  await asyncio.sleep(1) # Give time for tasks to cancel
46
46
  process_manager.start_live_processes()
47
47
  return {"status": "success", "message": "Stream restarted"}
@@ -2,6 +2,9 @@
2
2
  import asyncio
3
3
  import logging
4
4
 
5
+ from ..services.stream import live_stream_manager
6
+ from .websocket import connection_manager
7
+
5
8
  logger = logging.getLogger(__name__.replace("neuro_simulator", "server", 1))
6
9
 
7
10
  class ProcessManager:
@@ -28,7 +31,6 @@ class ProcessManager:
28
31
 
29
32
  logger.info("Starting core stream processes...")
30
33
  from ..core.application import generate_audience_chat_task, neuro_response_cycle, broadcast_events_task
31
- from ..services.stream import live_stream_manager
32
34
  from ..utils.queue import clear_all_queues
33
35
  from ..core.agent_factory import create_agent
34
36
 
@@ -45,10 +47,14 @@ class ProcessManager:
45
47
  self._is_running = True
46
48
  logger.info(f"Core processes started: {len(self._tasks)} tasks.")
47
49
 
48
- def stop_live_processes(self):
50
+ async def stop_live_processes(self):
49
51
  """Stops and cleans up all running background tasks."""
50
52
  if not self.is_running:
51
53
  return
54
+
55
+ logger.info("Broadcasting offline message before stopping tasks...")
56
+ await connection_manager.broadcast({"type": "offline"})
57
+ await asyncio.sleep(0.1) # Give a brief moment for the message to be sent
52
58
 
53
59
  logger.info(f"Stopping {len(self._tasks)} core tasks...")
54
60
  for task in self._tasks:
@@ -58,7 +64,6 @@ class ProcessManager:
58
64
  self._tasks.clear()
59
65
  self._is_running = False
60
66
 
61
- from ..services.stream import live_stream_manager
62
67
  live_stream_manager.reset_stream_state()
63
68
 
64
69
  logger.info("All core tasks have been stopped.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: neuro_simulator
3
- Version: 0.2.1
3
+ Version: 0.2.2
4
4
  Summary: Neuro Simulator Server
5
5
  Author-email: Moha-Master <hongkongreporter@outlook.com>
6
6
  License-Expression: MIT
@@ -11,7 +11,7 @@ neuro_simulator/agent/tools/__init__.py,sha256=1WZy6PADfi6o1avyy1y-ThWBFAPJ_bBqt
11
11
  neuro_simulator/agent/tools/core.py,sha256=o6Oyis-HFD-g6Z_u3T--tkmr9ylKJvybKqMRSMUwi1Q,5555
12
12
  neuro_simulator/api/__init__.py,sha256=5LWyDSayPGdQS8Rv13nmAKLyhPnMVPyTYDdvoMPB4xw,56
13
13
  neuro_simulator/api/agent.py,sha256=ABl_JoIxB4wW_J2J52bWndmTXkfGJBS5LZmbGuh7zv8,6343
14
- neuro_simulator/api/stream.py,sha256=Pg793dXLnJ0oydrIwWFgWD0cVdFAx_QOw6L5LjE0uIo,2069
14
+ neuro_simulator/api/stream.py,sha256=Yg-cwjVI2HTLAt7moWbDQ1ZbbP6QE1ZB8LrW6A3tcQk,2081
15
15
  neuro_simulator/api/system.py,sha256=hXznMcThuFhwopYWgpzrRxwtBuFnF_b_vinkOaE5XOs,3712
16
16
  neuro_simulator/core/__init__.py,sha256=-ojq25c8XA0CU25b0OxcGjH4IWFEDHR-HXSRSZIuKe8,57
17
17
  neuro_simulator/core/agent_factory.py,sha256=qMFidwT5IrOkyNHwmpO8_fRv20KLbaIBfWF-VTFCLNA,1742
@@ -26,12 +26,12 @@ neuro_simulator/services/letta.py,sha256=iXyzFyPVty3SjYCHOJAF1QqhUFmxTQbqk8lYJOw
26
26
  neuro_simulator/services/stream.py,sha256=dG7RuNI_ICohPkqKZ-zlBppo54BgWm_KYBs-ezzc73E,5907
27
27
  neuro_simulator/utils/__init__.py,sha256=xSEFzjT827W81mNyQ_DLtr00TgFlttqfFgpz9pSxFXQ,58
28
28
  neuro_simulator/utils/logging.py,sha256=BO-q_cCcoeamsc8eJqq2-L3Z8nhApze_v6LnmD-O8Ww,3411
29
- neuro_simulator/utils/process.py,sha256=FmwIuOsp19jJBEbAj-WeUpdUsQN7B9_J1rlU0Q1TXuo,2388
29
+ neuro_simulator/utils/process.py,sha256=9w2JQH59Wy6L8ADrig2QF88iajdykGPZIYJVJe6Al2Y,2603
30
30
  neuro_simulator/utils/queue.py,sha256=7SSnUnrqxHkqSeYVjp1S5kpr8qlo4IVdU2NsGwFQAVw,1546
31
31
  neuro_simulator/utils/state.py,sha256=E1ilecgMTOAhiw_kNvLG0akkhdZKhzKLrA3oB4NNVTA,538
32
32
  neuro_simulator/utils/websocket.py,sha256=yOdFvJzbNhcUn5EAuyS55G_R8q-snas5OvkOtS8g19E,2292
33
- neuro_simulator-0.2.1.dist-info/METADATA,sha256=bbJ6VZxoq8fqq0qVzjm0nYUKIhwfoNPNQd8hDKPSREY,8676
34
- neuro_simulator-0.2.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
- neuro_simulator-0.2.1.dist-info/entry_points.txt,sha256=qVd5ypnRRgU8Cw7rWfZ7o0OXyS9P9hgY-cRoN_mgz9g,51
36
- neuro_simulator-0.2.1.dist-info/top_level.txt,sha256=V8awSKpcrFnjJDiJxSfy7jtOrnuE2BgAR9hLmfMDWK8,16
37
- neuro_simulator-0.2.1.dist-info/RECORD,,
33
+ neuro_simulator-0.2.2.dist-info/METADATA,sha256=lBjb1G0VhfbDCQhRWQOxJzlt9Ut07XL6zApn6X6G_jo,8676
34
+ neuro_simulator-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
+ neuro_simulator-0.2.2.dist-info/entry_points.txt,sha256=qVd5ypnRRgU8Cw7rWfZ7o0OXyS9P9hgY-cRoN_mgz9g,51
36
+ neuro_simulator-0.2.2.dist-info/top_level.txt,sha256=V8awSKpcrFnjJDiJxSfy7jtOrnuE2BgAR9hLmfMDWK8,16
37
+ neuro_simulator-0.2.2.dist-info/RECORD,,