@openclaw/llama-cpp-provider 2026.10.1-beta.2 → 2026.10.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/.setup/{managed-provider-config-B99gmBnE.mjs → managed-provider-config-D0abOkC_.mjs}
RENAMED
|
@@ -19,6 +19,7 @@ const DEFAULT_LLAMA_CPP_CONTEXT_SIZE = 65536;
|
|
|
19
19
|
const DEFAULT_LLAMA_CPP_EMBEDDING_MODEL = "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf";
|
|
20
20
|
const DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION = "66f974f8cd48cc3b9c41c516b95508e75b4bee64";
|
|
21
21
|
const DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID = "embeddinggemma-300m-qat-q8_0";
|
|
22
|
+
const DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE = 2048;
|
|
22
23
|
const DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE = "hf_ggml-org_embeddinggemma-300m-qat-Q8_0.gguf";
|
|
23
24
|
const DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES = 328577056;
|
|
24
25
|
const DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256 = "6fa0c02a9c302be6f977521d399b4de3a46310a4f2621ee0063747881b673f67";
|
|
@@ -120,4 +121,4 @@ function resolveManagedLlamaCppProviderConfig(config) {
|
|
|
120
121
|
return provider;
|
|
121
122
|
}
|
|
122
123
|
//#endregion
|
|
123
|
-
export {
|
|
124
|
+
export { resolveCachedLlamaCppModelPath as C, resolveLlamaCppEmbeddingModel as D, resolveLlamaCppDataDir as E, resolveLlamaCppModelCacheDir as O, buildLlamaCppProviderConfig as S, resolveLegacyLlamaCppModelCacheDir as T, LLAMA_CPP_DEFAULT_PORT as _, DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE as a, LLAMA_CPP_PROVIDER_LABEL as b, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION as c, DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE as d, DEFAULT_LLAMA_CPP_MODEL_ID as f, DEFAULT_LLAMA_CPP_MODEL_URI as g, DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES as h, DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE as i, resolveLlamaCppModelSource as k, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256 as l, DEFAULT_LLAMA_CPP_MODEL_SHA256 as m, resolveManagedLlamaCppProviderConfig as n, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL as o, DEFAULT_LLAMA_CPP_MODEL_REVISION as p, DEFAULT_LLAMA_CPP_CONTEXT_SIZE as r, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID as s, MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE as t, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES as u, LLAMA_CPP_LOCAL_AUTH_MARKER as v, resolveHomePath as w, buildLlamaCppModel as x, LLAMA_CPP_PROVIDER_ID as y };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as resolveCachedLlamaCppModelPath, D as resolveLlamaCppEmbeddingModel, E as resolveLlamaCppDataDir, O as resolveLlamaCppModelCacheDir, S as buildLlamaCppProviderConfig, T as resolveLegacyLlamaCppModelCacheDir, _ as LLAMA_CPP_DEFAULT_PORT, a as DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE, b as LLAMA_CPP_PROVIDER_LABEL, c as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION, d as DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE, f as DEFAULT_LLAMA_CPP_MODEL_ID, g as DEFAULT_LLAMA_CPP_MODEL_URI, h as DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES, i as DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE, k as resolveLlamaCppModelSource, l as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256, m as DEFAULT_LLAMA_CPP_MODEL_SHA256, n as resolveManagedLlamaCppProviderConfig, o as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL, p as DEFAULT_LLAMA_CPP_MODEL_REVISION, s as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID, u as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES, v as LLAMA_CPP_LOCAL_AUTH_MARKER, w as resolveHomePath, x as buildLlamaCppModel, y as LLAMA_CPP_PROVIDER_ID } from "./.setup/managed-provider-config-D0abOkC_.mjs";
|
|
2
2
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { getEmbeddingProvider } from "openclaw/plugin-sdk/embedding-providers";
|
|
@@ -14,14 +14,15 @@ import { fetchConfiguredLocalOriginWithSsrFGuard } from "openclaw/plugin-sdk/ssr
|
|
|
14
14
|
import { execFile } from "node:child_process";
|
|
15
15
|
import fs$1, { constants } from "node:fs";
|
|
16
16
|
import { sha256File } from "@openclaw/fs-safe/durability";
|
|
17
|
+
import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
|
|
17
18
|
import { toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
18
19
|
import { ARCHIVE_LIMIT_ERROR_CODE, ArchiveLimitError, extractArchive } from "openclaw/plugin-sdk/archive";
|
|
20
|
+
import { createSubsystemLogger } from "openclaw/plugin-sdk/logging-core";
|
|
19
21
|
import { CUSTOM_LOCAL_AUTH_MARKER, applyAuthProfileConfig, buildApiKeyCredential, ensureApiKeyFromEnvOrPrompt, hasConfiguredSecretInput, isNonSecretApiKeyMarker, normalizeOptionalSecretInput, upsertAuthProfileWithLock } from "openclaw/plugin-sdk/provider-auth";
|
|
20
22
|
import { buildProviderToolCompatFamilyHooks } from "openclaw/plugin-sdk/provider-tools";
|
|
21
23
|
import { removeAuthProfileConfig, removeProviderAuthProfilesWithLock, resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
22
24
|
import { resolveConfiguredSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime";
|
|
23
25
|
import { LiveModelCatalogHttpError, runLiveProviderCatalog } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
|
24
|
-
import { getCachedLiveCatalogValue } from "openclaw/plugin-sdk/provider-catalog-shared";
|
|
25
26
|
import { SELF_HOSTED_DEFAULT_CONTEXT_WINDOW, SELF_HOSTED_DEFAULT_COST, SELF_HOSTED_DEFAULT_MAX_TOKENS, applyProviderDefaultModel, discoverOpenAICompatibleLocalModels } from "openclaw/plugin-sdk/provider-setup";
|
|
26
27
|
import { selectPreferredLocalModelId } from "openclaw/plugin-sdk/provider-model-shared";
|
|
27
28
|
import { streamSimple } from "openclaw/plugin-sdk/llm";
|
|
@@ -214,6 +215,9 @@ function resolveManagedLlamaServerPaths(asset = selectLlamaServerAsset()) {
|
|
|
214
215
|
presetPath: path.join(resolveLlamaCppDataDir(), "models.ini")
|
|
215
216
|
};
|
|
216
217
|
}
|
|
218
|
+
function findManagedLlamaServerAsset(command, platform = process.platform, arch = process.arch) {
|
|
219
|
+
return LLAMA_SERVER_ASSETS.find((asset) => asset.platform === platform && asset.arch === arch && resolveManagedLlamaServerPaths(asset).command === command);
|
|
220
|
+
}
|
|
217
221
|
//#endregion
|
|
218
222
|
//#region extensions/llama-cpp/src/llama-server-extract.ts
|
|
219
223
|
const MEBIBYTE = 1048576;
|
|
@@ -422,8 +426,8 @@ async function extractWindowsVcRuntime(params) {
|
|
|
422
426
|
//#endregion
|
|
423
427
|
//#region extensions/llama-cpp/src/llama-server-install.ts
|
|
424
428
|
const DOWNLOAD_TIMEOUT_MS = 18e5;
|
|
425
|
-
const
|
|
426
|
-
const
|
|
429
|
+
const PROBE_TIMEOUT_MS = 15e3;
|
|
430
|
+
const VERSION_TIMEOUT_MS = 12e4;
|
|
427
431
|
const installationPromises = /* @__PURE__ */ new Map();
|
|
428
432
|
function compareVersion(left, right) {
|
|
429
433
|
const leftParts = left.split(".").map(Number);
|
|
@@ -434,13 +438,30 @@ function compareVersion(left, right) {
|
|
|
434
438
|
}
|
|
435
439
|
return 0;
|
|
436
440
|
}
|
|
441
|
+
/** The verified build cannot run on this host; rerunning setup cannot change that. */
|
|
442
|
+
var UnsupportedLlamaServerHostError = class extends Error {
|
|
443
|
+
constructor(..._args) {
|
|
444
|
+
super(..._args);
|
|
445
|
+
this.name = "UnsupportedLlamaServerHostError";
|
|
446
|
+
}
|
|
447
|
+
};
|
|
437
448
|
function assertSupportedLinuxRuntime(asset) {
|
|
438
449
|
if (asset.platform !== "linux") return;
|
|
439
450
|
const header = asOptionalRecord(asOptionalRecord(process.report?.getReport())?.header);
|
|
440
451
|
const glibc = typeof header?.glibcVersionRuntime === "string" ? header.glibcVersionRuntime : "";
|
|
441
|
-
if (!glibc) throw new
|
|
452
|
+
if (!glibc) throw new UnsupportedLlamaServerHostError("The verified Ubuntu llama-server build requires glibc and cannot run on musl/Alpine. Install llama-server manually for this host and configure its absolute path.");
|
|
442
453
|
const minimum = asset.arch === "arm64" ? "2.38" : "2.34";
|
|
443
|
-
if (compareVersion(glibc, minimum) < 0) throw new
|
|
454
|
+
if (compareVersion(glibc, minimum) < 0) throw new UnsupportedLlamaServerHostError(`The verified llama-server build requires glibc ${minimum}+ on Linux ${asset.arch}; this host has ${glibc}. Install a compatible llama-server manually and configure its absolute path.`);
|
|
455
|
+
}
|
|
456
|
+
const MACOS_MINIMUM = "13.3";
|
|
457
|
+
async function assertSupportedMacosRuntime(asset, signal, cause) {
|
|
458
|
+
if (asset.platform !== "darwin") return;
|
|
459
|
+
const version = await runServerCommand("/usr/bin/sw_vers", ["-productVersion"], signal).catch(() => {
|
|
460
|
+
signal?.throwIfAborted();
|
|
461
|
+
return "";
|
|
462
|
+
});
|
|
463
|
+
if (!/^\d+\.\d+(?:\.\d+)?$/u.test(version) || compareVersion(version, MACOS_MINIMUM) >= 0) return;
|
|
464
|
+
throw new UnsupportedLlamaServerHostError(`The verified llama-server ${LLAMA_SERVER_RELEASE} build requires macOS ${MACOS_MINIMUM}+; this Mac runs macOS ${version}. Build llama-server for this Mac and set models.providers.llama-cpp.localService.command to its absolute path, or use a remote model or embedding provider.`, cause === void 0 ? void 0 : { cause });
|
|
444
465
|
}
|
|
445
466
|
function assetUrl(asset) {
|
|
446
467
|
return asset.url ?? `https://github.com/ggml-org/llama.cpp/releases/download/b10809/${asset.name}`;
|
|
@@ -456,10 +477,7 @@ function rememberVerifiedFile(filePath, stat, sha256) {
|
|
|
456
477
|
identity: fileIdentity(stat),
|
|
457
478
|
sha256
|
|
458
479
|
});
|
|
459
|
-
|
|
460
|
-
const oldest = verifiedFiles.keys().next().value;
|
|
461
|
-
if (oldest !== void 0) verifiedFiles.delete(oldest);
|
|
462
|
-
}
|
|
480
|
+
pruneMapToMaxSize(verifiedFiles, VERIFIED_FILE_LIMIT);
|
|
463
481
|
}
|
|
464
482
|
async function sha256File$1(filePath, signal) {
|
|
465
483
|
signal?.throwIfAborted();
|
|
@@ -554,7 +572,7 @@ async function downloadVerifiedFile(params) {
|
|
|
554
572
|
await fs.rm(partialPath, { force: true }).catch(() => void 0);
|
|
555
573
|
}
|
|
556
574
|
}
|
|
557
|
-
async function runServerCommand(command, args, signal, timeoutMs =
|
|
575
|
+
async function runServerCommand(command, args, signal, timeoutMs = PROBE_TIMEOUT_MS) {
|
|
558
576
|
return await new Promise((resolve, reject) => {
|
|
559
577
|
execFile(command, args, {
|
|
560
578
|
timeout: timeoutMs,
|
|
@@ -572,9 +590,9 @@ function formatRuntimeDependencyError(error) {
|
|
|
572
590
|
if (process.platform === "win32") return new Error(`The verified llama-server build could not start with its app-local Visual C++ runtime. Rerun llama.cpp setup to reinstall it, or configure a compatible llama-server manually. Detail: ${detail}`, { cause: error });
|
|
573
591
|
return new Error(`The verified llama-server build could not start: ${detail}`, { cause: error });
|
|
574
592
|
}
|
|
575
|
-
async function queryServerVersion(command, signal
|
|
593
|
+
async function queryServerVersion(command, signal) {
|
|
576
594
|
try {
|
|
577
|
-
return await runServerCommand(command, ["--version"], signal,
|
|
595
|
+
return await runServerCommand(command, ["--version"], signal, VERSION_TIMEOUT_MS);
|
|
578
596
|
} catch (error) {
|
|
579
597
|
signal?.throwIfAborted();
|
|
580
598
|
throw formatRuntimeDependencyError(error);
|
|
@@ -592,8 +610,8 @@ async function validateCudaServer(command, asset, signal) {
|
|
|
592
610
|
if (!/^\s*CUDA\d+: .+\(\d+ MiB, \d+ MiB free\)$/mu.test(devices)) throw new Error("The verified llama-server could not initialize an NVIDIA CUDA device. Update the NVIDIA driver and rerun setup, or configure a compatible llama-server manually. CPU fallback was not activated.");
|
|
593
611
|
}
|
|
594
612
|
}
|
|
595
|
-
async function validateInstalledServer(command, asset, signal
|
|
596
|
-
validateServerVersionOutput(command, await queryServerVersion(command, signal
|
|
613
|
+
async function validateInstalledServer(command, asset, signal) {
|
|
614
|
+
validateServerVersionOutput(command, await queryServerVersion(command, signal));
|
|
597
615
|
await validateCudaServer(command, asset, signal);
|
|
598
616
|
}
|
|
599
617
|
async function stageLlamaServerDependency(params) {
|
|
@@ -632,9 +650,15 @@ async function installLlamaServer(asset, options) {
|
|
|
632
650
|
assertSupportedLinuxRuntime(asset);
|
|
633
651
|
const { installDir, command } = resolveManagedLlamaServerPaths(asset);
|
|
634
652
|
if (await fs.stat(command).then((stat) => stat.isFile()).catch(() => false)) {
|
|
635
|
-
|
|
653
|
+
try {
|
|
654
|
+
await validateInstalledServer(command, asset, options.signal);
|
|
655
|
+
} catch (error) {
|
|
656
|
+
await assertSupportedMacosRuntime(asset, options.signal, error);
|
|
657
|
+
throw error;
|
|
658
|
+
}
|
|
636
659
|
return command;
|
|
637
660
|
}
|
|
661
|
+
await assertSupportedMacosRuntime(asset, options.signal);
|
|
638
662
|
const dataDir = resolveLlamaCppDataDir();
|
|
639
663
|
const archivePath = path.join(dataDir, `.download-${randomUUID()}-${asset.name}`);
|
|
640
664
|
const extractDir = path.join(dataDir, `.extract-${randomUUID()}`);
|
|
@@ -673,7 +697,7 @@ async function installLlamaServer(asset, options) {
|
|
|
673
697
|
if (windowsRuntimeDependencies.length > 0) {
|
|
674
698
|
let version;
|
|
675
699
|
try {
|
|
676
|
-
version = await queryServerVersion(extractedCommand, options.signal
|
|
700
|
+
version = await queryServerVersion(extractedCommand, options.signal);
|
|
677
701
|
} catch (startupError) {
|
|
678
702
|
options.signal?.throwIfAborted();
|
|
679
703
|
try {
|
|
@@ -689,7 +713,7 @@ async function installLlamaServer(asset, options) {
|
|
|
689
713
|
throw formatVcRuntimeFallbackError(startupError, stagingError);
|
|
690
714
|
}
|
|
691
715
|
try {
|
|
692
|
-
version = await queryServerVersion(extractedCommand, options.signal
|
|
716
|
+
version = await queryServerVersion(extractedCommand, options.signal);
|
|
693
717
|
} catch (retryError) {
|
|
694
718
|
options.signal?.throwIfAborted();
|
|
695
719
|
throw formatVcRuntimeFallbackError(startupError, retryError);
|
|
@@ -697,7 +721,7 @@ async function installLlamaServer(asset, options) {
|
|
|
697
721
|
}
|
|
698
722
|
validateServerVersionOutput(extractedCommand, version);
|
|
699
723
|
await validateCudaServer(extractedCommand, asset, options.signal);
|
|
700
|
-
} else await validateInstalledServer(extractedCommand, asset, options.signal
|
|
724
|
+
} else await validateInstalledServer(extractedCommand, asset, options.signal);
|
|
701
725
|
await fs.mkdir(path.dirname(installDir), { recursive: true });
|
|
702
726
|
options.signal?.throwIfAborted();
|
|
703
727
|
await fs.rm(installDir, {
|
|
@@ -739,7 +763,6 @@ async function ensureLlamaServerInstalled(options = {}) {
|
|
|
739
763
|
}
|
|
740
764
|
//#endregion
|
|
741
765
|
//#region extensions/llama-cpp/src/llama-server-preset.ts
|
|
742
|
-
const LLAMA_CPP_EMBEDDING_UBATCH_SIZE = 2048;
|
|
743
766
|
function assertIniValue(value, label) {
|
|
744
767
|
if (/\r|\n/u.test(value)) throw new Error(`${label} cannot contain a newline`);
|
|
745
768
|
return value;
|
|
@@ -771,14 +794,26 @@ const PRESET_KEY_ALIASES = {
|
|
|
771
794
|
ub: "ubatch-size",
|
|
772
795
|
LLAMA_ARG_UBATCH: "ubatch-size",
|
|
773
796
|
embeddings: "embedding",
|
|
774
|
-
LLAMA_ARG_EMBEDDINGS: "embedding"
|
|
797
|
+
LLAMA_ARG_EMBEDDINGS: "embedding",
|
|
798
|
+
np: "parallel",
|
|
799
|
+
LLAMA_ARG_N_PARALLEL: "parallel",
|
|
800
|
+
LLAMA_ARG_KV_UNIFIED_PER_SLOT: "kv-unified-per-slot"
|
|
775
801
|
};
|
|
802
|
+
const PRESET_SETTING_PATTERN = /(?<![^\r\n])([a-zA-Z_][a-zA-Z0-9_.-]*)([ \t]*=[ \t]*)([^\r\n]*?)([ \t]*(?:[;#][^\r\n]*)?)(\r\n|\n|\r|(?![\s\S]))/g;
|
|
803
|
+
function readSettingKeys(section) {
|
|
804
|
+
return new Set([...(section ?? "").matchAll(PRESET_SETTING_PATTERN)].map(([, key = ""]) => PRESET_KEY_ALIASES[key] ?? key));
|
|
805
|
+
}
|
|
806
|
+
function readServiceSettingKeys(service) {
|
|
807
|
+
const caseInsensitiveEnv = process.platform === "win32";
|
|
808
|
+
const keys = [...Object.entries(service?.env ?? {}).filter(([, value]) => value !== void 0).map(([key]) => caseInsensitiveEnv ? key.toUpperCase() : key).filter((key) => key.startsWith("LLAMA_ARG_")), ...(service?.args ?? []).filter((arg) => arg.startsWith("-")).map((arg) => arg.startsWith("--") ? arg.slice(2).replaceAll("_", "-") : arg.slice(1))];
|
|
809
|
+
return new Set(keys.map((key) => PRESET_KEY_ALIASES[key] ?? key));
|
|
810
|
+
}
|
|
776
811
|
function updateModelSection(sections, id, values, newline) {
|
|
777
812
|
assertIniValue(id, "llama.cpp model id");
|
|
778
813
|
if (id.includes("]")) throw new Error("llama.cpp model ids cannot contain ]");
|
|
779
814
|
const name = [...sections.keys()].filter((candidate) => normalizePresetName(candidate) === normalizePresetName(id)).toSorted((left, right) => Buffer.compare(Buffer.from(left), Buffer.from(right))).at(-1) ?? id;
|
|
780
815
|
const pending = new Set(Object.keys(values));
|
|
781
|
-
let contents = (sections.get(name) ?? `[${id}]${newline}`).replace(
|
|
816
|
+
let contents = (sections.get(name) ?? `[${id}]${newline}`).replace(PRESET_SETTING_PATTERN, (line, key, separator, _value, comment, ending) => {
|
|
782
817
|
const canonical = PRESET_KEY_ALIASES[key] ?? key;
|
|
783
818
|
if (!Object.hasOwn(values, canonical)) return line;
|
|
784
819
|
pending.delete(canonical);
|
|
@@ -800,11 +835,22 @@ function buildLlamaServerPreset(existing, params) {
|
|
|
800
835
|
}, newline);
|
|
801
836
|
const embeddingPath = params.embeddingModelPath ?? (!sections.has("embeddinggemma-300m-qat-q8_0") ? params.defaultEmbeddingModelPath : void 0);
|
|
802
837
|
if (embeddingPath) {
|
|
803
|
-
const
|
|
838
|
+
const configured = /* @__PURE__ */ new Set([
|
|
839
|
+
...readSettingKeys(sections.get(DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID)),
|
|
840
|
+
...readSettingKeys(sections.get("*")),
|
|
841
|
+
...readServiceSettingKeys(params.serviceSettings)
|
|
842
|
+
]);
|
|
843
|
+
const defaults = {
|
|
844
|
+
parallel: "1",
|
|
845
|
+
"ctx-size": String(DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE),
|
|
846
|
+
"ubatch-size": String(DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE)
|
|
847
|
+
};
|
|
848
|
+
if (configured.has("parallel") || configured.has("kv-unified-per-slot")) delete defaults["ctx-size"];
|
|
849
|
+
for (const key of configured) delete defaults[key];
|
|
804
850
|
updateModelSection(sections, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID, {
|
|
805
851
|
model: assertIniValue(embeddingPath, "llama.cpp embedding model path"),
|
|
806
|
-
|
|
807
|
-
|
|
852
|
+
embedding: "true",
|
|
853
|
+
...defaults
|
|
808
854
|
}, newline);
|
|
809
855
|
}
|
|
810
856
|
const embeddingSection = sections.get(DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID);
|
|
@@ -814,6 +860,60 @@ function buildLlamaServerPreset(existing, params) {
|
|
|
814
860
|
return header + (header && !/[\r\n]$/u.test(header) ? newline : "") + orderedSections.map((section) => section.replace(/[\r\n]+$/u, "")).join(newline + newline) + newline;
|
|
815
861
|
}
|
|
816
862
|
//#endregion
|
|
863
|
+
//#region extensions/llama-cpp/src/managed-server-orphans.ts
|
|
864
|
+
const log = createSubsystemLogger("llama-cpp");
|
|
865
|
+
const recoveries = /* @__PURE__ */ new Map();
|
|
866
|
+
function readUniqueArgument(argv, name) {
|
|
867
|
+
const values = argv.flatMap((argument, index) => {
|
|
868
|
+
if (argument === name) {
|
|
869
|
+
const value = argv[index + 1];
|
|
870
|
+
return value === void 0 ? [] : [value];
|
|
871
|
+
}
|
|
872
|
+
return argument.startsWith(`${name}=`) ? [argument.slice(name.length + 1)] : [];
|
|
873
|
+
});
|
|
874
|
+
return values.length === 1 ? values[0] : void 0;
|
|
875
|
+
}
|
|
876
|
+
/** A new host process recovers once; in-process restarts retain that host's children. */
|
|
877
|
+
async function recoverManagedLlamaServer(params) {
|
|
878
|
+
params.signal?.throwIfAborted();
|
|
879
|
+
if (!findManagedLlamaServerAsset(params.command)) return;
|
|
880
|
+
const args = params.args ?? [];
|
|
881
|
+
const preset = readUniqueArgument(args, "--models-preset");
|
|
882
|
+
const host = readUniqueArgument(args, "--host");
|
|
883
|
+
if (!preset || !host || readUniqueArgument(args, "--port") !== String(params.port)) return;
|
|
884
|
+
const required = /* @__PURE__ */ new Map([
|
|
885
|
+
["--port", String(params.port)],
|
|
886
|
+
["--models-preset", preset],
|
|
887
|
+
["--host", host]
|
|
888
|
+
]);
|
|
889
|
+
const cwd = !path.isAbsolute(preset) ? path.resolve(params.cwd ?? process.cwd()) : void 0;
|
|
890
|
+
const key = JSON.stringify([
|
|
891
|
+
params.command,
|
|
892
|
+
[...required],
|
|
893
|
+
cwd
|
|
894
|
+
]);
|
|
895
|
+
let recovery = recoveries.get(key);
|
|
896
|
+
if (!recovery) {
|
|
897
|
+
recovery = (async () => {
|
|
898
|
+
const { reapOrphanedProcesses } = await import("openclaw/plugin-sdk/process-runtime");
|
|
899
|
+
if (typeof reapOrphanedProcesses !== "function") return;
|
|
900
|
+
await reapOrphanedProcesses({
|
|
901
|
+
command: params.command,
|
|
902
|
+
cwd,
|
|
903
|
+
matchesArguments: (argv) => [...required].every(([name, value]) => readUniqueArgument(argv, name) === value),
|
|
904
|
+
signal: params.signal,
|
|
905
|
+
onReap: (pid) => log.info(`reaping orphaned managed llama-server: pid=${pid} port=${params.port}`)
|
|
906
|
+
});
|
|
907
|
+
})().catch((error) => {
|
|
908
|
+
recoveries.delete(key);
|
|
909
|
+
throw error;
|
|
910
|
+
});
|
|
911
|
+
recoveries.set(key, recovery);
|
|
912
|
+
}
|
|
913
|
+
await recovery;
|
|
914
|
+
params.signal?.throwIfAborted();
|
|
915
|
+
}
|
|
916
|
+
//#endregion
|
|
817
917
|
//#region extensions/llama-cpp/src/hardware.ts
|
|
818
918
|
const GIB$1 = 1024 ** 3;
|
|
819
919
|
const MIB = 1024 ** 2;
|
|
@@ -1106,7 +1206,7 @@ function recommendLlamaCppModel(hardware, backend, cached = {}) {
|
|
|
1106
1206
|
}
|
|
1107
1207
|
return {
|
|
1108
1208
|
kind: "unavailable",
|
|
1109
|
-
reason: candidates.length > 0 ? "There is not enough free disk space for a recommended model, embeddings, and the runtime. Free space in the model cache and retry setup." : `No recommended model fits the current ${formatLlamaCppMemory(Math.max(0, memoryBudgetBytes))} memory budget. Close other applications and retry, or configure an existing GGUF or external server.`
|
|
1209
|
+
reason: candidates.length > 0 ? "There is not enough free disk space for a recommended model, embeddings, and the runtime. Free space in the model cache and retry setup." : `No recommended model fits the current ${formatLlamaCppMemory(Math.max(0, memoryBudgetBytes))} memory budget. Close other applications and retry, or configure an existing GGUF or external server. For local memory search without a chat model, an embedding-only local server (about 0.3 GB for the default embedding model) can fit instead. Set memory.search.provider to "local" with openclaw config set memory.search.provider local, then re-run openclaw models auth login --provider llama-cpp --method local using the same profile for both commands.`
|
|
1110
1210
|
};
|
|
1111
1211
|
}
|
|
1112
1212
|
//#endregion
|
|
@@ -1240,6 +1340,34 @@ async function resolveModelArtifact(source, signal) {
|
|
|
1240
1340
|
}
|
|
1241
1341
|
throw new Error(`Unsupported remote model URI: ${source}`);
|
|
1242
1342
|
}
|
|
1343
|
+
async function resolveCachedModelArtifact(source, cacheDir, signal) {
|
|
1344
|
+
const key = `${path.resolve(cacheDir)}\0${source}`;
|
|
1345
|
+
const artifact = resolvedModelArtifacts.get(key) ?? await resolveModelArtifact(source, signal);
|
|
1346
|
+
resolvedModelArtifacts.set(key, artifact);
|
|
1347
|
+
return artifact;
|
|
1348
|
+
}
|
|
1349
|
+
async function resolveLlamaCppModelDownloadSize(source, cacheDir, signal) {
|
|
1350
|
+
const artifact = await resolveCachedModelArtifact(source, cacheDir, signal);
|
|
1351
|
+
if (artifact.expectedSize !== void 0) return artifact.expectedSize;
|
|
1352
|
+
const result = await fetchWithSsrFGuard({
|
|
1353
|
+
url: artifact.url,
|
|
1354
|
+
init: { method: "HEAD" },
|
|
1355
|
+
signal,
|
|
1356
|
+
requireHttps: true,
|
|
1357
|
+
policy: ssrfPolicyFromHttpBaseUrlAllowedOrigin(artifact.url),
|
|
1358
|
+
auditContext: "llama-cpp-model-resolve"
|
|
1359
|
+
}).catch(() => {
|
|
1360
|
+
signal?.throwIfAborted();
|
|
1361
|
+
});
|
|
1362
|
+
if (!result) return;
|
|
1363
|
+
const { response, release } = result;
|
|
1364
|
+
try {
|
|
1365
|
+
const size = response.ok ? Number(response.headers.get("content-length")) : 0;
|
|
1366
|
+
return Number.isSafeInteger(size) && size > 0 ? size : void 0;
|
|
1367
|
+
} finally {
|
|
1368
|
+
await release();
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1243
1371
|
async function ensureLlamaCppModel(params) {
|
|
1244
1372
|
const localSource = resolveHomePath(params.source);
|
|
1245
1373
|
if (!/^(?:hf|huggingface|https):/iu.test(localSource)) {
|
|
@@ -1247,9 +1375,7 @@ async function ensureLlamaCppModel(params) {
|
|
|
1247
1375
|
await assertGguf(localPath);
|
|
1248
1376
|
return localPath;
|
|
1249
1377
|
}
|
|
1250
|
-
const
|
|
1251
|
-
const artifact = resolvedModelArtifacts.get(artifactCacheKey) ?? await resolveModelArtifact(localSource, params.signal);
|
|
1252
|
-
resolvedModelArtifacts.set(artifactCacheKey, artifact);
|
|
1378
|
+
const artifact = await resolveCachedModelArtifact(localSource, params.cacheDir, params.signal);
|
|
1253
1379
|
const destination = path.join(params.cacheDir, artifact.fileName);
|
|
1254
1380
|
const load = modelPromises.get(destination) ?? (async () => {
|
|
1255
1381
|
const exists = await fs.stat(destination).then((stat) => stat.isFile()).catch(() => false);
|
|
@@ -1335,8 +1461,16 @@ async function findAvailableLlamaServerPort(preferred = LLAMA_CPP_DEFAULT_PORT)
|
|
|
1335
1461
|
}
|
|
1336
1462
|
async function prepareManagedLlamaServer(params) {
|
|
1337
1463
|
params.signal?.throwIfAborted();
|
|
1338
|
-
|
|
1339
|
-
|
|
1464
|
+
let command = params.localService?.command;
|
|
1465
|
+
const asset = command === void 0 ? params.asset : findManagedLlamaServerAsset(command);
|
|
1466
|
+
if (command !== void 0 && asset) try {
|
|
1467
|
+
await fs.stat(command);
|
|
1468
|
+
} catch (error) {
|
|
1469
|
+
if (asOptionalRecord(error)?.code !== "ENOENT") throw error;
|
|
1470
|
+
command = void 0;
|
|
1471
|
+
}
|
|
1472
|
+
command ??= (await ensureLlamaServerInstalled({
|
|
1473
|
+
asset,
|
|
1340
1474
|
signal: params.signal,
|
|
1341
1475
|
onProgress: params.onProgress
|
|
1342
1476
|
})).command;
|
|
@@ -1349,6 +1483,13 @@ async function prepareManagedLlamaServer(params) {
|
|
|
1349
1483
|
healthUrl: params.localService?.healthUrl ?? `${rootUrl}/health`
|
|
1350
1484
|
};
|
|
1351
1485
|
const configuredPreset = params.localService?.args?.find((_, index, args) => args[index - 1] === "--models-preset") ?? params.localService?.env?.LLAMA_ARG_MODELS_PRESET;
|
|
1486
|
+
if (params.localService && !params.isolated) await recoverManagedLlamaServer({
|
|
1487
|
+
command,
|
|
1488
|
+
port,
|
|
1489
|
+
cwd: params.localService.cwd,
|
|
1490
|
+
args: params.localService.args,
|
|
1491
|
+
signal: params.signal
|
|
1492
|
+
});
|
|
1352
1493
|
if (params.localService && !configuredPreset && !params.isolated) {
|
|
1353
1494
|
await runPresetTransition(async () => {
|
|
1354
1495
|
presetState.desiredRevisions.delete(reconcileOrigin);
|
|
@@ -1364,9 +1505,15 @@ async function prepareManagedLlamaServer(params) {
|
|
|
1364
1505
|
await updatePreset(presetPath, {
|
|
1365
1506
|
chatModel: params.chatModel,
|
|
1366
1507
|
configuredChatModelIds: params.configuredChatModelIds,
|
|
1367
|
-
embeddingModelIsDefault: params.embeddingModelIsDefault,
|
|
1368
1508
|
embeddingModelPath: params.embeddingModelPath,
|
|
1369
1509
|
defaultEmbeddingModelPath: params.defaultEmbeddingModelPath,
|
|
1510
|
+
serviceSettings: params.isolated ? { env: process.env } : {
|
|
1511
|
+
args: params.localService?.args,
|
|
1512
|
+
env: {
|
|
1513
|
+
...process.env,
|
|
1514
|
+
...params.localService?.env
|
|
1515
|
+
}
|
|
1516
|
+
},
|
|
1370
1517
|
reconcileOrigin: params.isolated ? void 0 : reconcileOrigin
|
|
1371
1518
|
});
|
|
1372
1519
|
params.signal?.throwIfAborted();
|
|
@@ -1520,7 +1667,7 @@ function resolveProviderPort(provider) {
|
|
|
1520
1667
|
if (!Number.isInteger(port) || port <= 0) throw new Error("Managed llama.cpp provider baseUrl must include a loopback port.");
|
|
1521
1668
|
return port;
|
|
1522
1669
|
}
|
|
1523
|
-
async function prepareEmbeddingServer(options, embeddingSource
|
|
1670
|
+
async function prepareEmbeddingServer(options, embeddingSource) {
|
|
1524
1671
|
const provider = resolveManagedLlamaCppProviderConfig(options.config);
|
|
1525
1672
|
const embeddingModelPath = await ensureLlamaCppModel({
|
|
1526
1673
|
source: embeddingSource,
|
|
@@ -1530,7 +1677,6 @@ async function prepareEmbeddingServer(options, embeddingSource, embeddingModelIs
|
|
|
1530
1677
|
await prepareManagedLlamaServer({
|
|
1531
1678
|
chatModel: { mode: "preserve" },
|
|
1532
1679
|
configuredChatModelIds: provider.models.map((model) => model.id),
|
|
1533
|
-
embeddingModelIsDefault,
|
|
1534
1680
|
embeddingModelPath,
|
|
1535
1681
|
port: resolveProviderPort(provider),
|
|
1536
1682
|
reconcileBaseUrl: provider.baseUrl,
|
|
@@ -1560,9 +1706,9 @@ function wrapProvider(params) {
|
|
|
1560
1706
|
id: "local",
|
|
1561
1707
|
model: params.canonicalModel,
|
|
1562
1708
|
dimensions: params.provider.dimensions,
|
|
1563
|
-
maxInputTokens: params.provider.maxInputTokens,
|
|
1564
|
-
embed:
|
|
1565
|
-
embedBatch:
|
|
1709
|
+
maxInputTokens: params.provider.maxInputTokens ?? 2044,
|
|
1710
|
+
embed: (input, callOptions) => withFacts(() => params.provider.embed(input, callOptions)),
|
|
1711
|
+
embedBatch: (inputs, callOptions) => withFacts(() => params.provider.embedBatch(inputs, callOptions)),
|
|
1566
1712
|
close: params.provider.close
|
|
1567
1713
|
};
|
|
1568
1714
|
Object.defineProperty(wrapped, LOCAL_EMBEDDING_RUNTIME_FACTS, {
|
|
@@ -1583,7 +1729,7 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
1583
1729
|
const local = readIdentityLocalOptions(options);
|
|
1584
1730
|
const embeddingModel = resolveLlamaCppEmbeddingModel(local);
|
|
1585
1731
|
const identity = resolveModelIdentity(local, options.dimensions);
|
|
1586
|
-
await prepareEmbeddingServer(options, embeddingModel.source
|
|
1732
|
+
await prepareEmbeddingServer(options, embeddingModel.source);
|
|
1587
1733
|
const genericAdapter = getEmbeddingProvider("openai-compatible", options.config);
|
|
1588
1734
|
if (!genericAdapter) throw new Error("OpenAI-compatible embedding transport is unavailable.");
|
|
1589
1735
|
const acquireLocalService = options.acquireLocalService;
|
|
@@ -1661,6 +1807,7 @@ async function resolveLlamaServerRuntimeApiKey(params) {
|
|
|
1661
1807
|
//#region extensions/llama-cpp/src/external-server/defaults.ts
|
|
1662
1808
|
const LLAMA_SERVER_DEFAULT_ORIGIN = "http://127.0.0.1:8080";
|
|
1663
1809
|
const LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR = "LLAMA_SERVER_API_KEY";
|
|
1810
|
+
const LLAMA_SERVER_DISCOVERY_TIMEOUT_MS = 5e3;
|
|
1664
1811
|
//#endregion
|
|
1665
1812
|
//#region extensions/llama-cpp/src/external-server/endpoint.ts
|
|
1666
1813
|
/** Resolves the server origin and its OpenAI-compatible `/v1` inference base. */
|
|
@@ -1773,44 +1920,31 @@ function buildLlamaServerProviderConfig(params) {
|
|
|
1773
1920
|
/** Discovers llama-server models without loading, waking, or unloading them. */
|
|
1774
1921
|
async function discoverLlamaServer(params) {
|
|
1775
1922
|
const endpoint = resolveLlamaServerEndpoint(params.baseUrl);
|
|
1776
|
-
const
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
baseUrl: endpoint.inferenceBaseUrl,
|
|
1789
|
-
serverBaseUrl: endpoint.origin,
|
|
1790
|
-
apiKey: params.apiKey,
|
|
1791
|
-
headers: params.headers,
|
|
1792
|
-
label: "llama-server",
|
|
1793
|
-
healthPath: "/health",
|
|
1794
|
-
modelsPathOrder: "server-first",
|
|
1795
|
-
routerModelProps: true,
|
|
1796
|
-
timeoutMs: params.timeoutMs ?? 5e3,
|
|
1797
|
-
signal: params.signal,
|
|
1798
|
-
rawResult: true
|
|
1799
|
-
});
|
|
1800
|
-
if (result.kind !== "success") return {
|
|
1801
|
-
...result,
|
|
1802
|
-
endpoint
|
|
1803
|
-
};
|
|
1804
|
-
return {
|
|
1805
|
-
kind: "success",
|
|
1806
|
-
endpoint,
|
|
1807
|
-
models: result.rows.flatMap(({ model, props }) => {
|
|
1808
|
-
const mapped = mapLlamaServerModel(model, props);
|
|
1809
|
-
return mapped ? [mapped] : [];
|
|
1810
|
-
})
|
|
1811
|
-
};
|
|
1812
|
-
}
|
|
1923
|
+
const result = await discoverOpenAICompatibleLocalModels({
|
|
1924
|
+
baseUrl: endpoint.inferenceBaseUrl,
|
|
1925
|
+
serverBaseUrl: endpoint.origin,
|
|
1926
|
+
apiKey: params.apiKey,
|
|
1927
|
+
headers: params.headers,
|
|
1928
|
+
label: "llama-server",
|
|
1929
|
+
healthPath: "/health",
|
|
1930
|
+
modelsPathOrder: "server-first",
|
|
1931
|
+
routerModelProps: true,
|
|
1932
|
+
timeoutMs: LLAMA_SERVER_DISCOVERY_TIMEOUT_MS,
|
|
1933
|
+
signal: params.signal,
|
|
1934
|
+
rawResult: true
|
|
1813
1935
|
});
|
|
1936
|
+
if (result.kind !== "success") return {
|
|
1937
|
+
...result,
|
|
1938
|
+
endpoint
|
|
1939
|
+
};
|
|
1940
|
+
return {
|
|
1941
|
+
kind: "success",
|
|
1942
|
+
endpoint,
|
|
1943
|
+
models: result.rows.flatMap(({ model, props }) => {
|
|
1944
|
+
const mapped = mapLlamaServerModel(model, props);
|
|
1945
|
+
return mapped ? [mapped] : [];
|
|
1946
|
+
})
|
|
1947
|
+
};
|
|
1814
1948
|
}
|
|
1815
1949
|
//#endregion
|
|
1816
1950
|
//#region extensions/llama-cpp/src/external-server/provider.ts
|
|
@@ -1832,8 +1966,7 @@ async function discoverLlamaServerProvider(ctx) {
|
|
|
1832
1966
|
const discovery = await discoverLlamaServer({
|
|
1833
1967
|
baseUrl: configured?.baseUrl,
|
|
1834
1968
|
apiKey,
|
|
1835
|
-
headers
|
|
1836
|
-
cacheTtlMs: 0
|
|
1969
|
+
headers
|
|
1837
1970
|
});
|
|
1838
1971
|
if (discovery.kind !== "success") {
|
|
1839
1972
|
if (!configured && !apiKey && !headers) return null;
|
|
@@ -1860,8 +1993,7 @@ async function prepareLlamaServerDynamicModel(ctx) {
|
|
|
1860
1993
|
const discovery = await discoverLlamaServer({
|
|
1861
1994
|
baseUrl: ctx.providerConfig?.baseUrl,
|
|
1862
1995
|
apiKey: hasLlamaServerAuthorizationHeader(headers) ? void 0 : apiKey,
|
|
1863
|
-
headers
|
|
1864
|
-
cacheTtlMs: 0
|
|
1996
|
+
headers
|
|
1865
1997
|
});
|
|
1866
1998
|
const model = discovery.kind === "success" ? discovery.models.find((entry) => entry.config.id === ctx.modelId) : void 0;
|
|
1867
1999
|
if (!model) return;
|
|
@@ -2006,8 +2138,7 @@ async function discoverForSetup(ctx) {
|
|
|
2006
2138
|
baseUrl: provider?.baseUrl ?? "http://127.0.0.1:8080",
|
|
2007
2139
|
apiKey,
|
|
2008
2140
|
headers,
|
|
2009
|
-
signal: ctx.signal
|
|
2010
|
-
cacheTtlMs: 0
|
|
2141
|
+
signal: ctx.signal
|
|
2011
2142
|
});
|
|
2012
2143
|
return discovery.kind === "success" ? discovery : null;
|
|
2013
2144
|
} catch {
|
|
@@ -2110,8 +2241,7 @@ async function runLlamaServerSetup(ctx) {
|
|
|
2110
2241
|
baseUrl: endpoint.inferenceBaseUrl,
|
|
2111
2242
|
apiKey,
|
|
2112
2243
|
headers,
|
|
2113
|
-
signal: ctx.signal
|
|
2114
|
-
cacheTtlMs: 0
|
|
2244
|
+
signal: ctx.signal
|
|
2115
2245
|
});
|
|
2116
2246
|
if (discovery.kind !== "success") throw new Error(describeDiscoveryFailure(discovery));
|
|
2117
2247
|
const modelId = selectSetupModelId(discovery);
|
|
@@ -2170,21 +2300,14 @@ async function validateNonInteractiveDiscovery(ctx) {
|
|
|
2170
2300
|
const discovery = await discoverLlamaServer({
|
|
2171
2301
|
baseUrl,
|
|
2172
2302
|
apiKey,
|
|
2173
|
-
headers
|
|
2174
|
-
cacheTtlMs: 0
|
|
2303
|
+
headers
|
|
2175
2304
|
});
|
|
2176
|
-
if (discovery.kind !== "success")
|
|
2177
|
-
ctx.runtime.error(describeDiscoveryFailure(discovery));
|
|
2178
|
-
ctx.runtime.exit(1);
|
|
2179
|
-
return null;
|
|
2180
|
-
}
|
|
2305
|
+
if (discovery.kind !== "success") throw new Error(describeDiscoveryFailure(discovery));
|
|
2181
2306
|
const requestedModelId = normalizeOptionalSecretInput(ctx.opts.customModelId);
|
|
2182
2307
|
const modelId = requestedModelId ?? selectSetupModelId(discovery);
|
|
2183
2308
|
if (!modelId || !discovery.models.some((model) => model.config.id === modelId)) {
|
|
2184
2309
|
const available = discovery.models.map((model) => model.config.id).join(", ");
|
|
2185
|
-
|
|
2186
|
-
ctx.runtime.exit(1);
|
|
2187
|
-
return null;
|
|
2310
|
+
throw new Error(requestedModelId ? `llama-server model ${requestedModelId} was not found. Available models: ${available}` : `No llama-server text models were found at ${discovery.endpoint.origin}.`);
|
|
2188
2311
|
}
|
|
2189
2312
|
return {
|
|
2190
2313
|
discovery,
|
|
@@ -2194,12 +2317,12 @@ async function validateNonInteractiveDiscovery(ctx) {
|
|
|
2194
2317
|
};
|
|
2195
2318
|
}
|
|
2196
2319
|
async function validateLlamaServerNonInteractive(ctx) {
|
|
2197
|
-
|
|
2320
|
+
await validateNonInteractiveDiscovery(ctx);
|
|
2321
|
+
return true;
|
|
2198
2322
|
}
|
|
2199
2323
|
/** Non-interactive setup with optional API-key persistence. */
|
|
2200
2324
|
async function configureLlamaServerNonInteractive(ctx) {
|
|
2201
2325
|
const validated = await validateNonInteractiveDiscovery(ctx);
|
|
2202
|
-
if (!validated) return null;
|
|
2203
2326
|
const providerConfig = buildExistingProviderConfig({
|
|
2204
2327
|
config: ctx.config,
|
|
2205
2328
|
...validated
|
|
@@ -2285,13 +2408,9 @@ function readPrimaryModel(config) {
|
|
|
2285
2408
|
const model = config.agents?.defaults?.model;
|
|
2286
2409
|
return typeof model === "string" ? model : model?.primary;
|
|
2287
2410
|
}
|
|
2288
|
-
function configuredCandidates(config
|
|
2289
|
-
const
|
|
2290
|
-
|
|
2291
|
-
const provider = buildLlamaCppProviderConfig({
|
|
2292
|
-
existing: managedExisting,
|
|
2293
|
-
...managedExisting && scope === "detection" ? { modelInventory: managedExisting.models } : {}
|
|
2294
|
-
});
|
|
2411
|
+
function configuredCandidates(config) {
|
|
2412
|
+
const provider = config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2413
|
+
if (!provider?.localService) return [];
|
|
2295
2414
|
const primary = readPrimaryModel(config);
|
|
2296
2415
|
const primaryId = primary?.startsWith(`llama-cpp/`) ? primary.slice(LLAMA_CPP_PROVIDER_ID.length + 1) : void 0;
|
|
2297
2416
|
return provider.models.map((model) => ({
|
|
@@ -2346,7 +2465,7 @@ async function detectLlamaCppSetup(ctx) {
|
|
|
2346
2465
|
const command = existing?.localService?.command;
|
|
2347
2466
|
const presetPath = existing?.localService?.args?.find((_, index, args) => args[index - 1] === "--models-preset");
|
|
2348
2467
|
if (!command || !path.isAbsolute(command) || !await isFile(command) || !presetPath || !await isFile(presetPath)) return null;
|
|
2349
|
-
for (const candidate of configuredCandidates(ctx.config
|
|
2468
|
+
for (const candidate of configuredCandidates(ctx.config)) if (await resolveCachedCandidate(candidate, ctx.signal)) return {
|
|
2350
2469
|
modelRef: `${LLAMA_CPP_PROVIDER_ID}/${candidate.model.id}`,
|
|
2351
2470
|
detail: "Managed llama.cpp server ready"
|
|
2352
2471
|
};
|
|
@@ -2401,8 +2520,40 @@ async function resolveSetupPlan(ctx, candidates, embeddingModelIsDefault, localM
|
|
|
2401
2520
|
cachedPath: configuredPath
|
|
2402
2521
|
};
|
|
2403
2522
|
}
|
|
2404
|
-
const
|
|
2523
|
+
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2524
|
+
const provider = existing?.localService ? existing : buildLlamaCppProviderConfig();
|
|
2405
2525
|
const cacheDir = resolveLlamaCppModelCacheDir(provider);
|
|
2526
|
+
if (candidate) {
|
|
2527
|
+
const source = resolveLlamaCppModelSource(candidate.model);
|
|
2528
|
+
let size;
|
|
2529
|
+
try {
|
|
2530
|
+
if (path.isAbsolute(source) || !/^[a-z][a-z\d+.-]*:/iu.test(source)) {
|
|
2531
|
+
const cachedPath = await ensureLlamaCppModel({
|
|
2532
|
+
source,
|
|
2533
|
+
cacheDir,
|
|
2534
|
+
download: false,
|
|
2535
|
+
signal: ctx.signal
|
|
2536
|
+
});
|
|
2537
|
+
return {
|
|
2538
|
+
kind: "chat",
|
|
2539
|
+
candidate,
|
|
2540
|
+
cachedPath
|
|
2541
|
+
};
|
|
2542
|
+
}
|
|
2543
|
+
size = await resolveLlamaCppModelDownloadSize(source, cacheDir, ctx.signal);
|
|
2544
|
+
} catch (error) {
|
|
2545
|
+
ctx.signal?.throwIfAborted();
|
|
2546
|
+
await ctx.prompter.note(`Cannot use configured model ${candidate.model.name}: ${error instanceof Error ? error.message : String(error)} Check params.modelPath and retry llama.cpp setup.`, "Setup skipped");
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
return await ctx.prompter.confirm({
|
|
2550
|
+
message: `${runtimeNote ? `${runtimeNote}\n` : ""}Download ${candidate.model.name} (${size ? `${(size / BYTES_PER_GB).toFixed(1)} GB` : "size unknown"}), ${describeEmbeddingDownload(embeddingModelIsDefault)}, and the verified ${asset.backend.toUpperCase()} runtime on Gateway host ${os.hostname()}, then use this model?`,
|
|
2551
|
+
initialValue: false
|
|
2552
|
+
}) ? {
|
|
2553
|
+
kind: "chat",
|
|
2554
|
+
candidate
|
|
2555
|
+
} : void 0;
|
|
2556
|
+
}
|
|
2406
2557
|
const cachedModels = /* @__PURE__ */ new Map();
|
|
2407
2558
|
for (const recipe of resolveLlamaCppModelCandidates(hardware, asset.backend).recipes) {
|
|
2408
2559
|
const cached = await resolveCachedArtifact(resolveLlamaCppModelSource(recipe.model), cacheDir, ctx.signal);
|
|
@@ -2445,7 +2596,6 @@ async function resolveSetupPlan(ctx, candidates, embeddingModelIsDefault, localM
|
|
|
2445
2596
|
await ctx.prompter.note(recommendation.reason, "Setup skipped");
|
|
2446
2597
|
return;
|
|
2447
2598
|
}
|
|
2448
|
-
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2449
2599
|
if (localMemoryIntent && existing && (!existing.localService || existing.models.length > 0)) {
|
|
2450
2600
|
await ctx.prompter.note("Embedding-only setup cannot replace an existing llama.cpp server or configured llama.cpp chat routes. Move those routes to another provider, remove any existing server config, then retry llama.cpp setup.", "Setup skipped");
|
|
2451
2601
|
return;
|
|
@@ -2481,10 +2631,15 @@ async function runLlamaCppSetup(ctx) {
|
|
|
2481
2631
|
asset = selectLlamaServerAsset(hardware.platform, hardware.arch, { kind: "cpu" });
|
|
2482
2632
|
runtimeNote = `${error instanceof Error ? error.message : String(error)} This recommendation uses CPU execution.`;
|
|
2483
2633
|
}
|
|
2484
|
-
const plan = await resolveSetupPlan(ctx, configuredCandidates(ctx.config
|
|
2634
|
+
const plan = await resolveSetupPlan(ctx, configuredCandidates(ctx.config), embeddingModel.isDefault, embeddingSetup.localMemoryIntent, hardware, asset, runtimeNote);
|
|
2485
2635
|
if (!plan) return { profiles: [] };
|
|
2486
2636
|
const progress = ctx.prompter.progress("Preparing managed llama.cpp server…");
|
|
2487
2637
|
try {
|
|
2638
|
+
await ensureLlamaServerInstalled({
|
|
2639
|
+
asset,
|
|
2640
|
+
signal: ctx.signal,
|
|
2641
|
+
onProgress: (status) => progress.update(formatDownloadProgress("llama.cpp runtime", status))
|
|
2642
|
+
});
|
|
2488
2643
|
let chatModel;
|
|
2489
2644
|
if (plan.kind === "chat") {
|
|
2490
2645
|
const chatModelPath = plan.cachedPath ?? await ensureLlamaCppModel({
|
|
@@ -2514,7 +2669,6 @@ async function runLlamaCppSetup(ctx) {
|
|
|
2514
2669
|
const managed = await prepareManagedLlamaServer({
|
|
2515
2670
|
chatModel,
|
|
2516
2671
|
configuredChatModelIds: plan.kind === "chat" ? plan.candidate.provider.models.map((model) => model.id) : [],
|
|
2517
|
-
embeddingModelIsDefault: embeddingModel.isDefault,
|
|
2518
2672
|
embeddingModelPath,
|
|
2519
2673
|
asset,
|
|
2520
2674
|
isolated: true,
|
|
@@ -2535,7 +2689,7 @@ async function runLlamaCppSetup(ctx) {
|
|
|
2535
2689
|
} catch (error) {
|
|
2536
2690
|
progress.stop("llama.cpp setup failed");
|
|
2537
2691
|
const detail = error instanceof Error ? error.message : String(error);
|
|
2538
|
-
throw new Error(`Managed llama.cpp setup failed. Run openclaw doctor, fix the reported runtime or model issue, then retry. ${detail}`, { cause: error });
|
|
2692
|
+
throw new Error(error instanceof UnsupportedLlamaServerHostError ? `Managed llama.cpp setup is unavailable on this host. ${detail}` : `Managed llama.cpp setup failed. Run openclaw doctor, fix the reported runtime or model issue, then retry. ${detail}`, { cause: error });
|
|
2539
2693
|
}
|
|
2540
2694
|
}
|
|
2541
2695
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as resolveManagedLlamaCppProviderConfig, t as MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE } from "./.setup/managed-provider-config-
|
|
1
|
+
import { n as resolveManagedLlamaCppProviderConfig, t as MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE } from "./.setup/managed-provider-config-D0abOkC_.mjs";
|
|
2
2
|
//#region extensions/llama-cpp/provider-policy-api.ts
|
|
3
3
|
function inspectEmbeddingProviderSetup(params) {
|
|
4
4
|
if (params.provider !== "local") return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/llama-cpp-provider",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.5-beta.1",
|
|
4
4
|
"description": "OpenClaw provider for managed and external llama.cpp servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"minHostVersion": ">=2026.6.2"
|
|
22
22
|
},
|
|
23
23
|
"compat": {
|
|
24
|
-
"pluginApi": ">=2026.10.
|
|
24
|
+
"pluginApi": ">=2026.10.5-beta.1"
|
|
25
25
|
},
|
|
26
26
|
"build": {
|
|
27
|
-
"openclawVersion": "2026.10.
|
|
27
|
+
"openclawVersion": "2026.10.5-beta.1"
|
|
28
28
|
},
|
|
29
29
|
"release": {
|
|
30
30
|
"bundleRuntimeDependencies": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
]
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@openclaw/fs-safe": "0.
|
|
39
|
+
"@openclaw/fs-safe": "0.25.0"
|
|
40
40
|
},
|
|
41
41
|
"files": [
|
|
42
42
|
"dist/**",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"assets/activity.svg"
|
|
47
47
|
],
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"openclaw": ">=2026.10.
|
|
49
|
+
"openclaw": ">=2026.10.5-beta.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"openclaw": {
|