Add automatic note clustering using density-based algorithm (DBSCAN variant) and bridge notes detection for connecting different thematic clusters. Features: - NoteCluster, ClusterMember, BridgeNote, BridgeSuggestion models - Clustering service with pgvector cosine similarity - Bridge notes detection (notes connecting >=2 clusters) - AI-powered suggestions for missing cluster connections - /insights page with React Flow visualization - Cron endpoint for automatic recalculation Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { auth } from '@/auth'
|
|
import { bridgeNotesService } from '@/lib/ai/services/bridge-notes.service'
|
|
|
|
/**
|
|
* GET /api/bridge-notes/suggestions
|
|
* Get AI-powered bridge note suggestions for unconnected clusters.
|
|
*/
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const session = await auth()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const userId = session.user.id
|
|
const { searchParams } = new URL(request.url)
|
|
const includeDismissed = searchParams.get('dismissed') === 'true'
|
|
|
|
const suggestions = await bridgeNotesService.getBridgeSuggestions(userId, includeDismissed)
|
|
|
|
return NextResponse.json({
|
|
suggestions,
|
|
count: suggestions.length
|
|
})
|
|
} catch (error) {
|
|
console.error('Error fetching bridge suggestions:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch suggestions' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* POST /api/bridge-notes/suggestions/generate
|
|
* Generate new bridge suggestions (force regeneration).
|
|
*/
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const session = await auth()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const userId = session.user.id
|
|
|
|
// Generate new suggestions
|
|
const suggestions = await bridgeNotesService.generateBridgeSuggestions(userId)
|
|
|
|
// Save to database
|
|
await bridgeNotesService.saveBridgeSuggestions(userId, suggestions)
|
|
|
|
return NextResponse.json({
|
|
suggestions,
|
|
count: suggestions.length,
|
|
message: `Generated ${suggestions.length} bridge suggestions`
|
|
})
|
|
} catch (error) {
|
|
console.error('Error generating bridge suggestions:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to generate suggestions' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|