feat: sync quick add ingestion updates

- simplify quick add source selection and fallback saving
- improve description context and manual edit behavior
- add extractor dimension filtering and edge explanation migration
This commit is contained in:
“BeeRad”
2026-03-19 21:15:30 +11:00
parent 64aaf10feb
commit 1f8f41b4e0
14 changed files with 558 additions and 140 deletions
+2 -3
View File
@@ -57,9 +57,8 @@ export async function POST(request: NextRequest) {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
title,
type: 'pdf',
// Keep content readable in UI (not the full extracted text)
content: `Imported PDF: ${file.name} (${extraction.metadata.pages} pages, ${Math.round(extraction.metadata.text_length / 1000)}k characters)`,
// Give the description generator and UI a readable summary plus a short excerpt.
notes: `Imported PDF document: ${file.name} (${extraction.metadata.pages} pages, ${Math.round(extraction.metadata.text_length / 1000)}k characters).\n\nPreview:\n${extraction.chunk.slice(0, 1200)}`,
// Full extracted text goes in chunk for universal chunking/embedding
chunk: extraction.chunk,
metadata: {
+3 -4
View File
@@ -75,10 +75,9 @@ export async function PUT(
if (typeof body.description === 'string') {
const descriptionError = validateExplicitDescription(body.description);
if (descriptionError) {
return NextResponse.json({
success: false,
error: descriptionError
}, { status: 400 });
console.warn(
`[DescriptionQuality] User-updated description failed validation for node ${nodeId}: ${descriptionError}`
);
}
}
+15 -7
View File
@@ -93,6 +93,7 @@ export async function POST(request: NextRequest) {
body.title = sanitizeTitle(body.title);
const rawNotes = typeof body.notes === 'string' ? body.notes : null;
const rawChunk = typeof body.chunk === 'string' ? body.chunk : null;
const eventDate = typeof body.event_date === 'string' ? body.event_date : null;
// Process provided dimensions first (needed for description generation)
@@ -107,7 +108,7 @@ export async function POST(request: NextRequest) {
try {
nodeDescription = await generateDescription({
title: body.title,
notes: rawNotes || undefined,
notes: rawNotes || rawChunk?.slice(0, 2000) || undefined,
link: body.link || undefined,
metadata: body.metadata,
dimensions: trimmedProvidedDimensions
@@ -122,14 +123,22 @@ export async function POST(request: NextRequest) {
nodeDescription = body.title.slice(0, 280);
}
const finalDescription = nodeDescription ?? body.title.slice(0, 280);
let finalDescription = nodeDescription ?? body.title.slice(0, 280);
const descriptionError = validateExplicitDescription(finalDescription);
if (descriptionError) {
return NextResponse.json({
success: false,
error: descriptionError
}, { status: 400 });
const isUserSuppliedDescription = typeof body.description === 'string' && body.description.trim().length > 0;
if (isUserSuppliedDescription) {
return NextResponse.json({
success: false,
error: descriptionError
}, { status: 400 });
}
console.warn(
`[DescriptionQuality] Auto-generated description failed validation for "${body.title}": ${descriptionError}. Falling back to title.`
);
finalDescription = body.title.slice(0, 280);
}
// Monitor description quality
@@ -139,7 +148,6 @@ export async function POST(request: NextRequest) {
// Use only provided dimensions (no auto-assignment)
const finalDimensions = trimmedProvidedDimensions;
const rawChunk = typeof body.chunk === 'string' ? body.chunk : null;
let chunkToStore = rawChunk;
let chunkStatus: Node['chunk_status'];
+3 -3
View File
@@ -14,18 +14,18 @@ export async function POST(request: NextRequest) {
}
const normalizedMode: QuickAddMode | undefined =
mode === 'link' || mode === 'note' || mode === 'chat' ? mode : undefined;
mode === 'link' || mode === 'text' ? mode : undefined;
const normalizedDescription: string | undefined =
typeof description === 'string' && description.trim() ? description.trim() : undefined;
const delegation = await enqueueQuickAdd({
const result = await enqueueQuickAdd({
rawInput: input.trim(),
mode: normalizedMode,
description: normalizedDescription,
});
return NextResponse.json({ success: true, delegation });
return NextResponse.json({ success: true, result });
} catch (error) {
console.error('[Quick Add API] Error:', error);
const message = error instanceof Error ? error.message : 'Unknown error';