@openclaw/llama-cpp-provider 2026.10.5-beta.4 → 2026.10.10-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-CL2lz0cV.mjs";
2
+ //#region extensions/llama-cpp/src/auth-config.ts
3
+ const LLAMA_CPP_DEFAULT_PROFILE_ID = `${LLAMA_CPP_PROVIDER_ID}:default`;
4
+ function buildLlamaCppAuthProfileRemovalPatch(config) {
5
+ const profileExists = Boolean(config.auth?.profiles?.[LLAMA_CPP_DEFAULT_PROFILE_ID]);
6
+ const referencedOrders = Object.entries(config.auth?.order ?? {}).filter(([, ids]) => ids.includes(LLAMA_CPP_DEFAULT_PROFILE_ID));
7
+ if (!profileExists && referencedOrders.length === 0) return {};
8
+ const authPatch = {};
9
+ if (profileExists) Reflect.set(authPatch, "profiles", { [LLAMA_CPP_DEFAULT_PROFILE_ID]: void 0 });
10
+ if (referencedOrders.length > 0) Reflect.set(authPatch, "order", Object.fromEntries(referencedOrders.map(([providerId, ids]) => {
11
+ const next = ids.filter((id) => id !== LLAMA_CPP_DEFAULT_PROFILE_ID);
12
+ return [providerId, next.length > 0 ? next : void 0];
13
+ })));
14
+ return { auth: authPatch };
15
+ }
16
+ //#endregion
17
+ export { buildLlamaCppAuthProfileRemovalPatch as n, LLAMA_CPP_DEFAULT_PROFILE_ID as t };
@@ -99,17 +99,17 @@ function buildLlamaCppProviderConfig(params = {}) {
99
99
  return {
100
100
  ...existing,
101
101
  baseUrl: managed?.baseUrl ?? existing?.baseUrl ?? `http://127.0.0.1:19432/v1`,
102
- apiKey: existing?.apiKey ?? "llama-cpp-local",
103
102
  api: "openai-completions",
104
103
  timeoutSeconds: existing?.timeoutSeconds ?? 600,
105
104
  ...managed ? { localService: {
105
+ ...existing?.localService,
106
106
  command: managed.command,
107
107
  args: managed.args,
108
108
  healthUrl: managed.healthUrl,
109
- readyTimeoutMs: LLAMA_CPP_READY_TIMEOUT_MS,
110
- idleStopMs: LLAMA_CPP_IDLE_STOP_MS
109
+ readyTimeoutMs: existing?.localService?.readyTimeoutMs ?? LLAMA_CPP_READY_TIMEOUT_MS,
110
+ idleStopMs: existing?.localService?.idleStopMs ?? LLAMA_CPP_IDLE_STOP_MS
111
111
  } } : {},
112
- models
112
+ models: managed && existing?.localService ? models.map((model) => model.baseUrl === existing.baseUrl ? Object.assign({}, model, { baseUrl: managed.baseUrl }) : model) : models
113
113
  };
114
114
  }
115
115
  //#endregion
@@ -1,23 +1,10 @@
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";
1
+ import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-CL2lz0cV.mjs";
2
+ import { n as normalizeLlamaServerProviderConfig, o as LLAMA_SERVER_DISCOVERY_TIMEOUT_MS, r as resolveLlamaServerEndpoint } from "./provider-discovery-97l8WbMa.mjs";
3
3
  import { asOptionalRecord, asPositiveSafeInteger } from "openclaw/plugin-sdk/string-coerce-runtime";
4
4
  import { isNonSecretApiKeyMarker } from "openclaw/plugin-sdk/provider-auth";
5
- import { LiveModelCatalogHttpError, runLiveProviderCatalog } from "openclaw/plugin-sdk/provider-catalog-live-runtime";
6
5
  import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
7
6
  import { resolveConfiguredSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime";
8
7
  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
8
  //#region extensions/llama-cpp/src/external-server/auth.ts
22
9
  async function resolveLlamaServerProviderHeaders(params) {
23
10
  const headers = asOptionalRecord(params.headers);
@@ -140,6 +127,7 @@ async function discoverLlamaServer(params) {
140
127
  const result = await discoverOpenAICompatibleLocalModels({
141
128
  baseUrl: endpoint.inferenceBaseUrl,
142
129
  serverBaseUrl: endpoint.origin,
130
+ allowPrivateNetwork: params.allowPrivateNetwork,
143
131
  apiKey: params.apiKey,
144
132
  headers: params.headers,
145
133
  label: "llama-server",
@@ -164,67 +152,4 @@ async function discoverLlamaServer(params) {
164
152
  };
165
153
  }
166
154
  //#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 };
155
+ export { resolveLlamaServerRuntimeApiKey as i, buildLlamaServerProviderConfig as n, resolveLlamaServerProviderHeaders as r, discoverLlamaServer as t };
@@ -0,0 +1,163 @@
1
+ import { E as resolveLlamaCppModelCacheDir, _ as LLAMA_CPP_PROVIDER_ID, a as DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID } from "./defaults-CL2lz0cV.mjs";
2
+ import { o as resolveLlamaCppMediaModels } from "./media-config-CZ7CluNV.mjs";
3
+ import { n as resolveManagedLlamaCppProviderConfig } from "./managed-provider-config-G_LBLX0A.mjs";
4
+ import { ensureLlamaCppModel, prepareManagedLlamaServer, reconcileManagedLlamaServer } from "./managed-server-C2ukpg0h.mjs";
5
+ import { asOptionalRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
6
+ import { getEmbeddingProvider } from "openclaw/plugin-sdk/embedding-providers";
7
+ import { readProviderJsonResponse, readProviderTextResponse } from "openclaw/plugin-sdk/provider-http";
8
+ import { ssrfPolicyFromHttpBaseUrlAllowedOrigin } from "openclaw/plugin-sdk/ssrf-runtime";
9
+ import { fetchConfiguredLocalOriginWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime-internal";
10
+ //#region extensions/llama-cpp/src/managed-server-inspection.ts
11
+ async function fetchEndpoint(url, accept) {
12
+ try {
13
+ const configuredLocalOriginBaseUrl = new URL(url).origin;
14
+ const { response, release } = await fetchConfiguredLocalOriginWithSsrFGuard({
15
+ url,
16
+ configuredLocalOriginBaseUrl,
17
+ policy: ssrfPolicyFromHttpBaseUrlAllowedOrigin(configuredLocalOriginBaseUrl),
18
+ timeoutMs: 2500,
19
+ auditContext: "llama-server-inspect"
20
+ });
21
+ try {
22
+ if (!response.ok) return { ok: false };
23
+ return {
24
+ ok: true,
25
+ value: accept === "json" ? await readProviderJsonResponse(response, "llama-server inspection") : await readProviderTextResponse(response, "llama-server inspection")
26
+ };
27
+ } finally {
28
+ await release();
29
+ }
30
+ } catch {
31
+ return { ok: false };
32
+ }
33
+ }
34
+ async function inspectLlamaServerRuntime(params) {
35
+ const root = params.baseUrl.replace(/\/v1\/?$/u, "").replace(/\/+$/u, "");
36
+ const query = `model=${encodeURIComponent(params.modelId)}&autoload=false`;
37
+ const [health, models, props, metrics] = await Promise.all([
38
+ fetchEndpoint(`${root}/health`, "json"),
39
+ fetchEndpoint(`${root}/models`, "json"),
40
+ fetchEndpoint(`${root}/props?${query}`, "json"),
41
+ fetchEndpoint(`${root}/metrics?${query}`, "text")
42
+ ]);
43
+ const propsRecord = asOptionalRecord(props.value);
44
+ const modalities = asOptionalRecord(propsRecord?.modalities);
45
+ const modelsRecord = asOptionalRecord(models.value);
46
+ const selected = (Array.isArray(modelsRecord?.data) ? modelsRecord.data : []).map((row) => asOptionalRecord(row)).find((row) => row?.id === params.modelId);
47
+ const pathValue = typeof propsRecord?.model_path === "string" ? propsRecord.model_path : typeof selected?.path === "string" ? selected.path : void 0;
48
+ return {
49
+ engine: "llama.cpp",
50
+ state: health.ok && models.ok && props.ok && !params.loadError ? "ready" : "failed",
51
+ backend: params.backend,
52
+ buildInfo: typeof propsRecord?.build_info === "string" ? propsRecord.build_info : void 0,
53
+ model: {
54
+ id: params.modelId,
55
+ ...pathValue ? { path: pathValue } : {}
56
+ },
57
+ capabilities: {
58
+ vision: modalities?.vision === true,
59
+ draft: false
60
+ },
61
+ endpoints: {
62
+ health: health.ok ? "ready" : "unavailable",
63
+ models: models.ok ? "ready" : "unavailable",
64
+ props: props.ok ? "ready" : "unavailable",
65
+ metrics: metrics.ok ? "ready" : "unavailable"
66
+ },
67
+ ...params.loadError ? { loadError: params.loadError } : {}
68
+ };
69
+ }
70
+ //#endregion
71
+ //#region extensions/llama-cpp/src/embedding-provider.runtime.ts
72
+ const LOCAL_EMBEDDING_RUNTIME_FACTS = Symbol.for("openclaw.localEmbeddingRuntimeFacts");
73
+ function resolveProviderPort(provider) {
74
+ const port = Number(new URL(provider.baseUrl ?? "").port);
75
+ if (!Number.isInteger(port) || port <= 0) throw new Error("Managed llama.cpp provider baseUrl must include a loopback port.");
76
+ return port;
77
+ }
78
+ async function prepareEmbeddingServer(options, embeddingSource) {
79
+ const provider = resolveManagedLlamaCppProviderConfig(options.config);
80
+ const mediaModels = resolveLlamaCppMediaModels(provider);
81
+ const cacheDir = resolveLlamaCppModelCacheDir(provider);
82
+ const embeddingModelPath = await ensureLlamaCppModel({
83
+ source: embeddingSource,
84
+ cacheDir,
85
+ download: true
86
+ });
87
+ await prepareManagedLlamaServer({
88
+ chatModel: { mode: "preserve" },
89
+ configuredChatModelIds: provider.models.map((model) => model.id),
90
+ ...mediaModels ? { mediaModels: [] } : {},
91
+ embeddingModelPath,
92
+ port: resolveProviderPort(provider),
93
+ reconcileBaseUrl: provider.baseUrl,
94
+ localService: provider.localService
95
+ });
96
+ }
97
+ function wrapProvider(params) {
98
+ let runtimeFacts;
99
+ const refreshFacts = async (loadError) => {
100
+ runtimeFacts = await inspectLlamaServerRuntime({
101
+ baseUrl: params.baseUrl,
102
+ modelId: DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID,
103
+ loadError
104
+ });
105
+ };
106
+ const withFacts = async (operation) => {
107
+ try {
108
+ const value = await operation();
109
+ await refreshFacts();
110
+ return value;
111
+ } catch (error) {
112
+ await refreshFacts(error instanceof Error ? error.message : String(error));
113
+ throw error;
114
+ }
115
+ };
116
+ const wrapped = {
117
+ id: "local",
118
+ model: params.canonicalModel,
119
+ dimensions: params.provider.dimensions,
120
+ maxInputTokens: params.provider.maxInputTokens ?? 2044,
121
+ embed: (input, callOptions) => withFacts(() => params.provider.embed(input, callOptions)),
122
+ embedBatch: (inputs, callOptions) => withFacts(() => params.provider.embedBatch(inputs, callOptions)),
123
+ close: params.provider.close
124
+ };
125
+ Object.defineProperty(wrapped, LOCAL_EMBEDDING_RUNTIME_FACTS, {
126
+ enumerable: false,
127
+ value: () => runtimeFacts
128
+ });
129
+ return wrapped;
130
+ }
131
+ async function createLlamaCppEmbeddingProvider(options, embeddingSource, identity) {
132
+ await prepareEmbeddingServer(options, embeddingSource);
133
+ const genericAdapter = getEmbeddingProvider("openai-compatible", options.config);
134
+ if (!genericAdapter) throw new Error("OpenAI-compatible embedding transport is unavailable.");
135
+ const acquireLocalService = options.acquireLocalService;
136
+ const result = await genericAdapter.create({
137
+ ...options,
138
+ provider: LLAMA_CPP_PROVIDER_ID,
139
+ model: DEFAULT_LLAMA_CPP_EMBEDDING_MODEL_ID,
140
+ remote: void 0,
141
+ ...acquireLocalService ? { acquireLocalService: (...[target, signal]) => acquireLocalService({
142
+ ...target,
143
+ reconcile: reconcileManagedLlamaServer
144
+ }, signal) } : {}
145
+ });
146
+ if (!result.provider) return result;
147
+ return {
148
+ provider: wrapProvider({
149
+ provider: result.provider,
150
+ canonicalModel: identity.model,
151
+ baseUrl: resolveManagedLlamaCppProviderConfig(options.config).baseUrl ?? ""
152
+ }),
153
+ runtime: {
154
+ id: "local",
155
+ inlineQueryTimeoutMs: 3e5,
156
+ inlineBatchTimeoutMs: 6e5,
157
+ cacheKeyData: identity.cacheKeyData,
158
+ ...(identity.aliases?.length ?? 0) > 0 ? { indexIdentityAliases: identity.aliases } : {}
159
+ }
160
+ };
161
+ }
162
+ //#endregion
163
+ export { createLlamaCppEmbeddingProvider };
@@ -1,4 +1,4 @@
1
- import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-ATX0SyoG.mjs";
1
+ import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-CL2lz0cV.mjs";
2
2
  //#region extensions/llama-cpp/src/managed-provider-config.ts
3
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
4
  function resolveManagedLlamaCppProviderConfig(config) {