@openclaw/llama-cpp-provider 2026.8.1-beta.3 → 2026.8.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/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-C9_YC5Rd.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
|
];
|
|
@@ -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("/");
|
|
@@ -462,18 +465,46 @@ function assertIniValue(value, label) {
|
|
|
462
465
|
if (/\r|\n/u.test(value)) throw new Error(`${label} cannot contain a newline`);
|
|
463
466
|
return value;
|
|
464
467
|
}
|
|
468
|
+
function renderChatModelSection(params) {
|
|
469
|
+
const id = assertIniValue(params.id, "llama.cpp model id");
|
|
470
|
+
if (id.includes("]")) throw new Error("llama.cpp model ids cannot contain ]");
|
|
471
|
+
return [
|
|
472
|
+
`[${id}]`,
|
|
473
|
+
`model = ${assertIniValue(params.modelPath, "llama.cpp model path")}`,
|
|
474
|
+
`ctx-size = ${params.contextSize ?? 65536}`,
|
|
475
|
+
`n-predict = ${params.maxTokens ?? 2048}`,
|
|
476
|
+
"jinja = true"
|
|
477
|
+
].join("\n");
|
|
478
|
+
}
|
|
479
|
+
function renderEmbeddingModelSection(params) {
|
|
480
|
+
return [
|
|
481
|
+
`[${DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID}]`,
|
|
482
|
+
`model = ${assertIniValue(params.modelPath, "llama.cpp embedding model path")}`,
|
|
483
|
+
...params.isDefault ? [`ubatch-size = ${LLAMA_CPP_EMBEDDING_UBATCH_SIZE}`] : [],
|
|
484
|
+
"embedding = true"
|
|
485
|
+
].join("\n");
|
|
486
|
+
}
|
|
487
|
+
function readModelSection(contents, id) {
|
|
488
|
+
if (!contents) return;
|
|
489
|
+
const lines = contents.split(/\r?\n/u);
|
|
490
|
+
const start = lines.indexOf(`[${id}]`);
|
|
491
|
+
if (start < 0) return;
|
|
492
|
+
let end = start + 1;
|
|
493
|
+
while (end < lines.length && !/^\[[^\]]+\]$/u.test(lines[end] ?? "")) end += 1;
|
|
494
|
+
return lines.slice(start, end).join("\n").trimEnd();
|
|
495
|
+
}
|
|
496
|
+
function readChatModelSection(contents) {
|
|
497
|
+
const id = contents?.split(/\r?\n/u).map((line) => /^\[([^\]]+)\]$/u.exec(line)?.[1]).find((candidate) => candidate && candidate !== "embeddinggemma-300m-qat-q8_0");
|
|
498
|
+
return id ? readModelSection(contents, id) : void 0;
|
|
499
|
+
}
|
|
465
500
|
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");
|
|
501
|
+
return [
|
|
502
|
+
"version = 1",
|
|
503
|
+
"",
|
|
504
|
+
...params.chatSection ? [params.chatSection, ""] : [],
|
|
505
|
+
params.embeddingSection,
|
|
506
|
+
""
|
|
507
|
+
].join("\n");
|
|
477
508
|
}
|
|
478
509
|
async function writePreset(presetPath, contents) {
|
|
479
510
|
await fsp.mkdir(path.dirname(presetPath), { recursive: true });
|
|
@@ -481,6 +512,38 @@ async function writePreset(presetPath, contents) {
|
|
|
481
512
|
await fsp.writeFile(temporary, contents, { mode: 384 });
|
|
482
513
|
await fsp.rename(temporary, presetPath);
|
|
483
514
|
}
|
|
515
|
+
async function updatePreset(presetPath, params) {
|
|
516
|
+
const pending = (presetWritePromises.get(presetPath) ?? Promise.resolve()).catch(() => void 0).then(async () => {
|
|
517
|
+
const existing = await fsp.readFile(presetPath, "utf8").catch((error) => {
|
|
518
|
+
if (asOptionalRecord(error)?.code === "ENOENT") return;
|
|
519
|
+
throw error;
|
|
520
|
+
});
|
|
521
|
+
const chatSection = params.chatModel.mode === "preserve" ? readChatModelSection(existing) : params.chatModel.mode === "configure" ? renderChatModelSection({
|
|
522
|
+
id: params.chatModel.id,
|
|
523
|
+
modelPath: params.chatModel.path,
|
|
524
|
+
contextSize: params.chatModel.contextSize,
|
|
525
|
+
maxTokens: params.chatModel.maxTokens
|
|
526
|
+
}) : void 0;
|
|
527
|
+
const embeddingSection = params.embeddingModelPath ? renderEmbeddingModelSection({
|
|
528
|
+
isDefault: params.embeddingModelIsDefault,
|
|
529
|
+
modelPath: params.embeddingModelPath
|
|
530
|
+
}) : readModelSection(existing, "embeddinggemma-300m-qat-q8_0") ?? (params.defaultEmbeddingModelPath ? renderEmbeddingModelSection({
|
|
531
|
+
isDefault: true,
|
|
532
|
+
modelPath: params.defaultEmbeddingModelPath
|
|
533
|
+
}) : void 0);
|
|
534
|
+
if (!embeddingSection) throw new Error("llama.cpp embedding model path is required for a new managed preset");
|
|
535
|
+
await writePreset(presetPath, renderLlamaServerPreset({
|
|
536
|
+
chatSection,
|
|
537
|
+
embeddingSection
|
|
538
|
+
}));
|
|
539
|
+
});
|
|
540
|
+
presetWritePromises.set(presetPath, pending);
|
|
541
|
+
try {
|
|
542
|
+
await pending;
|
|
543
|
+
} finally {
|
|
544
|
+
if (presetWritePromises.get(presetPath) === pending) presetWritePromises.delete(presetPath);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
484
547
|
async function findAvailableLlamaServerPort(preferred = LLAMA_CPP_DEFAULT_PORT) {
|
|
485
548
|
const tryPort = async (port) => await new Promise((resolve) => {
|
|
486
549
|
const server = net.createServer();
|
|
@@ -497,16 +560,12 @@ async function findAvailableLlamaServerPort(preferred = LLAMA_CPP_DEFAULT_PORT)
|
|
|
497
560
|
async function prepareManagedLlamaServer(params) {
|
|
498
561
|
const { command, asset } = await ensureLlamaServerInstalled();
|
|
499
562
|
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
|
-
}));
|
|
563
|
+
await updatePreset(presetPath, {
|
|
564
|
+
chatModel: params.chatModel,
|
|
565
|
+
embeddingModelIsDefault: params.embeddingModelIsDefault,
|
|
566
|
+
embeddingModelPath: params.embeddingModelPath,
|
|
567
|
+
defaultEmbeddingModelPath: params.defaultEmbeddingModelPath
|
|
568
|
+
});
|
|
510
569
|
const port = params.port ?? await findAvailableLlamaServerPort();
|
|
511
570
|
const rootUrl = `http://127.0.0.1:${port}`;
|
|
512
571
|
return {
|
|
@@ -553,11 +612,14 @@ async function ensureManagedLlamaServerForChat(params) {
|
|
|
553
612
|
const configuredContext = params.model.params?.contextSize;
|
|
554
613
|
const port = Number(new URL(params.provider.baseUrl).port);
|
|
555
614
|
await prepareManagedLlamaServer({
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
615
|
+
chatModel: {
|
|
616
|
+
mode: "configure",
|
|
617
|
+
id: params.model.id,
|
|
618
|
+
path: chatModelPath,
|
|
619
|
+
contextSize: typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : params.model.contextTokens,
|
|
620
|
+
maxTokens: params.model.maxTokens
|
|
621
|
+
},
|
|
622
|
+
defaultEmbeddingModelPath: path.join(cacheDir, "hf_ggml-org_embeddinggemma-300m-qat-Q8_0.gguf"),
|
|
561
623
|
port: Number.isInteger(port) && port > 0 ? port : void 0
|
|
562
624
|
});
|
|
563
625
|
})();
|
|
@@ -635,6 +697,14 @@ const preparedEmbeddingServers = /* @__PURE__ */ new Map();
|
|
|
635
697
|
function readLocalOptions(options) {
|
|
636
698
|
return options.local ?? {};
|
|
637
699
|
}
|
|
700
|
+
function readIdentityLocalOptions(options) {
|
|
701
|
+
const local = readLocalOptions(options);
|
|
702
|
+
const provider = options.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
703
|
+
return provider?.localService ? {
|
|
704
|
+
...local,
|
|
705
|
+
modelCacheDir: resolveLlamaCppModelCacheDir(provider)
|
|
706
|
+
} : local;
|
|
707
|
+
}
|
|
638
708
|
function createCacheKeyData(model, dimensions) {
|
|
639
709
|
return {
|
|
640
710
|
provider: "local",
|
|
@@ -642,14 +712,14 @@ function createCacheKeyData(model, dimensions) {
|
|
|
642
712
|
...typeof dimensions === "number" ? { outputDimensionality: dimensions } : {}
|
|
643
713
|
};
|
|
644
714
|
}
|
|
645
|
-
function resolveModelIdentity(local,
|
|
646
|
-
const
|
|
715
|
+
function resolveModelIdentity(local, dimensions) {
|
|
716
|
+
const embeddingModel = resolveLlamaCppEmbeddingModel(local);
|
|
717
|
+
const configuredCacheDir = embeddingModel.cacheDir;
|
|
647
718
|
const currentDefaultPath = path.resolve(configuredCacheDir, DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE);
|
|
648
719
|
const legacyDefaultPath = path.resolve(resolveLegacyLlamaCppModelCacheDir(), DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE);
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
cacheKeyData: createCacheKeyData(modelPath, dimensions),
|
|
720
|
+
if (!embeddingModel.isDefault) return {
|
|
721
|
+
model: embeddingModel.source,
|
|
722
|
+
cacheKeyData: createCacheKeyData(embeddingModel.source, dimensions),
|
|
653
723
|
aliases: []
|
|
654
724
|
};
|
|
655
725
|
const aliases = /* @__PURE__ */ new Set([
|
|
@@ -657,7 +727,7 @@ function resolveModelIdentity(local, modelPath, dimensions) {
|
|
|
657
727
|
legacyDefaultPath,
|
|
658
728
|
DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE
|
|
659
729
|
]);
|
|
660
|
-
if (
|
|
730
|
+
if (embeddingModel.source !== "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf") aliases.add(embeddingModel.source);
|
|
661
731
|
return {
|
|
662
732
|
model: DEFAULT_LLAMA_CPP_EMBEDDING_MODEL,
|
|
663
733
|
cacheKeyData: createCacheKeyData(DEFAULT_LLAMA_CPP_EMBEDDING_MODEL, dimensions),
|
|
@@ -675,36 +745,23 @@ function resolveProviderPort(provider) {
|
|
|
675
745
|
if (!Number.isInteger(port) || port <= 0) throw new Error("Managed llama.cpp provider baseUrl must include a loopback port.");
|
|
676
746
|
return port;
|
|
677
747
|
}
|
|
678
|
-
async function prepareEmbeddingServer(options, embeddingSource) {
|
|
748
|
+
async function prepareEmbeddingServer(options, embeddingSource, embeddingModelIsDefault) {
|
|
679
749
|
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
750
|
const cacheDir = resolveLlamaCppModelCacheDir(provider);
|
|
685
751
|
const key = JSON.stringify([
|
|
686
752
|
provider.baseUrl,
|
|
687
|
-
chatModel?.id ?? null,
|
|
688
753
|
embeddingSource,
|
|
689
754
|
cacheDir
|
|
690
755
|
]);
|
|
691
756
|
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
757
|
await prepareManagedLlamaServer({
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
758
|
+
chatModel: { mode: "preserve" },
|
|
759
|
+
embeddingModelIsDefault,
|
|
760
|
+
embeddingModelPath: await ensureLlamaCppModel({
|
|
761
|
+
source: embeddingSource,
|
|
762
|
+
cacheDir,
|
|
763
|
+
download: true
|
|
764
|
+
}),
|
|
708
765
|
port: resolveProviderPort(provider)
|
|
709
766
|
});
|
|
710
767
|
})();
|
|
@@ -757,13 +814,13 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
757
814
|
transport: "local",
|
|
758
815
|
formatSetupError: (error) => `Managed local embeddings are unavailable. Run \`openclaw configure\`, choose llama.cpp, and retry. ${error instanceof Error ? error.message : String(error)}`,
|
|
759
816
|
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);
|
|
817
|
+
return resolveModelIdentity(readIdentityLocalOptions(options), options.dimensions);
|
|
762
818
|
},
|
|
763
819
|
create: async (options) => {
|
|
764
|
-
const local =
|
|
765
|
-
const
|
|
766
|
-
|
|
820
|
+
const local = readIdentityLocalOptions(options);
|
|
821
|
+
const embeddingModel = resolveLlamaCppEmbeddingModel(local);
|
|
822
|
+
const identity = resolveModelIdentity(local, options.dimensions);
|
|
823
|
+
await prepareEmbeddingServer(options, embeddingModel.source, embeddingModel.isDefault);
|
|
767
824
|
const genericAdapter = getEmbeddingProvider("openai-compatible", options.config);
|
|
768
825
|
if (!genericAdapter) throw new Error("OpenAI-compatible embedding transport is unavailable.");
|
|
769
826
|
const result = await genericAdapter.create({
|
|
@@ -773,7 +830,6 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
773
830
|
remote: void 0
|
|
774
831
|
});
|
|
775
832
|
if (!result.provider) return result;
|
|
776
|
-
const identity = resolveModelIdentity(local, modelPath, options.dimensions);
|
|
777
833
|
return {
|
|
778
834
|
provider: wrapProvider({
|
|
779
835
|
provider: result.provider,
|
|
@@ -905,7 +961,7 @@ function buildCompat(props) {
|
|
|
905
961
|
supportsReasoningEffort: false,
|
|
906
962
|
supportsTemperature: true,
|
|
907
963
|
supportsUsageInStreaming: true,
|
|
908
|
-
supportsTools: asBoolean(caps?.
|
|
964
|
+
supportsTools: asBoolean(caps?.supports_tool_calls) === true,
|
|
909
965
|
supportsStrictMode: false,
|
|
910
966
|
supportsJsonSchemaResponseFormat: true,
|
|
911
967
|
requiresStringContent: !(asBoolean(caps?.supports_typed_content) === true),
|
|
@@ -1073,12 +1129,9 @@ function buildLlamaCppAuthProfileRemovalPatch(config) {
|
|
|
1073
1129
|
//#endregion
|
|
1074
1130
|
//#region extensions/llama-cpp/src/external-server/setup.ts
|
|
1075
1131
|
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);
|
|
1132
|
+
const candidates = discovery.models.filter((model) => !model.failed);
|
|
1133
|
+
const ready = candidates.filter((model) => model.status === "loaded" || model.status === "sleeping");
|
|
1134
|
+
const ids = (ready.length > 0 ? ready : candidates).map((model) => model.config.id);
|
|
1082
1135
|
return selectPreferredLocalModelId(ids) ?? ids[0];
|
|
1083
1136
|
}
|
|
1084
1137
|
function describeDiscoveryFailure(result) {
|
|
@@ -1176,21 +1229,27 @@ async function removeDefaultAuthProfile(agentDir) {
|
|
|
1176
1229
|
profileIds: [LLAMA_CPP_DEFAULT_PROFILE_ID]
|
|
1177
1230
|
})) throw new Error("Failed to remove the previous llama-server auth profile; wait a moment and retry.");
|
|
1178
1231
|
}
|
|
1179
|
-
async function discoverForSetup(
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1232
|
+
async function discoverForSetup(ctx) {
|
|
1233
|
+
const provider = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1234
|
+
if (provider?.localService) return null;
|
|
1235
|
+
try {
|
|
1236
|
+
const headers = await resolveLlamaServerProviderHeaders({
|
|
1237
|
+
config: ctx.config,
|
|
1238
|
+
env: ctx.env,
|
|
1239
|
+
headers: provider?.headers
|
|
1240
|
+
});
|
|
1241
|
+
const apiKey = !hasLlamaServerAuthorizationHeader(headers) ? await resolveLlamaServerRuntimeApiKey({ config: ctx.config }) : void 0;
|
|
1242
|
+
const discovery = await discoverLlamaServer({
|
|
1243
|
+
baseUrl: provider?.baseUrl ?? "http://127.0.0.1:8080",
|
|
1244
|
+
apiKey,
|
|
1245
|
+
headers,
|
|
1246
|
+
signal: ctx.signal,
|
|
1247
|
+
cacheTtlMs: 0
|
|
1248
|
+
});
|
|
1249
|
+
return discovery.kind === "success" ? discovery : null;
|
|
1250
|
+
} catch {
|
|
1251
|
+
return null;
|
|
1252
|
+
}
|
|
1194
1253
|
}
|
|
1195
1254
|
async function discoverWithAccess(params) {
|
|
1196
1255
|
return await discoverLlamaServer({
|
|
@@ -1203,21 +1262,8 @@ async function discoverWithAccess(params) {
|
|
|
1203
1262
|
}
|
|
1204
1263
|
/** Read-only discovery for the guided local-provider setup ladder. */
|
|
1205
1264
|
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;
|
|
1265
|
+
const discovery = await discoverForSetup(ctx);
|
|
1266
|
+
if (!discovery) return null;
|
|
1221
1267
|
const modelId = selectSetupModelId(discovery);
|
|
1222
1268
|
if (!modelId) return null;
|
|
1223
1269
|
return {
|
|
@@ -1227,20 +1273,8 @@ async function detectLlamaServerSetup(ctx) {
|
|
|
1227
1273
|
}
|
|
1228
1274
|
/** Rechecks one guided candidate and returns the config needed for a live probe. */
|
|
1229
1275
|
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;
|
|
1276
|
+
const discovery = await discoverForSetup(ctx);
|
|
1277
|
+
if (!discovery) return null;
|
|
1244
1278
|
const prefix = `${LLAMA_CPP_PROVIDER_ID}/`;
|
|
1245
1279
|
const modelId = ctx.modelRef.startsWith(prefix) ? ctx.modelRef.slice(prefix.length) : "";
|
|
1246
1280
|
if (!modelId || !discovery.models.some((model) => model.config.id === modelId)) return null;
|
|
@@ -1485,13 +1519,20 @@ function formatDownloadProgress(label, params) {
|
|
|
1485
1519
|
function formatRamGb(totalmemBytes) {
|
|
1486
1520
|
return (totalmemBytes / 1024 ** 3).toFixed(1).replace(/\.0$/u, "");
|
|
1487
1521
|
}
|
|
1522
|
+
function describeEmbeddingDownload(isDefault) {
|
|
1523
|
+
return isDefault ? "the local embedding model (about 0.3 GB)" : "your configured local embedding model";
|
|
1524
|
+
}
|
|
1488
1525
|
function readPrimaryModel(config) {
|
|
1489
1526
|
const model = config.agents?.defaults?.model;
|
|
1490
1527
|
return typeof model === "string" ? model : model?.primary;
|
|
1491
1528
|
}
|
|
1492
|
-
function configuredCandidates(config) {
|
|
1529
|
+
function configuredCandidates(config, scope) {
|
|
1493
1530
|
const existing = config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1494
|
-
const
|
|
1531
|
+
const managedExisting = existing?.localService ? existing : void 0;
|
|
1532
|
+
const provider = buildLlamaCppProviderConfig({
|
|
1533
|
+
existing: managedExisting,
|
|
1534
|
+
...managedExisting && scope === "detection" ? { modelInventory: managedExisting.models } : {}
|
|
1535
|
+
});
|
|
1495
1536
|
const primary = readPrimaryModel(config);
|
|
1496
1537
|
const primaryId = primary?.startsWith(`llama-cpp/`) ? primary.slice(LLAMA_CPP_PROVIDER_ID.length + 1) : void 0;
|
|
1497
1538
|
return provider.models.map((model) => ({
|
|
@@ -1531,12 +1572,16 @@ function buildSetupResult(params) {
|
|
|
1531
1572
|
const switchingFromExternal = Boolean(existing && !existing.localService);
|
|
1532
1573
|
return {
|
|
1533
1574
|
profiles: [],
|
|
1534
|
-
defaultModel: params.defaultModel
|
|
1575
|
+
...params.defaultModel ? { defaultModel: params.defaultModel } : {},
|
|
1535
1576
|
configPatch: {
|
|
1536
1577
|
...buildLlamaCppAuthProfileRemovalPatch(params.config),
|
|
1537
1578
|
models: {
|
|
1538
1579
|
mode: params.config.models?.mode ?? "merge",
|
|
1539
|
-
providers: { [LLAMA_CPP_PROVIDER_ID]: buildLlamaCppProviderConfig(
|
|
1580
|
+
providers: { [LLAMA_CPP_PROVIDER_ID]: buildLlamaCppProviderConfig({
|
|
1581
|
+
existing: switchingFromExternal ? void 0 : existing,
|
|
1582
|
+
managed: params.managed,
|
|
1583
|
+
...params.plan === "embedding-only" ? { modelInventory: [] } : {}
|
|
1584
|
+
}) }
|
|
1540
1585
|
}
|
|
1541
1586
|
}
|
|
1542
1587
|
};
|
|
@@ -1546,7 +1591,7 @@ async function detectLlamaCppSetup(ctx) {
|
|
|
1546
1591
|
const command = existing?.localService?.command;
|
|
1547
1592
|
const presetPath = existing?.localService?.args?.find((_, index, args) => args[index - 1] === "--models-preset");
|
|
1548
1593
|
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 {
|
|
1594
|
+
for (const candidate of configuredCandidates(ctx.config, "detection")) if (await resolveCachedCandidate(candidate)) return {
|
|
1550
1595
|
modelRef: `${LLAMA_CPP_PROVIDER_ID}/${candidate.model.id}`,
|
|
1551
1596
|
detail: "Managed llama.cpp server ready"
|
|
1552
1597
|
};
|
|
@@ -1560,6 +1605,7 @@ async function prepareLlamaCppSetup(ctx) {
|
|
|
1560
1605
|
const rootUrl = baseUrl.replace(/\/v1$/u, "");
|
|
1561
1606
|
return buildSetupResult({
|
|
1562
1607
|
config: ctx.config,
|
|
1608
|
+
plan: "chat",
|
|
1563
1609
|
defaultModel: ctx.modelRef,
|
|
1564
1610
|
managed: {
|
|
1565
1611
|
command: existing.localService.command,
|
|
@@ -1569,52 +1615,101 @@ async function prepareLlamaCppSetup(ctx) {
|
|
|
1569
1615
|
}
|
|
1570
1616
|
});
|
|
1571
1617
|
}
|
|
1618
|
+
function resolveEmbeddingSetup(config, cacheDir) {
|
|
1619
|
+
const defaults = config.memory?.search;
|
|
1620
|
+
const models = listAgentIds(config).flatMap((agentId) => {
|
|
1621
|
+
const override = resolveAgentConfig(config, agentId)?.memory?.search;
|
|
1622
|
+
if (!(override?.enabled ?? defaults?.enabled ?? true) || (override?.provider ?? defaults?.provider) !== "local") return [];
|
|
1623
|
+
return [resolveLlamaCppEmbeddingModel({
|
|
1624
|
+
modelPath: override?.local?.modelPath ?? defaults?.local?.modelPath,
|
|
1625
|
+
modelCacheDir: cacheDir
|
|
1626
|
+
})];
|
|
1627
|
+
});
|
|
1628
|
+
const model = models[0] ?? resolveLlamaCppEmbeddingModel({ modelCacheDir: cacheDir });
|
|
1629
|
+
return {
|
|
1630
|
+
model,
|
|
1631
|
+
localMemoryIntent: models.length > 0,
|
|
1632
|
+
conflict: models.some((candidate) => candidate.source !== model.source)
|
|
1633
|
+
};
|
|
1634
|
+
}
|
|
1635
|
+
async function resolveSetupPlan(ctx, candidates, embeddingModelIsDefault, localMemoryIntent) {
|
|
1636
|
+
let candidate = candidates[0];
|
|
1637
|
+
const cachedPath = candidate ? await resolveCachedCandidate(candidate) : void 0;
|
|
1638
|
+
if (candidate && cachedPath) return {
|
|
1639
|
+
kind: "chat",
|
|
1640
|
+
candidate,
|
|
1641
|
+
cachedPath
|
|
1642
|
+
};
|
|
1643
|
+
candidate = candidates.find((entry) => entry.model.id === DEFAULT_LLAMA_CPP_MODEL_ID);
|
|
1644
|
+
const totalmemBytes = os.totalmem();
|
|
1645
|
+
if (candidate && meetsLlamaCppDefaultModelRamFloor(totalmemBytes)) {
|
|
1646
|
+
if (await ctx.prompter.confirm({
|
|
1647
|
+
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?`,
|
|
1648
|
+
initialValue: false
|
|
1649
|
+
})) return {
|
|
1650
|
+
kind: "chat",
|
|
1651
|
+
candidate
|
|
1652
|
+
};
|
|
1653
|
+
} else if (!localMemoryIntent) {
|
|
1654
|
+
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");
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1658
|
+
if (localMemoryIntent && existing && (!existing.localService || existing.models.length > 0)) {
|
|
1659
|
+
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");
|
|
1660
|
+
return;
|
|
1661
|
+
}
|
|
1662
|
+
if (localMemoryIntent) {
|
|
1663
|
+
if (await ctx.prompter.confirm({
|
|
1664
|
+
message: `OpenClaw can install a verified llama.cpp server and download only ${describeEmbeddingDownload(embeddingModelIsDefault)}. This will not install or change your chat model. Continue?`,
|
|
1665
|
+
initialValue: false
|
|
1666
|
+
})) return { kind: "embedding-only" };
|
|
1667
|
+
}
|
|
1668
|
+
await ctx.prompter.note("Local model setup skipped.", "Setup skipped");
|
|
1669
|
+
}
|
|
1572
1670
|
async function runLlamaCppSetup(ctx) {
|
|
1573
1671
|
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1574
1672
|
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
|
-
}
|
|
1673
|
+
const cacheDir = resolveLlamaCppModelCacheDir(managedExisting);
|
|
1674
|
+
const embeddingSetup = resolveEmbeddingSetup(ctx.config, cacheDir);
|
|
1675
|
+
if (embeddingSetup.conflict) {
|
|
1676
|
+
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");
|
|
1677
|
+
return { profiles: [] };
|
|
1592
1678
|
}
|
|
1593
|
-
|
|
1679
|
+
const embeddingModel = embeddingSetup.model;
|
|
1680
|
+
const plan = await resolveSetupPlan(ctx, configuredCandidates(ctx.config, "setup"), embeddingModel.isDefault, embeddingSetup.localMemoryIntent);
|
|
1681
|
+
if (!plan) return { profiles: [] };
|
|
1594
1682
|
const progress = ctx.prompter.progress("Preparing managed llama.cpp server…");
|
|
1595
1683
|
try {
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1684
|
+
let chatModel;
|
|
1685
|
+
if (plan.kind === "chat") {
|
|
1686
|
+
const chatModelPath = plan.cachedPath ?? await ensureLlamaCppModel({
|
|
1687
|
+
source: resolveLlamaCppModelSource(plan.candidate.model),
|
|
1688
|
+
cacheDir,
|
|
1689
|
+
download: true,
|
|
1690
|
+
signal: ctx.signal,
|
|
1691
|
+
onProgress: (status) => progress.update(formatDownloadProgress("Gemma 4 E4B", status))
|
|
1692
|
+
});
|
|
1693
|
+
const configuredContext = plan.candidate.model.params?.contextSize;
|
|
1694
|
+
chatModel = {
|
|
1695
|
+
mode: "configure",
|
|
1696
|
+
id: plan.candidate.model.id,
|
|
1697
|
+
path: chatModelPath,
|
|
1698
|
+
contextSize: typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : plan.candidate.model.contextTokens,
|
|
1699
|
+
maxTokens: plan.candidate.model.maxTokens
|
|
1700
|
+
};
|
|
1701
|
+
} else chatModel = { mode: "remove" };
|
|
1702
|
+
const embeddingModelLabel = embeddingModel.isDefault ? "EmbeddingGemma" : "configured embedding model";
|
|
1604
1703
|
const embeddingModelPath = await ensureLlamaCppModel({
|
|
1605
|
-
source:
|
|
1704
|
+
source: embeddingModel.source,
|
|
1606
1705
|
cacheDir,
|
|
1607
1706
|
download: true,
|
|
1608
1707
|
signal: ctx.signal,
|
|
1609
|
-
onProgress: (status) => progress.update(formatDownloadProgress(
|
|
1708
|
+
onProgress: (status) => progress.update(formatDownloadProgress(embeddingModelLabel, status))
|
|
1610
1709
|
});
|
|
1611
|
-
const configuredContext = selected.model.params?.contextSize;
|
|
1612
|
-
const contextSize = typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : selected.model.contextTokens;
|
|
1613
1710
|
const managed = await prepareManagedLlamaServer({
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
contextSize,
|
|
1617
|
-
maxTokens: selected.model.maxTokens,
|
|
1711
|
+
chatModel,
|
|
1712
|
+
embeddingModelIsDefault: embeddingModel.isDefault,
|
|
1618
1713
|
embeddingModelPath,
|
|
1619
1714
|
port: readConfiguredPort(managedExisting)
|
|
1620
1715
|
});
|
|
@@ -1627,7 +1722,8 @@ async function runLlamaCppSetup(ctx) {
|
|
|
1627
1722
|
return buildSetupResult({
|
|
1628
1723
|
config: ctx.config,
|
|
1629
1724
|
managed,
|
|
1630
|
-
|
|
1725
|
+
plan: plan.kind,
|
|
1726
|
+
...plan.kind === "chat" ? { defaultModel: `${LLAMA_CPP_PROVIDER_ID}/${plan.candidate.model.id}` } : {}
|
|
1631
1727
|
});
|
|
1632
1728
|
} catch (error) {
|
|
1633
1729
|
progress.stop("llama.cpp setup failed");
|
|
@@ -1688,7 +1784,10 @@ function registerLlamaCppProvider(api) {
|
|
|
1688
1784
|
order: "late",
|
|
1689
1785
|
run: async (ctx) => {
|
|
1690
1786
|
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1691
|
-
return configured?.localService ? { provider: buildLlamaCppProviderConfig(
|
|
1787
|
+
return configured?.localService ? { provider: buildLlamaCppProviderConfig({
|
|
1788
|
+
existing: configured,
|
|
1789
|
+
modelInventory: configured.models
|
|
1790
|
+
}) } : await discoverLlamaServerProvider(ctx);
|
|
1692
1791
|
}
|
|
1693
1792
|
},
|
|
1694
1793
|
staticCatalog: {
|
|
@@ -1,6 +1,7 @@
|
|
|
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";
|
|
@@ -12,7 +13,6 @@ 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-C9_YC5Rd.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.1
|
|
3
|
+
"version": "2026.8.1",
|
|
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.1
|
|
27
|
+
"pluginApi": ">=2026.8.1"
|
|
28
28
|
},
|
|
29
29
|
"build": {
|
|
30
|
-
"openclawVersion": "2026.8.1
|
|
30
|
+
"openclawVersion": "2026.8.1"
|
|
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.1
|
|
47
|
+
"openclaw": ">=2026.8.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"openclaw": {
|