diff --git a/.changeset/afraid-seals-rescue.md b/.changeset/afraid-seals-rescue.md new file mode 100644 index 0000000..39e9f1c --- /dev/null +++ b/.changeset/afraid-seals-rescue.md @@ -0,0 +1,5 @@ +--- +'@llamaindex/chat-ui': patch +--- + +fix: support releative URLs in document viewer diff --git a/packages/chat-ui/src/widgets/document-info.tsx b/packages/chat-ui/src/widgets/document-info.tsx index 2015793..f236afa 100644 --- a/packages/chat-ui/src/widgets/document-info.tsx +++ b/packages/chat-ui/src/widgets/document-info.tsx @@ -31,7 +31,8 @@ export function DocumentInfo({ onRemove?: () => void }) { const { url, sources } = document - const fileName = urlToFileName(url) + const urlParts = url.split('/') + const fileName = urlParts.length > 0 ? urlParts[urlParts.length - 1] : url const fileExt = fileName?.split('.').pop() as DocumentFileType | undefined const previewFile = { @@ -191,10 +192,3 @@ function DocumentPreviewCard(props: { function inKB(size: number) { return Math.round((size / 1024) * 10) / 10 } - -function urlToFileName(url: string) { - const urlObj = new URL(url) - const urlParts = urlObj.pathname.split('/') - const fileName = urlParts.length > 0 ? urlParts[urlParts.length - 1] : url - return fileName -}