Files
homarr/packages/definitions/src/assistant.ts
T
+12 fcd7c979df feat!: release v2 (#6545)
Co-authored-by: Artur <145776561+arturict@users.noreply.github.com>
Co-authored-by: arturict <arturict@users.noreply.github.com>
Co-authored-by: Thomas <thomas@ajnart.fr>
Co-authored-by: Afonso Jorge Ramos <afonsojorgeramos@gmail.com>
Co-authored-by: Danura30082 <danura30082+github@gmail.com>
Co-authored-by: Kushie <122986913+kushiemoon-dev@users.noreply.github.com>
Co-authored-by: ajnart <thomas@ajnart.fr>
Co-authored-by: ajnart <thomas@ajnart.dev>
Co-authored-by: chenjun <chenjun@foxmail.com>
Co-authored-by: Wikibear <wikibear@users.noreply.github.com>
Co-authored-by: Bergasha <bergasha@gmail.com>
Co-authored-by: leafyelin <43306196+leafyelin@users.noreply.github.com>
Co-authored-by: Lucas Araujo <lucas.lra@gmail.com>
Co-authored-by: GreenMonito <86085570+GreenMonito@users.noreply.github.com>
Co-authored-by: Nerdy-Technician <roffo@nerdy-technician.social>
Co-authored-by: Jun <34545896+jcstrong@users.noreply.github.com>
Co-authored-by: Edmond Abraham <54119952+gitedmond@users.noreply.github.com>
Co-authored-by: thrawnx <tight.bulb9384@fastmail.com>
Co-authored-by: Chris <58918656+nordada@users.noreply.github.com>
Co-authored-by: yi111 <153097222+Yi-111-a@users.noreply.github.com>
Co-authored-by: Yanis <naamaneyanis@gmail.com>
Co-authored-by: Wikibear <me@sej.de>
Co-authored-by: alessiottavo <93441886+alessiottavo@users.noreply.github.com>
2026-10-02 21:00:14 +02:00

189 lines
5.7 KiB
TypeScript

export const assistantProviderIds = [
"homarr",
"openrouter",
"openai",
"anthropic",
"google-gemini",
"xai",
"groq",
"mistral",
"deepseek",
"together",
"ollama",
"lm-studio",
"llama-cpp",
"custom",
] as const;
export type AssistantProvider = (typeof assistantProviderIds)[number];
export type AssistantProviderCategory = "free" | "hosted" | "local" | "custom";
export const assistantHomarrProviderTokenHeader = "X-Homarr-Provider-Token";
export const assistantReasoningModes = ["auto", "none", "minimal", "low", "medium", "high"] as const;
export type AssistantReasoningMode = (typeof assistantReasoningModes)[number];
export interface AssistantModelOption {
id: string;
name: string;
}
export const getAssistantModelOptionLabel = (model: AssistantModelOption) =>
model.name === model.id ? model.id : `${model.name} (${model.id})`;
export const resolveAssistantModelId = (models: AssistantModelOption[], value: string) =>
models.find((model) => model.id === value || getAssistantModelOptionLabel(model) === value)?.id ?? null;
const providerIconBaseUrl = "https://cdn.jsdelivr.net/npm/@lobehub/icons-static-svg@latest/icons";
interface AssistantProviderPreset {
label?: string;
baseUrl: string;
modelDiscoveryPath: string | null;
requiresApiKey: boolean;
category: AssistantProviderCategory;
discoveryAuthentication: "bearer" | "anthropic";
iconUrl: string | null;
darkIconUrl?: string;
}
export const assistantProviderPresets = {
homarr: {
label: "Homarr",
// Browser and server code replace this public fallback with WORKSHOP_API_URL at runtime.
baseUrl: "https://homarr.dev/api/ai/v1",
modelDiscoveryPath: "/models",
requiresApiKey: false,
category: "free",
discoveryAuthentication: "bearer",
iconUrl: "https://homarr.dev/img/logo.png",
},
openrouter: {
label: "OpenRouter",
baseUrl: "https://openrouter.ai/api/v1",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/openrouter-color.svg`,
},
openai: {
label: "OpenAI",
baseUrl: "https://api.openai.com/v1",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/openai.svg`,
},
anthropic: {
label: "Anthropic Claude",
baseUrl: "https://api.anthropic.com/v1",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "anthropic",
iconUrl: `${providerIconBaseUrl}/anthropic.svg`,
},
"google-gemini": {
label: "Google Gemini",
baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/gemini-color.svg`,
},
xai: {
label: "xAI",
baseUrl: "https://api.x.ai/v1",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/xai.svg`,
},
groq: {
label: "Groq",
baseUrl: "https://api.groq.com/openai/v1",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/groq.svg`,
darkIconUrl: "https://cdn.jsdelivr.net/npm/@lobehub/icons-static-png@latest/dark/groq.png",
},
mistral: {
label: "Mistral AI",
baseUrl: "https://api.mistral.ai/v1",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/mistral-color.svg`,
},
deepseek: {
label: "DeepSeek",
baseUrl: "https://api.deepseek.com",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/deepseek-color.svg`,
},
together: {
label: "Together AI",
baseUrl: "https://api.together.xyz/v1",
modelDiscoveryPath: "/models",
requiresApiKey: true,
category: "hosted",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/together-color.svg`,
},
ollama: {
label: "Ollama",
baseUrl: "http://localhost:11434/v1",
modelDiscoveryPath: "/models",
requiresApiKey: false,
category: "local",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/ollama.svg`,
},
"lm-studio": {
label: "LM Studio",
baseUrl: "http://localhost:1234/v1",
modelDiscoveryPath: "/models",
requiresApiKey: false,
category: "local",
discoveryAuthentication: "bearer",
iconUrl: `${providerIconBaseUrl}/lmstudio.svg`,
},
"llama-cpp": {
label: "llama.cpp",
baseUrl: "http://localhost:8080/v1",
modelDiscoveryPath: "/models",
requiresApiKey: false,
category: "local",
discoveryAuthentication: "bearer",
iconUrl: "https://cdn.jsdelivr.net/gh/selfhst/icons/svg/llama-cpp.svg",
},
custom: {
label: undefined,
baseUrl: "",
modelDiscoveryPath: "/models",
requiresApiKey: false,
category: "custom",
discoveryAuthentication: "bearer",
iconUrl: null,
},
} as const satisfies Record<AssistantProvider, AssistantProviderPreset>;
export const assistantProviderRequiresApiKey = (provider: AssistantProvider) =>
assistantProviderPresets[provider].requiresApiKey;
/**
* OpenRouter and Homarr Router implement OpenRouter server tools directly.
* Custom endpoints may opt in when they proxy the OpenRouter request format.
*/
export const assistantProviderCanUseOpenRouterServerTools = (provider: AssistantProvider) =>
provider === "openrouter" || provider === "homarr" || provider === "custom";