@openclaw/llama-cpp-provider 2026.10.5-beta.3 → 2026.10.5
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/{managed-provider-config-D0abOkC_.mjs → defaults-ATX0SyoG.mjs} +1 -9
- package/dist/.setup/managed-provider-config-Nd32gsuH.mjs +10 -0
- package/dist/.setup/provider-OCMqlJ0I.mjs +230 -0
- package/dist/.setup/provider-discovery-CEcEBzKt.mjs +84 -0
- package/dist/index.js +20 -283
- package/dist/provider-discovery.js +1 -0
- package/dist/provider-policy-api.js +1 -1
- package/openclaw.plugin.json +22 -7
- package/package.json +4 -4
|
@@ -113,12 +113,4 @@ function buildLlamaCppProviderConfig(params = {}) {
|
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
//#endregion
|
|
116
|
-
|
|
117
|
-
const MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE = "Local embeddings need the managed llama.cpp server config (llama-server). The in-process node-llama-cpp runtime was removed; semantic memory recall is degraded until setup. Run `openclaw configure`, choose llama.cpp once, then retry `openclaw memory status --deep`.";
|
|
118
|
-
function resolveManagedLlamaCppProviderConfig(config) {
|
|
119
|
-
const provider = config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
120
|
-
if (!provider?.localService || !provider.baseUrl) throw new Error(MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE);
|
|
121
|
-
return provider;
|
|
122
|
-
}
|
|
123
|
-
//#endregion
|
|
124
|
-
export { resolveCachedLlamaCppModelPath as C, resolveLlamaCppEmbeddingModel as D, resolveLlamaCppDataDir as E, resolveLlamaCppModelCacheDir as O, buildLlamaCppProviderConfig as S, resolveLegacyLlamaCppModelCacheDir as T, LLAMA_CPP_DEFAULT_PORT as _, DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE as a, LLAMA_CPP_PROVIDER_LABEL as b, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION as c, DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE as d, DEFAULT_LLAMA_CPP_MODEL_ID as f, DEFAULT_LLAMA_CPP_MODEL_URI as g, DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES as h, DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE as i, resolveLlamaCppModelSource as k, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256 as l, DEFAULT_LLAMA_CPP_MODEL_SHA256 as m, resolveManagedLlamaCppProviderConfig as n, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL as o, DEFAULT_LLAMA_CPP_MODEL_REVISION as p, DEFAULT_LLAMA_CPP_CONTEXT_SIZE as r, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID as s, MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE as t, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES as u, LLAMA_CPP_LOCAL_AUTH_MARKER as v, resolveHomePath as w, buildLlamaCppModel as x, LLAMA_CPP_PROVIDER_ID as y };
|
|
116
|
+
export { resolveLegacyLlamaCppModelCacheDir as C, resolveLlamaCppModelSource as D, resolveLlamaCppModelCacheDir as E, resolveHomePath as S, resolveLlamaCppEmbeddingModel as T, LLAMA_CPP_PROVIDER_ID as _, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID as a, buildLlamaCppProviderConfig as b, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES as c, DEFAULT_LLAMA_CPP_MODEL_REVISION as d, DEFAULT_LLAMA_CPP_MODEL_SHA256 as f, LLAMA_CPP_LOCAL_AUTH_MARKER as g, LLAMA_CPP_DEFAULT_PORT as h, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL as i, DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE as l, DEFAULT_LLAMA_CPP_MODEL_URI as m, DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE as n, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION as o, DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES as p, DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE as r, DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256 as s, DEFAULT_LLAMA_CPP_CONTEXT_SIZE as t, DEFAULT_LLAMA_CPP_MODEL_ID as u, LLAMA_CPP_PROVIDER_LABEL as v, resolveLlamaCppDataDir as w, resolveCachedLlamaCppModelPath as x, buildLlamaCppModel as y };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-ATX0SyoG.mjs";
|
|
2
|
+
//#region extensions/llama-cpp/src/managed-provider-config.ts
|
|
3
|
+
const MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE = "Local embeddings need the managed llama.cpp server config (llama-server). The in-process node-llama-cpp runtime was removed; semantic memory recall is degraded until setup. Run `openclaw configure`, choose llama.cpp once, then retry `openclaw memory status --deep`.";
|
|
4
|
+
function resolveManagedLlamaCppProviderConfig(config) {
|
|
5
|
+
const provider = config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
6
|
+
if (!provider?.localService || !provider.baseUrl) throw new Error(MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE);
|
|
7
|
+
return provider;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { resolveManagedLlamaCppProviderConfig as n, MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE as t };
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-ATX0SyoG.mjs";
|
|
2
|
+
import { n as normalizeLlamaServerProviderConfig, o as LLAMA_SERVER_DISCOVERY_TIMEOUT_MS, r as resolveLlamaServerEndpoint, s as hasLlamaServerAuthorizationHeader } from "./provider-discovery-CEcEBzKt.mjs";
|
|
3
|
+
import { asOptionalRecord, asPositiveSafeInteger } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
+
import { isNonSecretApiKeyMarker } from "openclaw/plugin-sdk/provider-auth";
|
|
5
|
+
import { LiveModelCatalogHttpError, runLiveProviderCatalog } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
|
|
6
|
+
import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
7
|
+
import { resolveConfiguredSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime";
|
|
8
|
+
import { SELF_HOSTED_DEFAULT_CONTEXT_WINDOW, SELF_HOSTED_DEFAULT_COST, SELF_HOSTED_DEFAULT_MAX_TOKENS, discoverOpenAICompatibleLocalModels } from "openclaw/plugin-sdk/provider-setup";
|
|
9
|
+
//#region \0rolldown/runtime.js
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __exportAll = (all, no_symbols) => {
|
|
12
|
+
let target = {};
|
|
13
|
+
for (var name in all) __defProp(target, name, {
|
|
14
|
+
get: all[name],
|
|
15
|
+
enumerable: true
|
|
16
|
+
});
|
|
17
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region extensions/llama-cpp/src/external-server/auth.ts
|
|
22
|
+
async function resolveLlamaServerProviderHeaders(params) {
|
|
23
|
+
const headers = asOptionalRecord(params.headers);
|
|
24
|
+
if (!headers) return;
|
|
25
|
+
const resolved = {};
|
|
26
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
27
|
+
if (!params.config) {
|
|
28
|
+
if (typeof value === "string" && value.trim()) resolved[name] = value.trim();
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const path = `models.providers.${LLAMA_CPP_PROVIDER_ID}.headers[${JSON.stringify(name)}]`;
|
|
32
|
+
const header = await resolveConfiguredSecretInputString({
|
|
33
|
+
config: params.config,
|
|
34
|
+
env: params.env ?? process.env,
|
|
35
|
+
value,
|
|
36
|
+
path,
|
|
37
|
+
unresolvedReasonStyle: "detailed"
|
|
38
|
+
});
|
|
39
|
+
if (header.unresolvedRefReason) throw new Error(`${path}: ${header.unresolvedRefReason}`);
|
|
40
|
+
if (header.value) resolved[name] = header.value;
|
|
41
|
+
}
|
|
42
|
+
return Object.keys(resolved).length > 0 ? resolved : void 0;
|
|
43
|
+
}
|
|
44
|
+
async function resolveLlamaServerRuntimeApiKey(params) {
|
|
45
|
+
const apiKey = (await resolveApiKeyForProvider({
|
|
46
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
47
|
+
cfg: params.config,
|
|
48
|
+
agentDir: params.agentDir,
|
|
49
|
+
profileId: params.profileId,
|
|
50
|
+
lockedProfile: params.profileId !== void 0
|
|
51
|
+
})).apiKey?.trim();
|
|
52
|
+
return apiKey && !isNonSecretApiKeyMarker(apiKey) ? apiKey : void 0;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region extensions/llama-cpp/src/external-server/models.ts
|
|
56
|
+
function normalizeStatus(value) {
|
|
57
|
+
switch (value) {
|
|
58
|
+
case "unloaded":
|
|
59
|
+
case "loading":
|
|
60
|
+
case "loaded":
|
|
61
|
+
case "sleeping":
|
|
62
|
+
case "downloading": return value;
|
|
63
|
+
default: return "unknown";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function resolveMaxTokens(props, contextWindow) {
|
|
67
|
+
const params = props?.default_generation_settings?.params;
|
|
68
|
+
const advertised = asPositiveSafeInteger(params?.max_tokens) ?? asPositiveSafeInteger(params?.n_predict);
|
|
69
|
+
return Math.min(advertised ?? SELF_HOSTED_DEFAULT_MAX_TOKENS, contextWindow);
|
|
70
|
+
}
|
|
71
|
+
function resolveInput(row, props) {
|
|
72
|
+
const advertised = row.architecture?.input_modalities;
|
|
73
|
+
return Array.isArray(advertised) && advertised.includes("image") || props?.modalities?.vision === true ? ["text", "image"] : ["text"];
|
|
74
|
+
}
|
|
75
|
+
function buildCompat(props, useRuntimeDefaults) {
|
|
76
|
+
const caps = props?.chat_template_caps;
|
|
77
|
+
return {
|
|
78
|
+
supportsStore: false,
|
|
79
|
+
supportsDeveloperRole: false,
|
|
80
|
+
supportsReasoningEffort: caps?.supports_reasoning_effort === true,
|
|
81
|
+
supportsTemperature: true,
|
|
82
|
+
supportsUsageInStreaming: true,
|
|
83
|
+
...typeof caps?.supports_tool_calls === "boolean" || useRuntimeDefaults ? { supportsTools: caps?.supports_tool_calls === true } : {},
|
|
84
|
+
supportsStrictMode: false,
|
|
85
|
+
supportsJsonSchemaResponseFormat: true,
|
|
86
|
+
requiresStringContent: caps?.supports_typed_content !== true,
|
|
87
|
+
maxTokensField: "max_tokens"
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Maps one llama-server model row plus optional runtime properties into OpenClaw config. */
|
|
91
|
+
function mapLlamaServerModel(row, props, useRuntimeDefaults = true) {
|
|
92
|
+
const id = typeof row.id === "string" ? row.id.trim() : "";
|
|
93
|
+
if (!id || row.object !== void 0 && row.object !== "model") return null;
|
|
94
|
+
const contextWindow = asPositiveSafeInteger(props?.default_generation_settings?.n_ctx) ?? asPositiveSafeInteger(props?.n_ctx) ?? (useRuntimeDefaults ? SELF_HOSTED_DEFAULT_CONTEXT_WINDOW : void 0);
|
|
95
|
+
const compat = buildCompat(props, useRuntimeDefaults);
|
|
96
|
+
return {
|
|
97
|
+
config: {
|
|
98
|
+
id,
|
|
99
|
+
name: id,
|
|
100
|
+
reasoning: compat.supportsReasoningEffort === true,
|
|
101
|
+
input: resolveInput(row, props),
|
|
102
|
+
cost: { ...SELF_HOSTED_DEFAULT_COST },
|
|
103
|
+
contextWindow,
|
|
104
|
+
contextTokens: contextWindow,
|
|
105
|
+
maxTokens: resolveMaxTokens(props, contextWindow ?? SELF_HOSTED_DEFAULT_CONTEXT_WINDOW),
|
|
106
|
+
compat
|
|
107
|
+
},
|
|
108
|
+
status: normalizeStatus(row.status?.value),
|
|
109
|
+
failed: row.status?.failed === true
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
function buildLlamaServerProviderConfig(params) {
|
|
113
|
+
const baseUrl = resolveLlamaServerEndpoint(params.configured?.baseUrl).inferenceBaseUrl;
|
|
114
|
+
const discoveredById = new Map(params.discoveredModels.map(({ config }) => [config.id, config]));
|
|
115
|
+
const models = (params.configured?.models ?? []).map((configured) => {
|
|
116
|
+
const discovered = discoveredById.get(configured.id);
|
|
117
|
+
discoveredById.delete(configured.id);
|
|
118
|
+
const matchesRoute = (!configured.api || configured.api === "openai-completions") && resolveLlamaServerEndpoint(configured.baseUrl?.trim() || baseUrl).inferenceBaseUrl === baseUrl;
|
|
119
|
+
return discovered && matchesRoute ? Object.assign({}, discovered, configured, {
|
|
120
|
+
contextWindow: configured.contextWindow ?? discovered.contextWindow,
|
|
121
|
+
contextTokens: configured.contextTokens ?? discovered.contextTokens,
|
|
122
|
+
compat: {
|
|
123
|
+
...discovered.compat,
|
|
124
|
+
...configured.compat
|
|
125
|
+
}
|
|
126
|
+
}) : configured;
|
|
127
|
+
});
|
|
128
|
+
models.push(...discoveredById.values());
|
|
129
|
+
return normalizeLlamaServerProviderConfig({
|
|
130
|
+
...params.configured,
|
|
131
|
+
baseUrl,
|
|
132
|
+
models
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region extensions/llama-cpp/src/external-server/discovery.ts
|
|
137
|
+
/** Discovers llama-server models without loading, waking, or unloading them. */
|
|
138
|
+
async function discoverLlamaServer(params) {
|
|
139
|
+
const endpoint = resolveLlamaServerEndpoint(params.baseUrl);
|
|
140
|
+
const result = await discoverOpenAICompatibleLocalModels({
|
|
141
|
+
baseUrl: endpoint.inferenceBaseUrl,
|
|
142
|
+
serverBaseUrl: endpoint.origin,
|
|
143
|
+
apiKey: params.apiKey,
|
|
144
|
+
headers: params.headers,
|
|
145
|
+
label: "llama-server",
|
|
146
|
+
healthPath: "/health",
|
|
147
|
+
modelsPathOrder: "server-first",
|
|
148
|
+
routerModelProps: true,
|
|
149
|
+
timeoutMs: LLAMA_SERVER_DISCOVERY_TIMEOUT_MS,
|
|
150
|
+
signal: params.signal,
|
|
151
|
+
rawResult: true
|
|
152
|
+
});
|
|
153
|
+
if (result.kind !== "success") return {
|
|
154
|
+
...result,
|
|
155
|
+
endpoint
|
|
156
|
+
};
|
|
157
|
+
return {
|
|
158
|
+
kind: "success",
|
|
159
|
+
endpoint,
|
|
160
|
+
models: result.rows.flatMap(({ model, props }) => {
|
|
161
|
+
const mapped = mapLlamaServerModel(model, props, params.useRuntimeDefaults);
|
|
162
|
+
return mapped ? [mapped] : [];
|
|
163
|
+
})
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region extensions/llama-cpp/src/external-server/provider.ts
|
|
168
|
+
var provider_exports = /* @__PURE__ */ __exportAll({
|
|
169
|
+
discoverLlamaServerProvider: () => discoverLlamaServerProvider,
|
|
170
|
+
prepareLlamaServerDynamicModel: () => prepareLlamaServerDynamicModel
|
|
171
|
+
});
|
|
172
|
+
/** Discovers external llama-server models for provider runtime resolution. */
|
|
173
|
+
async function discoverLlamaServerProvider(ctx) {
|
|
174
|
+
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
175
|
+
const auth = ctx.resolveProviderApiKey(LLAMA_CPP_PROVIDER_ID);
|
|
176
|
+
const headers = await resolveLlamaServerProviderHeaders({
|
|
177
|
+
config: ctx.config,
|
|
178
|
+
env: ctx.env,
|
|
179
|
+
headers: configured?.headers
|
|
180
|
+
});
|
|
181
|
+
const authApiKey = auth.discoveryApiKey ?? auth.apiKey;
|
|
182
|
+
const apiKey = hasLlamaServerAuthorizationHeader(headers) || authApiKey && isNonSecretApiKeyMarker(authApiKey) ? void 0 : authApiKey;
|
|
183
|
+
return await runLiveProviderCatalog({
|
|
184
|
+
providerId: LLAMA_CPP_PROVIDER_ID,
|
|
185
|
+
profileId: apiKey ? auth.profileId : void 0,
|
|
186
|
+
run: async () => {
|
|
187
|
+
const discovery = await discoverLlamaServer({
|
|
188
|
+
baseUrl: configured?.baseUrl,
|
|
189
|
+
apiKey,
|
|
190
|
+
headers
|
|
191
|
+
});
|
|
192
|
+
if (discovery.kind !== "success") {
|
|
193
|
+
if (!configured && !apiKey && !headers) return null;
|
|
194
|
+
throw discovery.kind === "http-error" ? new LiveModelCatalogHttpError(LLAMA_CPP_PROVIDER_ID, discovery.status) : discovery.error;
|
|
195
|
+
}
|
|
196
|
+
return { provider: buildLlamaServerProviderConfig({
|
|
197
|
+
configured,
|
|
198
|
+
discoveredModels: discovery.models
|
|
199
|
+
}) };
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
async function prepareLlamaServerDynamicModel(ctx) {
|
|
204
|
+
const apiKey = await resolveLlamaServerRuntimeApiKey({
|
|
205
|
+
config: ctx.config,
|
|
206
|
+
agentDir: ctx.agentDir,
|
|
207
|
+
profileId: ctx.authProfileId
|
|
208
|
+
});
|
|
209
|
+
const headers = await resolveLlamaServerProviderHeaders({
|
|
210
|
+
config: ctx.config,
|
|
211
|
+
env: process.env,
|
|
212
|
+
headers: ctx.providerConfig?.headers
|
|
213
|
+
});
|
|
214
|
+
const discovery = await discoverLlamaServer({
|
|
215
|
+
baseUrl: ctx.providerConfig?.baseUrl,
|
|
216
|
+
apiKey: hasLlamaServerAuthorizationHeader(headers) ? void 0 : apiKey,
|
|
217
|
+
headers
|
|
218
|
+
});
|
|
219
|
+
const model = discovery.kind === "success" ? discovery.models.find((entry) => entry.config.id === ctx.modelId) : void 0;
|
|
220
|
+
if (!model) return;
|
|
221
|
+
return {
|
|
222
|
+
...model.config,
|
|
223
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
224
|
+
api: ctx.providerConfig?.api ?? "openai-completions",
|
|
225
|
+
baseUrl: resolveLlamaServerEndpoint(ctx.providerConfig?.baseUrl).inferenceBaseUrl,
|
|
226
|
+
input: model.config.input.filter((entry) => entry === "text" || entry === "image")
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
export { resolveLlamaServerProviderHeaders as a, buildLlamaServerProviderConfig as i, provider_exports as n, resolveLlamaServerRuntimeApiKey as o, discoverLlamaServer as r, prepareLlamaServerDynamicModel as t };
|
|
@@ -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-ATX0SyoG.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-OCMqlJ0I.mjs").then((n) => n.n);
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as resolveLlamaServerProviderHeaders, i as buildLlamaServerProviderConfig, o as resolveLlamaServerRuntimeApiKey, r as discoverLlamaServer, t as prepareLlamaServerDynamicModel } from "./.setup/provider-OCMqlJ0I.mjs";
|
|
2
|
+
import { C as resolveLegacyLlamaCppModelCacheDir, D as resolveLlamaCppModelSource, E as resolveLlamaCppModelCacheDir, S as resolveHomePath, T as resolveLlamaCppEmbeddingModel, _ as LLAMA_CPP_PROVIDER_ID, a as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID, b as buildLlamaCppProviderConfig, c as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SIZE_BYTES, d as DEFAULT_LLAMA_CPP_MODEL_REVISION, f as DEFAULT_LLAMA_CPP_MODEL_SHA256, h as LLAMA_CPP_DEFAULT_PORT, i as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL, l as DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE, m as DEFAULT_LLAMA_CPP_MODEL_URI, n as DEFAULT_LLAMA_CPP_EMBEDDING_CACHE_FILE, o as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_REVISION, p as DEFAULT_LLAMA_CPP_MODEL_SIZE_BYTES, r as DEFAULT_LLAMA_CPP_EMBEDDING_CONTEXT_SIZE, s as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_SHA256, u as DEFAULT_LLAMA_CPP_MODEL_ID, v as LLAMA_CPP_PROVIDER_LABEL, w as resolveLlamaCppDataDir, x as resolveCachedLlamaCppModelPath, y as buildLlamaCppModel } from "./.setup/defaults-ATX0SyoG.mjs";
|
|
3
|
+
import { n as resolveManagedLlamaCppProviderConfig } from "./.setup/managed-provider-config-Nd32gsuH.mjs";
|
|
4
|
+
import { a as LLAMA_SERVER_DEFAULT_ORIGIN, i as LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR, r as resolveLlamaServerEndpoint, s as hasLlamaServerAuthorizationHeader, t as provider_discovery_default } from "./.setup/provider-discovery-CEcEBzKt.mjs";
|
|
2
5
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
6
|
import path from "node:path";
|
|
4
7
|
import { getEmbeddingProvider } from "openclaw/plugin-sdk/embedding-providers";
|
|
5
8
|
import os from "node:os";
|
|
6
|
-
import { asOptionalRecord,
|
|
9
|
+
import { asOptionalRecord, isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
10
|
import { createHash, randomUUID } from "node:crypto";
|
|
8
11
|
import fs from "node:fs/promises";
|
|
9
12
|
import net from "node:net";
|
|
@@ -18,12 +21,10 @@ import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
|
|
|
18
21
|
import { toErrorObject } from "openclaw/plugin-sdk/error-runtime";
|
|
19
22
|
import { ARCHIVE_LIMIT_ERROR_CODE, ArchiveLimitError, extractArchive } from "openclaw/plugin-sdk/archive";
|
|
20
23
|
import { createSubsystemLogger } from "openclaw/plugin-sdk/logging-core";
|
|
21
|
-
import { CUSTOM_LOCAL_AUTH_MARKER, applyAuthProfileConfig, buildApiKeyCredential, ensureApiKeyFromEnvOrPrompt, hasConfiguredSecretInput, isNonSecretApiKeyMarker, normalizeOptionalSecretInput } from "openclaw/plugin-sdk/provider-auth";
|
|
22
24
|
import { buildProviderToolCompatFamilyHooks } from "openclaw/plugin-sdk/provider-tools";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { SELF_HOSTED_DEFAULT_CONTEXT_WINDOW, SELF_HOSTED_DEFAULT_COST, SELF_HOSTED_DEFAULT_MAX_TOKENS, applyProviderDefaultModel, discoverOpenAICompatibleLocalModels } from "openclaw/plugin-sdk/provider-setup";
|
|
25
|
+
import { applyAuthProfileConfig, buildApiKeyCredential, ensureApiKeyFromEnvOrPrompt, normalizeOptionalSecretInput } from "openclaw/plugin-sdk/provider-auth";
|
|
26
|
+
import { removeAuthProfileConfig, removeProviderAuthProfilesWithLock } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
27
|
+
import { applyProviderDefaultModel } from "openclaw/plugin-sdk/provider-setup";
|
|
27
28
|
import { upsertAuthProfileWithLockOrThrow } from "openclaw/plugin-sdk/provider-auth-api-key";
|
|
28
29
|
import { selectPreferredLocalModelId } from "openclaw/plugin-sdk/provider-model-shared";
|
|
29
30
|
import { streamSimple } from "openclaw/plugin-sdk/llm";
|
|
@@ -1762,251 +1763,6 @@ const llamaCppEmbeddingProviderAdapter = {
|
|
|
1762
1763
|
}
|
|
1763
1764
|
};
|
|
1764
1765
|
//#endregion
|
|
1765
|
-
//#region extensions/llama-cpp/src/external-server/auth.ts
|
|
1766
|
-
function hasLlamaServerAuthorizationHeader(headers) {
|
|
1767
|
-
const record = asOptionalRecord(headers);
|
|
1768
|
-
if (!record) return false;
|
|
1769
|
-
return Object.entries(record).some(([name, value]) => name.trim().toLowerCase() === "authorization" && hasConfiguredSecretInput(value));
|
|
1770
|
-
}
|
|
1771
|
-
function shouldUseLlamaServerSyntheticAuth(providerConfig) {
|
|
1772
|
-
const apiKey = normalizeOptionalSecretInput(providerConfig?.apiKey)?.trim();
|
|
1773
|
-
return !(hasConfiguredSecretInput(providerConfig?.apiKey) && apiKey !== "llama-cpp-local" && apiKey !== CUSTOM_LOCAL_AUTH_MARKER);
|
|
1774
|
-
}
|
|
1775
|
-
async function resolveLlamaServerProviderHeaders(params) {
|
|
1776
|
-
const headers = asOptionalRecord(params.headers);
|
|
1777
|
-
if (!headers) return;
|
|
1778
|
-
const resolved = {};
|
|
1779
|
-
for (const [name, value] of Object.entries(headers)) {
|
|
1780
|
-
if (!params.config) {
|
|
1781
|
-
if (typeof value === "string" && value.trim()) resolved[name] = value.trim();
|
|
1782
|
-
continue;
|
|
1783
|
-
}
|
|
1784
|
-
const path = `models.providers.${LLAMA_CPP_PROVIDER_ID}.headers[${JSON.stringify(name)}]`;
|
|
1785
|
-
const header = await resolveConfiguredSecretInputString({
|
|
1786
|
-
config: params.config,
|
|
1787
|
-
env: params.env ?? process.env,
|
|
1788
|
-
value,
|
|
1789
|
-
path,
|
|
1790
|
-
unresolvedReasonStyle: "detailed"
|
|
1791
|
-
});
|
|
1792
|
-
if (header.unresolvedRefReason) throw new Error(`${path}: ${header.unresolvedRefReason}`);
|
|
1793
|
-
if (header.value) resolved[name] = header.value;
|
|
1794
|
-
}
|
|
1795
|
-
return Object.keys(resolved).length > 0 ? resolved : void 0;
|
|
1796
|
-
}
|
|
1797
|
-
async function resolveLlamaServerRuntimeApiKey(params) {
|
|
1798
|
-
const apiKey = (await resolveApiKeyForProvider({
|
|
1799
|
-
provider: LLAMA_CPP_PROVIDER_ID,
|
|
1800
|
-
cfg: params.config,
|
|
1801
|
-
agentDir: params.agentDir,
|
|
1802
|
-
profileId: params.profileId,
|
|
1803
|
-
lockedProfile: params.profileId !== void 0
|
|
1804
|
-
})).apiKey?.trim();
|
|
1805
|
-
return apiKey && !isNonSecretApiKeyMarker(apiKey) ? apiKey : void 0;
|
|
1806
|
-
}
|
|
1807
|
-
//#endregion
|
|
1808
|
-
//#region extensions/llama-cpp/src/external-server/defaults.ts
|
|
1809
|
-
const LLAMA_SERVER_DEFAULT_ORIGIN = "http://127.0.0.1:8080";
|
|
1810
|
-
const LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR = "LLAMA_SERVER_API_KEY";
|
|
1811
|
-
const LLAMA_SERVER_DISCOVERY_TIMEOUT_MS = 5e3;
|
|
1812
|
-
//#endregion
|
|
1813
|
-
//#region extensions/llama-cpp/src/external-server/endpoint.ts
|
|
1814
|
-
/** Resolves the server origin and its OpenAI-compatible `/v1` inference base. */
|
|
1815
|
-
function resolveLlamaServerEndpoint(configuredBaseUrl) {
|
|
1816
|
-
const configured = configuredBaseUrl?.trim() || "http://127.0.0.1:8080";
|
|
1817
|
-
const parsed = new URL(/^[a-z][a-z\d+.-]*:\/\//iu.test(configured) ? configured : `http://${configured}`);
|
|
1818
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new TypeError(`Unsupported llama-server protocol: ${parsed.protocol}`);
|
|
1819
|
-
if (parsed.username || parsed.password) throw new TypeError("llama-server base URL must not contain credentials");
|
|
1820
|
-
parsed.pathname = parsed.pathname.replace(/\/+$/u, "").replace(/\/v1$/iu, "") || "/";
|
|
1821
|
-
parsed.search = "";
|
|
1822
|
-
parsed.hash = "";
|
|
1823
|
-
const origin = parsed.toString().replace(/\/$/u, "");
|
|
1824
|
-
return {
|
|
1825
|
-
origin,
|
|
1826
|
-
inferenceBaseUrl: `${origin}/v1`
|
|
1827
|
-
};
|
|
1828
|
-
}
|
|
1829
|
-
/** Canonicalizes persisted provider config for the shared OpenAI transport. */
|
|
1830
|
-
function normalizeLlamaServerProviderConfig(provider) {
|
|
1831
|
-
const endpoint = resolveLlamaServerEndpoint(provider.baseUrl);
|
|
1832
|
-
const request = provider.request ?? {};
|
|
1833
|
-
const normalizedRequest = typeof request.allowPrivateNetwork === "boolean" ? request : {
|
|
1834
|
-
...request,
|
|
1835
|
-
allowPrivateNetwork: true
|
|
1836
|
-
};
|
|
1837
|
-
return {
|
|
1838
|
-
...provider,
|
|
1839
|
-
baseUrl: endpoint.inferenceBaseUrl,
|
|
1840
|
-
api: "openai-completions",
|
|
1841
|
-
request: normalizedRequest
|
|
1842
|
-
};
|
|
1843
|
-
}
|
|
1844
|
-
//#endregion
|
|
1845
|
-
//#region extensions/llama-cpp/src/external-server/models.ts
|
|
1846
|
-
function normalizeStatus(value) {
|
|
1847
|
-
switch (value) {
|
|
1848
|
-
case "unloaded":
|
|
1849
|
-
case "loading":
|
|
1850
|
-
case "loaded":
|
|
1851
|
-
case "sleeping":
|
|
1852
|
-
case "downloading": return value;
|
|
1853
|
-
default: return "unknown";
|
|
1854
|
-
}
|
|
1855
|
-
}
|
|
1856
|
-
function resolveContextWindow(props) {
|
|
1857
|
-
return asPositiveSafeInteger(props?.default_generation_settings?.n_ctx) ?? asPositiveSafeInteger(props?.n_ctx) ?? SELF_HOSTED_DEFAULT_CONTEXT_WINDOW;
|
|
1858
|
-
}
|
|
1859
|
-
function resolveMaxTokens(props, contextWindow) {
|
|
1860
|
-
const params = props?.default_generation_settings?.params;
|
|
1861
|
-
const advertised = asPositiveSafeInteger(params?.max_tokens) ?? asPositiveSafeInteger(params?.n_predict);
|
|
1862
|
-
return Math.min(advertised ?? SELF_HOSTED_DEFAULT_MAX_TOKENS, contextWindow);
|
|
1863
|
-
}
|
|
1864
|
-
function resolveInput(row, props) {
|
|
1865
|
-
const advertised = row.architecture?.input_modalities;
|
|
1866
|
-
return Array.isArray(advertised) && advertised.includes("image") || props?.modalities?.vision === true ? ["text", "image"] : ["text"];
|
|
1867
|
-
}
|
|
1868
|
-
function buildCompat(props) {
|
|
1869
|
-
const caps = props?.chat_template_caps;
|
|
1870
|
-
return {
|
|
1871
|
-
supportsStore: false,
|
|
1872
|
-
supportsDeveloperRole: false,
|
|
1873
|
-
supportsReasoningEffort: caps?.supports_reasoning_effort === true,
|
|
1874
|
-
supportsTemperature: true,
|
|
1875
|
-
supportsUsageInStreaming: true,
|
|
1876
|
-
supportsTools: caps?.supports_tool_calls === true,
|
|
1877
|
-
supportsStrictMode: false,
|
|
1878
|
-
supportsJsonSchemaResponseFormat: true,
|
|
1879
|
-
requiresStringContent: caps?.supports_typed_content !== true,
|
|
1880
|
-
maxTokensField: "max_tokens"
|
|
1881
|
-
};
|
|
1882
|
-
}
|
|
1883
|
-
/** Maps one llama-server model row plus optional runtime properties into OpenClaw config. */
|
|
1884
|
-
function mapLlamaServerModel(row, props) {
|
|
1885
|
-
const id = typeof row.id === "string" ? row.id.trim() : "";
|
|
1886
|
-
if (!id || row.object !== void 0 && row.object !== "model") return null;
|
|
1887
|
-
const contextWindow = resolveContextWindow(props);
|
|
1888
|
-
const compat = buildCompat(props);
|
|
1889
|
-
return {
|
|
1890
|
-
config: {
|
|
1891
|
-
id,
|
|
1892
|
-
name: id,
|
|
1893
|
-
reasoning: compat.supportsReasoningEffort === true,
|
|
1894
|
-
input: resolveInput(row, props),
|
|
1895
|
-
cost: { ...SELF_HOSTED_DEFAULT_COST },
|
|
1896
|
-
contextWindow,
|
|
1897
|
-
contextTokens: contextWindow,
|
|
1898
|
-
maxTokens: resolveMaxTokens(props, contextWindow),
|
|
1899
|
-
compat
|
|
1900
|
-
},
|
|
1901
|
-
status: normalizeStatus(row.status?.value),
|
|
1902
|
-
failed: row.status?.failed === true
|
|
1903
|
-
};
|
|
1904
|
-
}
|
|
1905
|
-
function buildLlamaServerProviderConfig(params) {
|
|
1906
|
-
const models = Array.isArray(params.configured?.models) ? [...params.configured.models] : [];
|
|
1907
|
-
const seen = new Set(models.map((model) => model.id));
|
|
1908
|
-
for (const discovered of params.discoveredModels) {
|
|
1909
|
-
if (seen.has(discovered.config.id)) continue;
|
|
1910
|
-
seen.add(discovered.config.id);
|
|
1911
|
-
models.push(discovered.config);
|
|
1912
|
-
}
|
|
1913
|
-
return normalizeLlamaServerProviderConfig({
|
|
1914
|
-
...params.configured,
|
|
1915
|
-
baseUrl: params.configured?.baseUrl ?? "http://127.0.0.1:8080",
|
|
1916
|
-
models
|
|
1917
|
-
});
|
|
1918
|
-
}
|
|
1919
|
-
//#endregion
|
|
1920
|
-
//#region extensions/llama-cpp/src/external-server/discovery.ts
|
|
1921
|
-
/** Discovers llama-server models without loading, waking, or unloading them. */
|
|
1922
|
-
async function discoverLlamaServer(params) {
|
|
1923
|
-
const endpoint = resolveLlamaServerEndpoint(params.baseUrl);
|
|
1924
|
-
const result = await discoverOpenAICompatibleLocalModels({
|
|
1925
|
-
baseUrl: endpoint.inferenceBaseUrl,
|
|
1926
|
-
serverBaseUrl: endpoint.origin,
|
|
1927
|
-
apiKey: params.apiKey,
|
|
1928
|
-
headers: params.headers,
|
|
1929
|
-
label: "llama-server",
|
|
1930
|
-
healthPath: "/health",
|
|
1931
|
-
modelsPathOrder: "server-first",
|
|
1932
|
-
routerModelProps: true,
|
|
1933
|
-
timeoutMs: LLAMA_SERVER_DISCOVERY_TIMEOUT_MS,
|
|
1934
|
-
signal: params.signal,
|
|
1935
|
-
rawResult: true
|
|
1936
|
-
});
|
|
1937
|
-
if (result.kind !== "success") return {
|
|
1938
|
-
...result,
|
|
1939
|
-
endpoint
|
|
1940
|
-
};
|
|
1941
|
-
return {
|
|
1942
|
-
kind: "success",
|
|
1943
|
-
endpoint,
|
|
1944
|
-
models: result.rows.flatMap(({ model, props }) => {
|
|
1945
|
-
const mapped = mapLlamaServerModel(model, props);
|
|
1946
|
-
return mapped ? [mapped] : [];
|
|
1947
|
-
})
|
|
1948
|
-
};
|
|
1949
|
-
}
|
|
1950
|
-
//#endregion
|
|
1951
|
-
//#region extensions/llama-cpp/src/external-server/provider.ts
|
|
1952
|
-
/** Discovers external llama-server models for provider runtime resolution. */
|
|
1953
|
-
async function discoverLlamaServerProvider(ctx) {
|
|
1954
|
-
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
1955
|
-
const auth = ctx.resolveProviderApiKey(LLAMA_CPP_PROVIDER_ID);
|
|
1956
|
-
const headers = await resolveLlamaServerProviderHeaders({
|
|
1957
|
-
config: ctx.config,
|
|
1958
|
-
env: ctx.env,
|
|
1959
|
-
headers: configured?.headers
|
|
1960
|
-
});
|
|
1961
|
-
const authApiKey = auth.discoveryApiKey ?? auth.apiKey;
|
|
1962
|
-
const apiKey = hasLlamaServerAuthorizationHeader(headers) || authApiKey && isNonSecretApiKeyMarker(authApiKey) ? void 0 : authApiKey;
|
|
1963
|
-
return await runLiveProviderCatalog({
|
|
1964
|
-
providerId: LLAMA_CPP_PROVIDER_ID,
|
|
1965
|
-
profileId: apiKey ? auth.profileId : void 0,
|
|
1966
|
-
run: async () => {
|
|
1967
|
-
const discovery = await discoverLlamaServer({
|
|
1968
|
-
baseUrl: configured?.baseUrl,
|
|
1969
|
-
apiKey,
|
|
1970
|
-
headers
|
|
1971
|
-
});
|
|
1972
|
-
if (discovery.kind !== "success") {
|
|
1973
|
-
if (!configured && !apiKey && !headers) return null;
|
|
1974
|
-
throw discovery.kind === "http-error" ? new LiveModelCatalogHttpError(LLAMA_CPP_PROVIDER_ID, discovery.status) : discovery.error;
|
|
1975
|
-
}
|
|
1976
|
-
return { provider: buildLlamaServerProviderConfig({
|
|
1977
|
-
configured,
|
|
1978
|
-
discoveredModels: discovery.models
|
|
1979
|
-
}) };
|
|
1980
|
-
}
|
|
1981
|
-
});
|
|
1982
|
-
}
|
|
1983
|
-
async function prepareLlamaServerDynamicModel(ctx) {
|
|
1984
|
-
const apiKey = await resolveLlamaServerRuntimeApiKey({
|
|
1985
|
-
config: ctx.config,
|
|
1986
|
-
agentDir: ctx.agentDir,
|
|
1987
|
-
profileId: ctx.authProfileId
|
|
1988
|
-
});
|
|
1989
|
-
const headers = await resolveLlamaServerProviderHeaders({
|
|
1990
|
-
config: ctx.config,
|
|
1991
|
-
env: process.env,
|
|
1992
|
-
headers: ctx.providerConfig?.headers
|
|
1993
|
-
});
|
|
1994
|
-
const discovery = await discoverLlamaServer({
|
|
1995
|
-
baseUrl: ctx.providerConfig?.baseUrl,
|
|
1996
|
-
apiKey: hasLlamaServerAuthorizationHeader(headers) ? void 0 : apiKey,
|
|
1997
|
-
headers
|
|
1998
|
-
});
|
|
1999
|
-
const model = discovery.kind === "success" ? discovery.models.find((entry) => entry.config.id === ctx.modelId) : void 0;
|
|
2000
|
-
if (!model) return;
|
|
2001
|
-
return {
|
|
2002
|
-
...model.config,
|
|
2003
|
-
provider: LLAMA_CPP_PROVIDER_ID,
|
|
2004
|
-
api: ctx.providerConfig?.api ?? "openai-completions",
|
|
2005
|
-
baseUrl: resolveLlamaServerEndpoint(ctx.providerConfig?.baseUrl).inferenceBaseUrl,
|
|
2006
|
-
input: model.config.input.filter((entry) => entry === "text" || entry === "image")
|
|
2007
|
-
};
|
|
2008
|
-
}
|
|
2009
|
-
//#endregion
|
|
2010
1766
|
//#region extensions/llama-cpp/src/auth-config.ts
|
|
2011
1767
|
const LLAMA_CPP_DEFAULT_PROFILE_ID = `${LLAMA_CPP_PROVIDER_ID}:default`;
|
|
2012
1768
|
function buildLlamaCppAuthProfileRemovalPatch(config) {
|
|
@@ -2066,7 +1822,8 @@ function stripEndpointCredentials(provider) {
|
|
|
2066
1822
|
}
|
|
2067
1823
|
function hasEndpointChanged(provider, baseUrl) {
|
|
2068
1824
|
if (!provider) return false;
|
|
2069
|
-
|
|
1825
|
+
const configuredBaseUrl = provider.baseUrl ?? "http://127.0.0.1:8080";
|
|
1826
|
+
return resolveLlamaServerEndpoint(configuredBaseUrl).inferenceBaseUrl !== resolveLlamaServerEndpoint(baseUrl).inferenceBaseUrl;
|
|
2070
1827
|
}
|
|
2071
1828
|
function stripLlamaServerEndpointAuth(config) {
|
|
2072
1829
|
const withoutProfile = removeAuthProfileConfig(config, LLAMA_CPP_DEFAULT_PROFILE_ID);
|
|
@@ -2139,7 +1896,8 @@ async function discoverForSetup(ctx) {
|
|
|
2139
1896
|
baseUrl: provider?.baseUrl ?? "http://127.0.0.1:8080",
|
|
2140
1897
|
apiKey,
|
|
2141
1898
|
headers,
|
|
2142
|
-
signal: ctx.signal
|
|
1899
|
+
signal: ctx.signal,
|
|
1900
|
+
useRuntimeDefaults: false
|
|
2143
1901
|
});
|
|
2144
1902
|
return discovery.kind === "success" ? discovery : null;
|
|
2145
1903
|
} catch {
|
|
@@ -2176,7 +1934,7 @@ async function prepareLlamaServerSetup(ctx) {
|
|
|
2176
1934
|
async function runLlamaServerSetup(ctx) {
|
|
2177
1935
|
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2178
1936
|
const defaultOrigin = resolveLlamaServerEndpoint(existing?.baseUrl).origin;
|
|
2179
|
-
const
|
|
1937
|
+
const baseUrl = await ctx.prompter.text({
|
|
2180
1938
|
message: `${LLAMA_CPP_PROVIDER_LABEL} URL`,
|
|
2181
1939
|
initialValue: defaultOrigin,
|
|
2182
1940
|
placeholder: LLAMA_SERVER_DEFAULT_ORIGIN,
|
|
@@ -2189,7 +1947,8 @@ async function runLlamaServerSetup(ctx) {
|
|
|
2189
1947
|
return "Enter a valid HTTP or HTTPS URL without embedded credentials (e.g. http://localhost:8080).";
|
|
2190
1948
|
}
|
|
2191
1949
|
}
|
|
2192
|
-
})
|
|
1950
|
+
});
|
|
1951
|
+
const endpoint = resolveLlamaServerEndpoint(baseUrl);
|
|
2193
1952
|
const endpointChanged = Boolean(existing?.localService) || hasEndpointChanged(existing, endpoint.inferenceBaseUrl);
|
|
2194
1953
|
const resolvedHeaders = endpointChanged ? void 0 : await resolveLlamaServerProviderHeaders({
|
|
2195
1954
|
config: ctx.config,
|
|
@@ -2242,7 +2001,8 @@ async function runLlamaServerSetup(ctx) {
|
|
|
2242
2001
|
baseUrl: endpoint.inferenceBaseUrl,
|
|
2243
2002
|
apiKey,
|
|
2244
2003
|
headers,
|
|
2245
|
-
signal: ctx.signal
|
|
2004
|
+
signal: ctx.signal,
|
|
2005
|
+
useRuntimeDefaults: false
|
|
2246
2006
|
});
|
|
2247
2007
|
if (discovery.kind !== "success") throw new Error(describeDiscoveryFailure(discovery));
|
|
2248
2008
|
const modelId = selectSetupModelId(discovery);
|
|
@@ -2301,7 +2061,8 @@ async function validateNonInteractiveDiscovery(ctx) {
|
|
|
2301
2061
|
const discovery = await discoverLlamaServer({
|
|
2302
2062
|
baseUrl,
|
|
2303
2063
|
apiKey,
|
|
2304
|
-
headers
|
|
2064
|
+
headers,
|
|
2065
|
+
useRuntimeDefaults: false
|
|
2305
2066
|
});
|
|
2306
2067
|
if (discovery.kind !== "success") throw new Error(describeDiscoveryFailure(discovery));
|
|
2307
2068
|
const requestedModelId = normalizeOptionalSecretInput(ctx.opts.customModelId);
|
|
@@ -2712,10 +2473,7 @@ function wrapLlamaCppStream(ctx) {
|
|
|
2712
2473
|
}
|
|
2713
2474
|
function registerLlamaCppProvider(api) {
|
|
2714
2475
|
api.registerProvider({
|
|
2715
|
-
|
|
2716
|
-
label: LLAMA_CPP_PROVIDER_LABEL,
|
|
2717
|
-
docsPath: "/plugins/llama-cpp",
|
|
2718
|
-
envVars: [LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR],
|
|
2476
|
+
...provider_discovery_default,
|
|
2719
2477
|
auth: [{
|
|
2720
2478
|
id: "local",
|
|
2721
2479
|
label: LLAMA_CPP_PROVIDER_LABEL,
|
|
@@ -2757,27 +2515,6 @@ function registerLlamaCppProvider(api) {
|
|
|
2757
2515
|
validateNonInteractive: validateLlamaServerNonInteractive,
|
|
2758
2516
|
runNonInteractive: configureLlamaServerNonInteractive
|
|
2759
2517
|
}],
|
|
2760
|
-
catalog: {
|
|
2761
|
-
order: "late",
|
|
2762
|
-
run: async (ctx) => {
|
|
2763
|
-
const configured = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
2764
|
-
return configured?.localService ? { provider: buildLlamaCppProviderConfig({
|
|
2765
|
-
existing: configured,
|
|
2766
|
-
modelInventory: configured.models
|
|
2767
|
-
}) } : await discoverLlamaServerProvider(ctx);
|
|
2768
|
-
}
|
|
2769
|
-
},
|
|
2770
|
-
staticCatalog: {
|
|
2771
|
-
order: "late",
|
|
2772
|
-
run: async () => ({ provider: buildLlamaCppProviderConfig() })
|
|
2773
|
-
},
|
|
2774
|
-
resolveSyntheticAuth: ({ providerConfig }) => providerConfig?.localService || shouldUseLlamaServerSyntheticAuth(providerConfig) ? {
|
|
2775
|
-
apiKey: LLAMA_CPP_LOCAL_AUTH_MARKER,
|
|
2776
|
-
source: providerConfig?.localService ? "managed local llama.cpp server" : hasLlamaServerAuthorizationHeader(providerConfig?.headers) ? "models.providers.llama-cpp.headers.Authorization" : "models.providers.llama-cpp (synthetic local key)",
|
|
2777
|
-
mode: "api-key"
|
|
2778
|
-
} : void 0,
|
|
2779
|
-
shouldDeferSyntheticProfileAuth: ({ resolvedApiKey }) => resolvedApiKey?.trim() === "llama-cpp-local" || resolvedApiKey?.trim() === CUSTOM_LOCAL_AUTH_MARKER,
|
|
2780
|
-
normalizeConfig: ({ providerConfig }) => providerConfig.localService ? providerConfig : normalizeLlamaServerProviderConfig(providerConfig),
|
|
2781
2518
|
prepareDynamicModel: async (ctx) => ctx.config?.models?.providers?.["llama-cpp"]?.localService ? void 0 : await prepareLlamaServerDynamicModel(ctx),
|
|
2782
2519
|
reconcileLocalService: reconcileManagedLlamaServer,
|
|
2783
2520
|
wrapSimpleCompletionStreamFn: wrapLlamaCppStream,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as default } from "./.setup/provider-discovery-CEcEBzKt.mjs";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as resolveManagedLlamaCppProviderConfig, t as MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE } from "./.setup/managed-provider-config-
|
|
1
|
+
import { n as resolveManagedLlamaCppProviderConfig, t as MANAGED_LLAMA_CPP_CONFIG_REQUIRED_MESSAGE } from "./.setup/managed-provider-config-Nd32gsuH.mjs";
|
|
2
2
|
//#region extensions/llama-cpp/provider-policy-api.ts
|
|
3
3
|
function inspectEmbeddingProviderSetup(params) {
|
|
4
4
|
if (params.provider !== "local") return null;
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "llama-cpp",
|
|
3
|
-
"categories": [
|
|
3
|
+
"categories": [
|
|
4
|
+
"models"
|
|
5
|
+
],
|
|
4
6
|
"name": "llama.cpp Provider",
|
|
5
7
|
"description": "Managed and external llama.cpp servers for GGUF chat and embeddings.",
|
|
6
8
|
"activation": {
|
|
7
9
|
"onStartup": false
|
|
8
10
|
},
|
|
11
|
+
"providerCatalogEntry": "./dist/provider-discovery.js",
|
|
9
12
|
"enabledByDefault": true,
|
|
10
|
-
"autoEnableWhenConfiguredProviders": [
|
|
11
|
-
|
|
13
|
+
"autoEnableWhenConfiguredProviders": [
|
|
14
|
+
"llama-cpp"
|
|
15
|
+
],
|
|
16
|
+
"providers": [
|
|
17
|
+
"llama-cpp"
|
|
18
|
+
],
|
|
12
19
|
"modelCatalog": {
|
|
13
20
|
"discovery": {
|
|
14
21
|
"llama-cpp": "refreshable"
|
|
@@ -31,13 +38,19 @@
|
|
|
31
38
|
}
|
|
32
39
|
}
|
|
33
40
|
},
|
|
34
|
-
"syntheticAuthRefs": [
|
|
35
|
-
|
|
41
|
+
"syntheticAuthRefs": [
|
|
42
|
+
"llama-cpp"
|
|
43
|
+
],
|
|
44
|
+
"nonSecretAuthMarkers": [
|
|
45
|
+
"llama-cpp-local"
|
|
46
|
+
],
|
|
36
47
|
"setup": {
|
|
37
48
|
"providers": [
|
|
38
49
|
{
|
|
39
50
|
"id": "llama-cpp",
|
|
40
|
-
"envVars": [
|
|
51
|
+
"envVars": [
|
|
52
|
+
"LLAMA_SERVER_API_KEY"
|
|
53
|
+
]
|
|
41
54
|
}
|
|
42
55
|
]
|
|
43
56
|
},
|
|
@@ -72,7 +85,9 @@
|
|
|
72
85
|
}
|
|
73
86
|
],
|
|
74
87
|
"contracts": {
|
|
75
|
-
"embeddingProviders": [
|
|
88
|
+
"embeddingProviders": [
|
|
89
|
+
"local"
|
|
90
|
+
]
|
|
76
91
|
},
|
|
77
92
|
"configSchema": {
|
|
78
93
|
"type": "object",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/llama-cpp-provider",
|
|
3
|
-
"version": "2026.10.5
|
|
3
|
+
"version": "2026.10.5",
|
|
4
4
|
"description": "OpenClaw provider for managed and external llama.cpp servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"minHostVersion": ">=2026.6.2"
|
|
22
22
|
},
|
|
23
23
|
"compat": {
|
|
24
|
-
"pluginApi": ">=2026.10.5
|
|
24
|
+
"pluginApi": ">=2026.10.5"
|
|
25
25
|
},
|
|
26
26
|
"build": {
|
|
27
|
-
"openclawVersion": "2026.10.5
|
|
27
|
+
"openclawVersion": "2026.10.5"
|
|
28
28
|
},
|
|
29
29
|
"release": {
|
|
30
30
|
"bundleRuntimeDependencies": false,
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"assets/activity.svg"
|
|
47
47
|
],
|
|
48
48
|
"peerDependencies": {
|
|
49
|
-
"openclaw": ">=2026.10.5
|
|
49
|
+
"openclaw": ">=2026.10.5"
|
|
50
50
|
},
|
|
51
51
|
"peerDependenciesMeta": {
|
|
52
52
|
"openclaw": {
|