Skip to content

Commit 52fcb22

Browse files
czerwiukkCopilot
andauthored
Deafen agent by default while introducing (#55)
* defer user input * adjust stories * wider tiles * Update deep-sea-stories/packages/backend/src/prompts/stories.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * remove slop * remove slop2 * formaty --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent bb5a158 commit 52fcb22

6 files changed

Lines changed: 27 additions & 7 deletions

File tree

deep-sea-stories/packages/backend/src/agent/api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export interface AgentConfig {
66
onEndGame: () => Promise<void>;
77
gameTimeLimitSeconds: number;
88
onTranscription: (transcription: string) => void;
9+
onReadyForPlayerInput?: () => void;
910
}
1011

1112
export interface VoiceAgentApi {

deep-sea-stories/packages/backend/src/agent/gemini/session.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class GeminiSession implements VoiceAgentSession {
2525
private opening = false;
2626
private reconnecting = false;
2727
private ending = false;
28+
private awaitingInitialGreeting = false;
2829

2930
private talkingTimeLeft = 0;
3031
private talkingInterval: NodeJS.Timeout | null = null;
@@ -87,6 +88,9 @@ export class GeminiSession implements VoiceAgentSession {
8788
this.opening = true;
8889
this.ending = false;
8990

91+
const shouldRequestIntro =
92+
!this.previousHandle && !this.awaitingInitialGreeting;
93+
9094
const params: LiveConnectParameters = {
9195
model: GEMINI_MODEL,
9296
config: {
@@ -130,7 +134,8 @@ export class GeminiSession implements VoiceAgentSession {
130134

131135
this.session = await this.genai.live.connect(params);
132136

133-
if (!this.previousHandle) {
137+
if (shouldRequestIntro) {
138+
this.awaitingInitialGreeting = true;
134139
this.session.sendClientContent({
135140
turns: [
136141
{
@@ -139,6 +144,8 @@ export class GeminiSession implements VoiceAgentSession {
139144
],
140145
turnComplete: true,
141146
});
147+
} else if (!this.awaitingInitialGreeting) {
148+
this.config.onReadyForPlayerInput?.();
142149
}
143150

144151
if (this.talkingInterval) clearInterval(this.talkingInterval);
@@ -212,7 +219,13 @@ export class GeminiSession implements VoiceAgentSession {
212219
this.transcriptionParts = [];
213220
}
214221

215-
if (turnFinished) this.onTurnEnd?.();
222+
if (turnFinished) {
223+
if (this.awaitingInitialGreeting) {
224+
this.awaitingInitialGreeting = false;
225+
this.config.onReadyForPlayerInput?.();
226+
}
227+
this.onTurnEnd?.();
228+
}
216229

217230
const base64 = message.data;
218231
if (base64) {

deep-sea-stories/packages/backend/src/game/room.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ export class GameRoom {
146146
timestamp: Date.now(),
147147
});
148148
},
149+
onReadyForPlayerInput: () => {
150+
this.gameSession?.setAiAgentMuted(false);
151+
},
149152
});
150153

151154
const { agent: fishjamAgent, agentId: fishjamAgentId } =
@@ -166,6 +169,8 @@ export class GameRoom {
166169
this.notifierService,
167170
);
168171

172+
this.gameSession.setAiAgentMuted(true);
173+
169174
console.log(
170175
`Starting game for ${this.players.size} players in room ${this.roomId}`,
171176
);

deep-sea-stories/packages/backend/src/game/session.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export class GameSession {
3535
}
3636

3737
setAiAgentMuted(muted: boolean) {
38+
if (this.isAiAgentMuted === muted) return;
3839
this.isAiAgentMuted = muted;
3940
this.audioOrchestrator.setMuted(muted);
4041

deep-sea-stories/packages/backend/src/prompts/stories.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
"id": 1,
44
"title": "The Diver in the Forest",
55
"front": "A man is found dead in the middle of a burnt forest. He is wearing a full wet suit, flippers, and a scuba tank.",
6-
"back": "The man was diving in the ocean near the coast. A massive forest fire was raging nearby. A firefighting plane scooped up a load of water from the ocean to dump on the fire. The diver was accidentally scooped up along with the water and dropped from a great height onto the burning forest. He died on impact."
6+
"back": "The man was diving in the ocean near the coast. A massive forest fire was raging nearby. A firefighting plane scooped up a load of water from the ocean to dump on the fire. The diver was accidentally scooped up along with the water and dropped from a great height onto the burning forest."
77
},
88
{
99
"id": 2,
1010
"title": "The Light Switch",
11-
"front": "A man turned off the light and went to sleep. The next morning, he woke up, looked out the window, saw the devastation, and immediately killed himself.",
12-
"back": "The man was a lighthouse keeper. By turning off the light before going to sleep during a storm, he caused several ships to crash into the coast. When he saw the wreckage and bodies floating in the sea the next morning, he couldn't live with the guilt."
11+
"front": "A man turned off the light and went to sleep. The next morning, he woke up, looked out the window, saw tremendous devastation.",
12+
"back": "The man was a lighthouse keeper. By turning off the light before going to sleep during a storm, he caused several ships to crash into the coast. He saw the wreckage in the sea the next morning."
1313
},
1414
{
1515
"id": 3,
1616
"title": "The High Card",
17-
"front": "Four men sat around a table in a metal room. One man drew the highest card, smiled, and then immediately died.",
17+
"front": "Four men sat around a table in a metal room. One man drew the highest card, froze, and passed away seconds later.",
1818
"back": "The four men were the crew of a military submarine that had lost power and was running out of oxygen. They realized there was only enough air left for three of them to survive until rescue arrived. They drew cards to decide who would sacrifice themselves to save the others. The man with the high card \"won\" the draw and shot himself to stop consuming oxygen."
1919
},
2020
{

deep-sea-stories/packages/web/src/components/PeerTile.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const PeerTile: FC<PropsWithChildren<PeerTileProps>> = ({
4242
}, [audioStream]);
4343

4444
return (
45-
<div className={cn('h-full w-full max-w-xl', className)} {...props}>
45+
<div className={cn('h-full w-full max-w-3xl', className)} {...props}>
4646
<div
4747
className={cn(
4848
'h-full w-full flex border items-center justify-center rounded-xl overflow-hidden',

0 commit comments

Comments
 (0)