All files / web/src/app/api/debug/seed-students/embeddings route.ts

0% Statements 0/47
0% Branches 0/1
0% Functions 0/1
0% Lines 0/47

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                               
import { NextResponse } from 'next/server'
import { getEmbeddingStatus, regenerateEmbeddings } from '@/lib/seed/embedding-search'
import { withAuth } from '@/lib/auth/withAuth'

/**
 * GET /api/debug/seed-students/embeddings
 *
 * Returns the current embedding cache status including whether
 * cached embeddings are stale (profile content changed since generation).
 */
export const GET = withAuth(
  async () => {
    try {
      const status = getEmbeddingStatus()
      return NextResponse.json(status)
    } catch (error) {
      console.error('[seed-students/embeddings] Status check failed:', error)
      return NextResponse.json(
        { error: error instanceof Error ? error.message : 'Status check failed' },
        { status: 500 }
      )
    }
  },
  { role: 'admin' }
)

/**
 * POST /api/debug/seed-students/embeddings
 *
 * Invalidates cached embeddings and regenerates them from current
 * profile content. Use this after updating profile intentionNotes.
 */
export const POST = withAuth(
  async () => {
    try {
      const status = await regenerateEmbeddings()
      return NextResponse.json(status)
    } catch (error) {
      console.error('[seed-students/embeddings] Regeneration failed:', error)
      return NextResponse.json(
        { error: error instanceof Error ? error.message : 'Regeneration failed' },
        { status: 500 }
      )
    }
  },
  { role: 'admin' }
)