UNPKG

manifest

Version:

Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard

182 lines 6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PROVIDER_ENDPOINTS = void 0; exports.buildCustomEndpoint = buildCustomEndpoint; exports.buildEndpointOverride = buildEndpointOverride; exports.resolveEndpointKey = resolveEndpointKey; const ollama_1 = require("../../common/constants/ollama"); const providers_1 = require("../../common/constants/providers"); const provider_base_url_1 = require("../provider-base-url"); const qwen_region_1 = require("../qwen-region"); const openaiHeaders = (apiKey) => ({ Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json', }); const openaiPath = () => '/v1/chat/completions'; const anthropicHeaders = (apiKey, authType) => { const headers = { 'Content-Type': 'application/json', 'anthropic-version': '2023-06-01', }; if (authType === 'subscription') { headers['Authorization'] = `Bearer ${apiKey}`; headers['anthropic-beta'] = 'oauth-2025-04-20'; } else { headers['x-api-key'] = apiKey; } return headers; }; const anthropicBearerHeaders = (apiKey) => ({ Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json', 'anthropic-version': '2023-06-01', }); const CHATGPT_SUBSCRIPTION_BASE = 'https://chatgpt.com/backend-api'; const MINIMAX_SUBSCRIPTION_BASE = 'https://api.minimax.io/anthropic'; const chatgptSubscriptionHeaders = (apiKey) => ({ Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json', originator: 'codex_cli_rs', 'user-agent': 'codex_cli_rs/0.0.0 (Unknown 0; unknown) unknown', }); exports.PROVIDER_ENDPOINTS = { openai: { baseUrl: 'https://api.openai.com', buildHeaders: openaiHeaders, buildPath: openaiPath, format: 'openai', }, 'openai-subscription': { baseUrl: CHATGPT_SUBSCRIPTION_BASE, buildHeaders: chatgptSubscriptionHeaders, buildPath: () => '/codex/responses', format: 'chatgpt', }, anthropic: { baseUrl: 'https://api.anthropic.com', buildHeaders: anthropicHeaders, buildPath: () => '/v1/messages', format: 'anthropic', }, deepseek: { baseUrl: 'https://api.deepseek.com', buildHeaders: openaiHeaders, buildPath: openaiPath, format: 'openai', }, mistral: { baseUrl: 'https://api.mistral.ai', buildHeaders: openaiHeaders, buildPath: openaiPath, format: 'openai', }, xai: { baseUrl: 'https://api.x.ai', buildHeaders: openaiHeaders, buildPath: openaiPath, format: 'openai', }, minimax: { baseUrl: 'https://api.minimax.io', buildHeaders: openaiHeaders, buildPath: openaiPath, format: 'openai', }, 'minimax-subscription': { baseUrl: MINIMAX_SUBSCRIPTION_BASE, buildHeaders: anthropicBearerHeaders, buildPath: () => '/v1/messages', format: 'anthropic', }, moonshot: { baseUrl: 'https://api.moonshot.ai', buildHeaders: openaiHeaders, buildPath: openaiPath, format: 'openai', }, qwen: { baseUrl: (0, qwen_region_1.getQwenCompatibleBaseUrl)('beijing'), buildHeaders: openaiHeaders, buildPath: openaiPath, format: 'openai', }, zai: { baseUrl: 'https://api.z.ai', buildHeaders: openaiHeaders, buildPath: () => '/api/paas/v4/chat/completions', format: 'openai', }, google: { baseUrl: 'https://generativelanguage.googleapis.com', buildHeaders: () => ({ 'Content-Type': 'application/json' }), buildPath: (model) => `/v1beta/models/${model}:generateContent`, format: 'google', }, copilot: { baseUrl: 'https://api.githubcopilot.com', buildHeaders: (apiKey) => ({ Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json', 'Editor-Version': 'vscode/1.100.0', 'Editor-Plugin-Version': 'copilot/1.300.0', 'Copilot-Integration-Id': 'vscode-chat', }), buildPath: () => '/chat/completions', format: 'openai', }, openrouter: { baseUrl: 'https://openrouter.ai', buildHeaders: (apiKey) => ({ Authorization: `Bearer ${apiKey}`, 'Content-Type': 'application/json', 'HTTP-Referer': 'https://manifest.build', 'X-Title': 'Manifest', }), buildPath: () => '/api/v1/chat/completions', format: 'openai', }, ollama: { baseUrl: ollama_1.OLLAMA_HOST, buildHeaders: () => ({ 'Content-Type': 'application/json' }), buildPath: openaiPath, format: 'openai', }, }; function buildCustomEndpoint(baseUrl) { const normalized = (0, provider_base_url_1.normalizeProviderBaseUrl)(baseUrl); return { baseUrl: normalized, buildHeaders: openaiHeaders, buildPath: openaiPath, format: 'openai', }; } function buildEndpointOverride(baseUrl, templateKey) { const template = exports.PROVIDER_ENDPOINTS[templateKey]; if (!template) { throw new Error(`No provider endpoint template configured for: ${templateKey}`); } return { ...template, baseUrl: (0, provider_base_url_1.normalizeProviderBaseUrl)(baseUrl), }; } function resolveEndpointKey(provider) { const lower = provider.toLowerCase(); if (exports.PROVIDER_ENDPOINTS[lower]) return lower; if (lower.startsWith('custom:')) return lower; const entry = providers_1.PROVIDER_BY_ID_OR_ALIAS.get(lower); if (entry) { if (exports.PROVIDER_ENDPOINTS[entry.id]) return entry.id; for (const alias of entry.aliases) { if (exports.PROVIDER_ENDPOINTS[alias]) return alias; } } return null; } //# sourceMappingURL=provider-endpoints.js.map