fix: relay confirmation interrupts past muted input
This commit is contained in:
@@ -8,7 +8,6 @@
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
from collections.abc import Awaitable, Callable
|
||||
from io import BytesIO
|
||||
from typing import Any
|
||||
|
||||
@@ -107,21 +106,6 @@ ON_DEMAND_KNOWLEDGE_SYSTEM_HINT = (
|
||||
)
|
||||
|
||||
|
||||
async def _wait_for_output_stop(
|
||||
wait_until_stopped: Callable[[], Awaitable[None]],
|
||||
*,
|
||||
timeout_seconds: float = 3.0,
|
||||
) -> None:
|
||||
"""Wait for the transport's real stop event after an interruption."""
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
wait_until_stopped(),
|
||||
timeout=timeout_seconds,
|
||||
)
|
||||
except TimeoutError as exc:
|
||||
raise RuntimeError("等待客户端语音停止超时") from exc
|
||||
|
||||
|
||||
def _compact_knowledge_metadata(value: str, max_length: int) -> str:
|
||||
"""Keep tool metadata useful without letting it dominate the model context."""
|
||||
compact = " ".join(value.split())
|
||||
@@ -437,6 +421,11 @@ async def run_pipeline(
|
||||
should_ignore_update=lambda: call_end.ending,
|
||||
)
|
||||
client_tools = ClientToolBroker()
|
||||
# Confirmation nodes mute the user aggregator, which intentionally drops
|
||||
# InterruptionFrame. Relay confirmation interruptions from the next
|
||||
# processor instead so LLM, assistant aggregation, TTS, and output all see
|
||||
# the frame before the workflow continues.
|
||||
client_tools.set_interrupt_handler(user_turn_router.broadcast_interruption)
|
||||
vision_capture = VisionCaptureProcessor()
|
||||
knowledge_retrieval = KnowledgeRetrievalProcessor(
|
||||
automatic_knowledge_id,
|
||||
@@ -751,11 +740,6 @@ async def run_pipeline(
|
||||
current_enable_interrupt = enable_interrupt
|
||||
current_turn_config = normalized
|
||||
|
||||
async def wait_for_output_stopped() -> None:
|
||||
"""Keep workflow continuation behind the interrupted output."""
|
||||
if call_end.speaking:
|
||||
await _wait_for_output_stop(call_end.wait_until_silent)
|
||||
|
||||
def set_system_prompt(text: str) -> None:
|
||||
"""替换上下文里的系统提示(节点切换时整体替换,而非追加)。"""
|
||||
messages = context.get_messages()
|
||||
@@ -788,7 +772,6 @@ async def run_pipeline(
|
||||
set_vision_scope=lambda scope: workflow_vision_scope.update(scope),
|
||||
vision_function=workflow_vision_function,
|
||||
set_input_enabled=lambda enabled: input_state.__setitem__("enabled", enabled),
|
||||
wait_for_output_stopped=wait_for_output_stopped,
|
||||
apply_turn_config=apply_workflow_turn_config,
|
||||
flow_global_functions=flow_global_functions,
|
||||
),
|
||||
@@ -877,6 +860,7 @@ async def run_pipeline(
|
||||
vision_enabled=vision_enabled,
|
||||
vision_state=vision_state,
|
||||
submit_user_input=submit_user_input,
|
||||
client_tools=client_tools,
|
||||
)
|
||||
runner = WorkerRunner(handle_sigint=False)
|
||||
run_status = "completed"
|
||||
|
||||
@@ -16,6 +16,7 @@ from pipecat.runner.utils import (
|
||||
maybe_capture_participant_camera,
|
||||
)
|
||||
from pipecat.utils.time import time_now_iso8601
|
||||
from services.client_tools import ClientToolBroker
|
||||
from services.pipecat.processors import UserInput
|
||||
|
||||
|
||||
@@ -32,6 +33,7 @@ def bind_cascade_pipeline_events(
|
||||
vision_enabled: bool,
|
||||
vision_state: dict[str, str | None],
|
||||
submit_user_input: Callable[[UserInput], Awaitable[None]] | None = None,
|
||||
client_tools: ClientToolBroker | None = None,
|
||||
) -> None:
|
||||
"""Connect processors to transport events without owning pipeline assembly."""
|
||||
|
||||
@@ -159,6 +161,8 @@ def bind_cascade_pipeline_events(
|
||||
|
||||
@assistant_aggregator.event_handler("on_interruption_processed")
|
||||
async def on_interruption_processed(_aggregator):
|
||||
if client_tools is not None:
|
||||
client_tools.on_interruption_processed()
|
||||
if not pending_user_inputs:
|
||||
return
|
||||
await finish_user_input(pending_user_inputs.pop(0))
|
||||
|
||||
Reference in New Issue
Block a user