36 lines
873 B
TypeScript
36 lines
873 B
TypeScript
|
|
import { NextResponse } from 'next/server';
|
||
|
|
import { getProviders, setProviderApiKey } from '@/lib/openclaw';
|
||
|
|
|
||
|
|
export async function GET() {
|
||
|
|
try {
|
||
|
|
const providers = await getProviders();
|
||
|
|
return NextResponse.json({ providers });
|
||
|
|
} catch (error) {
|
||
|
|
return NextResponse.json(
|
||
|
|
{ error: (error as Error).message },
|
||
|
|
{ status: 500 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function POST(request: Request) {
|
||
|
|
try {
|
||
|
|
const { providerId, apiKey } = await request.json();
|
||
|
|
|
||
|
|
if (!providerId || !apiKey) {
|
||
|
|
return NextResponse.json(
|
||
|
|
{ error: 'providerId and apiKey are required' },
|
||
|
|
{ status: 400 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
const result = await setProviderApiKey(providerId, apiKey);
|
||
|
|
return NextResponse.json(result);
|
||
|
|
} catch (error) {
|
||
|
|
return NextResponse.json(
|
||
|
|
{ error: (error as Error).message },
|
||
|
|
{ status: 500 }
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|