From 8f670a935caa94e4bc36af9d2e70fc1f49e80491 Mon Sep 17 00:00:00 2001
From: Marcus Schiesser <mail@marcusschiesser.de>
Date: Tue, 27 Aug 2024 14:14:17 +0700
Subject: [PATCH] fix: allow relative URL in docs (#259)

---
 .changeset/tidy-months-dance.md                        |  5 +++++
 .../streaming/nextjs/app/components/ui/chat/index.ts   |  3 +--
 .../streaming/nextjs/app/components/ui/lib/utils.ts    | 10 ----------
 3 files changed, 6 insertions(+), 12 deletions(-)
 create mode 100644 .changeset/tidy-months-dance.md

diff --git a/.changeset/tidy-months-dance.md b/.changeset/tidy-months-dance.md
new file mode 100644
index 00000000..a459ff8e
--- /dev/null
+++ b/.changeset/tidy-months-dance.md
@@ -0,0 +1,5 @@
+---
+"create-llama": patch
+---
+
+Allow relative URL in documents
diff --git a/templates/types/streaming/nextjs/app/components/ui/chat/index.ts b/templates/types/streaming/nextjs/app/components/ui/chat/index.ts
index 669f404a..cacd5503 100644
--- a/templates/types/streaming/nextjs/app/components/ui/chat/index.ts
+++ b/templates/types/streaming/nextjs/app/components/ui/chat/index.ts
@@ -1,5 +1,4 @@
 import { JSONValue } from "ai";
-import { isValidUrl } from "../lib/utils";
 import ChatInput from "./chat-input";
 import ChatMessages from "./chat-messages";
 
@@ -113,7 +112,7 @@ function preprocessSourceNodes(nodes: SourceNode[]): SourceNode[] {
   // Filter source nodes has lower score
   nodes = nodes
     .filter((node) => (node.score ?? 1) > NODE_SCORE_THRESHOLD)
-    .filter((node) => isValidUrl(node.url))
+    .filter((node) => node.url && node.url.trim() !== "")
     .sort((a, b) => (b.score ?? 1) - (a.score ?? 1))
     .map((node) => {
       // remove trailing slash for node url if exists
diff --git a/templates/types/streaming/nextjs/app/components/ui/lib/utils.ts b/templates/types/streaming/nextjs/app/components/ui/lib/utils.ts
index 59c84c0c..a5ef1935 100644
--- a/templates/types/streaming/nextjs/app/components/ui/lib/utils.ts
+++ b/templates/types/streaming/nextjs/app/components/ui/lib/utils.ts
@@ -4,13 +4,3 @@ import { twMerge } from "tailwind-merge";
 export function cn(...inputs: ClassValue[]) {
   return twMerge(clsx(inputs));
 }
-
-export function isValidUrl(url?: string): boolean {
-  if (!url) return false;
-  try {
-    new URL(url);
-    return true;
-  } catch (_) {
-    return false;
-  }
-}
\ No newline at end of file
-- 
GitLab