2026-01-04 21:58:59 -05:00
|
|
|
// Re-export from open-sse with localDb integration
|
2026-02-02 07:45:12 -05:00
|
|
|
import { getModelAliases, getComboByName, getProviderNodes } from "@/lib/localDb";
|
2026-01-04 21:58:59 -05:00
|
|
|
import { parseModel, resolveModelAliasFromMap, getModelInfoCore } from "open-sse/services/model.js";
|
|
|
|
|
|
|
|
|
|
export { parseModel };
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolve model alias from localDb
|
|
|
|
|
*/
|
|
|
|
|
export async function resolveModelAlias(alias) {
|
|
|
|
|
const aliases = await getModelAliases();
|
|
|
|
|
return resolveModelAliasFromMap(alias, aliases);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get full model info (parse or resolve)
|
|
|
|
|
*/
|
|
|
|
|
export async function getModelInfo(modelStr) {
|
2026-02-02 07:45:12 -05:00
|
|
|
const parsed = parseModel(modelStr);
|
|
|
|
|
|
|
|
|
|
if (!parsed.isAlias) {
|
|
|
|
|
if (parsed.provider === parsed.providerAlias) {
|
2026-02-03 03:11:41 -05:00
|
|
|
// Check OpenAI Compatible nodes
|
|
|
|
|
const openaiNodes = await getProviderNodes({ type: "openai-compatible" });
|
|
|
|
|
const matchedOpenAI = openaiNodes.find((node) => node.prefix === parsed.providerAlias);
|
|
|
|
|
if (matchedOpenAI) {
|
|
|
|
|
return { provider: matchedOpenAI.id, model: parsed.model };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check Anthropic Compatible nodes
|
|
|
|
|
const anthropicNodes = await getProviderNodes({ type: "anthropic-compatible" });
|
|
|
|
|
const matchedAnthropic = anthropicNodes.find((node) => node.prefix === parsed.providerAlias);
|
|
|
|
|
if (matchedAnthropic) {
|
|
|
|
|
return { provider: matchedAnthropic.id, model: parsed.model };
|
2026-02-02 07:45:12 -05:00
|
|
|
}
|
2026-04-25 05:22:30 -04:00
|
|
|
|
|
|
|
|
// Check Custom Embedding nodes
|
|
|
|
|
const embeddingNodes = await getProviderNodes({ type: "custom-embedding" });
|
|
|
|
|
const matchedEmbedding = embeddingNodes.find((node) => node.prefix === parsed.providerAlias);
|
|
|
|
|
if (matchedEmbedding) {
|
|
|
|
|
return { provider: matchedEmbedding.id, model: parsed.model };
|
|
|
|
|
}
|
2026-02-02 07:45:12 -05:00
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
provider: parsed.provider,
|
|
|
|
|
model: parsed.model
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-24 23:40:50 -05:00
|
|
|
// Check if this is a combo name before resolving as alias
|
|
|
|
|
// This prevents combo names from being incorrectly routed to providers
|
|
|
|
|
const combo = await getComboByName(parsed.model);
|
|
|
|
|
if (combo) {
|
|
|
|
|
// Return null provider to signal this should be handled as combo
|
|
|
|
|
// The caller (handleChat) will detect this and handle it as combo
|
|
|
|
|
return { provider: null, model: parsed.model };
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-04 21:58:59 -05:00
|
|
|
return getModelInfoCore(modelStr, getModelAliases);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if model is a combo and get models list
|
|
|
|
|
* @returns {Promise<string[]|null>} Array of models or null if not a combo
|
|
|
|
|
*/
|
|
|
|
|
export async function getComboModels(modelStr) {
|
|
|
|
|
// Only check if it's not in provider/model format
|
|
|
|
|
if (modelStr.includes("/")) return null;
|
2026-02-24 23:40:50 -05:00
|
|
|
|
2026-01-04 21:58:59 -05:00
|
|
|
const combo = await getComboByName(modelStr);
|
|
|
|
|
if (combo && combo.models && combo.models.length > 0) {
|
|
|
|
|
return combo.models;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|