UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

221 lines (220 loc) • 7.1 kB
import { o as normalizeLowercaseStringOrEmpty } from "./string-coerce-CCIiB4H7.mjs"; import { R as resolveTimerTimeoutMs } from "./number-coercion-D6u-4YD8.mjs"; import { o as resolveDefaultModelMaxTokens } from "./defaults-BWyoTPqn.mjs"; import { h as ssrfPolicyFromHttpBaseUrlAllowedHostname } from "./ssrf-DHBNJw0c.mjs"; import { o as withTrustedEnvProxyGuardedFetchMode, r as fetchWithSsrFGuard } from "./fetch-guard-BLMw2n18.mjs"; import { n as buildManifestModelProviderConfig } from "./provider-catalog-lIjm3m2s.mjs"; import "./string-coerce-runtime-BwAZZDf5.mjs"; import "./ssrf-runtime-B6q6NM4E.mjs"; import "./number-runtime-W4chuk8B.mjs"; import "./fetch-runtime-Dz-KqFMb.mjs"; import "./provider-model-shared-Dg70R9-2.mjs"; import { t as buildLiveModelProviderConfig, x as readLiveModelCatalogStringField } from "./provider-catalog-live-runtime-D-M7f_ww.mjs"; import "./provider-catalog-shared-ZRbc_4xZ.mjs"; //#region extensions/huggingface/openclaw.plugin.json var openclaw_plugin_default = { id: "huggingface", categories: ["models"], activation: { "onStartup": false }, enabledByDefault: true, providers: ["huggingface"], modelCatalog: { "providers": { "huggingface": { "baseUrl": "https://router.huggingface.co/v1", "api": "openai-completions", "models": [ { "id": "deepseek-ai/DeepSeek-R1", "name": "DeepSeek R1", "reasoning": true, "input": ["text"], "contextWindow": 131072, "maxTokens": 8192, "cost": { "input": 3, "output": 7, "cacheRead": 3, "cacheWrite": 3 } }, { "id": "deepseek-ai/DeepSeek-V3.1", "name": "DeepSeek V3.1", "reasoning": false, "input": ["text"], "contextWindow": 131072, "maxTokens": 8192, "cost": { "input": .6, "output": 1.25, "cacheRead": .6, "cacheWrite": .6 } }, { "id": "openai/gpt-oss-120b", "name": "GPT-OSS 120B", "reasoning": false, "input": ["text"], "contextWindow": 131072, "maxTokens": 8192, "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 } } ] } }, "discovery": { "huggingface": "refreshable" } }, modelIdNormalization: { "providers": { "huggingface": { "stripPrefixes": ["huggingface/"] } } }, setup: { "providers": [{ "id": "huggingface", "envVars": ["HUGGINGFACE_HUB_TOKEN", "HF_TOKEN"] }] }, providerAuthChoices: [{ "provider": "huggingface", "method": "api-key", "choiceId": "huggingface-api-key", "appGuidedSecret": true, "choiceLabel": "Hugging Face API key", "choiceHint": "Inference API (HF token)", "groupId": "huggingface", "groupLabel": "Hugging Face", "groupHint": "Inference API (HF token)", "optionKey": "huggingfaceApiKey", "cliFlag": "--huggingface-api-key", "cliOption": "--huggingface-api-key <key>", "cliDescription": "Hugging Face API key (HF token)" }], configGroups: [{ "id": "model-discovery", "title": "Model discovery", "order": 10, "properties": ["discovery"] }], configSchema: { "type": "object", "additionalProperties": false, "properties": { "discovery": { "type": "object", "additionalProperties": false, "properties": { "enabled": { "type": "boolean" } } } } }, uiHints: { "discovery": { "label": "Model Discovery", "help": "Plugin-owned controls for Hugging Face model auto-discovery." }, "discovery.enabled": { "label": "Enable Discovery", "help": "When false, OpenClaw keeps the Hugging Face plugin available but skips implicit startup discovery from ambient Hugging Face credentials." } } }; //#endregion //#region extensions/huggingface/models.ts const HUGGINGFACE_MANIFEST_CATALOG = openclaw_plugin_default.modelCatalog.providers.huggingface; const HUGGINGFACE_BASE_URL = HUGGINGFACE_MANIFEST_CATALOG.baseUrl; const HUGGINGFACE_DISCOVERY_TIMEOUT_MS = 3e4; const HUGGINGFACE_DEFAULT_COST = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }; const HUGGINGFACE_DEFAULT_CONTEXT_WINDOW = 131072; const HUGGINGFACE_MODEL_CATALOG = buildManifestModelProviderConfig({ providerId: "huggingface", catalog: HUGGINGFACE_MANIFEST_CATALOG }).models; function isReasoningModelHeuristic(e) { const t = normalizeLowercaseStringOrEmpty(e); return [ "r1", "reason", "thinking", "grok", "qwq" ].some((e) => t.includes(e)); } function displayNameFromApiEntry(e) { const t = readLiveModelCatalogStringField(e, [ "name", "title", "display_name" ]); if (t) return t; const n = e.id.split("/").pop() ?? e.id; const r = readLiveModelCatalogStringField(e, "owned_by"); if (r) return `${r}/${n}`; return n.replace(/-/g, " ").replace(/\b(\w)/g, (e) => e.toUpperCase()); } async function discoverHuggingfaceModels(e, t = HUGGINGFACE_DISCOVERY_TIMEOUT_MS, n = {}) { const r = e?.trim(); if (!r) return HUGGINGFACE_MODEL_CATALOG; const i = resolveTimerTimeoutMs(t, HUGGINGFACE_DISCOVERY_TIMEOUT_MS); return (await buildLiveModelProviderConfig({ ...n, providerId: "huggingface", endpoint: `${HUGGINGFACE_BASE_URL}/models`, providerConfig: { baseUrl: HUGGINGFACE_BASE_URL, api: "openai-completions" }, models: HUGGINGFACE_MODEL_CATALOG, discoveryApiKey: r, timeoutMs: i, ttlMs: 0, readRows(e) { const t = e?.data; if (!Array.isArray(t)) throw new Error("Hugging Face model discovery response must contain a data array"); return t; }, buildRequestHeaders: () => ({ Authorization: `Bearer ${r}`, "Content-Type": "application/json" }), policy: ssrfPolicyFromHttpBaseUrlAllowedHostname(HUGGINGFACE_BASE_URL), auditContext: "huggingface-model-discovery", fetchGuard: (e) => fetchWithSsrFGuard(withTrustedEnvProxyGuardedFetchMode(e)), projectRows(e) { const t = new Map(HUGGINGFACE_MODEL_CATALOG.map((e) => [e.id, e])); const n = /* @__PURE__ */ new Set(); const r = []; for (const i of e) { const e = i; const a = typeof e?.id === "string" ? e.id.trim() : ""; if (!e || !a || n.has(a)) continue; n.add(a); const o = e?.architecture?.input_modalities; const s = Array.isArray(e?.providers) ? e.providers.filter((e) => e?.status !== "error") : []; const c = s.map((e) => e?.context_length).filter((e) => typeof e === "number" && e > 0); const l = c.length > 0 ? Math.min(...c) : void 0; const u = t.get(a) ?? { id: a, name: displayNameFromApiEntry(e), reasoning: isReasoningModelHeuristic(a), input: Array.isArray(o) && o.includes("image") ? ["text", "image"] : ["text"], cost: HUGGINGFACE_DEFAULT_COST, contextWindow: HUGGINGFACE_DEFAULT_CONTEXT_WINDOW, maxTokens: resolveDefaultModelMaxTokens(l ?? HUGGINGFACE_DEFAULT_CONTEXT_WINDOW) }; r.push({ ...u, contextWindow: l ?? u.contextWindow, ...s.some((e) => e?.supports_tools === false) ? { compat: { ...u.compat, supportsTools: false } } : {} }); } return r; } })).models; } //#endregion export { openclaw_plugin_default as i, HUGGINGFACE_MODEL_CATALOG as n, discoverHuggingfaceModels as r, HUGGINGFACE_BASE_URL as t };