* feat(media): resolve image, video, and ASR models from server config The image generation chain never consulted the server-side IMAGE_<PREFIX>_MODELS config: the route only forwarded the client x-image-model header and each adapter silently fell back to a hardcoded vendor default, so a managed provider could generate with a model the operator never chose. The provider itself also defaulted to a hardcoded vendor id when the client sent no preference. - Add resolveImageModel / resolveVideoModel / resolveASRModel and resolveServerImageProviderId / resolveServerVideoProviderId to the server provider config, mirroring how TTS already resolves server-managed settings. - Routes resolve provider and model server-side when the client sends no preference and fail loud with a clear 400 when nothing resolves; no more hardcoded vendor defaults. - Adapters require an explicit model via requireModel; connectivity probes keep a fixed probe payload since they are auth handshakes, not user-facing generation. - Tests cover the resolver precedence and the fail-loud paths. * fix(media): align model resolution semantics across capabilities resolveImageModel and resolveASRModel let the server pin win unconditionally, while resolveVideoModel implements allowlist semantics (client choice wins when it is in the pinned list, otherwise the first pinned entry). Align image and ASR to the video allowlist semantics so a client picking any server-pinned model is honored, and update the resolver docstrings and tests to pin the aligned behavior for all three capabilities. The classroom media path has no client model and no HTTP response to fail loud with: it now falls back to the first catalog model when the operator pins no _MODELS list, so key-only deployments keep generating media instead of silently skipping every element via the adapter's requireModel backstop. * fix(media): normalize configured model lists and client model ids
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
|
|
export const API_ERROR_CODES = {
|
|
MISSING_REQUIRED_FIELD: 'MISSING_REQUIRED_FIELD',
|
|
MISSING_API_KEY: 'MISSING_API_KEY',
|
|
MISSING_PROVIDER: 'MISSING_PROVIDER',
|
|
MISSING_MODEL: 'MISSING_MODEL',
|
|
INVALID_CREDENTIALS: 'INVALID_CREDENTIALS',
|
|
INVALID_REQUEST: 'INVALID_REQUEST',
|
|
UNAUTHENTICATED: 'UNAUTHENTICATED',
|
|
ASSET_NOT_FOUND: 'ASSET_NOT_FOUND',
|
|
PROVIDER_DISABLED: 'PROVIDER_DISABLED',
|
|
VOXCPM_AUTO_VOICE_REQUIRES_CONTEXT: 'VOXCPM_AUTO_VOICE_REQUIRES_CONTEXT',
|
|
INVALID_URL: 'INVALID_URL',
|
|
REDIRECT_NOT_ALLOWED: 'REDIRECT_NOT_ALLOWED',
|
|
TOO_MANY_REDIRECTS: 'TOO_MANY_REDIRECTS',
|
|
CONTENT_SENSITIVE: 'CONTENT_SENSITIVE',
|
|
UPSTREAM_ERROR: 'UPSTREAM_ERROR',
|
|
RATE_LIMITED: 'RATE_LIMITED',
|
|
QWEN_VC_CONFIG_MISSING: 'QWEN_VC_CONFIG_MISSING',
|
|
QWEN_VC_ENDPOINT_INVALID: 'QWEN_VC_ENDPOINT_INVALID',
|
|
QWEN_VC_HTTP_ERROR: 'QWEN_VC_HTTP_ERROR',
|
|
QWEN_VC_TIMEOUT: 'QWEN_VC_TIMEOUT',
|
|
QWEN_VC_TRANSPORT_ERROR: 'QWEN_VC_TRANSPORT_ERROR',
|
|
QWEN_VC_RESPONSE_JSON_INVALID: 'QWEN_VC_RESPONSE_JSON_INVALID',
|
|
QWEN_VC_RESPONSE_VOICE_MISSING: 'QWEN_VC_RESPONSE_VOICE_MISSING',
|
|
QWEN_VC_RESPONSE_AUDIO_URL_MISSING: 'QWEN_VC_RESPONSE_AUDIO_URL_MISSING',
|
|
QWEN_VC_AUDIO_URL_INVALID: 'QWEN_VC_AUDIO_URL_INVALID',
|
|
QWEN_VC_AUDIO_DOWNLOAD_FAILED: 'QWEN_VC_AUDIO_DOWNLOAD_FAILED',
|
|
QWEN_VC_AUDIO_TOO_LARGE: 'QWEN_VC_AUDIO_TOO_LARGE',
|
|
QWEN_VC_AUDIO_EMPTY: 'QWEN_VC_AUDIO_EMPTY',
|
|
QWEN_VC_VOICE_NOT_FOUND: 'QWEN_VC_VOICE_NOT_FOUND',
|
|
QWEN_VC_BOOTSTRAP_UNSUPPORTED: 'QWEN_VC_BOOTSTRAP_UNSUPPORTED',
|
|
QWEN_VC_REFERENCE_AUDIO_INVALID: 'QWEN_VC_REFERENCE_AUDIO_INVALID',
|
|
QWEN_TTS_ERROR: 'QWEN_TTS_ERROR',
|
|
GENERATION_FAILED: 'GENERATION_FAILED',
|
|
TRANSCRIPTION_FAILED: 'TRANSCRIPTION_FAILED',
|
|
PARSE_FAILED: 'PARSE_FAILED',
|
|
INTERNAL_ERROR: 'INTERNAL_ERROR',
|
|
} as const;
|
|
|
|
export type ApiErrorCode = (typeof API_ERROR_CODES)[keyof typeof API_ERROR_CODES];
|
|
|
|
export interface ApiErrorBody {
|
|
success: false;
|
|
errorCode: ApiErrorCode;
|
|
error: string;
|
|
details?: string;
|
|
}
|
|
|
|
export function apiError(
|
|
code: ApiErrorCode,
|
|
status: number,
|
|
error: string,
|
|
details?: string,
|
|
): NextResponse<ApiErrorBody> {
|
|
return NextResponse.json(
|
|
{
|
|
success: false as const,
|
|
errorCode: code,
|
|
error,
|
|
...(details ? { details } : {}),
|
|
},
|
|
{ status },
|
|
);
|
|
}
|
|
|
|
export function apiSuccess<T extends Record<string, unknown>>(data: T, status = 200): NextResponse {
|
|
return NextResponse.json({ success: true, ...data }, { status });
|
|
}
|