From f5f67885fc9c0dc93106ae8fef37d14500055156 Mon Sep 17 00:00:00 2001 From: J Chris Anderson Date: Tue, 25 Mar 2025 11:47:14 -0700 Subject: [PATCH] fix: lint and format remaining files --- app/lib/common/llms-txt/docs.json | 12 ++---------- app/lib/common/llms-txt/index.ts | 13 ++++++++----- app/routes/api.chat.ts | 14 ++++++++------ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/lib/common/llms-txt/docs.json b/app/lib/common/llms-txt/docs.json index a1d3f0e..dd39ed0 100644 --- a/app/lib/common/llms-txt/docs.json +++ b/app/lib/common/llms-txt/docs.json @@ -2,22 +2,14 @@ "libraries": [ { "name": "Fireproof", - "keywords": [ - "fireproof", - "fireproof db", - "use-fireproof" - ], + "keywords": ["fireproof", "fireproof db", "use-fireproof"], "docSource": "https://use-fireproof.com/llms.txt", "docFile": "docs/fireproof.txt", "lastUpdated": "2025-03-25" }, { "name": "CallAI", - "keywords": [ - "callai", - "call-ai", - "AI helper" - ], + "keywords": ["callai", "call-ai", "AI helper"], "docSource": "https://use-fireproof.com/callai-llms.txt", "docFile": "docs/callai.txt", "lastUpdated": "2025-03-25" diff --git a/app/lib/common/llms-txt/index.ts b/app/lib/common/llms-txt/index.ts index aa81689..82f6bd3 100644 --- a/app/lib/common/llms-txt/index.ts +++ b/app/lib/common/llms-txt/index.ts @@ -22,6 +22,7 @@ const DOCS_DIR = path.join(process.cwd(), 'app', 'lib', 'common', 'llms-txt'); function loadDocsConfig(): DocsConfig { const configPath = path.join(DOCS_DIR, 'docs.json'); const configData = fs.readFileSync(configPath, 'utf8'); + return JSON.parse(configData) as DocsConfig; } @@ -29,6 +30,7 @@ function loadDocsConfig(): DocsConfig { function getLibraryDocs(library: Library): string | null { try { const docPath = path.join(DOCS_DIR, library.docFile); + if (fs.existsSync(docPath)) { return fs.readFileSync(docPath, 'utf8'); } @@ -48,7 +50,7 @@ function isLibraryMentioned(prompt: string, library: Library): boolean { export function detectLibrariesFromChatHistory(messages: Messages): Library[] { const config = loadDocsConfig(); const detectedLibraries = new Set(); - + // check each message for library mentions for (const message of messages) { for (const library of config.libraries) { @@ -57,7 +59,7 @@ export function detectLibrariesFromChatHistory(messages: Messages): Library[] { } } } - + return Array.from(detectedLibraries); } @@ -65,19 +67,20 @@ export function detectLibrariesFromChatHistory(messages: Messages): Library[] { export function enhancePromptWithLibraryDocumentation(prompt: string, libraries: Library[]): string { try { let enhancedPrompt = prompt; - + // add documentation for each detected library for (const library of libraries) { const docs = getLibraryDocs(library); + if (docs) { // add the documentation in a standardized format enhancedPrompt += `\n\n## ${library.name} Documentation\n${docs}\n`; } } - + return enhancedPrompt; } catch (error) { console.error('Error enhancing prompt with docs:', error); return prompt; // return the original prompt if there's an error } -} \ No newline at end of file +} diff --git a/app/routes/api.chat.ts b/app/routes/api.chat.ts index 75f0f2e..e61e338 100644 --- a/app/routes/api.chat.ts +++ b/app/routes/api.chat.ts @@ -11,7 +11,7 @@ export async function action(args: ActionFunctionArgs) { async function chatAction({ context, request }: ActionFunctionArgs) { const { messages } = await request.json<{ messages: Messages }>(); - + console.log('[DEBUG] api.chat - Original messages:', JSON.stringify(messages)); // detect libraries mentioned in the chat history @@ -27,18 +27,20 @@ async function chatAction({ context, request }: ActionFunctionArgs) { // enhance the user's last message with library documentation const lastUserMessage = messages[lastUserMessageIndex]; console.log('[DEBUG] api.chat - Last user message before enhancement:', lastUserMessage.content); - + const enhancedContent = enhancePromptWithLibraryDocumentation(lastUserMessage.content, detectedLibraries); - console.log('[DEBUG] api.chat - Enhanced content includes Fireproof?', - enhancedContent.includes('Fireproof'), - enhancedContent.includes('')); + console.log( + '[DEBUG] api.chat - Enhanced content includes Fireproof?', + enhancedContent.includes('Fireproof'), + enhancedContent.includes(''), + ); // replace the content with enhanced content messages[lastUserMessageIndex] = { ...lastUserMessage, content: enhancedContent, }; - + console.log('[DEBUG] api.chat - Message after enhancement:', JSON.stringify(messages[lastUserMessageIndex])); } }