fix: keep worldlabs provider enabled on runtime errors
This commit is contained in:
parent
6674c22cdd
commit
1598722ad0
@ -14,9 +14,9 @@ import { createLogger } from "@/lib/observability/logger";
|
||||
import { get3DWorldCreditCost } from "@/lib/points/config";
|
||||
import { WorldLabsApiError, worldLabsRequest } from "@/lib/worldlabs/client";
|
||||
import {
|
||||
disableWorldLabsProvider,
|
||||
getWorldLabsProviderConfig,
|
||||
getWorldLabsProviderConfigs,
|
||||
reportWorldLabsProviderRuntimeFailure,
|
||||
} from "@/lib/worldlabs/server";
|
||||
import type { WorldLabsModel, WorldLabsOperation } from "@/lib/worldlabs/types";
|
||||
|
||||
@ -142,7 +142,7 @@ function buildWorldPrompt(body: CreateWorldTaskRequest, mode: WorldTaskMode) {
|
||||
};
|
||||
}
|
||||
|
||||
function isPermanentProviderError(error: unknown) {
|
||||
function isCredentialOrBillingProviderError(error: unknown) {
|
||||
return (
|
||||
error instanceof WorldLabsApiError &&
|
||||
[401, 402, 403].includes(error.httpStatus)
|
||||
@ -250,8 +250,8 @@ export async function POST(request: Request) {
|
||||
break;
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
if (isPermanentProviderError(error)) {
|
||||
await disableWorldLabsProvider(
|
||||
if (isCredentialOrBillingProviderError(error)) {
|
||||
await reportWorldLabsProviderRuntimeFailure(
|
||||
candidate.providerId,
|
||||
error instanceof Error ? error.message : String(error)
|
||||
);
|
||||
|
||||
@ -3,9 +3,9 @@ import { auth } from "@/app/(auth)/auth";
|
||||
import { createLogger } from "@/lib/observability/logger";
|
||||
import { WorldLabsApiError, worldLabsRequest } from "@/lib/worldlabs/client";
|
||||
import {
|
||||
disableWorldLabsProvider,
|
||||
getWorldLabsProviderConfig,
|
||||
getWorldLabsProviderConfigs,
|
||||
reportWorldLabsProviderRuntimeFailure,
|
||||
} from "@/lib/worldlabs/server";
|
||||
import type { WorldLabsPrepareUploadResponse } from "@/lib/worldlabs/types";
|
||||
|
||||
@ -112,7 +112,7 @@ function normalizeMediaAssetId(data: WorldLabsPrepareUploadResponse) {
|
||||
return String(data.media_asset?.media_asset_id || data.media_asset?.id || "").trim();
|
||||
}
|
||||
|
||||
function isPermanentProviderError(error: unknown) {
|
||||
function isCredentialOrBillingProviderError(error: unknown) {
|
||||
return (
|
||||
error instanceof WorldLabsApiError &&
|
||||
[401, 402, 403].includes(error.httpStatus)
|
||||
@ -252,8 +252,11 @@ export async function POST(request: Request) {
|
||||
});
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
if (isPermanentProviderError(error)) {
|
||||
await disableWorldLabsProvider(config.providerId, (error as Error).message);
|
||||
if (isCredentialOrBillingProviderError(error)) {
|
||||
await reportWorldLabsProviderRuntimeFailure(
|
||||
config.providerId,
|
||||
error instanceof Error ? error.message : String(error)
|
||||
);
|
||||
}
|
||||
if (requestedProviderId) {
|
||||
break;
|
||||
|
||||
@ -3,7 +3,6 @@ import "server-only";
|
||||
import {
|
||||
getAiProviderById,
|
||||
getAiProvidersByType,
|
||||
updateAiProvider,
|
||||
} from "@/lib/db/queries";
|
||||
import type { WorldLabsProviderConfig } from "./types";
|
||||
|
||||
@ -110,28 +109,15 @@ export async function getWorldLabsProviderConfig(
|
||||
throw new Error("未配置 World Labs API,请在系统设置-本地AI新增 World Labs 提供商");
|
||||
}
|
||||
|
||||
export async function disableWorldLabsProvider(
|
||||
export async function reportWorldLabsProviderRuntimeFailure(
|
||||
providerId?: string | null,
|
||||
reason?: string
|
||||
) {
|
||||
const normalizedProviderId = String(providerId || "").trim();
|
||||
if (!normalizedProviderId) return;
|
||||
|
||||
try {
|
||||
await updateAiProvider({
|
||||
id: normalizedProviderId,
|
||||
isEnabled: false,
|
||||
});
|
||||
console.warn(
|
||||
`[WorldLabsPool] Disabled provider ${normalizedProviderId}${
|
||||
reason ? `: ${reason}` : ""
|
||||
}`
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("[WorldLabsPool] Failed to disable provider:", {
|
||||
providerId: normalizedProviderId,
|
||||
reason,
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
});
|
||||
}
|
||||
console.warn("[WorldLabsPool] Provider reported a runtime failure; keeping enabled", {
|
||||
providerId: normalizedProviderId,
|
||||
reason,
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user