manifest
Version:
Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard
51 lines • 2.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isQwenResolvedRegion = isQwenResolvedRegion;
exports.isQwenRegion = isQwenRegion;
exports.getQwenCompatibleBaseUrl = getQwenCompatibleBaseUrl;
exports.normalizeQwenCompatibleBaseUrl = normalizeQwenCompatibleBaseUrl;
exports.detectQwenRegion = detectQwenRegion;
const provider_base_url_1 = require("./provider-base-url");
const QWEN_REGION_BASE_URLS = {
singapore: 'https://dashscope-intl.aliyuncs.com/compatible-mode',
us: 'https://dashscope-us.aliyuncs.com/compatible-mode',
beijing: 'https://dashscope.aliyuncs.com/compatible-mode',
};
const QWEN_ALLOWED_BASE_URLS = new Set(Object.values(QWEN_REGION_BASE_URLS));
const QWEN_REGION_DETECTION_ORDER = ['singapore', 'us', 'beijing'];
const QWEN_DETECTION_TIMEOUT_MS = 3000;
function buildModelsUrl(region) {
return `${QWEN_REGION_BASE_URLS[region]}/v1/models`;
}
function isQwenResolvedRegion(value) {
return value === 'singapore' || value === 'us' || value === 'beijing';
}
function isQwenRegion(value) {
return value === 'auto' || isQwenResolvedRegion(value);
}
function getQwenCompatibleBaseUrl(region) {
if (isQwenResolvedRegion(region))
return QWEN_REGION_BASE_URLS[region];
return QWEN_REGION_BASE_URLS.beijing;
}
function normalizeQwenCompatibleBaseUrl(baseUrl) {
const normalized = (0, provider_base_url_1.normalizeProviderBaseUrl)(baseUrl);
return QWEN_ALLOWED_BASE_URLS.has(normalized) ? normalized : null;
}
async function detectQwenRegion(apiKey, fetchImpl = fetch) {
const headers = { Authorization: `Bearer ${apiKey}` };
for (const region of QWEN_REGION_DETECTION_ORDER) {
try {
const response = await fetchImpl(buildModelsUrl(region), {
headers,
signal: AbortSignal.timeout(QWEN_DETECTION_TIMEOUT_MS),
});
if (response.ok)
return region;
}
catch {
}
}
return null;
}
//# sourceMappingURL=qwen-region.js.map