feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
import { POST as validateModel } from "@/app/api/validate-model/route"
|
|
|
|
|
import { checkAdminAuth } from "@/lib/admin/auth"
|
2026-06-11 13:14:05 +09:00
|
|
|
import {
|
|
|
|
|
AdminProviderSchema,
|
|
|
|
|
loadAdminProviders,
|
|
|
|
|
mergeSecrets,
|
|
|
|
|
} from "@/lib/admin/providers"
|
feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
|
|
|
|
|
export const runtime = "nodejs"
|
|
|
|
|
export const dynamic = "force-dynamic"
|
|
|
|
|
|
2026-06-11 13:14:05 +09:00
|
|
|
// Test a model with the client's CURRENT provider state (which may be
|
|
|
|
|
// unsaved). Secret fields arrive either as plaintext (newly typed) or as
|
|
|
|
|
// masked {isSet} markers, which are resolved against settings.json — so
|
|
|
|
|
// testing works both before and after saving.
|
feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
export async function POST(req: Request) {
|
|
|
|
|
const authError = checkAdminAuth(req)
|
|
|
|
|
if (authError) return authError
|
|
|
|
|
|
2026-06-11 13:14:05 +09:00
|
|
|
let body: { provider?: unknown; modelId?: string }
|
feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
try {
|
|
|
|
|
body = await req.json()
|
|
|
|
|
} catch {
|
|
|
|
|
return Response.json({ error: "Invalid JSON body" }, { status: 400 })
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-11 13:14:05 +09:00
|
|
|
const parsed = AdminProviderSchema.safeParse(body.provider)
|
|
|
|
|
if (!parsed.success || !body.modelId) {
|
feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
return Response.json(
|
2026-06-11 13:14:05 +09:00
|
|
|
{ valid: false, error: "Invalid provider or model" },
|
feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
{ status: 400 },
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-12 08:13:26 +09:00
|
|
|
// SECURITY: a stored secret is only resolved from an {isSet} marker if
|
|
|
|
|
// the endpoint it would be sent to (provider + baseUrl) still matches
|
|
|
|
|
// the stored entry. Otherwise a tampered baseUrl could exfiltrate the
|
|
|
|
|
// stored key to an arbitrary host. Mismatches must re-supply plaintext.
|
|
|
|
|
const stored = loadAdminProviders().find((p) => p.id === parsed.data.id)
|
|
|
|
|
const sameEndpoint =
|
|
|
|
|
stored &&
|
|
|
|
|
stored.provider === parsed.data.provider &&
|
|
|
|
|
(stored.baseUrl ?? "") === (parsed.data.baseUrl ?? "") &&
|
|
|
|
|
(stored.awsRegion ?? "") === (parsed.data.awsRegion ?? "")
|
|
|
|
|
const [resolved] = mergeSecrets(
|
|
|
|
|
[parsed.data],
|
|
|
|
|
sameEndpoint && stored ? [stored] : [],
|
|
|
|
|
)
|
2026-06-11 13:14:05 +09:00
|
|
|
|
feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
return validateModel(
|
|
|
|
|
new Request(new URL("/api/validate-model", req.url), {
|
|
|
|
|
method: "POST",
|
|
|
|
|
headers: { "Content-Type": "application/json" },
|
|
|
|
|
body: JSON.stringify({
|
2026-06-11 13:14:05 +09:00
|
|
|
provider: resolved.provider,
|
|
|
|
|
apiKey: resolved.apiKey,
|
|
|
|
|
baseUrl: resolved.baseUrl,
|
feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
modelId: body.modelId,
|
2026-06-11 13:14:05 +09:00
|
|
|
awsAccessKeyId: resolved.awsAccessKeyId,
|
|
|
|
|
awsSecretAccessKey: resolved.awsSecretAccessKey,
|
|
|
|
|
awsRegion: resolved.awsRegion,
|
|
|
|
|
vertexApiKey: resolved.vertexApiKey,
|
feat: graphical model management in admin panel
Replace the provider credential fields and raw AI_MODELS_CONFIG JSON
textarea with a Models section mirroring the in-app model settings UI:
provider instance list with logos, credential fields per provider type,
model add/remove with suggestions, per-model connectivity test, and a
default-provider star.
On save the server derives everything the runtime needs into
settings.json: credential env vars (with _2 suffixes for multiple
instances of one provider), AI_MODELS_CONFIG, and AI_PROVIDER/AI_MODEL
for the default. Secrets round-trip as masked markers and are never
sent back to the browser. The general settings registry now only
covers non-provider settings (generation, access, features,
observability, quota).
2026-06-10 23:15:18 +09:00
|
|
|
}),
|
|
|
|
|
}),
|
|
|
|
|
)
|
|
|
|
|
}
|