@openclaw/llama-cpp-provider 2026.10.1 → 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/index.js +223 -95
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -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, {
|
|
@@ -836,6 +860,60 @@ function buildLlamaServerPreset(existing, params) {
|
|
|
836
860
|
return header + (header && !/[\r\n]$/u.test(header) ? newline : "") + orderedSections.map((section) => section.replace(/[\r\n]+$/u, "")).join(newline + newline) + newline;
|
|
837
861
|
}
|
|
838
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
|
|
839
917
|
//#region extensions/llama-cpp/src/hardware.ts
|
|
840
918
|
const GIB$1 = 1024 ** 3;
|
|
841
919
|
const MIB = 1024 ** 2;
|
|
@@ -1128,7 +1206,7 @@ function recommendLlamaCppModel(hardware, backend, cached = {}) {
|
|
|
1128
1206
|
}
|
|
1129
1207
|
return {
|
|
1130
1208
|
kind: "unavailable",
|
|
1131
|
-
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.`
|
|
1132
1210
|
};
|
|
1133
1211
|
}
|
|
1134
1212
|
//#endregion
|
|
@@ -1262,6 +1340,34 @@ async function resolveModelArtifact(source, signal) {
|
|
|
1262
1340
|
}
|
|
1263
1341
|
throw new Error(`Unsupported remote model URI: ${source}`);
|
|
1264
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
|
+
}
|
|
1265
1371
|
async function ensureLlamaCppModel(params) {
|
|
1266
1372
|
const localSource = resolveHomePath(params.source);
|
|
1267
1373
|
if (!/^(?:hf|huggingface|https):/iu.test(localSource)) {
|
|
@@ -1269,9 +1375,7 @@ async function ensureLlamaCppModel(params) {
|
|
|
1269
1375
|
await assertGguf(localPath);
|
|
1270
1376
|
return localPath;
|
|
1271
1377
|
}
|
|
1272
|
-
const
|
|
1273
|
-
const artifact = resolvedModelArtifacts.get(artifactCacheKey) ?? await resolveModelArtifact(localSource, params.signal);
|
|
1274
|
-
resolvedModelArtifacts.set(artifactCacheKey, artifact);
|
|
1378
|
+
const artifact = await resolveCachedModelArtifact(localSource, params.cacheDir, params.signal);
|
|
1275
1379
|
const destination = path.join(params.cacheDir, artifact.fileName);
|
|
1276
1380
|
const load = modelPromises.get(destination) ?? (async () => {
|
|
1277
1381
|
const exists = await fs.stat(destination).then((stat) => stat.isFile()).catch(() => false);
|
|
@@ -1357,8 +1461,16 @@ async function findAvailableLlamaServerPort(preferred = LLAMA_CPP_DEFAULT_PORT)
|
|
|
1357
1461
|
}
|
|
1358
1462
|
async function prepareManagedLlamaServer(params) {
|
|
1359
1463
|
params.signal?.throwIfAborted();
|
|
1360
|
-
|
|
1361
|
-
|
|
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,
|
|
1362
1474
|
signal: params.signal,
|
|
1363
1475
|
onProgress: params.onProgress
|
|
1364
1476
|
})).command;
|
|
@@ -1371,6 +1483,13 @@ async function prepareManagedLlamaServer(params) {
|
|
|
1371
1483
|
healthUrl: params.localService?.healthUrl ?? `${rootUrl}/health`
|
|
1372
1484
|
};
|
|
1373
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
|
+
});
|
|
1374
1493
|
if (params.localService && !configuredPreset && !params.isolated) {
|
|
1375
1494
|
await runPresetTransition(async () => {
|
|
1376
1495
|
presetState.desiredRevisions.delete(reconcileOrigin);
|
|
@@ -1588,8 +1707,8 @@ function wrapProvider(params) {
|
|
|
1588
1707
|
model: params.canonicalModel,
|
|
1589
1708
|
dimensions: params.provider.dimensions,
|
|
1590
1709
|
maxInputTokens: params.provider.maxInputTokens ?? 2044,
|
|
1591
|
-
embed:
|
|
1592
|
-
embedBatch:
|
|
1710
|
+
embed: (input, callOptions) => withFacts(() => params.provider.embed(input, callOptions)),
|
|
1711
|
+
embedBatch: (inputs, callOptions) => withFacts(() => params.provider.embedBatch(inputs, callOptions)),
|
|
1593
1712
|
close: params.provider.close
|
|
1594
1713
|
};
|
|
1595
1714
|
Object.defineProperty(wrapped, LOCAL_EMBEDDING_RUNTIME_FACTS, {
|
|
@@ -1688,6 +1807,7 @@ async function resolveLlamaServerRuntimeApiKey(params) {
|
|
|
1688
1807
|
//#region extensions/llama-cpp/src/external-server/defaults.ts
|
|
1689
1808
|
const LLAMA_SERVER_DEFAULT_ORIGIN = "http://127.0.0.1:8080";
|
|
1690
1809
|
const LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR = "LLAMA_SERVER_API_KEY";
|
|
1810
|
+
const LLAMA_SERVER_DISCOVERY_TIMEOUT_MS = 5e3;
|
|
1691
1811
|
//#endregion
|
|
1692
1812
|
//#region extensions/llama-cpp/src/external-server/endpoint.ts
|
|
1693
1813
|
/** Resolves the server origin and its OpenAI-compatible `/v1` inference base. */
|
|
@@ -1800,44 +1920,31 @@ function buildLlamaServerProviderConfig(params) {
|
|
|
1800
1920
|
/** Discovers llama-server models without loading, waking, or unloading them. */
|
|
1801
1921
|
async function discoverLlamaServer(params) {
|
|
1802
1922
|
const endpoint = resolveLlamaServerEndpoint(params.baseUrl);
|
|
1803
|
-
const
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
baseUrl: endpoint.inferenceBaseUrl,
|
|
1816
|
-
serverBaseUrl: endpoint.origin,
|
|
1817
|
-
apiKey: params.apiKey,
|
|
1818
|
-
headers: params.headers,
|
|
1819
|
-
label: "llama-server",
|
|
1820
|
-
healthPath: "/health",
|
|
1821
|
-
modelsPathOrder: "server-first",
|
|
1822
|
-
routerModelProps: true,
|
|
1823
|
-
timeoutMs: params.timeoutMs ?? 5e3,
|
|
1824
|
-
signal: params.signal,
|
|
1825
|
-
rawResult: true
|
|
1826
|
-
});
|
|
1827
|
-
if (result.kind !== "success") return {
|
|
1828
|
-
...result,
|
|
1829
|
-
endpoint
|
|
1830
|
-
};
|
|
1831
|
-
return {
|
|
1832
|
-
kind: "success",
|
|
1833
|
-
endpoint,
|
|
1834
|
-
models: result.rows.flatMap(({ model, props }) => {
|
|
1835
|
-
const mapped = mapLlamaServerModel(model, props);
|
|
1836
|
-
return mapped ? [mapped] : [];
|
|
1837
|
-
})
|
|
1838
|
-
};
|
|
1839
|
-
}
|
|
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
|
|
1840
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
|
+
};
|
|
1841
1948
|
}
|
|
1842
1949
|
//#endregion
|
|
1843
1950
|
//#region extensions/llama-cpp/src/external-server/provider.ts
|
|
@@ -1859,8 +1966,7 @@ async function discoverLlamaServerProvider(ctx) {
|
|
|
1859
1966
|
const discovery = await discoverLlamaServer({
|
|
1860
1967
|
baseUrl: configured?.baseUrl,
|
|
1861
1968
|
apiKey,
|
|
1862
|
-
headers
|
|
1863
|
-
cacheTtlMs: 0
|
|
1969
|
+
headers
|
|
1864
1970
|
});
|
|
1865
1971
|
if (discovery.kind !== "success") {
|
|
1866
1972
|
if (!configured && !apiKey && !headers) return null;
|
|
@@ -1887,8 +1993,7 @@ async function prepareLlamaServerDynamicModel(ctx) {
|
|
|
1887
1993
|
const discovery = await discoverLlamaServer({
|
|
1888
1994
|
baseUrl: ctx.providerConfig?.baseUrl,
|
|
1889
1995
|
apiKey: hasLlamaServerAuthorizationHeader(headers) ? void 0 : apiKey,
|
|
1890
|
-
headers
|
|
1891
|
-
cacheTtlMs: 0
|
|
1996
|
+
headers
|
|
1892
1997
|
});
|
|
1893
1998
|
const model = discovery.kind === "success" ? discovery.models.find((entry) => entry.config.id === ctx.modelId) : void 0;
|
|
1894
1999
|
if (!model) return;
|
|
@@ -2033,8 +2138,7 @@ async function discoverForSetup(ctx) {
|
|
|
2033
2138
|
baseUrl: provider?.baseUrl ?? "http://127.0.0.1:8080",
|
|
2034
2139
|
apiKey,
|
|
2035
2140
|
headers,
|
|
2036
|
-
signal: ctx.signal
|
|
2037
|
-
cacheTtlMs: 0
|
|
2141
|
+
signal: ctx.signal
|
|
2038
2142
|
});
|
|
2039
2143
|
return discovery.kind === "success" ? discovery : null;
|
|
2040
2144
|
} catch {
|
|
@@ -2137,8 +2241,7 @@ async function runLlamaServerSetup(ctx) {
|
|
|
2137
2241
|
baseUrl: endpoint.inferenceBaseUrl,
|
|
2138
2242
|
apiKey,
|
|
2139
2243
|
headers,
|
|
2140
|
-
signal: ctx.signal
|
|
2141
|
-
cacheTtlMs: 0
|
|
2244
|
+
signal: ctx.signal
|
|
2142
2245
|
});
|
|
2143
2246
|
if (discovery.kind !== "success") throw new Error(describeDiscoveryFailure(discovery));
|
|
2144
2247
|
const modelId = selectSetupModelId(discovery);
|
|
@@ -2197,21 +2300,14 @@ async function validateNonInteractiveDiscovery(ctx) {
|
|
|
2197
2300
|
const discovery = await discoverLlamaServer({
|
|
2198
2301
|
baseUrl,
|
|
2199
2302
|
apiKey,
|
|
2200
|
-
headers
|
|
2201
|
-
cacheTtlMs: 0
|
|
2303
|
+
headers
|
|
2202
2304
|
});
|
|
2203
|
-
if (discovery.kind !== "success")
|
|
2204
|
-
ctx.runtime.error(describeDiscoveryFailure(discovery));
|
|
2205
|
-
ctx.runtime.exit(1);
|
|
2206
|
-
return null;
|
|
2207
|
-
}
|
|
2305
|
+
if (discovery.kind !== "success") throw new Error(describeDiscoveryFailure(discovery));
|
|
2208
2306
|
const requestedModelId = normalizeOptionalSecretInput(ctx.opts.customModelId);
|
|
2209
2307
|
const modelId = requestedModelId ?? selectSetupModelId(discovery);
|
|
2210
2308
|
if (!modelId || !discovery.models.some((model) => model.config.id === modelId)) {
|
|
2211
2309
|
const available = discovery.models.map((model) => model.config.id).join(", ");
|
|
2212
|
-
|
|
2213
|
-
ctx.runtime.exit(1);
|
|
2214
|
-
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}.`);
|
|
2215
2311
|
}
|
|
2216
2312
|
return {
|
|
2217
2313
|
discovery,
|
|
@@ -2221,12 +2317,12 @@ async function validateNonInteractiveDiscovery(ctx) {
|
|
|
2221
2317
|
};
|
|
2222
2318
|
}
|
|
2223
2319
|
async function validateLlamaServerNonInteractive(ctx) {
|
|
2224
|
-
|
|
2320
|
+
await validateNonInteractiveDiscovery(ctx);
|
|
2321
|
+
return true;
|
|
2225
2322
|
}
|
|
2226
2323
|
/** Non-interactive setup with optional API-key persistence. */
|
|
2227
2324
|
async function configureLlamaServerNonInteractive(ctx) {
|
|
2228
2325
|
const validated = await validateNonInteractiveDiscovery(ctx);
|
|
2229
|
-
if (!validated) return null;
|
|
2230
2326
|
const providerConfig = buildExistingProviderConfig({
|
|
2231
2327
|
config: ctx.config,
|
|
2232
2328
|
...validated
|
|
@@ -2312,13 +2408,9 @@ function readPrimaryModel(config) {
|
|
|
2312
2408
|
const model = config.agents?.defaults?.model;
|
|
2313
2409
|
return typeof model === "string" ? model : model?.primary;
|
|
2314
2410
|
}
|
|
2315
|
-
function configuredCandidates(config
|
|
2316
|
-
const
|
|
2317
|
-
|
|
2318
|
-
const provider = buildLlamaCppProviderConfig({
|
|
2319
|
-
existing: managedExisting,
|
|
2320
|
-
...managedExisting && scope === "detection" ? { modelInventory: managedExisting.models } : {}
|
|
2321
|
-
});
|
|
2411
|
+
function configuredCandidates(config) {
|
|
2412
|
+
const provider = config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2413
|
+
if (!provider?.localService) return [];
|
|
2322
2414
|
const primary = readPrimaryModel(config);
|
|
2323
2415
|
const primaryId = primary?.startsWith(`llama-cpp/`) ? primary.slice(LLAMA_CPP_PROVIDER_ID.length + 1) : void 0;
|
|
2324
2416
|
return provider.models.map((model) => ({
|
|
@@ -2373,7 +2465,7 @@ async function detectLlamaCppSetup(ctx) {
|
|
|
2373
2465
|
const command = existing?.localService?.command;
|
|
2374
2466
|
const presetPath = existing?.localService?.args?.find((_, index, args) => args[index - 1] === "--models-preset");
|
|
2375
2467
|
if (!command || !path.isAbsolute(command) || !await isFile(command) || !presetPath || !await isFile(presetPath)) return null;
|
|
2376
|
-
for (const candidate of configuredCandidates(ctx.config
|
|
2468
|
+
for (const candidate of configuredCandidates(ctx.config)) if (await resolveCachedCandidate(candidate, ctx.signal)) return {
|
|
2377
2469
|
modelRef: `${LLAMA_CPP_PROVIDER_ID}/${candidate.model.id}`,
|
|
2378
2470
|
detail: "Managed llama.cpp server ready"
|
|
2379
2471
|
};
|
|
@@ -2428,8 +2520,40 @@ async function resolveSetupPlan(ctx, candidates, embeddingModelIsDefault, localM
|
|
|
2428
2520
|
cachedPath: configuredPath
|
|
2429
2521
|
};
|
|
2430
2522
|
}
|
|
2431
|
-
const
|
|
2523
|
+
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2524
|
+
const provider = existing?.localService ? existing : buildLlamaCppProviderConfig();
|
|
2432
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
|
+
}
|
|
2433
2557
|
const cachedModels = /* @__PURE__ */ new Map();
|
|
2434
2558
|
for (const recipe of resolveLlamaCppModelCandidates(hardware, asset.backend).recipes) {
|
|
2435
2559
|
const cached = await resolveCachedArtifact(resolveLlamaCppModelSource(recipe.model), cacheDir, ctx.signal);
|
|
@@ -2472,7 +2596,6 @@ async function resolveSetupPlan(ctx, candidates, embeddingModelIsDefault, localM
|
|
|
2472
2596
|
await ctx.prompter.note(recommendation.reason, "Setup skipped");
|
|
2473
2597
|
return;
|
|
2474
2598
|
}
|
|
2475
|
-
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2476
2599
|
if (localMemoryIntent && existing && (!existing.localService || existing.models.length > 0)) {
|
|
2477
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");
|
|
2478
2601
|
return;
|
|
@@ -2508,10 +2631,15 @@ async function runLlamaCppSetup(ctx) {
|
|
|
2508
2631
|
asset = selectLlamaServerAsset(hardware.platform, hardware.arch, { kind: "cpu" });
|
|
2509
2632
|
runtimeNote = `${error instanceof Error ? error.message : String(error)} This recommendation uses CPU execution.`;
|
|
2510
2633
|
}
|
|
2511
|
-
const plan = await resolveSetupPlan(ctx, configuredCandidates(ctx.config
|
|
2634
|
+
const plan = await resolveSetupPlan(ctx, configuredCandidates(ctx.config), embeddingModel.isDefault, embeddingSetup.localMemoryIntent, hardware, asset, runtimeNote);
|
|
2512
2635
|
if (!plan) return { profiles: [] };
|
|
2513
2636
|
const progress = ctx.prompter.progress("Preparing managed llama.cpp server…");
|
|
2514
2637
|
try {
|
|
2638
|
+
await ensureLlamaServerInstalled({
|
|
2639
|
+
asset,
|
|
2640
|
+
signal: ctx.signal,
|
|
2641
|
+
onProgress: (status) => progress.update(formatDownloadProgress("llama.cpp runtime", status))
|
|
2642
|
+
});
|
|
2515
2643
|
let chatModel;
|
|
2516
2644
|
if (plan.kind === "chat") {
|
|
2517
2645
|
const chatModelPath = plan.cachedPath ?? await ensureLlamaCppModel({
|
|
@@ -2561,7 +2689,7 @@ async function runLlamaCppSetup(ctx) {
|
|
|
2561
2689
|
} catch (error) {
|
|
2562
2690
|
progress.stop("llama.cpp setup failed");
|
|
2563
2691
|
const detail = error instanceof Error ? error.message : String(error);
|
|
2564
|
-
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 });
|
|
2565
2693
|
}
|
|
2566
2694
|
}
|
|
2567
2695
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/llama-cpp-provider",
|
|
3
|
-
"version": "2026.10.1",
|
|
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.1"
|
|
24
|
+
"pluginApi": ">=2026.10.5-beta.1"
|
|
25
25
|
},
|
|
26
26
|
"build": {
|
|
27
|
-
"openclawVersion": "2026.10.1"
|
|
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.1"
|
|
49
|
+
"openclaw": ">=2026.10.5-beta.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"openclaw": {
|