feat: couple broadcast to voice + voice-controlled broadcast toggle
Completes the STREAM_BROWSER=true behaviour:
- handleJoin auto-starts the broadcast on voice join and wires the session to
the guild streamer; each turn reports the live state to the brain so search
routes Chrome (live) vs Gemini (off).
- New setBroadcast tool lets the user toggle the broadcast by voice ("방송
켜줘/꺼줘") via the LLM (no hardcoded phrases); it refuses when
STREAM_BROWSER=false. The directive flows brain -> bridge (broadcast_action)
-> bot streamer.start/stop, guarded by isActive() so it's idempotent.
- Per-turn IPC uses a thread-local (reply/turn_state.py) instead of threading
params through the whole engine chain: bridge sets broadcasting in, tool
records the directive out; Tool.execute exposes broadcasting on ToolContext.
Bot typecheck clean; brain covered by tests/test_set_broadcast.py (+ existing
routing tests). Specs + docs updated.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -81,6 +81,30 @@ async function handleJoin(i: ChatInputCommandInteraction) {
|
||||
const session = await joinChannel(channel);
|
||||
session.onTurn = ({ transcript, reply }) =>
|
||||
console.log(`🗣️ ${transcript}\n🤖 ${reply}`);
|
||||
|
||||
// Screen-share mode (STREAM_BROWSER=true): the broadcast is coupled to the
|
||||
// voice session. Auto-start it on join, report its live state to the brain
|
||||
// each turn (search routes Chrome while live / Gemini when off), and let the
|
||||
// brain toggle it via voice ("방송 켜줘 / 꺼줘"). In voice-only mode
|
||||
// (STREAM_BROWSER=false) none of this runs and the broadcast stays off.
|
||||
if (config.screenBrowser) {
|
||||
const streamer = await getStreamer(i.guildId!);
|
||||
const ctx: StreamContext = { guildId: i.guildId!, voiceChannelId: channel.id };
|
||||
session.getBroadcasting = () => streamer.isActive();
|
||||
session.onBroadcastAction = async (action) => {
|
||||
if (action === "start") {
|
||||
if (!streamer.isActive()) await streamer.start(ctx);
|
||||
} else if (streamer.isActive()) {
|
||||
await streamer.stop();
|
||||
}
|
||||
};
|
||||
try {
|
||||
if (!streamer.isActive()) await streamer.start(ctx);
|
||||
} catch (e) {
|
||||
console.error("[join] auto-broadcast failed:", e);
|
||||
}
|
||||
}
|
||||
|
||||
await i.editReply(`🎙️ '${channel.name}' 채널에 접속했습니다. 말씀하세요.`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user