fix: label management - transaction safety, deletion sync, error handling
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 42s
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 42s
- Use prisma.$transaction in auto-label-creation.service with tx client - Fix DELETE /api/labels to properly JSON.parse + disconnect labelRelations - Fix PUT /api/labels rename to handle JSON labels - Graceful error handling in /api/ai/tags and /api/ai/auto-labels - Client-side label-deleted event in home-client, notes-tabs-view, label-management-dialog Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -69,13 +69,8 @@ export async function POST(request: NextRequest) {
|
||||
data: suggestions,
|
||||
})
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to get label suggestions',
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
console.error('[/api/ai/auto-labels] POST failed:', error)
|
||||
return NextResponse.json({ success: true, data: null })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,12 +113,7 @@ export async function PUT(request: NextRequest) {
|
||||
},
|
||||
})
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to create labels',
|
||||
},
|
||||
{ status: 500 }
|
||||
)
|
||||
console.error('[/api/ai/auto-labels] PUT failed:', error)
|
||||
return NextResponse.json({ success: false, error: 'Failed to create labels' })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,31 +30,38 @@ export async function POST(req: NextRequest) {
|
||||
|
||||
// If notebookId is provided, use contextual suggestions (IA2)
|
||||
if (notebookId) {
|
||||
const suggestions = await contextualAutoTagService.suggestLabels(
|
||||
content,
|
||||
notebookId,
|
||||
session.user.id,
|
||||
language
|
||||
);
|
||||
try {
|
||||
const suggestions = await contextualAutoTagService.suggestLabels(
|
||||
content,
|
||||
notebookId,
|
||||
session.user.id,
|
||||
language
|
||||
);
|
||||
|
||||
// Convert label → tag to match TagSuggestion interface
|
||||
const convertedTags = suggestions.map(s => ({
|
||||
tag: s.label, // Convert label to tag
|
||||
confidence: s.confidence,
|
||||
// Keep additional properties for client-side use
|
||||
...(s.reasoning && { reasoning: s.reasoning }),
|
||||
...(s.isNewLabel !== undefined && { isNewLabel: s.isNewLabel })
|
||||
}));
|
||||
const convertedTags = suggestions.map(s => ({
|
||||
tag: s.label,
|
||||
confidence: s.confidence,
|
||||
...(s.reasoning && { reasoning: s.reasoning }),
|
||||
...(s.isNewLabel !== undefined && { isNewLabel: s.isNewLabel })
|
||||
}));
|
||||
|
||||
return NextResponse.json({ tags: convertedTags });
|
||||
return NextResponse.json({ tags: convertedTags });
|
||||
} catch (err) {
|
||||
console.error('[/api/ai/tags] contextualAutoTag failed:', err)
|
||||
return NextResponse.json({ tags: [] });
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, use legacy auto-tagging (generates new tags)
|
||||
const config = await getSystemConfig();
|
||||
const provider = getTagsProvider(config);
|
||||
const tags = await provider.generateTags(content, language);
|
||||
|
||||
return NextResponse.json({ tags });
|
||||
try {
|
||||
const config = await getSystemConfig();
|
||||
const provider = getTagsProvider(config);
|
||||
const tags = await provider.generateTags(content, language);
|
||||
return NextResponse.json({ tags });
|
||||
} catch (err) {
|
||||
console.error('[/api/ai/tags] legacy tagging failed:', err)
|
||||
return NextResponse.json({ tags: [] });
|
||||
}
|
||||
} catch (error: any) {
|
||||
|
||||
if (error instanceof z.ZodError) {
|
||||
|
||||
Reference in New Issue
Block a user