generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add deployment dashboard (#284)
- Loading branch information
1 parent
5440ad4
commit 4f39cc5
Showing
25 changed files
with
2,007 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { NextResponse } from "next/server"; | ||
import { db, vercelTokens } from "@/drizzle/schema"; | ||
import { auth } from "@clerk/nextjs/server"; | ||
import { eq } from "drizzle-orm"; | ||
import { Vercel } from "@vercel/sdk"; | ||
|
||
export async function GET() { | ||
try { | ||
const { userId } = auth(); | ||
if (!userId) { | ||
return new NextResponse("Unauthorized", { status: 401 }); | ||
} | ||
|
||
const [deployment] = await db | ||
.select() | ||
.from(vercelTokens) | ||
.where(eq(vercelTokens.userId, userId)) | ||
.limit(1); | ||
|
||
if (!deployment) { | ||
return new NextResponse("No deployment found", { status: 404 }); | ||
} | ||
|
||
// Check for API keys and model names in Vercel environment | ||
const vercel = new Vercel({ | ||
bearerToken: deployment.token, | ||
}); | ||
|
||
// @ts-ignore | ||
const { envs } = await vercel.projects.filterProjectEnvs({ | ||
idOrName: deployment.projectId, | ||
}); | ||
|
||
// Find environment variables | ||
const openaiKeyPresent = envs.some(env => env.key === "OPENAI_API_KEY"); | ||
const anthropicKeyPresent = envs.some(env => env.key === "ANTHROPIC_API_KEY"); | ||
const currentModelName = envs.find(env => env.key === "MODEL_NAME")?.value || 'gpt-4o'; | ||
const currentVisionModelName = envs.find(env => env.key === "VISION_MODEL_NAME")?.value || 'gpt-4o'; | ||
|
||
return NextResponse.json({ | ||
projectUrl: deployment.projectUrl, | ||
deploymentUrl: deployment.deploymentUrl, | ||
lastDeployment: deployment.lastDeployment, | ||
modelName: currentModelName, | ||
visionModelName: currentVisionModelName, | ||
lastApiKeyUpdate: deployment.lastApiKeyUpdate, | ||
openaiKeyPresent, | ||
anthropicKeyPresent, | ||
}); | ||
} catch (error) { | ||
console.error("Error fetching deployment status:", error); | ||
return NextResponse.json( | ||
{ error: "Failed to fetch deployment status" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { NextResponse } from "next/server"; | ||
import { db, vercelTokens } from "@/drizzle/schema"; | ||
import { auth } from "@clerk/nextjs/server"; | ||
import { eq } from "drizzle-orm"; | ||
import { Vercel } from "@vercel/sdk"; | ||
|
||
export async function POST(request: Request) { | ||
try { | ||
const { userId } = auth(); | ||
if (!userId) { | ||
return new NextResponse("Unauthorized", { status: 401 }); | ||
} | ||
|
||
const { provider, modelApiKey, modelName, soloApiKey } = await request.json(); | ||
|
||
const [deployment] = await db | ||
.select() | ||
.from(vercelTokens) | ||
.where(eq(vercelTokens.userId, userId)) | ||
.limit(1); | ||
|
||
if (!deployment) { | ||
return new NextResponse("No deployment found", { status: 404 }); | ||
} | ||
|
||
const vercel = new Vercel({ | ||
bearerToken: deployment.token, | ||
}); | ||
|
||
// Prepare environment variables | ||
const envVars = [ | ||
{ | ||
key: provider === 'anthropic' ? 'ANTHROPIC_API_KEY' : 'OPENAI_API_KEY', | ||
value: modelApiKey, | ||
type: "encrypted", | ||
target: ["production"], | ||
}, | ||
]; | ||
|
||
// Add SOLO_API_KEY if provided | ||
if (soloApiKey) { | ||
envVars.push({ | ||
key: 'SOLO_API_KEY', | ||
value: soloApiKey, | ||
type: "encrypted", | ||
target: ["production"], | ||
}); | ||
} | ||
|
||
// Update environment variables using the correct method | ||
await vercel.projects.createProjectEnv({ | ||
idOrName: deployment.projectId, | ||
upsert: 'true', | ||
// @ts-ignore | ||
requestBody: envVars, | ||
}) | ||
|
||
|
||
|
||
// Update database record | ||
await db | ||
.update(vercelTokens) | ||
.set({ | ||
modelProvider: provider, | ||
modelName, | ||
lastApiKeyUpdate: new Date(), | ||
updatedAt: new Date(), | ||
}) | ||
.where(eq(vercelTokens.userId, userId)); | ||
|
||
return NextResponse.json({ success: true }); | ||
} catch (error) { | ||
console.error("Error updating API key:", error); | ||
return NextResponse.json( | ||
{ error: "Failed to update API key" }, | ||
{ status: 500 } | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.