Skip to content

Commit 3d5fa94

Browse files
committed
feat(frontend): pass model and length from Hero submit
1 parent 4fc2881 commit 3d5fa94

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

frontend/src/components/landing/Hero.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { filesToAttached } from "@/lib/attachFiles"
1212
import type { AttachedFile } from "@/types/file"
1313
import { useSpeechRecognition } from "@/hooks/useSpeechRecognition"
1414
import { useAuth } from "@/context/AuthContext"
15-
import { MODEL_OPTIONS, DEFAULT_MODEL_ID, type ModelOptionId } from "@/lib/models"
15+
import { MODEL_OPTIONS, DEFAULT_MODEL_ID, MODEL_ID_TO_API, type ModelOptionId } from "@/lib/models"
1616
import { startBackendSession, uploadLandingStashedFiles } from "@/lib/api"
1717

1818
/* ——— Rotating placeholder questions ——— */
@@ -172,7 +172,7 @@ function HeroModelBadge({ value, onChange }: { value: ModelOptionId; onChange?:
172172
)
173173
}
174174

175-
function ChatBox({ active, onActiveChange, onSubmit }: { active: boolean; onActiveChange: (v: boolean) => void; onSubmit: (text: string, files?: AttachedFile[]) => void }) {
175+
function ChatBox({ active, onActiveChange, onSubmit }: { active: boolean; onActiveChange: (v: boolean) => void; onSubmit: (text: string, files?: AttachedFile[], model?: ModelOptionId, lengthPreset?: "short" | "medium" | "long") => void }) {
176176
const [inputValue, setInputValue] = useState("")
177177
const [typedText, setTypedText] = useState("")
178178
const [model, setModel] = useState<ModelOptionId>(DEFAULT_MODEL_ID)
@@ -287,7 +287,7 @@ function ChatBox({ active, onActiveChange, onSubmit }: { active: boolean; onActi
287287
const text = inputValue.trim()
288288
if (!text && attachments.length === 0) return
289289
const messageText = text || "See attached files."
290-
onSubmit(messageText, attachments.length > 0 ? attachments : undefined)
290+
onSubmit(messageText, attachments.length > 0 ? attachments : undefined, model, lengthPreset)
291291
setInputValue("")
292292
setAttachments([])
293293
const ta = textareaRef.current
@@ -298,7 +298,7 @@ function ChatBox({ active, onActiveChange, onSubmit }: { active: boolean; onActi
298298
if (wrapper) wrapper.style.height = `${ROW_H}px`
299299
}
300300
setAttachments([])
301-
}, [inputValue, attachments, onSubmit])
301+
}, [inputValue, attachments, onSubmit, model, lengthPreset])
302302

303303
const handleFileChange = useCallback(async (e: React.ChangeEvent<HTMLInputElement>) => {
304304
const files = e.target.files
@@ -611,9 +611,9 @@ export function Hero() {
611611
const [chatActive, setChatActive] = useState(false)
612612
const [creatingSession, setCreatingSession] = useState(false)
613613
const [createError, setCreateError] = useState<string | null>(null)
614-
const pendingSubmitRef = useRef<{ text: string; files?: AttachedFile[] } | null>(null)
614+
const pendingSubmitRef = useRef<{ text: string; files?: AttachedFile[]; modelId?: ModelOptionId; length?: "short" | "medium" | "long" } | null>(null)
615615

616-
const doSubmit = useCallback((text: string, files?: AttachedFile[]) => {
616+
const doSubmit = useCallback((text: string, files?: AttachedFile[], modelId?: ModelOptionId, length?: "short" | "medium" | "long") => {
617617
const question = text.trim()
618618
if (!question && !files?.length) return
619619

@@ -632,14 +632,20 @@ export function Hero() {
632632
}
633633
}
634634

635+
const apiModel = modelId ? MODEL_ID_TO_API[modelId] : undefined
636+
const depth = length
637+
? (length.charAt(0).toUpperCase() + length.slice(1)) as "Short" | "Medium" | "Long"
638+
: "Medium"
639+
635640
setCreatingSession(true)
636641
void (async () => {
637642
try {
638643
const filesForApi = await uploadLandingStashedFiles()
639644
const run = await startBackendSession({
640645
question: messageText,
641646
webSearch: true,
642-
explanationDepth: "Medium",
647+
explanationDepth: depth,
648+
model: apiModel,
643649
topicName: messageText,
644650
files: filesForApi ?? undefined,
645651
})
@@ -658,20 +664,20 @@ export function Hero() {
658664
/* After user logs in, auto-submit any pending message */
659665
useEffect(() => {
660666
if (!loading && user && pendingSubmitRef.current) {
661-
const { text, files } = pendingSubmitRef.current
667+
const { text, files, modelId, length } = pendingSubmitRef.current
662668
pendingSubmitRef.current = null
663-
doSubmit(text, files)
669+
doSubmit(text, files, modelId, length)
664670
}
665671
}, [loading, user, doSubmit])
666672

667-
const handleHeroSubmit = useCallback((text: string, files?: AttachedFile[]) => {
673+
const handleHeroSubmit = useCallback((text: string, files?: AttachedFile[], modelId?: ModelOptionId, length?: "short" | "medium" | "long") => {
668674
if (loading) return
669675
if (!user) {
670-
pendingSubmitRef.current = { text, files }
676+
pendingSubmitRef.current = { text, files, modelId, length }
671677
openLoginModal("Sign in to start a chat session.")
672678
return
673679
}
674-
doSubmit(text, files)
680+
doSubmit(text, files, modelId, length)
675681
}, [loading, user, openLoginModal, doSubmit])
676682

677683
/* ——— Mouse parallax — direct DOM refs for performance (no React re-renders) ——— */

0 commit comments

Comments
 (0)