refactor(open-sse): B1 consolidate media endpoint URLs into registry

- image/embed/tts/search base URLs derive from media.*Config.baseUrl /
  searchViaChat.endpoint (single source); handlers read PROVIDER_MEDIA.
- ~18 hardcoded endpoints moved: bfl/fal/stability/runway/hf/gemini/
  cloudflare/recraft/sdwebui/comfyui/nanobanana image, voyage embed,
  gemini/openrouter tts, chatSearch endpoints.
- Byte-identical: PROVIDERS 62 + alias 90 baselines, image buildUrl outputs.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
decolua
2026-06-14 13:58:12 +07:00
parent bb9e9aa91f
commit e53ce79abb
32 changed files with 96 additions and 38 deletions

View File

@@ -4,8 +4,10 @@
*/
import { PROVIDER_MEDIA } from "../../providers/index.js";
// Default search model derives from registry searchViaChat (single source)
// Default search model + endpoint derive from registry searchViaChat (single source)
const searchModel = (id) => PROVIDER_MEDIA[id]?.searchViaChat?.defaultModel;
const searchEndpoint = (id, model) =>
(PROVIDER_MEDIA[id]?.searchViaChat?.endpoint || "").replace("{model}", model || "");
const REQUEST_TIMEOUT_MS = 15000;
const DEFAULT_MAX_RESULTS = 10;
@@ -47,8 +49,7 @@ function normalizeCitation(c) {
*/
const CHAT_SEARCH_CONFIG = {
gemini: {
endpoint: (model) =>
`https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent`,
endpoint: (model) => searchEndpoint("gemini", model),
buildBody: (query) => ({
contents: [{ role: "user", parts: [{ text: query }] }],
tools: [{ google_search: {} }]
@@ -73,7 +74,7 @@ const CHAT_SEARCH_CONFIG = {
},
openai: {
endpoint: () => "https://api.openai.com/v1/chat/completions",
endpoint: () => searchEndpoint("openai"),
buildBody: (query, model) => {
const body = {
model,
@@ -107,7 +108,7 @@ const CHAT_SEARCH_CONFIG = {
},
xai: {
endpoint: () => "https://api.x.ai/v1/responses",
endpoint: () => searchEndpoint("xai"),
buildBody: (query, model) => ({
model,
input: [{ role: "user", content: query }],
@@ -146,7 +147,7 @@ const CHAT_SEARCH_CONFIG = {
},
kimi: {
endpoint: () => "https://api.moonshot.cn/v1/chat/completions",
endpoint: () => searchEndpoint("kimi"),
buildBody: (query, model) => ({
model,
messages: [{ role: "user", content: query }],
@@ -195,7 +196,7 @@ const CHAT_SEARCH_CONFIG = {
},
minimax: {
endpoint: () => "https://api.minimaxi.com/v1/text/chatcompletion_v2",
endpoint: () => searchEndpoint("minimax"),
buildBody: (query, model) => ({
model,
messages: [{ role: "user", content: query }],
@@ -253,7 +254,7 @@ const CHAT_SEARCH_CONFIG = {
},
perplexity: {
endpoint: () => "https://api.perplexity.ai/chat/completions",
endpoint: () => searchEndpoint("perplexity"),
buildBody: (query, model) => ({
model,
messages: [{ role: "user", content: query }]