feat: port contexts layer and MCP parity
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { contextService } from '@/services/database';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const contextId = parseInt(id, 10);
|
||||
if (Number.isNaN(contextId)) {
|
||||
return NextResponse.json({ success: false, error: 'Invalid context ID' }, { status: 400 });
|
||||
}
|
||||
|
||||
const nodes = await contextService.getNodesForContext(contextId);
|
||||
return NextResponse.json({ success: true, data: nodes, count: nodes.length });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false, error: error instanceof Error ? error.message : 'Failed to fetch context nodes' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { contextService } from '@/services/database';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const contextId = parseInt(id, 10);
|
||||
if (Number.isNaN(contextId)) {
|
||||
return NextResponse.json({ success: false, error: 'Invalid context ID' }, { status: 400 });
|
||||
}
|
||||
|
||||
const context = await contextService.getContextById(contextId);
|
||||
if (!context) {
|
||||
return NextResponse.json({ success: false, error: 'Context not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, data: context });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false, error: error instanceof Error ? error.message : 'Failed to fetch context' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { contextService } from '@/services/database';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const contexts = await contextService.listContexts();
|
||||
return NextResponse.json({ success: true, data: contexts });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false, error: error instanceof Error ? error.message : 'Failed to fetch contexts' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const context = await contextService.createContext({
|
||||
name: body.name,
|
||||
description: body.description,
|
||||
icon: body.icon,
|
||||
});
|
||||
return NextResponse.json({ success: true, data: context }, { status: 201 });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false, error: error instanceof Error ? error.message : 'Failed to create context' }, { status: 400 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
if (typeof body.id !== 'number' || !Number.isInteger(body.id) || body.id <= 0) {
|
||||
return NextResponse.json({ success: false, error: 'Context id is required' }, { status: 400 });
|
||||
}
|
||||
|
||||
const context = await contextService.updateContext({
|
||||
id: body.id,
|
||||
name: body.name,
|
||||
description: body.description,
|
||||
icon: body.icon,
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, data: context });
|
||||
} catch (error) {
|
||||
return NextResponse.json({ success: false, error: error instanceof Error ? error.message : 'Failed to update context' }, { status: 400 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user