fix klavis error on project deletion

This commit is contained in:
Ramnique Singh 2025-06-08 16:32:20 +05:30
parent a79667b401
commit 7c00012fbc

View file

@ -14,6 +14,8 @@ import { USE_AUTH } from "../lib/feature_flags";
import { deleteMcpServerInstance, listActiveServerInstances } from "./klavis_actions"; import { deleteMcpServerInstance, listActiveServerInstances } from "./klavis_actions";
import { authorizeUserAction } from "./billing_actions"; import { authorizeUserAction } from "./billing_actions";
const KLAVIS_API_KEY = process.env.KLAVIS_API_KEY || '';
export async function projectAuthCheck(projectId: string) { export async function projectAuthCheck(projectId: string) {
if (!USE_AUTH) { if (!USE_AUTH) {
return; return;
@ -224,6 +226,7 @@ export async function deleteProject(projectId: string) {
await projectAuthCheck(projectId); await projectAuthCheck(projectId);
// First cleanup any Klavis instances // First cleanup any Klavis instances
if (KLAVIS_API_KEY) {
const deletionErrors = await cleanupMcpServers(projectId); const deletionErrors = await cleanupMcpServers(projectId);
// If there were any errors deleting instances, throw an error // If there were any errors deleting instances, throw an error
@ -231,6 +234,7 @@ export async function deleteProject(projectId: string) {
const failedServers = deletionErrors.map(e => `${e.serverName} (${e.error})`).join(', '); const failedServers = deletionErrors.map(e => `${e.serverName} (${e.error})`).join(', ');
throw new Error(`Cannot delete project because the following Klavis instances could not be deleted: ${failedServers}. Please try again or contact support if the issue persists.`); throw new Error(`Cannot delete project because the following Klavis instances could not be deleted: ${failedServers}. Please try again or contact support if the issue persists.`);
} }
}
// delete api keys // delete api keys
await apiKeysCollection.deleteMany({ await apiKeysCollection.deleteMany({