@openclaw/llama-cpp-provider 2026.10.5-beta.3 → 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/{managed-provider-config-D0abOkC_.mjs → defaults-CL2lz0cV.mjs} +5 -13
- package/dist/.setup/discovery-VdqP6WcN.mjs +155 -0
- package/dist/.setup/embedding-provider.runtime-FcwMX9AK.mjs +163 -0
- package/dist/.setup/managed-provider-config-G_LBLX0A.mjs +10 -0
- 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-97l8WbMa.mjs +84 -0
- 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 +191 -2721
- package/dist/provider-discovery.js +1 -0
- package/dist/provider-policy-api.js +1 -1
- package/openclaw.plugin.json +33 -8
- package/package.json +5 -5
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-CL2lz0cV.mjs";
|
|
2
|
+
import { a as isManagedLlamaCppMediaProvider, n as LLAMA_CPP_MEDIA_MAX_CHARS, o as resolveLlamaCppMediaModels, r as LLAMA_CPP_MEDIA_MAX_TOKENS } from "./media-config-CZ7CluNV.mjs";
|
|
3
|
+
import { t as LLAMA_CPP_MEDIA_RECIPES } from "./media-catalog-M5BEPQng.mjs";
|
|
4
|
+
import { asOptionalRecord, truncateUtf16Safe } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
5
|
+
import { describeImageWithModel, describeImagesWithModel, describeImagesWithModelPayloadTransform } from "openclaw/plugin-sdk/media-understanding";
|
|
6
|
+
//#region extensions/llama-cpp/src/media-provider.runtime.ts
|
|
7
|
+
async function describeLlamaCppImages(req) {
|
|
8
|
+
const provider = req.cfg.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
9
|
+
const routes = resolveLlamaCppMediaModels(provider);
|
|
10
|
+
if (provider?.params?.mediaModels !== void 0 && !routes) throw new Error("The configured local media routes are incomplete. Rerun local media setup.");
|
|
11
|
+
if (!routes || req.model !== routes.ocr && req.model !== routes.vision) return await describeImagesWithModel(req);
|
|
12
|
+
req.signal?.throwIfAborted();
|
|
13
|
+
const preparedProvider = req.preparedModelRuntime?.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
14
|
+
const assertDirectLoopback = () => {
|
|
15
|
+
if (req.provider !== "llama-cpp" || !isManagedLlamaCppMediaProvider(provider) || req.preparedModelRuntime && !isManagedLlamaCppMediaProvider(preparedProvider)) throw new Error("Managed local images require a direct loopback llama.cpp server. Remove models.providers.llama-cpp.request.proxy if explicit, and add the server address to NO_PROXY when using an environment proxy. Rerun local media setup.");
|
|
16
|
+
};
|
|
17
|
+
assertDirectLoopback();
|
|
18
|
+
const models = [provider?.models.find((model) => model.id === req.model), ...req.preparedModelRuntime ? [preparedProvider?.models.find((model) => model.id === req.model)] : []];
|
|
19
|
+
if (models.some((model) => !model?.input.includes("image"))) throw new Error("The configured local image model is unavailable. Rerun local media setup.");
|
|
20
|
+
if (preparedProvider && preparedProvider.baseUrl !== provider?.baseUrl || models.some((model) => model?.baseUrl !== void 0 && model.baseUrl !== provider?.baseUrl)) throw new Error("The local image model endpoint must match the managed llama.cpp provider. Rerun local media setup.");
|
|
21
|
+
const baseUrl = provider?.baseUrl;
|
|
22
|
+
if (req.images.length === 0 || req.images.some((image) => image.buffer.length === 0) || req.images.reduce((total, image) => total + image.buffer.length, 0) > 10485760) throw new Error("Local image input must contain between 1 byte and 10 MiB of image data.");
|
|
23
|
+
const recipe = LLAMA_CPP_MEDIA_RECIPES.find((candidate) => candidate.id === req.model);
|
|
24
|
+
const task = req.model === routes.ocr ? "ocr" : "vision";
|
|
25
|
+
if (!recipe || recipe.capability !== task || routes.ocr === routes.vision || task === "ocr" && !recipe.prompt?.trim()) throw new Error("The configured local media recipe is unavailable. Rerun local media setup.");
|
|
26
|
+
if (models.some((model) => model?.params?.modelPath !== recipe.model.source || model?.params?.mmprojPath !== recipe.projector.source)) throw new Error("The local image model and projector must match the verified recipe artifacts. Rerun local media setup.");
|
|
27
|
+
if (req.images.length !== 1) throw new Error("Managed local media accepts one image per request. Analyze images separately.");
|
|
28
|
+
const maxTokens = req.maxTokens ?? 2048;
|
|
29
|
+
if (!Number.isFinite(maxTokens) || maxTokens < 1) throw new Error("Local image maxTokens must be a positive finite number.");
|
|
30
|
+
const prompt = recipe.capability === "ocr" ? recipe.prompt : req.prompt ?? "Describe the image.";
|
|
31
|
+
const result = await describeImagesWithModelPayloadTransform({
|
|
32
|
+
...req,
|
|
33
|
+
prompt,
|
|
34
|
+
maxTokens: Math.min(Math.floor(maxTokens), LLAMA_CPP_MEDIA_MAX_TOKENS)
|
|
35
|
+
}, (payload, model) => {
|
|
36
|
+
assertDirectLoopback();
|
|
37
|
+
if (model.provider !== "llama-cpp" || model.id !== req.model || model.baseUrl !== baseUrl) throw new Error("The resolved local image model must match the managed llama.cpp route. Rerun local media setup.");
|
|
38
|
+
const request = asOptionalRecord(payload);
|
|
39
|
+
const user = (Array.isArray(request?.messages) ? request.messages : []).map(asOptionalRecord).find((message) => message?.role === "user");
|
|
40
|
+
if (!request || !Array.isArray(user?.content)) throw new Error("Local media requires the OpenAI image request format.");
|
|
41
|
+
return {
|
|
42
|
+
...request,
|
|
43
|
+
temperature: 0,
|
|
44
|
+
seed: 4827,
|
|
45
|
+
messages: [{
|
|
46
|
+
role: "user",
|
|
47
|
+
content: [...user.content, {
|
|
48
|
+
type: "text",
|
|
49
|
+
text: prompt
|
|
50
|
+
}]
|
|
51
|
+
}]
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
req.signal?.throwIfAborted();
|
|
55
|
+
return {
|
|
56
|
+
...result,
|
|
57
|
+
text: truncateUtf16Safe(result.text, LLAMA_CPP_MEDIA_MAX_CHARS)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async function describeLlamaCppImage(req) {
|
|
61
|
+
if ((req.cfg.models?.providers?.["llama-cpp"])?.params?.mediaModels === void 0) return await describeImageWithModel(req);
|
|
62
|
+
return await describeLlamaCppImages({
|
|
63
|
+
...req,
|
|
64
|
+
images: [{
|
|
65
|
+
buffer: req.buffer,
|
|
66
|
+
fileName: req.fileName,
|
|
67
|
+
mime: req.mime
|
|
68
|
+
}]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { describeLlamaCppImage, describeLlamaCppImages };
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { E as resolveLlamaCppModelCacheDir, _ as LLAMA_CPP_PROVIDER_ID, b as buildLlamaCppProviderConfig, w as resolveLlamaCppDataDir } from "./defaults-CL2lz0cV.mjs";
|
|
2
|
+
import { a as isManagedLlamaCppMediaProvider, i as LLAMA_CPP_MEDIA_TIMEOUT_MS } from "./media-config-CZ7CluNV.mjs";
|
|
3
|
+
import { c as formatLlamaCppMemory, m as selectLlamaServerAsset, n as recommendLlamaCppMedia, p as resolveManagedLlamaServerPaths, s as detectLlamaCppHardware, t as LLAMA_CPP_MEDIA_RECIPES } from "./media-catalog-M5BEPQng.mjs";
|
|
4
|
+
import { ensureLlamaCppModel, prepareManagedLlamaServer, r as ensureLlamaServerInstalled, resolveLlamaCppPresetPath, t as assertMediaPresetLimits } from "./managed-server-C2ukpg0h.mjs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import os from "node:os";
|
|
7
|
+
import fs from "node:fs/promises";
|
|
8
|
+
//#region extensions/llama-cpp/src/media-verification-fixtures.ts
|
|
9
|
+
const LLAMA_CPP_OCR_FIXTURE = Buffer.from("iVBORw0KGgoAAAANSUhEUgAAA+gAAADcAQAAAADL27ZvAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAAHdElNRQfqCQ4IFRcssbVtAAAFjElEQVR42u3Zy27mJhQAYFyk8S7uMqvxa3QxqtX3qoLdvJiz6muw69a7skCm5wIYHP+piUbqSD2RJhfzm4+bjw+MCv/llxJddNFFF1100UUXXXTRRRdddNFFF1100UUXXXTRRRdddNFFF1100UUXXXTRRRdddNFF/7H1XZmry/PwoBKvHpSvI16e2vRN9SFY1cHtSimqQ4fg4MKu010zfGIKnkCr8AeVKzXGHnTYKroNKpsV1nZPX/GjVqkp66jihVofgyN9RoXLldKH7uBmrqxFRxIrG6I+kA41DKzvWCmNK+k7V03ldCvNBnfAcGUNOlYx4a191HvS4dc+6SbpI007KlxOt+KX43mbAl1p0L0yMHsWB7HQdzWupW6y7tQOAJdX+jzCR9RX1vVN3WkcbDttHRrQBY06LGwfdY8rwuCHNtS3HpxcHpfdhrrZhtDxyt/v6nALVGhhCZU6tCkUujX4hJEOq88OudzSQgy2w8phXQxYX4OOaxn1kHR60rCOP7kO9zPpf0DFOMzrRA2O5S7qS4Bu+z5McWn2N3WozWvUZ1Po0KbwV9SfRyxO+myotbHcMfO2YJDw+Mfx7ZZu8Gm1OLesz6QD9Het0wDRo++P8sgspO/tOvQlVPqK+jrl2dt+GbHXr1FXoSyPzOtZH+7qdL3UDdZuDv0bjXnf4+xjS3GsUnmc4H7Jf9A3d1enwIW6jbpFHdtU6mPS6VqXy1nf+6PvrI+f1qdat7/3pPOAXOvDSd9a9NUU+nbWX3rsS/966PNJ95/VqbZaH+Fad+gr6fvwitGeF9Wcy1l34+mJo2ezSU+rzp31gEHlgc5r3k2gL7zS6Ztt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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB+8F914nYCHOlTpgAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyNi0wOS0xNFQwODoxNzo0MCswMDowMA6iP0UAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjYtMDktMTRUMDg6MTc6NDArMDA6MDB//4f5AAAAAElFTkSuQmCC", "base64");
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region extensions/llama-cpp/src/media-setup.ts
|
|
13
|
+
function modelDefinition(recipe, device, baseUrl) {
|
|
14
|
+
return {
|
|
15
|
+
id: recipe.id,
|
|
16
|
+
name: recipe.name,
|
|
17
|
+
api: "openai-completions",
|
|
18
|
+
baseUrl,
|
|
19
|
+
reasoning: false,
|
|
20
|
+
input: ["text", "image"],
|
|
21
|
+
cost: {
|
|
22
|
+
input: 0,
|
|
23
|
+
output: 0,
|
|
24
|
+
cacheRead: 0,
|
|
25
|
+
cacheWrite: 0
|
|
26
|
+
},
|
|
27
|
+
contextWindow: recipe.contextSize,
|
|
28
|
+
contextTokens: recipe.contextSize,
|
|
29
|
+
maxTokens: recipe.maxTokens,
|
|
30
|
+
params: {
|
|
31
|
+
modelPath: recipe.model.source,
|
|
32
|
+
mmprojPath: recipe.projector.source,
|
|
33
|
+
contextSize: recipe.contextSize,
|
|
34
|
+
imageMaxTokens: recipe.imageMaxTokens,
|
|
35
|
+
device
|
|
36
|
+
},
|
|
37
|
+
compat: {
|
|
38
|
+
supportsTools: false,
|
|
39
|
+
supportsUsageInStreaming: true
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
async function runLlamaCppMediaSetup(ctx, mediaProvider) {
|
|
44
|
+
ctx.signal?.throwIfAborted();
|
|
45
|
+
if (ctx.credentialOnly) throw new Error("Local media setup installs and activates image routes. Run models auth login without --credential-only to complete setup.");
|
|
46
|
+
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
47
|
+
if (existing && (!isManagedLlamaCppMediaProvider(existing) || !resolveLlamaCppPresetPath(existing.localService))) throw new Error("Local media setup requires a managed llama.cpp router with a direct loopback endpoint and no explicit proxy. Add the server address to NO_PROXY when using an environment proxy. Your existing server is unchanged; configure managed server ownership first.");
|
|
48
|
+
const previousMedia = ctx.config.tools?.media;
|
|
49
|
+
if (previousMedia?.models?.some((entry) => !entry.capabilities?.length)) throw new Error("Add explicit capabilities to your existing tools.media.models entries before local media setup, so audio/video routes can be preserved without a remote image fallback.");
|
|
50
|
+
if (!mediaProvider.describeImage) throw new Error("The llama.cpp image provider is unavailable. Enable the llama-cpp plugin and retry.");
|
|
51
|
+
const cacheDir = resolveLlamaCppModelCacheDir(existing);
|
|
52
|
+
const hardware = await detectLlamaCppHardware({
|
|
53
|
+
cacheDir,
|
|
54
|
+
signal: ctx.signal
|
|
55
|
+
});
|
|
56
|
+
if (hardware.platform !== "linux" || hardware.arch !== "x64") {
|
|
57
|
+
await ctx.prompter.note(`Automatic local OCR and vision setup currently supports Linux x64 with CPU execution only; this Gateway is ${hardware.platform}/${hardware.arch}. Use this command on a Linux x64 Gateway, or configure another image provider. Existing llama.cpp chat and embedding setup is unchanged.`, "Local media unavailable");
|
|
58
|
+
return { profiles: [] };
|
|
59
|
+
}
|
|
60
|
+
const asset = selectLlamaServerAsset(hardware.platform, hardware.arch, { kind: "cpu" });
|
|
61
|
+
const degraded = hardware.accelerator.kind === "cpu" ? void 0 : "Initial local media support uses CPU execution even when an accelerator is detected.";
|
|
62
|
+
const cached = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const recipe of LLAMA_CPP_MEDIA_RECIPES) for (const artifact of [recipe.model, recipe.projector]) {
|
|
64
|
+
const file = await ensureLlamaCppModel({
|
|
65
|
+
source: artifact.source,
|
|
66
|
+
cacheDir,
|
|
67
|
+
download: false,
|
|
68
|
+
signal: ctx.signal
|
|
69
|
+
}).catch(() => {
|
|
70
|
+
ctx.signal?.throwIfAborted();
|
|
71
|
+
});
|
|
72
|
+
if (file) cached.set(artifact.expectedSha256, file);
|
|
73
|
+
}
|
|
74
|
+
const runtimeCached = await fs.stat(resolveManagedLlamaServerPaths(asset).command).then((stat) => stat.isFile()).catch(() => false);
|
|
75
|
+
const recommendation = recommendLlamaCppMedia(hardware, {
|
|
76
|
+
artifactSha256: new Set(cached.keys()),
|
|
77
|
+
runtime: runtimeCached
|
|
78
|
+
});
|
|
79
|
+
if (recommendation.kind === "unavailable") {
|
|
80
|
+
await ctx.prompter.note(recommendation.reason, "Local media unavailable");
|
|
81
|
+
return { profiles: [] };
|
|
82
|
+
}
|
|
83
|
+
const recipes = [recommendation.ocr, recommendation.vision];
|
|
84
|
+
assertMediaPresetLimits(existing?.localService?.args ?? [], recipes);
|
|
85
|
+
const artifacts = [...new Map(recipes.flatMap((recipe) => [recipe.model, recipe.projector]).map((artifact) => [artifact.expectedSha256, artifact])).values()];
|
|
86
|
+
const runtimeBytes = asset.sizeBytes ?? 0;
|
|
87
|
+
const downloads = artifacts.filter((artifact) => !cached.has(artifact.expectedSha256));
|
|
88
|
+
const consent = await ctx.prompter.confirm({
|
|
89
|
+
initialValue: false,
|
|
90
|
+
message: [
|
|
91
|
+
`Gateway host: ${os.hostname()} (${hardware.platform}/${hardware.arch})`,
|
|
92
|
+
`Backend: ${asset.backend.toUpperCase()}`,
|
|
93
|
+
degraded ?? (hardware.accelerator.kind === "cpu" ? hardware.accelerator.reason : void 0),
|
|
94
|
+
`RAM: ${formatLlamaCppMemory(hardware.totalMemoryBytes)} total, ${formatLlamaCppMemory(hardware.availableMemoryBytes)} available.`,
|
|
95
|
+
`Disk: ${formatLlamaCppMemory(hardware.availableDiskBytes ?? 0)} model volume; ${formatLlamaCppMemory(hardware.availableRuntimeDiskBytes ?? 0)} runtime volume (${hardware.sharedDisk ? "shared budget" : "separate budgets"}).`,
|
|
96
|
+
recommendation.reason,
|
|
97
|
+
...recipes.flatMap((recipe) => [`${recipe.capability.toUpperCase()}: ${recipe.name}`, ...recipe.limitations]),
|
|
98
|
+
...artifacts.map((artifact) => `${artifact.filename}: ${formatLlamaCppMemory(artifact.expectedSize)}${cached.has(artifact.expectedSha256) ? " (verified cache)" : " download"}`),
|
|
99
|
+
`llama.cpp runtime: ${runtimeBytes.toLocaleString()} bytes${runtimeCached ? " (cached; version will be verified)" : " download"}.`,
|
|
100
|
+
`Total download: ${formatLlamaCppMemory(downloads.reduce((total, artifact) => total + artifact.expectedSize, 0) + (runtimeCached ? 0 : runtimeBytes))}; required free disk including runtime staging: ${formatLlamaCppMemory(recommendation.requiredDiskBytes)}.`,
|
|
101
|
+
"Load one model at a time; switching between chat, embeddings, OCR and vision may add latency. Existing chat defaults, inventory and embeddings are preserved.",
|
|
102
|
+
"Replace image-understanding routes and the image tool default with local vision, without remote fallbacks. OCR is selected explicitly with local_image task=ocr; ambiguous tasks use vision.",
|
|
103
|
+
"These image inference routes stay local. Original images remain available; an existing cloud chat model can still receive them under its normal native-vision policy.",
|
|
104
|
+
"Download, verify real OCR and spatial image understanding, then activate?"
|
|
105
|
+
].filter(Boolean).join("\n")
|
|
106
|
+
});
|
|
107
|
+
ctx.signal?.throwIfAborted();
|
|
108
|
+
if (!consent) return { profiles: [] };
|
|
109
|
+
const progress = ctx.prompter.progress("Preparing local OCR and vision…");
|
|
110
|
+
let presetPath;
|
|
111
|
+
let verificationDir;
|
|
112
|
+
let verified = false;
|
|
113
|
+
try {
|
|
114
|
+
ctx.assertCurrent?.();
|
|
115
|
+
await ensureLlamaServerInstalled({
|
|
116
|
+
asset,
|
|
117
|
+
signal: ctx.signal
|
|
118
|
+
});
|
|
119
|
+
const device = "none";
|
|
120
|
+
for (const artifact of artifacts) {
|
|
121
|
+
ctx.assertCurrent?.();
|
|
122
|
+
const file = await ensureLlamaCppModel({
|
|
123
|
+
source: artifact.source,
|
|
124
|
+
cacheDir,
|
|
125
|
+
download: true,
|
|
126
|
+
signal: ctx.signal,
|
|
127
|
+
onProgress: (status) => progress.update(`${artifact.filename}: ${Math.floor(100 * status.downloadedSize / Math.max(1, status.totalSize))}%`)
|
|
128
|
+
});
|
|
129
|
+
cached.set(artifact.expectedSha256, file);
|
|
130
|
+
}
|
|
131
|
+
const mediaModels = recipes.map((recipe) => {
|
|
132
|
+
const modelPath = cached.get(recipe.model.expectedSha256);
|
|
133
|
+
const projectorPath = cached.get(recipe.projector.expectedSha256);
|
|
134
|
+
if (!modelPath || !projectorPath) throw new Error(`Missing verified model or projector for ${recipe.name}. Retry setup.`);
|
|
135
|
+
return {
|
|
136
|
+
id: recipe.id,
|
|
137
|
+
path: modelPath,
|
|
138
|
+
projectorPath,
|
|
139
|
+
contextSize: recipe.contextSize,
|
|
140
|
+
maxTokens: recipe.maxTokens,
|
|
141
|
+
imageMaxTokens: recipe.imageMaxTokens,
|
|
142
|
+
device
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
const managed = await prepareManagedLlamaServer({
|
|
146
|
+
chatModel: { mode: "preserve" },
|
|
147
|
+
mediaModels,
|
|
148
|
+
configuredChatModelIds: [...existing?.models.map((model) => model.id) ?? [], ...recipes.map((recipe) => recipe.id)],
|
|
149
|
+
modelsMax: 1,
|
|
150
|
+
localService: existing?.localService,
|
|
151
|
+
asset,
|
|
152
|
+
isolated: true,
|
|
153
|
+
signal: ctx.signal
|
|
154
|
+
});
|
|
155
|
+
presetPath = resolveLlamaCppPresetPath(managed);
|
|
156
|
+
const selectedIds = new Set(recipes.map((recipe) => recipe.id));
|
|
157
|
+
const provider = buildLlamaCppProviderConfig({
|
|
158
|
+
existing,
|
|
159
|
+
managed,
|
|
160
|
+
modelInventory: [...(existing?.models ?? []).filter((model) => !selectedIds.has(model.id)), ...recipes.map((recipe) => modelDefinition(recipe, device, managed.baseUrl))]
|
|
161
|
+
});
|
|
162
|
+
provider.params = {
|
|
163
|
+
...existing?.params,
|
|
164
|
+
mediaModels: {
|
|
165
|
+
ocr: recommendation.ocr.id,
|
|
166
|
+
vision: recommendation.vision.id
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
const configPatch = {
|
|
170
|
+
models: {
|
|
171
|
+
...ctx.config.models,
|
|
172
|
+
providers: {
|
|
173
|
+
...ctx.config.models?.providers,
|
|
174
|
+
[LLAMA_CPP_PROVIDER_ID]: provider
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
agents: {
|
|
178
|
+
...ctx.config.agents,
|
|
179
|
+
defaults: {
|
|
180
|
+
...ctx.config.agents?.defaults,
|
|
181
|
+
imageModel: {
|
|
182
|
+
primary: `${LLAMA_CPP_PROVIDER_ID}/${recommendation.vision.id}`,
|
|
183
|
+
fallbacks: []
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
tools: {
|
|
188
|
+
...ctx.config.tools,
|
|
189
|
+
media: {
|
|
190
|
+
...previousMedia,
|
|
191
|
+
models: [...(previousMedia?.models ?? []).flatMap((entry) => {
|
|
192
|
+
const capabilities = entry.capabilities?.filter((capability) => capability !== "image");
|
|
193
|
+
return capabilities?.length ? [{
|
|
194
|
+
...entry,
|
|
195
|
+
capabilities
|
|
196
|
+
}] : [];
|
|
197
|
+
}), {
|
|
198
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
199
|
+
model: recommendation.vision.id,
|
|
200
|
+
capabilities: ["image"]
|
|
201
|
+
}],
|
|
202
|
+
image: {
|
|
203
|
+
...previousMedia?.image,
|
|
204
|
+
enabled: true,
|
|
205
|
+
maxBytes: previousMedia?.image?.maxBytes ?? 10485760,
|
|
206
|
+
maxChars: previousMedia?.image?.maxChars ?? 12e3,
|
|
207
|
+
timeoutSeconds: previousMedia?.image?.timeoutSeconds ?? 600
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
await fs.mkdir(resolveLlamaCppDataDir(), { recursive: true });
|
|
213
|
+
verificationDir = await fs.mkdtemp(path.join(resolveLlamaCppDataDir(), ".media-verify-"));
|
|
214
|
+
const candidateProvider = {
|
|
215
|
+
...provider,
|
|
216
|
+
localService: {
|
|
217
|
+
...provider.localService,
|
|
218
|
+
command: managed.command,
|
|
219
|
+
idleStopMs: 1
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
const candidateConfig = {
|
|
223
|
+
...ctx.config,
|
|
224
|
+
...configPatch,
|
|
225
|
+
models: {
|
|
226
|
+
...configPatch.models,
|
|
227
|
+
providers: {
|
|
228
|
+
...configPatch.models?.providers,
|
|
229
|
+
[LLAMA_CPP_PROVIDER_ID]: candidateProvider
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
for (const task of ["ocr", "vision"]) {
|
|
234
|
+
ctx.assertCurrent?.();
|
|
235
|
+
ctx.signal?.throwIfAborted();
|
|
236
|
+
progress.update(`Verifying real ${task.toUpperCase()} inference…`);
|
|
237
|
+
const response = await mediaProvider.describeImage({
|
|
238
|
+
cfg: candidateConfig,
|
|
239
|
+
agentDir: verificationDir,
|
|
240
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
241
|
+
model: recommendation[task].id,
|
|
242
|
+
buffer: task === "ocr" ? LLAMA_CPP_OCR_FIXTURE : LLAMA_CPP_VISION_FIXTURE,
|
|
243
|
+
fileName: `${task}-verification.png`,
|
|
244
|
+
mime: "image/png",
|
|
245
|
+
prompt: task === "ocr" ? "Transcribe the visible text." : "Which shape is above the blue circle? Answer with its color and shape.",
|
|
246
|
+
maxTokens: 64,
|
|
247
|
+
timeoutMs: Math.min(LLAMA_CPP_MEDIA_TIMEOUT_MS, (previousMedia?.image?.timeoutSeconds ?? 600) * 1e3),
|
|
248
|
+
signal: ctx.signal
|
|
249
|
+
});
|
|
250
|
+
ctx.signal?.throwIfAborted();
|
|
251
|
+
if (!(task === "ocr" ? /\bOPENCLAW\s+OCR\s+4827\b/iu.test(response.text) : /\bred\s+square\b/iu.test(response.text) && !/\b(?:not|no|below)\b/iu.test(response.text))) throw new Error(`${task.toUpperCase()} inference verification failed for ${recommendation[task].name}. Existing configuration is unchanged. Retry setup or review model limitations.`);
|
|
252
|
+
}
|
|
253
|
+
ctx.assertCurrent?.();
|
|
254
|
+
ctx.signal?.throwIfAborted();
|
|
255
|
+
verified = true;
|
|
256
|
+
progress.stop("Local OCR and vision verified");
|
|
257
|
+
return {
|
|
258
|
+
profiles: [],
|
|
259
|
+
configPatch,
|
|
260
|
+
notes: ["Local OCR and vision passed real image checks. Use local_image task=ocr for transcription or task=vision for visual questions. Existing chat defaults and embeddings are unchanged."]
|
|
261
|
+
};
|
|
262
|
+
} catch (error) {
|
|
263
|
+
progress.stop("Local media setup failed; previous configuration retained");
|
|
264
|
+
throw error;
|
|
265
|
+
} finally {
|
|
266
|
+
if (!verified && presetPath) await fs.rm(presetPath, { force: true });
|
|
267
|
+
if (verificationDir) await fs.rm(verificationDir, {
|
|
268
|
+
recursive: true,
|
|
269
|
+
force: true
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
//#endregion
|
|
274
|
+
export { runLlamaCppMediaSetup };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { _ as LLAMA_CPP_PROVIDER_ID, b as buildLlamaCppProviderConfig, g as LLAMA_CPP_LOCAL_AUTH_MARKER, v as LLAMA_CPP_PROVIDER_LABEL } from "./defaults-CL2lz0cV.mjs";
|
|
2
|
+
import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
|
+
import { CUSTOM_LOCAL_AUTH_MARKER, hasConfiguredSecretInput, normalizeOptionalSecretInput } from "openclaw/plugin-sdk/provider-auth";
|
|
4
|
+
//#region extensions/llama-cpp/src/external-server/auth-policy.ts
|
|
5
|
+
function hasLlamaServerAuthorizationHeader(headers) {
|
|
6
|
+
const record = asOptionalRecord(headers);
|
|
7
|
+
if (!record) return false;
|
|
8
|
+
return Object.entries(record).some(([name, value]) => name.trim().toLowerCase() === "authorization" && hasConfiguredSecretInput(value));
|
|
9
|
+
}
|
|
10
|
+
function shouldUseLlamaServerSyntheticAuth(providerConfig) {
|
|
11
|
+
const apiKey = normalizeOptionalSecretInput(providerConfig?.apiKey)?.trim();
|
|
12
|
+
return !(hasConfiguredSecretInput(providerConfig?.apiKey) && apiKey !== "llama-cpp-local" && apiKey !== CUSTOM_LOCAL_AUTH_MARKER);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region extensions/llama-cpp/src/external-server/defaults.ts
|
|
16
|
+
const LLAMA_SERVER_DEFAULT_ORIGIN = "http://127.0.0.1:8080";
|
|
17
|
+
const LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR = "LLAMA_SERVER_API_KEY";
|
|
18
|
+
const LLAMA_SERVER_DISCOVERY_TIMEOUT_MS = 5e3;
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region extensions/llama-cpp/src/external-server/endpoint.ts
|
|
21
|
+
/** Resolves the server origin and its OpenAI-compatible `/v1` inference base. */
|
|
22
|
+
function resolveLlamaServerEndpoint(configuredBaseUrl) {
|
|
23
|
+
const configured = configuredBaseUrl?.trim() || "http://127.0.0.1:8080";
|
|
24
|
+
const parsed = new URL(/^[a-z][a-z\d+.-]*:\/\//iu.test(configured) ? configured : `http://${configured}`);
|
|
25
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new TypeError(`Unsupported llama-server protocol: ${parsed.protocol}`);
|
|
26
|
+
if (parsed.username || parsed.password) throw new TypeError("llama-server base URL must not contain credentials");
|
|
27
|
+
parsed.pathname = parsed.pathname.replace(/\/+$/u, "").replace(/\/v1$/iu, "") || "/";
|
|
28
|
+
parsed.search = "";
|
|
29
|
+
parsed.hash = "";
|
|
30
|
+
const origin = parsed.toString().replace(/\/$/u, "");
|
|
31
|
+
return {
|
|
32
|
+
origin,
|
|
33
|
+
inferenceBaseUrl: `${origin}/v1`
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/** Canonicalizes persisted provider config for the shared OpenAI transport. */
|
|
37
|
+
function normalizeLlamaServerProviderConfig(provider) {
|
|
38
|
+
const endpoint = resolveLlamaServerEndpoint(provider.baseUrl);
|
|
39
|
+
const request = provider.request ?? {};
|
|
40
|
+
const normalizedRequest = typeof request.allowPrivateNetwork === "boolean" ? request : {
|
|
41
|
+
...request,
|
|
42
|
+
allowPrivateNetwork: true
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
...provider,
|
|
46
|
+
baseUrl: endpoint.inferenceBaseUrl,
|
|
47
|
+
api: "openai-completions",
|
|
48
|
+
request: normalizedRequest
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region extensions/llama-cpp/provider-discovery.ts
|
|
53
|
+
var provider_discovery_default = {
|
|
54
|
+
id: LLAMA_CPP_PROVIDER_ID,
|
|
55
|
+
label: LLAMA_CPP_PROVIDER_LABEL,
|
|
56
|
+
docsPath: "/plugins/llama-cpp",
|
|
57
|
+
envVars: [LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR],
|
|
58
|
+
auth: [],
|
|
59
|
+
catalog: {
|
|
60
|
+
order: "late",
|
|
61
|
+
run: async (ctx) => {
|
|
62
|
+
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
63
|
+
if (configured?.localService) return { provider: buildLlamaCppProviderConfig({
|
|
64
|
+
existing: configured,
|
|
65
|
+
modelInventory: configured.models
|
|
66
|
+
}) };
|
|
67
|
+
const { discoverLlamaServerProvider } = await import("./provider-w5p9JK8O.mjs");
|
|
68
|
+
return await discoverLlamaServerProvider(ctx);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
staticCatalog: {
|
|
72
|
+
order: "late",
|
|
73
|
+
run: async () => ({ provider: buildLlamaCppProviderConfig() })
|
|
74
|
+
},
|
|
75
|
+
resolveSyntheticAuth: ({ providerConfig }) => providerConfig?.localService || shouldUseLlamaServerSyntheticAuth(providerConfig) ? {
|
|
76
|
+
apiKey: LLAMA_CPP_LOCAL_AUTH_MARKER,
|
|
77
|
+
source: providerConfig?.localService ? "managed local llama.cpp server" : hasLlamaServerAuthorizationHeader(providerConfig?.headers) ? "models.providers.llama-cpp.headers.Authorization" : "models.providers.llama-cpp (synthetic local key)",
|
|
78
|
+
mode: "api-key"
|
|
79
|
+
} : void 0,
|
|
80
|
+
shouldDeferSyntheticProfileAuth: ({ resolvedApiKey }) => resolvedApiKey?.trim() === "llama-cpp-local" || resolvedApiKey?.trim() === CUSTOM_LOCAL_AUTH_MARKER,
|
|
81
|
+
normalizeConfig: ({ providerConfig }) => providerConfig.localService ? providerConfig : normalizeLlamaServerProviderConfig(providerConfig)
|
|
82
|
+
};
|
|
83
|
+
//#endregion
|
|
84
|
+
export { LLAMA_SERVER_DEFAULT_ORIGIN as a, LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR as i, normalizeLlamaServerProviderConfig as n, LLAMA_SERVER_DISCOVERY_TIMEOUT_MS as o, resolveLlamaServerEndpoint as r, hasLlamaServerAuthorizationHeader as s, provider_discovery_default as t };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-CL2lz0cV.mjs";
|
|
2
|
+
import { r as resolveLlamaServerEndpoint, s as hasLlamaServerAuthorizationHeader } from "./provider-discovery-97l8WbMa.mjs";
|
|
3
|
+
import { i as resolveLlamaServerRuntimeApiKey, n as buildLlamaServerProviderConfig, r as resolveLlamaServerProviderHeaders, t as discoverLlamaServer } from "./discovery-VdqP6WcN.mjs";
|
|
4
|
+
import { isNonSecretApiKeyMarker } from "openclaw/plugin-sdk/provider-auth";
|
|
5
|
+
import { LiveModelCatalogHttpError, runLiveProviderCatalog } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
|
6
|
+
//#region extensions/llama-cpp/src/external-server/provider.ts
|
|
7
|
+
/** Discovers external llama-server models for provider runtime resolution. */
|
|
8
|
+
async function discoverLlamaServerProvider(ctx) {
|
|
9
|
+
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
10
|
+
const auth = ctx.resolveProviderApiKey(LLAMA_CPP_PROVIDER_ID);
|
|
11
|
+
const headers = await resolveLlamaServerProviderHeaders({
|
|
12
|
+
config: ctx.config,
|
|
13
|
+
env: ctx.env,
|
|
14
|
+
headers: configured?.headers
|
|
15
|
+
});
|
|
16
|
+
const authApiKey = auth.discoveryApiKey ?? auth.apiKey;
|
|
17
|
+
const apiKey = hasLlamaServerAuthorizationHeader(headers) || authApiKey && isNonSecretApiKeyMarker(authApiKey) ? void 0 : authApiKey;
|
|
18
|
+
return await runLiveProviderCatalog({
|
|
19
|
+
providerId: LLAMA_CPP_PROVIDER_ID,
|
|
20
|
+
profileId: apiKey ? auth.profileId : void 0,
|
|
21
|
+
run: async () => {
|
|
22
|
+
const discovery = await discoverLlamaServer({
|
|
23
|
+
baseUrl: configured?.baseUrl,
|
|
24
|
+
apiKey,
|
|
25
|
+
headers,
|
|
26
|
+
allowPrivateNetwork: configured?.request?.allowPrivateNetwork
|
|
27
|
+
});
|
|
28
|
+
if (discovery.kind !== "success") {
|
|
29
|
+
if (!configured && !apiKey && !headers) return null;
|
|
30
|
+
throw discovery.kind === "http-error" ? new LiveModelCatalogHttpError(LLAMA_CPP_PROVIDER_ID, discovery.status) : discovery.error;
|
|
31
|
+
}
|
|
32
|
+
return { provider: buildLlamaServerProviderConfig({
|
|
33
|
+
configured,
|
|
34
|
+
discoveredModels: discovery.models
|
|
35
|
+
}) };
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async function prepareLlamaServerDynamicModel(ctx) {
|
|
40
|
+
const apiKey = await resolveLlamaServerRuntimeApiKey({
|
|
41
|
+
config: ctx.config,
|
|
42
|
+
agentDir: ctx.agentDir,
|
|
43
|
+
profileId: ctx.authProfileId
|
|
44
|
+
});
|
|
45
|
+
const headers = await resolveLlamaServerProviderHeaders({
|
|
46
|
+
config: ctx.config,
|
|
47
|
+
env: process.env,
|
|
48
|
+
headers: ctx.providerConfig?.headers
|
|
49
|
+
});
|
|
50
|
+
const discovery = await discoverLlamaServer({
|
|
51
|
+
baseUrl: ctx.providerConfig?.baseUrl,
|
|
52
|
+
apiKey: hasLlamaServerAuthorizationHeader(headers) ? void 0 : apiKey,
|
|
53
|
+
headers,
|
|
54
|
+
allowPrivateNetwork: ctx.providerConfig?.request?.allowPrivateNetwork
|
|
55
|
+
});
|
|
56
|
+
const model = discovery.kind === "success" ? discovery.models.find((entry) => entry.config.id === ctx.modelId) : void 0;
|
|
57
|
+
if (!model) return;
|
|
58
|
+
return {
|
|
59
|
+
...model.config,
|
|
60
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
61
|
+
api: ctx.providerConfig?.api ?? "openai-completions",
|
|
62
|
+
baseUrl: resolveLlamaServerEndpoint(ctx.providerConfig?.baseUrl).inferenceBaseUrl,
|
|
63
|
+
input: model.config.input.filter((entry) => entry === "text" || entry === "image")
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { discoverLlamaServerProvider, prepareLlamaServerDynamicModel };
|