Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion site/src/pages/AgentsPage/components/AgentComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ function VoiceInput() {
return null;
}

// Dictation edits the draft, so only states that lock the draft block a
// new recording. A live recording can always be canceled.
const isDraftLocked = state.isReadOnly || state.isLoading;
const isStartBlocked = !state.speechRecording && isDraftLocked;

return (
<>
<Button
Expand All @@ -188,7 +193,7 @@ function VoiceInput() {
? actions.cancelRecording
: actions.startRecording
}
disabled={state.isDisabled}
disabled={isStartBlocked}
aria-label={
state.speechRecording ? "Cancel voice input" : "Voice input"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export function useComposerEditor(
};

const startRecording = () => {
if (isReadOnly || isLoading) {
return;
}

resetPromptCycle();
setPreRecordingValue(editorRef.current?.getValue()?.trim() ?? "");
speech.start();
Expand Down
64 changes: 37 additions & 27 deletions site/src/pages/AgentsPage/components/AgentComposers.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,33 +454,43 @@ describe("ChatComposer", () => {
expect(cancel).toHaveBeenCalledTimes(1);
});

it("lets a recording start while a turn is streaming", async () => {
const user = userEvent.setup();
const start = vi.fn();
mockedUseSpeechRecognition.mockReturnValue({
isSupported: true,
isRecording: false,
transcript: "",
error: null,
start,
stop: vi.fn(),
cancel: vi.fn(),
});

renderInput(
<ChatComposer
{...withBindings({
onSend: vi.fn(),
isStreaming: true,
onInterrupt: vi.fn(),
})}
/>,
);

await user.click(screen.getByRole("button", { name: "Voice input" }));
expect(start).toHaveBeenCalledTimes(1);
expect(screen.getByRole("button", { name: "Stop" })).toBeEnabled();
});
it.each([
{ isDisabled: false, isLoading: false, isReadOnly: false, starts: true },
{ isDisabled: true, isLoading: false, isReadOnly: false, starts: true },
{ isDisabled: false, isLoading: true, isReadOnly: false, starts: false },
{ isDisabled: false, isLoading: false, isReadOnly: true, starts: false },
])(
"guards voice input while streaming (%o)",
async ({ isDisabled, isLoading, isReadOnly, starts }) => {
const user = userEvent.setup();
const start = vi.fn();
mockedUseSpeechRecognition.mockReturnValue({
isSupported: true,
isRecording: false,
transcript: "",
error: null,
start,
stop: vi.fn(),
cancel: vi.fn(),
});

renderInput(
<ChatComposer
{...withBindings({
onSend: vi.fn(),
isStreaming: true,
isDisabled,
isLoading,
isReadOnly,
onInterrupt: vi.fn(),
})}
/>,
);

await user.click(screen.getByRole("button", { name: "Voice input" }));
expect(start).toHaveBeenCalledTimes(starts ? 1 : 0);
},
);

it("falls back to pasted text when every pasted file is refused", async () => {
const onAttach = vi.fn();
Expand Down
Loading