Skip to content

Commit 22c7fc2

Browse files
committed
Adds voice input feature
1 parent e34e569 commit 22c7fc2

File tree

3 files changed

+419
-52
lines changed

3 files changed

+419
-52
lines changed

frontend/package-lock.json

Lines changed: 50 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/InputForm.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SelectTrigger,
1010
SelectValue,
1111
} from "@/components/ui/select";
12+
import { VoiceInput } from "@/components/VoiceInput";
1213

1314
// Updated InputFormProps
1415
interface InputFormProps {
@@ -26,7 +27,7 @@ export const InputForm: React.FC<InputFormProps> = ({
2627
}) => {
2728
const [internalInputValue, setInternalInputValue] = useState("");
2829
const [effort, setEffort] = useState("medium");
29-
const [model, setModel] = useState("gemini-2.5-flash-preview-04-17");
30+
const [model, setModel] = useState("gemini-2.5-flash");
3031

3132
const handleInternalSubmit = (e?: React.FormEvent) => {
3233
if (e) e.preventDefault();
@@ -36,13 +37,35 @@ export const InputForm: React.FC<InputFormProps> = ({
3637
};
3738

3839
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
39-
// Submit with Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac)
40+
// Submit with Enter (not Ctrl+Enter) - this is more intuitive
41+
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey) {
42+
e.preventDefault();
43+
handleInternalSubmit();
44+
}
45+
// Allow Shift+Enter for new lines
46+
// Allow Ctrl+Enter and Cmd+Enter as alternative submit methods
4047
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
4148
e.preventDefault();
4249
handleInternalSubmit();
4350
}
4451
};
4552

53+
const handleVoiceTranscription = (transcription: string, shouldAutoSubmit = false) => {
54+
// Append transcription to existing input value or replace if empty
55+
const newValue = internalInputValue.trim()
56+
? `${internalInputValue} ${transcription}`
57+
: transcription;
58+
console.log('Setting transcription value:', newValue); // Debug log
59+
setInternalInputValue(newValue);
60+
61+
// If auto-submit is requested, submit immediately with the new value
62+
if (shouldAutoSubmit && newValue.trim()) {
63+
console.log('Auto-submitting with new value:', newValue); // Debug log
64+
onSubmit(newValue, effort, model);
65+
setInternalInputValue("");
66+
}
67+
};
68+
4669
const isSubmitDisabled = !internalInputValue.trim() || isLoading;
4770

4871
return (
@@ -64,7 +87,16 @@ export const InputForm: React.FC<InputFormProps> = ({
6487
md:text-base min-h-[56px] max-h-[200px]`}
6588
rows={1}
6689
/>
67-
<div className="-mt-3">
90+
<div className="flex items-center gap-2 -mt-3">
91+
{/* Voice Input Button */}
92+
<VoiceInput
93+
onTranscription={handleVoiceTranscription}
94+
disabled={isLoading}
95+
autoSubmit={true}
96+
timeoutDuration={15000} // 15 seconds instead of 30
97+
/>
98+
99+
{/* Submit/Cancel Button */}
68100
{isLoading ? (
69101
<Button
70102
type="button"
@@ -144,7 +176,7 @@ export const InputForm: React.FC<InputFormProps> = ({
144176
</div>
145177
</SelectItem>
146178
<SelectItem
147-
value="gemini-2.5-flash-preview-04-17"
179+
value="gemini-2.5-flash"
148180
className="hover:bg-neutral-600 focus:bg-neutral-600 cursor-pointer"
149181
>
150182
<div className="flex items-center">
@@ -176,4 +208,4 @@ export const InputForm: React.FC<InputFormProps> = ({
176208
</div>
177209
</form>
178210
);
179-
};
211+
};

0 commit comments

Comments
 (0)