generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b09940
commit a3d7da9
Showing
23 changed files
with
1,665 additions
and
17 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,58 @@ | ||
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 in Vercel environment | ||
const vercel = new Vercel({ | ||
bearerToken: deployment.token, | ||
}); | ||
|
||
const envVars = await vercel.projects.filterProjectEnvs({ | ||
idOrName: deployment.projectId, | ||
}); | ||
console.log('env vars', envVars); | ||
|
||
const openaiKeyPresent = envVars.envs.some( | ||
(env) => env.key === "OPENAI_API_KEY" | ||
); | ||
const anthropicKeyPresent = envVars.envs.some( | ||
(env) => env.key === "ANTHROPIC_API_KEY" | ||
); | ||
|
||
return NextResponse.json({ | ||
projectUrl: deployment.projectUrl, | ||
deploymentUrl: deployment.deploymentUrl, | ||
lastDeployment: deployment.lastDeployment, | ||
modelName: deployment.modelName, | ||
visionModelName: deployment.visionModelName, | ||
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.