Files
ra-h-os/app/api/nodes/[id]/regenerate-description/route.ts
T
“BeeRad” 4f030c7d29 sync: ingestion improvements from private repo
- Fixed dimension auto-assignment (locked dimensions now properly assigned)
- Added description field as grounding context for AI
- Updated embedding format: Title → Description → Content → Dimensions
- Description-weighted search (5x boost)
- Bug fixes: extraction tool dimension display, DimensionSearchModal closing
- Removed quickLink tool (use Quick Link workflow instead)
- Added regenerate-description API endpoint
2026-01-13 11:03:56 +11:00

59 lines
1.7 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { nodeService } from '@/services/database';
import { generateDescription } from '@/services/database/descriptionService';
export const runtime = 'nodejs';
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const nodeId = parseInt(id, 10);
if (isNaN(nodeId)) {
return NextResponse.json({
success: false,
error: 'Invalid node ID'
}, { status: 400 });
}
const node = await nodeService.getNodeById(nodeId);
if (!node) {
return NextResponse.json({
success: false,
error: 'Node not found'
}, { status: 404 });
}
// Generate new description using the description service
const newDescription = await generateDescription({
title: node.title,
content: node.content || undefined,
metadata: node.metadata as { source?: string; channel_name?: string; author?: string; site_name?: string } | undefined,
type: (node.metadata as { type?: string } | null)?.type
});
// Update the node with the new description
const updatedNode = await nodeService.updateNode(nodeId, {
description: newDescription
});
return NextResponse.json({
success: true,
node: updatedNode,
description: newDescription,
message: 'Description regenerated successfully'
});
} catch (error) {
console.error('Error regenerating description:', error);
return NextResponse.json({
success: false,
error: error instanceof Error ? error.message : 'Failed to regenerate description'
}, { status: 500 });
}
}