HEL-879 rework materials: hatchling cache correction with the offline mem0ai wheel actually built from the fixed source (sha256 698284b6..., zero downloads/installs, no 3.10 mixing, recorded in release-artifacts.json), hel895 release doc §0 now separates the historical HEL-895/896 candidate from the current hel-879-assembly candidate and §4/§5 carry the v3 snapshot semantics, budget §6.2.4 amended - a sealed library is never reopened by raising total_requests (contradiction removed), runbook §3.3/3.5/3.6/4.4/4.5 corrected (bounded cleanup ledger replaces the unproven rooms-die-naturally claim; assistant_interim kind; real-but-default-off proactive seam; single-owner dual launcher), one comment-only correction in web/src/voice/session.ts removing the unproven server-auto-cleanup claim (no logic/style change; CSS and JS bundle hashes byte-stable), CG-011 + her incremental subtitles now have a real minimal backend seam (voice/seam.py + worker/llm_chat_api wiring, proactive default off) with the precise frontend interface and acceptance list in docs/rework/hel879/voice-seam-interfaces.md, real-SDK check extended to 10 items (worker callback path on real SpeechHandle/SpeechCreatedEvent; interim seam through real LLMStream) and re-run on .12 ALL PASS, handoff-HEL-879.json appended with the rework scope; regression at this head: pytest 341/341, ruff clean except 1 pre-existing error identical at 7f0a739, web typecheck 0 errors / lint 0 errors 1 pre-existing warning / vitest 88/88 / build passes (CSS index-BpZaybfD.css unchanged), voice chain 8/8, budget split 10/10, release offline R1-R7, http pagination 7/7, real-service browser 9/9 with zero non-loopback outbound, pinned-SDK 16/16+12/12+6/6+7/7+12/12, requirements checks 4/4 (origin/main and c121c42, each with/without handoff)
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
multica-agent
parent
78a5cfd8d7
commit
7c73d392b9
@@ -35,6 +35,7 @@ from livekit.plugins.silero import VAD
|
||||
|
||||
from .llm_chat_api import CyberGrillLLM
|
||||
from .receipt import ReceiptSender, TurnLedger, should_ack
|
||||
from .seam import AssistantInterimPublisher, pending_proactive
|
||||
from .stt_funasr import FunASRSTT
|
||||
from .tts_cosyvoice import CosyVoiceTTS
|
||||
|
||||
@@ -46,6 +47,10 @@ VOICE_STATE = Path(
|
||||
)
|
||||
)
|
||||
WORKER_HEALTH_PORT = int(os.environ.get("CYBERGRIL_WORKER_HEALTH_PORT", "8082"))
|
||||
# CG-011 语音主动开口(HEL-879 最小接缝):默认关闭,接线卡与视觉作者定好
|
||||
# 入口呈现并经批准后才置 1。开启后只念服务端已落库 proactive=1 的行。
|
||||
PROACTIVE_VOICE = os.environ.get("CYBERGRIL_PROACTIVE_VOICE", "") == "1"
|
||||
PROACTIVE_PER_SESSION = 1
|
||||
SUBTOPIC = "cg.subtitle"
|
||||
|
||||
# 占位指令:真正的人格由统一服务在 /api/chat 服务端组装。适配器忽略
|
||||
@@ -66,15 +71,27 @@ def prewarm(proc: JobProcess) -> None:
|
||||
proc.userdata["vad"] = VAD.load()
|
||||
|
||||
|
||||
async def _maybe_open_proactive(session: AgentSession, room) -> None:
|
||||
"""CG-011 主动开口接缝(本卡不实现,留明确边界,不丢需求)。
|
||||
async def _maybe_open_proactive(session: AgentSession, room, client=None,
|
||||
already_spoken: set[int] | None = None) -> list[int]:
|
||||
"""CG-011 主动开口最小接缝(HEL-879:真实代码路径,默认关闭).
|
||||
|
||||
语音里的主动开口必须:仅在已开启的语音会话内、走同一条业务链(只念
|
||||
服务端已落库、标记 proactive=1 的 companion 行,不新起模型调用)、可被
|
||||
用户打断、不新造第二条回执通道。具体呈现与节奏由总管/视觉总监在接线
|
||||
卡定;在此之前保持空操作。
|
||||
仅在已开启的语音会话内、只念服务端已落库、标记 proactive=1、未在本房间
|
||||
念过的 companion 行(同一 GET /api/messages 入口,无第二人格/无新模型调用),
|
||||
`session.say(..., allow_interruptions=True)` 可被用户打断,不新建回执通道
|
||||
(文字回执规则独立且已存在)。每会话有界(PROACTIVE_PER_SESSION)。
|
||||
入口呈现与节奏由总管/视觉总监在接线卡定;批准前置 CYBERGRIL_PROACTIVE_VOICE=1。
|
||||
返回本次念出的消息 id(接线/验收用;未启用返回空)。
|
||||
"""
|
||||
return None
|
||||
if not PROACTIVE_VOICE:
|
||||
return []
|
||||
spoken: set[int] = already_spoken if already_spoken is not None else set()
|
||||
rows = await pending_proactive(client, already_spoken=spoken,
|
||||
limit=PROACTIVE_PER_SESSION)
|
||||
spoken_ids: list[int] = []
|
||||
for row in rows:
|
||||
await session.say(row["text"], allow_interruptions=True)
|
||||
spoken_ids.append(row["id"])
|
||||
return spoken_ids
|
||||
|
||||
|
||||
async def entrypoint(ctx: JobContext) -> None:
|
||||
@@ -82,12 +99,22 @@ async def entrypoint(ctx: JobContext) -> None:
|
||||
# agent 说话期间短文本/相似文本视为回声丢弃(同通用 worker 的实测做法)
|
||||
stt.agent_speaking = False
|
||||
stt.agent_recent_text = ""
|
||||
|
||||
def subtitle(payload: dict) -> None:
|
||||
data = json.dumps(payload, ensure_ascii=False).encode()
|
||||
asyncio.get_running_loop().create_task(
|
||||
ctx.room.local_participant.publish_data(data, topic=SUBTOPIC, reliable=False)
|
||||
)
|
||||
|
||||
ledger = TurnLedger()
|
||||
interim = AssistantInterimPublisher(subtitle)
|
||||
|
||||
def note_stream(stream) -> None:
|
||||
interim.reset() # a new generation must not inherit the old text
|
||||
ledger.note_stream(stream, stream.created_at)
|
||||
|
||||
llm = CyberGrillLLM(API_BASE, on_stream_started=note_stream)
|
||||
llm = CyberGrillLLM(API_BASE, on_stream_started=note_stream,
|
||||
on_assistant_delta=interim.feed)
|
||||
receipts = ReceiptSender(llm.client)
|
||||
|
||||
session = AgentSession(
|
||||
@@ -101,12 +128,6 @@ async def entrypoint(ctx: JobContext) -> None:
|
||||
},
|
||||
)
|
||||
|
||||
def subtitle(payload: dict) -> None:
|
||||
data = json.dumps(payload, ensure_ascii=False).encode()
|
||||
asyncio.get_running_loop().create_task(
|
||||
ctx.room.local_participant.publish_data(data, topic=SUBTOPIC, reliable=False)
|
||||
)
|
||||
|
||||
@session.on("user_input_transcribed")
|
||||
def _on_transcript(ev) -> None:
|
||||
if ev.transcript.strip():
|
||||
@@ -175,7 +196,14 @@ async def entrypoint(ctx: JobContext) -> None:
|
||||
|
||||
await ctx.connect()
|
||||
await session.start(room=ctx.room, agent=Agent(instructions=INSTRUCTIONS_PLACEHOLDER))
|
||||
await _maybe_open_proactive(session, ctx.room)
|
||||
spoken_proactive: set[int] = set()
|
||||
try:
|
||||
spoken = await _maybe_open_proactive(session, ctx.room, client=llm.client,
|
||||
already_spoken=spoken_proactive)
|
||||
spoken_proactive.update(spoken)
|
||||
except Exception as exc: # seam failure never breaks the session start
|
||||
print(f"[cybergril-worker] proactive seam skipped: {type(exc).__name__}: {exc}",
|
||||
flush=True)
|
||||
print(
|
||||
f"[cybergril-worker] session started (api={API_BASE}, "
|
||||
f"voice={read_default_voice()}, agent_name={AGENT_NAME})",
|
||||
|
||||
Reference in New Issue
Block a user