(_event: React.UIEvent, messageInput?: string)
| 147 | }; |
| 148 | |
| 149 | const sendMessage = async (_event: React.UIEvent, messageInput?: string) => { |
| 150 | const _input = messageInput || input; |
| 151 | |
| 152 | if (_input.length === 0 || isLoading) { |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * @note (delm) Usually saving files shouldn't take long but it may take longer if there |
| 158 | * many unsaved files. In that case we need to block user input and show an indicator |
| 159 | * of some kind so the user is aware that something is happening. But I consider the |
| 160 | * happy case to be no unsaved files and I would expect users to save their changes |
| 161 | * before they send another message. |
| 162 | */ |
| 163 | await workbenchStore.saveAllFiles(); |
| 164 | |
| 165 | const fileModifications = workbenchStore.getFileModifcations(); |
| 166 | |
| 167 | chatStore.setKey('aborted', false); |
| 168 | |
| 169 | runAnimation(); |
| 170 | |
| 171 | if (fileModifications !== undefined) { |
| 172 | const diff = fileModificationsToHTML(fileModifications); |
| 173 | |
| 174 | /** |
| 175 | * If we have file modifications we append a new user message manually since we have to prefix |
| 176 | * the user input with the file modifications and we don't want the new user input to appear |
| 177 | * in the prompt. Using `append` is almost the same as `handleSubmit` except that we have to |
| 178 | * manually reset the input and we'd have to manually pass in file attachments. However, those |
| 179 | * aren't relevant here. |
| 180 | */ |
| 181 | append({ role: 'user', content: `${diff}\n\n${_input}` }); |
| 182 | |
| 183 | /** |
| 184 | * After sending a new message we reset all modifications since the model |
| 185 | * should now be aware of all the changes. |
| 186 | */ |
| 187 | workbenchStore.resetAllFileModifications(); |
| 188 | } else { |
| 189 | append({ role: 'user', content: _input }); |
| 190 | } |
| 191 | |
| 192 | setInput(''); |
| 193 | |
| 194 | resetEnhancer(); |
| 195 | |
| 196 | textareaRef.current?.blur(); |
| 197 | }; |
| 198 | |
| 199 | const [messageRef, scrollRef] = useSnapScroll(); |
| 200 |
no test coverage detected