|
3 | 3 | import { processFilesToChatUploaded } from '$lib/utils/process-uploaded-files'; |
4 | 4 | import { serverStore } from '$lib/stores/server.svelte'; |
5 | 5 | import { isFileTypeSupported } from '$lib/constants/supported-file-types'; |
6 | | - import { filterFilesByModalities, generateModalityErrorMessage } from '$lib/utils/modality-file-validation'; |
| 6 | + import { |
| 7 | + filterFilesByModalities, |
| 8 | + generateModalityErrorMessage |
| 9 | + } from '$lib/utils/modality-file-validation'; |
7 | 10 | import { supportsVision, supportsAudio } from '$lib/stores/server.svelte'; |
8 | 11 | import { ChatForm, ChatScreenHeader, ChatMessages, ServerInfo } from '$lib/components/app'; |
9 | 12 | import { |
|
28 | 31 | let uploadedFiles = $state<ChatUploadedFile[]>([]); |
29 | 32 | let isDragOver = $state(false); |
30 | 33 | let dragCounter = $state(0); |
31 | | - |
| 34 | +
|
32 | 35 | // Alert Dialog state for file upload errors |
33 | 36 | let showFileErrorDialog = $state(false); |
34 | 37 | let fileErrorData = $state<{ |
|
106 | 109 |
|
107 | 110 | // Check context limit using real-time slots data |
108 | 111 | const contextCheck = await contextService.checkContextLimit(); |
109 | | - |
| 112 | +
|
110 | 113 | if (contextCheck && contextCheck.wouldExceed) { |
111 | 114 | const errorMessage = contextService.getContextErrorMessage(contextCheck); |
112 | 115 |
|
113 | 116 | setMaxContextError({ |
114 | 117 | message: errorMessage, |
115 | 118 | estimatedTokens: contextCheck.currentUsage, |
116 | | - maxAllowed: contextCheck.availableTokens, |
117 | 119 | maxContext: contextCheck.maxContext |
118 | 120 | }); |
119 | 121 |
|
|
122 | 124 |
|
123 | 125 | await sendMessage(message, extras); |
124 | 126 | scrollChatToBottom(); |
125 | | - |
| 127 | +
|
126 | 128 | return true; |
127 | 129 | } |
128 | 130 |
|
|
140 | 142 | } |
141 | 143 |
|
142 | 144 | // Then filter by model modalities |
143 | | - const { supportedFiles, unsupportedFiles, modalityReasons } = filterFilesByModalities(generallySupported); |
| 145 | + const { supportedFiles, unsupportedFiles, modalityReasons } = |
| 146 | + filterFilesByModalities(generallySupported); |
144 | 147 |
|
145 | 148 | // Combine all unsupported files |
146 | 149 | const allUnsupportedFiles = [...generallyUnsupported, ...unsupportedFiles]; |
|
150 | 153 | const supportedTypes: string[] = ['text files', 'PDFs']; |
151 | 154 | if (supportsVision()) supportedTypes.push('images'); |
152 | 155 | if (supportsAudio()) supportedTypes.push('audio files'); |
153 | | - |
| 156 | +
|
154 | 157 | // Structure error data for better presentation |
155 | 158 | fileErrorData = { |
156 | 159 | generallyUnsupported, |
|
184 | 187 | if (navigating) { |
185 | 188 | scrollChatToBottom('instant'); |
186 | 189 | } |
187 | | - }) |
| 190 | + }); |
188 | 191 |
|
189 | 192 | $effect(() => { |
190 | 193 | if (isLoading() && autoScrollEnabled) { |
|
273 | 276 | <AlertDialog.Content class="max-w-md"> |
274 | 277 | <AlertDialog.Header> |
275 | 278 | <AlertDialog.Title>File Upload Error</AlertDialog.Title> |
276 | | - <AlertDialog.Description class="text-sm text-muted-foreground"> |
| 279 | + <AlertDialog.Description class="text-muted-foreground text-sm"> |
277 | 280 | Some files cannot be uploaded with the current model. |
278 | 281 | </AlertDialog.Description> |
279 | 282 | </AlertDialog.Header> |
280 | | - |
| 283 | + |
281 | 284 | <div class="space-y-4"> |
282 | 285 | <!-- Generally unsupported files --> |
283 | 286 | {#if fileErrorData.generallyUnsupported.length > 0} |
284 | 287 | <div class="space-y-2"> |
285 | | - <h4 class="text-sm font-medium text-destructive">Unsupported File Types</h4> |
| 288 | + <h4 class="text-destructive text-sm font-medium">Unsupported File Types</h4> |
286 | 289 | <div class="space-y-1"> |
287 | 290 | {#each fileErrorData.generallyUnsupported as file} |
288 | | - <div class="rounded-md bg-destructive/10 px-3 py-2"> |
289 | | - <p class="text-sm font-mono text-destructive break-all">{file.name}</p> |
290 | | - <p class="text-xs text-muted-foreground mt-1">File type not supported</p> |
| 291 | + <div class="bg-destructive/10 rounded-md px-3 py-2"> |
| 292 | + <p class="text-destructive break-all font-mono text-sm"> |
| 293 | + {file.name} |
| 294 | + </p> |
| 295 | + <p class="text-muted-foreground mt-1 text-xs"> |
| 296 | + File type not supported |
| 297 | + </p> |
291 | 298 | </div> |
292 | 299 | {/each} |
293 | 300 | </div> |
294 | 301 | </div> |
295 | 302 | {/if} |
296 | | - |
| 303 | + |
297 | 304 | <!-- Modality-restricted files --> |
298 | 305 | {#if fileErrorData.modalityUnsupported.length > 0} |
299 | 306 | <div class="space-y-2"> |
300 | | - <h4 class="text-sm font-medium text-destructive">Model Compatibility Issues</h4> |
| 307 | + <h4 class="text-destructive text-sm font-medium"> |
| 308 | + Model Compatibility Issues |
| 309 | + </h4> |
301 | 310 | <div class="space-y-1"> |
302 | 311 | {#each fileErrorData.modalityUnsupported as file} |
303 | | - <div class="rounded-md bg-destructive/10 px-3 py-2"> |
304 | | - <p class="text-sm font-mono text-destructive break-all">{file.name}</p> |
305 | | - <p class="text-xs text-muted-foreground mt-1"> |
306 | | - {fileErrorData.modalityReasons[file.name] || 'Not supported by current model'} |
| 312 | + <div class="bg-destructive/10 rounded-md px-3 py-2"> |
| 313 | + <p class="text-destructive break-all font-mono text-sm"> |
| 314 | + {file.name} |
| 315 | + </p> |
| 316 | + <p class="text-muted-foreground mt-1 text-xs"> |
| 317 | + {fileErrorData.modalityReasons[file.name] || |
| 318 | + 'Not supported by current model'} |
307 | 319 | </p> |
308 | 320 | </div> |
309 | 321 | {/each} |
310 | 322 | </div> |
311 | 323 | </div> |
312 | 324 | {/if} |
313 | | - |
| 325 | + |
314 | 326 | <!-- Supported file types --> |
315 | | - <div class="rounded-md bg-muted/50 p-3"> |
316 | | - <h4 class="text-sm font-medium mb-2">This model supports:</h4> |
317 | | - <p class="text-sm text-muted-foreground"> |
| 327 | + <div class="bg-muted/50 rounded-md p-3"> |
| 328 | + <h4 class="mb-2 text-sm font-medium">This model supports:</h4> |
| 329 | + <p class="text-muted-foreground text-sm"> |
318 | 330 | {fileErrorData.supportedTypes.join(', ')} |
319 | 331 | </p> |
320 | 332 | </div> |
321 | 333 | </div> |
322 | | - |
| 334 | + |
323 | 335 | <AlertDialog.Footer> |
324 | | - <AlertDialog.Action onclick={() => showFileErrorDialog = false}> |
| 336 | + <AlertDialog.Action onclick={() => (showFileErrorDialog = false)}> |
325 | 337 | Got it |
326 | 338 | </AlertDialog.Action> |
327 | 339 | </AlertDialog.Footer> |
|
0 commit comments