mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-09-08 12:20:20 +08:00
feat: enable client side config
This commit is contained in:
@@ -81,6 +81,9 @@ interface ValidateRequest {
|
|||||||
awsAccessKeyId?: string
|
awsAccessKeyId?: string
|
||||||
awsSecretAccessKey?: string
|
awsSecretAccessKey?: string
|
||||||
awsRegion?: string
|
awsRegion?: string
|
||||||
|
// Vertex AI specific
|
||||||
|
vertexProject?: string
|
||||||
|
vertexLocation?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST(req: Request) {
|
export async function POST(req: Request) {
|
||||||
@@ -94,6 +97,8 @@ export async function POST(req: Request) {
|
|||||||
awsAccessKeyId,
|
awsAccessKeyId,
|
||||||
awsSecretAccessKey,
|
awsSecretAccessKey,
|
||||||
awsRegion,
|
awsRegion,
|
||||||
|
vertexProject,
|
||||||
|
vertexLocation,
|
||||||
} = body
|
} = body
|
||||||
|
|
||||||
if (!provider || !modelId) {
|
if (!provider || !modelId) {
|
||||||
@@ -166,23 +171,27 @@ export async function POST(req: Request) {
|
|||||||
|
|
||||||
case "vertexai": {
|
case "vertexai": {
|
||||||
// Vertex AI uses GCP service account authentication via environment variables
|
// Vertex AI uses GCP service account authentication via environment variables
|
||||||
const vertexProject = process.env.GOOGLE_VERTEX_PROJECT
|
// OR client-provided project/location
|
||||||
const vertexLocation =
|
const project =
|
||||||
process.env.GOOGLE_VERTEX_LOCATION || "us-central1"
|
vertexProject || process.env.GOOGLE_VERTEX_PROJECT
|
||||||
|
const location =
|
||||||
|
vertexLocation ||
|
||||||
|
process.env.GOOGLE_VERTEX_LOCATION ||
|
||||||
|
"us-central1"
|
||||||
|
|
||||||
if (!vertexProject) {
|
if (!project) {
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
valid: false,
|
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 },
|
{ status: 400 },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const vertex = createVertex({
|
const vertex = createVertex({
|
||||||
project: vertexProject,
|
project: project,
|
||||||
location: vertexLocation,
|
location: location,
|
||||||
})
|
})
|
||||||
model = vertex(modelId)
|
model = vertex(modelId)
|
||||||
break
|
break
|
||||||
|
|||||||
+10
-3
@@ -30,6 +30,9 @@ export interface ClientOverrides {
|
|||||||
awsSecretAccessKey?: string | null
|
awsSecretAccessKey?: string | null
|
||||||
awsRegion?: string | null
|
awsRegion?: string | null
|
||||||
awsSessionToken?: string | null
|
awsSessionToken?: string | null
|
||||||
|
// Vertex AI config
|
||||||
|
vertexProject?: string | null
|
||||||
|
vertexLocation?: string | null
|
||||||
// Custom headers (e.g., for EdgeOne cookie auth)
|
// Custom headers (e.g., for EdgeOne cookie auth)
|
||||||
headers?: Record<string, string>
|
headers?: Record<string, string>
|
||||||
}
|
}
|
||||||
@@ -684,13 +687,17 @@ export function getAIModel(overrides?: ClientOverrides): ModelConfig {
|
|||||||
case "vertexai": {
|
case "vertexai": {
|
||||||
// Google Vertex AI uses GCP service account authentication, not API keys
|
// Google Vertex AI uses GCP service account authentication, not API keys
|
||||||
// Auth is handled via GOOGLE_APPLICATION_CREDENTIALS env var or GCP default credentials
|
// 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 =
|
const vertexLocation =
|
||||||
process.env.GOOGLE_VERTEX_LOCATION || "us-central1"
|
overrides?.vertexLocation ||
|
||||||
|
process.env.GOOGLE_VERTEX_LOCATION ||
|
||||||
|
"us-central1"
|
||||||
|
|
||||||
if (!vertexProject) {
|
if (!vertexProject) {
|
||||||
throw new Error(
|
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.",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ export interface ProviderConfig {
|
|||||||
awsSecretAccessKey?: string
|
awsSecretAccessKey?: string
|
||||||
awsRegion?: string
|
awsRegion?: string
|
||||||
awsSessionToken?: string // Optional, for temporary credentials
|
awsSessionToken?: string // Optional, for temporary credentials
|
||||||
|
// Vertex AI specific fields
|
||||||
|
vertexProject?: string
|
||||||
|
vertexLocation?: string
|
||||||
|
|
||||||
models: ModelConfig[]
|
models: ModelConfig[]
|
||||||
validated?: boolean // Has API key been validated
|
validated?: boolean // Has API key been validated
|
||||||
}
|
}
|
||||||
@@ -62,6 +66,10 @@ export interface FlattenedModel {
|
|||||||
awsSecretAccessKey?: string
|
awsSecretAccessKey?: string
|
||||||
awsRegion?: string
|
awsRegion?: string
|
||||||
awsSessionToken?: string
|
awsSessionToken?: string
|
||||||
|
// Vertex AI specific fields
|
||||||
|
vertexProject?: string
|
||||||
|
vertexLocation?: string
|
||||||
|
|
||||||
validated?: boolean // Has this model been validated
|
validated?: boolean // Has this model been validated
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,6 +331,10 @@ export function flattenModels(config: MultiModelConfig): FlattenedModel[] {
|
|||||||
awsSecretAccessKey: provider.awsSecretAccessKey,
|
awsSecretAccessKey: provider.awsSecretAccessKey,
|
||||||
awsRegion: provider.awsRegion,
|
awsRegion: provider.awsRegion,
|
||||||
awsSessionToken: provider.awsSessionToken,
|
awsSessionToken: provider.awsSessionToken,
|
||||||
|
// Vertex AI fields
|
||||||
|
vertexProject: provider.vertexProject,
|
||||||
|
vertexLocation: provider.vertexLocation,
|
||||||
|
|
||||||
validated: model.validated,
|
validated: model.validated,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user