fix: lint and format remaining files

This commit is contained in:
J Chris Anderson 2025-03-25 11:47:14 -07:00
parent 94737c5ade
commit f5f67885fc
No known key found for this signature in database
3 changed files with 18 additions and 21 deletions

View File

@ -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"

View File

@ -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<Library>();
// 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
}
}
}

View File

@ -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('<library name="Fireproof">'));
console.log(
'[DEBUG] api.chat - Enhanced content includes Fireproof?',
enhancedContent.includes('Fireproof'),
enhancedContent.includes('<library name="Fireproof">'),
);
// replace the content with enhanced content
messages[lastUserMessageIndex] = {
...lastUserMessage,
content: enhancedContent,
};
console.log('[DEBUG] api.chat - Message after enhancement:', JSON.stringify(messages[lastUserMessageIndex]));
}
}