@openclaw/llama-cpp-provider 2026.10.5-beta.4 → 2026.10.10-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/auth-config-DPqFwXcI.mjs +17 -0
- package/dist/.setup/{defaults-ATX0SyoG.mjs → defaults-CL2lz0cV.mjs} +4 -4
- package/dist/.setup/{provider-OCMqlJ0I.mjs → discovery-VdqP6WcN.mjs} +4 -79
- package/dist/.setup/embedding-provider.runtime-FcwMX9AK.mjs +163 -0
- package/dist/.setup/{managed-provider-config-Nd32gsuH.mjs → managed-provider-config-G_LBLX0A.mjs} +1 -1
- package/dist/.setup/managed-server-C2ukpg0h.mjs +1115 -0
- package/dist/.setup/media-catalog-M5BEPQng.mjs +597 -0
- package/dist/.setup/media-config-CZ7CluNV.mjs +30 -0
- package/dist/.setup/media-provider.runtime-LQf52Hb3.mjs +72 -0
- package/dist/.setup/media-setup-Blmm3-wk.mjs +274 -0
- package/dist/.setup/{provider-discovery-CEcEBzKt.mjs → provider-discovery-97l8WbMa.mjs} +2 -2
- package/dist/.setup/provider-w5p9JK8O.mjs +67 -0
- package/dist/.setup/setup-Cscvds1K.mjs +351 -0
- package/dist/.setup/setup-sQ_NpNbD.mjs +359 -0
- package/dist/.setup/stream-Cu8XUda8.mjs +36 -0
- package/dist/index.js +192 -2459
- package/dist/provider-discovery.js +1 -2
- package/dist/provider-policy-api.js +1 -1
- package/openclaw.plugin.json +11 -1
- package/package.json +5 -5
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import { c as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES, d as DEFAULT_LLAMA_CPP_MODEL_REVISION, f as DEFAULT_LLAMA_CPP_MODEL_SHA256, l as DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE, m as DEFAULT_LLAMA_CPP_MODEL_URI, p as DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES, u as DEFAULT_LLAMA_CPP_MODEL_ID, w as resolveLlamaCppDataDir, y as buildLlamaCppModel } from "./defaults-CL2lz0cV.mjs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import fs from "node:fs/promises";
|
|
5
|
+
import { execFile } from "node:child_process";
|
|
6
|
+
//#region extensions/llama-cpp/src/llama-server-assets.ts
|
|
7
|
+
const LLAMA_SERVER_RELEASE = "b10809";
|
|
8
|
+
const LLAMA_SERVER_BUILD = 10809;
|
|
9
|
+
const LLAMA_SERVER_COMMIT = "5266f24da75dc449bd56cbed7addb9c8e4a6a73e";
|
|
10
|
+
const MEBIBYTE = 1048576;
|
|
11
|
+
const CUDA_ARCHIVE_LIMITS = {
|
|
12
|
+
maxArchiveBytes: 400 * MEBIBYTE,
|
|
13
|
+
maxExtractedBytes: 600 * MEBIBYTE,
|
|
14
|
+
maxEntryBytes: 521 * MEBIBYTE
|
|
15
|
+
};
|
|
16
|
+
const WINDOWS_X64_VC_RUNTIME = {
|
|
17
|
+
archive: "vc-redist",
|
|
18
|
+
name: "VC_redist.x64.exe",
|
|
19
|
+
url: "https://download.visualstudio.microsoft.com/download/pr/ebdab8e5-1d7b-4d9f-a11b-cbb1720c3b12/843068991DAAA1F73AD9F6239BCE4D0F6A07A51F18C37EA2A867E9BECA71295C/VC_redist.x64.exe",
|
|
20
|
+
sha256: "843068991daaa1f73ad9f6239bce4d0f6a07a51f18c37ea2a867e9beca71295c",
|
|
21
|
+
size: 18731856,
|
|
22
|
+
containerOffset: 63e4,
|
|
23
|
+
containerSize: 18091661,
|
|
24
|
+
nestedCabinet: "a4",
|
|
25
|
+
files: [
|
|
26
|
+
{
|
|
27
|
+
source: "msvcp140.dll_amd64",
|
|
28
|
+
target: "msvcp140.dll"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
source: "vcruntime140.dll_amd64",
|
|
32
|
+
target: "vcruntime140.dll"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
source: "vcruntime140_1.dll_amd64",
|
|
36
|
+
target: "vcruntime140_1.dll"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
const WINDOWS_ARM64_VC_RUNTIME = {
|
|
41
|
+
archive: "vc-redist",
|
|
42
|
+
name: "VC_redist.arm64.exe",
|
|
43
|
+
url: "https://download.visualstudio.microsoft.com/download/pr/ece44298-3977-4f73-ab91-c13fe79cfea8/B70EF586669A620A0A30A1156969C05C6A3831DC8F8BC992DA75779D2A92F944/VC_redist.arm64.exe",
|
|
44
|
+
sha256: "b70ef586669a620a0a30a1156969c05c6a3831dc8f8bc992da75779d2a92f944",
|
|
45
|
+
size: 11870816,
|
|
46
|
+
containerOffset: 684112,
|
|
47
|
+
containerSize: 11176508,
|
|
48
|
+
nestedCabinet: "a1",
|
|
49
|
+
files: [{
|
|
50
|
+
source: "msvcp140.dll_arm64",
|
|
51
|
+
target: "msvcp140.dll"
|
|
52
|
+
}, {
|
|
53
|
+
source: "vcruntime140.dll_arm64",
|
|
54
|
+
target: "vcruntime140.dll"
|
|
55
|
+
}]
|
|
56
|
+
};
|
|
57
|
+
const MACOS_ALIASES = [
|
|
58
|
+
["libggml-rpc.0.23.0.dylib", ["libggml-rpc.0.dylib", "libggml-rpc.dylib"]],
|
|
59
|
+
["libllama.0.4.0.dylib", ["libllama.0.dylib", "libllama.dylib"]],
|
|
60
|
+
["libmtmd.0.4.0.dylib", ["libmtmd.0.dylib", "libmtmd.dylib"]],
|
|
61
|
+
["libggml.0.23.0.dylib", ["libggml.0.dylib", "libggml.dylib"]],
|
|
62
|
+
["libggml-base.0.23.0.dylib", ["libggml-base.0.dylib", "libggml-base.dylib"]],
|
|
63
|
+
["libggml-blas.0.23.0.dylib", ["libggml-blas.0.dylib", "libggml-blas.dylib"]],
|
|
64
|
+
["libllama-common.0.4.0.dylib", ["libllama-common.0.dylib", "libllama-common.dylib"]],
|
|
65
|
+
["libggml-cpu.0.23.0.dylib", ["libggml-cpu.0.dylib", "libggml-cpu.dylib"]]
|
|
66
|
+
];
|
|
67
|
+
const MACOS_METAL_ALIASES = [...MACOS_ALIASES, ["libggml-metal.0.23.0.dylib", ["libggml-metal.0.dylib", "libggml-metal.dylib"]]];
|
|
68
|
+
const LINUX_ALIASES = [
|
|
69
|
+
["libllama.so.0.4.0", ["libllama.so.0", "libllama.so"]],
|
|
70
|
+
["libggml.so.0.23.0", ["libggml.so.0", "libggml.so"]],
|
|
71
|
+
["libmtmd.so.0.4.0", ["libmtmd.so.0", "libmtmd.so"]],
|
|
72
|
+
["libggml-base.so.0.23.0", ["libggml-base.so.0", "libggml-base.so"]],
|
|
73
|
+
["libllama-common.so.0.4.0", ["libllama-common.so.0", "libllama-common.so"]]
|
|
74
|
+
];
|
|
75
|
+
const LLAMA_SERVER_ASSETS = [
|
|
76
|
+
{
|
|
77
|
+
platform: "darwin",
|
|
78
|
+
arch: "arm64",
|
|
79
|
+
backend: "metal",
|
|
80
|
+
archive: "tar.gz",
|
|
81
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
82
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-arm64.tar.gz`,
|
|
83
|
+
sha256: "7d692df9e1e386e62f1c12b843903218041e6cd74c9415aa39a7ed3176f9eaa2",
|
|
84
|
+
sizeBytes: 11123196,
|
|
85
|
+
executable: "llama-server",
|
|
86
|
+
regularFileAliases: MACOS_METAL_ALIASES
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
platform: "darwin",
|
|
90
|
+
arch: "x64",
|
|
91
|
+
backend: "cpu",
|
|
92
|
+
archive: "tar.gz",
|
|
93
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
94
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-x64.tar.gz`,
|
|
95
|
+
sha256: "13b34aa8a5d87341a21065a83f54a8167e1aaa6fe0d66065de01632a1ed64be6",
|
|
96
|
+
sizeBytes: 11175330,
|
|
97
|
+
executable: "llama-server",
|
|
98
|
+
regularFileAliases: MACOS_ALIASES
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
platform: "linux",
|
|
102
|
+
arch: "arm64",
|
|
103
|
+
backend: "cpu",
|
|
104
|
+
archive: "tar.gz",
|
|
105
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
106
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-arm64.tar.gz`,
|
|
107
|
+
sha256: "f2b7333971e1b7b42e9268bfdbfa30f5f56e2897156084d2251385df94aec358",
|
|
108
|
+
sizeBytes: 13380118,
|
|
109
|
+
executable: "llama-server",
|
|
110
|
+
regularFileAliases: LINUX_ALIASES
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
platform: "linux",
|
|
114
|
+
arch: "x64",
|
|
115
|
+
backend: "cpu",
|
|
116
|
+
archive: "tar.gz",
|
|
117
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
118
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-x64.tar.gz`,
|
|
119
|
+
sha256: "5e34434ddc6d03cd1584f403201aff0d4bd1a5793a72ff7e286532dfd1e4b941",
|
|
120
|
+
sizeBytes: 16734586,
|
|
121
|
+
executable: "llama-server",
|
|
122
|
+
regularFileAliases: LINUX_ALIASES
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
platform: "win32",
|
|
126
|
+
arch: "x64",
|
|
127
|
+
backend: "cuda",
|
|
128
|
+
archive: "zip",
|
|
129
|
+
archiveRoot: ".",
|
|
130
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cuda-12.4-x64.zip`,
|
|
131
|
+
sha256: "c77bfcd9ed8d91e8721a2d6a290b907fddd4fa5412a47b21c6fa1709116b85f9",
|
|
132
|
+
sizeBytes: 253938543,
|
|
133
|
+
executable: "llama-server.exe",
|
|
134
|
+
regularFileAliases: [],
|
|
135
|
+
limits: CUDA_ARCHIVE_LIMITS,
|
|
136
|
+
dependencies: [{
|
|
137
|
+
archive: "zip",
|
|
138
|
+
archiveRoot: ".",
|
|
139
|
+
name: "cudart-llama-bin-win-cuda-12.4-x64.zip",
|
|
140
|
+
sha256: "8c79a9b226de4b3cacfd1f83d24f962d0773be79f1e7b75c6af4ded7e32ae1d6",
|
|
141
|
+
sizeBytes: 391443627,
|
|
142
|
+
regularFileAliases: [],
|
|
143
|
+
files: [
|
|
144
|
+
"cublas64_12.dll",
|
|
145
|
+
"cublasLt64_12.dll",
|
|
146
|
+
"cudart64_12.dll"
|
|
147
|
+
],
|
|
148
|
+
limits: {
|
|
149
|
+
...CUDA_ARCHIVE_LIMITS,
|
|
150
|
+
maxEntries: 3
|
|
151
|
+
}
|
|
152
|
+
}, WINDOWS_X64_VC_RUNTIME]
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
platform: "win32",
|
|
156
|
+
arch: "arm64",
|
|
157
|
+
backend: "cpu",
|
|
158
|
+
archive: "zip",
|
|
159
|
+
archiveRoot: ".",
|
|
160
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-arm64.zip`,
|
|
161
|
+
sha256: "c1058fe5764a687275c8d20d6bbc1454e787cdbb8ebb8c37a2f959f2b144dc77",
|
|
162
|
+
sizeBytes: 11974499,
|
|
163
|
+
executable: "llama-server.exe",
|
|
164
|
+
regularFileAliases: [],
|
|
165
|
+
dependencies: [WINDOWS_ARM64_VC_RUNTIME]
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
platform: "win32",
|
|
169
|
+
arch: "x64",
|
|
170
|
+
backend: "cpu",
|
|
171
|
+
archive: "zip",
|
|
172
|
+
archiveRoot: ".",
|
|
173
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-x64.zip`,
|
|
174
|
+
sha256: "9df3158ed228a641a4b127942d7f459f24c9e13f04682659d05c00c80099b6b5",
|
|
175
|
+
sizeBytes: 18407457,
|
|
176
|
+
executable: "llama-server.exe",
|
|
177
|
+
regularFileAliases: [],
|
|
178
|
+
dependencies: [WINDOWS_X64_VC_RUNTIME]
|
|
179
|
+
}
|
|
180
|
+
];
|
|
181
|
+
function selectLlamaServerAsset(platform = process.platform, arch = process.arch, acceleration) {
|
|
182
|
+
const backend = acceleration?.kind ?? (platform === "darwin" && arch === "arm64" ? "metal" : "cpu");
|
|
183
|
+
if (backend === "cuda" && acceleration?.kind === "cuda") {
|
|
184
|
+
if (platform !== "win32" || arch !== "x64") throw new Error(`No verified CUDA llama-server ${LLAMA_SERVER_RELEASE} build is available for ${platform}/${arch}. Install a CUDA-enabled llama-server manually and configure its absolute path, or explicitly choose CPU setup.`);
|
|
185
|
+
if (!(acceleration.devices.length > 0 && acceleration.devices.every((device) => {
|
|
186
|
+
const version = /^(\d+)\.(\d+)(?:\.\d+)?$/u.exec(device.driverVersion);
|
|
187
|
+
return version && (Number(version[1]) > 551 || Number(version[1]) === 551 && Number(version[2]) >= 78) && (device.computeCapability === void 0 || device.computeCapability >= 5);
|
|
188
|
+
}))) throw new Error("The verified CUDA 12.4 build requires NVIDIA driver 551.78 or newer and compute capability 5.0 or newer. Update the NVIDIA driver, configure a compatible llama-server manually, or explicitly choose CPU setup.");
|
|
189
|
+
}
|
|
190
|
+
const asset = LLAMA_SERVER_ASSETS.find((candidate) => candidate.platform === platform && candidate.arch === arch && candidate.backend === backend);
|
|
191
|
+
if (!asset) throw new Error(`No verified llama-server ${LLAMA_SERVER_RELEASE} build is available for ${platform}/${arch}. Install a compatible llama-server manually, then rerun llama.cpp setup with its absolute path.`);
|
|
192
|
+
return asset;
|
|
193
|
+
}
|
|
194
|
+
function resolveManagedLlamaServerPaths(asset = selectLlamaServerAsset()) {
|
|
195
|
+
const installDir = path.join(resolveLlamaCppDataDir(), LLAMA_SERVER_RELEASE, `${asset.platform}-${asset.arch}${asset.backend === "cuda" ? "-cuda-12.4" : ""}`);
|
|
196
|
+
return {
|
|
197
|
+
installDir,
|
|
198
|
+
command: path.join(installDir, asset.executable),
|
|
199
|
+
presetPath: path.join(resolveLlamaCppDataDir(), "models.ini")
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function findManagedLlamaServerAsset(command, platform = process.platform, arch = process.arch) {
|
|
203
|
+
return LLAMA_SERVER_ASSETS.find((asset) => asset.platform === platform && asset.arch === arch && resolveManagedLlamaServerPaths(asset).command === command);
|
|
204
|
+
}
|
|
205
|
+
//#endregion
|
|
206
|
+
//#region extensions/llama-cpp/src/hardware.ts
|
|
207
|
+
const GIB$2 = 1024 ** 3;
|
|
208
|
+
const MIB = 1024 ** 2;
|
|
209
|
+
async function runHardwareProbe(command, args, signal) {
|
|
210
|
+
try {
|
|
211
|
+
return await new Promise((resolve, reject) => {
|
|
212
|
+
execFile(command, args, {
|
|
213
|
+
encoding: "utf8",
|
|
214
|
+
timeout: 3e3,
|
|
215
|
+
maxBuffer: 65536,
|
|
216
|
+
signal
|
|
217
|
+
}, (error, stdout) => error ? reject(error) : resolve(stdout));
|
|
218
|
+
});
|
|
219
|
+
} catch {
|
|
220
|
+
signal?.throwIfAborted();
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
async function readAvailableMemory(platform, signal) {
|
|
225
|
+
if (platform === "linux") {
|
|
226
|
+
const meminfo = await fs.readFile("/proc/meminfo", "utf8").catch(() => "");
|
|
227
|
+
const available = /^MemAvailable:\s+(\d+)\s+kB$/mu.exec(meminfo)?.[1];
|
|
228
|
+
if (available) return Number(available) * 1024;
|
|
229
|
+
}
|
|
230
|
+
if (platform === "darwin") {
|
|
231
|
+
const vmstat = await runHardwareProbe("/usr/bin/vm_stat", [], signal);
|
|
232
|
+
const pageSize = /page size of (\d+) bytes/u.exec(vmstat ?? "")?.[1];
|
|
233
|
+
const free = /^Pages free:\s+(\d+)\./mu.exec(vmstat ?? "")?.[1];
|
|
234
|
+
const inactive = /^Pages inactive:\s+(\d+)\./mu.exec(vmstat ?? "")?.[1];
|
|
235
|
+
if (pageSize && free && inactive) return (Number(free) + Number(inactive)) * Number(pageSize);
|
|
236
|
+
}
|
|
237
|
+
return os.freemem();
|
|
238
|
+
}
|
|
239
|
+
async function readAvailableDisk(cacheDir, platform, signal) {
|
|
240
|
+
let directory = path.resolve(cacheDir);
|
|
241
|
+
while (true) try {
|
|
242
|
+
const [capacity, stat] = await Promise.all([fs.statfs(directory), fs.stat(directory)]);
|
|
243
|
+
let capacityGroup = `device:${stat.dev}`;
|
|
244
|
+
if (platform === "linux" && ![
|
|
245
|
+
61267,
|
|
246
|
+
1481003842,
|
|
247
|
+
4076150800
|
|
248
|
+
].includes(capacity.type)) capacityGroup = void 0;
|
|
249
|
+
if (platform === "darwin") {
|
|
250
|
+
const disk = /^\/dev\/(disk\d+(?:s\d+)*)\s/mu.exec(await runHardwareProbe("/bin/df", ["-P", directory], signal) ?? "")?.[1];
|
|
251
|
+
const info = disk ? await runHardwareProbe("/usr/sbin/diskutil", [
|
|
252
|
+
"info",
|
|
253
|
+
"-plist",
|
|
254
|
+
disk
|
|
255
|
+
], signal) : void 0;
|
|
256
|
+
const container = /<key>APFSContainerReference<\/key>\s*<string>(disk\d+)<\/string>/u.exec(info ?? "")?.[1];
|
|
257
|
+
const filesystem = /<key>FilesystemType<\/key>\s*<string>([^<]+)<\/string>/u.exec(info ?? "")?.[1];
|
|
258
|
+
capacityGroup = container ? `apfs:${container}` : filesystem && filesystem !== "apfs" ? capacityGroup : void 0;
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
availableBytes: capacity.bavail * capacity.bsize,
|
|
262
|
+
capacityGroup
|
|
263
|
+
};
|
|
264
|
+
} catch (error) {
|
|
265
|
+
signal?.throwIfAborted();
|
|
266
|
+
const code = error instanceof Error && "code" in error ? error.code : void 0;
|
|
267
|
+
const parent = path.dirname(directory);
|
|
268
|
+
if (code !== "ENOENT" && code !== "ENOTDIR" || parent === directory) return;
|
|
269
|
+
directory = parent;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async function readAccelerator(platform, arch, signal) {
|
|
273
|
+
if (platform === "darwin" && arch === "arm64") return { kind: "metal" };
|
|
274
|
+
if (platform !== "linux" && platform !== "win32") return {
|
|
275
|
+
kind: "cpu",
|
|
276
|
+
reason: "No managed GPU backend is available for this host."
|
|
277
|
+
};
|
|
278
|
+
const devices = ((await runHardwareProbe("nvidia-smi", ["--query-gpu=name,memory.total,memory.free,driver_version,compute_cap", "--format=csv,noheader,nounits"], signal))?.trim().split(/\r?\n/u) ?? []).slice(0, 32).flatMap((line) => {
|
|
279
|
+
const fields = line.split(",").map((field) => field.trim());
|
|
280
|
+
const [total, available, driverVersion, compute] = fields.slice(-4);
|
|
281
|
+
const name = fields.slice(0, -4).join(", ");
|
|
282
|
+
const totalMemoryBytes = Number(total) * MIB;
|
|
283
|
+
const availableMemoryBytes = Number(available) * MIB;
|
|
284
|
+
const computeCapability = Number(compute);
|
|
285
|
+
if (!name || !driverVersion || !/^\d+(?:\.\d+)+$/u.test(driverVersion) || !Number.isFinite(totalMemoryBytes) || !Number.isFinite(availableMemoryBytes) || totalMemoryBytes <= 0 || availableMemoryBytes < 0 || availableMemoryBytes > totalMemoryBytes) return [];
|
|
286
|
+
return [{
|
|
287
|
+
name,
|
|
288
|
+
totalMemoryBytes,
|
|
289
|
+
availableMemoryBytes,
|
|
290
|
+
driverVersion,
|
|
291
|
+
...Number.isFinite(computeCapability) && computeCapability > 0 ? { computeCapability } : {}
|
|
292
|
+
}];
|
|
293
|
+
});
|
|
294
|
+
return devices.length > 0 ? {
|
|
295
|
+
kind: "cuda",
|
|
296
|
+
devices
|
|
297
|
+
} : {
|
|
298
|
+
kind: "cpu",
|
|
299
|
+
reason: "nvidia-smi did not report a usable NVIDIA GPU."
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
/** Read the Gateway host once during setup; never probe on inference requests. */
|
|
303
|
+
async function detectLlamaCppHardware(params) {
|
|
304
|
+
params.signal?.throwIfAborted();
|
|
305
|
+
const platform = os.platform();
|
|
306
|
+
const arch = os.arch();
|
|
307
|
+
const hostMemoryBytes = os.totalmem();
|
|
308
|
+
const constrainedMemory = process.constrainedMemory();
|
|
309
|
+
const constrained = constrainedMemory > 0 && constrainedMemory < hostMemoryBytes;
|
|
310
|
+
const totalMemoryBytes = constrained ? constrainedMemory : hostMemoryBytes;
|
|
311
|
+
const [availableMemory, modelDisk, runtimeDisk, accelerator] = await Promise.all([
|
|
312
|
+
readAvailableMemory(platform, params.signal),
|
|
313
|
+
readAvailableDisk(params.cacheDir, platform, params.signal),
|
|
314
|
+
readAvailableDisk(resolveLlamaCppDataDir(), platform, params.signal),
|
|
315
|
+
readAccelerator(platform, arch, params.signal)
|
|
316
|
+
]);
|
|
317
|
+
params.signal?.throwIfAborted();
|
|
318
|
+
return {
|
|
319
|
+
platform,
|
|
320
|
+
arch,
|
|
321
|
+
totalMemoryBytes,
|
|
322
|
+
availableMemoryBytes: Math.min(totalMemoryBytes, availableMemory, constrained ? process.availableMemory() : totalMemoryBytes),
|
|
323
|
+
availableDiskBytes: modelDisk?.availableBytes,
|
|
324
|
+
availableRuntimeDiskBytes: runtimeDisk?.availableBytes,
|
|
325
|
+
sharedDisk: !modelDisk?.capacityGroup || !runtimeDisk?.capacityGroup || modelDisk.capacityGroup === runtimeDisk.capacityGroup,
|
|
326
|
+
accelerator
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function formatLlamaCppMemory(bytes) {
|
|
330
|
+
return `${(bytes / GIB$2).toFixed(1).replace(/\.0$/u, "")} GiB`;
|
|
331
|
+
}
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region extensions/llama-cpp/src/model-catalog.ts
|
|
334
|
+
const GIB$1 = 1024 ** 3;
|
|
335
|
+
function modelRecipe(params) {
|
|
336
|
+
const source = params.source ?? `hf:${params.repository}/${params.file}#${params.revision}`;
|
|
337
|
+
return {
|
|
338
|
+
model: buildLlamaCppModel({
|
|
339
|
+
...params,
|
|
340
|
+
source
|
|
341
|
+
}),
|
|
342
|
+
sizeBytes: params.sizeBytes,
|
|
343
|
+
memoryBytes: params.memoryGiB * GIB$1,
|
|
344
|
+
minimumSystemMemoryBytes: params.minimumSystemGiB * GIB$1,
|
|
345
|
+
requiresAcceleration: params.requiresAcceleration ?? false,
|
|
346
|
+
artifact: {
|
|
347
|
+
fileName: params.cacheFile ?? `hf_${params.repository.replaceAll("/", "_")}_${params.revision}_${params.file}`,
|
|
348
|
+
url: `https://huggingface.co/${params.repository}/resolve/${params.revision}/${params.file}?download=true`,
|
|
349
|
+
expectedSize: params.sizeBytes,
|
|
350
|
+
expectedSha256: params.sha256
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
const LLAMA_CPP_MODEL_RECIPES = [
|
|
355
|
+
modelRecipe({
|
|
356
|
+
id: "qwen3.8-27b-ud-q4_k_m",
|
|
357
|
+
name: "Qwen3.8 27B (UD-Q4_K_M)",
|
|
358
|
+
repository: "unsloth/Qwen3.8-27B-GGUF",
|
|
359
|
+
file: "Qwen3.8-27B-UD-Q4_K_M.gguf",
|
|
360
|
+
revision: "4ca720788d1e01f1bff70c033e0d0028fd02e502",
|
|
361
|
+
sha256: "322e194ff79741c7baa497c240f677f54b201b0efab44ca8e50f122b39123482",
|
|
362
|
+
sizeBytes: 16464440224,
|
|
363
|
+
memoryGiB: 22,
|
|
364
|
+
minimumSystemGiB: 32,
|
|
365
|
+
requiresAcceleration: true,
|
|
366
|
+
reasoning: true,
|
|
367
|
+
maxTokens: 16384
|
|
368
|
+
}),
|
|
369
|
+
modelRecipe({
|
|
370
|
+
id: "muse-glimmer-30b-q4_k_m",
|
|
371
|
+
name: "Muse Glimmer 30B (Q4_K_M)",
|
|
372
|
+
repository: "meta-models/Muse-Glimmer-30B-GGUF",
|
|
373
|
+
file: "Muse-Glimmer-30B-KQuant-17GB-Q4_K_M.gguf",
|
|
374
|
+
revision: "70bf1b61ac09f91b24d39038091b41c582bc5d7a",
|
|
375
|
+
sha256: "4cc57c0f51040a226e5a72cc47b7613f7772950e460a665f7083de89f183f60e",
|
|
376
|
+
sizeBytes: 16756683904,
|
|
377
|
+
memoryGiB: 20,
|
|
378
|
+
minimumSystemGiB: 32,
|
|
379
|
+
requiresAcceleration: true,
|
|
380
|
+
reasoning: true,
|
|
381
|
+
maxTokens: 16384
|
|
382
|
+
}),
|
|
383
|
+
modelRecipe({
|
|
384
|
+
id: "gemma-4-26b-a4b-it-ud-q4_k_m",
|
|
385
|
+
name: "Gemma 4 26B A4B (UD-Q4_K_M)",
|
|
386
|
+
repository: "unsloth/gemma-4-26B-A4B-it-GGUF",
|
|
387
|
+
file: "gemma-4-26B-A4B-it-UD-Q4_K_M.gguf",
|
|
388
|
+
revision: "c099eb48e663fd284577b04978a94ffccb261841",
|
|
389
|
+
sha256: "f2c28b3dc4776931ac6f879e11f203dec637ea0f14267a86ec8f6165f63f293f",
|
|
390
|
+
sizeBytes: 16947541728,
|
|
391
|
+
memoryGiB: 22,
|
|
392
|
+
minimumSystemGiB: 32,
|
|
393
|
+
requiresAcceleration: true
|
|
394
|
+
}),
|
|
395
|
+
modelRecipe({
|
|
396
|
+
id: "gemma-4-12b-it-q4_k_m",
|
|
397
|
+
name: "Gemma 4 12B (Q4_K_M)",
|
|
398
|
+
repository: "unsloth/gemma-4-12b-it-GGUF",
|
|
399
|
+
file: "gemma-4-12b-it-Q4_K_M.gguf",
|
|
400
|
+
revision: "fc034cfff751157913579611efad8462ac1be606",
|
|
401
|
+
sha256: "0a270ec9fe6b34f4a0d33992b6135117b484ebc4766ab76b51d4ae8c457e4c42",
|
|
402
|
+
sizeBytes: 7121861440,
|
|
403
|
+
memoryGiB: 12,
|
|
404
|
+
minimumSystemGiB: 24,
|
|
405
|
+
requiresAcceleration: true,
|
|
406
|
+
reasoning: true,
|
|
407
|
+
maxTokens: 16384
|
|
408
|
+
}),
|
|
409
|
+
modelRecipe({
|
|
410
|
+
id: "qwen3.5-9b-q4_k_m",
|
|
411
|
+
name: "Qwen3.5 9B (Q4_K_M)",
|
|
412
|
+
repository: "unsloth/Qwen3.5-9B-GGUF",
|
|
413
|
+
file: "Qwen3.5-9B-Q4_K_M.gguf",
|
|
414
|
+
revision: "3885219b6810b007914f3a7950a8d1b469d598a5",
|
|
415
|
+
sha256: "03b74727a860a56338e042c4420bb3f04b2fec5734175f4cb9fa853daf52b7e8",
|
|
416
|
+
sizeBytes: 5680522464,
|
|
417
|
+
memoryGiB: 10,
|
|
418
|
+
minimumSystemGiB: 16,
|
|
419
|
+
reasoning: true,
|
|
420
|
+
maxTokens: 16384
|
|
421
|
+
}),
|
|
422
|
+
modelRecipe({
|
|
423
|
+
id: DEFAULT_LLAMA_CPP_MODEL_ID,
|
|
424
|
+
name: "Gemma 4 E4B (Q4_K_M)",
|
|
425
|
+
repository: "unsloth/gemma-4-E4B-it-GGUF",
|
|
426
|
+
file: "gemma-4-E4B-it-Q4_K_M.gguf",
|
|
427
|
+
revision: DEFAULT_LLAMA_CPP_MODEL_REVISION,
|
|
428
|
+
sha256: DEFAULT_LLAMA_CPP_MODEL_SHA256,
|
|
429
|
+
sizeBytes: DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES,
|
|
430
|
+
memoryGiB: 10,
|
|
431
|
+
minimumSystemGiB: 16,
|
|
432
|
+
source: DEFAULT_LLAMA_CPP_MODEL_URI,
|
|
433
|
+
cacheFile: DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE
|
|
434
|
+
}),
|
|
435
|
+
modelRecipe({
|
|
436
|
+
id: "qwen3.5-4b-q4_k_m",
|
|
437
|
+
name: "Qwen3.5 4B (Q4_K_M)",
|
|
438
|
+
repository: "unsloth/Qwen3.5-4B-GGUF",
|
|
439
|
+
file: "Qwen3.5-4B-Q4_K_M.gguf",
|
|
440
|
+
revision: "e87f176479d0855a907a41277aca2f8ee7a09523",
|
|
441
|
+
sha256: "00fe7986ff5f6b463e62455821146049db6f9313603938a70800d1fb69ef11a4",
|
|
442
|
+
sizeBytes: 2740937888,
|
|
443
|
+
memoryGiB: 6,
|
|
444
|
+
minimumSystemGiB: 8,
|
|
445
|
+
reasoning: true,
|
|
446
|
+
maxTokens: 16384
|
|
447
|
+
}),
|
|
448
|
+
modelRecipe({
|
|
449
|
+
id: "gemma-4-e2b-it-q4_k_m",
|
|
450
|
+
name: "Gemma 4 E2B (Q4_K_M)",
|
|
451
|
+
repository: "unsloth/gemma-4-E2B-it-GGUF",
|
|
452
|
+
file: "gemma-4-E2B-it-Q4_K_M.gguf",
|
|
453
|
+
revision: "0314792d7f1f7e229411f620751375812bb9faf2",
|
|
454
|
+
sha256: "740185b21d22ceb83a11c3aa62ad5842ef32c70f6096d756bbee85a1e4ec34b8",
|
|
455
|
+
sizeBytes: 3106738272,
|
|
456
|
+
memoryGiB: 6,
|
|
457
|
+
minimumSystemGiB: 8
|
|
458
|
+
})
|
|
459
|
+
];
|
|
460
|
+
function resolveLlamaCppCatalogArtifact(source) {
|
|
461
|
+
return LLAMA_CPP_MODEL_RECIPES.find((recipe) => recipe.model.params?.modelPath === source)?.artifact;
|
|
462
|
+
}
|
|
463
|
+
function resolveLlamaCppMemoryBudget(hardware, backend) {
|
|
464
|
+
const systemBudget = Math.min(hardware.availableMemoryBytes, hardware.totalMemoryBytes - Math.max(2 * GIB$1, hardware.totalMemoryBytes * .25));
|
|
465
|
+
const gpuBudget = hardware.accelerator.kind === "cuda" ? Math.max(0, ...hardware.accelerator.devices.map((device) => Math.min(device.availableMemoryBytes, device.totalMemoryBytes - Math.max(GIB$1, device.totalMemoryBytes * .1)))) : 0;
|
|
466
|
+
return Math.max(0, backend === "cuda" ? Math.min(systemBudget, gpuBudget) : systemBudget);
|
|
467
|
+
}
|
|
468
|
+
function resolveLlamaCppModelCandidates(hardware, backend) {
|
|
469
|
+
const memoryBudgetBytes = resolveLlamaCppMemoryBudget(hardware, backend);
|
|
470
|
+
return {
|
|
471
|
+
recipes: LLAMA_CPP_MODEL_RECIPES.filter((recipe) => (!recipe.requiresAcceleration || backend !== "cpu") && hardware.totalMemoryBytes >= recipe.minimumSystemMemoryBytes && memoryBudgetBytes >= recipe.memoryBytes),
|
|
472
|
+
memoryBudgetBytes
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
function resolveLlamaCppDiskBudget(hardware, backend, runtimeCached = false) {
|
|
476
|
+
if (hardware.availableDiskBytes === void 0 || hardware.availableRuntimeDiskBytes === void 0) return {
|
|
477
|
+
kind: "unavailable",
|
|
478
|
+
reason: "Cannot measure free space in the model cache or runtime directory. Check their permissions and retry setup."
|
|
479
|
+
};
|
|
480
|
+
const runtimeDiskBytes = runtimeCached ? 0 : (backend === "cuda" ? 3 : 2) * GIB$1;
|
|
481
|
+
if (!hardware.sharedDisk && hardware.availableRuntimeDiskBytes < runtimeDiskBytes) return {
|
|
482
|
+
kind: "unavailable",
|
|
483
|
+
reason: "There is not enough free disk space in the runtime directory. Free space on that volume and retry setup."
|
|
484
|
+
};
|
|
485
|
+
return {
|
|
486
|
+
kind: "available",
|
|
487
|
+
modelDiskBudget: hardware.sharedDisk ? Math.min(hardware.availableDiskBytes, hardware.availableRuntimeDiskBytes) - runtimeDiskBytes : hardware.availableDiskBytes,
|
|
488
|
+
runtimeDiskBytes
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
function recommendLlamaCppModel(hardware, backend, cached = {}) {
|
|
492
|
+
const disk = resolveLlamaCppDiskBudget(hardware, backend, cached.runtime);
|
|
493
|
+
if (disk.kind === "unavailable") return disk;
|
|
494
|
+
const { modelDiskBudget, runtimeDiskBytes } = disk;
|
|
495
|
+
const { recipes: candidates, memoryBudgetBytes } = resolveLlamaCppModelCandidates(hardware, backend);
|
|
496
|
+
for (const recipe of candidates) {
|
|
497
|
+
const modelDiskBytes = (cached.modelIds?.has(recipe.model.id) ? 0 : recipe.sizeBytes) + (cached.embedding ? 0 : DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES);
|
|
498
|
+
if (modelDiskBudget < modelDiskBytes) continue;
|
|
499
|
+
const placement = backend === "metal" ? "Metal unified memory" : backend === "cuda" ? "NVIDIA GPU memory" : "CPU memory";
|
|
500
|
+
return {
|
|
501
|
+
kind: "recommended",
|
|
502
|
+
recipe,
|
|
503
|
+
memoryBudgetBytes,
|
|
504
|
+
requiredDiskBytes: modelDiskBytes + runtimeDiskBytes,
|
|
505
|
+
reason: `${recipe.model.name} fits the ${formatLlamaCppMemory(memoryBudgetBytes)} ${placement} budget with a 64K context. Runtime verification checks the actual model before activation.`
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
kind: "unavailable",
|
|
510
|
+
reason: candidates.length > 0 ? "There is not enough free disk space for a recommended model, embeddings, and the runtime. Free space in the model cache and retry setup." : `No recommended model fits the current ${formatLlamaCppMemory(Math.max(0, memoryBudgetBytes))} memory budget. Close other applications and retry, or configure an existing GGUF or external server. For local memory search without a chat model, an embedding-only local server (about 0.3 GB for the default embedding model) can fit instead. Set memory.search.provider to "local" with openclaw config set memory.search.provider local, then re-run openclaw models auth login --provider llama-cpp --method local using the same profile for both commands.`
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region extensions/llama-cpp/src/media-catalog.ts
|
|
515
|
+
const GIB = 1024 ** 3;
|
|
516
|
+
function artifact(repository, revision, filename, expectedSize, expectedSha256) {
|
|
517
|
+
return {
|
|
518
|
+
repository,
|
|
519
|
+
revision,
|
|
520
|
+
filename,
|
|
521
|
+
source: `hf:${repository}/${filename}#${revision}`,
|
|
522
|
+
fileName: `hf_${repository.replaceAll("/", "_")}_${revision}_${filename}`,
|
|
523
|
+
url: `https://huggingface.co/${repository}/resolve/${revision}/${filename}?download=true`,
|
|
524
|
+
expectedSize,
|
|
525
|
+
expectedSha256
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
const GLM_OCR_REPOSITORY = "ggml-org/GLM-OCR-GGUF";
|
|
529
|
+
const GLM_OCR_REVISION = "65a42de1148dbed2297e922b5dbc7d9b70c36578";
|
|
530
|
+
const SMOL_VLM2_REPOSITORY = "ggml-org/SmolVLM2-2.2B-Instruct-GGUF";
|
|
531
|
+
const SMOL_VLM2_REVISION = "1bc3c9f74ceafd4c8d4411cc9cf188bba3798f91";
|
|
532
|
+
const LLAMA_CPP_MEDIA_RECIPES = [{
|
|
533
|
+
id: "glm-ocr-q8_0",
|
|
534
|
+
name: "GLM-OCR (Q8_0)",
|
|
535
|
+
capability: "ocr",
|
|
536
|
+
model: artifact(GLM_OCR_REPOSITORY, GLM_OCR_REVISION, "GLM-OCR-Q8_0.gguf", 950433408, "45bc244a6446aff850521dc41f18bc8d7105ad5f0c2c8c28af04e7cc4f4d50b1"),
|
|
537
|
+
projector: artifact(GLM_OCR_REPOSITORY, GLM_OCR_REVISION, "mmproj-GLM-OCR-Q8_0.gguf", 484403648, "9c4b58e33e316ed142eb5dcb41abec3844d3e6e5dc361ffb782c3fa9d175141f"),
|
|
538
|
+
minimumSystemMemoryBytes: 6 * GIB,
|
|
539
|
+
memoryBytes: 4 * GIB,
|
|
540
|
+
contextSize: 8192,
|
|
541
|
+
maxTokens: 4096,
|
|
542
|
+
imageMaxTokens: 1024,
|
|
543
|
+
prompt: "Text Recognition:",
|
|
544
|
+
limitations: [
|
|
545
|
+
"Recognizes text; use the vision model for scenes, charts, and spatial questions.",
|
|
546
|
+
"Dense or multi-column pages may need separate crops; no document layout detector is installed.",
|
|
547
|
+
"Image encoding is limited to 1024 tokens (about 0.8 megapixels); small text may lose detail."
|
|
548
|
+
]
|
|
549
|
+
}, {
|
|
550
|
+
id: "smolvlm2-2.2b-instruct-q4_k_m",
|
|
551
|
+
name: "SmolVLM2 2.2B (Q4_K_M)",
|
|
552
|
+
capability: "vision",
|
|
553
|
+
model: artifact(SMOL_VLM2_REPOSITORY, SMOL_VLM2_REVISION, "SmolVLM2-2.2B-Instruct-Q4_K_M.gguf", 1112602656, "0cf76814555b8665149075b74ab6b5c1d428ea1d3d01c1918c12012e8d7c9f58"),
|
|
554
|
+
projector: artifact(SMOL_VLM2_REPOSITORY, SMOL_VLM2_REVISION, "mmproj-SmolVLM2-2.2B-Instruct-Q8_0.gguf", 592523200, "ae07ea1facd07dd3230c4483b63e8cda96c6944ad2481f33d531f79e892dd024"),
|
|
555
|
+
minimumSystemMemoryBytes: 6 * GIB,
|
|
556
|
+
memoryBytes: 5 * GIB,
|
|
557
|
+
contextSize: 8192,
|
|
558
|
+
maxTokens: 2048,
|
|
559
|
+
imageMaxTokens: 1024,
|
|
560
|
+
limitations: ["Small English-focused vision model; complex diagrams and spatial reasoning may be inaccurate."]
|
|
561
|
+
}];
|
|
562
|
+
function resolveLlamaCppMediaArtifact(source) {
|
|
563
|
+
for (const recipe of LLAMA_CPP_MEDIA_RECIPES) for (const value of [recipe.model, recipe.projector]) if (value.source === source) return value;
|
|
564
|
+
}
|
|
565
|
+
function recommendLlamaCppMedia(hardware, cached = {}) {
|
|
566
|
+
const unavailable = (reason) => ({
|
|
567
|
+
kind: "unavailable",
|
|
568
|
+
reason
|
|
569
|
+
});
|
|
570
|
+
const memoryBudgetBytes = resolveLlamaCppMemoryBudget(hardware, "cpu");
|
|
571
|
+
const rejections = [];
|
|
572
|
+
for (const recipe of LLAMA_CPP_MEDIA_RECIPES) {
|
|
573
|
+
if (hardware.totalMemoryBytes < recipe.minimumSystemMemoryBytes) rejections.push(`${recipe.name} requires ${formatLlamaCppMemory(recipe.minimumSystemMemoryBytes)} total RAM; host has ${formatLlamaCppMemory(hardware.totalMemoryBytes)}.`);
|
|
574
|
+
if (memoryBudgetBytes < recipe.memoryBytes) rejections.push(`${recipe.name} requires ${formatLlamaCppMemory(recipe.memoryBytes)} memory; the system memory budget is ${formatLlamaCppMemory(memoryBudgetBytes)} after host headroom and current memory pressure.`);
|
|
575
|
+
}
|
|
576
|
+
if (rejections.length > 0) return unavailable(`${rejections.join(" ")} Close other applications or use a host with more memory and retry setup.`);
|
|
577
|
+
const disk = resolveLlamaCppDiskBudget(hardware, "cpu", cached.runtime);
|
|
578
|
+
if (disk.kind === "unavailable") return unavailable(disk.reason);
|
|
579
|
+
const { modelDiskBudget, runtimeDiskBytes } = disk;
|
|
580
|
+
const [ocr, vision] = LLAMA_CPP_MEDIA_RECIPES;
|
|
581
|
+
const modelDiskBytes = [
|
|
582
|
+
ocr.model,
|
|
583
|
+
ocr.projector,
|
|
584
|
+
vision.model,
|
|
585
|
+
vision.projector
|
|
586
|
+
].reduce((bytes, item) => bytes + (cached.artifactSha256?.has(item.expectedSha256) ? 0 : item.expectedSize), 0);
|
|
587
|
+
if (modelDiskBytes > modelDiskBudget) return unavailable(`Missing OCR and vision models and projectors need ${formatLlamaCppMemory(modelDiskBytes)} disk space; ${formatLlamaCppMemory(Math.max(0, modelDiskBudget))} remains after the runtime reserve. Free space in the model cache and retry setup.`);
|
|
588
|
+
return {
|
|
589
|
+
kind: "recommended",
|
|
590
|
+
ocr,
|
|
591
|
+
vision,
|
|
592
|
+
requiredDiskBytes: modelDiskBytes + runtimeDiskBytes,
|
|
593
|
+
reason: `${ocr.name} (OCR, ${formatLlamaCppMemory(ocr.memoryBytes)}) and ${vision.name} (vision, ${formatLlamaCppMemory(vision.memoryBytes)}) fit the ${formatLlamaCppMemory(memoryBudgetBytes)} CPU memory budget. Load one model at a time, preserving the chat and embedding inventory. Images stay local; runtime verification must pass before activation.`
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
//#endregion
|
|
597
|
+
export { resolveLlamaCppCatalogArtifact as a, formatLlamaCppMemory as c, LLAMA_SERVER_RELEASE as d, findManagedLlamaServerAsset as f, recommendLlamaCppModel as i, LLAMA_SERVER_BUILD as l, selectLlamaServerAsset as m, recommendLlamaCppMedia as n, resolveLlamaCppModelCandidates as o, resolveManagedLlamaServerPaths as p, resolveLlamaCppMediaArtifact as r, detectLlamaCppHardware as s, LLAMA_CPP_MEDIA_RECIPES as t, LLAMA_SERVER_COMMIT as u };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { isRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
2
|
+
import { shouldUseEnvHttpProxyForUrl } from "openclaw/plugin-sdk/fetch-runtime";
|
|
3
|
+
//#region extensions/llama-cpp/src/media-config.ts
|
|
4
|
+
const LLAMA_CPP_MEDIA_MAX_BYTES = 10485760;
|
|
5
|
+
const LLAMA_CPP_MEDIA_MAX_TOKENS = 2048;
|
|
6
|
+
const LLAMA_CPP_MEDIA_MAX_CHARS = 12e3;
|
|
7
|
+
const LLAMA_CPP_MEDIA_TIMEOUT_MS = 6e5;
|
|
8
|
+
/** Managed media never sends image bytes to an external provider endpoint. */
|
|
9
|
+
function isManagedLlamaCppMediaProvider(provider) {
|
|
10
|
+
if (!provider?.localService || provider.request?.proxy?.mode === "explicit-proxy") return false;
|
|
11
|
+
try {
|
|
12
|
+
const url = new URL(provider.baseUrl);
|
|
13
|
+
return url.protocol === "http:" && (url.hostname === "127.0.0.1" || url.hostname === "[::1]") && !shouldUseEnvHttpProxyForUrl(url.href) && !url.username && !url.password;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Saved recipe selections, never inferred from an image's prompt or filename. */
|
|
19
|
+
function resolveLlamaCppMediaModels(provider) {
|
|
20
|
+
const models = provider?.params?.mediaModels;
|
|
21
|
+
if (!isRecord(models)) return;
|
|
22
|
+
const ocr = normalizeOptionalString(models.ocr);
|
|
23
|
+
const vision = normalizeOptionalString(models.vision);
|
|
24
|
+
return ocr && vision ? {
|
|
25
|
+
ocr,
|
|
26
|
+
vision
|
|
27
|
+
} : void 0;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { isManagedLlamaCppMediaProvider as a, LLAMA_CPP_MEDIA_TIMEOUT_MS as i, LLAMA_CPP_MEDIA_MAX_CHARS as n, resolveLlamaCppMediaModels as o, LLAMA_CPP_MEDIA_MAX_TOKENS as r, LLAMA_CPP_MEDIA_MAX_BYTES as t };
|