feat: enable client side config

This commit is contained in:
ElshadHu
2026-01-12 14:42:32 -05:00
parent 72d438e53a
commit af913f7223
3 changed files with 38 additions and 10 deletions
+16 -7
View File
@@ -81,6 +81,9 @@ interface ValidateRequest {
awsAccessKeyId?: string
awsSecretAccessKey?: string
awsRegion?: string
// Vertex AI specific
vertexProject?: string
vertexLocation?: string
}
export async function POST(req: Request) {
@@ -94,6 +97,8 @@ export async function POST(req: Request) {
awsAccessKeyId,
awsSecretAccessKey,
awsRegion,
vertexProject,
vertexLocation,
} = body
if (!provider || !modelId) {
@@ -166,23 +171,27 @@ export async function POST(req: Request) {
case "vertexai": {
// Vertex AI uses GCP service account authentication via environment variables
const vertexProject = process.env.GOOGLE_VERTEX_PROJECT
const vertexLocation =
process.env.GOOGLE_VERTEX_LOCATION || "us-central1"
// OR client-provided project/location
const project =
vertexProject || process.env.GOOGLE_VERTEX_PROJECT
const location =
vertexLocation ||
process.env.GOOGLE_VERTEX_LOCATION ||
"us-central1"
if (!vertexProject) {
if (!project) {
return NextResponse.json(
{
valid: false,
error: "GOOGLE_VERTEX_PROJECT environment variable is required",
error: "Project ID is required (set in Settings or via GOOGLE_VERTEX_PROJECT)",
},
{ status: 400 },
)
}
const vertex = createVertex({
project: vertexProject,
location: vertexLocation,
project: project,
location: location,
})
model = vertex(modelId)
break
+10 -3
View File
@@ -30,6 +30,9 @@ export interface ClientOverrides {
awsSecretAccessKey?: string | null
awsRegion?: string | null
awsSessionToken?: string | null
// Vertex AI config
vertexProject?: string | null
vertexLocation?: string | null
// Custom headers (e.g., for EdgeOne cookie auth)
headers?: Record<string, string>
}
@@ -684,13 +687,17 @@ export function getAIModel(overrides?: ClientOverrides): ModelConfig {
case "vertexai": {
// Google Vertex AI uses GCP service account authentication, not API keys
// Auth is handled via GOOGLE_APPLICATION_CREDENTIALS env var or GCP default credentials
const vertexProject = process.env.GOOGLE_VERTEX_PROJECT
// Client-provided Project ID and Location, falling back to server environment variables
const vertexProject =
overrides?.vertexProject || process.env.GOOGLE_VERTEX_PROJECT
const vertexLocation =
process.env.GOOGLE_VERTEX_LOCATION || "us-central1"
overrides?.vertexLocation ||
process.env.GOOGLE_VERTEX_LOCATION ||
"us-central1"
if (!vertexProject) {
throw new Error(
"GOOGLE_VERTEX_PROJECT environment variable is required for vertexai provider.",
"Project ID is required for Vertex AI. Please configure it in Settings or set GOOGLE_VERTEX_PROJECT environment variable.",
)
}
+12
View File
@@ -37,6 +37,10 @@ export interface ProviderConfig {
awsSecretAccessKey?: string
awsRegion?: string
awsSessionToken?: string // Optional, for temporary credentials
// Vertex AI specific fields
vertexProject?: string
vertexLocation?: string
models: ModelConfig[]
validated?: boolean // Has API key been validated
}
@@ -62,6 +66,10 @@ export interface FlattenedModel {
awsSecretAccessKey?: string
awsRegion?: string
awsSessionToken?: string
// Vertex AI specific fields
vertexProject?: string
vertexLocation?: string
validated?: boolean // Has this model been validated
}
@@ -323,6 +331,10 @@ export function flattenModels(config: MultiModelConfig): FlattenedModel[] {
awsSecretAccessKey: provider.awsSecretAccessKey,
awsRegion: provider.awsRegion,
awsSessionToken: provider.awsSessionToken,
// Vertex AI fields
vertexProject: provider.vertexProject,
vertexLocation: provider.vertexLocation,
validated: model.validated,
})
}