44
55from typing import Any , Callable , Dict , Optional
66
7- from ...contracts .v1 import DaemonError , DaemonResponse
8- from ...kernel .actors import list_actors
7+ from ...contracts .v1 import DaemonError , DaemonResponse , SystemNotifyData
98from ...kernel .group import load_group
109from ...kernel .inbox import find_event
1110from ...kernel .ledger import append_event
11+ from .delivery import emit_system_notify
1212
1313
1414def _error (code : str , message : str , * , details : Optional [Dict [str , Any ]] = None ) -> DaemonResponse :
@@ -19,7 +19,6 @@ def handle_system_notify(
1919 args : Dict [str , Any ],
2020 * ,
2121 coerce_bool : Callable [[Any ], bool ],
22- queue_system_notify : Callable [..., None ],
2322) -> DaemonResponse :
2423 group_id = str (args .get ("group_id" ) or "" ).strip ()
2524 by = str (args .get ("by" ) or "system" ).strip ()
@@ -44,47 +43,16 @@ def handle_system_notify(
4443 if priority not in valid_priorities :
4544 priority = "normal"
4645
47- event = append_event (
48- group .ledger_path ,
49- kind = "system.notify" ,
50- group_id = group .group_id ,
51- scope_key = "" ,
52- by = by ,
53- data = {
54- "kind" : kind ,
55- "priority" : priority ,
56- "title" : title ,
57- "message" : message ,
58- "target_actor_id" : target_actor_id ,
59- "requires_ack" : requires_ack ,
60- "context" : context ,
61- },
46+ notify = SystemNotifyData (
47+ kind = kind ,
48+ priority = priority ,
49+ title = title ,
50+ message = message ,
51+ target_actor_id = target_actor_id ,
52+ requires_ack = requires_ack ,
53+ context = context ,
6254 )
63-
64- if priority in ("high" , "urgent" ):
65- event_id = str (event .get ("id" ) or "" ).strip ()
66- event_ts = str (event .get ("ts" ) or "" ).strip ()
67- for actor in list_actors (group ):
68- if not isinstance (actor , dict ):
69- continue
70- aid = str (actor .get ("id" ) or "" ).strip ()
71- if not aid or aid == "user" :
72- continue
73- if target_actor_id and aid != target_actor_id :
74- continue
75- runner_kind = str (actor .get ("runner" ) or "pty" ).strip ()
76- if runner_kind != "pty" :
77- continue
78- queue_system_notify (
79- group ,
80- actor_id = aid ,
81- event_id = event_id ,
82- notify_kind = kind ,
83- title = title ,
84- message = message ,
85- ts = event_ts ,
86- )
87-
55+ event = emit_system_notify (group , by = by , notify = notify )
8856 return DaemonResponse (ok = True , result = {"event" : event })
8957
9058
@@ -131,10 +99,9 @@ def try_handle_system_notify_op(
13199 args : Dict [str , Any ],
132100 * ,
133101 coerce_bool : Callable [[Any ], bool ],
134- queue_system_notify : Callable [..., None ],
135102) -> Optional [DaemonResponse ]:
136103 if op == "system_notify" :
137- return handle_system_notify (args , coerce_bool = coerce_bool , queue_system_notify = queue_system_notify )
104+ return handle_system_notify (args , coerce_bool = coerce_bool )
138105 if op == "notify_ack" :
139106 return handle_notify_ack (args )
140107 return None
0 commit comments