openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
78 lines (77 loc) • 3.07 kB
JavaScript
import { c as OLLAMA_DEFAULT_COST, m as normalizeOllamaCloudModelId, o as OLLAMA_DEFAULT_BASE_URL, s as OLLAMA_DEFAULT_CONTEXT_WINDOW } from "./defaults-DreqJ3YB.mjs";
//#region extensions/ollama/src/provider-base-url.ts
function resolveOllamaBaseUrlForRun(e) {
return e.providerBaseUrl?.trim() || e.modelBaseUrl?.trim() || "http://127.0.0.1:11434";
}
function resolveOllamaChatUrl(e) {
return `${e.trim().replace(/\/+$/, "").replace(/\/v1$/i, "") || "http://127.0.0.1:11434"}/api/chat`;
}
function readProviderBaseUrl(e) {
if (!e) return;
if (Object.hasOwn(e, "baseUrl") && e.baseUrl?.trim()) return e.baseUrl.trim();
const t = e;
if (Object.hasOwn(t, "baseURL") && typeof t.baseURL === "string" && t.baseURL.trim()) return t.baseURL.trim();
}
//#endregion
//#region extensions/ollama/src/model-reasoning.ts
const OLLAMA_THINKING_EFFORTS = [
"minimal",
"low",
"medium",
"high",
"xhigh",
"max"
];
function readOllamaThinkingMapValue(e) {
return e === "false" ? false : e === "true" ? true : OLLAMA_THINKING_EFFORTS.find((t) => t === e);
}
/** Prepare native wire values once, inside the discovery/cache lifecycle. */
async function buildOllamaThinkingLevelMap(e, t) {
if (!t || typeof t !== "object" || !("values" in t) || !Array.isArray(t.values)) return;
const n = t.values;
const r = ["off", ...OLLAMA_THINKING_EFFORTS];
const i = Object.fromEntries(r.map((e) => [e, e === "off" ? n.includes(false) ? "false" : null : n.includes(e) ? e : e === "low" && n.includes(true) ? "true" : null]));
if (!Object.values(i).some((e) => e !== null)) return;
const { clampThinkingLevel: a } = await import("./plugin-sdk/llm.js");
const o = {
id: e,
name: e,
provider: "ollama",
api: "ollama",
baseUrl: "",
reasoning: true,
input: ["text"],
cost: OLLAMA_DEFAULT_COST,
contextWindow: OLLAMA_DEFAULT_CONTEXT_WINDOW,
maxTokens: OLLAMA_DEFAULT_CONTEXT_WINDOW,
thinkingLevelMap: i
};
return {
...Object.fromEntries(r.map((e) => [e, i[a(o, e)]])),
minimal: i.minimal,
xhigh: i.xhigh
};
}
const OLLAMA_CLOUD_FULL_THINKING_EFFORT_MODEL_IDS = /* @__PURE__ */ new Set([
"deepseek-v4-flash",
"deepseek-v4-pro",
"deepseek-v4.1-flash",
"glm-5.2",
"glm-5.3",
"glm-5.3-flash",
"kimi-k3"
]);
function supportsOllamaCloudFullThinkingEffort(e) {
return OLLAMA_CLOUD_FULL_THINKING_EFFORT_MODEL_IDS.has(normalizeOllamaCloudModelId(e));
}
const OLLAMA_CLOUD_THINKING_FLOOR_MODEL_IDS = /* @__PURE__ */ new Set(["glm-5.3", "glm-5.3-flash"]);
function applyOllamaThinkingFloor(e, t) {
if (typeof e !== "object" || e === null || !("think" in e) || e.think !== false) return e;
const n = readOllamaThinkingMapValue(t.thinkingLevelMap?.off) ?? (OLLAMA_CLOUD_THINKING_FLOOR_MODEL_IDS.has(normalizeOllamaCloudModelId(t.id)) ? "low" : false);
return n === false ? e : {
...e,
think: n
};
}
//#endregion
export { readProviderBaseUrl as a, supportsOllamaCloudFullThinkingEffort as i, buildOllamaThinkingLevelMap as n, resolveOllamaBaseUrlForRun as o, readOllamaThinkingMapValue as r, resolveOllamaChatUrl as s, applyOllamaThinkingFloor as t };