Add on_client_ready method to BaseBrain and WorkflowBrain
- Implement on_client_ready in BaseBrain to handle client-visible state after the app message channel is ready. - Extend WorkflowBrain with on_client_ready to replay state that may have been emitted before WebRTC data was ready. - Update pipeline to call on_client_ready when a client connects. - Enhance tests to verify the correct behavior of on_client_ready in WorkflowBrain.
This commit is contained in:
@@ -498,6 +498,25 @@ class WorkflowBrainTests(unittest.IsolatedAsyncioTestCase):
|
||||
start_brain._manager = FakeManager()
|
||||
await start_brain.on_connected()
|
||||
self.assertEqual(start_brain._manager.current_node, "start")
|
||||
queued.clear()
|
||||
await start_brain.on_client_ready()
|
||||
ready_messages = [
|
||||
frame.message
|
||||
for frame in queued
|
||||
if isinstance(frame, OutputTransportMessageUrgentFrame)
|
||||
]
|
||||
self.assertIn(
|
||||
{"type": "node-active", "nodeId": "start"},
|
||||
ready_messages,
|
||||
)
|
||||
self.assertTrue(
|
||||
any(
|
||||
message.get("type") == "workflow-variables"
|
||||
and message.get("reason") == "client_ready"
|
||||
and message.get("nodeId") == "start"
|
||||
for message in ready_messages
|
||||
)
|
||||
)
|
||||
|
||||
agent_brain = WorkflowBrain(
|
||||
{
|
||||
@@ -524,6 +543,16 @@ class WorkflowBrainTests(unittest.IsolatedAsyncioTestCase):
|
||||
agent_brain._runtime = runtime
|
||||
agent_brain._manager = FakeManager("agent")
|
||||
queued.clear()
|
||||
await agent_brain.on_client_ready()
|
||||
self.assertTrue(
|
||||
any(
|
||||
isinstance(frame, OutputTransportMessageUrgentFrame)
|
||||
and frame.message
|
||||
== {"type": "node-active", "nodeId": "agent"}
|
||||
for frame in queued
|
||||
)
|
||||
)
|
||||
queued.clear()
|
||||
handled = await agent_brain.on_user_turn_end("请继续回答")
|
||||
self.assertTrue(handled)
|
||||
self.assertEqual(agent_brain._manager.current_node, "agent")
|
||||
|
||||
Reference in New Issue
Block a user