@@ -40,6 +40,7 @@ import { resolveToolDisplay } from "../../../lib/chat/tool-display.ts";
4040import { resolveUiHourCycleOptions } from "../../../lib/format.ts" ;
4141import { formatCompactTokenCount } from "../../../lib/format.ts" ;
4242import "../../../components/tooltip.ts" ;
43+ import { getMediaFileExtension } from "../../../lib/media-file-extension.ts" ;
4344import { openExternalUrlSafe } from "../../../lib/open-external-url.ts" ;
4445import { stripThinkingTags } from "../../../lib/strip-thinking-tags.ts" ;
4546import { detectTextDirection } from "../../../lib/text-direction.ts" ;
@@ -250,23 +251,6 @@ function buildBase64ImageUrl(params: { data: string; mediaType?: string }): stri
250251 : `data:${ params . mediaType ?? "image/png" } ;base64,${ params . data } ` ;
251252}
252253
253- function getFileExtension ( url : string ) : string | undefined {
254- const source = ( ( ) => {
255- try {
256- const trimmed = url . trim ( ) ;
257- if ( / ^ h t t p s ? : \/ \/ / i. test ( trimmed ) ) {
258- return new URL ( trimmed ) . pathname ;
259- }
260- } catch {
261- // Fall back to the raw path when URL parsing fails.
262- }
263- return url ;
264- } ) ( ) ;
265- const fileName = source . split ( / [ \\ / ] / ) . pop ( ) ?? source ;
266- const match = / \. ( [ a - z A - Z 0 - 9 ] + ) $ / . exec ( fileName ) ;
267- return match ?. [ 1 ] ?. toLowerCase ( ) ;
268- }
269-
270254function isImageTranscriptMediaPath ( path : string , mediaType : unknown ) : boolean {
271255 if ( typeof mediaType === "string" && mediaType . trim ( ) ) {
272256 const normalized = mediaType . trim ( ) . toLowerCase ( ) ;
@@ -277,7 +261,7 @@ function isImageTranscriptMediaPath(path: string, mediaType: unknown): boolean {
277261 return false ;
278262 }
279263 }
280- const ext = getFileExtension ( path ) ;
264+ const ext = getMediaFileExtension ( path ) ;
281265 return (
282266 ext !== undefined &&
283267 [ "png" , "jpg" , "jpeg" , "gif" , "webp" , "bmp" , "svg" , "heic" , "heif" , "avif" ] . includes ( ext )
@@ -288,7 +272,7 @@ function isAudioTranscriptMediaPath(path: string, mediaType: unknown): boolean {
288272 if ( typeof mediaType === "string" && mediaType . trim ( ) . toLowerCase ( ) . startsWith ( "audio/" ) ) {
289273 return true ;
290274 }
291- const ext = getFileExtension ( path ) ;
275+ const ext = getMediaFileExtension ( path ) ;
292276 return (
293277 ext !== undefined &&
294278 [ "aac" , "flac" , "m2a" , "m4a" , "mp3" , "oga" , "ogg" , "opus" , "wav" ] . includes ( ext )
@@ -299,7 +283,7 @@ function isVideoTranscriptMediaPath(path: string, mediaType: unknown): boolean {
299283 if ( typeof mediaType === "string" && mediaType . trim ( ) . toLowerCase ( ) . startsWith ( "video/" ) ) {
300284 return true ;
301285 }
302- const ext = getFileExtension ( path ) ;
286+ const ext = getMediaFileExtension ( path ) ;
303287 return ext !== undefined && [ "m4v" , "mov" , "mp4" , "webm" ] . includes ( ext ) ;
304288}
305289
0 commit comments