feat(app): add provider methods

This commit is contained in:
ItzCrazyKns
2025-10-18 15:06:00 +05:30
parent e02b9a5efc
commit 5a7f45cace
5 changed files with 447 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
import ModelRegistry from '@/lib/models/registry';
import { NextRequest } from 'next/server';
export const GET = async (req: Request) => {
try {
@@ -6,9 +7,13 @@ export const GET = async (req: Request) => {
const activeProviders = await registry.getActiveProviders();
const filteredProviders = activeProviders.filter((p) => {
return !p.chatModels.some((m) => m.key === 'error');
});
return Response.json(
{
providers: activeProviders,
providers: filteredProviders,
},
{
status: 200,
@@ -26,3 +31,44 @@ export const GET = async (req: Request) => {
);
}
};
export const POST = async (req: NextRequest) => {
try {
const body = await req.json();
const { type, name, config } = body;
if (!type || !name || !config) {
return Response.json(
{
message: 'Missing required fields.',
},
{
status: 400,
},
);
}
const registry = new ModelRegistry();
const newProvider = await registry.addProvider(type, name, config);
return Response.json(
{
provider: newProvider,
},
{
status: 200,
},
);
} catch (err) {
console.error('An error occurred while creating provider', err);
return Response.json(
{
message: 'An error has occurred.',
},
{
status: 500,
},
);
}
};