@openclaw/llama-cpp-provider 2026.9.1-beta.1 → 2026.9.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,16 +1,16 @@
|
|
|
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
|
-
import fs from "node:fs";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import * as tar from "tar";
|
|
9
|
+
import fs, { constants } from "node:fs";
|
|
10
|
+
import fs$1 from "node:fs/promises";
|
|
11
|
+
import { ARCHIVE_LIMIT_ERROR_CODE, ArchiveLimitError, extractArchive } from "openclaw/plugin-sdk/archive";
|
|
13
12
|
import net from "node:net";
|
|
13
|
+
import { readProviderJsonResponse, readProviderTextResponse } from "openclaw/plugin-sdk/provider-http";
|
|
14
14
|
import { fetchWithSsrFGuard, ssrfPolicyFromHttpBaseUrlAllowedOrigin } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
15
15
|
import { fetchConfiguredLocalOriginWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime-internal";
|
|
16
16
|
import { CUSTOM_LOCAL_AUTH_MARKER, applyAuthProfileConfig, buildApiKeyCredential, ensureApiKeyFromEnvOrPrompt, hasConfiguredSecretInput, isNonSecretApiKeyMarker, normalizeOptionalSecretInput, upsertAuthProfileWithLock } from "openclaw/plugin-sdk/provider-auth";
|
|
@@ -22,63 +22,94 @@ 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";
|
|
29
|
+
const MACOS_ALIASES = [
|
|
30
|
+
["libggml-rpc.0.20.2.dylib", ["libggml-rpc.0.dylib", "libggml-rpc.dylib"]],
|
|
31
|
+
["libllama.0.1.2.dylib", ["libllama.0.dylib", "libllama.dylib"]],
|
|
32
|
+
["libmtmd.0.1.2.dylib", ["libmtmd.0.dylib", "libmtmd.dylib"]],
|
|
33
|
+
["libggml.0.20.2.dylib", ["libggml.0.dylib", "libggml.dylib"]],
|
|
34
|
+
["libggml-base.0.20.2.dylib", ["libggml-base.0.dylib", "libggml-base.dylib"]],
|
|
35
|
+
["libggml-blas.0.20.2.dylib", ["libggml-blas.0.dylib", "libggml-blas.dylib"]],
|
|
36
|
+
["libllama-common.0.1.2.dylib", ["libllama-common.0.dylib", "libllama-common.dylib"]],
|
|
37
|
+
["libggml-cpu.0.20.2.dylib", ["libggml-cpu.0.dylib", "libggml-cpu.dylib"]]
|
|
38
|
+
];
|
|
39
|
+
const MACOS_METAL_ALIASES = [...MACOS_ALIASES, ["libggml-metal.0.20.2.dylib", ["libggml-metal.0.dylib", "libggml-metal.dylib"]]];
|
|
40
|
+
const LINUX_ALIASES = [
|
|
41
|
+
["libllama.so.0.1.2", ["libllama.so.0", "libllama.so"]],
|
|
42
|
+
["libggml.so.0.20.2", ["libggml.so.0", "libggml.so"]],
|
|
43
|
+
["libmtmd.so.0.1.2", ["libmtmd.so.0", "libmtmd.so"]],
|
|
44
|
+
["libggml-base.so.0.20.2", ["libggml-base.so.0", "libggml-base.so"]],
|
|
45
|
+
["libllama-common.so.0.1.2", ["libllama-common.so.0", "libllama-common.so"]]
|
|
46
|
+
];
|
|
28
47
|
const LLAMA_SERVER_ASSETS = [
|
|
29
48
|
{
|
|
30
49
|
platform: "darwin",
|
|
31
50
|
arch: "arm64",
|
|
32
51
|
backend: "metal",
|
|
33
52
|
archive: "tar.gz",
|
|
53
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
34
54
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-arm64.tar.gz`,
|
|
35
|
-
sha256: "
|
|
36
|
-
executable: "llama-server"
|
|
55
|
+
sha256: "51f193eef26b053554e288fb924b24d41d3d7b2bafa338c19e2817fa793d5e86",
|
|
56
|
+
executable: "llama-server",
|
|
57
|
+
regularFileAliases: MACOS_METAL_ALIASES
|
|
37
58
|
},
|
|
38
59
|
{
|
|
39
60
|
platform: "darwin",
|
|
40
61
|
arch: "x64",
|
|
41
62
|
backend: "cpu",
|
|
42
63
|
archive: "tar.gz",
|
|
64
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
43
65
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-x64.tar.gz`,
|
|
44
|
-
sha256: "
|
|
45
|
-
executable: "llama-server"
|
|
66
|
+
sha256: "69b13035f4301354922a8cfacd1bcf2bb2de4ff0c2e19fedb44963378ff53dc5",
|
|
67
|
+
executable: "llama-server",
|
|
68
|
+
regularFileAliases: MACOS_ALIASES
|
|
46
69
|
},
|
|
47
70
|
{
|
|
48
71
|
platform: "linux",
|
|
49
72
|
arch: "arm64",
|
|
50
73
|
backend: "cpu",
|
|
51
74
|
archive: "tar.gz",
|
|
75
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
52
76
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-arm64.tar.gz`,
|
|
53
|
-
sha256: "
|
|
54
|
-
executable: "llama-server"
|
|
77
|
+
sha256: "66535de5cb9293c075a1951c51a3b2ae6f1899623e21177845f6d2a73b78c94e",
|
|
78
|
+
executable: "llama-server",
|
|
79
|
+
regularFileAliases: LINUX_ALIASES
|
|
55
80
|
},
|
|
56
81
|
{
|
|
57
82
|
platform: "linux",
|
|
58
83
|
arch: "x64",
|
|
59
84
|
backend: "cpu",
|
|
60
85
|
archive: "tar.gz",
|
|
86
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
61
87
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-x64.tar.gz`,
|
|
62
|
-
sha256: "
|
|
63
|
-
executable: "llama-server"
|
|
88
|
+
sha256: "cc6a12b026edcf1b211be2bb7366c5dadcad778fd8f13019d0694038053d5e4a",
|
|
89
|
+
executable: "llama-server",
|
|
90
|
+
regularFileAliases: LINUX_ALIASES
|
|
64
91
|
},
|
|
65
92
|
{
|
|
66
93
|
platform: "win32",
|
|
67
94
|
arch: "arm64",
|
|
68
95
|
backend: "cpu",
|
|
69
96
|
archive: "zip",
|
|
97
|
+
archiveRoot: ".",
|
|
70
98
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-arm64.zip`,
|
|
71
|
-
sha256: "
|
|
72
|
-
executable: "llama-server.exe"
|
|
99
|
+
sha256: "d33618b10fda35d34d85da60926c6c470f98f3f66ce6b52c3c1f583461416012",
|
|
100
|
+
executable: "llama-server.exe",
|
|
101
|
+
regularFileAliases: []
|
|
73
102
|
},
|
|
74
103
|
{
|
|
75
104
|
platform: "win32",
|
|
76
105
|
arch: "x64",
|
|
77
106
|
backend: "cpu",
|
|
78
107
|
archive: "zip",
|
|
108
|
+
archiveRoot: ".",
|
|
79
109
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-x64.zip`,
|
|
80
|
-
sha256: "
|
|
81
|
-
executable: "llama-server.exe"
|
|
110
|
+
sha256: "295ae03ad58d9276afa36f5f8d111d67fc1491c7aff3a3e6d13051a772f93c21",
|
|
111
|
+
executable: "llama-server.exe",
|
|
112
|
+
regularFileAliases: []
|
|
82
113
|
}
|
|
83
114
|
];
|
|
84
115
|
function selectLlamaServerAsset(platform = process.platform, arch = process.arch) {
|
|
@@ -95,8 +126,83 @@ function resolveManagedLlamaServerPaths(asset = selectLlamaServerAsset()) {
|
|
|
95
126
|
};
|
|
96
127
|
}
|
|
97
128
|
//#endregion
|
|
129
|
+
//#region extensions/llama-cpp/src/llama-server-extract.ts
|
|
130
|
+
const MEBIBYTE = 1048576;
|
|
131
|
+
const LLAMA_ARCHIVE_LIMITS = {
|
|
132
|
+
maxArchiveBytes: 256 * MEBIBYTE,
|
|
133
|
+
maxEntries: 1e3,
|
|
134
|
+
maxExtractedBytes: 512 * MEBIBYTE,
|
|
135
|
+
maxEntryBytes: 256 * MEBIBYTE,
|
|
136
|
+
maxMetaEntryBytes: MEBIBYTE
|
|
137
|
+
};
|
|
138
|
+
const MAX_ALIAS_BYTES = 512 * MEBIBYTE;
|
|
139
|
+
function assertManifestBasename(filename) {
|
|
140
|
+
if (!filename || filename === "." || filename === ".." || /[\\/]/u.test(filename) || path.basename(filename) !== filename) throw new Error(`invalid llama-server archive manifest filename: ${filename}`);
|
|
141
|
+
return filename;
|
|
142
|
+
}
|
|
143
|
+
function resolveArchiveRoot(destDir, archiveRoot) {
|
|
144
|
+
if (archiveRoot === ".") return destDir;
|
|
145
|
+
if (path.isAbsolute(archiveRoot) || /\\/u.test(archiveRoot)) throw new Error(`invalid llama-server archive root: ${archiveRoot}`);
|
|
146
|
+
const parts = archiveRoot.split("/");
|
|
147
|
+
if (parts.some((part) => !part || part === "." || part === "..")) throw new Error(`invalid llama-server archive root: ${archiveRoot}`);
|
|
148
|
+
return path.join(destDir, ...parts);
|
|
149
|
+
}
|
|
150
|
+
async function assertRegularFile(filePath, label) {
|
|
151
|
+
const stat = await fs$1.lstat(filePath).catch(() => void 0);
|
|
152
|
+
if (!stat?.isFile() || stat.nlink > 1) throw new Error(`llama-server archive does not contain regular ${label}`);
|
|
153
|
+
return stat;
|
|
154
|
+
}
|
|
155
|
+
async function materializeAssetAliases(params) {
|
|
156
|
+
const claimedNames = /* @__PURE__ */ new Set([assertManifestBasename(params.asset.executable)]);
|
|
157
|
+
await assertRegularFile(path.join(params.rootDir, params.asset.executable), `executable ${params.asset.executable}`);
|
|
158
|
+
let copiedBytes = 0;
|
|
159
|
+
for (const [rawSource, rawAliases] of params.asset.regularFileAliases) {
|
|
160
|
+
const source = assertManifestBasename(rawSource);
|
|
161
|
+
if (claimedNames.has(source)) throw new Error(`duplicate llama-server archive manifest filename: ${source}`);
|
|
162
|
+
claimedNames.add(source);
|
|
163
|
+
const sourcePath = path.join(params.rootDir, source);
|
|
164
|
+
const sourceStat = await assertRegularFile(sourcePath, `alias source ${source}`);
|
|
165
|
+
for (const rawAlias of rawAliases) {
|
|
166
|
+
const alias = assertManifestBasename(rawAlias);
|
|
167
|
+
if (claimedNames.has(alias)) throw new Error(`duplicate llama-server archive manifest filename: ${alias}`);
|
|
168
|
+
claimedNames.add(alias);
|
|
169
|
+
copiedBytes += sourceStat.size;
|
|
170
|
+
if (copiedBytes > MAX_ALIAS_BYTES) throw new ArchiveLimitError(ARCHIVE_LIMIT_ERROR_CODE.EXTRACTED_SIZE_EXCEEDS_LIMIT);
|
|
171
|
+
const aliasPath = path.join(params.rootDir, alias);
|
|
172
|
+
await fs$1.copyFile(sourcePath, aliasPath, constants.COPYFILE_EXCL);
|
|
173
|
+
await fs$1.chmod(aliasPath, sourceStat.mode & 511);
|
|
174
|
+
if ((await assertRegularFile(aliasPath, `alias ${alias}`)).size !== sourceStat.size) throw new Error(`llama-server archive alias copy is incomplete: ${alias}`);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
/** Extracts one verified asset and returns its unpublished executable path. */
|
|
179
|
+
async function extractLlamaServerArchive(params) {
|
|
180
|
+
const isTar = params.asset.archive === "tar.gz";
|
|
181
|
+
const aliasCount = params.asset.regularFileAliases.reduce((count, [, aliases]) => count + aliases.length, 0);
|
|
182
|
+
if (aliasCount > LLAMA_ARCHIVE_LIMITS.maxEntries) throw new ArchiveLimitError(ARCHIVE_LIMIT_ERROR_CODE.ENTRY_COUNT_EXCEEDS_LIMIT);
|
|
183
|
+
await extractArchive({
|
|
184
|
+
archivePath: params.archivePath,
|
|
185
|
+
destDir: params.destDir,
|
|
186
|
+
kind: isTar ? "tar" : "zip",
|
|
187
|
+
timeoutMs: 0,
|
|
188
|
+
limits: {
|
|
189
|
+
...LLAMA_ARCHIVE_LIMITS,
|
|
190
|
+
maxEntries: LLAMA_ARCHIVE_LIMITS.maxEntries - aliasCount
|
|
191
|
+
},
|
|
192
|
+
tarGzip: isTar,
|
|
193
|
+
entryFilter: (entry) => entry.kind === "symlink" ? "skip" : "extract",
|
|
194
|
+
onFiltered: "skip-entry"
|
|
195
|
+
});
|
|
196
|
+
const rootDir = resolveArchiveRoot(params.destDir, params.asset.archiveRoot);
|
|
197
|
+
await materializeAssetAliases({
|
|
198
|
+
rootDir,
|
|
199
|
+
asset: params.asset
|
|
200
|
+
});
|
|
201
|
+
return path.join(rootDir, params.asset.executable);
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
98
204
|
//#region extensions/llama-cpp/src/llama-server-install.ts
|
|
99
|
-
const DOWNLOAD_TIMEOUT_MS =
|
|
205
|
+
const DOWNLOAD_TIMEOUT_MS = 18e5;
|
|
100
206
|
const VERSION_TIMEOUT_MS = 15e3;
|
|
101
207
|
const installationPromises = /* @__PURE__ */ new Map();
|
|
102
208
|
function compareVersion(left, right) {
|
|
@@ -139,7 +245,7 @@ function readResponseSha256(response) {
|
|
|
139
245
|
}
|
|
140
246
|
async function downloadVerifiedFile(params) {
|
|
141
247
|
const partialPath = `${params.destination}.partial-${randomUUID()}`;
|
|
142
|
-
await
|
|
248
|
+
await fs$1.mkdir(path.dirname(params.destination), { recursive: true });
|
|
143
249
|
const { fetchWithSsrFGuard, ssrfPolicyFromHttpBaseUrlAllowedOrigin } = await import("openclaw/plugin-sdk/ssrf-runtime");
|
|
144
250
|
try {
|
|
145
251
|
const { response, release } = await fetchWithSsrFGuard({
|
|
@@ -156,17 +262,14 @@ async function downloadVerifiedFile(params) {
|
|
|
156
262
|
if (!expectedSha256 && params.requireServerDigest) throw new Error("the download server did not provide a SHA-256 digest; download the GGUF manually and configure its local path");
|
|
157
263
|
const contentLength = Number(response.headers.get("content-length"));
|
|
158
264
|
const totalSize = params.expectedSize ?? (Number.isFinite(contentLength) && contentLength > 0 ? contentLength : 0);
|
|
159
|
-
const handle = await
|
|
265
|
+
const handle = await fs$1.open(partialPath, "wx", 384);
|
|
160
266
|
const hash = createHash("sha256");
|
|
161
|
-
const reader = response.body.getReader();
|
|
162
267
|
let downloadedSize = 0;
|
|
163
268
|
let previousSize = 0;
|
|
164
269
|
let previousAt = Date.now();
|
|
165
270
|
let rollingBytesPerSecond = 0;
|
|
166
271
|
try {
|
|
167
|
-
for (
|
|
168
|
-
const { done, value } = await reader.read();
|
|
169
|
-
if (done) break;
|
|
272
|
+
for await (const value of response.body.values({ preventCancel: true })) {
|
|
170
273
|
const chunk = Buffer.from(value);
|
|
171
274
|
await handle.writeFile(chunk);
|
|
172
275
|
hash.update(chunk);
|
|
@@ -190,38 +293,14 @@ async function downloadVerifiedFile(params) {
|
|
|
190
293
|
if (params.expectedSize && downloadedSize !== params.expectedSize) throw new Error(`download size mismatch: expected ${params.expectedSize}, got ${downloadedSize}`);
|
|
191
294
|
const actualSha256 = hash.digest("hex");
|
|
192
295
|
if (expectedSha256 && actualSha256 !== expectedSha256.toLowerCase()) throw new Error(`download SHA-256 mismatch: expected ${expectedSha256}, got ${actualSha256}`);
|
|
193
|
-
await
|
|
296
|
+
await fs$1.rename(partialPath, params.destination);
|
|
194
297
|
} finally {
|
|
195
298
|
await release();
|
|
196
299
|
}
|
|
197
300
|
} finally {
|
|
198
|
-
await
|
|
301
|
+
await fs$1.rm(partialPath, { force: true }).catch(() => void 0);
|
|
199
302
|
}
|
|
200
303
|
}
|
|
201
|
-
async function extractZip(archivePath, destination) {
|
|
202
|
-
const zip = await JSZip.loadAsync(await fsp.readFile(archivePath));
|
|
203
|
-
for (const entry of Object.values(zip.files)) {
|
|
204
|
-
const normalized = path.posix.normalize(entry.name);
|
|
205
|
-
if (normalized.startsWith("/") || normalized === ".." || normalized.startsWith("../")) throw new Error(`unsafe path in llama-server archive: ${entry.name}`);
|
|
206
|
-
const outputPath = path.join(destination, ...normalized.split("/"));
|
|
207
|
-
if (entry.dir) await fsp.mkdir(outputPath, { recursive: true });
|
|
208
|
-
else {
|
|
209
|
-
await fsp.mkdir(path.dirname(outputPath), { recursive: true });
|
|
210
|
-
await fsp.writeFile(outputPath, await entry.async("nodebuffer"), { mode: 384 });
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
async function findExecutable(root, executable) {
|
|
215
|
-
for (const entry of await fsp.readdir(root, { withFileTypes: true })) {
|
|
216
|
-
const candidate = path.join(root, entry.name);
|
|
217
|
-
if (entry.isFile() && entry.name === executable) return candidate;
|
|
218
|
-
if (entry.isDirectory()) {
|
|
219
|
-
const nested = await findExecutable(candidate, executable).catch(() => void 0);
|
|
220
|
-
if (nested) return nested;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
throw new Error(`llama-server archive does not contain ${executable}`);
|
|
224
|
-
}
|
|
225
304
|
async function runVersion(command) {
|
|
226
305
|
return await new Promise((resolve, reject) => {
|
|
227
306
|
execFile(command, ["--version"], { timeout: VERSION_TIMEOUT_MS }, (error, stdout, stderr) => {
|
|
@@ -246,46 +325,44 @@ async function validateInstalledServer(command) {
|
|
|
246
325
|
const match = (version.split(/\r?\n/u, 1)[0]?.trim() ?? "").match(/^version: .+ \(build (\d+), commit ([a-f\d]{9})\)$/u);
|
|
247
326
|
const build = match?.[1] ? Number(match[1]) : void 0;
|
|
248
327
|
const commit = match?.[2];
|
|
249
|
-
if (build !==
|
|
328
|
+
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"}`);
|
|
250
329
|
}
|
|
251
330
|
async function installLlamaServer(asset) {
|
|
252
331
|
assertSupportedLinuxRuntime(asset);
|
|
253
332
|
const { installDir, command } = resolveManagedLlamaServerPaths(asset);
|
|
254
|
-
if (await
|
|
333
|
+
if (await fs$1.stat(command).then((stat) => stat.isFile()).catch(() => false)) {
|
|
255
334
|
await validateInstalledServer(command);
|
|
256
335
|
return command;
|
|
257
336
|
}
|
|
258
337
|
const dataDir = resolveLlamaCppDataDir();
|
|
259
338
|
const archivePath = path.join(dataDir, `.download-${randomUUID()}-${asset.name}`);
|
|
260
339
|
const extractDir = path.join(dataDir, `.extract-${randomUUID()}`);
|
|
261
|
-
await
|
|
340
|
+
await fs$1.mkdir(dataDir, { recursive: true });
|
|
262
341
|
try {
|
|
263
342
|
await downloadVerifiedFile({
|
|
264
343
|
url: assetUrl(asset),
|
|
265
344
|
destination: archivePath,
|
|
266
345
|
expectedSha256: asset.sha256
|
|
267
346
|
});
|
|
268
|
-
await
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
preservePaths: false
|
|
347
|
+
await fs$1.mkdir(extractDir, { recursive: true });
|
|
348
|
+
const extractedCommand = await extractLlamaServerArchive({
|
|
349
|
+
archivePath,
|
|
350
|
+
destDir: extractDir,
|
|
351
|
+
asset
|
|
274
352
|
});
|
|
275
|
-
const extractedCommand = await findExecutable(extractDir, asset.executable);
|
|
276
353
|
const extractedRoot = path.dirname(extractedCommand);
|
|
277
|
-
await
|
|
354
|
+
await fs$1.chmod(extractedCommand, 493);
|
|
278
355
|
await validateInstalledServer(extractedCommand);
|
|
279
|
-
await
|
|
280
|
-
await
|
|
356
|
+
await fs$1.mkdir(path.dirname(installDir), { recursive: true });
|
|
357
|
+
await fs$1.rm(installDir, {
|
|
281
358
|
recursive: true,
|
|
282
359
|
force: true
|
|
283
360
|
});
|
|
284
|
-
await
|
|
361
|
+
await fs$1.rename(extractedRoot, installDir);
|
|
285
362
|
await validateInstalledServer(command);
|
|
286
363
|
return command;
|
|
287
364
|
} finally {
|
|
288
|
-
await Promise.all([
|
|
365
|
+
await Promise.all([fs$1.rm(archivePath, { force: true }), fs$1.rm(extractDir, {
|
|
289
366
|
recursive: true,
|
|
290
367
|
force: true
|
|
291
368
|
})]);
|
|
@@ -398,7 +475,7 @@ function defaultArtifact(source) {
|
|
|
398
475
|
};
|
|
399
476
|
}
|
|
400
477
|
async function assertGguf(filePath) {
|
|
401
|
-
const handle = await
|
|
478
|
+
const handle = await fs$1.open(filePath, "r").catch((error) => {
|
|
402
479
|
if ((error instanceof Error && "code" in error ? error.code : void 0) === "ENOENT") throw new Error(`Model file is missing: ${filePath}. Run interactive llama.cpp setup or correct params.modelPath.`, { cause: error });
|
|
403
480
|
throw error;
|
|
404
481
|
});
|
|
@@ -437,11 +514,13 @@ async function ensureLlamaCppModel(params) {
|
|
|
437
514
|
const pending = modelPromises.get(destination);
|
|
438
515
|
if (pending) return await pending;
|
|
439
516
|
const load = (async () => {
|
|
440
|
-
if (await
|
|
441
|
-
if (
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
517
|
+
if (await fs$1.stat(destination).then((stat) => stat.isFile()).catch(() => false)) {
|
|
518
|
+
if (artifact.expectedSha256) {
|
|
519
|
+
if (await sha256File(destination) === artifact.expectedSha256) return destination;
|
|
520
|
+
} else {
|
|
521
|
+
await assertGguf(destination);
|
|
522
|
+
return destination;
|
|
523
|
+
}
|
|
445
524
|
}
|
|
446
525
|
if (!params.download) throw new Error(`Model is not cached at ${destination}`);
|
|
447
526
|
await downloadVerifiedFile({
|
|
@@ -509,26 +588,23 @@ function renderLlamaServerPreset(params) {
|
|
|
509
588
|
].join("\n");
|
|
510
589
|
}
|
|
511
590
|
async function writePreset(presetPath, contents) {
|
|
512
|
-
await
|
|
591
|
+
await fs$1.mkdir(path.dirname(presetPath), { recursive: true });
|
|
513
592
|
const temporary = `${presetPath}.tmp-${randomUUID()}`;
|
|
514
|
-
await
|
|
515
|
-
await
|
|
593
|
+
await fs$1.writeFile(temporary, contents, { mode: 384 });
|
|
594
|
+
await fs$1.rename(temporary, presetPath);
|
|
516
595
|
}
|
|
517
596
|
async function updatePreset(presetPath, params) {
|
|
518
597
|
const pending = (presetWritePromises.get(presetPath) ?? Promise.resolve()).catch(() => void 0).then(async () => {
|
|
519
|
-
const existing = await
|
|
598
|
+
const existing = await fs$1.readFile(presetPath, "utf8").catch((error) => {
|
|
520
599
|
if (asOptionalRecord(error)?.code === "ENOENT") return;
|
|
521
600
|
throw error;
|
|
522
601
|
});
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
contextSize: params.contextSize,
|
|
530
|
-
maxTokens: params.maxTokens
|
|
531
|
-
}) : readChatModelSection(existing);
|
|
602
|
+
const chatSection = params.chatModel.mode === "preserve" ? readChatModelSection(existing) : params.chatModel.mode === "configure" ? renderChatModelSection({
|
|
603
|
+
id: params.chatModel.id,
|
|
604
|
+
modelPath: params.chatModel.path,
|
|
605
|
+
contextSize: params.chatModel.contextSize,
|
|
606
|
+
maxTokens: params.chatModel.maxTokens
|
|
607
|
+
}) : void 0;
|
|
532
608
|
const embeddingSection = params.embeddingModelPath ? renderEmbeddingModelSection({
|
|
533
609
|
isDefault: params.embeddingModelIsDefault,
|
|
534
610
|
modelPath: params.embeddingModelPath
|
|
@@ -566,12 +642,7 @@ async function prepareManagedLlamaServer(params) {
|
|
|
566
642
|
const { command, asset } = await ensureLlamaServerInstalled();
|
|
567
643
|
const { presetPath } = resolveManagedLlamaServerPaths(asset);
|
|
568
644
|
await updatePreset(presetPath, {
|
|
569
|
-
|
|
570
|
-
chatModelId: params.chatModelId ?? "gemma-4-e4b-it-q4_k_m",
|
|
571
|
-
chatModelPath: params.chatModelPath
|
|
572
|
-
} : {},
|
|
573
|
-
contextSize: params.contextSize,
|
|
574
|
-
maxTokens: params.maxTokens,
|
|
645
|
+
chatModel: params.chatModel,
|
|
575
646
|
embeddingModelIsDefault: params.embeddingModelIsDefault,
|
|
576
647
|
embeddingModelPath: params.embeddingModelPath,
|
|
577
648
|
defaultEmbeddingModelPath: params.defaultEmbeddingModelPath
|
|
@@ -612,7 +683,7 @@ async function ensureManagedLlamaServerForChat(params) {
|
|
|
612
683
|
});
|
|
613
684
|
if (!chatModelPath && resolveLlamaCppModelSource(params.model) === "hf:unsloth/gemma-4-E4B-it-GGUF/gemma-4-E4B-it-Q4_K_M.gguf") {
|
|
614
685
|
const legacy = path.join(resolveLegacyLlamaCppModelCacheDir(), "hf_unsloth_gemma-4-E4B-it-GGUF_gemma-4-E4B-it-Q4_K_M.gguf");
|
|
615
|
-
if (await
|
|
686
|
+
if (await fs$1.stat(legacy).then((stat) => stat.isFile()).catch(() => false)) chatModelPath = legacy;
|
|
616
687
|
}
|
|
617
688
|
chatModelPath = await ensureLlamaCppModel({
|
|
618
689
|
source: chatModelPath ?? resolveLlamaCppModelSource(params.model),
|
|
@@ -622,10 +693,13 @@ async function ensureManagedLlamaServerForChat(params) {
|
|
|
622
693
|
const configuredContext = params.model.params?.contextSize;
|
|
623
694
|
const port = Number(new URL(params.provider.baseUrl).port);
|
|
624
695
|
await prepareManagedLlamaServer({
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
696
|
+
chatModel: {
|
|
697
|
+
mode: "configure",
|
|
698
|
+
id: params.model.id,
|
|
699
|
+
path: chatModelPath,
|
|
700
|
+
contextSize: typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : params.model.contextTokens,
|
|
701
|
+
maxTokens: params.model.maxTokens
|
|
702
|
+
},
|
|
629
703
|
defaultEmbeddingModelPath: path.join(cacheDir, "hf_ggml-org_embeddinggemma-300m-qat-Q8_0.gguf"),
|
|
630
704
|
port: Number.isInteger(port) && port > 0 ? port : void 0
|
|
631
705
|
});
|
|
@@ -652,7 +726,7 @@ async function fetchEndpoint(url, accept) {
|
|
|
652
726
|
if (!response.ok) return { ok: false };
|
|
653
727
|
return {
|
|
654
728
|
ok: true,
|
|
655
|
-
value: accept === "json" ? await response
|
|
729
|
+
value: accept === "json" ? await readProviderJsonResponse(response, "llama-server inspection") : await readProviderTextResponse(response, "llama-server inspection")
|
|
656
730
|
};
|
|
657
731
|
} finally {
|
|
658
732
|
await release();
|
|
@@ -719,14 +793,14 @@ function createCacheKeyData(model, dimensions) {
|
|
|
719
793
|
...typeof dimensions === "number" ? { outputDimensionality: dimensions } : {}
|
|
720
794
|
};
|
|
721
795
|
}
|
|
722
|
-
function resolveModelIdentity(local,
|
|
723
|
-
const
|
|
796
|
+
function resolveModelIdentity(local, dimensions) {
|
|
797
|
+
const embeddingModel = resolveLlamaCppEmbeddingModel(local);
|
|
798
|
+
const configuredCacheDir = embeddingModel.cacheDir;
|
|
724
799
|
const currentDefaultPath = path.resolve(configuredCacheDir, DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE);
|
|
725
800
|
const legacyDefaultPath = path.resolve(resolveLegacyLlamaCppModelCacheDir(), DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE);
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
cacheKeyData: createCacheKeyData(modelPath, dimensions),
|
|
801
|
+
if (!embeddingModel.isDefault) return {
|
|
802
|
+
model: embeddingModel.source,
|
|
803
|
+
cacheKeyData: createCacheKeyData(embeddingModel.source, dimensions),
|
|
730
804
|
aliases: []
|
|
731
805
|
};
|
|
732
806
|
const aliases = /* @__PURE__ */ new Set([
|
|
@@ -734,7 +808,7 @@ function resolveModelIdentity(local, modelPath, dimensions) {
|
|
|
734
808
|
legacyDefaultPath,
|
|
735
809
|
DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE
|
|
736
810
|
]);
|
|
737
|
-
if (
|
|
811
|
+
if (embeddingModel.source !== "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf") aliases.add(embeddingModel.source);
|
|
738
812
|
return {
|
|
739
813
|
model: DEFAULT_LLAMA_CPP_EMBEDDING_MODEL,
|
|
740
814
|
cacheKeyData: createCacheKeyData(DEFAULT_LLAMA_CPP_EMBEDDING_MODEL, dimensions),
|
|
@@ -744,14 +818,6 @@ function resolveModelIdentity(local, modelPath, dimensions) {
|
|
|
744
818
|
}))
|
|
745
819
|
};
|
|
746
820
|
}
|
|
747
|
-
function resolveLlamaCppEmbeddingModel(localValue) {
|
|
748
|
-
const local = readLocalOptions({ local: localValue });
|
|
749
|
-
const source = normalizeOptionalString(local.modelPath) ?? "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf";
|
|
750
|
-
return {
|
|
751
|
-
source,
|
|
752
|
-
isDefault: resolveModelIdentity(local, source).model === DEFAULT_LLAMA_CPP_EMBEDDING_MODEL
|
|
753
|
-
};
|
|
754
|
-
}
|
|
755
821
|
function resolveConfiguredProvider(options) {
|
|
756
822
|
return resolveManagedLlamaCppProviderConfig(options.config);
|
|
757
823
|
}
|
|
@@ -770,6 +836,7 @@ async function prepareEmbeddingServer(options, embeddingSource, embeddingModelIs
|
|
|
770
836
|
]);
|
|
771
837
|
const pending = preparedEmbeddingServers.get(key) ?? (async () => {
|
|
772
838
|
await prepareManagedLlamaServer({
|
|
839
|
+
chatModel: { mode: "preserve" },
|
|
773
840
|
embeddingModelIsDefault,
|
|
774
841
|
embeddingModelPath: await ensureLlamaCppModel({
|
|
775
842
|
source: embeddingSource,
|
|
@@ -828,13 +895,12 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
828
895
|
transport: "local",
|
|
829
896
|
formatSetupError: (error) => `Managed local embeddings are unavailable. Run \`openclaw configure\`, choose llama.cpp, and retry. ${error instanceof Error ? error.message : String(error)}`,
|
|
830
897
|
resolveIndexIdentity: (options) => {
|
|
831
|
-
|
|
832
|
-
return resolveModelIdentity(local, normalizeOptionalString(local.modelPath) ?? "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf", options.dimensions);
|
|
898
|
+
return resolveModelIdentity(readIdentityLocalOptions(options), options.dimensions);
|
|
833
899
|
},
|
|
834
900
|
create: async (options) => {
|
|
835
901
|
const local = readIdentityLocalOptions(options);
|
|
836
902
|
const embeddingModel = resolveLlamaCppEmbeddingModel(local);
|
|
837
|
-
const identity = resolveModelIdentity(local,
|
|
903
|
+
const identity = resolveModelIdentity(local, options.dimensions);
|
|
838
904
|
await prepareEmbeddingServer(options, embeddingModel.source, embeddingModel.isDefault);
|
|
839
905
|
const genericAdapter = getEmbeddingProvider("openai-compatible", options.config);
|
|
840
906
|
if (!genericAdapter) throw new Error("OpenAI-compatible embedding transport is unavailable.");
|
|
@@ -853,8 +919,8 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
853
919
|
}),
|
|
854
920
|
runtime: {
|
|
855
921
|
id: "local",
|
|
856
|
-
inlineQueryTimeoutMs:
|
|
857
|
-
inlineBatchTimeoutMs:
|
|
922
|
+
inlineQueryTimeoutMs: 3e5,
|
|
923
|
+
inlineBatchTimeoutMs: 6e5,
|
|
858
924
|
cacheKeyData: identity.cacheKeyData,
|
|
859
925
|
...identity.aliases.length > 0 ? { indexIdentityAliases: identity.aliases } : {}
|
|
860
926
|
}
|
|
@@ -1534,13 +1600,20 @@ function formatDownloadProgress(label, params) {
|
|
|
1534
1600
|
function formatRamGb(totalmemBytes) {
|
|
1535
1601
|
return (totalmemBytes / 1024 ** 3).toFixed(1).replace(/\.0$/u, "");
|
|
1536
1602
|
}
|
|
1603
|
+
function describeEmbeddingDownload(isDefault) {
|
|
1604
|
+
return isDefault ? "the local embedding model (about 0.3 GB)" : "your configured local embedding model";
|
|
1605
|
+
}
|
|
1537
1606
|
function readPrimaryModel(config) {
|
|
1538
1607
|
const model = config.agents?.defaults?.model;
|
|
1539
1608
|
return typeof model === "string" ? model : model?.primary;
|
|
1540
1609
|
}
|
|
1541
|
-
function configuredCandidates(config) {
|
|
1610
|
+
function configuredCandidates(config, scope) {
|
|
1542
1611
|
const existing = config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1543
|
-
const
|
|
1612
|
+
const managedExisting = existing?.localService ? existing : void 0;
|
|
1613
|
+
const provider = buildLlamaCppProviderConfig({
|
|
1614
|
+
existing: managedExisting,
|
|
1615
|
+
...managedExisting && scope === "detection" ? { modelInventory: managedExisting.models } : {}
|
|
1616
|
+
});
|
|
1544
1617
|
const primary = readPrimaryModel(config);
|
|
1545
1618
|
const primaryId = primary?.startsWith(`llama-cpp/`) ? primary.slice(LLAMA_CPP_PROVIDER_ID.length + 1) : void 0;
|
|
1546
1619
|
return provider.models.map((model) => ({
|
|
@@ -1549,7 +1622,7 @@ function configuredCandidates(config) {
|
|
|
1549
1622
|
})).toSorted((a, b) => Number(b.model.id === primaryId) - Number(a.model.id === primaryId));
|
|
1550
1623
|
}
|
|
1551
1624
|
async function isFile(filePath) {
|
|
1552
|
-
return await
|
|
1625
|
+
return await fs$1.stat(filePath).then((stat) => stat.isFile()).catch(() => false);
|
|
1553
1626
|
}
|
|
1554
1627
|
async function resolveCachedCandidate(candidate) {
|
|
1555
1628
|
const source = resolveLlamaCppModelSource(candidate.model);
|
|
@@ -1580,12 +1653,16 @@ function buildSetupResult(params) {
|
|
|
1580
1653
|
const switchingFromExternal = Boolean(existing && !existing.localService);
|
|
1581
1654
|
return {
|
|
1582
1655
|
profiles: [],
|
|
1583
|
-
defaultModel: params.defaultModel
|
|
1656
|
+
...params.defaultModel ? { defaultModel: params.defaultModel } : {},
|
|
1584
1657
|
configPatch: {
|
|
1585
1658
|
...buildLlamaCppAuthProfileRemovalPatch(params.config),
|
|
1586
1659
|
models: {
|
|
1587
1660
|
mode: params.config.models?.mode ?? "merge",
|
|
1588
|
-
providers: { [LLAMA_CPP_PROVIDER_ID]: buildLlamaCppProviderConfig(
|
|
1661
|
+
providers: { [LLAMA_CPP_PROVIDER_ID]: buildLlamaCppProviderConfig({
|
|
1662
|
+
existing: switchingFromExternal ? void 0 : existing,
|
|
1663
|
+
managed: params.managed,
|
|
1664
|
+
...params.plan === "embedding-only" ? { modelInventory: [] } : {}
|
|
1665
|
+
}) }
|
|
1589
1666
|
}
|
|
1590
1667
|
}
|
|
1591
1668
|
};
|
|
@@ -1595,7 +1672,7 @@ async function detectLlamaCppSetup(ctx) {
|
|
|
1595
1672
|
const command = existing?.localService?.command;
|
|
1596
1673
|
const presetPath = existing?.localService?.args?.find((_, index, args) => args[index - 1] === "--models-preset");
|
|
1597
1674
|
if (!command || !path.isAbsolute(command) || !await isFile(command) || !presetPath || !await isFile(presetPath)) return null;
|
|
1598
|
-
for (const candidate of configuredCandidates(ctx.config)) if (await resolveCachedCandidate(candidate)) return {
|
|
1675
|
+
for (const candidate of configuredCandidates(ctx.config, "detection")) if (await resolveCachedCandidate(candidate)) return {
|
|
1599
1676
|
modelRef: `${LLAMA_CPP_PROVIDER_ID}/${candidate.model.id}`,
|
|
1600
1677
|
detail: "Managed llama.cpp server ready"
|
|
1601
1678
|
};
|
|
@@ -1609,6 +1686,7 @@ async function prepareLlamaCppSetup(ctx) {
|
|
|
1609
1686
|
const rootUrl = baseUrl.replace(/\/v1$/u, "");
|
|
1610
1687
|
return buildSetupResult({
|
|
1611
1688
|
config: ctx.config,
|
|
1689
|
+
plan: "chat",
|
|
1612
1690
|
defaultModel: ctx.modelRef,
|
|
1613
1691
|
managed: {
|
|
1614
1692
|
command: existing.localService.command,
|
|
@@ -1618,53 +1696,101 @@ async function prepareLlamaCppSetup(ctx) {
|
|
|
1618
1696
|
}
|
|
1619
1697
|
});
|
|
1620
1698
|
}
|
|
1699
|
+
function resolveEmbeddingSetup(config, cacheDir) {
|
|
1700
|
+
const defaults = config.memory?.search;
|
|
1701
|
+
const models = listAgentIds(config).flatMap((agentId) => {
|
|
1702
|
+
const override = resolveAgentConfig(config, agentId)?.memory?.search;
|
|
1703
|
+
if (!(override?.enabled ?? defaults?.enabled ?? true) || (override?.provider ?? defaults?.provider) !== "local") return [];
|
|
1704
|
+
return [resolveLlamaCppEmbeddingModel({
|
|
1705
|
+
modelPath: override?.local?.modelPath ?? defaults?.local?.modelPath,
|
|
1706
|
+
modelCacheDir: cacheDir
|
|
1707
|
+
})];
|
|
1708
|
+
});
|
|
1709
|
+
const model = models[0] ?? resolveLlamaCppEmbeddingModel({ modelCacheDir: cacheDir });
|
|
1710
|
+
return {
|
|
1711
|
+
model,
|
|
1712
|
+
localMemoryIntent: models.length > 0,
|
|
1713
|
+
conflict: models.some((candidate) => candidate.source !== model.source)
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
async function resolveSetupPlan(ctx, candidates, embeddingModelIsDefault, localMemoryIntent) {
|
|
1717
|
+
let candidate = candidates[0];
|
|
1718
|
+
const cachedPath = candidate ? await resolveCachedCandidate(candidate) : void 0;
|
|
1719
|
+
if (candidate && cachedPath) return {
|
|
1720
|
+
kind: "chat",
|
|
1721
|
+
candidate,
|
|
1722
|
+
cachedPath
|
|
1723
|
+
};
|
|
1724
|
+
candidate = candidates.find((entry) => entry.model.id === DEFAULT_LLAMA_CPP_MODEL_ID);
|
|
1725
|
+
const totalmemBytes = os.totalmem();
|
|
1726
|
+
if (candidate && meetsLlamaCppDefaultModelRamFloor(totalmemBytes)) {
|
|
1727
|
+
if (await ctx.prompter.confirm({
|
|
1728
|
+
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?`,
|
|
1729
|
+
initialValue: false
|
|
1730
|
+
})) return {
|
|
1731
|
+
kind: "chat",
|
|
1732
|
+
candidate
|
|
1733
|
+
};
|
|
1734
|
+
} else if (!localMemoryIntent) {
|
|
1735
|
+
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");
|
|
1736
|
+
return;
|
|
1737
|
+
}
|
|
1738
|
+
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1739
|
+
if (localMemoryIntent && existing && (!existing.localService || existing.models.length > 0)) {
|
|
1740
|
+
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");
|
|
1741
|
+
return;
|
|
1742
|
+
}
|
|
1743
|
+
if (localMemoryIntent) {
|
|
1744
|
+
if (await ctx.prompter.confirm({
|
|
1745
|
+
message: `OpenClaw can install a verified llama.cpp server and download only ${describeEmbeddingDownload(embeddingModelIsDefault)}. This will not install or change your chat model. Continue?`,
|
|
1746
|
+
initialValue: false
|
|
1747
|
+
})) return { kind: "embedding-only" };
|
|
1748
|
+
}
|
|
1749
|
+
await ctx.prompter.note("Local model setup skipped.", "Setup skipped");
|
|
1750
|
+
}
|
|
1621
1751
|
async function runLlamaCppSetup(ctx) {
|
|
1622
1752
|
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1623
1753
|
const managedExisting = existing?.localService ? existing : void 0;
|
|
1624
|
-
const
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
const totalmemBytes = os.totalmem();
|
|
1630
|
-
if (!selected || !meetsLlamaCppDefaultModelRamFloor(totalmemBytes)) {
|
|
1631
|
-
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");
|
|
1632
|
-
return { profiles: [] };
|
|
1633
|
-
}
|
|
1634
|
-
if (!await ctx.prompter.confirm({
|
|
1635
|
-
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?",
|
|
1636
|
-
initialValue: false
|
|
1637
|
-
})) {
|
|
1638
|
-
await ctx.prompter.note("Local model setup skipped.", "Setup skipped");
|
|
1639
|
-
return { profiles: [] };
|
|
1640
|
-
}
|
|
1754
|
+
const cacheDir = resolveLlamaCppModelCacheDir(managedExisting);
|
|
1755
|
+
const embeddingSetup = resolveEmbeddingSetup(ctx.config, cacheDir);
|
|
1756
|
+
if (embeddingSetup.conflict) {
|
|
1757
|
+
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");
|
|
1758
|
+
return { profiles: [] };
|
|
1641
1759
|
}
|
|
1642
|
-
|
|
1760
|
+
const embeddingModel = embeddingSetup.model;
|
|
1761
|
+
const plan = await resolveSetupPlan(ctx, configuredCandidates(ctx.config, "setup"), embeddingModel.isDefault, embeddingSetup.localMemoryIntent);
|
|
1762
|
+
if (!plan) return { profiles: [] };
|
|
1643
1763
|
const progress = ctx.prompter.progress("Preparing managed llama.cpp server…");
|
|
1644
1764
|
try {
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1765
|
+
let chatModel;
|
|
1766
|
+
if (plan.kind === "chat") {
|
|
1767
|
+
const chatModelPath = plan.cachedPath ?? await ensureLlamaCppModel({
|
|
1768
|
+
source: resolveLlamaCppModelSource(plan.candidate.model),
|
|
1769
|
+
cacheDir,
|
|
1770
|
+
download: true,
|
|
1771
|
+
signal: ctx.signal,
|
|
1772
|
+
onProgress: (status) => progress.update(formatDownloadProgress("Gemma 4 E4B", status))
|
|
1773
|
+
});
|
|
1774
|
+
const configuredContext = plan.candidate.model.params?.contextSize;
|
|
1775
|
+
chatModel = {
|
|
1776
|
+
mode: "configure",
|
|
1777
|
+
id: plan.candidate.model.id,
|
|
1778
|
+
path: chatModelPath,
|
|
1779
|
+
contextSize: typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : plan.candidate.model.contextTokens,
|
|
1780
|
+
maxTokens: plan.candidate.model.maxTokens
|
|
1781
|
+
};
|
|
1782
|
+
} else chatModel = { mode: "remove" };
|
|
1783
|
+
const embeddingModelLabel = embeddingModel.isDefault ? "EmbeddingGemma" : "configured embedding model";
|
|
1653
1784
|
const embeddingModelPath = await ensureLlamaCppModel({
|
|
1654
|
-
source:
|
|
1785
|
+
source: embeddingModel.source,
|
|
1655
1786
|
cacheDir,
|
|
1656
1787
|
download: true,
|
|
1657
1788
|
signal: ctx.signal,
|
|
1658
|
-
onProgress: (status) => progress.update(formatDownloadProgress(
|
|
1789
|
+
onProgress: (status) => progress.update(formatDownloadProgress(embeddingModelLabel, status))
|
|
1659
1790
|
});
|
|
1660
|
-
const configuredContext = selected.model.params?.contextSize;
|
|
1661
|
-
const contextSize = typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : selected.model.contextTokens;
|
|
1662
1791
|
const managed = await prepareManagedLlamaServer({
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
contextSize,
|
|
1666
|
-
maxTokens: selected.model.maxTokens,
|
|
1667
|
-
embeddingModelIsDefault: true,
|
|
1792
|
+
chatModel,
|
|
1793
|
+
embeddingModelIsDefault: embeddingModel.isDefault,
|
|
1668
1794
|
embeddingModelPath,
|
|
1669
1795
|
port: readConfiguredPort(managedExisting)
|
|
1670
1796
|
});
|
|
@@ -1677,7 +1803,8 @@ async function runLlamaCppSetup(ctx) {
|
|
|
1677
1803
|
return buildSetupResult({
|
|
1678
1804
|
config: ctx.config,
|
|
1679
1805
|
managed,
|
|
1680
|
-
|
|
1806
|
+
plan: plan.kind,
|
|
1807
|
+
...plan.kind === "chat" ? { defaultModel: `${LLAMA_CPP_PROVIDER_ID}/${plan.candidate.model.id}` } : {}
|
|
1681
1808
|
});
|
|
1682
1809
|
} catch (error) {
|
|
1683
1810
|
progress.stop("llama.cpp setup failed");
|
|
@@ -1738,7 +1865,10 @@ function registerLlamaCppProvider(api) {
|
|
|
1738
1865
|
order: "late",
|
|
1739
1866
|
run: async (ctx) => {
|
|
1740
1867
|
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1741
|
-
return configured?.localService ? { provider: buildLlamaCppProviderConfig(
|
|
1868
|
+
return configured?.localService ? { provider: buildLlamaCppProviderConfig({
|
|
1869
|
+
existing: configured,
|
|
1870
|
+
modelInventory: configured.models
|
|
1871
|
+
}) } : await discoverLlamaServerProvider(ctx);
|
|
1742
1872
|
}
|
|
1743
1873
|
},
|
|
1744
1874
|
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,16 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/llama-cpp-provider",
|
|
3
|
-
"version": "2026.9.1
|
|
3
|
+
"version": "2026.9.1",
|
|
4
4
|
"description": "OpenClaw provider for managed and external llama.cpp servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/openclaw/openclaw"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"jszip": "3.10.1",
|
|
12
|
-
"tar": "7.5.22"
|
|
13
|
-
},
|
|
14
10
|
"devDependencies": {
|
|
15
11
|
"@openclaw/plugin-sdk": "workspace:*"
|
|
16
12
|
},
|
|
@@ -24,10 +20,10 @@
|
|
|
24
20
|
"minHostVersion": ">=2026.6.2"
|
|
25
21
|
},
|
|
26
22
|
"compat": {
|
|
27
|
-
"pluginApi": ">=2026.9.1
|
|
23
|
+
"pluginApi": ">=2026.9.1"
|
|
28
24
|
},
|
|
29
25
|
"build": {
|
|
30
|
-
"openclawVersion": "2026.9.1
|
|
26
|
+
"openclawVersion": "2026.9.1"
|
|
31
27
|
},
|
|
32
28
|
"release": {
|
|
33
29
|
"bundleRuntimeDependencies": false,
|
|
@@ -44,7 +40,7 @@
|
|
|
44
40
|
"README.md"
|
|
45
41
|
],
|
|
46
42
|
"peerDependencies": {
|
|
47
|
-
"openclaw": ">=2026.9.1
|
|
43
|
+
"openclaw": ">=2026.9.1"
|
|
48
44
|
},
|
|
49
45
|
"peerDependenciesMeta": {
|
|
50
46
|
"openclaw": {
|