feat: add FastAPI model/load endpoint and all Next.js proxy routes (tasks 2-4)

This commit is contained in:
Marko Djordjevic 2026-02-17 18:47:04 +01:00
parent b8e649e333
commit 2a02669222
29 changed files with 1110 additions and 780 deletions

View file

@ -0,0 +1,34 @@
import { NextRequest, NextResponse } from 'next/server';
const INFERENCE_API_URL = process.env.INFERENCE_API_URL || 'http://localhost:8001';
const INFERENCE_API_TIMEOUT = parseInt(process.env.INFERENCE_API_TIMEOUT || '10000', 10);
export async function GET(_request: NextRequest) {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), INFERENCE_API_TIMEOUT);
try {
const response = await fetch(`${INFERENCE_API_URL}/patterns/available`, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
signal: controller.signal,
});
clearTimeout(timeoutId);
const data = await response.json();
if (!response.ok) {
return NextResponse.json({ error: data.detail || 'Request failed' }, { status: response.status });
}
return NextResponse.json(data);
} catch (error: any) {
clearTimeout(timeoutId);
if (error.name === 'AbortError') {
return NextResponse.json({ error: 'Request timed out' }, { status: 504 });
}
if (error.cause?.code === 'ECONNREFUSED' || error.message?.includes('fetch failed')) {
return NextResponse.json({ error: 'Inference service unavailable' }, { status: 503 });
}
console.error('patterns/available proxy error:', error);
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
}
}