Trae Assistant
接入硅基流,直接跟知识库对话
05ed527
raw
history blame contribute delete
897 Bytes
import { NextResponse } from 'next/server';
import db from '@/lib/db';
export async function GET() {
try {
const kbs = db.prepare(`
SELECT
kb.namespace,
kb.name,
kb.description,
COUNT(d.id) as doc_count
FROM knowledge_bases kb
LEFT JOIN documents d ON kb.namespace = d.namespace
GROUP BY kb.namespace
ORDER BY kb.name ASC
`).all() as { namespace: string, name: string, description: string, doc_count: number }[];
// Ensure 'NOTES' is always present if it has docs, even if not in knowledge_bases table (legacy support)
// Actually, yuque-service inserts into knowledge_bases table now.
return NextResponse.json({ kbs });
} catch (error) {
console.error("Failed to fetch knowledge bases:", error);
return NextResponse.json({ error: "Failed to fetch knowledge bases" }, { status: 500 });
}
}