fix: record message confirmations in context
This commit is contained in:
@@ -12,6 +12,7 @@ from pipecat.frames.frames import (
|
||||
)
|
||||
import services.brains # Initialize the brain registry before realtime imports.
|
||||
from services.fixed_speech import FixedSpeechOutput
|
||||
from services.message_stage import MESSAGE_CONFIRMATION_CONTEXT_MARKER
|
||||
from services.pipecat.call_lifecycle import (
|
||||
CallEndCoordinator,
|
||||
FixedSpeechPlaybackMarkerFrame,
|
||||
@@ -141,6 +142,62 @@ class FixedSpeechPlaybackTest(unittest.IsolatedAsyncioTestCase):
|
||||
|
||||
self.assertEqual(reasons, ["workflow_completed"])
|
||||
|
||||
async def test_realtime_confirmation_is_appended_without_running_model(self):
|
||||
graph = {
|
||||
"specVersion": 3,
|
||||
"settings": {},
|
||||
"nodes": [
|
||||
{
|
||||
"id": "message",
|
||||
"type": "message",
|
||||
"data": {
|
||||
"title": "办理提示",
|
||||
"message": "确认后开始办理。",
|
||||
"confirmLabel": "继续办理",
|
||||
"completionPolicy": "confirmation",
|
||||
},
|
||||
}
|
||||
],
|
||||
"edges": [],
|
||||
}
|
||||
appended = []
|
||||
input_states = []
|
||||
|
||||
class FakeRealtime:
|
||||
async def send_text(self, text, *, run_immediately=True):
|
||||
appended.append((text, run_immediately))
|
||||
|
||||
class FakeClientTools:
|
||||
async def call(self, *_args, **_kwargs):
|
||||
return {"status": "ok", "data": {"action": "confirmed"}}
|
||||
|
||||
async def queue_frame(_frame):
|
||||
pass
|
||||
|
||||
controller = WorkflowRealtimeController(
|
||||
cfg=AssistantConfig(type="workflow", graph=graph),
|
||||
engine=WorkflowEngine(graph),
|
||||
store=DynamicVariableStore({}),
|
||||
runtime=SimpleNamespace(
|
||||
realtime=FakeRealtime(),
|
||||
queue_frame=queue_frame,
|
||||
call_end=SimpleNamespace(ending=False),
|
||||
session_id="test-session",
|
||||
client_tools=FakeClientTools(),
|
||||
set_input_enabled=input_states.append,
|
||||
capture_image=None,
|
||||
),
|
||||
)
|
||||
|
||||
succeeded = await controller._enter_message("message")
|
||||
|
||||
self.assertTrue(succeeded)
|
||||
self.assertEqual(input_states, [False, True])
|
||||
self.assertEqual(len(appended), 1)
|
||||
self.assertFalse(appended[0][1])
|
||||
self.assertIn(MESSAGE_CONFIRMATION_CONTEXT_MARKER, appended[0][0])
|
||||
self.assertIn("点击“继续办理”", appended[0][0])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user