Google OAuth was implemented locally but never deployed; the login button only renders when AUTH_GOOGLE_ID and AUTH_GOOGLE_SECRET are set. Also restores /api/ai/test-* endpoints removed by mistake and wires Google credentials into deploy workflows. Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { getChatProvider } from '@/lib/ai/factory'
|
|
import { getSystemConfig } from '@/lib/config'
|
|
import { auth } from '@/auth'
|
|
|
|
export async function POST() {
|
|
const session = await auth()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
if ((session.user as { role?: string }).role !== 'ADMIN') {
|
|
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
|
|
}
|
|
|
|
try {
|
|
const config = await getSystemConfig()
|
|
const provider = getChatProvider(config)
|
|
|
|
const testMessage = 'Reply in exactly 3 words: what is your name?'
|
|
|
|
const startTime = Date.now()
|
|
const response = await provider.generateText(testMessage)
|
|
const endTime = Date.now()
|
|
|
|
if (!response || response.trim().length === 0) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: 'No response from chat provider',
|
|
provider: config.AI_PROVIDER_CHAT || config.AI_PROVIDER_TAGS || 'ollama',
|
|
model: config.AI_MODEL_CHAT || 'granite4:latest',
|
|
},
|
|
{ status: 500 },
|
|
)
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
provider: config.AI_PROVIDER_CHAT || config.AI_PROVIDER_TAGS || 'ollama',
|
|
model: config.AI_MODEL_CHAT || 'granite4:latest',
|
|
chatResponse: response.trim(),
|
|
responseTime: endTime - startTime,
|
|
})
|
|
} catch (error: unknown) {
|
|
const config = await getSystemConfig()
|
|
const message = error instanceof Error ? error.message : 'Unknown error'
|
|
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: message,
|
|
provider: config.AI_PROVIDER_CHAT || config.AI_PROVIDER_TAGS || 'ollama',
|
|
model: config.AI_MODEL_CHAT || 'granite4:latest',
|
|
stack: process.env.NODE_ENV === 'development' && error instanceof Error ? error.stack : undefined,
|
|
},
|
|
{ status: 500 },
|
|
)
|
|
}
|
|
}
|