fix(world): guard unsupported modes for external world task provider

This commit is contained in:
134 2026-08-19 12:34:13 +08:00
parent 15c3b519a7
commit a9a9f8e138

View File

@ -145,6 +145,26 @@ function shouldUseExternalTaskCreateApi(
return isWorldLabsExternalTaskApi(config.baseUrl) && mode === "text";
}
function isWorldLabsModeUnsupportedByExternalProvider(
config: Awaited<ReturnType<typeof getWorldLabsProviderConfig>>,
mode: WorldTaskMode
) {
return isWorldLabsExternalTaskApi(config.baseUrl) && mode !== "text";
}
function assertWorldModeSupportedByCandidate(
config: Awaited<ReturnType<typeof getWorldLabsProviderConfig>>,
mode: WorldTaskMode,
) {
if (isWorldLabsModeUnsupportedByExternalProvider(config, mode)) {
const normalizedBaseUrl = String(config.baseUrl || "").trim() || "未知服务地址";
const normalizedMode = String(mode || "").trim() || "未知模式";
throw new Error(
`${normalizedBaseUrl} 的 world-generation 当前仅支持文生世界(text)。当前提交的是 ${normalizedMode},请先切换供应商或使用文生世界。`
);
}
}
function resolveOfficialMarbleModel(model?: string | null) {
const normalized = readOptionalTrimmedText(model);
if (!normalized || normalized === WORLDLABS_EXTERNAL_TASK_MODEL) {
@ -356,6 +376,7 @@ export async function POST(request: Request) {
for (const candidate of candidates) {
try {
const useExternalTaskApi = shouldUseExternalTaskCreateApi(candidate, mode);
assertWorldModeSupportedByCandidate(candidate, mode);
if (useExternalTaskApi) {
const prompt = readOptionalTrimmedText(body.prompt);
if (!prompt) {