h-ai-brain 0.0.7__py3-none-any.whl → 0.0.9__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.
@@ -17,13 +17,9 @@ class PriorityQueueService:
17
17
  self.repository.add_item(queue_name, item)
18
18
  return item
19
19
 
20
- def get_next_item(self, queue_name: str) -> Optional[QueueItem]:
20
+ def get_next_item(self, queue_name: str, block: bool = True, timeout: float = 30.0) -> Optional[QueueItem]:
21
21
  """Get and remove the highest priority item from the queue"""
22
- return self.repository.get_highest_priority_item(queue_name)
23
-
24
- def get_items(self, queue_name: str, limit: int = 10) -> List[QueueItem]:
25
- """Get multiple items from the queue in priority order without removing them"""
26
- return self.repository.get_items(queue_name, limit)
22
+ return self.repository.get_highest_priority_item(queue_name, block=block, timeout=timeout)
27
23
 
28
24
  def get_queue_length(self, queue_name: str) -> int:
29
25
  """Get the number of items in the queue"""
@@ -14,14 +14,14 @@ class PriorityQueueRepository(ABC):
14
14
  pass
15
15
 
16
16
  @abstractmethod
17
- def get_highest_priority_item(self, queue_name: str) -> Optional[QueueItem]:
17
+ def get_highest_priority_item(self, queue_name: str, block: bool = False, timeout: Optional[float] = None) -> Optional[QueueItem]:
18
18
  """Get and remove the highest priority item from the queue"""
19
19
  pass
20
20
 
21
- @abstractmethod
22
- def get_items(self, queue_name: str, limit: int = 10) -> List[QueueItem]:
23
- """Get multiple items from the queue in priority order without removing them"""
24
- pass
21
+ # @abstractmethod
22
+ # def get_items(self, queue_name: str, limit: int = 10) -> List[QueueItem]:
23
+ # """Get multiple items from the queue in priority order without removing them"""
24
+ # pass
25
25
 
26
26
  @abstractmethod
27
27
  def queue_length(self, queue_name: str) -> int:
@@ -1,4 +1,4 @@
1
-
1
+ import queue
2
2
  import threading
3
3
  from queue import PriorityQueue
4
4
  from typing import Dict, List, Optional
@@ -31,56 +31,67 @@ class InMemoryPriorityQueueRepository(PriorityQueueRepository):
31
31
 
32
32
  def add_item(self, queue_name: str, item: QueueItem) -> None:
33
33
  """Add an item to the specified queue"""
34
- queue = self._get_or_create_queue(queue_name)
34
+ q = self._get_or_create_queue(queue_name)
35
35
  with self._get_lock(queue_name):
36
36
  # The queue automatically orders by priority
37
- queue.put(item)
37
+ q.put(item)
38
38
 
39
- def get_highest_priority_item(self, queue_name: str) -> Optional[QueueItem]:
39
+ def get_highest_priority_item(self, queue_name: str, block: bool = False, timeout: Optional[float] = None) -> Optional[QueueItem]:
40
40
  """Get and remove the highest priority item from the queue"""
41
41
  if queue_name not in self.queues:
42
42
  return None
43
43
 
44
- queue = self.queues[queue_name]
45
- with self._get_lock(queue_name):
46
- if queue.empty():
47
- return None
48
- return queue.get()
44
+ q = self.queues[queue_name]
45
+ try:
46
+ # We need to acquire the lock to check initially, but then we need to release it
47
+ # so that other threads can add items while we're blocking
48
+ with self._get_lock(queue_name):
49
+ # If not blocking and queue is empty, return immediately
50
+ if not block and q.empty():
51
+ return None
52
+
53
+ # Note: queue.get() with block=True will internally manage locking
54
+ # We don't hold our custom lock during the blocking wait
55
+ return q.get(block=block, timeout=timeout)
56
+ except queue.Empty:
57
+ # This will be raised if timeout occurs with no items
58
+ return None
59
+
49
60
 
50
61
  def get_items(self, queue_name: str, limit: int = 10) -> List[QueueItem]:
51
- """Get multiple items from the queue in priority order without removing them"""
52
- if queue_name not in self.queues:
53
- return []
62
+ """Get multiple items from the queue in priority order without removing them"""
63
+ if queue_name not in self.queues:
64
+ return []
54
65
 
55
- queue = self.queues[queue_name]
56
- result = []
66
+ q = self.queues[queue_name]
67
+ result = []
57
68
 
58
- with self._get_lock(queue_name):
59
- # Create a temporary list to hold items that we'll put back
60
- temp_items = []
69
+ with self._get_lock(queue_name):
70
+ # Create a temporary list to hold items that we'll put back
71
+ temp_items = []
61
72
 
62
- # Get up to 'limit' items
63
- count = 0
64
- while not queue.empty() and count < limit:
65
- item = queue.get()
66
- temp_items.append(item)
67
- result.append(item)
68
- count += 1
73
+ # Get up to 'limit' items
74
+ count = 0
75
+ while not q.empty() and count < limit:
76
+ item = q.get()
77
+ temp_items.append(item)
78
+ result.append(item)
79
+ count += 1
69
80
 
70
- # Put all the items back in the same order
71
- for item in temp_items:
72
- queue.put(item)
81
+ # Put all the items back in the same order
82
+ for item in temp_items:
83
+ q.put(item)
73
84
 
74
- return result
85
+ return result
75
86
 
76
87
  def queue_length(self, queue_name: str) -> int:
77
88
  """Get the number of items in the queue"""
78
89
  if queue_name not in self.queues:
79
90
  return 0
80
91
 
81
- queue = self.queues[queue_name]
92
+ q = self.queues[queue_name]
82
93
  with self._get_lock(queue_name):
83
- return queue.qsize()
94
+ return q.qsize()
84
95
 
85
96
  def get_queue_names(self) -> List[str]:
86
97
  """Get a list of all available queue names"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: h_ai_brain
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: AI Research agent API
5
5
  Author-email: shoebill <shoebill.hai@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,13 +1,13 @@
1
1
  h_ai/__init__.py,sha256=bmHMDoui52Q73UvXdHslQ3w_LubmhRuKRlrjOYyCP8c,153
2
2
  h_ai/application/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  h_ai/application/hai_service.py,sha256=ZSbDLP8oCBliLpbhpKOf7Xv6cWDsLCSeDeurn207FsA,3005
4
- h_ai/application/priority_queue_service.py,sha256=qi1PZMLYxy3HzG6cu-2hLijUYGcYGYMpzAp4S0vl0I0,1462
4
+ h_ai/application/priority_queue_service.py,sha256=QzPOPDV-_KXTConRpuHmzFFe9HF8HLGPkX_Ael7Hs9g,1304
5
5
  h_ai/application/web_docs_service.py,sha256=YiPBfPyjlloDq6CIOP0u7F1jNBK-elYRU8xl4qJ1oVc,1652
6
6
  h_ai/application/system_prompts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  h_ai/application/system_prompts/roles/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  h_ai/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
9
  h_ai/domain/priorityqueue/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
- h_ai/domain/priorityqueue/priority_queue_repository.py,sha256=XCjBrJezloblcqOPJUStTmU5tofx954h-mzxOsYIAbg,1042
10
+ h_ai/domain/priorityqueue/priority_queue_repository.py,sha256=_px-WFlsj439EKV1qN-z85rQDeybhs2p-xGEXRpOtHE,1104
11
11
  h_ai/domain/priorityqueue/queue_item.py,sha256=aP2Sd3ig9dgKnAsKE_rr3uRjJ_ClWIrvz0Y3nC8XbmE,1417
12
12
  h_ai/domain/reasoning/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
13
  h_ai/domain/reasoning/llm_chat_repository.py,sha256=rY2izDyaDnoyyrCRS1qc9erHB98vARj4Mp-SnPwNhyY,211
@@ -47,10 +47,10 @@ h_ai/infrastructure/llm/ollama/models/ollama_chat_session.py,sha256=GZ_ddpbWa8iy
47
47
  h_ai/infrastructure/playwright/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  h_ai/infrastructure/playwright/playwright_web_content_fetcher.py,sha256=FVwcK6hv_6aE4fYlJapLHyxNHsztQkKaulklHabyrEc,2684
49
49
  h_ai/infrastructure/priorityqueue/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
50
- h_ai/infrastructure/priorityqueue/in_memory_priority_queue_repository.py,sha256=-DodmvFBUFnglJJmbUFEi3HpqxEdZvYrOpwZrWZrSU0,3262
51
- h_ai_brain-0.0.7.dist-info/licenses/LICENSE,sha256=SbvpEU5JIU3yzMMkyzrI0dGqHDoJR_lMKGdl6GZHsy4,11558
52
- h_ai_brain-0.0.7.dist-info/licenses/NOTICE.txt,sha256=vxeIKUiGqAePLvDW4AVm3Xh-3BcsvMtCMn1tbsr9zsE,668
53
- h_ai_brain-0.0.7.dist-info/METADATA,sha256=KxLN_FGexCNE_QbLb9lpyx_YWEM7-P8VO_Zoy--v1Yk,735
54
- h_ai_brain-0.0.7.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
55
- h_ai_brain-0.0.7.dist-info/top_level.txt,sha256=3MChDBWvDJV4cEHuZhzeODxQ4ewtw-arOuyaDOc6sIo,5
56
- h_ai_brain-0.0.7.dist-info/RECORD,,
50
+ h_ai/infrastructure/priorityqueue/in_memory_priority_queue_repository.py,sha256=zxnrbzoLfiKQMB28dI1bPe0qUtvIDG8OEFcTQL_UeFg,3886
51
+ h_ai_brain-0.0.9.dist-info/licenses/LICENSE,sha256=SbvpEU5JIU3yzMMkyzrI0dGqHDoJR_lMKGdl6GZHsy4,11558
52
+ h_ai_brain-0.0.9.dist-info/licenses/NOTICE.txt,sha256=vxeIKUiGqAePLvDW4AVm3Xh-3BcsvMtCMn1tbsr9zsE,668
53
+ h_ai_brain-0.0.9.dist-info/METADATA,sha256=mjj0vnc-r1oeLMoJF_dkXWnKUeOGu1IJrlcwTZ_1TII,735
54
+ h_ai_brain-0.0.9.dist-info/WHEEL,sha256=pxyMxgL8-pra_rKaQ4drOZAegBVuX-G_4nRHjjgWbmo,91
55
+ h_ai_brain-0.0.9.dist-info/top_level.txt,sha256=3MChDBWvDJV4cEHuZhzeODxQ4ewtw-arOuyaDOc6sIo,5
56
+ h_ai_brain-0.0.9.dist-info/RECORD,,