@openclaw/llama-cpp-provider 2026.9.2 → 2026.9.3
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 +4 -4
- package/dist/index.js +292 -220
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -20,10 +20,10 @@ shows **Managed local server** and **Existing llama-server** under one
|
|
|
20
20
|
|
|
21
21
|
## Configure managed text inference
|
|
22
22
|
|
|
23
|
-
After explicit consent, OpenClaw installs the matching server build and
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
After explicit consent, OpenClaw installs the matching server build and a
|
|
24
|
+
recommended chat model that fits the Gateway's memory, GPU, and free disk space.
|
|
25
|
+
The download also includes the configured local embedding model, or EmbeddingGemma
|
|
26
|
+
by default (approximately 0.3 GB). See the provider guide for current recommendations.
|
|
27
27
|
|
|
28
28
|
When local memory search is configured and chat setup is unavailable or
|
|
29
29
|
declined, OpenClaw offers a separate embedding-only setup. After explicit
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { CUSTOM_LOCAL_AUTH_MARKER, applyAuthProfileConfig, buildApiKeyCredential
|
|
|
18
18
|
import { buildProviderToolCompatFamilyHooks } from "openclaw/plugin-sdk/provider-tools";
|
|
19
19
|
import { removeAuthProfileConfig, removeProviderAuthProfilesWithLock, resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
20
20
|
import { resolveConfiguredSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime";
|
|
21
|
+
import * as liveCatalogRuntime from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
|
21
22
|
import { getCachedLiveCatalogValue } from "openclaw/plugin-sdk/provider-catalog-shared";
|
|
22
23
|
import { SELF_HOSTED_DEFAULT_CONTEXT_WINDOW, SELF_HOSTED_DEFAULT_COST, SELF_HOSTED_DEFAULT_MAX_TOKENS, applyProviderDefaultModel, discoverOpenAICompatibleLocalModels } from "openclaw/plugin-sdk/provider-setup";
|
|
23
24
|
import { selectPreferredLocalModelId } from "openclaw/plugin-sdk/provider-model-shared";
|
|
@@ -25,31 +26,31 @@ import { streamSimple } from "openclaw/plugin-sdk/llm";
|
|
|
25
26
|
import { setQwenChatTemplateThinking } from "openclaw/plugin-sdk/provider-stream-shared";
|
|
26
27
|
import { listAgentIds, resolveAgentConfig } from "openclaw/plugin-sdk/agent-scope-runtime";
|
|
27
28
|
//#region extensions/llama-cpp/src/llama-server-assets.ts
|
|
28
|
-
const LLAMA_SERVER_RELEASE = "
|
|
29
|
-
const LLAMA_SERVER_COMMIT = "
|
|
29
|
+
const LLAMA_SERVER_RELEASE = "b10809";
|
|
30
|
+
const LLAMA_SERVER_COMMIT = "5266f24da75dc449bd56cbed7addb9c8e4a6a73e";
|
|
30
31
|
const MEBIBYTE$1 = 1048576;
|
|
31
32
|
const CUDA_ARCHIVE_LIMITS = {
|
|
32
33
|
maxArchiveBytes: 400 * MEBIBYTE$1,
|
|
33
34
|
maxExtractedBytes: 600 * MEBIBYTE$1,
|
|
34
|
-
maxEntryBytes:
|
|
35
|
+
maxEntryBytes: 521 * MEBIBYTE$1
|
|
35
36
|
};
|
|
36
37
|
const MACOS_ALIASES = [
|
|
37
|
-
["libggml-rpc.0.
|
|
38
|
-
["libllama.0.
|
|
39
|
-
["libmtmd.0.
|
|
40
|
-
["libggml.0.
|
|
41
|
-
["libggml-base.0.
|
|
42
|
-
["libggml-blas.0.
|
|
43
|
-
["libllama-common.0.
|
|
44
|
-
["libggml-cpu.0.
|
|
38
|
+
["libggml-rpc.0.23.0.dylib", ["libggml-rpc.0.dylib", "libggml-rpc.dylib"]],
|
|
39
|
+
["libllama.0.4.0.dylib", ["libllama.0.dylib", "libllama.dylib"]],
|
|
40
|
+
["libmtmd.0.4.0.dylib", ["libmtmd.0.dylib", "libmtmd.dylib"]],
|
|
41
|
+
["libggml.0.23.0.dylib", ["libggml.0.dylib", "libggml.dylib"]],
|
|
42
|
+
["libggml-base.0.23.0.dylib", ["libggml-base.0.dylib", "libggml-base.dylib"]],
|
|
43
|
+
["libggml-blas.0.23.0.dylib", ["libggml-blas.0.dylib", "libggml-blas.dylib"]],
|
|
44
|
+
["libllama-common.0.4.0.dylib", ["libllama-common.0.dylib", "libllama-common.dylib"]],
|
|
45
|
+
["libggml-cpu.0.23.0.dylib", ["libggml-cpu.0.dylib", "libggml-cpu.dylib"]]
|
|
45
46
|
];
|
|
46
|
-
const MACOS_METAL_ALIASES = [...MACOS_ALIASES, ["libggml-metal.0.
|
|
47
|
+
const MACOS_METAL_ALIASES = [...MACOS_ALIASES, ["libggml-metal.0.23.0.dylib", ["libggml-metal.0.dylib", "libggml-metal.dylib"]]];
|
|
47
48
|
const LINUX_ALIASES = [
|
|
48
|
-
["libllama.so.0.
|
|
49
|
-
["libggml.so.0.
|
|
50
|
-
["libmtmd.so.0.
|
|
51
|
-
["libggml-base.so.0.
|
|
52
|
-
["libllama-common.so.0.
|
|
49
|
+
["libllama.so.0.4.0", ["libllama.so.0", "libllama.so"]],
|
|
50
|
+
["libggml.so.0.23.0", ["libggml.so.0", "libggml.so"]],
|
|
51
|
+
["libmtmd.so.0.4.0", ["libmtmd.so.0", "libmtmd.so"]],
|
|
52
|
+
["libggml-base.so.0.23.0", ["libggml-base.so.0", "libggml-base.so"]],
|
|
53
|
+
["libllama-common.so.0.4.0", ["libllama-common.so.0", "libllama-common.so"]]
|
|
53
54
|
];
|
|
54
55
|
const LLAMA_SERVER_ASSETS = [
|
|
55
56
|
{
|
|
@@ -59,7 +60,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
59
60
|
archive: "tar.gz",
|
|
60
61
|
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
61
62
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-arm64.tar.gz`,
|
|
62
|
-
sha256: "
|
|
63
|
+
sha256: "7d692df9e1e386e62f1c12b843903218041e6cd74c9415aa39a7ed3176f9eaa2",
|
|
63
64
|
executable: "llama-server",
|
|
64
65
|
regularFileAliases: MACOS_METAL_ALIASES
|
|
65
66
|
},
|
|
@@ -70,7 +71,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
70
71
|
archive: "tar.gz",
|
|
71
72
|
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
72
73
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-x64.tar.gz`,
|
|
73
|
-
sha256: "
|
|
74
|
+
sha256: "13b34aa8a5d87341a21065a83f54a8167e1aaa6fe0d66065de01632a1ed64be6",
|
|
74
75
|
executable: "llama-server",
|
|
75
76
|
regularFileAliases: MACOS_ALIASES
|
|
76
77
|
},
|
|
@@ -81,7 +82,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
81
82
|
archive: "tar.gz",
|
|
82
83
|
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
83
84
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-arm64.tar.gz`,
|
|
84
|
-
sha256: "
|
|
85
|
+
sha256: "f2b7333971e1b7b42e9268bfdbfa30f5f56e2897156084d2251385df94aec358",
|
|
85
86
|
executable: "llama-server",
|
|
86
87
|
regularFileAliases: LINUX_ALIASES
|
|
87
88
|
},
|
|
@@ -92,7 +93,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
92
93
|
archive: "tar.gz",
|
|
93
94
|
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
94
95
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-x64.tar.gz`,
|
|
95
|
-
sha256: "
|
|
96
|
+
sha256: "5e34434ddc6d03cd1584f403201aff0d4bd1a5793a72ff7e286532dfd1e4b941",
|
|
96
97
|
executable: "llama-server",
|
|
97
98
|
regularFileAliases: LINUX_ALIASES
|
|
98
99
|
},
|
|
@@ -103,7 +104,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
103
104
|
archive: "zip",
|
|
104
105
|
archiveRoot: ".",
|
|
105
106
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cuda-12.4-x64.zip`,
|
|
106
|
-
sha256: "
|
|
107
|
+
sha256: "c77bfcd9ed8d91e8721a2d6a290b907fddd4fa5412a47b21c6fa1709116b85f9",
|
|
107
108
|
executable: "llama-server.exe",
|
|
108
109
|
regularFileAliases: [],
|
|
109
110
|
limits: CUDA_ARCHIVE_LIMITS,
|
|
@@ -131,7 +132,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
131
132
|
archive: "zip",
|
|
132
133
|
archiveRoot: ".",
|
|
133
134
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-arm64.zip`,
|
|
134
|
-
sha256: "
|
|
135
|
+
sha256: "c1058fe5764a687275c8d20d6bbc1454e787cdbb8ebb8c37a2f959f2b144dc77",
|
|
135
136
|
executable: "llama-server.exe",
|
|
136
137
|
regularFileAliases: []
|
|
137
138
|
},
|
|
@@ -142,7 +143,7 @@ const LLAMA_SERVER_ASSETS = [
|
|
|
142
143
|
archive: "zip",
|
|
143
144
|
archiveRoot: ".",
|
|
144
145
|
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-x64.zip`,
|
|
145
|
-
sha256: "
|
|
146
|
+
sha256: "9df3158ed228a641a4b127942d7f459f24c9e13f04682659d05c00c80099b6b5",
|
|
146
147
|
executable: "llama-server.exe",
|
|
147
148
|
regularFileAliases: []
|
|
148
149
|
}
|
|
@@ -265,6 +266,7 @@ async function extractLlamaServerDependencyArchive(params) {
|
|
|
265
266
|
//#region extensions/llama-cpp/src/llama-server-install.ts
|
|
266
267
|
const DOWNLOAD_TIMEOUT_MS = 18e5;
|
|
267
268
|
const VERSION_TIMEOUT_MS = 15e3;
|
|
269
|
+
const FRESH_VERSION_TIMEOUT_MS = 12e4;
|
|
268
270
|
const installationPromises = /* @__PURE__ */ new Map();
|
|
269
271
|
function compareVersion(left, right) {
|
|
270
272
|
const leftParts = left.split(".").map(Number);
|
|
@@ -402,10 +404,10 @@ async function downloadVerifiedFile(params) {
|
|
|
402
404
|
await fs.rm(partialPath, { force: true }).catch(() => void 0);
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
|
-
async function runServerCommand(command, args, signal) {
|
|
407
|
+
async function runServerCommand(command, args, signal, timeoutMs = VERSION_TIMEOUT_MS) {
|
|
406
408
|
return await new Promise((resolve, reject) => {
|
|
407
409
|
execFile(command, args, {
|
|
408
|
-
timeout:
|
|
410
|
+
timeout: timeoutMs,
|
|
409
411
|
signal,
|
|
410
412
|
windowsHide: true
|
|
411
413
|
}, (error, stdout, stderr) => {
|
|
@@ -420,10 +422,10 @@ function formatRuntimeDependencyError(error) {
|
|
|
420
422
|
if (process.platform === "win32") return new Error(`The verified llama-server build could not start. Install the Microsoft Visual C++ 2015-2022 Redistributable, then rerun llama.cpp setup. Detail: ${detail}`, { cause: error });
|
|
421
423
|
return new Error(`The verified llama-server build could not start: ${detail}`, { cause: error });
|
|
422
424
|
}
|
|
423
|
-
async function validateInstalledServer(command, asset, signal) {
|
|
425
|
+
async function validateInstalledServer(command, asset, signal, versionTimeoutMs = VERSION_TIMEOUT_MS) {
|
|
424
426
|
let version;
|
|
425
427
|
try {
|
|
426
|
-
version = await runServerCommand(command, ["--version"], signal);
|
|
428
|
+
version = await runServerCommand(command, ["--version"], signal, versionTimeoutMs);
|
|
427
429
|
} catch (error) {
|
|
428
430
|
signal?.throwIfAborted();
|
|
429
431
|
throw formatRuntimeDependencyError(error);
|
|
@@ -431,7 +433,7 @@ async function validateInstalledServer(command, asset, signal) {
|
|
|
431
433
|
const match = (version.split(/\r?\n/u, 1)[0]?.trim() ?? "").match(/^version: .+ \(build (\d+), commit ([a-f\d]{9})\)$/u);
|
|
432
434
|
const build = match?.[1] ? Number(match[1]) : void 0;
|
|
433
435
|
const commit = match?.[2];
|
|
434
|
-
if (build !==
|
|
436
|
+
if (build !== 10809 || commit !== "5266f24da75dc449bd56cbed7addb9c8e4a6a73e".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"}`);
|
|
435
437
|
if (asset.backend === "cuda") {
|
|
436
438
|
const devices = await runServerCommand(command, ["--list-devices"], signal);
|
|
437
439
|
if (!/^\s*CUDA\d+: .+\(\d+ MiB, \d+ MiB free\)$/mu.test(devices)) throw new Error("The verified llama-server could not initialize an NVIDIA CUDA device. Update the NVIDIA driver and rerun setup, or configure a compatible llama-server manually. CPU fallback was not activated.");
|
|
@@ -486,7 +488,7 @@ async function installLlamaServer(asset, options) {
|
|
|
486
488
|
}
|
|
487
489
|
options.signal?.throwIfAborted();
|
|
488
490
|
await fs.chmod(extractedCommand, 493);
|
|
489
|
-
await validateInstalledServer(extractedCommand, asset, options.signal);
|
|
491
|
+
await validateInstalledServer(extractedCommand, asset, options.signal, FRESH_VERSION_TIMEOUT_MS);
|
|
490
492
|
await fs.mkdir(path.dirname(installDir), { recursive: true });
|
|
491
493
|
options.signal?.throwIfAborted();
|
|
492
494
|
await fs.rm(installDir, {
|
|
@@ -524,6 +526,82 @@ async function ensureLlamaServerInstalled(options = {}) {
|
|
|
524
526
|
};
|
|
525
527
|
}
|
|
526
528
|
//#endregion
|
|
529
|
+
//#region extensions/llama-cpp/src/llama-server-preset.ts
|
|
530
|
+
const LLAMA_CPP_EMBEDDING_UBATCH_SIZE = 2048;
|
|
531
|
+
function assertIniValue(value, label) {
|
|
532
|
+
if (/\r|\n/u.test(value)) throw new Error(`${label} cannot contain a newline`);
|
|
533
|
+
return value;
|
|
534
|
+
}
|
|
535
|
+
function normalizePresetName(name) {
|
|
536
|
+
const colon = name.lastIndexOf(":");
|
|
537
|
+
if (colon < 0) return name;
|
|
538
|
+
const tag = name.slice(colon + 1);
|
|
539
|
+
const quantization = /[-.]([a-zA-Z0-9_]+)$/u.exec(tag)?.[1] ?? tag;
|
|
540
|
+
return name.slice(0, colon + 1) + quantization.replace(/[a-z]/g, (char) => char.toUpperCase());
|
|
541
|
+
}
|
|
542
|
+
function readModelSections(contents) {
|
|
543
|
+
const headers = [...contents.matchAll(/(?<![^\r\n])\[[ \t]*([^\]]+)\][ \t]*(?:[;#][^\r\n]*)?(?:\r\n|\n|\r|(?![\s\S]))/g)];
|
|
544
|
+
return {
|
|
545
|
+
header: contents.slice(0, headers[0]?.index ?? contents.length),
|
|
546
|
+
sections: new Map(headers.map((match, index) => [match[1], contents.slice(match.index, headers[index + 1]?.index ?? contents.length)]))
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
const PRESET_KEY_ALIASES = {
|
|
550
|
+
m: "model",
|
|
551
|
+
LLAMA_ARG_MODEL: "model",
|
|
552
|
+
c: "ctx-size",
|
|
553
|
+
LLAMA_ARG_CTX_SIZE: "ctx-size",
|
|
554
|
+
n: "n-predict",
|
|
555
|
+
predict: "n-predict",
|
|
556
|
+
LLAMA_ARG_N_PREDICT: "n-predict",
|
|
557
|
+
"no-jinja": "jinja",
|
|
558
|
+
LLAMA_ARG_JINJA: "jinja",
|
|
559
|
+
ub: "ubatch-size",
|
|
560
|
+
LLAMA_ARG_UBATCH: "ubatch-size",
|
|
561
|
+
embeddings: "embedding",
|
|
562
|
+
LLAMA_ARG_EMBEDDINGS: "embedding"
|
|
563
|
+
};
|
|
564
|
+
function updateModelSection(sections, id, values, newline) {
|
|
565
|
+
assertIniValue(id, "llama.cpp model id");
|
|
566
|
+
if (id.includes("]")) throw new Error("llama.cpp model ids cannot contain ]");
|
|
567
|
+
const name = [...sections.keys()].filter((candidate) => normalizePresetName(candidate) === normalizePresetName(id)).toSorted((left, right) => Buffer.compare(Buffer.from(left), Buffer.from(right))).at(-1) ?? id;
|
|
568
|
+
const pending = new Set(Object.keys(values));
|
|
569
|
+
let contents = (sections.get(name) ?? `[${id}]${newline}`).replace(/(?<![^\r\n])([a-zA-Z_][a-zA-Z0-9_.-]*)([ \t]*=[ \t]*)([^\r\n]*?)([ \t]*(?:[;#][^\r\n]*)?)(\r\n|\n|\r|(?![\s\S]))/g, (line, key, separator, _value, comment, ending) => {
|
|
570
|
+
const canonical = PRESET_KEY_ALIASES[key] ?? key;
|
|
571
|
+
if (!Object.hasOwn(values, canonical)) return line;
|
|
572
|
+
pending.delete(canonical);
|
|
573
|
+
return `${canonical}${separator}${values[canonical]}${comment}${ending}`;
|
|
574
|
+
});
|
|
575
|
+
for (const key of pending) contents += `${/[\r\n]$/u.test(contents) ? "" : newline}${key} = ${values[key]}${newline}`;
|
|
576
|
+
sections.set(name, contents);
|
|
577
|
+
}
|
|
578
|
+
function buildLlamaServerPreset(existing, params) {
|
|
579
|
+
const newline = existing?.match(/\r\n|\n|\r/u)?.[0] ?? "\n";
|
|
580
|
+
const { header, sections } = readModelSections(existing ?? "version = 1\n\n");
|
|
581
|
+
const configuredIds = params.configuredChatModelIds ? new Set(params.configuredChatModelIds.map(normalizePresetName)) : void 0;
|
|
582
|
+
for (const id of sections.keys()) if (id !== "*" && id !== "embeddinggemma-300m-qat-q8_0" && (params.chatModel.mode === "remove" || configuredIds && !configuredIds.has(normalizePresetName(id)))) sections.delete(id);
|
|
583
|
+
if (params.chatModel.mode === "configure") updateModelSection(sections, params.chatModel.id, {
|
|
584
|
+
model: assertIniValue(params.chatModel.path, "llama.cpp model path"),
|
|
585
|
+
"ctx-size": String(params.chatModel.contextSize ?? 65536),
|
|
586
|
+
"n-predict": String(params.chatModel.maxTokens ?? 2048),
|
|
587
|
+
jinja: "true"
|
|
588
|
+
}, newline);
|
|
589
|
+
const embeddingPath = params.embeddingModelPath ?? (!sections.has("embeddinggemma-300m-qat-q8_0") ? params.defaultEmbeddingModelPath : void 0);
|
|
590
|
+
if (embeddingPath) {
|
|
591
|
+
const isDefault = params.embeddingModelPath ? params.embeddingModelIsDefault : true;
|
|
592
|
+
updateModelSection(sections, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID, {
|
|
593
|
+
model: assertIniValue(embeddingPath, "llama.cpp embedding model path"),
|
|
594
|
+
...isDefault ? { "ubatch-size": String(LLAMA_CPP_EMBEDDING_UBATCH_SIZE) } : {},
|
|
595
|
+
embedding: "true"
|
|
596
|
+
}, newline);
|
|
597
|
+
}
|
|
598
|
+
const embeddingSection = sections.get(DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID);
|
|
599
|
+
if (!embeddingSection) throw new Error("llama.cpp embedding model path is required for a new managed preset");
|
|
600
|
+
sections.delete(DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID);
|
|
601
|
+
const orderedSections = [...[...sections].toSorted(([left], [right]) => Number(left > right) - Number(left < right)).map(([, section]) => section), embeddingSection];
|
|
602
|
+
return header + (header && !/[\r\n]$/u.test(header) ? newline : "") + orderedSections.map((section) => section.replace(/[\r\n]+$/u, "")).join(newline + newline) + newline;
|
|
603
|
+
}
|
|
604
|
+
//#endregion
|
|
527
605
|
//#region extensions/llama-cpp/src/hardware.ts
|
|
528
606
|
const GIB$1 = 1024 ** 3;
|
|
529
607
|
const MIB = 1024 ** 2;
|
|
@@ -843,9 +921,13 @@ function recommendLlamaCppModel(hardware, backend, cached = {}) {
|
|
|
843
921
|
//#endregion
|
|
844
922
|
//#region extensions/llama-cpp/src/managed-server.ts
|
|
845
923
|
const modelPromises = /* @__PURE__ */ new Map();
|
|
846
|
-
const
|
|
847
|
-
const
|
|
848
|
-
|
|
924
|
+
const resolvedModelArtifacts = /* @__PURE__ */ new Map();
|
|
925
|
+
const presetState = {
|
|
926
|
+
appliedRevisions: /* @__PURE__ */ new Map(),
|
|
927
|
+
desiredRevisions: /* @__PURE__ */ new Map(),
|
|
928
|
+
transition: Promise.resolve()
|
|
929
|
+
};
|
|
930
|
+
const LLAMA_CPP_PRESET_RELOAD_TIMEOUT_MS = 15e3;
|
|
849
931
|
function parseHuggingFaceSource(source) {
|
|
850
932
|
const [pathPart, revisionPart] = source.replace(/^(?:hf|huggingface):(?:\/\/)?/iu, "").split("#", 2);
|
|
851
933
|
const [user, repositoryWithTag, ...fileParts] = (pathPart ?? "").split("/");
|
|
@@ -974,18 +1056,16 @@ async function ensureLlamaCppModel(params) {
|
|
|
974
1056
|
await assertGguf(localPath);
|
|
975
1057
|
return localPath;
|
|
976
1058
|
}
|
|
977
|
-
const
|
|
1059
|
+
const artifactCacheKey = `${path.resolve(params.cacheDir)}\0${localSource}`;
|
|
1060
|
+
const artifact = resolvedModelArtifacts.get(artifactCacheKey) ?? await resolveModelArtifact(localSource, params.signal);
|
|
1061
|
+
resolvedModelArtifacts.set(artifactCacheKey, artifact);
|
|
978
1062
|
const destination = path.join(params.cacheDir, artifact.fileName);
|
|
979
|
-
const
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
if (
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
} else {
|
|
986
|
-
await assertGguf(destination);
|
|
987
|
-
return destination;
|
|
988
|
-
}
|
|
1063
|
+
const load = modelPromises.get(destination) ?? (async () => {
|
|
1064
|
+
const exists = await fs.stat(destination).then((stat) => stat.isFile()).catch(() => false);
|
|
1065
|
+
if (exists && artifact.expectedSha256 && await sha256File(destination, params.signal) === artifact.expectedSha256) return destination;
|
|
1066
|
+
if (exists && !artifact.expectedSha256) {
|
|
1067
|
+
await assertGguf(destination);
|
|
1068
|
+
return destination;
|
|
989
1069
|
}
|
|
990
1070
|
if (!params.download) throw new Error(`Model is not cached at ${destination}`);
|
|
991
1071
|
await downloadVerifiedFile({
|
|
@@ -1007,88 +1087,52 @@ async function ensureLlamaCppModel(params) {
|
|
|
1007
1087
|
if (modelPromises.get(destination) === load) modelPromises.delete(destination);
|
|
1008
1088
|
}
|
|
1009
1089
|
}
|
|
1010
|
-
function assertIniValue(value, label) {
|
|
1011
|
-
if (/\r|\n/u.test(value)) throw new Error(`${label} cannot contain a newline`);
|
|
1012
|
-
return value;
|
|
1013
|
-
}
|
|
1014
|
-
function renderChatModelSection(params) {
|
|
1015
|
-
const id = assertIniValue(params.id, "llama.cpp model id");
|
|
1016
|
-
if (id.includes("]")) throw new Error("llama.cpp model ids cannot contain ]");
|
|
1017
|
-
return [
|
|
1018
|
-
`[${id}]`,
|
|
1019
|
-
`model = ${assertIniValue(params.modelPath, "llama.cpp model path")}`,
|
|
1020
|
-
`ctx-size = ${params.contextSize ?? 65536}`,
|
|
1021
|
-
`n-predict = ${params.maxTokens ?? 2048}`,
|
|
1022
|
-
"jinja = true"
|
|
1023
|
-
].join("\n");
|
|
1024
|
-
}
|
|
1025
|
-
function renderEmbeddingModelSection(params) {
|
|
1026
|
-
return [
|
|
1027
|
-
`[${DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID}]`,
|
|
1028
|
-
`model = ${assertIniValue(params.modelPath, "llama.cpp embedding model path")}`,
|
|
1029
|
-
...params.isDefault ? [`ubatch-size = ${LLAMA_CPP_EMBEDDING_UBATCH_SIZE}`] : [],
|
|
1030
|
-
"embedding = true"
|
|
1031
|
-
].join("\n");
|
|
1032
|
-
}
|
|
1033
|
-
function readModelSection(contents, id) {
|
|
1034
|
-
if (!contents) return;
|
|
1035
|
-
const lines = contents.split(/\r?\n/u);
|
|
1036
|
-
const start = lines.indexOf(`[${id}]`);
|
|
1037
|
-
if (start < 0) return;
|
|
1038
|
-
let end = start + 1;
|
|
1039
|
-
while (end < lines.length && !/^\[[^\]]+\]$/u.test(lines[end] ?? "")) end += 1;
|
|
1040
|
-
return lines.slice(start, end).join("\n").trimEnd();
|
|
1041
|
-
}
|
|
1042
|
-
function readChatModelSection(contents) {
|
|
1043
|
-
const id = contents?.split(/\r?\n/u).map((line) => /^\[([^\]]+)\]$/u.exec(line)?.[1]).find((candidate) => candidate && candidate !== "embeddinggemma-300m-qat-q8_0");
|
|
1044
|
-
return id ? readModelSection(contents, id) : void 0;
|
|
1045
|
-
}
|
|
1046
|
-
function renderLlamaServerPreset(params) {
|
|
1047
|
-
return [
|
|
1048
|
-
"version = 1",
|
|
1049
|
-
"",
|
|
1050
|
-
...params.chatSection ? [params.chatSection, ""] : [],
|
|
1051
|
-
params.embeddingSection,
|
|
1052
|
-
""
|
|
1053
|
-
].join("\n");
|
|
1054
|
-
}
|
|
1055
1090
|
async function writePreset(presetPath, contents) {
|
|
1056
1091
|
await fs.mkdir(path.dirname(presetPath), { recursive: true });
|
|
1057
1092
|
const temporary = `${presetPath}.tmp-${randomUUID()}`;
|
|
1058
|
-
|
|
1059
|
-
|
|
1093
|
+
try {
|
|
1094
|
+
await fs.writeFile(temporary, contents, { mode: 384 });
|
|
1095
|
+
await fs.rename(temporary, presetPath);
|
|
1096
|
+
} finally {
|
|
1097
|
+
await fs.rm(temporary, { force: true });
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
async function runPresetTransition(run) {
|
|
1101
|
+
const pending = presetState.transition.catch(() => void 0).then(run);
|
|
1102
|
+
presetState.transition = pending;
|
|
1103
|
+
await pending;
|
|
1060
1104
|
}
|
|
1061
1105
|
async function updatePreset(presetPath, params) {
|
|
1062
|
-
|
|
1106
|
+
await runPresetTransition(async () => {
|
|
1063
1107
|
const existing = await fs.readFile(presetPath, "utf8").catch((error) => {
|
|
1064
1108
|
if (asOptionalRecord(error)?.code === "ENOENT") return;
|
|
1065
1109
|
throw error;
|
|
1066
1110
|
});
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
})
|
|
1111
|
+
const next = buildLlamaServerPreset(existing, params);
|
|
1112
|
+
if (next !== existing) await writePreset(presetPath, next);
|
|
1113
|
+
if (params.reconcileOrigin) presetState.desiredRevisions.set(params.reconcileOrigin, `${presetPath}\0${next}`);
|
|
1114
|
+
});
|
|
1115
|
+
}
|
|
1116
|
+
async function reconcileManagedLlamaServer(params) {
|
|
1117
|
+
await runPresetTransition(async () => {
|
|
1118
|
+
const origin = new URL(params.baseUrl).origin;
|
|
1119
|
+
const revision = presetState.desiredRevisions.get(origin);
|
|
1120
|
+
if (!revision || presetState.appliedRevisions.get(origin) === revision) return;
|
|
1121
|
+
const { response, release } = await fetchConfiguredLocalOriginWithSsrFGuard({
|
|
1122
|
+
url: `${origin}/models?reload=1`,
|
|
1123
|
+
configuredLocalOriginBaseUrl: origin,
|
|
1124
|
+
policy: ssrfPolicyFromHttpBaseUrlAllowedOrigin(origin),
|
|
1125
|
+
signal: params.signal,
|
|
1126
|
+
timeoutMs: LLAMA_CPP_PRESET_RELOAD_TIMEOUT_MS,
|
|
1127
|
+
auditContext: "llama-server-preset-reload"
|
|
1128
|
+
});
|
|
1129
|
+
try {
|
|
1130
|
+
if (!response.ok) throw new Error(`llama.cpp preset reload failed: HTTP ${response.status}`);
|
|
1131
|
+
presetState.appliedRevisions.set(origin, revision);
|
|
1132
|
+
} finally {
|
|
1133
|
+
await release();
|
|
1134
|
+
}
|
|
1085
1135
|
});
|
|
1086
|
-
presetWritePromises.set(presetPath, pending);
|
|
1087
|
-
try {
|
|
1088
|
-
await pending;
|
|
1089
|
-
} finally {
|
|
1090
|
-
if (presetWritePromises.get(presetPath) === pending) presetWritePromises.delete(presetPath);
|
|
1091
|
-
}
|
|
1092
1136
|
}
|
|
1093
1137
|
async function findAvailableLlamaServerPort(preferred = LLAMA_CPP_DEFAULT_PORT) {
|
|
1094
1138
|
const tryPort = async (port) => await new Promise((resolve) => {
|
|
@@ -1112,23 +1156,32 @@ async function prepareManagedLlamaServer(params) {
|
|
|
1112
1156
|
})).command;
|
|
1113
1157
|
const port = params.port ?? await findAvailableLlamaServerPort(params.isolated ? 0 : void 0);
|
|
1114
1158
|
const rootUrl = `http://127.0.0.1:${port}`;
|
|
1159
|
+
const reconcileOrigin = params.reconcileBaseUrl ? new URL(params.reconcileBaseUrl).origin : rootUrl;
|
|
1115
1160
|
const endpoint = {
|
|
1116
1161
|
command,
|
|
1117
1162
|
baseUrl: `${rootUrl}/v1`,
|
|
1118
1163
|
healthUrl: params.localService?.healthUrl ?? `${rootUrl}/health`
|
|
1119
1164
|
};
|
|
1120
1165
|
const configuredPreset = params.localService?.args?.find((_, index, args) => args[index - 1] === "--models-preset") ?? params.localService?.env?.LLAMA_ARG_MODELS_PRESET;
|
|
1121
|
-
if (params.localService && !configuredPreset && !params.isolated)
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1166
|
+
if (params.localService && !configuredPreset && !params.isolated) {
|
|
1167
|
+
await runPresetTransition(async () => {
|
|
1168
|
+
presetState.desiredRevisions.delete(reconcileOrigin);
|
|
1169
|
+
presetState.appliedRevisions.delete(reconcileOrigin);
|
|
1170
|
+
});
|
|
1171
|
+
return {
|
|
1172
|
+
...endpoint,
|
|
1173
|
+
args: params.localService.args ?? []
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1125
1176
|
const defaultPreset = configuredPreset ? path.resolve(params.localService?.cwd ?? process.cwd(), configuredPreset) : resolveManagedLlamaServerPaths(params.asset).presetPath;
|
|
1126
1177
|
const presetPath = params.isolated ? path.join(path.dirname(defaultPreset), `models-${randomUUID()}.ini`) : defaultPreset;
|
|
1127
1178
|
await updatePreset(presetPath, {
|
|
1128
1179
|
chatModel: params.chatModel,
|
|
1180
|
+
configuredChatModelIds: params.configuredChatModelIds,
|
|
1129
1181
|
embeddingModelIsDefault: params.embeddingModelIsDefault,
|
|
1130
1182
|
embeddingModelPath: params.embeddingModelPath,
|
|
1131
|
-
defaultEmbeddingModelPath: params.defaultEmbeddingModelPath
|
|
1183
|
+
defaultEmbeddingModelPath: params.defaultEmbeddingModelPath,
|
|
1184
|
+
reconcileOrigin: params.isolated ? void 0 : reconcileOrigin
|
|
1132
1185
|
});
|
|
1133
1186
|
params.signal?.throwIfAborted();
|
|
1134
1187
|
return {
|
|
@@ -1150,49 +1203,35 @@ async function prepareManagedLlamaServer(params) {
|
|
|
1150
1203
|
async function ensureManagedLlamaServerForChat(params) {
|
|
1151
1204
|
if (!params.provider.localService || !params.provider.baseUrl) return;
|
|
1152
1205
|
const cacheDir = resolveLlamaCppModelCacheDir(params.provider);
|
|
1153
|
-
|
|
1154
|
-
params.
|
|
1155
|
-
params.provider
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
const pending = chatPreparationPromises.get(key) ?? (async () => {
|
|
1161
|
-
let chatModelPath = resolveCachedLlamaCppModelPath({
|
|
1162
|
-
model: params.model,
|
|
1163
|
-
provider: params.provider
|
|
1164
|
-
});
|
|
1165
|
-
if (!chatModelPath && resolveLlamaCppModelSource(params.model) === "hf:unsloth/gemma-4-E4B-it-GGUF/gemma-4-E4B-it-Q4_K_M.gguf") {
|
|
1166
|
-
const legacy = path.join(resolveLegacyLlamaCppModelCacheDir(), "hf_unsloth_gemma-4-E4B-it-GGUF_gemma-4-E4B-it-Q4_K_M.gguf");
|
|
1167
|
-
if (await fs.stat(legacy).then((stat) => stat.isFile()).catch(() => false)) chatModelPath = legacy;
|
|
1168
|
-
}
|
|
1169
|
-
chatModelPath = await ensureLlamaCppModel({
|
|
1170
|
-
source: chatModelPath ?? resolveLlamaCppModelSource(params.model),
|
|
1171
|
-
cacheDir,
|
|
1172
|
-
download: false
|
|
1173
|
-
});
|
|
1174
|
-
const configuredContext = params.model.params?.contextSize;
|
|
1175
|
-
const port = Number(new URL(params.provider.baseUrl).port);
|
|
1176
|
-
await prepareManagedLlamaServer({
|
|
1177
|
-
chatModel: {
|
|
1178
|
-
mode: "configure",
|
|
1179
|
-
id: params.model.id,
|
|
1180
|
-
path: chatModelPath,
|
|
1181
|
-
contextSize: typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : params.model.contextTokens,
|
|
1182
|
-
maxTokens: params.model.maxTokens
|
|
1183
|
-
},
|
|
1184
|
-
defaultEmbeddingModelPath: path.join(cacheDir, "hf_ggml-org_embeddinggemma-300m-qat-Q8_0.gguf"),
|
|
1185
|
-
port: Number.isInteger(port) && port > 0 ? port : void 0,
|
|
1186
|
-
localService: params.provider.localService
|
|
1187
|
-
});
|
|
1188
|
-
})();
|
|
1189
|
-
chatPreparationPromises.set(key, pending);
|
|
1190
|
-
try {
|
|
1191
|
-
await pending;
|
|
1192
|
-
} catch (error) {
|
|
1193
|
-
if (chatPreparationPromises.get(key) === pending) chatPreparationPromises.delete(key);
|
|
1194
|
-
throw error;
|
|
1206
|
+
let chatModelPath = resolveCachedLlamaCppModelPath({
|
|
1207
|
+
model: params.model,
|
|
1208
|
+
provider: params.provider
|
|
1209
|
+
});
|
|
1210
|
+
if (!chatModelPath && resolveLlamaCppModelSource(params.model) === "hf:unsloth/gemma-4-E4B-it-GGUF/gemma-4-E4B-it-Q4_K_M.gguf") {
|
|
1211
|
+
const legacy = path.join(resolveLegacyLlamaCppModelCacheDir(), DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE);
|
|
1212
|
+
if (await fs.stat(legacy).then((stat) => stat.isFile()).catch(() => false)) chatModelPath = legacy;
|
|
1195
1213
|
}
|
|
1214
|
+
chatModelPath = await ensureLlamaCppModel({
|
|
1215
|
+
source: chatModelPath ?? resolveLlamaCppModelSource(params.model),
|
|
1216
|
+
cacheDir,
|
|
1217
|
+
download: false
|
|
1218
|
+
});
|
|
1219
|
+
const configuredContext = params.model.params?.contextSize;
|
|
1220
|
+
const port = Number(new URL(params.provider.baseUrl).port);
|
|
1221
|
+
await prepareManagedLlamaServer({
|
|
1222
|
+
chatModel: {
|
|
1223
|
+
mode: "configure",
|
|
1224
|
+
id: params.model.id,
|
|
1225
|
+
path: chatModelPath,
|
|
1226
|
+
contextSize: typeof configuredContext === "number" && configuredContext > 0 ? Math.floor(configuredContext) : params.model.contextTokens,
|
|
1227
|
+
maxTokens: params.model.maxTokens
|
|
1228
|
+
},
|
|
1229
|
+
configuredChatModelIds: params.provider.models.map((model) => model.id),
|
|
1230
|
+
defaultEmbeddingModelPath: path.join(cacheDir, DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE),
|
|
1231
|
+
port: Number.isInteger(port) && port > 0 ? port : void 0,
|
|
1232
|
+
reconcileBaseUrl: params.provider.baseUrl,
|
|
1233
|
+
localService: params.provider.localService
|
|
1234
|
+
});
|
|
1196
1235
|
}
|
|
1197
1236
|
async function fetchEndpoint(url, accept) {
|
|
1198
1237
|
try {
|
|
@@ -1256,7 +1295,6 @@ async function inspectLlamaServerRuntime(params) {
|
|
|
1256
1295
|
//#endregion
|
|
1257
1296
|
//#region extensions/llama-cpp/src/embedding-provider.ts
|
|
1258
1297
|
const LOCAL_EMBEDDING_RUNTIME_FACTS = Symbol.for("openclaw.localEmbeddingRuntimeFacts");
|
|
1259
|
-
const preparedEmbeddingServers = /* @__PURE__ */ new Map();
|
|
1260
1298
|
function readLocalOptions(options) {
|
|
1261
1299
|
return options.local ?? {};
|
|
1262
1300
|
}
|
|
@@ -1310,33 +1348,20 @@ function resolveProviderPort(provider) {
|
|
|
1310
1348
|
}
|
|
1311
1349
|
async function prepareEmbeddingServer(options, embeddingSource, embeddingModelIsDefault) {
|
|
1312
1350
|
const provider = resolveConfiguredProvider(options);
|
|
1313
|
-
const
|
|
1314
|
-
|
|
1315
|
-
provider
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
download: true
|
|
1328
|
-
}),
|
|
1329
|
-
port: resolveProviderPort(provider),
|
|
1330
|
-
localService: provider.localService
|
|
1331
|
-
});
|
|
1332
|
-
})();
|
|
1333
|
-
preparedEmbeddingServers.set(key, pending);
|
|
1334
|
-
try {
|
|
1335
|
-
await pending;
|
|
1336
|
-
} catch (error) {
|
|
1337
|
-
if (preparedEmbeddingServers.get(key) === pending) preparedEmbeddingServers.delete(key);
|
|
1338
|
-
throw error;
|
|
1339
|
-
}
|
|
1351
|
+
const embeddingModelPath = await ensureLlamaCppModel({
|
|
1352
|
+
source: embeddingSource,
|
|
1353
|
+
cacheDir: resolveLlamaCppModelCacheDir(provider),
|
|
1354
|
+
download: true
|
|
1355
|
+
});
|
|
1356
|
+
await prepareManagedLlamaServer({
|
|
1357
|
+
chatModel: { mode: "preserve" },
|
|
1358
|
+
configuredChatModelIds: provider.models.map((model) => model.id),
|
|
1359
|
+
embeddingModelIsDefault,
|
|
1360
|
+
embeddingModelPath,
|
|
1361
|
+
port: resolveProviderPort(provider),
|
|
1362
|
+
reconcileBaseUrl: provider.baseUrl,
|
|
1363
|
+
localService: provider.localService
|
|
1364
|
+
});
|
|
1340
1365
|
}
|
|
1341
1366
|
function wrapProvider(params) {
|
|
1342
1367
|
let runtimeFacts;
|
|
@@ -1387,11 +1412,16 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
1387
1412
|
await prepareEmbeddingServer(options, embeddingModel.source, embeddingModel.isDefault);
|
|
1388
1413
|
const genericAdapter = getEmbeddingProvider("openai-compatible", options.config);
|
|
1389
1414
|
if (!genericAdapter) throw new Error("OpenAI-compatible embedding transport is unavailable.");
|
|
1415
|
+
const acquireLocalService = options.acquireLocalService;
|
|
1390
1416
|
const result = await genericAdapter.create({
|
|
1391
1417
|
...options,
|
|
1392
1418
|
provider: LLAMA_CPP_PROVIDER_ID,
|
|
1393
1419
|
model: DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID,
|
|
1394
|
-
remote: void 0
|
|
1420
|
+
remote: void 0,
|
|
1421
|
+
...acquireLocalService ? { acquireLocalService: (...[target, signal]) => acquireLocalService({
|
|
1422
|
+
...target,
|
|
1423
|
+
reconcile: reconcileManagedLlamaServer
|
|
1424
|
+
}, signal) } : {}
|
|
1395
1425
|
});
|
|
1396
1426
|
if (!result.provider) return result;
|
|
1397
1427
|
return {
|
|
@@ -1621,6 +1651,36 @@ async function discoverLlamaServer(params) {
|
|
|
1621
1651
|
}
|
|
1622
1652
|
//#endregion
|
|
1623
1653
|
//#region extensions/llama-cpp/src/external-server/provider.ts
|
|
1654
|
+
const liveCatalogSdk = liveCatalogRuntime;
|
|
1655
|
+
async function runLlamaServerCatalog(params) {
|
|
1656
|
+
if (liveCatalogSdk.runLiveProviderCatalog) return await liveCatalogSdk.runLiveProviderCatalog(params);
|
|
1657
|
+
const identity = {
|
|
1658
|
+
provider: params.providerId,
|
|
1659
|
+
...params.profileId ? { profileId: params.profileId } : {}
|
|
1660
|
+
};
|
|
1661
|
+
try {
|
|
1662
|
+
const result = await params.run();
|
|
1663
|
+
return result ? {
|
|
1664
|
+
...result,
|
|
1665
|
+
outcomes: [...result.outcomes ?? [], {
|
|
1666
|
+
...identity,
|
|
1667
|
+
status: "ready"
|
|
1668
|
+
}]
|
|
1669
|
+
} : result;
|
|
1670
|
+
} catch (error) {
|
|
1671
|
+
return {
|
|
1672
|
+
providers: {},
|
|
1673
|
+
outcomes: [error instanceof liveCatalogRuntime.LiveModelCatalogHttpError && (error.status === 401 || error.status === 403) ? {
|
|
1674
|
+
...identity,
|
|
1675
|
+
status: "auth-rejected",
|
|
1676
|
+
rejectionScope: "catalog"
|
|
1677
|
+
} : {
|
|
1678
|
+
...identity,
|
|
1679
|
+
status: "unavailable"
|
|
1680
|
+
}]
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1624
1684
|
/** Discovers external llama-server models for provider runtime resolution. */
|
|
1625
1685
|
async function discoverLlamaServerProvider(ctx) {
|
|
1626
1686
|
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
@@ -1630,23 +1690,28 @@ async function discoverLlamaServerProvider(ctx) {
|
|
|
1630
1690
|
env: ctx.env,
|
|
1631
1691
|
headers: configured?.headers
|
|
1632
1692
|
});
|
|
1633
|
-
const
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1693
|
+
const authApiKey = auth.discoveryApiKey ?? auth.apiKey;
|
|
1694
|
+
const apiKey = hasLlamaServerAuthorizationHeader(headers) || authApiKey && isNonSecretApiKeyMarker(authApiKey) ? void 0 : authApiKey;
|
|
1695
|
+
return await runLlamaServerCatalog({
|
|
1696
|
+
providerId: LLAMA_CPP_PROVIDER_ID,
|
|
1697
|
+
profileId: apiKey ? auth.profileId : void 0,
|
|
1698
|
+
run: async () => {
|
|
1699
|
+
const discovery = await discoverLlamaServer({
|
|
1700
|
+
baseUrl: configured?.baseUrl,
|
|
1701
|
+
apiKey,
|
|
1702
|
+
headers,
|
|
1703
|
+
cacheTtlMs: 0
|
|
1704
|
+
});
|
|
1705
|
+
if (discovery.kind !== "success") {
|
|
1706
|
+
if (!configured && !apiKey && !headers) return null;
|
|
1707
|
+
throw discovery.kind === "http-error" ? new liveCatalogRuntime.LiveModelCatalogHttpError(LLAMA_CPP_PROVIDER_ID, discovery.status) : discovery.error;
|
|
1708
|
+
}
|
|
1709
|
+
return { provider: buildLlamaServerProviderConfig({
|
|
1710
|
+
configured,
|
|
1711
|
+
discoveredModels: discovery.models
|
|
1712
|
+
}) };
|
|
1713
|
+
}
|
|
1637
1714
|
});
|
|
1638
|
-
if (discovery.kind !== "success") return configured ? { provider: buildLlamaServerProviderConfig({
|
|
1639
|
-
configured,
|
|
1640
|
-
discoveredModels: []
|
|
1641
|
-
}) } : null;
|
|
1642
|
-
return { provider: buildLlamaServerProviderConfig({
|
|
1643
|
-
configured: {
|
|
1644
|
-
...configured,
|
|
1645
|
-
baseUrl: discovery.endpoint.inferenceBaseUrl,
|
|
1646
|
-
models: configured?.models ?? []
|
|
1647
|
-
},
|
|
1648
|
-
discoveredModels: discovery.models
|
|
1649
|
-
}) };
|
|
1650
1715
|
}
|
|
1651
1716
|
async function prepareLlamaServerDynamicModel(ctx) {
|
|
1652
1717
|
const apiKey = await resolveLlamaServerRuntimeApiKey({
|
|
@@ -2315,6 +2380,7 @@ async function runLlamaCppSetup(ctx) {
|
|
|
2315
2380
|
});
|
|
2316
2381
|
const managed = await prepareManagedLlamaServer({
|
|
2317
2382
|
chatModel,
|
|
2383
|
+
configuredChatModelIds: plan.kind === "chat" ? plan.candidate.provider.models.map((model) => model.id) : [],
|
|
2318
2384
|
embeddingModelIsDefault: embeddingModel.isDefault,
|
|
2319
2385
|
embeddingModelPath,
|
|
2320
2386
|
asset,
|
|
@@ -2341,6 +2407,20 @@ async function runLlamaCppSetup(ctx) {
|
|
|
2341
2407
|
}
|
|
2342
2408
|
//#endregion
|
|
2343
2409
|
//#region extensions/llama-cpp/src/managed-provider.ts
|
|
2410
|
+
function wrapManagedLlamaCppStream(ctx, streamFn = ctx.streamFn) {
|
|
2411
|
+
const providerConfig = ctx.config?.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2412
|
+
if (!providerConfig?.localService) return;
|
|
2413
|
+
const inner = streamFn;
|
|
2414
|
+
const selectedModel = ctx.model;
|
|
2415
|
+
if (!inner || !selectedModel) return;
|
|
2416
|
+
return async (...args) => {
|
|
2417
|
+
await ensureManagedLlamaServerForChat({
|
|
2418
|
+
provider: providerConfig,
|
|
2419
|
+
model: selectedModel
|
|
2420
|
+
});
|
|
2421
|
+
return inner(...args);
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2344
2424
|
function registerLlamaCppProvider(api) {
|
|
2345
2425
|
api.registerProvider({
|
|
2346
2426
|
id: LLAMA_CPP_PROVIDER_ID,
|
|
@@ -2410,19 +2490,11 @@ function registerLlamaCppProvider(api) {
|
|
|
2410
2490
|
shouldDeferSyntheticProfileAuth: ({ resolvedApiKey }) => resolvedApiKey?.trim() === resolveLlamaCppSyntheticApiKey() || resolvedApiKey?.trim() === CUSTOM_LOCAL_AUTH_MARKER,
|
|
2411
2491
|
normalizeConfig: ({ providerConfig }) => providerConfig.localService ? providerConfig : normalizeLlamaServerProviderConfig(providerConfig),
|
|
2412
2492
|
prepareDynamicModel: async (ctx) => ctx.config?.models?.providers?.["llama-cpp"]?.localService ? void 0 : await prepareLlamaServerDynamicModel(ctx),
|
|
2493
|
+
reconcileLocalService: reconcileManagedLlamaServer,
|
|
2494
|
+
wrapSimpleCompletionStreamFn: wrapManagedLlamaCppStream,
|
|
2413
2495
|
wrapStreamFn: (ctx) => {
|
|
2414
|
-
const
|
|
2415
|
-
|
|
2416
|
-
if (!providerConfig?.localService) return inner;
|
|
2417
|
-
const selectedModel = ctx.model;
|
|
2418
|
-
if (!selectedModel) return;
|
|
2419
|
-
return async (model, context, options) => {
|
|
2420
|
-
await ensureManagedLlamaServerForChat({
|
|
2421
|
-
provider: providerConfig,
|
|
2422
|
-
model: selectedModel
|
|
2423
|
-
});
|
|
2424
|
-
return inner(model, context, options);
|
|
2425
|
-
};
|
|
2496
|
+
const streamFn = wrapLlamaServerStream(ctx);
|
|
2497
|
+
return ctx.config?.models?.providers?.["llama-cpp"]?.localService ? wrapManagedLlamaCppStream(ctx, streamFn) : streamFn;
|
|
2426
2498
|
},
|
|
2427
2499
|
...buildProviderToolCompatFamilyHooks("llamacpp-gbnf"),
|
|
2428
2500
|
wizard: { modelPicker: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/llama-cpp-provider",
|
|
3
|
-
"version": "2026.9.
|
|
3
|
+
"version": "2026.9.3",
|
|
4
4
|
"description": "OpenClaw provider for managed and external llama.cpp servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"minHostVersion": ">=2026.6.2"
|
|
21
21
|
},
|
|
22
22
|
"compat": {
|
|
23
|
-
"pluginApi": ">=2026.9.
|
|
23
|
+
"pluginApi": ">=2026.9.3"
|
|
24
24
|
},
|
|
25
25
|
"build": {
|
|
26
|
-
"openclawVersion": "2026.9.
|
|
26
|
+
"openclawVersion": "2026.9.3"
|
|
27
27
|
},
|
|
28
28
|
"release": {
|
|
29
29
|
"bundleRuntimeDependencies": false,
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"README.md"
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"openclaw": ">=2026.9.
|
|
43
|
+
"openclaw": ">=2026.9.3"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {
|
|
46
46
|
"openclaw": {
|