@openclaw/llama-cpp-provider 2026.8.1-beta.3 → 2026.8.2
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/README.md
CHANGED
|
@@ -25,6 +25,13 @@ downloads Gemma 4 E4B IT Q4_K_M (approximately 5.0 GB) plus EmbeddingGemma
|
|
|
25
25
|
(approximately 0.3 GB). The default chat download is offered only on machines
|
|
26
26
|
with at least 16 GiB of RAM.
|
|
27
27
|
|
|
28
|
+
When local memory search is configured and chat setup is unavailable or
|
|
29
|
+
declined, OpenClaw offers a separate embedding-only setup. After explicit
|
|
30
|
+
consent, it installs only the server and EmbeddingGemma. It leaves the current
|
|
31
|
+
chat model unchanged. Move any llama.cpp chat routes and remove its configured
|
|
32
|
+
chat model entries first. Remove an existing external server config before
|
|
33
|
+
retrying embedding-only setup.
|
|
34
|
+
|
|
28
35
|
Custom GGUF models remain supported through `params.modelPath`. Rerun llama.cpp
|
|
29
36
|
setup after changing the model so OpenClaw can verify the file and regenerate
|
|
30
37
|
the managed router preset.
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as resolveLegacyLlamaCppModelCacheDir, D as resolveLlamaCppModelSource, E as resolveLlamaCppModelCacheDir, O as resolveLlamaCppSyntheticApiKey, S as resolveHomePath, T as resolveLlamaCppEmbeddingModel, _ as LLAMA_CPP_PROVIDER_ID, a as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL, b as meetsLlamaCppDefaultModelRamFloor, c as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256, d as DEFAULT_LLAMA_CPP_MODEL_ID, f as DEFAULT_LLAMA_CPP_MODEL_REVISION, g as LLAMA_CPP_DEFAULT_PORT, i as DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE, l as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES, m as DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES, n as resolveManagedLlamaCppProviderConfig, o as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID, p as DEFAULT_LLAMA_CPP_MODEL_SHA256, s as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION, u as DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE, v as LLAMA_CPP_PROVIDER_LABEL, w as resolveLlamaCppDataDir, x as resolveCachedLlamaCppModelPath, y as buildLlamaCppProviderConfig } from "./managed-provider-config-Ovg5QQxD.js";
|
|
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";
|
|
5
|
-
import { asBoolean, asOptionalRecord, asPositiveSafeInteger, isRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
6
5
|
import os from "node:os";
|
|
6
|
+
import { asBoolean, asOptionalRecord, asPositiveSafeInteger, isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
7
|
import { execFile } from "node:child_process";
|
|
8
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
9
9
|
import fs from "node:fs";
|
|
@@ -22,9 +22,10 @@ import { SELF_HOSTED_DEFAULT_CONTEXT_WINDOW, SELF_HOSTED_DEFAULT_COST, SELF_HOST
|
|
|
22
22
|
import { selectPreferredLocalModelId } from "openclaw/plugin-sdk/provider-model-shared";
|
|
23
23
|
import { streamSimple } from "openclaw/plugin-sdk/llm";
|
|
24
24
|
import { setQwenChatTemplateThinking } from "openclaw/plugin-sdk/provider-stream-shared";
|
|
25
|
+
import { listAgentIds, resolveAgentConfig } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
25
26
|
//#region extensions/llama-cpp/src/llama-server-assets.ts
|
|
26
|
-
const LLAMA_SERVER_RELEASE = "
|
|
27
|
-
const LLAMA_SERVER_COMMIT = "
|
|
27
|
+
const LLAMA_SERVER_RELEASE = "b10534";
|
|
28
|
+
const LLAMA_SERVER_COMMIT = "2b5621094ef383cdcd8428ef6d22efe5df976532";
|
|
28
29
|
const LLAMA_SERVER_ASSETS = [
|
|
29
30
|
{
|
|
30
31
|
platform: "darwin",
|
|
@@ -32,7 +33,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
32
33
|
backend: "metal",
|
|
33
34
|
archive: "tar.gz",
|
|
34
35
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-arm64.tar.gz`,
|
|
35
|
-
sha256: "
|
|
36
|
+
sha256: "51f193eef26b053554e288fb924b24d41d3d7b2bafa338c19e2817fa793d5e86",
|
|
36
37
|
executable: "llama-server"
|
|
37
38
|
},
|
|
38
39
|
{
|
|
@@ -41,7 +42,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
41
42
|
backend: "cpu",
|
|
42
43
|
archive: "tar.gz",
|
|
43
44
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-x64.tar.gz`,
|
|
44
|
-
sha256: "
|
|
45
|
+
sha256: "69b13035f4301354922a8cfacd1bcf2bb2de4ff0c2e19fedb44963378ff53dc5",
|
|
45
46
|
executable: "llama-server"
|
|
46
47
|
},
|
|
47
48
|
{
|
|
@@ -50,7 +51,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
50
51
|
backend: "cpu",
|
|
51
52
|
archive: "tar.gz",
|
|
52
53
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-arm64.tar.gz`,
|
|
53
|
-
sha256: "
|
|
54
|
+
sha256: "66535de5cb9293c075a1951c51a3b2ae6f1899623e21177845f6d2a73b78c94e",
|
|
54
55
|
executable: "llama-server"
|
|
55
56
|
},
|
|
56
57
|
{
|
|
@@ -59,7 +60,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
59
60
|
backend: "cpu",
|
|
60
61
|
archive: "tar.gz",
|
|
61
62
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-x64.tar.gz`,
|
|
62
|
-
sha256: "
|
|
63
|
+
sha256: "cc6a12b026edcf1b211be2bb7366c5dadcad778fd8f13019d0694038053d5e4a",
|
|
63
64
|
executable: "llama-server"
|
|
64
65
|
},
|
|
65
66
|
{
|
|
@@ -68,7 +69,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
68
69
|
backend: "cpu",
|
|
69
70
|
archive: "zip",
|
|
70
71
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-arm64.zip`,
|
|
71
|
-
sha256: "
|
|
72
|
+
sha256: "d33618b10fda35d34d85da60926c6c470f98f3f66ce6b52c3c1f583461416012",
|
|
72
73
|
executable: "llama-server.exe"
|
|
73
74
|
},
|
|
74
75
|
{
|
|
@@ -77,7 +78,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
77
78
|
backend: "cpu",
|
|
78
79
|
archive: "zip",
|
|
79
80
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-x64.zip`,
|
|
80
|
-
sha256: "
|
|
81
|
+
sha256: "295ae03ad58d9276afa36f5f8d111d67fc1491c7aff3a3e6d13051a772f93c21",
|
|
81
82
|
executable: "llama-server.exe"
|
|
82
83
|
}
|
|
83
84
|
];
|
|
@@ -96,7 +97,7 @@ function resolveManagedLlamaServerPaths(asset = selectLlamaServerAsset()) {
|
|
|
96
97
|
}
|
|
97
98
|
//#endregion
|
|
98
99
|
//#region extensions/llama-cpp/src/llama-server-install.ts
|
|
99
|
-
const DOWNLOAD_TIMEOUT_MS =
|
|
100
|
+
const DOWNLOAD_TIMEOUT_MS = 18e5;
|
|
100
101
|
const VERSION_TIMEOUT_MS = 15e3;
|
|
101
102
|
const installationPromises = /* @__PURE__ */ new Map();
|
|
102
103
|
function compareVersion(left, right) {
|
|
@@ -158,15 +159,12 @@ async function downloadVerifiedFile(params) {
|
|
|
158
159
|
const totalSize = params.expectedSize ?? (Number.isFinite(contentLength) && contentLength > 0 ? contentLength : 0);
|
|
159
160
|
const handle = await fsp.open(partialPath, "wx", 384);
|
|
160
161
|
const hash = createHash("sha256");
|
|
161
|
-
const reader = response.body.getReader();
|
|
162
162
|
let downloadedSize = 0;
|
|
163
163
|
let previousSize = 0;
|
|
164
164
|
let previousAt = Date.now();
|
|
165
165
|
let rollingBytesPerSecond = 0;
|
|
166
166
|
try {
|
|
167
|
-
for (
|
|
168
|
-
const { done, value } = await reader.read();
|
|
169
|
-
if (done) break;
|
|
167
|
+
for await (const value of response.body.values({ preventCancel: true })) {
|
|
170
168
|
const chunk = Buffer.from(value);
|
|
171
169
|
await handle.writeFile(chunk);
|
|
172
170
|
hash.update(chunk);
|
|
@@ -243,7 +241,10 @@ async function validateInstalledServer(command) {
|
|
|
243
241
|
} catch (error) {
|
|
244
242
|
throw formatRuntimeDependencyError(error);
|
|
245
243
|
}
|
|
246
|
-
|
|
244
|
+
const match = (version.split(/\r?\n/u, 1)[0]?.trim() ?? "").match(/^version: .+ \(build (\d+), commit ([a-f\d]{9})\)$/u);
|
|
245
|
+
const build = match?.[1] ? Number(match[1]) : void 0;
|
|
246
|
+
const commit = match?.[2];
|
|
247
|
+
if (build !== 10534 || commit !== "2b5621094ef383cdcd8428ef6d22efe5df976532".slice(0, 9)) throw new Error(`Unexpected llama-server build at ${command}: expected ${LLAMA_SERVER_RELEASE} (${LLAMA_SERVER_COMMIT.slice(0, 9)}), got ${version || "no version output"}`);
|
|
247
248
|
}
|
|
248
249
|
async function installLlamaServer(asset) {
|
|
249
250
|
assertSupportedLinuxRuntime(asset);
|
|
@@ -306,6 +307,8 @@ async function ensureLlamaServerInstalled() {
|
|
|
306
307
|
//#region extensions/llama-cpp/src/managed-server.ts
|
|
307
308
|
const modelPromises = /* @__PURE__ */ new Map();
|
|
308
309
|
const chatPreparationPromises = /* @__PURE__ */ new Map();
|
|
310
|
+
const presetWritePromises = /* @__PURE__ */ new Map();
|
|
311
|
+
const LLAMA_CPP_EMBEDDING_UBATCH_SIZE = 2048;
|
|
309
312
|
function parseHuggingFaceSource(source) {
|
|
310
313
|
const [pathPart, revisionPart] = source.replace(/^(?:hf|huggingface):(?:\/\/)?/iu, "").split("#", 2);
|
|
311
314
|
const [user, repositoryWithTag, ...fileParts] = (pathPart ?? "").split("/");
|
|
@@ -432,11 +435,13 @@ async function ensureLlamaCppModel(params) {
|
|
|
432
435
|
const pending = modelPromises.get(destination);
|
|
433
436
|
if (pending) return await pending;
|
|
434
437
|
const load = (async () => {
|
|
435
|
-
if (await fsp.stat(destination).then((stat) => stat.isFile()).catch(() => false))
|
|
436
|
-
if (
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
438
|
+
if (await fsp.stat(destination).then((stat) => stat.isFile()).catch(() => false)) {
|
|
439
|
+
if (artifact.expectedSha256) {
|
|
440
|
+
if (await sha256File(destination) === artifact.expectedSha256) return destination;
|
|
441
|
+
} else {
|
|
442
|
+
await assertGguf(destination);
|
|
443
|
+
return destination;
|
|
444
|
+
}
|
|
440
445
|
}
|
|
441
446
|
if (!params.download) throw new Error(`Model is not cached at ${destination}`);
|
|
442
447
|
await downloadVerifiedFile({
|
|
@@ -462,18 +467,46 @@ function assertIniValue(value, label) {
|
|
|
462
467
|
if (/\r|\n/u.test(value)) throw new Error(`${label} cannot contain a newline`);
|
|
463
468
|
return value;
|
|
464
469
|
}
|
|
470
|
+
function renderChatModelSection(params) {
|
|
471
|
+
const id = assertIniValue(params.id, "llama.cpp model id");
|
|
472
|
+
if (id.includes("]")) throw new Error("llama.cpp model ids cannot contain ]");
|
|
473
|
+
return [
|
|
474
|
+
`[${id}]`,
|
|
475
|
+
`model = ${assertIniValue(params.modelPath, "llama.cpp model path")}`,
|
|
476
|
+
`ctx-size = ${params.contextSize ?? 65536}`,
|
|
477
|
+
`n-predict = ${params.maxTokens ?? 2048}`,
|
|
478
|
+
"jinja = true"
|
|
479
|
+
].join("\n");
|
|
480
|
+
}
|
|
481
|
+
function renderEmbeddingModelSection(params) {
|
|
482
|
+
return [
|
|
483
|
+
`[${DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID}]`,
|
|
484
|
+
`model = ${assertIniValue(params.modelPath, "llama.cpp embedding model path")}`,
|
|
485
|
+
...params.isDefault ? [`ubatch-size = ${LLAMA_CPP_EMBEDDING_UBATCH_SIZE}`] : [],
|
|
486
|
+
"embedding = true"
|
|
487
|
+
].join("\n");
|
|
488
|
+
}
|
|
489
|
+
function readModelSection(contents, id) {
|
|
490
|
+
if (!contents) return;
|
|
491
|
+
const lines = contents.split(/\r?\n/u);
|
|
492
|
+
const start = lines.indexOf(`[${id}]`);
|
|
493
|
+
if (start < 0) return;
|
|
494
|
+
let end = start + 1;
|
|
495
|
+
while (end < lines.length && !/^\[[^\]]+\]$/u.test(lines[end] ?? "")) end += 1;
|
|
496
|
+
return lines.slice(start, end).join("\n").trimEnd();
|
|
497
|
+
}
|
|
498
|
+
function readChatModelSection(contents) {
|
|
499
|
+
const id = contents?.split(/\r?\n/u).map((line) => /^\[([^\]]+)\]$/u.exec(line)?.[1]).find((candidate) => candidate && candidate !== "embeddinggemma-300m-qat-q8_0");
|
|
500
|
+
return id ? readModelSection(contents, id) : void 0;
|
|
501
|
+
}
|
|
465
502
|
function renderLlamaServerPreset(params) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
lines.push(`[${chatId}]`, `model = ${assertIniValue(params.chatModelPath, "llama.cpp model path")}`, `ctx-size = ${params.contextSize ?? 65536}`, `n-predict = ${params.maxTokens ?? 2048}`, "jinja = true", "");
|
|
474
|
-
}
|
|
475
|
-
lines.push(`[${embeddingId}]`, `model = ${assertIniValue(params.embeddingModelPath, "llama.cpp embedding model path")}`, "embedding = true", "");
|
|
476
|
-
return lines.join("\n");
|
|
503
|
+
return [
|
|
504
|
+
"version = 1",
|
|
505
|
+
"",
|
|
506
|
+
...params.chatSection ? [params.chatSection, ""] : [],
|
|
507
|
+
params.embeddingSection,
|
|
508
|
+
""
|
|
509
|
+
].join("\n");
|
|
477
510
|
}
|
|
478
511
|
async function writePreset(presetPath, contents) {
|
|
479
512
|
await fsp.mkdir(path.dirname(presetPath), { recursive: true });
|
|
@@ -481,6 +514,38 @@ async function writePreset(presetPath, contents) {
|
|
|
481
514
|
await fsp.writeFile(temporary, contents, { mode: 384 });
|
|
482
515
|
await fsp.rename(temporary, presetPath);
|
|
483
516
|
}
|
|
517
|
+
async function updatePreset(presetPath, params) {
|
|
518
|
+
const pending = (presetWritePromises.get(presetPath) ?? Promise.resolve()).catch(() => void 0).then(async () => {
|
|
519
|
+
const existing = await fsp.readFile(presetPath, "utf8").catch((error) => {
|
|
520
|
+
if (asOptionalRecord(error)?.code === "ENOENT") return;
|
|
521
|
+
throw error;
|
|
522
|
+
});
|
|
523
|
+
const chatSection = params.chatModel.mode === "preserve" ? readChatModelSection(existing) : params.chatModel.mode === "configure" ? renderChatModelSection({
|
|
524
|
+
id: params.chatModel.id,
|
|
525
|
+
modelPath: params.chatModel.path,
|
|
526
|
+
contextSize: params.chatModel.contextSize,
|
|
527
|
+
maxTokens: params.chatModel.maxTokens
|
|
528
|
+
}) : void 0;
|
|
529
|
+
const embeddingSection = params.embeddingModelPath ? renderEmbeddingModelSection({
|
|
530
|
+
isDefault: params.embeddingModelIsDefault,
|
|
531
|
+
modelPath: params.embeddingModelPath
|
|
532
|
+
}) : readModelSection(existing, "embeddinggemma-300m-qat-q8_0") ?? (params.defaultEmbeddingModelPath ? renderEmbeddingModelSection({
|
|
533
|
+
isDefault: true,
|
|
534
|
+
modelPath: params.defaultEmbeddingModelPath
|
|
535
|
+
}) : void 0);
|
|
536
|
+
if (!embeddingSection) throw new Error("llama.cpp embedding model path is required for a new managed preset");
|
|
537
|
+
await writePreset(presetPath, renderLlamaServerPreset({
|
|
538
|
+
chatSection,
|
|
539
|
+
embeddingSection
|
|
540
|
+
}));
|
|
541
|
+
});
|
|
542
|
+
presetWritePromises.set(presetPath, pending);
|
|
543
|
+
try {
|
|
544
|
+
await pending;
|
|
545
|
+
} finally {
|
|
546
|
+
if (presetWritePromises.get(presetPath) === pending) presetWritePromises.delete(presetPath);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
484
549
|
async function findAvailableLlamaServerPort(preferred = LLAMA_CPP_DEFAULT_PORT) {
|
|
485
550
|
const tryPort = async (port) => await new Promise((resolve) => {
|
|
486
551
|
const server = net.createServer();
|
|
@@ -497,16 +562,12 @@ async function findAvailableLlamaServerPort(preferred = LLAMA_CPP_DEFAULT_PORT)
|
|
|
497
562
|
async function prepareManagedLlamaServer(params) {
|
|
498
563
|
const { command, asset } = await ensureLlamaServerInstalled();
|
|
499
564
|
const { presetPath } = resolveManagedLlamaServerPaths(asset);
|
|
500
|
-
await
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
maxTokens: params.maxTokens,
|
|
507
|
-
embeddingModelId: DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID,
|
|
508
|
-
embeddingModelPath: params.embeddingModelPath
|
|
509
|
-
}));
|
|
565
|
+
await updatePreset(presetPath, {
|
|
566
|
+
chatModel: params.chatModel,
|
|
567
|
+
embeddingModelIsDefault: params.embeddingModelIsDefault,
|
|
568
|
+
embeddingModelPath: params.embeddingModelPath,
|
|
569
|
+
defaultEmbeddingModelPath: params.defaultEmbeddingModelPath
|
|
570
|
+
});
|
|
510
571
|
const port = params.port ?? await findAvailableLlamaServerPort();
|
|
511
572
|
const rootUrl = `http://127.0.0.1:${port}`;
|
|
512
573
|
return {
|
|
@@ -553,11 +614,14 @@ async function ensureManagedLlamaServerForChat(params) {
|
|
|
553
614
|
const configuredContext = params.model.params?.contextSize;
|
|
554
615
|
const port = Number(new URL(params.provider.baseUrl).port);
|
|
555
616
|
await prepareManagedLlamaServer({
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
617
|
+
chatModel: {
|
|
618
|
+
mode: "configure",
|
|
619
|
+
id: params.model.id,
|
|
620
|
+
path: chatModelPath,
|
|
621
|
+
contextSize: typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : params.model.contextTokens,
|
|
622
|
+
maxTokens: params.model.maxTokens
|
|
623
|
+
},
|
|
624
|
+
defaultEmbeddingModelPath: path.join(cacheDir, "hf_ggml-org_embeddinggemma-300m-qat-Q8_0.gguf"),
|
|
561
625
|
port: Number.isInteger(port) && port > 0 ? port : void 0
|
|
562
626
|
});
|
|
563
627
|
})();
|
|
@@ -635,6 +699,14 @@ const preparedEmbeddingServers = /* @__PURE__ */ new Map();
|
|
|
635
699
|
function readLocalOptions(options) {
|
|
636
700
|
return options.local ?? {};
|
|
637
701
|
}
|
|
702
|
+
function readIdentityLocalOptions(options) {
|
|
703
|
+
const local = readLocalOptions(options);
|
|
704
|
+
const provider = options.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
705
|
+
return provider?.localService ? {
|
|
706
|
+
...local,
|
|
707
|
+
modelCacheDir: resolveLlamaCppModelCacheDir(provider)
|
|
708
|
+
} : local;
|
|
709
|
+
}
|
|
638
710
|
function createCacheKeyData(model, dimensions) {
|
|
639
711
|
return {
|
|
640
712
|
provider: "local",
|
|
@@ -642,14 +714,14 @@ function createCacheKeyData(model, dimensions) {
|
|
|
642
714
|
...typeof dimensions === "number" ? { outputDimensionality: dimensions } : {}
|
|
643
715
|
};
|
|
644
716
|
}
|
|
645
|
-
function resolveModelIdentity(local,
|
|
646
|
-
const
|
|
717
|
+
function resolveModelIdentity(local, dimensions) {
|
|
718
|
+
const embeddingModel = resolveLlamaCppEmbeddingModel(local);
|
|
719
|
+
const configuredCacheDir = embeddingModel.cacheDir;
|
|
647
720
|
const currentDefaultPath = path.resolve(configuredCacheDir, DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE);
|
|
648
721
|
const legacyDefaultPath = path.resolve(resolveLegacyLlamaCppModelCacheDir(), DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE);
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
cacheKeyData: createCacheKeyData(modelPath, dimensions),
|
|
722
|
+
if (!embeddingModel.isDefault) return {
|
|
723
|
+
model: embeddingModel.source,
|
|
724
|
+
cacheKeyData: createCacheKeyData(embeddingModel.source, dimensions),
|
|
653
725
|
aliases: []
|
|
654
726
|
};
|
|
655
727
|
const aliases = /* @__PURE__ */ new Set([
|
|
@@ -657,7 +729,7 @@ function resolveModelIdentity(local, modelPath, dimensions) {
|
|
|
657
729
|
legacyDefaultPath,
|
|
658
730
|
DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE
|
|
659
731
|
]);
|
|
660
|
-
if (
|
|
732
|
+
if (embeddingModel.source !== "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf") aliases.add(embeddingModel.source);
|
|
661
733
|
return {
|
|
662
734
|
model: DEFAULT_LLAMA_CPP_EMBEDDING_MODEL,
|
|
663
735
|
cacheKeyData: createCacheKeyData(DEFAULT_LLAMA_CPP_EMBEDDING_MODEL, dimensions),
|
|
@@ -675,36 +747,23 @@ function resolveProviderPort(provider) {
|
|
|
675
747
|
if (!Number.isInteger(port) || port <= 0) throw new Error("Managed llama.cpp provider baseUrl must include a loopback port.");
|
|
676
748
|
return port;
|
|
677
749
|
}
|
|
678
|
-
async function prepareEmbeddingServer(options, embeddingSource) {
|
|
750
|
+
async function prepareEmbeddingServer(options, embeddingSource, embeddingModelIsDefault) {
|
|
679
751
|
const provider = resolveConfiguredProvider(options);
|
|
680
|
-
const configuredPrimary = options.config.agents?.defaults?.model;
|
|
681
|
-
const primaryRef = typeof configuredPrimary === "string" ? configuredPrimary : configuredPrimary?.primary;
|
|
682
|
-
const primaryId = primaryRef?.startsWith(`llama-cpp/`) ? primaryRef.slice(LLAMA_CPP_PROVIDER_ID.length + 1) : void 0;
|
|
683
|
-
const chatModel = provider.models.find((model) => model.id === primaryId) ?? provider.models.find((model) => model.id !== "gemma-4-e4b-it-q4_k_m") ?? provider.models[0];
|
|
684
752
|
const cacheDir = resolveLlamaCppModelCacheDir(provider);
|
|
685
753
|
const key = JSON.stringify([
|
|
686
754
|
provider.baseUrl,
|
|
687
|
-
chatModel?.id ?? null,
|
|
688
755
|
embeddingSource,
|
|
689
756
|
cacheDir
|
|
690
757
|
]);
|
|
691
758
|
const pending = preparedEmbeddingServers.get(key) ?? (async () => {
|
|
692
|
-
const [chatModelPath, embeddingModelPath] = await Promise.all([chatModel ? ensureLlamaCppModel({
|
|
693
|
-
source: resolveLlamaCppModelSource(chatModel),
|
|
694
|
-
cacheDir,
|
|
695
|
-
download: false
|
|
696
|
-
}) : Promise.resolve(void 0), ensureLlamaCppModel({
|
|
697
|
-
source: embeddingSource,
|
|
698
|
-
cacheDir,
|
|
699
|
-
download: true
|
|
700
|
-
})]);
|
|
701
|
-
const configuredContext = chatModel?.params?.contextSize;
|
|
702
759
|
await prepareManagedLlamaServer({
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
760
|
+
chatModel: { mode: "preserve" },
|
|
761
|
+
embeddingModelIsDefault,
|
|
762
|
+
embeddingModelPath: await ensureLlamaCppModel({
|
|
763
|
+
source: embeddingSource,
|
|
764
|
+
cacheDir,
|
|
765
|
+
download: true
|
|
766
|
+
}),
|
|
708
767
|
port: resolveProviderPort(provider)
|
|
709
768
|
});
|
|
710
769
|
})();
|
|
@@ -757,13 +816,13 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
757
816
|
transport: "local",
|
|
758
817
|
formatSetupError: (error) => `Managed local embeddings are unavailable. Run \`openclaw configure\`, choose llama.cpp, and retry. ${error instanceof Error ? error.message : String(error)}`,
|
|
759
818
|
resolveIndexIdentity: (options) => {
|
|
760
|
-
|
|
761
|
-
return resolveModelIdentity(local, normalizeOptionalString(local.modelPath) ?? "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf", options.dimensions);
|
|
819
|
+
return resolveModelIdentity(readIdentityLocalOptions(options), options.dimensions);
|
|
762
820
|
},
|
|
763
821
|
create: async (options) => {
|
|
764
|
-
const local =
|
|
765
|
-
const
|
|
766
|
-
|
|
822
|
+
const local = readIdentityLocalOptions(options);
|
|
823
|
+
const embeddingModel = resolveLlamaCppEmbeddingModel(local);
|
|
824
|
+
const identity = resolveModelIdentity(local, options.dimensions);
|
|
825
|
+
await prepareEmbeddingServer(options, embeddingModel.source, embeddingModel.isDefault);
|
|
767
826
|
const genericAdapter = getEmbeddingProvider("openai-compatible", options.config);
|
|
768
827
|
if (!genericAdapter) throw new Error("OpenAI-compatible embedding transport is unavailable.");
|
|
769
828
|
const result = await genericAdapter.create({
|
|
@@ -773,7 +832,6 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
773
832
|
remote: void 0
|
|
774
833
|
});
|
|
775
834
|
if (!result.provider) return result;
|
|
776
|
-
const identity = resolveModelIdentity(local, modelPath, options.dimensions);
|
|
777
835
|
return {
|
|
778
836
|
provider: wrapProvider({
|
|
779
837
|
provider: result.provider,
|
|
@@ -782,8 +840,8 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
782
840
|
}),
|
|
783
841
|
runtime: {
|
|
784
842
|
id: "local",
|
|
785
|
-
inlineQueryTimeoutMs:
|
|
786
|
-
inlineBatchTimeoutMs:
|
|
843
|
+
inlineQueryTimeoutMs: 3e5,
|
|
844
|
+
inlineBatchTimeoutMs: 6e5,
|
|
787
845
|
cacheKeyData: identity.cacheKeyData,
|
|
788
846
|
...identity.aliases.length > 0 ? { indexIdentityAliases: identity.aliases } : {}
|
|
789
847
|
}
|
|
@@ -905,7 +963,7 @@ function buildCompat(props) {
|
|
|
905
963
|
supportsReasoningEffort: false,
|
|
906
964
|
supportsTemperature: true,
|
|
907
965
|
supportsUsageInStreaming: true,
|
|
908
|
-
supportsTools: asBoolean(caps?.
|
|
966
|
+
supportsTools: asBoolean(caps?.supports_tool_calls) === true,
|
|
909
967
|
supportsStrictMode: false,
|
|
910
968
|
supportsJsonSchemaResponseFormat: true,
|
|
911
969
|
requiresStringContent: !(asBoolean(caps?.supports_typed_content) === true),
|
|
@@ -1073,12 +1131,9 @@ function buildLlamaCppAuthProfileRemovalPatch(config) {
|
|
|
1073
1131
|
//#endregion
|
|
1074
1132
|
//#region extensions/llama-cpp/src/external-server/setup.ts
|
|
1075
1133
|
function selectSetupModelId(discovery) {
|
|
1076
|
-
const
|
|
1077
|
-
const
|
|
1078
|
-
|
|
1079
|
-
const rightLoaded = right.status === "loaded" || right.status === "sleeping";
|
|
1080
|
-
return Number(rightLoaded) - Number(leftLoaded);
|
|
1081
|
-
}).map((model) => model.config.id);
|
|
1134
|
+
const candidates = discovery.models.filter((model) => !model.failed);
|
|
1135
|
+
const ready = candidates.filter((model) => model.status === "loaded" || model.status === "sleeping");
|
|
1136
|
+
const ids = (ready.length > 0 ? ready : candidates).map((model) => model.config.id);
|
|
1082
1137
|
return selectPreferredLocalModelId(ids) ?? ids[0];
|
|
1083
1138
|
}
|
|
1084
1139
|
function describeDiscoveryFailure(result) {
|
|
@@ -1176,21 +1231,27 @@ async function removeDefaultAuthProfile(agentDir) {
|
|
|
1176
1231
|
profileIds: [LLAMA_CPP_DEFAULT_PROFILE_ID]
|
|
1177
1232
|
})) throw new Error("Failed to remove the previous llama-server auth profile; wait a moment and retry.");
|
|
1178
1233
|
}
|
|
1179
|
-
async function discoverForSetup(
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1234
|
+
async function discoverForSetup(ctx) {
|
|
1235
|
+
const provider = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1236
|
+
if (provider?.localService) return null;
|
|
1237
|
+
try {
|
|
1238
|
+
const headers = await resolveLlamaServerProviderHeaders({
|
|
1239
|
+
config: ctx.config,
|
|
1240
|
+
env: ctx.env,
|
|
1241
|
+
headers: provider?.headers
|
|
1242
|
+
});
|
|
1243
|
+
const apiKey = !hasLlamaServerAuthorizationHeader(headers) ? await resolveLlamaServerRuntimeApiKey({ config: ctx.config }) : void 0;
|
|
1244
|
+
const discovery = await discoverLlamaServer({
|
|
1245
|
+
baseUrl: provider?.baseUrl ?? "http://127.0.0.1:8080",
|
|
1246
|
+
apiKey,
|
|
1247
|
+
headers,
|
|
1248
|
+
signal: ctx.signal,
|
|
1249
|
+
cacheTtlMs: 0
|
|
1250
|
+
});
|
|
1251
|
+
return discovery.kind === "success" ? discovery : null;
|
|
1252
|
+
} catch {
|
|
1253
|
+
return null;
|
|
1254
|
+
}
|
|
1194
1255
|
}
|
|
1195
1256
|
async function discoverWithAccess(params) {
|
|
1196
1257
|
return await discoverLlamaServer({
|
|
@@ -1203,21 +1264,8 @@ async function discoverWithAccess(params) {
|
|
|
1203
1264
|
}
|
|
1204
1265
|
/** Read-only discovery for the guided local-provider setup ladder. */
|
|
1205
1266
|
async function detectLlamaServerSetup(ctx) {
|
|
1206
|
-
const
|
|
1207
|
-
if (
|
|
1208
|
-
const baseUrl = provider?.baseUrl ?? "http://127.0.0.1:8080";
|
|
1209
|
-
let discovery;
|
|
1210
|
-
try {
|
|
1211
|
-
discovery = await discoverForSetup({
|
|
1212
|
-
config: ctx.config,
|
|
1213
|
-
baseUrl,
|
|
1214
|
-
env: ctx.env,
|
|
1215
|
-
signal: ctx.signal
|
|
1216
|
-
});
|
|
1217
|
-
} catch {
|
|
1218
|
-
return null;
|
|
1219
|
-
}
|
|
1220
|
-
if (discovery.kind !== "success") return null;
|
|
1267
|
+
const discovery = await discoverForSetup(ctx);
|
|
1268
|
+
if (!discovery) return null;
|
|
1221
1269
|
const modelId = selectSetupModelId(discovery);
|
|
1222
1270
|
if (!modelId) return null;
|
|
1223
1271
|
return {
|
|
@@ -1227,20 +1275,8 @@ async function detectLlamaServerSetup(ctx) {
|
|
|
1227
1275
|
}
|
|
1228
1276
|
/** Rechecks one guided candidate and returns the config needed for a live probe. */
|
|
1229
1277
|
async function prepareLlamaServerSetup(ctx) {
|
|
1230
|
-
const
|
|
1231
|
-
if (
|
|
1232
|
-
let discovery;
|
|
1233
|
-
try {
|
|
1234
|
-
discovery = await discoverForSetup({
|
|
1235
|
-
config: ctx.config,
|
|
1236
|
-
baseUrl: provider?.baseUrl ?? "http://127.0.0.1:8080",
|
|
1237
|
-
env: ctx.env,
|
|
1238
|
-
signal: ctx.signal
|
|
1239
|
-
});
|
|
1240
|
-
} catch {
|
|
1241
|
-
return null;
|
|
1242
|
-
}
|
|
1243
|
-
if (discovery.kind !== "success") return null;
|
|
1278
|
+
const discovery = await discoverForSetup(ctx);
|
|
1279
|
+
if (!discovery) return null;
|
|
1244
1280
|
const prefix = `${LLAMA_CPP_PROVIDER_ID}/`;
|
|
1245
1281
|
const modelId = ctx.modelRef.startsWith(prefix) ? ctx.modelRef.slice(prefix.length) : "";
|
|
1246
1282
|
if (!modelId || !discovery.models.some((model) => model.config.id === modelId)) return null;
|
|
@@ -1485,13 +1521,20 @@ function formatDownloadProgress(label, params) {
|
|
|
1485
1521
|
function formatRamGb(totalmemBytes) {
|
|
1486
1522
|
return (totalmemBytes / 1024 ** 3).toFixed(1).replace(/\.0$/u, "");
|
|
1487
1523
|
}
|
|
1524
|
+
function describeEmbeddingDownload(isDefault) {
|
|
1525
|
+
return isDefault ? "the local embedding model (about 0.3 GB)" : "your configured local embedding model";
|
|
1526
|
+
}
|
|
1488
1527
|
function readPrimaryModel(config) {
|
|
1489
1528
|
const model = config.agents?.defaults?.model;
|
|
1490
1529
|
return typeof model === "string" ? model : model?.primary;
|
|
1491
1530
|
}
|
|
1492
|
-
function configuredCandidates(config) {
|
|
1531
|
+
function configuredCandidates(config, scope) {
|
|
1493
1532
|
const existing = config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1494
|
-
const
|
|
1533
|
+
const managedExisting = existing?.localService ? existing : void 0;
|
|
1534
|
+
const provider = buildLlamaCppProviderConfig({
|
|
1535
|
+
existing: managedExisting,
|
|
1536
|
+
...managedExisting && scope === "detection" ? { modelInventory: managedExisting.models } : {}
|
|
1537
|
+
});
|
|
1495
1538
|
const primary = readPrimaryModel(config);
|
|
1496
1539
|
const primaryId = primary?.startsWith(`llama-cpp/`) ? primary.slice(LLAMA_CPP_PROVIDER_ID.length + 1) : void 0;
|
|
1497
1540
|
return provider.models.map((model) => ({
|
|
@@ -1531,12 +1574,16 @@ function buildSetupResult(params) {
|
|
|
1531
1574
|
const switchingFromExternal = Boolean(existing && !existing.localService);
|
|
1532
1575
|
return {
|
|
1533
1576
|
profiles: [],
|
|
1534
|
-
defaultModel: params.defaultModel
|
|
1577
|
+
...params.defaultModel ? { defaultModel: params.defaultModel } : {},
|
|
1535
1578
|
configPatch: {
|
|
1536
1579
|
...buildLlamaCppAuthProfileRemovalPatch(params.config),
|
|
1537
1580
|
models: {
|
|
1538
1581
|
mode: params.config.models?.mode ?? "merge",
|
|
1539
|
-
providers: { [LLAMA_CPP_PROVIDER_ID]: buildLlamaCppProviderConfig(
|
|
1582
|
+
providers: { [LLAMA_CPP_PROVIDER_ID]: buildLlamaCppProviderConfig({
|
|
1583
|
+
existing: switchingFromExternal ? void 0 : existing,
|
|
1584
|
+
managed: params.managed,
|
|
1585
|
+
...params.plan === "embedding-only" ? { modelInventory: [] } : {}
|
|
1586
|
+
}) }
|
|
1540
1587
|
}
|
|
1541
1588
|
}
|
|
1542
1589
|
};
|
|
@@ -1546,7 +1593,7 @@ async function detectLlamaCppSetup(ctx) {
|
|
|
1546
1593
|
const command = existing?.localService?.command;
|
|
1547
1594
|
const presetPath = existing?.localService?.args?.find((_, index, args) => args[index - 1] === "--models-preset");
|
|
1548
1595
|
if (!command || !path.isAbsolute(command) || !await isFile(command) || !presetPath || !await isFile(presetPath)) return null;
|
|
1549
|
-
for (const candidate of configuredCandidates(ctx.config)) if (await resolveCachedCandidate(candidate)) return {
|
|
1596
|
+
for (const candidate of configuredCandidates(ctx.config, "detection")) if (await resolveCachedCandidate(candidate)) return {
|
|
1550
1597
|
modelRef: `${LLAMA_CPP_PROVIDER_ID}/${candidate.model.id}`,
|
|
1551
1598
|
detail: "Managed llama.cpp server ready"
|
|
1552
1599
|
};
|
|
@@ -1560,6 +1607,7 @@ async function prepareLlamaCppSetup(ctx) {
|
|
|
1560
1607
|
const rootUrl = baseUrl.replace(/\/v1$/u, "");
|
|
1561
1608
|
return buildSetupResult({
|
|
1562
1609
|
config: ctx.config,
|
|
1610
|
+
plan: "chat",
|
|
1563
1611
|
defaultModel: ctx.modelRef,
|
|
1564
1612
|
managed: {
|
|
1565
1613
|
command: existing.localService.command,
|
|
@@ -1569,52 +1617,101 @@ async function prepareLlamaCppSetup(ctx) {
|
|
|
1569
1617
|
}
|
|
1570
1618
|
});
|
|
1571
1619
|
}
|
|
1620
|
+
function resolveEmbeddingSetup(config, cacheDir) {
|
|
1621
|
+
const defaults = config.memory?.search;
|
|
1622
|
+
const models = listAgentIds(config).flatMap((agentId) => {
|
|
1623
|
+
const override = resolveAgentConfig(config, agentId)?.memory?.search;
|
|
1624
|
+
if (!(override?.enabled ?? defaults?.enabled ?? true) || (override?.provider ?? defaults?.provider) !== "local") return [];
|
|
1625
|
+
return [resolveLlamaCppEmbeddingModel({
|
|
1626
|
+
modelPath: override?.local?.modelPath ?? defaults?.local?.modelPath,
|
|
1627
|
+
modelCacheDir: cacheDir
|
|
1628
|
+
})];
|
|
1629
|
+
});
|
|
1630
|
+
const model = models[0] ?? resolveLlamaCppEmbeddingModel({ modelCacheDir: cacheDir });
|
|
1631
|
+
return {
|
|
1632
|
+
model,
|
|
1633
|
+
localMemoryIntent: models.length > 0,
|
|
1634
|
+
conflict: models.some((candidate) => candidate.source !== model.source)
|
|
1635
|
+
};
|
|
1636
|
+
}
|
|
1637
|
+
async function resolveSetupPlan(ctx, candidates, embeddingModelIsDefault, localMemoryIntent) {
|
|
1638
|
+
let candidate = candidates[0];
|
|
1639
|
+
const cachedPath = candidate ? await resolveCachedCandidate(candidate) : void 0;
|
|
1640
|
+
if (candidate && cachedPath) return {
|
|
1641
|
+
kind: "chat",
|
|
1642
|
+
candidate,
|
|
1643
|
+
cachedPath
|
|
1644
|
+
};
|
|
1645
|
+
candidate = candidates.find((entry) => entry.model.id === DEFAULT_LLAMA_CPP_MODEL_ID);
|
|
1646
|
+
const totalmemBytes = os.totalmem();
|
|
1647
|
+
if (candidate && meetsLlamaCppDefaultModelRamFloor(totalmemBytes)) {
|
|
1648
|
+
if (await ctx.prompter.confirm({
|
|
1649
|
+
message: `OpenClaw will install a verified llama.cpp server and download Gemma 4 E4B IT Q4_K_M (about 5.0 GB) plus ${describeEmbeddingDownload(embeddingModelIsDefault)}. Continue?`,
|
|
1650
|
+
initialValue: false
|
|
1651
|
+
})) return {
|
|
1652
|
+
kind: "chat",
|
|
1653
|
+
candidate
|
|
1654
|
+
};
|
|
1655
|
+
} else if (!localMemoryIntent) {
|
|
1656
|
+
await ctx.prompter.note(`This Gateway has ${formatRamGb(totalmemBytes)} GB RAM; the recommended model needs 16 GB+. Configure an existing smaller GGUF, use Ollama or LM Studio, or choose a cloud provider.`, "Setup skipped");
|
|
1657
|
+
return;
|
|
1658
|
+
}
|
|
1659
|
+
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1660
|
+
if (localMemoryIntent && existing && (!existing.localService || existing.models.length > 0)) {
|
|
1661
|
+
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");
|
|
1662
|
+
return;
|
|
1663
|
+
}
|
|
1664
|
+
if (localMemoryIntent) {
|
|
1665
|
+
if (await ctx.prompter.confirm({
|
|
1666
|
+
message: `OpenClaw can install a verified llama.cpp server and download only ${describeEmbeddingDownload(embeddingModelIsDefault)}. This will not install or change your chat model. Continue?`,
|
|
1667
|
+
initialValue: false
|
|
1668
|
+
})) return { kind: "embedding-only" };
|
|
1669
|
+
}
|
|
1670
|
+
await ctx.prompter.note("Local model setup skipped.", "Setup skipped");
|
|
1671
|
+
}
|
|
1572
1672
|
async function runLlamaCppSetup(ctx) {
|
|
1573
1673
|
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1574
1674
|
const managedExisting = existing?.localService ? existing : void 0;
|
|
1575
|
-
const
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
const totalmemBytes = os.totalmem();
|
|
1581
|
-
if (!selected || !meetsLlamaCppDefaultModelRamFloor(totalmemBytes)) {
|
|
1582
|
-
await ctx.prompter.note(`This Gateway has ${formatRamGb(totalmemBytes)} GB RAM; the recommended model needs 16 GB+. Configure an existing smaller GGUF, use Ollama or LM Studio, or choose a cloud provider.`, "Setup skipped");
|
|
1583
|
-
return { profiles: [] };
|
|
1584
|
-
}
|
|
1585
|
-
if (!await ctx.prompter.confirm({
|
|
1586
|
-
message: "OpenClaw will install a verified llama.cpp server and download Gemma 4 E4B IT Q4_K_M (about 5.0 GB) plus the local embedding model (about 0.3 GB). Continue?",
|
|
1587
|
-
initialValue: false
|
|
1588
|
-
})) {
|
|
1589
|
-
await ctx.prompter.note("Local model setup skipped.", "Setup skipped");
|
|
1590
|
-
return { profiles: [] };
|
|
1591
|
-
}
|
|
1675
|
+
const cacheDir = resolveLlamaCppModelCacheDir(managedExisting);
|
|
1676
|
+
const embeddingSetup = resolveEmbeddingSetup(ctx.config, cacheDir);
|
|
1677
|
+
if (embeddingSetup.conflict) {
|
|
1678
|
+
await ctx.prompter.note("Configured agents resolve to different local embedding models. Set memory.search.local.modelPath and any per-agent overrides to the same value, then retry llama.cpp setup.", "Setup skipped");
|
|
1679
|
+
return { profiles: [] };
|
|
1592
1680
|
}
|
|
1593
|
-
|
|
1681
|
+
const embeddingModel = embeddingSetup.model;
|
|
1682
|
+
const plan = await resolveSetupPlan(ctx, configuredCandidates(ctx.config, "setup"), embeddingModel.isDefault, embeddingSetup.localMemoryIntent);
|
|
1683
|
+
if (!plan) return { profiles: [] };
|
|
1594
1684
|
const progress = ctx.prompter.progress("Preparing managed llama.cpp server…");
|
|
1595
1685
|
try {
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1686
|
+
let chatModel;
|
|
1687
|
+
if (plan.kind === "chat") {
|
|
1688
|
+
const chatModelPath = plan.cachedPath ?? await ensureLlamaCppModel({
|
|
1689
|
+
source: resolveLlamaCppModelSource(plan.candidate.model),
|
|
1690
|
+
cacheDir,
|
|
1691
|
+
download: true,
|
|
1692
|
+
signal: ctx.signal,
|
|
1693
|
+
onProgress: (status) => progress.update(formatDownloadProgress("Gemma 4 E4B", status))
|
|
1694
|
+
});
|
|
1695
|
+
const configuredContext = plan.candidate.model.params?.contextSize;
|
|
1696
|
+
chatModel = {
|
|
1697
|
+
mode: "configure",
|
|
1698
|
+
id: plan.candidate.model.id,
|
|
1699
|
+
path: chatModelPath,
|
|
1700
|
+
contextSize: typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : plan.candidate.model.contextTokens,
|
|
1701
|
+
maxTokens: plan.candidate.model.maxTokens
|
|
1702
|
+
};
|
|
1703
|
+
} else chatModel = { mode: "remove" };
|
|
1704
|
+
const embeddingModelLabel = embeddingModel.isDefault ? "EmbeddingGemma" : "configured embedding model";
|
|
1604
1705
|
const embeddingModelPath = await ensureLlamaCppModel({
|
|
1605
|
-
source:
|
|
1706
|
+
source: embeddingModel.source,
|
|
1606
1707
|
cacheDir,
|
|
1607
1708
|
download: true,
|
|
1608
1709
|
signal: ctx.signal,
|
|
1609
|
-
onProgress: (status) => progress.update(formatDownloadProgress(
|
|
1710
|
+
onProgress: (status) => progress.update(formatDownloadProgress(embeddingModelLabel, status))
|
|
1610
1711
|
});
|
|
1611
|
-
const configuredContext = selected.model.params?.contextSize;
|
|
1612
|
-
const contextSize = typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : selected.model.contextTokens;
|
|
1613
1712
|
const managed = await prepareManagedLlamaServer({
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
contextSize,
|
|
1617
|
-
maxTokens: selected.model.maxTokens,
|
|
1713
|
+
chatModel,
|
|
1714
|
+
embeddingModelIsDefault: embeddingModel.isDefault,
|
|
1618
1715
|
embeddingModelPath,
|
|
1619
1716
|
port: readConfiguredPort(managedExisting)
|
|
1620
1717
|
});
|
|
@@ -1627,7 +1724,8 @@ async function runLlamaCppSetup(ctx) {
|
|
|
1627
1724
|
return buildSetupResult({
|
|
1628
1725
|
config: ctx.config,
|
|
1629
1726
|
managed,
|
|
1630
|
-
|
|
1727
|
+
plan: plan.kind,
|
|
1728
|
+
...plan.kind === "chat" ? { defaultModel: `${LLAMA_CPP_PROVIDER_ID}/${plan.candidate.model.id}` } : {}
|
|
1631
1729
|
});
|
|
1632
1730
|
} catch (error) {
|
|
1633
1731
|
progress.stop("llama.cpp setup failed");
|
|
@@ -1688,7 +1786,10 @@ function registerLlamaCppProvider(api) {
|
|
|
1688
1786
|
order: "late",
|
|
1689
1787
|
run: async (ctx) => {
|
|
1690
1788
|
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1691
|
-
return configured?.localService ? { provider: buildLlamaCppProviderConfig(
|
|
1789
|
+
return configured?.localService ? { provider: buildLlamaCppProviderConfig({
|
|
1790
|
+
existing: configured,
|
|
1791
|
+
modelInventory: configured.models
|
|
1792
|
+
}) } : await discoverLlamaServerProvider(ctx);
|
|
1692
1793
|
}
|
|
1693
1794
|
},
|
|
1694
1795
|
staticCatalog: {
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import { resolveStateDir } from "openclaw/plugin-sdk/state-paths";
|
|
4
|
+
import { normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
5
|
//#region extensions/llama-cpp/src/defaults.ts
|
|
5
6
|
const LLAMA_CPP_PROVIDER_ID = "llama-cpp";
|
|
6
7
|
const LLAMA_CPP_PROVIDER_LABEL = "llama.cpp";
|
|
7
8
|
const LLAMA_CPP_LOCAL_AUTH_MARKER = "llama-cpp-local";
|
|
8
9
|
const LLAMA_CPP_DEFAULT_PORT = 19432;
|
|
9
10
|
const LLAMA_CPP_READY_TIMEOUT_MS = 3e4;
|
|
10
|
-
const LLAMA_CPP_IDLE_STOP_MS =
|
|
11
|
+
const LLAMA_CPP_IDLE_STOP_MS = 6e5;
|
|
11
12
|
function resolveLlamaCppSyntheticApiKey() {
|
|
12
13
|
return LLAMA_CPP_LOCAL_AUTH_MARKER;
|
|
13
14
|
}
|
|
14
15
|
const DEFAULT_LLAMA_CPP_MODEL_ID = "gemma-4-e4b-it-q4_k_m";
|
|
15
|
-
const DEFAULT_LLAMA_CPP_MODEL_REF = `${LLAMA_CPP_PROVIDER_ID}/${DEFAULT_LLAMA_CPP_MODEL_ID}`;
|
|
16
16
|
const DEFAULT_LLAMA_CPP_MODEL_URI = "hf:unsloth/gemma-4-E4B-it-GGUF/gemma-4-E4B-it-Q4_K_M.gguf";
|
|
17
17
|
const DEFAULT_LLAMA_CPP_MODEL_REVISION = "bfc15c382204943c3a8fff0c750b94ae2364d7a3";
|
|
18
18
|
const DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE = "hf_unsloth_gemma-4-E4B-it-GGUF_gemma-4-E4B-it-Q4_K_M.gguf";
|
|
@@ -39,6 +39,16 @@ function resolveLlamaCppModelCacheDir(provider) {
|
|
|
39
39
|
function resolveLegacyLlamaCppModelCacheDir() {
|
|
40
40
|
return path.join(os.homedir(), ".node-llama-cpp", "models");
|
|
41
41
|
}
|
|
42
|
+
function resolveLlamaCppEmbeddingModel(local = {}) {
|
|
43
|
+
const source = normalizeOptionalString(local.modelPath) ?? "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf";
|
|
44
|
+
const cacheDir = normalizeOptionalString(local.modelCacheDir) ?? resolveLlamaCppModelCacheDir();
|
|
45
|
+
const resolvedPath = /^(?:hf:|https?:\/\/)/iu.test(source) ? void 0 : path.resolve(cacheDir, source);
|
|
46
|
+
return {
|
|
47
|
+
source,
|
|
48
|
+
cacheDir,
|
|
49
|
+
isDefault: source === "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf" || resolvedPath === path.resolve(cacheDir, "hf_ggml-org_embeddinggemma-300m-qat-Q8_0.gguf") || resolvedPath === path.resolve(resolveLegacyLlamaCppModelCacheDir(), "hf_ggml-org_embeddinggemma-300m-qat-Q8_0.gguf")
|
|
50
|
+
};
|
|
51
|
+
}
|
|
42
52
|
function resolveHomePath(value) {
|
|
43
53
|
if (value === "~") return os.homedir();
|
|
44
54
|
if (value.startsWith("~/")) return path.join(os.homedir(), value.slice(2));
|
|
@@ -83,10 +93,11 @@ function buildDefaultLlamaCppModel() {
|
|
|
83
93
|
}
|
|
84
94
|
};
|
|
85
95
|
}
|
|
86
|
-
function buildLlamaCppProviderConfig(
|
|
96
|
+
function buildLlamaCppProviderConfig(params = {}) {
|
|
97
|
+
const { existing, managed, modelInventory } = params;
|
|
87
98
|
const defaultModel = buildDefaultLlamaCppModel();
|
|
88
99
|
const configuredModels = existing?.models ?? [];
|
|
89
|
-
const models = configuredModels.some((model) => model.id === defaultModel.id) ? configuredModels : [...configuredModels, defaultModel];
|
|
100
|
+
const models = modelInventory ?? (configuredModels.some((model) => model.id === defaultModel.id) ? configuredModels : [...configuredModels, defaultModel]);
|
|
90
101
|
return {
|
|
91
102
|
...existing,
|
|
92
103
|
baseUrl: managed?.baseUrl ?? existing?.baseUrl ?? `http://127.0.0.1:19432/v1`,
|
|
@@ -112,4 +123,4 @@ function resolveManagedLlamaCppProviderConfig(config) {
|
|
|
112
123
|
return provider;
|
|
113
124
|
}
|
|
114
125
|
//#endregion
|
|
115
|
-
export {
|
|
126
|
+
export { resolveLegacyLlamaCppModelCacheDir as C, resolveLlamaCppModelSource as D, resolveLlamaCppModelCacheDir as E, resolveLlamaCppSyntheticApiKey as O, resolveHomePath as S, resolveLlamaCppEmbeddingModel as T, LLAMA_CPP_PROVIDER_ID as _, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL as a, meetsLlamaCppDefaultModelRamFloor as b, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256 as c, DEFAULT_LLAMA_CPP_MODEL_ID as d, DEFAULT_LLAMA_CPP_MODEL_REVISION as f, LLAMA_CPP_DEFAULT_PORT as g, DEFAULT_LLAMA_CPP_MODEL_URI as h, DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE as i, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES as l, DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES as m, resolveManagedLlamaCppProviderConfig as n, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID as o, DEFAULT_LLAMA_CPP_MODEL_SHA256 as p, DEFAULT_LLAMA_CPP_CONTEXT_SIZE as r, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION as s, MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE as t, DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE as u, LLAMA_CPP_PROVIDER_LABEL as v, resolveLlamaCppDataDir as w, resolveCachedLlamaCppModelPath as x, buildLlamaCppProviderConfig as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as resolveManagedLlamaCppProviderConfig, t as MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE } from "./managed-provider-config-
|
|
1
|
+
import { n as resolveManagedLlamaCppProviderConfig, t as MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE } from "./managed-provider-config-Ovg5QQxD.js";
|
|
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.8.
|
|
3
|
+
"version": "2026.8.2",
|
|
4
4
|
"description": "OpenClaw provider for managed and external llama.cpp servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"minHostVersion": ">=2026.6.2"
|
|
25
25
|
},
|
|
26
26
|
"compat": {
|
|
27
|
-
"pluginApi": ">=2026.8.
|
|
27
|
+
"pluginApi": ">=2026.8.2"
|
|
28
28
|
},
|
|
29
29
|
"build": {
|
|
30
|
-
"openclawVersion": "2026.8.
|
|
30
|
+
"openclawVersion": "2026.8.2"
|
|
31
31
|
},
|
|
32
32
|
"release": {
|
|
33
33
|
"bundleRuntimeDependencies": false,
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"README.md"
|
|
45
45
|
],
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"openclaw": ">=2026.8.
|
|
47
|
+
"openclaw": ">=2026.8.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"openclaw": {
|