Your Name d76b31952f
Some checks failed
Lint / build (20) (push) Has been cancelled
Playwright Tests / test (push) Has been cancelled
feat: add world labs 3d workspace mode
2026-04-04 22:06:43 +08:00

51 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import "server-only";
import { getEnabledAiProviders } from "@/lib/db/queries";
import type { WorldLabsProviderConfig } from "./types";
const DEFAULT_WORLDLABS_BASE_URL = "https://api.worldlabs.ai";
function sanitizeWorldLabsApiKey(value: string): string {
return String(value || "")
.replace(/[\u2028\u2029]/g, "")
.replace(/[\u0000-\u001F\u007F]/g, "")
.replace(/\s+/g, "")
.trim();
}
function sanitizeWorldLabsBaseUrl(value: string): string {
return String(value || "")
.replace(/[\u2028\u2029]/g, "")
.replace(/[\u0000-\u001F\u007F]/g, "")
.trim();
}
export async function getWorldLabsProviderConfig(): Promise<WorldLabsProviderConfig> {
const providers = await getEnabledAiProviders();
const worldLabsProvider = providers.find((item) => item.type === "worldlabs-3d");
const providerApiKey = sanitizeWorldLabsApiKey(String(worldLabsProvider?.apiKey || ""));
if (worldLabsProvider && providerApiKey) {
return {
apiKey: providerApiKey,
baseUrl:
sanitizeWorldLabsBaseUrl(String(worldLabsProvider?.baseUrl || "")) ||
DEFAULT_WORLDLABS_BASE_URL,
providerId: worldLabsProvider.id,
providerName: worldLabsProvider.name,
};
}
const envApiKey = sanitizeWorldLabsApiKey(String(process.env.WORLDLABS_API_KEY || ""));
if (!envApiKey) {
throw new Error("未配置 World Labs API,请在系统设置-本地AI新增 World Labs 提供商");
}
return {
apiKey: envApiKey,
baseUrl:
sanitizeWorldLabsBaseUrl(String(process.env.WORLDLABS_BASE_URL || "")) ||
DEFAULT_WORLDLABS_BASE_URL,
};
}