Skip to content

Commit 1fce1a3

Browse files
jakeleventhalclaude
andcommitted
refactor: use Toggle for the voice button and a schema voice error
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 6ee113a commit 1fce1a3

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

‎apps/server/src/provider/CodexVoice.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Deferred from "effect/Deferred";
66
import * as Effect from "effect/Effect";
77
import * as Exit from "effect/Exit";
88
import * as Fiber from "effect/Fiber";
9+
import * as Schema from "effect/Schema";
910
import * as Scope from "effect/Scope";
1011
import * as Stream from "effect/Stream";
1112
import type * as CodexClient from "effect-codex-app-server/client";
@@ -183,7 +184,7 @@ describe("makeCodexVoice", () => {
183184
const exit = yield* Fiber.await(voice.fiber);
184185
NodeAssert.ok(Exit.isFailure(exit));
185186
const error = exit.cause.reasons[0];
186-
NodeAssert.ok(error?._tag === "Fail" && error.error instanceof CodexVoiceSessionError);
187+
NodeAssert.ok(error?._tag === "Fail" && Schema.is(CodexVoiceSessionError)(error.error));
187188
NodeAssert.equal(error.error.detail, "realtime unavailable");
188189
}),
189190
);

‎apps/server/src/provider/CodexVoice.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
*/
1111
import type { ProviderVoiceSessionEvent } from "@t3tools/contracts";
1212
import * as Cause from "effect/Cause";
13-
import * as Data from "effect/Data";
1413
import * as Effect from "effect/Effect";
1514
import * as Queue from "effect/Queue";
1615
import * as Ref from "effect/Ref";
16+
import * as Schema from "effect/Schema";
1717
import type * as Scope from "effect/Scope";
1818
import * as Stream from "effect/Stream";
1919
import type * as CodexClient from "effect-codex-app-server/client";
@@ -86,9 +86,11 @@ function transcriptRole(role: string): "user" | "assistant" {
8686
return role === "user" ? "user" : "assistant";
8787
}
8888

89-
export class CodexVoiceSessionError extends Data.TaggedError("CodexVoiceSessionError")<{
90-
readonly detail: string;
91-
}> {
89+
/** Codex ended the realtime session with an error; `detail` is Codex's explanation for the user. */
90+
export class CodexVoiceSessionError extends Schema.TaggedError<CodexVoiceSessionError>()(
91+
"CodexVoiceSessionError",
92+
{ detail: Schema.String },
93+
) {
9294
override get message(): string {
9395
return this.detail;
9496
}

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ function ComposerCommandMenuLayer(props: { anchor: HTMLElement | null; children:
10551055
);
10561056
}
10571057
import { Button } from "../ui/button";
1058+
import { Toggle } from "../ui/toggle";
10581059
import { Select, SelectItem, SelectPopup, SelectValue } from "../ui/select";
10591060
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
10601061
import { toastManager } from "../ui/toast";
@@ -7416,19 +7417,17 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
74167417
<Tooltip>
74177418
<TooltipTrigger
74187419
render={
7419-
<Button
7420-
type="button"
7420+
<Toggle
74217421
variant="ghost"
7422-
size="icon-sm"
7422+
size="sm"
74237423
// aria-disabled rather than disabled keeps the tooltip explaining why.
7424-
className={cn(
7425-
voiceEngaged && "bg-accent text-foreground",
7426-
"aria-disabled:cursor-not-allowed aria-disabled:opacity-64",
7427-
)}
7424+
className="aria-disabled:cursor-not-allowed aria-disabled:opacity-64"
7425+
pressed={voiceEngaged}
74287426
onPointerDown={(event) => event.preventDefault()}
7429-
onClick={voiceButtonDisabledReason === null ? toggleVoice : undefined}
7427+
onPressedChange={() => {
7428+
if (voiceButtonDisabledReason === null) toggleVoice();
7429+
}}
74307430
aria-disabled={voiceButtonDisabledReason !== null || undefined}
7431-
aria-pressed={voiceEngaged}
74327431
aria-label={voiceButtonLabel}
74337432
/>
74347433
}

0 commit comments

Comments
 (0)