51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { auth } from "@/app/(auth)/auth";
|
|
import { getAiModelById, getAiProviderById } from "@/lib/db/queries";
|
|
import { buildVideoToolCapability } from "@/lib/ai/video-tool-capability";
|
|
import { ChatSDKError } from "@/lib/errors";
|
|
|
|
export async function GET(request: Request) {
|
|
try {
|
|
const session = await auth();
|
|
if (!session?.user?.id) {
|
|
return new ChatSDKError("unauthorized:chat").toResponse();
|
|
}
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const modelDbId = searchParams.get("modelId");
|
|
if (!modelDbId) {
|
|
return new ChatSDKError("bad_request:api", "modelId is required").toResponse();
|
|
}
|
|
|
|
const model = await getAiModelById({ id: modelDbId });
|
|
if (!model || !model.isEnabled) {
|
|
return new ChatSDKError("bad_request:api", "Model not found or disabled").toResponse();
|
|
}
|
|
|
|
const provider = await getAiProviderById({ id: model.providerId });
|
|
if (!provider || !provider.isEnabled) {
|
|
return new ChatSDKError("bad_request:api", "Provider not found or disabled").toResponse();
|
|
}
|
|
|
|
const capability = buildVideoToolCapability({
|
|
providerType: provider.type,
|
|
modelId: model.modelId,
|
|
rawCapabilities: model.capabilities,
|
|
imageGenConfig: (model.imageGenConfig || null) as
|
|
| { videoDurationOptions?: number[] | null }
|
|
| null,
|
|
});
|
|
|
|
return Response.json({
|
|
modelId: model.id,
|
|
modelName: model.displayName,
|
|
providerType: provider.type,
|
|
capability,
|
|
});
|
|
} catch (error) {
|
|
if (error instanceof ChatSDKError) {
|
|
return error.toResponse();
|
|
}
|
|
return new ChatSDKError("offline:chat").toResponse();
|
|
}
|
|
}
|