From ad3a5f3640b977f3955dd4bd6341578ede1154ee Mon Sep 17 00:00:00 2001 From: Waleed Latif Date: Mon, 3 Aug 2026 12:07:34 -0700 Subject: [PATCH] refactor(chat): drop code the voice removal left unreachable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Full-file cleanup pass over the files voice mode was removed from. - /api/speech/token: with the chatId branch gone, billingAttribution is always resolved, so four `billingAttribution ? ... : ...` guards and the checkActorUsageLimits fallback were unreachable. Removed, along with the now-unused imports and test mock. - chat.tsx: the inputValue state had one remaining writer (`''`) and no reader — ChatInput has owned its own input value since it went uncontrolled, and removing the voice-transcript caller left handleSendMessage always receiving an explicit message. - use-chat-streaming: messageIdMap was written in three frame handlers and never read, and setIsStreamingResponse was returned but never destructured by the only consumer. - Comments: dropped JSX section labels that restate the element beneath them and TSDoc that restates the identifier; narrowed the speech contract's workspaceId doc, which existed to contrast with the removed chatId field. --- .../(interfaces)/chat/[identifier]/chat.tsx | 11 +--------- .../chat/components/input/input.tsx | 7 ------- .../chat/hooks/use-chat-streaming.ts | 12 ----------- apps/sim/app/api/speech/token/route.test.ts | 7 ------- apps/sim/app/api/speech/token/route.ts | 20 ++++--------------- apps/sim/lib/api/contracts/media/speech.ts | 2 +- apps/sim/lib/core/config/env.ts | 2 +- apps/sim/lib/speech/config.ts | 6 +----- 8 files changed, 8 insertions(+), 59 deletions(-) diff --git a/apps/sim/app/(interfaces)/chat/[identifier]/chat.tsx b/apps/sim/app/(interfaces)/chat/[identifier]/chat.tsx index 2d896898f9d..0685f106822 100644 --- a/apps/sim/app/(interfaces)/chat/[identifier]/chat.tsx +++ b/apps/sim/app/(interfaces)/chat/[identifier]/chat.tsx @@ -39,9 +39,6 @@ interface ChatRequestPayload { files?: ChatRequestFile[] } -/** - * Converts a File object to a base64 data URL - */ function fileToBase64(file: File): Promise { return new Promise((resolve, reject) => { const reader = new FileReader() @@ -53,7 +50,6 @@ function fileToBase64(file: File): Promise { export default function ChatClient({ identifier }: { identifier: string }) { const [messages, setMessages] = useState([]) - const [inputValue, setInputValue] = useState('') const [isLoading, setIsLoading] = useState(false) const messagesEndRef = useRef(null) const messagesContainerRef = useRef(null) @@ -164,7 +160,7 @@ export default function ChatClient({ identifier }: { identifier: string }) { }, [chatConfig, authRequired]) const handleSendMessage = async ( - messageParam?: string, + messageToSend: string, files?: Array<{ id: string name: string @@ -174,7 +170,6 @@ export default function ChatClient({ identifier }: { identifier: string }) { dataUrl?: string }> ) => { - const messageToSend = messageParam ?? inputValue if ((!messageToSend.trim() && (!files || files.length === 0)) || isLoading) return logger.info('Sending message:', { @@ -201,7 +196,6 @@ export default function ChatClient({ identifier }: { identifier: string }) { } setMessages((prev) => [...prev, userMessage]) - setInputValue('') setIsLoading(true) setTimeout(() => { @@ -322,10 +316,8 @@ export default function ChatClient({ identifier }: { identifier: string }) { return (
- {/* Header component */} - {/* Message Container component */} - {/* Input area (free-standing at the bottom) */}
- {/* Error Messages */} {uploadErrors.length > 0 && (
{uploadErrors.map((error, idx) => ( @@ -145,7 +144,6 @@ export const ChatInput: React.FC<{
)} - {/* Input container */}
- {/* File thumbnails */} {attachedFiles.length > 0 && (
{attachedFiles.map((file) => ( @@ -221,7 +218,6 @@ export const ChatInput: React.FC<{
)} - {/* Textarea */}