UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

772 lines (771 loc) 16.6 kB
import { a as normalizeLowercaseStringOrEmpty, c as normalizeOptionalString } from "./string-coerce-mnp54Vah.js"; import { l as asPositiveSafeInteger } from "./number-coercion-CJQ8TR--.js"; import { t as createSubsystemLogger } from "./subsystem-BzXSmsuh.js"; import { y as ssrfPolicyFromHttpBaseUrlAllowedHostname } from "./ssrf-CvPEXMGn.js"; import "./runtime-env-D_2q8-VK.js"; import "./string-coerce-runtime-CEGJWkQ_.js"; import "./ssrf-runtime-BOGN5pUi.js"; import { r as clearLiveCatalogCacheForTests } from "./provider-catalog-shared-DZr41kLr.js"; import { a as getCachedLiveProviderModelRows, t as LiveModelCatalogHttpError } from "./provider-catalog-live-runtime-D65zJRSj.js"; import { t as isChutesModelDiscoveryTestEnvironment } from "./model-discovery-env-BSm2Y41b.js"; //#region extensions/chutes/models.ts /** * Chutes model catalog, static model definitions, and dynamic model discovery. */ const log = createSubsystemLogger("chutes-models"); /** Base URL for Chutes OpenAI-compatible inference. */ const CHUTES_BASE_URL = "https://llm.chutes.ai/v1"; /** Default Chutes model id used for onboarding. */ const CHUTES_DEFAULT_MODEL_ID = "zai-org/GLM-4.7-TEE"; /** Default Chutes model ref used for onboarding. */ const CHUTES_DEFAULT_MODEL_REF = `chutes/${CHUTES_DEFAULT_MODEL_ID}`; const CHUTES_DEFAULT_CONTEXT_WINDOW = 128e3; const CHUTES_DEFAULT_MAX_TOKENS = 4096; /** Bundled fallback Chutes model catalog. */ const CHUTES_MODEL_CATALOG = [ { id: "Qwen/Qwen3-32B", name: "Qwen/Qwen3-32B", reasoning: true, input: ["text"], contextWindow: 40960, maxTokens: 40960, cost: { input: .08, output: .24, cacheRead: 0, cacheWrite: 0 } }, { id: "unsloth/Mistral-Nemo-Instruct-2407", name: "unsloth/Mistral-Nemo-Instruct-2407", reasoning: false, input: ["text"], contextWindow: 131072, maxTokens: 131072, cost: { input: .02, output: .04, cacheRead: 0, cacheWrite: 0 } }, { id: "deepseek-ai/DeepSeek-V3-0324-TEE", name: "deepseek-ai/DeepSeek-V3-0324-TEE", reasoning: true, input: ["text"], contextWindow: 163840, maxTokens: 65536, cost: { input: .25, output: 1, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3-235B-A22B-Instruct-2507-TEE", name: "Qwen/Qwen3-235B-A22B-Instruct-2507-TEE", reasoning: true, input: ["text"], contextWindow: 262144, maxTokens: 65536, cost: { input: .08, output: .55, cacheRead: 0, cacheWrite: 0 } }, { id: "openai/gpt-oss-120b-TEE", name: "openai/gpt-oss-120b-TEE", reasoning: true, input: ["text"], contextWindow: 131072, maxTokens: 65536, cost: { input: .05, output: .45, cacheRead: 0, cacheWrite: 0 } }, { id: "chutesai/Mistral-Small-3.1-24B-Instruct-2503", name: "chutesai/Mistral-Small-3.1-24B-Instruct-2503", reasoning: false, input: ["text", "image"], contextWindow: 131072, maxTokens: 131072, cost: { input: .03, output: .11, cacheRead: 0, cacheWrite: 0 } }, { id: "deepseek-ai/DeepSeek-V3.2-TEE", name: "deepseek-ai/DeepSeek-V3.2-TEE", reasoning: true, input: ["text"], contextWindow: 131072, maxTokens: 65536, cost: { input: .28, output: .42, cacheRead: 0, cacheWrite: 0 } }, { id: "zai-org/GLM-4.7-TEE", name: "zai-org/GLM-4.7-TEE", reasoning: true, input: ["text"], contextWindow: 202752, maxTokens: 65535, cost: { input: .4, output: 2, cacheRead: 0, cacheWrite: 0 } }, { id: "moonshotai/Kimi-K2.5-TEE", name: "moonshotai/Kimi-K2.5-TEE", reasoning: true, input: ["text", "image"], contextWindow: 262144, maxTokens: 65535, cost: { input: .45, output: 2.2, cacheRead: 0, cacheWrite: 0 } }, { id: "unsloth/gemma-3-27b-it", name: "unsloth/gemma-3-27b-it", reasoning: false, input: ["text", "image"], contextWindow: 128e3, maxTokens: 65536, cost: { input: .04, output: .15, cacheRead: 0, cacheWrite: 0 } }, { id: "XiaomiMiMo/MiMo-V2-Flash-TEE", name: "XiaomiMiMo/MiMo-V2-Flash-TEE", reasoning: true, input: ["text"], contextWindow: 262144, maxTokens: 65536, cost: { input: .09, output: .29, cacheRead: 0, cacheWrite: 0 } }, { id: "chutesai/Mistral-Small-3.2-24B-Instruct-2506", name: "chutesai/Mistral-Small-3.2-24B-Instruct-2506", reasoning: false, input: ["text", "image"], contextWindow: 131072, maxTokens: 131072, cost: { input: .06, output: .18, cacheRead: 0, cacheWrite: 0 } }, { id: "deepseek-ai/DeepSeek-R1-0528-TEE", name: "deepseek-ai/DeepSeek-R1-0528-TEE", reasoning: true, input: ["text"], contextWindow: 163840, maxTokens: 65536, cost: { input: .45, output: 2.15, cacheRead: 0, cacheWrite: 0 } }, { id: "zai-org/GLM-5-TEE", name: "zai-org/GLM-5-TEE", reasoning: true, input: ["text"], contextWindow: 202752, maxTokens: 65535, cost: { input: .95, output: 3.15, cacheRead: 0, cacheWrite: 0 } }, { id: "deepseek-ai/DeepSeek-V3.1-TEE", name: "deepseek-ai/DeepSeek-V3.1-TEE", reasoning: true, input: ["text"], contextWindow: 163840, maxTokens: 65536, cost: { input: .2, output: .8, cacheRead: 0, cacheWrite: 0 } }, { id: "deepseek-ai/DeepSeek-V3.1-Terminus-TEE", name: "deepseek-ai/DeepSeek-V3.1-Terminus-TEE", reasoning: true, input: ["text"], contextWindow: 163840, maxTokens: 65536, cost: { input: .23, output: .9, cacheRead: 0, cacheWrite: 0 } }, { id: "unsloth/gemma-3-4b-it", name: "unsloth/gemma-3-4b-it", reasoning: false, input: ["text", "image"], contextWindow: 96e3, maxTokens: 96e3, cost: { input: .01, output: .03, cacheRead: 0, cacheWrite: 0 } }, { id: "MiniMaxAI/MiniMax-M2.5-TEE", name: "MiniMaxAI/MiniMax-M2.5-TEE", reasoning: true, input: ["text"], contextWindow: 196608, maxTokens: 65536, cost: { input: .3, output: 1.1, cacheRead: 0, cacheWrite: 0 } }, { id: "tngtech/DeepSeek-TNG-R1T2-Chimera", name: "tngtech/DeepSeek-TNG-R1T2-Chimera", reasoning: true, input: ["text"], contextWindow: 163840, maxTokens: 163840, cost: { input: .25, output: .85, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3-Coder-Next-TEE", name: "Qwen/Qwen3-Coder-Next-TEE", reasoning: true, input: ["text"], contextWindow: 262144, maxTokens: 65536, cost: { input: .12, output: .75, cacheRead: 0, cacheWrite: 0 } }, { id: "NousResearch/Hermes-4-405B-FP8-TEE", name: "NousResearch/Hermes-4-405B-FP8-TEE", reasoning: true, input: ["text"], contextWindow: 131072, maxTokens: 65536, cost: { input: .3, output: 1.2, cacheRead: 0, cacheWrite: 0 } }, { id: "deepseek-ai/DeepSeek-V3", name: "deepseek-ai/DeepSeek-V3", reasoning: false, input: ["text"], contextWindow: 163840, maxTokens: 163840, cost: { input: .3, output: 1.2, cacheRead: 0, cacheWrite: 0 } }, { id: "openai/gpt-oss-20b", name: "openai/gpt-oss-20b", reasoning: true, input: ["text"], contextWindow: 131072, maxTokens: 131072, cost: { input: .04, output: .15, cacheRead: 0, cacheWrite: 0 } }, { id: "unsloth/Llama-3.2-3B-Instruct", name: "unsloth/Llama-3.2-3B-Instruct", reasoning: false, input: ["text"], contextWindow: 128e3, maxTokens: 4096, cost: { input: .01, output: .01, cacheRead: 0, cacheWrite: 0 } }, { id: "unsloth/Mistral-Small-24B-Instruct-2501", name: "unsloth/Mistral-Small-24B-Instruct-2501", reasoning: false, input: ["text", "image"], contextWindow: 32768, maxTokens: 32768, cost: { input: .07, output: .3, cacheRead: 0, cacheWrite: 0 } }, { id: "zai-org/GLM-4.7-FP8", name: "zai-org/GLM-4.7-FP8", reasoning: true, input: ["text"], contextWindow: 202752, maxTokens: 65535, cost: { input: .3, output: 1.2, cacheRead: 0, cacheWrite: 0 } }, { id: "zai-org/GLM-4.6-TEE", name: "zai-org/GLM-4.6-TEE", reasoning: true, input: ["text"], contextWindow: 202752, maxTokens: 65536, cost: { input: .4, output: 1.7, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3.5-397B-A17B-TEE", name: "Qwen/Qwen3.5-397B-A17B-TEE", reasoning: true, input: ["text", "image"], contextWindow: 262144, maxTokens: 65536, cost: { input: .55, output: 3.5, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen2.5-72B-Instruct", name: "Qwen/Qwen2.5-72B-Instruct", reasoning: false, input: ["text"], contextWindow: 32768, maxTokens: 32768, cost: { input: .3, output: 1.2, cacheRead: 0, cacheWrite: 0 } }, { id: "NousResearch/DeepHermes-3-Mistral-24B-Preview", name: "NousResearch/DeepHermes-3-Mistral-24B-Preview", reasoning: false, input: ["text"], contextWindow: 32768, maxTokens: 32768, cost: { input: .02, output: .1, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3-Next-80B-A3B-Instruct", name: "Qwen/Qwen3-Next-80B-A3B-Instruct", reasoning: false, input: ["text"], contextWindow: 262144, maxTokens: 262144, cost: { input: .1, output: .8, cacheRead: 0, cacheWrite: 0 } }, { id: "zai-org/GLM-4.6-FP8", name: "zai-org/GLM-4.6-FP8", reasoning: true, input: ["text"], contextWindow: 202752, maxTokens: 65535, cost: { input: .3, output: 1.2, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3-235B-A22B-Thinking-2507", name: "Qwen/Qwen3-235B-A22B-Thinking-2507", reasoning: true, input: ["text"], contextWindow: 262144, maxTokens: 262144, cost: { input: .11, output: .6, cacheRead: 0, cacheWrite: 0 } }, { id: "deepseek-ai/DeepSeek-R1-Distill-Llama-70B", name: "deepseek-ai/DeepSeek-R1-Distill-Llama-70B", reasoning: true, input: ["text"], contextWindow: 131072, maxTokens: 131072, cost: { input: .03, output: .11, cacheRead: 0, cacheWrite: 0 } }, { id: "tngtech/R1T2-Chimera-Speed", name: "tngtech/R1T2-Chimera-Speed", reasoning: true, input: ["text"], contextWindow: 131072, maxTokens: 65536, cost: { input: .22, output: .6, cacheRead: 0, cacheWrite: 0 } }, { id: "zai-org/GLM-4.6V", name: "zai-org/GLM-4.6V", reasoning: true, input: ["text", "image"], contextWindow: 131072, maxTokens: 65536, cost: { input: .3, output: .9, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen2.5-VL-32B-Instruct", name: "Qwen/Qwen2.5-VL-32B-Instruct", reasoning: false, input: ["text", "image"], mediaInput: { image: { maxPixels: 12845056, preferredSidePx: 2048, tokenMode: "provider" } }, contextWindow: 16384, maxTokens: 16384, cost: { input: .05, output: .22, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3-VL-235B-A22B-Instruct", name: "Qwen/Qwen3-VL-235B-A22B-Instruct", reasoning: false, input: ["text", "image"], mediaInput: { image: { maxPixels: 12845056, preferredSidePx: 2048, tokenMode: "provider" } }, contextWindow: 262144, maxTokens: 262144, cost: { input: .3, output: 1.2, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3-14B", name: "Qwen/Qwen3-14B", reasoning: true, input: ["text"], contextWindow: 40960, maxTokens: 40960, cost: { input: .05, output: .22, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen2.5-Coder-32B-Instruct", name: "Qwen/Qwen2.5-Coder-32B-Instruct", reasoning: false, input: ["text"], contextWindow: 32768, maxTokens: 32768, cost: { input: .03, output: .11, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3-30B-A3B", name: "Qwen/Qwen3-30B-A3B", reasoning: true, input: ["text"], contextWindow: 40960, maxTokens: 40960, cost: { input: .06, output: .22, cacheRead: 0, cacheWrite: 0 } }, { id: "unsloth/gemma-3-12b-it", name: "unsloth/gemma-3-12b-it", reasoning: false, input: ["text", "image"], contextWindow: 131072, maxTokens: 131072, cost: { input: .03, output: .1, cacheRead: 0, cacheWrite: 0 } }, { id: "unsloth/Llama-3.2-1B-Instruct", name: "unsloth/Llama-3.2-1B-Instruct", reasoning: false, input: ["text"], contextWindow: 128e3, maxTokens: 4096, cost: { input: .01, output: .01, cacheRead: 0, cacheWrite: 0 } }, { id: "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16-TEE", name: "nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16-TEE", reasoning: true, input: ["text"], contextWindow: 128e3, maxTokens: 4096, cost: { input: .3, output: 1.2, cacheRead: 0, cacheWrite: 0 } }, { id: "NousResearch/Hermes-4-14B", name: "NousResearch/Hermes-4-14B", reasoning: true, input: ["text"], contextWindow: 40960, maxTokens: 40960, cost: { input: .01, output: .05, cacheRead: 0, cacheWrite: 0 } }, { id: "Qwen/Qwen3Guard-Gen-0.6B", name: "Qwen/Qwen3Guard-Gen-0.6B", reasoning: false, input: ["text"], contextWindow: 128e3, maxTokens: 4096, cost: { input: .01, output: .01, cacheRead: 0, cacheWrite: 0 } }, { id: "rednote-hilab/dots.ocr", name: "rednote-hilab/dots.ocr", reasoning: false, input: ["text", "image"], contextWindow: 131072, maxTokens: 131072, cost: { input: .01, output: .01, cacheRead: 0, cacheWrite: 0 } } ]; /** Adds Chutes provider compat metadata to one model catalog entry. */ function buildChutesModelDefinition(model) { return { ...model, compat: { supportsUsageInStreaming: false } }; } const CACHE_TTL = 300 * 1e3; /** Clears the dynamic Chutes model discovery cache for tests. */ function clearChutesModelCacheForTests() { clearLiveCatalogCacheForTests(); } async function fetchChutesModelRows(accessToken) { return await getCachedLiveProviderModelRows({ providerId: "chutes", endpoint: `${CHUTES_BASE_URL}/models`, discoveryApiKey: accessToken, timeoutMs: 1e4, ttlMs: CACHE_TTL, buildRequestHeaders: ({ discoveryApiKey }) => ({ Accept: "application/json", ...discoveryApiKey ? { Authorization: `Bearer ${discoveryApiKey}` } : {} }), policy: ssrfPolicyFromHttpBaseUrlAllowedHostname(CHUTES_BASE_URL), auditContext: "chutes-model-discovery" }); } /** Discovers Chutes models dynamically, falling back to the bundled static catalog. */ async function discoverChutesModels(accessToken) { const trimmedKey = normalizeOptionalString(accessToken) ?? ""; if (isChutesModelDiscoveryTestEnvironment()) return CHUTES_MODEL_CATALOG.map(buildChutesModelDefinition); const staticCatalog = () => CHUTES_MODEL_CATALOG.map(buildChutesModelDefinition); try { const data = await fetchChutesModelRows(trimmedKey || void 0); if (data.length === 0) { log.warn("No models in response, using static catalog"); return staticCatalog(); } const seen = /* @__PURE__ */ new Set(); const models = []; for (const entry of data) { const id = normalizeOptionalString(entry?.id) ?? ""; if (!id || seen.has(id)) continue; seen.add(id); const lowerId = normalizeLowercaseStringOrEmpty(id); const isReasoning = entry.supported_features?.includes("reasoning") || lowerId.includes("r1") || lowerId.includes("thinking") || lowerId.includes("reason") || lowerId.includes("tee"); const input = (entry.input_modalities || ["text"]).filter((i) => i === "text" || i === "image"); models.push({ id, name: id, reasoning: isReasoning, input, cost: { input: entry.pricing?.prompt || 0, output: entry.pricing?.completion || 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: asPositiveSafeInteger(entry.context_length) ?? CHUTES_DEFAULT_CONTEXT_WINDOW, maxTokens: asPositiveSafeInteger(entry.max_output_length) ?? CHUTES_DEFAULT_MAX_TOKENS, compat: { supportsUsageInStreaming: false } }); } if (models.length === 0) return staticCatalog(); return models; } catch (error) { if (error instanceof LiveModelCatalogHttpError && error.status === 401 && trimmedKey) return await discoverChutesModels(void 0); if (error instanceof LiveModelCatalogHttpError && error.status !== 401 && error.status !== 503) { log.warn(`GET /v1/models failed: HTTP ${error.status}, using static catalog`); return staticCatalog(); } log.warn(`Discovery failed: ${String(error)}, using static catalog`); return staticCatalog(); } } //#endregion export { buildChutesModelDefinition as a, CHUTES_MODEL_CATALOG as i, CHUTES_DEFAULT_MODEL_ID as n, clearChutesModelCacheForTests as o, CHUTES_DEFAULT_MODEL_REF as r, discoverChutesModels as s, CHUTES_BASE_URL as t };