@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,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,26 +99,18 @@ 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
|
|
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,155 @@
|
|
|
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
|
+
import { asOptionalRecord, asPositiveSafeInteger } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
+
import { isNonSecretApiKeyMarker } from "openclaw/plugin-sdk/provider-auth";
|
|
5
|
+
import { resolveApiKeyForProvider } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
6
|
+
import { resolveConfiguredSecretInputString } from "openclaw/plugin-sdk/secret-input-runtime";
|
|
7
|
+
import { SELF_HOSTED_DEFAULT_CONTEXT_WINDOW, SELF_HOSTED_DEFAULT_COST, SELF_HOSTED_DEFAULT_MAX_TOKENS, discoverOpenAICompatibleLocalModels } from "openclaw/plugin-sdk/provider-setup";
|
|
8
|
+
//#region extensions/llama-cpp/src/external-server/auth.ts
|
|
9
|
+
async function resolveLlamaServerProviderHeaders(params) {
|
|
10
|
+
const headers = asOptionalRecord(params.headers);
|
|
11
|
+
if (!headers) return;
|
|
12
|
+
const resolved = {};
|
|
13
|
+
for (const [name, value] of Object.entries(headers)) {
|
|
14
|
+
if (!params.config) {
|
|
15
|
+
if (typeof value === "string" && value.trim()) resolved[name] = value.trim();
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
const path = `models.providers.${LLAMA_CPP_PROVIDER_ID}.headers[${JSON.stringify(name)}]`;
|
|
19
|
+
const header = await resolveConfiguredSecretInputString({
|
|
20
|
+
config: params.config,
|
|
21
|
+
env: params.env ?? process.env,
|
|
22
|
+
value,
|
|
23
|
+
path,
|
|
24
|
+
unresolvedReasonStyle: "detailed"
|
|
25
|
+
});
|
|
26
|
+
if (header.unresolvedRefReason) throw new Error(`${path}: ${header.unresolvedRefReason}`);
|
|
27
|
+
if (header.value) resolved[name] = header.value;
|
|
28
|
+
}
|
|
29
|
+
return Object.keys(resolved).length > 0 ? resolved : void 0;
|
|
30
|
+
}
|
|
31
|
+
async function resolveLlamaServerRuntimeApiKey(params) {
|
|
32
|
+
const apiKey = (await resolveApiKeyForProvider({
|
|
33
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
34
|
+
cfg: params.config,
|
|
35
|
+
agentDir: params.agentDir,
|
|
36
|
+
profileId: params.profileId,
|
|
37
|
+
lockedProfile: params.profileId !== void 0
|
|
38
|
+
})).apiKey?.trim();
|
|
39
|
+
return apiKey && !isNonSecretApiKeyMarker(apiKey) ? apiKey : void 0;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region extensions/llama-cpp/src/external-server/models.ts
|
|
43
|
+
function normalizeStatus(value) {
|
|
44
|
+
switch (value) {
|
|
45
|
+
case "unloaded":
|
|
46
|
+
case "loading":
|
|
47
|
+
case "loaded":
|
|
48
|
+
case "sleeping":
|
|
49
|
+
case "downloading": return value;
|
|
50
|
+
default: return "unknown";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function resolveMaxTokens(props, contextWindow) {
|
|
54
|
+
const params = props?.default_generation_settings?.params;
|
|
55
|
+
const advertised = asPositiveSafeInteger(params?.max_tokens) ?? asPositiveSafeInteger(params?.n_predict);
|
|
56
|
+
return Math.min(advertised ?? SELF_HOSTED_DEFAULT_MAX_TOKENS, contextWindow);
|
|
57
|
+
}
|
|
58
|
+
function resolveInput(row, props) {
|
|
59
|
+
const advertised = row.architecture?.input_modalities;
|
|
60
|
+
return Array.isArray(advertised) && advertised.includes("image") || props?.modalities?.vision === true ? ["text", "image"] : ["text"];
|
|
61
|
+
}
|
|
62
|
+
function buildCompat(props, useRuntimeDefaults) {
|
|
63
|
+
const caps = props?.chat_template_caps;
|
|
64
|
+
return {
|
|
65
|
+
supportsStore: false,
|
|
66
|
+
supportsDeveloperRole: false,
|
|
67
|
+
supportsReasoningEffort: caps?.supports_reasoning_effort === true,
|
|
68
|
+
supportsTemperature: true,
|
|
69
|
+
supportsUsageInStreaming: true,
|
|
70
|
+
...typeof caps?.supports_tool_calls === "boolean" || useRuntimeDefaults ? { supportsTools: caps?.supports_tool_calls === true } : {},
|
|
71
|
+
supportsStrictMode: false,
|
|
72
|
+
supportsJsonSchemaResponseFormat: true,
|
|
73
|
+
requiresStringContent: caps?.supports_typed_content !== true,
|
|
74
|
+
maxTokensField: "max_tokens"
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/** Maps one llama-server model row plus optional runtime properties into OpenClaw config. */
|
|
78
|
+
function mapLlamaServerModel(row, props, useRuntimeDefaults = true) {
|
|
79
|
+
const id = typeof row.id === "string" ? row.id.trim() : "";
|
|
80
|
+
if (!id || row.object !== void 0 && row.object !== "model") return null;
|
|
81
|
+
const contextWindow = asPositiveSafeInteger(props?.default_generation_settings?.n_ctx) ?? asPositiveSafeInteger(props?.n_ctx) ?? (useRuntimeDefaults ? SELF_HOSTED_DEFAULT_CONTEXT_WINDOW : void 0);
|
|
82
|
+
const compat = buildCompat(props, useRuntimeDefaults);
|
|
83
|
+
return {
|
|
84
|
+
config: {
|
|
85
|
+
id,
|
|
86
|
+
name: id,
|
|
87
|
+
reasoning: compat.supportsReasoningEffort === true,
|
|
88
|
+
input: resolveInput(row, props),
|
|
89
|
+
cost: { ...SELF_HOSTED_DEFAULT_COST },
|
|
90
|
+
contextWindow,
|
|
91
|
+
contextTokens: contextWindow,
|
|
92
|
+
maxTokens: resolveMaxTokens(props, contextWindow ?? SELF_HOSTED_DEFAULT_CONTEXT_WINDOW),
|
|
93
|
+
compat
|
|
94
|
+
},
|
|
95
|
+
status: normalizeStatus(row.status?.value),
|
|
96
|
+
failed: row.status?.failed === true
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function buildLlamaServerProviderConfig(params) {
|
|
100
|
+
const baseUrl = resolveLlamaServerEndpoint(params.configured?.baseUrl).inferenceBaseUrl;
|
|
101
|
+
const discoveredById = new Map(params.discoveredModels.map(({ config }) => [config.id, config]));
|
|
102
|
+
const models = (params.configured?.models ?? []).map((configured) => {
|
|
103
|
+
const discovered = discoveredById.get(configured.id);
|
|
104
|
+
discoveredById.delete(configured.id);
|
|
105
|
+
const matchesRoute = (!configured.api || configured.api === "openai-completions") && resolveLlamaServerEndpoint(configured.baseUrl?.trim() || baseUrl).inferenceBaseUrl === baseUrl;
|
|
106
|
+
return discovered && matchesRoute ? Object.assign({}, discovered, configured, {
|
|
107
|
+
contextWindow: configured.contextWindow ?? discovered.contextWindow,
|
|
108
|
+
contextTokens: configured.contextTokens ?? discovered.contextTokens,
|
|
109
|
+
compat: {
|
|
110
|
+
...discovered.compat,
|
|
111
|
+
...configured.compat
|
|
112
|
+
}
|
|
113
|
+
}) : configured;
|
|
114
|
+
});
|
|
115
|
+
models.push(...discoveredById.values());
|
|
116
|
+
return normalizeLlamaServerProviderConfig({
|
|
117
|
+
...params.configured,
|
|
118
|
+
baseUrl,
|
|
119
|
+
models
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region extensions/llama-cpp/src/external-server/discovery.ts
|
|
124
|
+
/** Discovers llama-server models without loading, waking, or unloading them. */
|
|
125
|
+
async function discoverLlamaServer(params) {
|
|
126
|
+
const endpoint = resolveLlamaServerEndpoint(params.baseUrl);
|
|
127
|
+
const result = await discoverOpenAICompatibleLocalModels({
|
|
128
|
+
baseUrl: endpoint.inferenceBaseUrl,
|
|
129
|
+
serverBaseUrl: endpoint.origin,
|
|
130
|
+
allowPrivateNetwork: params.allowPrivateNetwork,
|
|
131
|
+
apiKey: params.apiKey,
|
|
132
|
+
headers: params.headers,
|
|
133
|
+
label: "llama-server",
|
|
134
|
+
healthPath: "/health",
|
|
135
|
+
modelsPathOrder: "server-first",
|
|
136
|
+
routerModelProps: true,
|
|
137
|
+
timeoutMs: LLAMA_SERVER_DISCOVERY_TIMEOUT_MS,
|
|
138
|
+
signal: params.signal,
|
|
139
|
+
rawResult: true
|
|
140
|
+
});
|
|
141
|
+
if (result.kind !== "success") return {
|
|
142
|
+
...result,
|
|
143
|
+
endpoint
|
|
144
|
+
};
|
|
145
|
+
return {
|
|
146
|
+
kind: "success",
|
|
147
|
+
endpoint,
|
|
148
|
+
models: result.rows.flatMap(({ model, props }) => {
|
|
149
|
+
const mapped = mapLlamaServerModel(model, props, params.useRuntimeDefaults);
|
|
150
|
+
return mapped ? [mapped] : [];
|
|
151
|
+
})
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
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 };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { _ as LLAMA_CPP_PROVIDER_ID } from "./defaults-CL2lz0cV.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 };
|