@openclaw/llama-cpp-provider 2026.10.10-beta.5 → 2026.11.5-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-Dx2WDi-G.mjs → auth-config-GFuvSOHY.mjs} +2 -3
- package/dist/.setup/{defaults-DX4XN2j1.mjs → defaults-B-3wLNsP.mjs} +2 -3
- package/dist/.setup/{discovery-DdCiAOWU.mjs → discovery-BzqfGNU5.mjs} +5 -9
- package/dist/.setup/{embedding-provider.runtime-djNMas6G.mjs → embedding-provider.runtime-D5WYHk8V.mjs} +49 -42
- package/dist/.setup/{managed-provider-config-BuFqNTx1.mjs → managed-provider-config-XhvrVUR1.mjs} +2 -3
- package/dist/.setup/{managed-server-Bjr1c5yX.mjs → managed-server-CTer5Rq4.mjs} +395 -299
- package/dist/.setup/{media-catalog-BwFQGYtY.mjs → media-catalog-D-CRqGbe.mjs} +10 -218
- package/dist/.setup/{media-config-CZ7CluNV.mjs → media-config-92b6iCHm.mjs} +1 -2
- package/dist/.setup/{media-provider.runtime-MqV-UJ1m.mjs → media-provider.runtime-CW2ZQBg4.mjs} +4 -5
- package/dist/.setup/{media-setup-BQ6-EW_y.mjs → media-setup-DIZRVYUM.mjs} +12 -14
- package/dist/.setup/{provider-tg85QOYU.mjs → provider-abJEzh8u.mjs} +5 -8
- package/dist/.setup/{provider-discovery-CWtKWZkY.mjs → provider-discovery-6Hy2SktE.mjs} +6 -10
- package/dist/.setup/{setup-DmjzzdfH.mjs → setup-4lK0M-lf.mjs} +125 -135
- package/dist/.setup/{setup-CDJ2D5mu.mjs → setup-BnmsVffD.mjs} +8 -11
- package/dist/.setup/{stream-CSBkXmdm.mjs → stream-PxiV675a.mjs} +40 -13
- package/dist/.source-module-urls/2a292bf2cc9d15ab4011c4fb7ee888280524a76675c662fb0329d5dc914f3fba.json +1 -1
- package/dist/index.js +118 -127
- package/dist/provider-discovery.js +1 -1
- package/dist/provider-policy-api.js +2 -3
- package/package.json +5 -5
|
@@ -1,23 +1,230 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as resolveLlamaCppCatalogArtifact,
|
|
1
|
+
import { D as resolveLlamaCppModelSource, E as resolveLlamaCppModelCacheDir, S as resolveHomePath, a as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID, c as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES, h as LLAMA_CPP_DEFAULT_PORT, n as DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE, o as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION, r as DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE, s as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256, w as resolveLlamaCppDataDir, x as resolveCachedLlamaCppModelPath } from "./defaults-B-3wLNsP.mjs";
|
|
2
|
+
import { a as resolveLlamaCppCatalogArtifact, r as resolveLlamaCppMediaArtifact } from "./media-catalog-D-CRqGbe.mjs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
5
5
|
import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";
|
|
6
6
|
import { fetchWithSsrFGuard, ssrfPolicyFromHttpBaseUrlAllowedOrigin } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
7
7
|
import { fetchConfiguredLocalOriginWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime-internal";
|
|
8
8
|
import { createHash, randomUUID } from "node:crypto";
|
|
9
|
-
import
|
|
9
|
+
import fsp from "node:fs/promises";
|
|
10
10
|
import net from "node:net";
|
|
11
11
|
import { createAsyncLock } from "openclaw/plugin-sdk/async-lock-runtime";
|
|
12
|
+
import { createSubsystemLogger } from "openclaw/plugin-sdk/logging-core";
|
|
12
13
|
import { execFile } from "node:child_process";
|
|
13
|
-
import fs
|
|
14
|
+
import fs, { createWriteStream } from "node:fs";
|
|
15
|
+
import { pipeline } from "node:stream/promises";
|
|
14
16
|
import { sha256File } from "@openclaw/fs-safe/durability";
|
|
17
|
+
import { ARCHIVE_LIMIT_ERROR_CODE, ArchiveLimitError, extractArchive } from "openclaw/plugin-sdk/archive";
|
|
15
18
|
import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
|
|
16
19
|
import { toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
import { racePromiseWithAbortSignal } from "openclaw/plugin-sdk/time-runtime";
|
|
21
|
+
// extensions/llama-cpp/src/llama-server-assets.ts
|
|
22
|
+
const LLAMA_SERVER_RELEASE = "b10809";
|
|
23
|
+
const LLAMA_SERVER_COMMIT = "5266f24da75dc449bd56cbed7addb9c8e4a6a73e";
|
|
24
|
+
const MEBIBYTE$1 = 1048576;
|
|
25
|
+
const CUDA_ARCHIVE_LIMITS = {
|
|
26
|
+
maxArchiveBytes: 400 * MEBIBYTE$1,
|
|
27
|
+
maxExtractedBytes: 600 * MEBIBYTE$1,
|
|
28
|
+
maxEntryBytes: 521 * MEBIBYTE$1
|
|
29
|
+
};
|
|
30
|
+
const WINDOWS_X64_VC_RUNTIME = {
|
|
31
|
+
archive: "vc-redist",
|
|
32
|
+
name: "VC_redist.x64.exe",
|
|
33
|
+
url: "https://download.visualstudio.microsoft.com/download/pr/ebdab8e5-1d7b-4d9f-a11b-cbb1720c3b12/843068991DAAA1F73AD9F6239BCE4D0F6A07A51F18C37EA2A867E9BECA71295C/VC_redist.x64.exe",
|
|
34
|
+
sha256: "843068991daaa1f73ad9f6239bce4d0f6a07a51f18c37ea2a867e9beca71295c",
|
|
35
|
+
size: 18731856,
|
|
36
|
+
containerOffset: 63e4,
|
|
37
|
+
containerSize: 18091661,
|
|
38
|
+
nestedCabinet: "a4",
|
|
39
|
+
files: [
|
|
40
|
+
{
|
|
41
|
+
source: "msvcp140.dll_amd64",
|
|
42
|
+
target: "msvcp140.dll"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
source: "vcruntime140.dll_amd64",
|
|
46
|
+
target: "vcruntime140.dll"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
source: "vcruntime140_1.dll_amd64",
|
|
50
|
+
target: "vcruntime140_1.dll"
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
};
|
|
54
|
+
const WINDOWS_ARM64_VC_RUNTIME = {
|
|
55
|
+
archive: "vc-redist",
|
|
56
|
+
name: "VC_redist.arm64.exe",
|
|
57
|
+
url: "https://download.visualstudio.microsoft.com/download/pr/ece44298-3977-4f73-ab91-c13fe79cfea8/B70EF586669A620A0A30A1156969C05C6A3831DC8F8BC992DA75779D2A92F944/VC_redist.arm64.exe",
|
|
58
|
+
sha256: "b70ef586669a620a0a30a1156969c05c6a3831dc8f8bc992da75779d2a92f944",
|
|
59
|
+
size: 11870816,
|
|
60
|
+
containerOffset: 684112,
|
|
61
|
+
containerSize: 11176508,
|
|
62
|
+
nestedCabinet: "a1",
|
|
63
|
+
files: [{
|
|
64
|
+
source: "msvcp140.dll_arm64",
|
|
65
|
+
target: "msvcp140.dll"
|
|
66
|
+
}, {
|
|
67
|
+
source: "vcruntime140.dll_arm64",
|
|
68
|
+
target: "vcruntime140.dll"
|
|
69
|
+
}]
|
|
70
|
+
};
|
|
71
|
+
const MACOS_ALIASES = [
|
|
72
|
+
["libggml-rpc.0.23.0.dylib", ["libggml-rpc.0.dylib", "libggml-rpc.dylib"]],
|
|
73
|
+
["libllama.0.4.0.dylib", ["libllama.0.dylib", "libllama.dylib"]],
|
|
74
|
+
["libmtmd.0.4.0.dylib", ["libmtmd.0.dylib", "libmtmd.dylib"]],
|
|
75
|
+
["libggml.0.23.0.dylib", ["libggml.0.dylib", "libggml.dylib"]],
|
|
76
|
+
["libggml-base.0.23.0.dylib", ["libggml-base.0.dylib", "libggml-base.dylib"]],
|
|
77
|
+
["libggml-blas.0.23.0.dylib", ["libggml-blas.0.dylib", "libggml-blas.dylib"]],
|
|
78
|
+
["libllama-common.0.4.0.dylib", ["libllama-common.0.dylib", "libllama-common.dylib"]],
|
|
79
|
+
["libggml-cpu.0.23.0.dylib", ["libggml-cpu.0.dylib", "libggml-cpu.dylib"]]
|
|
80
|
+
];
|
|
81
|
+
const MACOS_METAL_ALIASES = [...MACOS_ALIASES, ["libggml-metal.0.23.0.dylib", ["libggml-metal.0.dylib", "libggml-metal.dylib"]]];
|
|
82
|
+
const LINUX_ALIASES = [
|
|
83
|
+
["libllama.so.0.4.0", ["libllama.so.0", "libllama.so"]],
|
|
84
|
+
["libggml.so.0.23.0", ["libggml.so.0", "libggml.so"]],
|
|
85
|
+
["libmtmd.so.0.4.0", ["libmtmd.so.0", "libmtmd.so"]],
|
|
86
|
+
["libggml-base.so.0.23.0", ["libggml-base.so.0", "libggml-base.so"]],
|
|
87
|
+
["libllama-common.so.0.4.0", ["libllama-common.so.0", "libllama-common.so"]]
|
|
88
|
+
];
|
|
89
|
+
const LLAMA_SERVER_ASSETS = [
|
|
90
|
+
{
|
|
91
|
+
platform: "darwin",
|
|
92
|
+
arch: "arm64",
|
|
93
|
+
backend: "metal",
|
|
94
|
+
archive: "tar.gz",
|
|
95
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
96
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-arm64.tar.gz`,
|
|
97
|
+
sha256: "7d692df9e1e386e62f1c12b843903218041e6cd74c9415aa39a7ed3176f9eaa2",
|
|
98
|
+
sizeBytes: 11123196,
|
|
99
|
+
executable: "llama-server",
|
|
100
|
+
regularFileAliases: MACOS_METAL_ALIASES
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
platform: "darwin",
|
|
104
|
+
arch: "x64",
|
|
105
|
+
backend: "cpu",
|
|
106
|
+
archive: "tar.gz",
|
|
107
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
108
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-macos-x64.tar.gz`,
|
|
109
|
+
sha256: "13b34aa8a5d87341a21065a83f54a8167e1aaa6fe0d66065de01632a1ed64be6",
|
|
110
|
+
sizeBytes: 11175330,
|
|
111
|
+
executable: "llama-server",
|
|
112
|
+
regularFileAliases: MACOS_ALIASES
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
platform: "linux",
|
|
116
|
+
arch: "arm64",
|
|
117
|
+
backend: "cpu",
|
|
118
|
+
archive: "tar.gz",
|
|
119
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
120
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-arm64.tar.gz`,
|
|
121
|
+
sha256: "f2b7333971e1b7b42e9268bfdbfa30f5f56e2897156084d2251385df94aec358",
|
|
122
|
+
sizeBytes: 13380118,
|
|
123
|
+
executable: "llama-server",
|
|
124
|
+
regularFileAliases: LINUX_ALIASES
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
platform: "linux",
|
|
128
|
+
arch: "x64",
|
|
129
|
+
backend: "cpu",
|
|
130
|
+
archive: "tar.gz",
|
|
131
|
+
archiveRoot: `llama-${LLAMA_SERVER_RELEASE}`,
|
|
132
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-ubuntu-x64.tar.gz`,
|
|
133
|
+
sha256: "5e34434ddc6d03cd1584f403201aff0d4bd1a5793a72ff7e286532dfd1e4b941",
|
|
134
|
+
sizeBytes: 16734586,
|
|
135
|
+
executable: "llama-server",
|
|
136
|
+
regularFileAliases: LINUX_ALIASES
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
platform: "win32",
|
|
140
|
+
arch: "x64",
|
|
141
|
+
backend: "cuda",
|
|
142
|
+
archive: "zip",
|
|
143
|
+
archiveRoot: ".",
|
|
144
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cuda-12.4-x64.zip`,
|
|
145
|
+
sha256: "c77bfcd9ed8d91e8721a2d6a290b907fddd4fa5412a47b21c6fa1709116b85f9",
|
|
146
|
+
sizeBytes: 253938543,
|
|
147
|
+
executable: "llama-server.exe",
|
|
148
|
+
regularFileAliases: [],
|
|
149
|
+
limits: CUDA_ARCHIVE_LIMITS,
|
|
150
|
+
dependencies: [{
|
|
151
|
+
archive: "zip",
|
|
152
|
+
archiveRoot: ".",
|
|
153
|
+
name: "cudart-llama-bin-win-cuda-12.4-x64.zip",
|
|
154
|
+
sha256: "8c79a9b226de4b3cacfd1f83d24f962d0773be79f1e7b75c6af4ded7e32ae1d6",
|
|
155
|
+
sizeBytes: 391443627,
|
|
156
|
+
regularFileAliases: [],
|
|
157
|
+
files: [
|
|
158
|
+
"cublas64_12.dll",
|
|
159
|
+
"cublasLt64_12.dll",
|
|
160
|
+
"cudart64_12.dll"
|
|
161
|
+
],
|
|
162
|
+
limits: {
|
|
163
|
+
...CUDA_ARCHIVE_LIMITS,
|
|
164
|
+
maxEntries: 3
|
|
165
|
+
}
|
|
166
|
+
}, WINDOWS_X64_VC_RUNTIME]
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
platform: "win32",
|
|
170
|
+
arch: "arm64",
|
|
171
|
+
backend: "cpu",
|
|
172
|
+
archive: "zip",
|
|
173
|
+
archiveRoot: ".",
|
|
174
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-arm64.zip`,
|
|
175
|
+
sha256: "c1058fe5764a687275c8d20d6bbc1454e787cdbb8ebb8c37a2f959f2b144dc77",
|
|
176
|
+
sizeBytes: 11974499,
|
|
177
|
+
executable: "llama-server.exe",
|
|
178
|
+
regularFileAliases: [],
|
|
179
|
+
dependencies: [WINDOWS_ARM64_VC_RUNTIME]
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
platform: "win32",
|
|
183
|
+
arch: "x64",
|
|
184
|
+
backend: "cpu",
|
|
185
|
+
archive: "zip",
|
|
186
|
+
archiveRoot: ".",
|
|
187
|
+
name: `llama-${LLAMA_SERVER_RELEASE}-bin-win-cpu-x64.zip`,
|
|
188
|
+
sha256: "9df3158ed228a641a4b127942d7f459f24c9e13f04682659d05c00c80099b6b5",
|
|
189
|
+
sizeBytes: 18407457,
|
|
190
|
+
executable: "llama-server.exe",
|
|
191
|
+
regularFileAliases: [],
|
|
192
|
+
dependencies: [WINDOWS_X64_VC_RUNTIME]
|
|
193
|
+
}
|
|
194
|
+
];
|
|
195
|
+
function selectLlamaServerAsset(platform = process.platform, arch = process.arch, acceleration) {
|
|
196
|
+
const backend = acceleration?.kind ?? (platform === "darwin" && arch === "arm64" ? "metal" : "cpu");
|
|
197
|
+
if (backend === "cuda" && acceleration?.kind === "cuda") {
|
|
198
|
+
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.`);
|
|
199
|
+
if (!(acceleration.devices.length > 0 && acceleration.devices.every((device) => {
|
|
200
|
+
const version = /^(\d+)\.(\d+)(?:\.\d+)?$/u.exec(device.driverVersion);
|
|
201
|
+
return version && (Number(version[1]) > 551 || Number(version[1]) === 551 && Number(version[2]) >= 78) && (device.computeCapability === void 0 || device.computeCapability >= 5);
|
|
202
|
+
}))) 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.");
|
|
203
|
+
}
|
|
204
|
+
const asset = LLAMA_SERVER_ASSETS.find((candidate) => candidate.platform === platform && candidate.arch === arch && candidate.backend === backend);
|
|
205
|
+
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.`);
|
|
206
|
+
return asset;
|
|
207
|
+
}
|
|
208
|
+
function resolveManagedLlamaServerPaths(asset = selectLlamaServerAsset()) {
|
|
209
|
+
const installDir = path.join(resolveLlamaCppDataDir(), LLAMA_SERVER_RELEASE, `${asset.platform}-${asset.arch}${asset.backend === "cuda" ? "-cuda-12.4" : ""}`);
|
|
210
|
+
return {
|
|
211
|
+
installDir,
|
|
212
|
+
command: path.join(installDir, asset.executable),
|
|
213
|
+
presetPath: path.join(resolveLlamaCppDataDir(), "models.ini")
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function findManagedLlamaServerAsset(command, platform = process.platform, arch = process.arch) {
|
|
217
|
+
return LLAMA_SERVER_ASSETS.find((asset) => asset.platform === platform && asset.arch === arch && resolveManagedLlamaServerPaths(asset).command === command);
|
|
218
|
+
}
|
|
219
|
+
// extensions/llama-cpp/src/runtime-error.ts
|
|
220
|
+
function formatLlamaServerRuntimeError(error) {
|
|
221
|
+
const cause = error instanceof Error ? error : new Error(String(error));
|
|
222
|
+
const library = cause.message.match(/error while loading shared libraries: ([\w.+-]+):/u)?.[1];
|
|
223
|
+
if (!library) return cause;
|
|
224
|
+
const runtime = /^lib(?:ssl|crypto)\.so\.3$/u.test(library) ? "OpenSSL 3 (libssl3t64 or libssl3 on Debian/Ubuntu)" : library.startsWith("libgomp.so.") ? "OpenMP (libgomp1 on Debian/Ubuntu or libgomp on Fedora)" : library;
|
|
225
|
+
return new Error(`Missing llama-server shared library ${library}. Install the ${runtime} runtime using your system package manager, then rerun llama.cpp setup. Detail: ${cause.message}`, { cause });
|
|
226
|
+
}
|
|
227
|
+
// extensions/llama-cpp/src/llama-server-install.ts
|
|
21
228
|
const MEBIBYTE = 1048576;
|
|
22
229
|
const LLAMA_ARCHIVE_LIMITS = {
|
|
23
230
|
maxArchiveBytes: 256 * MEBIBYTE,
|
|
@@ -27,37 +234,24 @@ const LLAMA_ARCHIVE_LIMITS = {
|
|
|
27
234
|
maxMetaEntryBytes: MEBIBYTE
|
|
28
235
|
};
|
|
29
236
|
const MAX_ALIAS_BYTES = 512 * MEBIBYTE;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
237
|
+
const CAB_HEADER_SIZE = 12;
|
|
238
|
+
const EXPAND_TIMEOUT_MS = 6e4;
|
|
239
|
+
async function assertRegularFile(filePath, label, source = "llama-server archive") {
|
|
240
|
+
const stat = await fsp.lstat(filePath).catch(() => void 0);
|
|
241
|
+
if (!stat?.isFile() || stat.nlink > 1) throw new Error(`${source} does not contain regular ${label}`);
|
|
33
242
|
return stat;
|
|
34
243
|
}
|
|
35
|
-
async function
|
|
36
|
-
|
|
37
|
-
let copiedBytes = 0;
|
|
38
|
-
for (const [source, aliases] of params.asset.regularFileAliases) {
|
|
39
|
-
const sourcePath = path.join(params.rootDir, source);
|
|
40
|
-
const sourceStat = await assertRegularFile$1(sourcePath, `alias source ${source}`);
|
|
41
|
-
for (const alias of aliases) {
|
|
42
|
-
copiedBytes += sourceStat.size;
|
|
43
|
-
if (copiedBytes > MAX_ALIAS_BYTES) throw new ArchiveLimitError(ARCHIVE_LIMIT_ERROR_CODE.EXTRACTED_SIZE_EXCEEDS_LIMIT);
|
|
44
|
-
const aliasPath = path.join(params.rootDir, alias);
|
|
45
|
-
await fs.copyFile(sourcePath, aliasPath, constants.COPYFILE_EXCL);
|
|
46
|
-
await fs.chmod(aliasPath, sourceStat.mode & 511);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function extractVerifiedArchive(params) {
|
|
51
|
-
const isTar = params.asset.archive === "tar.gz";
|
|
244
|
+
async function extractVerifiedArchive(archivePath, destDir, asset, requiredFiles) {
|
|
245
|
+
const isTar = asset.archive === "tar.gz";
|
|
52
246
|
const limits = {
|
|
53
247
|
...LLAMA_ARCHIVE_LIMITS,
|
|
54
|
-
...
|
|
248
|
+
...asset.limits
|
|
55
249
|
};
|
|
56
|
-
const aliasCount =
|
|
250
|
+
const aliasCount = asset.regularFileAliases.reduce((count, [, aliases]) => count + aliases.length, 0);
|
|
57
251
|
if (aliasCount > limits.maxEntries) throw new ArchiveLimitError(ARCHIVE_LIMIT_ERROR_CODE.ENTRY_COUNT_EXCEEDS_LIMIT);
|
|
58
252
|
await extractArchive({
|
|
59
|
-
archivePath
|
|
60
|
-
destDir
|
|
253
|
+
archivePath,
|
|
254
|
+
destDir,
|
|
61
255
|
kind: isTar ? "tar" : "zip",
|
|
62
256
|
timeoutMs: 0,
|
|
63
257
|
limits: {
|
|
@@ -68,116 +262,28 @@ async function extractVerifiedArchive(params) {
|
|
|
68
262
|
entryFilter: (entry) => entry.kind === "symlink" ? "skip" : "extract",
|
|
69
263
|
onFiltered: "skip-entry"
|
|
70
264
|
});
|
|
71
|
-
const rootDir = path.join(
|
|
72
|
-
await
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
});
|
|
85
|
-
return path.join(rootDir, params.asset.executable);
|
|
86
|
-
}
|
|
87
|
-
async function extractLlamaServerDependencyArchive(params) {
|
|
88
|
-
return await extractVerifiedArchive({
|
|
89
|
-
...params,
|
|
90
|
-
requiredFiles: params.asset.files
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
//#endregion
|
|
94
|
-
//#region extensions/llama-cpp/src/llama-server-vc-runtime.ts
|
|
95
|
-
const CAB_HEADER_SIZE = 12;
|
|
96
|
-
const EXPAND_TIMEOUT_MS = 6e4;
|
|
97
|
-
async function extractPinnedContainer(params) {
|
|
98
|
-
const source = await fs.open(params.bundlePath, "r");
|
|
99
|
-
try {
|
|
100
|
-
const stat = await source.stat();
|
|
101
|
-
if (!stat.isFile() || stat.size !== params.asset.size) throw new Error(`Visual C++ runtime bundle size mismatch: expected ${params.asset.size}, got ${stat.size}`);
|
|
102
|
-
if (params.asset.containerOffset < 0 || params.asset.containerSize < CAB_HEADER_SIZE || params.asset.containerOffset + params.asset.containerSize > stat.size) throw new Error("invalid Visual C++ runtime container bounds");
|
|
103
|
-
const header = Buffer.alloc(CAB_HEADER_SIZE);
|
|
104
|
-
if ((await source.read(header, 0, header.length, params.asset.containerOffset)).bytesRead !== header.length || header.subarray(0, 4).toString("ascii") !== "MSCF" || header.readUInt32LE(8) !== params.asset.containerSize) throw new Error("Visual C++ runtime bundle does not contain the pinned cabinet");
|
|
105
|
-
await pipeline(source.createReadStream({
|
|
106
|
-
start: params.asset.containerOffset,
|
|
107
|
-
end: params.asset.containerOffset + params.asset.containerSize - 1,
|
|
108
|
-
autoClose: false
|
|
109
|
-
}), createWriteStream(params.containerPath, {
|
|
110
|
-
flags: "wx",
|
|
111
|
-
mode: 384
|
|
112
|
-
}), { signal: params.signal });
|
|
113
|
-
} finally {
|
|
114
|
-
await source.close();
|
|
265
|
+
const rootDir = path.join(destDir, asset.archiveRoot);
|
|
266
|
+
for (const file of requiredFiles) await assertRegularFile(path.join(rootDir, file), `file ${file}`);
|
|
267
|
+
let copiedBytes = 0;
|
|
268
|
+
for (const [source, aliases] of asset.regularFileAliases) {
|
|
269
|
+
const sourcePath = path.join(rootDir, source);
|
|
270
|
+
const sourceStat = await assertRegularFile(sourcePath, `alias source ${source}`);
|
|
271
|
+
for (const alias of aliases) {
|
|
272
|
+
copiedBytes += sourceStat.size;
|
|
273
|
+
if (copiedBytes > MAX_ALIAS_BYTES) throw new ArchiveLimitError(ARCHIVE_LIMIT_ERROR_CODE.EXTRACTED_SIZE_EXCEEDS_LIMIT);
|
|
274
|
+
const aliasPath = path.join(rootDir, alias);
|
|
275
|
+
await fsp.copyFile(sourcePath, aliasPath, fs.constants.COPYFILE_EXCL);
|
|
276
|
+
await fsp.chmod(aliasPath, sourceStat.mode & 511);
|
|
277
|
+
}
|
|
115
278
|
}
|
|
116
|
-
|
|
117
|
-
function resolveExpandCommand() {
|
|
118
|
-
const systemRoot = process.env.SystemRoot;
|
|
119
|
-
if (!systemRoot || !path.win32.isAbsolute(systemRoot)) throw new Error("SystemRoot is unavailable; cannot extract the Visual C++ runtime");
|
|
120
|
-
return path.win32.join(systemRoot, "System32", "expand.exe");
|
|
279
|
+
return rootDir;
|
|
121
280
|
}
|
|
122
281
|
async function runExpand(command, args, signal) {
|
|
123
|
-
await
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
signal,
|
|
127
|
-
windowsHide: true
|
|
128
|
-
}, (error, _stdout, stderr) => {
|
|
129
|
-
if (error) {
|
|
130
|
-
const detail = stderr.trim();
|
|
131
|
-
reject(new Error(`Failed to extract the Visual C++ runtime${detail ? `: ${detail}` : ""}`, { cause: error }));
|
|
132
|
-
} else resolve();
|
|
133
|
-
});
|
|
282
|
+
await runServerCommand(command, args, signal, EXPAND_TIMEOUT_MS, (error, stderr) => {
|
|
283
|
+
const detail = stderr.trim();
|
|
284
|
+
return new Error(`Failed to extract the Visual C++ runtime${detail ? `: ${detail}` : ""}`, { cause: error });
|
|
134
285
|
});
|
|
135
286
|
}
|
|
136
|
-
async function assertRegularFile(filePath, label) {
|
|
137
|
-
const stat = await fs.lstat(filePath).catch(() => void 0);
|
|
138
|
-
if (!stat?.isFile() || stat.nlink > 1) throw new Error(`Visual C++ runtime does not contain regular file ${label}`);
|
|
139
|
-
}
|
|
140
|
-
/** Extracts the pinned Microsoft redistributable DLLs without installing machine-wide state. */
|
|
141
|
-
async function extractWindowsVcRuntime(params) {
|
|
142
|
-
const { nestedCabinet, files } = params.asset;
|
|
143
|
-
const expandCommand = resolveExpandCommand();
|
|
144
|
-
const containerPath = path.join(params.destDir, "bundle.cab");
|
|
145
|
-
const nestedDir = path.join(params.destDir, "nested");
|
|
146
|
-
const filesDir = path.join(params.destDir, "files");
|
|
147
|
-
await Promise.all([
|
|
148
|
-
fs.mkdir(params.destDir, { recursive: true }),
|
|
149
|
-
fs.mkdir(nestedDir, { recursive: true }),
|
|
150
|
-
fs.mkdir(filesDir, { recursive: true })
|
|
151
|
-
]);
|
|
152
|
-
await extractPinnedContainer({
|
|
153
|
-
asset: params.asset,
|
|
154
|
-
bundlePath: params.bundlePath,
|
|
155
|
-
containerPath,
|
|
156
|
-
signal: params.signal
|
|
157
|
-
});
|
|
158
|
-
await runExpand(expandCommand, [
|
|
159
|
-
`-F:${nestedCabinet}`,
|
|
160
|
-
containerPath,
|
|
161
|
-
nestedDir
|
|
162
|
-
], params.signal);
|
|
163
|
-
const nestedPath = path.join(nestedDir, nestedCabinet);
|
|
164
|
-
await assertRegularFile(nestedPath, nestedCabinet);
|
|
165
|
-
for (const file of files) {
|
|
166
|
-
params.signal?.throwIfAborted();
|
|
167
|
-
await runExpand(expandCommand, [
|
|
168
|
-
`-F:${file.source}`,
|
|
169
|
-
nestedPath,
|
|
170
|
-
filesDir
|
|
171
|
-
], params.signal);
|
|
172
|
-
const sourcePath = path.join(filesDir, file.source);
|
|
173
|
-
await assertRegularFile(sourcePath, file.source);
|
|
174
|
-
const targetPath = path.join(params.destDir, file.target);
|
|
175
|
-
await fs.copyFile(sourcePath, targetPath, constants.COPYFILE_EXCL);
|
|
176
|
-
}
|
|
177
|
-
return params.destDir;
|
|
178
|
-
}
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region extensions/llama-cpp/src/llama-server-install.ts
|
|
181
287
|
const DOWNLOAD_TIMEOUT_MS = 18e5;
|
|
182
288
|
const PROBE_TIMEOUT_MS = 15e3;
|
|
183
289
|
const VERSION_TIMEOUT_MS = 12e4;
|
|
@@ -235,16 +341,16 @@ function rememberVerifiedFile(filePath, stat, sha256) {
|
|
|
235
341
|
async function sha256File$1(filePath, signal) {
|
|
236
342
|
signal?.throwIfAborted();
|
|
237
343
|
try {
|
|
238
|
-
const identity = fileIdentity(await
|
|
344
|
+
const identity = fileIdentity(await fsp.stat(filePath, { bigint: true }));
|
|
239
345
|
const verified = verifiedFiles.get(filePath);
|
|
240
346
|
if (verified?.identity === identity) return verified.sha256;
|
|
241
347
|
verifiedFiles.delete(filePath);
|
|
242
|
-
const handle = await
|
|
348
|
+
const handle = await fsp.open(filePath, "r");
|
|
243
349
|
try {
|
|
244
350
|
const before = fileIdentity(await handle.stat({ bigint: true }));
|
|
245
351
|
const { digest: sha256 } = await sha256File(handle, { signal });
|
|
246
352
|
const after = await handle.stat({ bigint: true });
|
|
247
|
-
if (before !== fileIdentity(after) || before !== fileIdentity(await
|
|
353
|
+
if (before !== fileIdentity(after) || before !== fileIdentity(await fsp.stat(filePath, { bigint: true }))) throw new Error(`File changed during integrity verification: ${filePath}. Retry setup.`);
|
|
248
354
|
rememberVerifiedFile(filePath, after, sha256);
|
|
249
355
|
return sha256;
|
|
250
356
|
} finally {
|
|
@@ -265,7 +371,7 @@ function readResponseSha256(response) {
|
|
|
265
371
|
}
|
|
266
372
|
async function downloadVerifiedFile(params) {
|
|
267
373
|
const partialPath = `${params.destination}.partial-${randomUUID()}`;
|
|
268
|
-
await
|
|
374
|
+
await fsp.mkdir(path.dirname(params.destination), { recursive: true });
|
|
269
375
|
const { fetchWithSsrFGuard, ssrfPolicyFromHttpBaseUrlAllowedOrigin } = await import("openclaw/plugin-sdk/ssrf-runtime");
|
|
270
376
|
try {
|
|
271
377
|
const { response, release } = await fetchWithSsrFGuard({
|
|
@@ -282,7 +388,7 @@ async function downloadVerifiedFile(params) {
|
|
|
282
388
|
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");
|
|
283
389
|
const contentLength = Number(response.headers.get("content-length"));
|
|
284
390
|
const totalSize = params.expectedSize ?? (Number.isFinite(contentLength) && contentLength > 0 ? contentLength : 0);
|
|
285
|
-
const handle = await
|
|
391
|
+
const handle = await fsp.open(partialPath, "wx", 384);
|
|
286
392
|
const hash = createHash("sha256");
|
|
287
393
|
let downloadedSize = 0;
|
|
288
394
|
let previousSize = 0;
|
|
@@ -312,7 +418,7 @@ async function downloadVerifiedFile(params) {
|
|
|
312
418
|
if (expectedSha256 && actualSha256 !== expectedSha256.toLowerCase()) throw new Error(`download SHA-256 mismatch: expected ${expectedSha256}, got ${actualSha256}`);
|
|
313
419
|
const completed = await handle.stat({ bigint: true });
|
|
314
420
|
params.signal?.throwIfAborted();
|
|
315
|
-
await
|
|
421
|
+
await fsp.rename(partialPath, params.destination);
|
|
316
422
|
const published = await handle.stat({ bigint: true });
|
|
317
423
|
if (completed.size === published.size && completed.mtimeNs === published.mtimeNs) rememberVerifiedFile(params.destination, published, actualSha256);
|
|
318
424
|
} finally {
|
|
@@ -322,34 +428,28 @@ async function downloadVerifiedFile(params) {
|
|
|
322
428
|
await release();
|
|
323
429
|
}
|
|
324
430
|
} finally {
|
|
325
|
-
await
|
|
431
|
+
await fsp.rm(partialPath, { force: true }).catch(() => void 0);
|
|
326
432
|
}
|
|
327
433
|
}
|
|
328
|
-
async function runServerCommand(command, args, signal, timeoutMs = PROBE_TIMEOUT_MS) {
|
|
434
|
+
async function runServerCommand(command, args, signal, timeoutMs = PROBE_TIMEOUT_MS, formatError = formatRuntimeDependencyError) {
|
|
329
435
|
return await new Promise((resolve, reject) => {
|
|
330
436
|
execFile(command, args, {
|
|
331
437
|
timeout: timeoutMs,
|
|
332
438
|
signal,
|
|
333
439
|
windowsHide: true
|
|
334
440
|
}, (error, stdout, stderr) => {
|
|
335
|
-
if (error) reject(
|
|
441
|
+
if (error) reject(signal?.aborted ? toErrorObject(signal.reason, "Installation cancelled") : formatError(error, stderr));
|
|
336
442
|
else resolve(`${stdout}${stderr}`.trim());
|
|
337
443
|
});
|
|
338
444
|
});
|
|
339
445
|
}
|
|
340
446
|
function formatRuntimeDependencyError(error) {
|
|
341
447
|
const detail = error instanceof Error ? error.message : String(error);
|
|
342
|
-
if (process.platform === "linux") return new Error(`The verified llama-server build could not start. Install the OpenMP runtime (for example libgomp1 on Debian/Ubuntu or libgomp on Fedora), then rerun llama.cpp setup. Detail: ${detail}`, { cause: error });
|
|
343
448
|
if (process.platform === "win32") return new Error(`The verified llama-server build could not start with its app-local Visual C++ runtime. Rerun llama.cpp setup to reinstall it, or configure a compatible llama-server manually. Detail: ${detail}`, { cause: error });
|
|
344
|
-
return
|
|
449
|
+
return formatLlamaServerRuntimeError(error);
|
|
345
450
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return await runServerCommand(command, ["--version"], signal, VERSION_TIMEOUT_MS);
|
|
349
|
-
} catch (error) {
|
|
350
|
-
signal?.throwIfAborted();
|
|
351
|
-
throw formatRuntimeDependencyError(error);
|
|
352
|
-
}
|
|
451
|
+
function queryServerVersion(command, signal) {
|
|
452
|
+
return runServerCommand(command, ["--version"], signal, VERSION_TIMEOUT_MS);
|
|
353
453
|
}
|
|
354
454
|
function validateServerVersionOutput(command, version) {
|
|
355
455
|
const match = (version.split(/\r?\n/u, 1)[0]?.trim() ?? "").match(/^version: .+ \(build (\d+), commit ([a-f\d]{9})\)$/u);
|
|
@@ -367,32 +467,6 @@ async function validateInstalledServer(command, asset, signal) {
|
|
|
367
467
|
validateServerVersionOutput(command, await queryServerVersion(command, signal));
|
|
368
468
|
await validateCudaServer(command, asset, signal);
|
|
369
469
|
}
|
|
370
|
-
async function stageLlamaServerDependency(params) {
|
|
371
|
-
const { dependency, extractDir, extractedRoot, index, options } = params;
|
|
372
|
-
options.signal?.throwIfAborted();
|
|
373
|
-
const dependencyArchive = path.join(extractDir, dependency.name);
|
|
374
|
-
await downloadVerifiedFile({
|
|
375
|
-
url: assetUrl(dependency),
|
|
376
|
-
destination: dependencyArchive,
|
|
377
|
-
expectedSha256: dependency.sha256,
|
|
378
|
-
expectedSize: dependency.archive === "vc-redist" ? dependency.size : void 0,
|
|
379
|
-
signal: options.signal,
|
|
380
|
-
onProgress: options.onProgress
|
|
381
|
-
});
|
|
382
|
-
const dependencyExtractDir = path.join(extractDir, `dependency-${index}`);
|
|
383
|
-
await fs.mkdir(dependencyExtractDir);
|
|
384
|
-
const dependencyRoot = dependency.archive === "vc-redist" ? await extractWindowsVcRuntime({
|
|
385
|
-
bundlePath: dependencyArchive,
|
|
386
|
-
destDir: dependencyExtractDir,
|
|
387
|
-
asset: dependency,
|
|
388
|
-
signal: options.signal
|
|
389
|
-
}) : await extractLlamaServerDependencyArchive({
|
|
390
|
-
archivePath: dependencyArchive,
|
|
391
|
-
destDir: dependencyExtractDir,
|
|
392
|
-
asset: dependency
|
|
393
|
-
});
|
|
394
|
-
for (const file of dependencyFiles(dependency)) await fs.copyFile(path.join(dependencyRoot, file), path.join(extractedRoot, file), fs$1.constants.COPYFILE_EXCL);
|
|
395
|
-
}
|
|
396
470
|
function formatVcRuntimeFallbackError(startupError, fallbackError) {
|
|
397
471
|
const startupDetail = startupError instanceof Error ? startupError.message : String(startupError);
|
|
398
472
|
const fallbackDetail = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
|
|
@@ -402,7 +476,7 @@ async function installLlamaServer(asset, options) {
|
|
|
402
476
|
options.signal?.throwIfAborted();
|
|
403
477
|
assertSupportedLinuxRuntime(asset);
|
|
404
478
|
const { installDir, command } = resolveManagedLlamaServerPaths(asset);
|
|
405
|
-
if (await
|
|
479
|
+
if (await fsp.stat(command).then((stat) => stat.isFile()).catch(() => false)) {
|
|
406
480
|
try {
|
|
407
481
|
await validateInstalledServer(command, asset, options.signal);
|
|
408
482
|
} catch (error) {
|
|
@@ -415,7 +489,7 @@ async function installLlamaServer(asset, options) {
|
|
|
415
489
|
const dataDir = resolveLlamaCppDataDir();
|
|
416
490
|
const archivePath = path.join(dataDir, `.download-${randomUUID()}-${asset.name}`);
|
|
417
491
|
const extractDir = path.join(dataDir, `.extract-${randomUUID()}`);
|
|
418
|
-
await
|
|
492
|
+
await fsp.mkdir(dataDir, { recursive: true });
|
|
419
493
|
try {
|
|
420
494
|
await downloadVerifiedFile({
|
|
421
495
|
url: assetUrl(asset),
|
|
@@ -425,28 +499,82 @@ async function installLlamaServer(asset, options) {
|
|
|
425
499
|
onProgress: options.onProgress
|
|
426
500
|
});
|
|
427
501
|
const serverExtractDir = path.join(extractDir, "server");
|
|
428
|
-
await
|
|
429
|
-
const extractedCommand = await
|
|
430
|
-
archivePath,
|
|
431
|
-
destDir: serverExtractDir,
|
|
432
|
-
asset
|
|
433
|
-
});
|
|
502
|
+
await fsp.mkdir(serverExtractDir, { recursive: true });
|
|
503
|
+
const extractedCommand = path.join(await extractVerifiedArchive(archivePath, serverExtractDir, asset, [asset.executable]), asset.executable);
|
|
434
504
|
const extractedRoot = path.dirname(extractedCommand);
|
|
505
|
+
const stageDependency = async (dependency, index) => {
|
|
506
|
+
options.signal?.throwIfAborted();
|
|
507
|
+
const dependencyArchive = path.join(extractDir, dependency.name);
|
|
508
|
+
await downloadVerifiedFile({
|
|
509
|
+
url: assetUrl(dependency),
|
|
510
|
+
destination: dependencyArchive,
|
|
511
|
+
expectedSha256: dependency.sha256,
|
|
512
|
+
expectedSize: dependency.archive === "vc-redist" ? dependency.size : void 0,
|
|
513
|
+
signal: options.signal,
|
|
514
|
+
onProgress: options.onProgress
|
|
515
|
+
});
|
|
516
|
+
const dependencyExtractDir = path.join(extractDir, `dependency-${index}`);
|
|
517
|
+
await fsp.mkdir(dependencyExtractDir);
|
|
518
|
+
let dependencyRoot;
|
|
519
|
+
if (dependency.archive === "vc-redist") {
|
|
520
|
+
const { nestedCabinet, files } = dependency;
|
|
521
|
+
const systemRoot = process.env.SystemRoot;
|
|
522
|
+
if (!systemRoot || !path.win32.isAbsolute(systemRoot)) throw new Error("SystemRoot is unavailable; cannot extract the Visual C++ runtime");
|
|
523
|
+
const expandCommand = path.win32.join(systemRoot, "System32", "expand.exe");
|
|
524
|
+
const containerPath = path.join(dependencyExtractDir, "bundle.cab");
|
|
525
|
+
const nestedDir = path.join(dependencyExtractDir, "nested");
|
|
526
|
+
const filesDir = path.join(dependencyExtractDir, "files");
|
|
527
|
+
await Promise.all([fsp.mkdir(nestedDir, { recursive: true }), fsp.mkdir(filesDir, { recursive: true })]);
|
|
528
|
+
const source = await fsp.open(dependencyArchive, "r");
|
|
529
|
+
try {
|
|
530
|
+
const stat = await source.stat();
|
|
531
|
+
if (!stat.isFile() || stat.size !== dependency.size) throw new Error(`Visual C++ runtime bundle size mismatch: expected ${dependency.size}, got ${stat.size}`);
|
|
532
|
+
if (dependency.containerOffset < 0 || dependency.containerSize < CAB_HEADER_SIZE || dependency.containerOffset + dependency.containerSize > stat.size) throw new Error("invalid Visual C++ runtime container bounds");
|
|
533
|
+
const header = Buffer.alloc(CAB_HEADER_SIZE);
|
|
534
|
+
if ((await source.read(header, 0, header.length, dependency.containerOffset)).bytesRead !== header.length || header.subarray(0, 4).toString("ascii") !== "MSCF" || header.readUInt32LE(8) !== dependency.containerSize) throw new Error("Visual C++ runtime bundle does not contain the pinned cabinet");
|
|
535
|
+
await pipeline(source.createReadStream({
|
|
536
|
+
start: dependency.containerOffset,
|
|
537
|
+
end: dependency.containerOffset + dependency.containerSize - 1,
|
|
538
|
+
autoClose: false
|
|
539
|
+
}), createWriteStream(containerPath, {
|
|
540
|
+
flags: "wx",
|
|
541
|
+
mode: 384
|
|
542
|
+
}), { signal: options.signal });
|
|
543
|
+
} finally {
|
|
544
|
+
await source.close();
|
|
545
|
+
}
|
|
546
|
+
await runExpand(expandCommand, [
|
|
547
|
+
`-F:${nestedCabinet}`,
|
|
548
|
+
containerPath,
|
|
549
|
+
nestedDir
|
|
550
|
+
], options.signal);
|
|
551
|
+
const nestedPath = path.join(nestedDir, nestedCabinet);
|
|
552
|
+
await assertRegularFile(nestedPath, `file ${nestedCabinet}`, "Visual C++ runtime");
|
|
553
|
+
for (const file of files) {
|
|
554
|
+
options.signal?.throwIfAborted();
|
|
555
|
+
await runExpand(expandCommand, [
|
|
556
|
+
`-F:${file.source}`,
|
|
557
|
+
nestedPath,
|
|
558
|
+
filesDir
|
|
559
|
+
], options.signal);
|
|
560
|
+
const sourcePath = path.join(filesDir, file.source);
|
|
561
|
+
await assertRegularFile(sourcePath, `file ${file.source}`, "Visual C++ runtime");
|
|
562
|
+
await fsp.copyFile(sourcePath, path.join(dependencyExtractDir, file.target), fs.constants.COPYFILE_EXCL);
|
|
563
|
+
}
|
|
564
|
+
dependencyRoot = dependencyExtractDir;
|
|
565
|
+
} else dependencyRoot = await extractVerifiedArchive(dependencyArchive, dependencyExtractDir, dependency, dependency.files);
|
|
566
|
+
const files = dependency.archive === "vc-redist" ? dependency.files.map((file) => file.target) : dependency.files;
|
|
567
|
+
for (const file of files) await fsp.copyFile(path.join(dependencyRoot, file), path.join(extractedRoot, file), fs.constants.COPYFILE_EXCL);
|
|
568
|
+
};
|
|
435
569
|
const dependencies = asset.dependencies ?? [];
|
|
436
570
|
const windowsRuntimeDependencies = [];
|
|
437
571
|
for (const [index, dependency] of dependencies.entries()) if (dependency.archive === "vc-redist") windowsRuntimeDependencies.push({
|
|
438
572
|
dependency,
|
|
439
573
|
index
|
|
440
574
|
});
|
|
441
|
-
else await
|
|
442
|
-
dependency,
|
|
443
|
-
index,
|
|
444
|
-
extractDir,
|
|
445
|
-
extractedRoot,
|
|
446
|
-
options
|
|
447
|
-
});
|
|
575
|
+
else await stageDependency(dependency, index);
|
|
448
576
|
options.signal?.throwIfAborted();
|
|
449
|
-
await
|
|
577
|
+
await fsp.chmod(extractedCommand, 493);
|
|
450
578
|
if (windowsRuntimeDependencies.length > 0) {
|
|
451
579
|
let version;
|
|
452
580
|
try {
|
|
@@ -454,13 +582,7 @@ async function installLlamaServer(asset, options) {
|
|
|
454
582
|
} catch (startupError) {
|
|
455
583
|
options.signal?.throwIfAborted();
|
|
456
584
|
try {
|
|
457
|
-
for (const { dependency, index } of windowsRuntimeDependencies) await
|
|
458
|
-
dependency,
|
|
459
|
-
index,
|
|
460
|
-
extractDir,
|
|
461
|
-
extractedRoot,
|
|
462
|
-
options
|
|
463
|
-
});
|
|
585
|
+
for (const { dependency, index } of windowsRuntimeDependencies) await stageDependency(dependency, index);
|
|
464
586
|
} catch (stagingError) {
|
|
465
587
|
options.signal?.throwIfAborted();
|
|
466
588
|
throw formatVcRuntimeFallbackError(startupError, stagingError);
|
|
@@ -475,25 +597,21 @@ async function installLlamaServer(asset, options) {
|
|
|
475
597
|
validateServerVersionOutput(extractedCommand, version);
|
|
476
598
|
await validateCudaServer(extractedCommand, asset, options.signal);
|
|
477
599
|
} else await validateInstalledServer(extractedCommand, asset, options.signal);
|
|
478
|
-
await
|
|
600
|
+
await fsp.mkdir(path.dirname(installDir), { recursive: true });
|
|
479
601
|
options.signal?.throwIfAborted();
|
|
480
|
-
await
|
|
602
|
+
await fsp.rm(installDir, {
|
|
481
603
|
recursive: true,
|
|
482
604
|
force: true
|
|
483
605
|
});
|
|
484
|
-
await
|
|
485
|
-
await validateInstalledServer(command, asset, options.signal);
|
|
606
|
+
await fsp.rename(extractedRoot, installDir);
|
|
486
607
|
return command;
|
|
487
608
|
} finally {
|
|
488
|
-
await Promise.all([
|
|
609
|
+
await Promise.all([fsp.rm(archivePath, { force: true }), fsp.rm(extractDir, {
|
|
489
610
|
recursive: true,
|
|
490
611
|
force: true
|
|
491
612
|
})]);
|
|
492
613
|
}
|
|
493
614
|
}
|
|
494
|
-
function dependencyFiles(dependency) {
|
|
495
|
-
return dependency.archive === "vc-redist" ? dependency.files.map((file) => file.target) : dependency.files;
|
|
496
|
-
}
|
|
497
615
|
async function ensureLlamaServerInstalled(options = {}) {
|
|
498
616
|
options.signal?.throwIfAborted();
|
|
499
617
|
const asset = options.asset ?? selectLlamaServerAsset();
|
|
@@ -503,19 +621,9 @@ async function ensureLlamaServerInstalled(options = {}) {
|
|
|
503
621
|
if (installationPromises.get(key) === pending) installationPromises.delete(key);
|
|
504
622
|
});
|
|
505
623
|
installationPromises.set(key, pending);
|
|
506
|
-
return {
|
|
507
|
-
command: previous && options.signal ? await new Promise((resolve, reject) => {
|
|
508
|
-
const signal = options.signal;
|
|
509
|
-
const onAbort = () => reject(toErrorObject(signal?.reason, "Installation cancelled"));
|
|
510
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
511
|
-
pending.then(resolve, reject).finally(() => signal?.removeEventListener("abort", onAbort));
|
|
512
|
-
if (signal?.aborted) onAbort();
|
|
513
|
-
}) : await pending,
|
|
514
|
-
asset
|
|
515
|
-
};
|
|
624
|
+
return { command: await racePromiseWithAbortSignal(pending, previous ? options.signal : void 0, (signal) => toErrorObject(signal.reason, "Installation cancelled")) };
|
|
516
625
|
}
|
|
517
|
-
|
|
518
|
-
//#region extensions/llama-cpp/src/llama-server-preset.ts
|
|
626
|
+
// extensions/llama-cpp/src/llama-server-preset.ts
|
|
519
627
|
function assertIniValue(value, label) {
|
|
520
628
|
if (/\r|\n/u.test(value)) throw new Error(`${label} cannot contain a newline`);
|
|
521
629
|
return value;
|
|
@@ -648,10 +756,17 @@ function buildLlamaServerPreset(existing, params) {
|
|
|
648
756
|
const orderedSections = [...[...sections].toSorted(([left], [right]) => Number(left > right) - Number(left < right)).map(([, section]) => section), ...embeddingSection ? [embeddingSection] : []];
|
|
649
757
|
return header + (header && !/[\r\n]$/u.test(header) ? newline : "") + orderedSections.map((section) => section.replace(/[\r\n]+$/u, "")).join(newline + newline) + newline;
|
|
650
758
|
}
|
|
651
|
-
|
|
652
|
-
|
|
759
|
+
// extensions/llama-cpp/src/managed-server.ts
|
|
760
|
+
const modelPromises = /* @__PURE__ */ new Map();
|
|
653
761
|
const log = createSubsystemLogger("llama-cpp");
|
|
654
762
|
const recoveries = /* @__PURE__ */ new Map();
|
|
763
|
+
const resolvedModelArtifacts = /* @__PURE__ */ new Map();
|
|
764
|
+
const presetState = {
|
|
765
|
+
appliedRevisions: /* @__PURE__ */ new Map(),
|
|
766
|
+
desiredRevisions: /* @__PURE__ */ new Map()
|
|
767
|
+
};
|
|
768
|
+
const runPresetTransition = createAsyncLock();
|
|
769
|
+
const LLAMA_CPP_PRESET_RELOAD_TIMEOUT_MS = 15e3;
|
|
655
770
|
function readUniqueArgument(argv, name) {
|
|
656
771
|
const values = argv.flatMap((argument, index) => {
|
|
657
772
|
if (argument === name) {
|
|
@@ -662,55 +777,6 @@ function readUniqueArgument(argv, name) {
|
|
|
662
777
|
});
|
|
663
778
|
return values.length === 1 ? values[0] : void 0;
|
|
664
779
|
}
|
|
665
|
-
/** A new host process recovers once; in-process restarts retain that host's children. */
|
|
666
|
-
async function recoverManagedLlamaServer(params) {
|
|
667
|
-
params.signal?.throwIfAborted();
|
|
668
|
-
if (!findManagedLlamaServerAsset(params.command)) return;
|
|
669
|
-
const args = params.args ?? [];
|
|
670
|
-
const preset = readUniqueArgument(args, "--models-preset");
|
|
671
|
-
const host = readUniqueArgument(args, "--host");
|
|
672
|
-
if (!preset || !host || readUniqueArgument(args, "--port") !== String(params.port)) return;
|
|
673
|
-
const required = /* @__PURE__ */ new Map([
|
|
674
|
-
["--port", String(params.port)],
|
|
675
|
-
["--models-preset", preset],
|
|
676
|
-
["--host", host]
|
|
677
|
-
]);
|
|
678
|
-
const cwd = !path.isAbsolute(preset) ? path.resolve(params.cwd ?? process.cwd()) : void 0;
|
|
679
|
-
const key = JSON.stringify([
|
|
680
|
-
params.command,
|
|
681
|
-
[...required],
|
|
682
|
-
cwd
|
|
683
|
-
]);
|
|
684
|
-
let recovery = recoveries.get(key);
|
|
685
|
-
if (!recovery) {
|
|
686
|
-
recovery = (async () => {
|
|
687
|
-
const { reapOrphanedProcesses } = await import("openclaw/plugin-sdk/process-runtime");
|
|
688
|
-
await reapOrphanedProcesses({
|
|
689
|
-
command: params.command,
|
|
690
|
-
cwd,
|
|
691
|
-
matchesArguments: (argv) => [...required].every(([name, value]) => readUniqueArgument(argv, name) === value),
|
|
692
|
-
signal: params.signal,
|
|
693
|
-
onReap: (pid) => log.info(`reaping orphaned managed llama-server: pid=${pid} port=${params.port}`)
|
|
694
|
-
});
|
|
695
|
-
})().catch((error) => {
|
|
696
|
-
recoveries.delete(key);
|
|
697
|
-
throw error;
|
|
698
|
-
});
|
|
699
|
-
recoveries.set(key, recovery);
|
|
700
|
-
}
|
|
701
|
-
await recovery;
|
|
702
|
-
params.signal?.throwIfAborted();
|
|
703
|
-
}
|
|
704
|
-
//#endregion
|
|
705
|
-
//#region extensions/llama-cpp/src/managed-server.ts
|
|
706
|
-
const modelPromises = /* @__PURE__ */ new Map();
|
|
707
|
-
const resolvedModelArtifacts = /* @__PURE__ */ new Map();
|
|
708
|
-
const presetState = {
|
|
709
|
-
appliedRevisions: /* @__PURE__ */ new Map(),
|
|
710
|
-
desiredRevisions: /* @__PURE__ */ new Map()
|
|
711
|
-
};
|
|
712
|
-
const runPresetTransition = createAsyncLock();
|
|
713
|
-
const LLAMA_CPP_PRESET_RELOAD_TIMEOUT_MS = 15e3;
|
|
714
780
|
function parseHuggingFaceSource(source) {
|
|
715
781
|
const [pathPart, revisionPart] = source.replace(/^(?:hf|huggingface):(?:\/\/)?/iu, "").split("#", 2);
|
|
716
782
|
const [user, repositoryWithTag, ...fileParts] = (pathPart ?? "").split("/");
|
|
@@ -805,7 +871,7 @@ function defaultArtifact(source) {
|
|
|
805
871
|
};
|
|
806
872
|
}
|
|
807
873
|
async function assertGguf(filePath) {
|
|
808
|
-
const handle = await
|
|
874
|
+
const handle = await fsp.open(filePath, "r").catch((error) => {
|
|
809
875
|
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 });
|
|
810
876
|
throw error;
|
|
811
877
|
});
|
|
@@ -871,8 +937,8 @@ async function ensureLlamaCppModel(params) {
|
|
|
871
937
|
const artifact = await resolveCachedModelArtifact(localSource, params.cacheDir, params.signal);
|
|
872
938
|
const destination = path.join(params.cacheDir, artifact.fileName);
|
|
873
939
|
const load = modelPromises.get(destination) ?? (async () => {
|
|
874
|
-
const exists = await
|
|
875
|
-
if (exists && artifact.expectedSha256 && (artifact.expectedSize === void 0 || (await
|
|
940
|
+
const exists = await fsp.stat(destination).then((stat) => stat.isFile()).catch(() => false);
|
|
941
|
+
if (exists && artifact.expectedSha256 && (artifact.expectedSize === void 0 || (await fsp.stat(destination)).size === artifact.expectedSize) && await sha256File$1(destination, params.signal) === artifact.expectedSha256) {
|
|
876
942
|
await assertGguf(destination);
|
|
877
943
|
return destination;
|
|
878
944
|
}
|
|
@@ -904,18 +970,18 @@ async function ensureLlamaCppModel(params) {
|
|
|
904
970
|
}
|
|
905
971
|
}
|
|
906
972
|
async function writePreset(presetPath, contents) {
|
|
907
|
-
await
|
|
973
|
+
await fsp.mkdir(path.dirname(presetPath), { recursive: true });
|
|
908
974
|
const temporary = `${presetPath}.tmp-${randomUUID()}`;
|
|
909
975
|
try {
|
|
910
|
-
await
|
|
911
|
-
await
|
|
976
|
+
await fsp.writeFile(temporary, contents, { mode: 384 });
|
|
977
|
+
await fsp.rename(temporary, presetPath);
|
|
912
978
|
} finally {
|
|
913
|
-
await
|
|
979
|
+
await fsp.rm(temporary, { force: true });
|
|
914
980
|
}
|
|
915
981
|
}
|
|
916
982
|
async function updatePreset(presetPath, params) {
|
|
917
983
|
await runPresetTransition(async () => {
|
|
918
|
-
const existing = await
|
|
984
|
+
const existing = await fsp.readFile(presetPath, "utf8").catch((error) => {
|
|
919
985
|
if (asOptionalRecord(error)?.code === "ENOENT") return;
|
|
920
986
|
throw error;
|
|
921
987
|
});
|
|
@@ -967,7 +1033,7 @@ async function prepareManagedLlamaServer(params) {
|
|
|
967
1033
|
let command = params.asset ? void 0 : params.localService?.command;
|
|
968
1034
|
const asset = command === void 0 ? params.asset : findManagedLlamaServerAsset(command);
|
|
969
1035
|
if (command !== void 0 && asset) try {
|
|
970
|
-
await
|
|
1036
|
+
await fsp.stat(command);
|
|
971
1037
|
} catch (error) {
|
|
972
1038
|
if (asOptionalRecord(error)?.code !== "ENOENT") throw error;
|
|
973
1039
|
command = void 0;
|
|
@@ -987,13 +1053,48 @@ async function prepareManagedLlamaServer(params) {
|
|
|
987
1053
|
healthUrl: (!params.isolated ? params.localService?.healthUrl : void 0) ?? `${rootUrl}/health`
|
|
988
1054
|
};
|
|
989
1055
|
const configuredPreset = resolveLlamaCppPresetPath(params.localService);
|
|
990
|
-
if (params.localService && !params.isolated)
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
1056
|
+
if (params.localService && !params.isolated) {
|
|
1057
|
+
const { cwd: configuredCwd, args: configuredArgs } = params.localService;
|
|
1058
|
+
const signal = params.signal;
|
|
1059
|
+
signal?.throwIfAborted();
|
|
1060
|
+
if (findManagedLlamaServerAsset(command)) {
|
|
1061
|
+
const args = configuredArgs ?? [];
|
|
1062
|
+
const preset = readUniqueArgument(args, "--models-preset");
|
|
1063
|
+
const host = readUniqueArgument(args, "--host");
|
|
1064
|
+
if (preset && host && readUniqueArgument(args, "--port") === String(port)) {
|
|
1065
|
+
const required = /* @__PURE__ */ new Map([
|
|
1066
|
+
["--port", String(port)],
|
|
1067
|
+
["--models-preset", preset],
|
|
1068
|
+
["--host", host]
|
|
1069
|
+
]);
|
|
1070
|
+
const cwd = !path.isAbsolute(preset) ? path.resolve(configuredCwd ?? process.cwd()) : void 0;
|
|
1071
|
+
const key = JSON.stringify([
|
|
1072
|
+
command,
|
|
1073
|
+
[...required],
|
|
1074
|
+
cwd
|
|
1075
|
+
]);
|
|
1076
|
+
let recovery = recoveries.get(key);
|
|
1077
|
+
if (!recovery) {
|
|
1078
|
+
recovery = (async () => {
|
|
1079
|
+
const { reapOrphanedProcesses } = await import("openclaw/plugin-sdk/process-runtime");
|
|
1080
|
+
await reapOrphanedProcesses({
|
|
1081
|
+
command,
|
|
1082
|
+
cwd,
|
|
1083
|
+
matchesArguments: (argv) => [...required].every(([name, value]) => readUniqueArgument(argv, name) === value),
|
|
1084
|
+
signal,
|
|
1085
|
+
onReap: (pid) => log.info(`reaping orphaned managed llama-server: pid=${pid} port=${port}`)
|
|
1086
|
+
});
|
|
1087
|
+
})().catch((error) => {
|
|
1088
|
+
recoveries.delete(key);
|
|
1089
|
+
throw error;
|
|
1090
|
+
});
|
|
1091
|
+
recoveries.set(key, recovery);
|
|
1092
|
+
}
|
|
1093
|
+
await recovery;
|
|
1094
|
+
signal?.throwIfAborted();
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
997
1098
|
if (params.localService && !configuredPreset && !params.isolated) {
|
|
998
1099
|
await runPresetTransition(async () => {
|
|
999
1100
|
presetState.desiredRevisions.delete(reconcileOrigin);
|
|
@@ -1006,7 +1107,7 @@ async function prepareManagedLlamaServer(params) {
|
|
|
1006
1107
|
}
|
|
1007
1108
|
const defaultPreset = configuredPreset ? path.resolve(params.localService?.cwd ?? process.cwd(), configuredPreset) : resolveManagedLlamaServerPaths(params.asset).presetPath;
|
|
1008
1109
|
const presetPath = params.isolated ? path.join(path.dirname(defaultPreset), `models-${randomUUID()}.ini`) : defaultPreset;
|
|
1009
|
-
const initialContents = params.isolated && params.mediaModels ? await
|
|
1110
|
+
const initialContents = params.isolated && params.mediaModels ? await fsp.readFile(defaultPreset, "utf8").catch((error) => {
|
|
1010
1111
|
if (!configuredPreset && asOptionalRecord(error)?.code === "ENOENT") return;
|
|
1011
1112
|
throw error;
|
|
1012
1113
|
}) : void 0;
|
|
@@ -1030,7 +1131,7 @@ async function prepareManagedLlamaServer(params) {
|
|
|
1030
1131
|
});
|
|
1031
1132
|
params.signal?.throwIfAborted();
|
|
1032
1133
|
} catch (error) {
|
|
1033
|
-
if (params.isolated) await
|
|
1134
|
+
if (params.isolated) await fsp.rm(presetPath, { force: true });
|
|
1034
1135
|
throw error;
|
|
1035
1136
|
}
|
|
1036
1137
|
return {
|
|
@@ -1073,10 +1174,6 @@ async function ensureManagedLlamaServerForChat(params) {
|
|
|
1073
1174
|
model: params.model,
|
|
1074
1175
|
provider: params.provider
|
|
1075
1176
|
});
|
|
1076
|
-
if (!chatModelPath && resolveLlamaCppModelSource(params.model) === "hf:unsloth/gemma-4-E4B-it-GGUF/gemma-4-E4B-it-Q4_K_M.gguf") {
|
|
1077
|
-
const legacy = path.join(resolveLegacyLlamaCppModelCacheDir(), DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE);
|
|
1078
|
-
if (await fs.stat(legacy).then((stat) => stat.isFile()).catch(() => false)) chatModelPath = legacy;
|
|
1079
|
-
}
|
|
1080
1177
|
chatModelPath = await ensureLlamaCppModel({
|
|
1081
1178
|
source: chatModelPath ?? resolveLlamaCppModelSource(params.model),
|
|
1082
1179
|
cacheDir,
|
|
@@ -1111,5 +1208,4 @@ async function ensureManagedLlamaServerForChat(params) {
|
|
|
1111
1208
|
signal: params.signal
|
|
1112
1209
|
});
|
|
1113
1210
|
}
|
|
1114
|
-
|
|
1115
|
-
export { ensureLlamaCppModel, ensureManagedLlamaServerForChat, UnsupportedLlamaServerHostError as n, prepareManagedLlamaServer, ensureLlamaServerInstalled as r, reconcileManagedLlamaServer, resolveLlamaCppModelDownloadSize, resolveLlamaCppPresetPath, assertMediaPresetLimits as t };
|
|
1211
|
+
export { resolveManagedLlamaServerPaths as a, ensureLlamaCppModel, ensureManagedLlamaServerForChat, formatLlamaServerRuntimeError as i, UnsupportedLlamaServerHostError as n, selectLlamaServerAsset as o, prepareManagedLlamaServer, ensureLlamaServerInstalled as r, reconcileManagedLlamaServer, resolveLlamaCppModelDownloadSize, resolveLlamaCppPresetPath, assertMediaPresetLimits as t };
|