MCPcopy Create free account
hub / github.com/ResearAI/AutoFigure / onFormSubmit

Function onFormSubmit

frontend/components/chat-panel.tsx:634–729  ·  view source on GitHub ↗
(e: React.FormEvent<HTMLFormElement>)

Source from the content-addressed store, hash-verified

632 }, [sessionId])
633
634 const onFormSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
635 e.preventDefault()
636 const isProcessing = status === "streaming" || status === "submitted"
637 if (input.trim() && !isProcessing) {
638 // Check if input matches a cached example (only when no messages yet)
639 if (messages.length === 0) {
640 const cached = findCachedResponse(
641 input.trim(),
642 files.length > 0,
643 )
644 if (cached) {
645 // Add user message and fake assistant response to messages
646 // The chat-message-display useEffect will handle displaying the diagram
647 const toolCallId = `cached-${Date.now()}`
648
649 // Build user message text including any file content
650 const userText = await processFilesAndAppendContent(
651 input,
652 files,
653 pdfData,
654 )
655
656 setMessages([
657 {
658 id: `user-${Date.now()}`,
659 role: "user" as const,
660 parts: [{ type: "text" as const, text: userText }],
661 },
662 {
663 id: `assistant-${Date.now()}`,
664 role: "assistant" as const,
665 parts: [
666 {
667 type: "tool-display_diagram" as const,
668 toolCallId,
669 state: "output-available" as const,
670 input: { xml: cached.xml },
671 output: "Successfully displayed the diagram.",
672 },
673 ],
674 },
675 ] as any)
676 setInput("")
677 setFiles([])
678 return
679 }
680 }
681
682 try {
683 let chartXml = await onFetchChart()
684 chartXml = formatXML(chartXml)
685
686 // Update ref directly to avoid race condition with React's async state update
687 // This ensures edit_diagram has the correct XML before AI responds
688 chartXMLRef.current = chartXml
689
690 // Build user text by concatenating input with pre-extracted text
691 // (Backend only reads first text part, so we must combine them)

Callers

nothing calls this directly

Calls 6

findCachedResponseFunction · 0.90
formatXMLFunction · 0.90
onFetchChartFunction · 0.85
checkAllQuotaLimitsFunction · 0.85
sendChatMessageFunction · 0.85

Tested by

no test coverage detected