Some checks failed
Deploy to Production / Build and Deploy (push) Failing after 1m7s
Replaced ~100+ hardcoded French and English text strings across 30+ components with proper i18n t() calls. Added 57 new translation keys to all 15 locale files (ar, de, en, es, fa, fr, hi, it, ja, ko, nl, pl, pt, ru, zh). Key changes: - contextual-ai-chat.tsx: 30 French strings → t() (actions, toasts, labels, placeholders) - ai-chat.tsx: 15 French/English strings → t() (header, tabs, welcome, insights, history) - note-inline-editor.tsx: 20 French fallbacks removed (toolbar, save status, checklist) - lab-skeleton.tsx: French loading text → t() - admin-header.tsx, header.tsx, editor-connections-section.tsx: French fallbacks removed - New AI chat component, agent cards, sidebar, settings panel i18n cleanup Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
130 lines
3.2 KiB
TypeScript
130 lines
3.2 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { auth } from '@/auth'
|
|
import { autoLabelCreationService } from '@/lib/ai/services'
|
|
import { getAISettings } from '@/app/actions/ai-settings'
|
|
|
|
/**
|
|
* POST /api/ai/auto-labels - Suggest new labels for a notebook
|
|
*/
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const session = await auth()
|
|
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json(
|
|
{ success: false, error: 'Unauthorized' },
|
|
{ status: 401 }
|
|
)
|
|
}
|
|
|
|
// Respect user's autoLabeling toggle
|
|
const userSettings = await getAISettings(session.user.id)
|
|
if (userSettings.autoLabeling === false) {
|
|
return NextResponse.json({ success: true, data: null, message: 'Auto-labeling disabled by user' })
|
|
}
|
|
|
|
const body = await request.json()
|
|
const { notebookId, language = 'en' } = body
|
|
|
|
if (!notebookId || typeof notebookId !== 'string') {
|
|
return NextResponse.json(
|
|
{ success: false, error: 'Missing required field: notebookId' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
// Check if notebook belongs to user
|
|
const { prisma } = await import('@/lib/prisma')
|
|
const notebook = await prisma.notebook.findFirst({
|
|
where: {
|
|
id: notebookId,
|
|
userId: session.user.id,
|
|
},
|
|
})
|
|
|
|
if (!notebook) {
|
|
return NextResponse.json(
|
|
{ success: false, error: 'Notebook not found' },
|
|
{ status: 404 }
|
|
)
|
|
}
|
|
|
|
// Get label suggestions
|
|
const suggestions = await autoLabelCreationService.suggestLabels(
|
|
notebookId,
|
|
session.user.id,
|
|
language
|
|
)
|
|
|
|
if (!suggestions) {
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: null,
|
|
message: 'No suggestions available (notebook may have fewer than 15 notes)',
|
|
})
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: suggestions,
|
|
})
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Failed to get label suggestions',
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|
|
/**
|
|
* PUT /api/ai/auto-labels - Create suggested labels
|
|
*/
|
|
export async function PUT(request: NextRequest) {
|
|
try {
|
|
const session = await auth()
|
|
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json(
|
|
{ success: false, error: 'Unauthorized' },
|
|
{ status: 401 }
|
|
)
|
|
}
|
|
|
|
const body = await request.json()
|
|
const { suggestions, selectedLabels } = body
|
|
|
|
if (!suggestions || !Array.isArray(selectedLabels)) {
|
|
return NextResponse.json(
|
|
{ success: false, error: 'Missing required fields: suggestions, selectedLabels' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
// Create labels
|
|
const createdCount = await autoLabelCreationService.createLabels(
|
|
suggestions.notebookId,
|
|
session.user.id,
|
|
suggestions,
|
|
selectedLabels
|
|
)
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: {
|
|
createdCount,
|
|
},
|
|
})
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : 'Failed to create labels',
|
|
},
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|