Skip to content

Commit aea070a

Browse files
committed
fix(voice): stop inspector sessions and bound initial captions
1 parent f9b550b commit aea070a

5 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎apps/mobile/src/features/voice-mode/useVoiceMode.test.tsx‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ beforeEach(() => {
4242
root = createRoot(document.createElement("div"));
4343
});
4444
afterEach(() => act(() => root.unmount()));
45-
const render = (overlay: boolean) =>
45+
const render = (overlay: boolean, overlayRoute = "ThreadFiles") =>
4646
act(() =>
4747
root.render(
4848
<>
4949
<RouteName value="Thread">
5050
<Lifecycle />
5151
</RouteName>
5252
{overlay ? (
53-
<RouteName value="ThreadFiles">
53+
<RouteName value={overlayRoute}>
5454
<Lifecycle />
5555
</RouteName>
5656
) : null}
@@ -70,3 +70,9 @@ it("stops the previous thread when navigation selects a different thread", () =>
7070
render(false);
7171
expect(fixture.stop).toHaveBeenCalledTimes(1);
7272
});
73+
74+
it("stops voice when its fullscreen thread closes over the still-mounted thread", () => {
75+
render(true, "ThreadInspectorFullscreen");
76+
render(false, "ThreadInspectorFullscreen");
77+
expect(fixture.stop).toHaveBeenCalledTimes(1);
78+
});

‎apps/mobile/src/features/voice-mode/useVoiceMode.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export function useVoiceModeThreadLifecycle(target: VoiceSessionTarget): void {
4848
// oxlint-disable-next-line t3code/react-effect-budget -- Release the native call when its owning thread screen unmounts.
4949
useEffect(
5050
() => () => {
51-
if (routeName === "Thread" && voiceMode.isActiveFor({ environmentId, threadId }))
51+
if (
52+
(routeName === "Thread" || routeName === "ThreadInspectorFullscreen") &&
53+
voiceMode.isActiveFor({ environmentId, threadId })
54+
)
5255
voiceMode.stop();
5356
},
5457
[environmentId, threadId, routeName],

‎packages/client-runtime/src/voice-mode/controller.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ describe("VoiceModeController", () => {
173173
});
174174

175175
describe("voice captions", () => {
176+
it("bounds the first streaming caption as well as later deltas", () => {
177+
const text = "a".repeat(1500) + "end";
178+
expect(appendVoiceCaption([], "user", text)).toEqual([
179+
{ role: "user", text: text.slice(-1024), final: false },
180+
]);
181+
});
176182
it("interleaves speakers and settles each with its final text", () => {
177183
let captions = appendVoiceCaption([], "user", "hello");
178184
captions = appendVoiceCaption(captions, "assistant", "Hi");

‎packages/client-runtime/src/voice-mode/controller.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ export function appendVoiceCaption(
115115
): ReadonlyArray<VoiceCaption> {
116116
const openIndex = captions.findLastIndex((caption) => caption.role === role && !caption.final);
117117
if (openIndex === -1) {
118-
return [...captions, { role, text: delta.trimStart(), final: false }].slice(-MAX_CAPTIONS);
118+
return [
119+
...captions,
120+
{ role, text: delta.trimStart().slice(-MAX_CAPTION_CHARS), final: false },
121+
].slice(-MAX_CAPTIONS);
119122
}
120123
const open = captions[openIndex]!;
121124
const text = (open.text + delta).slice(-MAX_CAPTION_CHARS);

‎packages/client-runtime/src/voice-mode/session.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,9 @@ export function makeVoiceSessionValidator(
8585
(session) => session.id === providerThread?.providerSessionId,
8686
);
8787
if (!session || !["ready", "running", "waiting"].includes(session.status)) {
88-
return yield* Effect.fail(
89-
new VoiceSessionUnavailable({
90-
message: "The provider session is no longer running. Send a message first.",
91-
}),
92-
);
88+
return yield* new VoiceSessionUnavailable({
89+
message: "The provider session is no longer running. Send a message first.",
90+
});
9391
}
9492
}).pipe(
9593
Effect.matchCause({

0 commit comments

Comments
 (0)