From 15a95bc017a5d67e6833319842fb4a7b693cd599 Mon Sep 17 00:00:00 2001 From: Amarendra Naidu <200739078+AmarTechWriter@users.noreply.github.com> Date: Mon, 10 Aug 2026 10:35:11 +0530 Subject: [PATCH] Change base URL extraction to include scheme MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The base URL passed to LlamaCloudIndex was built using .hostname, which strips the scheme (e.g. "api.cloud.llamaindex.ai" instead of "https://api.cloud.llamaindex.ai"). This produced a malformed URL when the LlamaCloud SDK later concatenated it with a request path, causing a Node ERR_INVALID_URL error on every generateResponse() call. Because this error was silently caught and swallowed, the app fell back to DefaultResponseService's hardcoded template answers instead of surfacing the failure — so response generation appeared to work, but returned generic, topic-mismatched boilerplate instead of real AI-generated, source-grounded answers. Fix: use .origin instead of .hostname to preserve the URL scheme. Also corrected the accompanying comment, which incorrectly described the expected value as a bare hostname. Reproduction: select any populated LlamaCloud index, extract questions from an RFP, and click Generate — responses returned unrelated boilerplate text (e.g. a payload-capacity question answered with content about REST APIs and OAuth) while console.error logged "Falling back to default response due to error" with code: 'ERR_INVALID_URL'. Fixes #50 --- lib/llamaindex-service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/llamaindex-service.ts b/lib/llamaindex-service.ts index 0b129a50..c359d2ac 100644 --- a/lib/llamaindex-service.ts +++ b/lib/llamaindex-service.ts @@ -43,9 +43,9 @@ export class LlamaIndexService implements ILlamaIndexService { private initializeIndexes(): void { try { - // Extract hostname from LLAMACLOUD_API_URL for LlamaCloudIndex - // The SDK expects just the hostname (e.g., 'api.cloud.eu.llamaindex.ai') - const baseUrlHostname = new URL(env.get('LLAMACLOUD_API_URL')!).hostname; + // Extract base URL (with scheme) from LLAMACLOUD_API_URL for LlamaCloudIndex + // The SDK expects the full origin (e.g., 'https://api.cloud.eu.llamaindex.ai') + const baseUrlHostname = new URL(env.get('LLAMACLOUD_API_URL')!).origin; console.log('Initializing LlamaCloud indexes with config:', this.config); if (this.config.indexNames && this.config.indexNames.length > 0) { @@ -176,4 +176,4 @@ export class LlamaIndexService implements ILlamaIndexService { getConfig(): Readonly { return { ...this.config }; } -} \ No newline at end of file +}