fix(world): guard unsupported modes for external world task provider
This commit is contained in:
parent
15c3b519a7
commit
a9a9f8e138
@ -145,6 +145,26 @@ function shouldUseExternalTaskCreateApi(
|
|||||||
return isWorldLabsExternalTaskApi(config.baseUrl) && mode === "text";
|
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) {
|
function resolveOfficialMarbleModel(model?: string | null) {
|
||||||
const normalized = readOptionalTrimmedText(model);
|
const normalized = readOptionalTrimmedText(model);
|
||||||
if (!normalized || normalized === WORLDLABS_EXTERNAL_TASK_MODEL) {
|
if (!normalized || normalized === WORLDLABS_EXTERNAL_TASK_MODEL) {
|
||||||
@ -356,6 +376,7 @@ export async function POST(request: Request) {
|
|||||||
for (const candidate of candidates) {
|
for (const candidate of candidates) {
|
||||||
try {
|
try {
|
||||||
const useExternalTaskApi = shouldUseExternalTaskCreateApi(candidate, mode);
|
const useExternalTaskApi = shouldUseExternalTaskCreateApi(candidate, mode);
|
||||||
|
assertWorldModeSupportedByCandidate(candidate, mode);
|
||||||
if (useExternalTaskApi) {
|
if (useExternalTaskApi) {
|
||||||
const prompt = readOptionalTrimmedText(body.prompt);
|
const prompt = readOptionalTrimmedText(body.prompt);
|
||||||
if (!prompt) {
|
if (!prompt) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user