mirror of
https://github.com/stackblitz/bolt.new
synced 2025-06-26 18:17:50 +00:00
fix: lint and format remaining files
This commit is contained in:
parent
94737c5ade
commit
f5f67885fc
@ -2,22 +2,14 @@
|
|||||||
"libraries": [
|
"libraries": [
|
||||||
{
|
{
|
||||||
"name": "Fireproof",
|
"name": "Fireproof",
|
||||||
"keywords": [
|
"keywords": ["fireproof", "fireproof db", "use-fireproof"],
|
||||||
"fireproof",
|
|
||||||
"fireproof db",
|
|
||||||
"use-fireproof"
|
|
||||||
],
|
|
||||||
"docSource": "https://use-fireproof.com/llms.txt",
|
"docSource": "https://use-fireproof.com/llms.txt",
|
||||||
"docFile": "docs/fireproof.txt",
|
"docFile": "docs/fireproof.txt",
|
||||||
"lastUpdated": "2025-03-25"
|
"lastUpdated": "2025-03-25"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "CallAI",
|
"name": "CallAI",
|
||||||
"keywords": [
|
"keywords": ["callai", "call-ai", "AI helper"],
|
||||||
"callai",
|
|
||||||
"call-ai",
|
|
||||||
"AI helper"
|
|
||||||
],
|
|
||||||
"docSource": "https://use-fireproof.com/callai-llms.txt",
|
"docSource": "https://use-fireproof.com/callai-llms.txt",
|
||||||
"docFile": "docs/callai.txt",
|
"docFile": "docs/callai.txt",
|
||||||
"lastUpdated": "2025-03-25"
|
"lastUpdated": "2025-03-25"
|
||||||
|
@ -22,6 +22,7 @@ const DOCS_DIR = path.join(process.cwd(), 'app', 'lib', 'common', 'llms-txt');
|
|||||||
function loadDocsConfig(): DocsConfig {
|
function loadDocsConfig(): DocsConfig {
|
||||||
const configPath = path.join(DOCS_DIR, 'docs.json');
|
const configPath = path.join(DOCS_DIR, 'docs.json');
|
||||||
const configData = fs.readFileSync(configPath, 'utf8');
|
const configData = fs.readFileSync(configPath, 'utf8');
|
||||||
|
|
||||||
return JSON.parse(configData) as DocsConfig;
|
return JSON.parse(configData) as DocsConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ function loadDocsConfig(): DocsConfig {
|
|||||||
function getLibraryDocs(library: Library): string | null {
|
function getLibraryDocs(library: Library): string | null {
|
||||||
try {
|
try {
|
||||||
const docPath = path.join(DOCS_DIR, library.docFile);
|
const docPath = path.join(DOCS_DIR, library.docFile);
|
||||||
|
|
||||||
if (fs.existsSync(docPath)) {
|
if (fs.existsSync(docPath)) {
|
||||||
return fs.readFileSync(docPath, 'utf8');
|
return fs.readFileSync(docPath, 'utf8');
|
||||||
}
|
}
|
||||||
@ -48,7 +50,7 @@ function isLibraryMentioned(prompt: string, library: Library): boolean {
|
|||||||
export function detectLibrariesFromChatHistory(messages: Messages): Library[] {
|
export function detectLibrariesFromChatHistory(messages: Messages): Library[] {
|
||||||
const config = loadDocsConfig();
|
const config = loadDocsConfig();
|
||||||
const detectedLibraries = new Set<Library>();
|
const detectedLibraries = new Set<Library>();
|
||||||
|
|
||||||
// check each message for library mentions
|
// check each message for library mentions
|
||||||
for (const message of messages) {
|
for (const message of messages) {
|
||||||
for (const library of config.libraries) {
|
for (const library of config.libraries) {
|
||||||
@ -57,7 +59,7 @@ export function detectLibrariesFromChatHistory(messages: Messages): Library[] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(detectedLibraries);
|
return Array.from(detectedLibraries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,19 +67,20 @@ export function detectLibrariesFromChatHistory(messages: Messages): Library[] {
|
|||||||
export function enhancePromptWithLibraryDocumentation(prompt: string, libraries: Library[]): string {
|
export function enhancePromptWithLibraryDocumentation(prompt: string, libraries: Library[]): string {
|
||||||
try {
|
try {
|
||||||
let enhancedPrompt = prompt;
|
let enhancedPrompt = prompt;
|
||||||
|
|
||||||
// add documentation for each detected library
|
// add documentation for each detected library
|
||||||
for (const library of libraries) {
|
for (const library of libraries) {
|
||||||
const docs = getLibraryDocs(library);
|
const docs = getLibraryDocs(library);
|
||||||
|
|
||||||
if (docs) {
|
if (docs) {
|
||||||
// add the documentation in a standardized format
|
// add the documentation in a standardized format
|
||||||
enhancedPrompt += `\n\n## ${library.name} Documentation\n${docs}\n`;
|
enhancedPrompt += `\n\n## ${library.name} Documentation\n${docs}\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return enhancedPrompt;
|
return enhancedPrompt;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error enhancing prompt with docs:', error);
|
console.error('Error enhancing prompt with docs:', error);
|
||||||
return prompt; // return the original prompt if there's an error
|
return prompt; // return the original prompt if there's an error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ export async function action(args: ActionFunctionArgs) {
|
|||||||
|
|
||||||
async function chatAction({ context, request }: ActionFunctionArgs) {
|
async function chatAction({ context, request }: ActionFunctionArgs) {
|
||||||
const { messages } = await request.json<{ messages: Messages }>();
|
const { messages } = await request.json<{ messages: Messages }>();
|
||||||
|
|
||||||
console.log('[DEBUG] api.chat - Original messages:', JSON.stringify(messages));
|
console.log('[DEBUG] api.chat - Original messages:', JSON.stringify(messages));
|
||||||
|
|
||||||
// detect libraries mentioned in the chat history
|
// 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
|
// enhance the user's last message with library documentation
|
||||||
const lastUserMessage = messages[lastUserMessageIndex];
|
const lastUserMessage = messages[lastUserMessageIndex];
|
||||||
console.log('[DEBUG] api.chat - Last user message before enhancement:', lastUserMessage.content);
|
console.log('[DEBUG] api.chat - Last user message before enhancement:', lastUserMessage.content);
|
||||||
|
|
||||||
const enhancedContent = enhancePromptWithLibraryDocumentation(lastUserMessage.content, detectedLibraries);
|
const enhancedContent = enhancePromptWithLibraryDocumentation(lastUserMessage.content, detectedLibraries);
|
||||||
console.log('[DEBUG] api.chat - Enhanced content includes Fireproof?',
|
console.log(
|
||||||
enhancedContent.includes('Fireproof'),
|
'[DEBUG] api.chat - Enhanced content includes Fireproof?',
|
||||||
enhancedContent.includes('<library name="Fireproof">'));
|
enhancedContent.includes('Fireproof'),
|
||||||
|
enhancedContent.includes('<library name="Fireproof">'),
|
||||||
|
);
|
||||||
|
|
||||||
// replace the content with enhanced content
|
// replace the content with enhanced content
|
||||||
messages[lastUserMessageIndex] = {
|
messages[lastUserMessageIndex] = {
|
||||||
...lastUserMessage,
|
...lastUserMessage,
|
||||||
content: enhancedContent,
|
content: enhancedContent,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[DEBUG] api.chat - Message after enhancement:', JSON.stringify(messages[lastUserMessageIndex]));
|
console.log('[DEBUG] api.chat - Message after enhancement:', JSON.stringify(messages[lastUserMessageIndex]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user