feat: enforce agent routing and persist restart state
Task 4: stale room blocking + agent_id binding - MatrixBot._check_agent_routing: blocks normal messages when user has no selected agent or room is bound to a different agent - agent_routing_enabled flag on MatrixRuntime activates the check only in real multi-agent mode (RoutedPlatformClient) - make_handle_new_chat now writes agent_id into new room metadata when user already has a selected agent Task 5: durable restart state tests - test_restart_persistence.py proves selected_agent_id, room agent_id, platform_chat_id, and the sequence counter all survive SQLiteStore close/reopen; also covers clean startup with no prior state
This commit is contained in:
parent
74cf028e8f
commit
e733119d1e
4 changed files with 256 additions and 22 deletions
|
|
@ -8,6 +8,7 @@ from nio.api import RoomVisibility
|
|||
from nio.responses import RoomCreateError
|
||||
|
||||
from adapter.matrix.store import (
|
||||
get_selected_agent_id,
|
||||
get_user_meta,
|
||||
next_chat_id,
|
||||
next_platform_chat_id,
|
||||
|
|
@ -104,18 +105,18 @@ def make_handle_new_chat(
|
|||
state_key=room_id,
|
||||
)
|
||||
|
||||
await set_room_meta(
|
||||
store,
|
||||
room_id,
|
||||
{
|
||||
"room_type": "chat",
|
||||
"chat_id": chat_id,
|
||||
"display_name": room_name,
|
||||
"matrix_user_id": event.user_id,
|
||||
"space_id": space_id,
|
||||
"platform_chat_id": platform_chat_id,
|
||||
},
|
||||
)
|
||||
selected_agent_id = await get_selected_agent_id(store, event.user_id)
|
||||
room_meta: dict = {
|
||||
"room_type": "chat",
|
||||
"chat_id": chat_id,
|
||||
"display_name": room_name,
|
||||
"matrix_user_id": event.user_id,
|
||||
"space_id": space_id,
|
||||
"platform_chat_id": platform_chat_id,
|
||||
}
|
||||
if selected_agent_id:
|
||||
room_meta["agent_id"] = selected_agent_id
|
||||
await set_room_meta(store, room_id, room_meta)
|
||||
ctx = await chat_mgr.get_or_create(
|
||||
user_id=event.user_id,
|
||||
chat_id=chat_id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue