fix: migrate AI chat system from Firebase/Firestore to Postgres
Firebase was not configured so every chat request crashed with 'Firebase Admin credentials not configured'. - chat-mode-resolver.ts: read project phase from fs_projects (Postgres) - chat-context.ts: load project data from fs_projects instead of Firestore - /api/ai/conversation: store/retrieve conversations in chat_conversations Postgres table (created automatically on first use) - /api/ai/chat: replace all Firestore reads/writes with Postgres queries - v_ai_chat/page.tsx: replace Firebase client auth with useSession from next-auth/react; remove Firestore listeners, use REST API for project data Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* building a compact context object for LLM consumption.
|
||||
*/
|
||||
|
||||
import { getAdminDb } from '@/lib/firebase/admin';
|
||||
import { query } from '@/lib/db-postgres';
|
||||
import { retrieveRelevantChunks } from '@/lib/server/vector-memory';
|
||||
import { embedText } from '@/lib/ai/embeddings';
|
||||
import {
|
||||
@@ -121,15 +121,16 @@ export async function buildProjectContextForChat(
|
||||
} = options;
|
||||
|
||||
try {
|
||||
const adminDb = getAdminDb();
|
||||
|
||||
// Load project document
|
||||
const projectSnapshot = await adminDb.collection('projects').doc(projectId).get();
|
||||
if (!projectSnapshot.exists) {
|
||||
// Load project from Postgres
|
||||
const projectRows = await query<{ data: any }>(
|
||||
`SELECT data FROM fs_projects WHERE id = $1 LIMIT 1`,
|
||||
[projectId]
|
||||
);
|
||||
if (projectRows.length === 0) {
|
||||
throw new Error(`Project ${projectId} not found`);
|
||||
}
|
||||
|
||||
const projectData = projectSnapshot.data() ?? {};
|
||||
const projectData = projectRows[0].data ?? {};
|
||||
|
||||
// Load summaries in parallel
|
||||
const [knowledgeSummary, extractionSummary] = await Promise.all([
|
||||
|
||||
Reference in New Issue
Block a user