fix: restore production model availability helpers
This commit is contained in:
parent
3ad353b97f
commit
6180c5fc49
19
lib/ai/model-visibility.ts
Normal file
19
lib/ai/model-visibility.ts
Normal file
@ -0,0 +1,19 @@
|
||||
export type HiddenModelAccessInput = {
|
||||
sessionUserType?: string | null;
|
||||
databaseUserRole?: string | null;
|
||||
isHighVip?: boolean | null;
|
||||
};
|
||||
|
||||
const HIDDEN_MODEL_ADMIN_ROLES = new Set(["admin", "agent_admin"]);
|
||||
|
||||
export function canAccessHiddenAiModels({
|
||||
sessionUserType,
|
||||
databaseUserRole,
|
||||
isHighVip,
|
||||
}: HiddenModelAccessInput) {
|
||||
return (
|
||||
isHighVip === true ||
|
||||
HIDDEN_MODEL_ADMIN_ROLES.has(String(databaseUserRole || "").trim()) ||
|
||||
HIDDEN_MODEL_ADMIN_ROLES.has(String(sessionUserType || "").trim())
|
||||
);
|
||||
}
|
||||
51
lib/style-pro/model-availability.ts
Normal file
51
lib/style-pro/model-availability.ts
Normal file
@ -0,0 +1,51 @@
|
||||
import type { AiModel, AiProvider } from "@/lib/db/schema";
|
||||
import {
|
||||
getAiModelFrontendAvailability,
|
||||
type ModelFrontendAvailability,
|
||||
} from "@/lib/ai/model-frontend-availability";
|
||||
import { modelSupportsReferenceImageInput } from "@/lib/ai/reference-image-capability";
|
||||
|
||||
type StyleProAvailabilityEntry = {
|
||||
model: Pick<
|
||||
AiModel,
|
||||
| "displayName"
|
||||
| "modelId"
|
||||
| "supportsVision"
|
||||
| "capabilities"
|
||||
| "defaultParams"
|
||||
| "isEnabled"
|
||||
| "healthStatus"
|
||||
| "healthAutoDisabledAt"
|
||||
| "healthObservationStartedAt"
|
||||
>;
|
||||
provider: Pick<AiProvider, "type">;
|
||||
};
|
||||
|
||||
export function getStyleProModelAvailability(
|
||||
entry: StyleProAvailabilityEntry
|
||||
): ModelFrontendAvailability {
|
||||
if (!modelSupportsReferenceImageInput(entry.model, entry.provider)) {
|
||||
return {
|
||||
availabilityStatus: "maintenance",
|
||||
availabilityLabel: "仅文生图",
|
||||
selectable: false,
|
||||
disabledReason: "风格化需要参考图,该模型仅支持文生图",
|
||||
};
|
||||
}
|
||||
|
||||
const availability = getAiModelFrontendAvailability(entry.model);
|
||||
if (availability.availabilityStatus === "testing") {
|
||||
return {
|
||||
availabilityStatus: "testing",
|
||||
availabilityLabel: "暂不可用",
|
||||
selectable: false,
|
||||
disabledReason: "模型近期生成异常,恢复健康后会自动开放",
|
||||
};
|
||||
}
|
||||
|
||||
return availability;
|
||||
}
|
||||
|
||||
export function isStyleProModelRunnable(entry: StyleProAvailabilityEntry) {
|
||||
return getStyleProModelAvailability(entry).selectable;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user