@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.
- package/dist/.setup/auth-config-DPqFwXcI.mjs +17 -0
- package/dist/.setup/{defaults-ATX0SyoG.mjs → defaults-CL2lz0cV.mjs} +4 -4
- package/dist/.setup/{provider-OCMqlJ0I.mjs → discovery-VdqP6WcN.mjs} +4 -79
- package/dist/.setup/embedding-provider.runtime-FcwMX9AK.mjs +163 -0
- package/dist/.setup/{managed-provider-config-Nd32gsuH.mjs → managed-provider-config-G_LBLX0A.mjs} +1 -1
- 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-CEcEBzKt.mjs → provider-discovery-97l8WbMa.mjs} +2 -2
- 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 +192 -2459
- package/dist/provider-discovery.js +1 -2
- package/dist/provider-policy-api.js +1 -1
- package/openclaw.plugin.json +11 -1
- package/package.json +5 -5
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { _ as LLAMA_CPP_PROVIDER_ID, v as LLAMA_CPP_PROVIDER_LABEL } from "./defaults-CL2lz0cV.mjs";
|
|
2
|
+
import { a as LLAMA_SERVER_DEFAULT_ORIGIN, i as LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR, 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 { n as buildLlamaCppAuthProfileRemovalPatch, t as LLAMA_CPP_DEFAULT_PROFILE_ID } from "./auth-config-DPqFwXcI.mjs";
|
|
5
|
+
import { applyAuthProfileConfig, buildApiKeyCredential, ensureApiKeyFromEnvOrPrompt, normalizeOptionalSecretInput } from "openclaw/plugin-sdk/provider-auth";
|
|
6
|
+
import { removeAuthProfileConfig, removeProviderAuthProfilesWithLock } from "openclaw/plugin-sdk/provider-auth-runtime";
|
|
7
|
+
import { applyProviderDefaultModel } from "openclaw/plugin-sdk/provider-setup";
|
|
8
|
+
import { upsertAuthProfileWithLockOrThrow } from "openclaw/plugin-sdk/provider-auth-api-key";
|
|
9
|
+
import { selectPreferredLocalModelId } from "openclaw/plugin-sdk/provider-model-shared";
|
|
10
|
+
//#region extensions/llama-cpp/src/external-server/setup.ts
|
|
11
|
+
function selectSetupModelId(discovery) {
|
|
12
|
+
const candidates = discovery.models.filter((model) => !model.failed);
|
|
13
|
+
const ready = candidates.filter((model) => model.status === "loaded" || model.status === "sleeping");
|
|
14
|
+
const ids = (ready.length > 0 ? ready : candidates).map((model) => model.config.id);
|
|
15
|
+
return selectPreferredLocalModelId(ids) ?? ids[0];
|
|
16
|
+
}
|
|
17
|
+
function describeDiscoveryFailure(result) {
|
|
18
|
+
switch (result.kind) {
|
|
19
|
+
case "unreachable": return `llama-server could not be reached at ${result.endpoint.origin}.`;
|
|
20
|
+
case "http-error": return `llama-server returned HTTP ${result.status} for ${result.path} at ${result.endpoint.origin}.`;
|
|
21
|
+
case "invalid-response": return `llama-server returned an invalid response from ${result.path} at ${result.endpoint.origin}.`;
|
|
22
|
+
default: throw new Error("Unexpected llama-server discovery result");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function stripAuthOverrides(provider, removeAuthorization) {
|
|
26
|
+
if (!provider) return provider;
|
|
27
|
+
const headers = removeAuthorization ? stripAuthorizationHeader(provider.headers) : provider.headers;
|
|
28
|
+
return {
|
|
29
|
+
...provider,
|
|
30
|
+
auth: void 0,
|
|
31
|
+
apiKey: void 0,
|
|
32
|
+
...removeAuthorization ? { headers } : {}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function stripEndpointCredentials(provider) {
|
|
36
|
+
if (!provider) return;
|
|
37
|
+
const { localService: _localService, ...external } = provider;
|
|
38
|
+
if (!provider.localService) return {
|
|
39
|
+
...external,
|
|
40
|
+
auth: void 0,
|
|
41
|
+
apiKey: void 0,
|
|
42
|
+
headers: void 0
|
|
43
|
+
};
|
|
44
|
+
const { auth: _auth, apiKey: _apiKey, headers: _headers, localService: _managedService, models: _managedModels, params: managedParams, timeoutSeconds: _managedTimeout, ...externalProvider } = provider;
|
|
45
|
+
const { modelCacheDir: _modelCacheDir, ...params } = managedParams ?? {};
|
|
46
|
+
return {
|
|
47
|
+
...externalProvider,
|
|
48
|
+
models: [],
|
|
49
|
+
params: Object.keys(params).length > 0 ? params : void 0
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function hasEndpointChanged(provider, baseUrl) {
|
|
53
|
+
if (!provider) return false;
|
|
54
|
+
const configuredBaseUrl = provider.baseUrl ?? "http://127.0.0.1:8080";
|
|
55
|
+
return resolveLlamaServerEndpoint(configuredBaseUrl).inferenceBaseUrl !== resolveLlamaServerEndpoint(baseUrl).inferenceBaseUrl;
|
|
56
|
+
}
|
|
57
|
+
function stripLlamaServerEndpointAuth(config) {
|
|
58
|
+
const withoutProfile = removeAuthProfileConfig(config, LLAMA_CPP_DEFAULT_PROFILE_ID);
|
|
59
|
+
const provider = withoutProfile.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
60
|
+
const endpointSafeProvider = stripEndpointCredentials(provider);
|
|
61
|
+
if (!endpointSafeProvider) return withoutProfile;
|
|
62
|
+
return {
|
|
63
|
+
...withoutProfile,
|
|
64
|
+
models: {
|
|
65
|
+
...withoutProfile.models,
|
|
66
|
+
providers: {
|
|
67
|
+
...withoutProfile.models?.providers,
|
|
68
|
+
[LLAMA_CPP_PROVIDER_ID]: endpointSafeProvider
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function stripAuthorizationHeader(headers) {
|
|
74
|
+
const filtered = Object.fromEntries(Object.entries(headers ?? {}).filter(([name]) => name.toLowerCase() !== "authorization"));
|
|
75
|
+
return Object.keys(filtered).length > 0 ? filtered : void 0;
|
|
76
|
+
}
|
|
77
|
+
function buildExistingProviderConfig(params) {
|
|
78
|
+
const configured = params.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
79
|
+
const endpointSafe = params.resetEndpoint ? stripEndpointCredentials(configured) : configured;
|
|
80
|
+
const existing = params.persistence.kind === "preserve" ? endpointSafe : stripAuthOverrides(endpointSafe, params.persistence.kind === "upsert");
|
|
81
|
+
return buildLlamaServerProviderConfig({
|
|
82
|
+
configured: {
|
|
83
|
+
...existing,
|
|
84
|
+
baseUrl: params.discovery.endpoint.inferenceBaseUrl,
|
|
85
|
+
models: existing?.models ?? []
|
|
86
|
+
},
|
|
87
|
+
discoveredModels: params.discovery.models
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function buildSetupResult(params) {
|
|
91
|
+
return {
|
|
92
|
+
profiles: params.persistence.kind === "upsert" ? [{
|
|
93
|
+
profileId: LLAMA_CPP_DEFAULT_PROFILE_ID,
|
|
94
|
+
credential: buildApiKeyCredential(LLAMA_CPP_PROVIDER_ID, params.persistence.credential, void 0, { config: params.config })
|
|
95
|
+
}] : [],
|
|
96
|
+
defaultModel: `${LLAMA_CPP_PROVIDER_ID}/${params.modelId}`,
|
|
97
|
+
configPatch: {
|
|
98
|
+
...params.persistence.kind === "remove" ? buildLlamaCppAuthProfileRemovalPatch(params.config) : {},
|
|
99
|
+
models: {
|
|
100
|
+
mode: params.config.models?.mode ?? "merge",
|
|
101
|
+
providers: { [LLAMA_CPP_PROVIDER_ID]: buildExistingProviderConfig(params) }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
async function removeDefaultAuthProfile(config, agentDir) {
|
|
107
|
+
if (!await removeProviderAuthProfilesWithLock({
|
|
108
|
+
cfg: config,
|
|
109
|
+
agentDir,
|
|
110
|
+
provider: "llama-cpp",
|
|
111
|
+
profileIds: [LLAMA_CPP_DEFAULT_PROFILE_ID]
|
|
112
|
+
})) throw new Error("Failed to remove the previous llama-server auth profile; wait a moment and retry.");
|
|
113
|
+
}
|
|
114
|
+
async function discoverForSetup(ctx) {
|
|
115
|
+
const provider = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
116
|
+
if (provider?.localService) return null;
|
|
117
|
+
try {
|
|
118
|
+
const headers = await resolveLlamaServerProviderHeaders({
|
|
119
|
+
config: ctx.config,
|
|
120
|
+
env: ctx.env,
|
|
121
|
+
headers: provider?.headers
|
|
122
|
+
});
|
|
123
|
+
const apiKey = !hasLlamaServerAuthorizationHeader(headers) ? await resolveLlamaServerRuntimeApiKey({ config: ctx.config }) : void 0;
|
|
124
|
+
const discovery = await discoverLlamaServer({
|
|
125
|
+
baseUrl: provider?.baseUrl ?? "http://127.0.0.1:8080",
|
|
126
|
+
apiKey,
|
|
127
|
+
headers,
|
|
128
|
+
allowPrivateNetwork: provider?.request?.allowPrivateNetwork,
|
|
129
|
+
signal: ctx.signal,
|
|
130
|
+
useRuntimeDefaults: false
|
|
131
|
+
});
|
|
132
|
+
return discovery.kind === "success" ? discovery : null;
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Read-only discovery for the guided local-provider setup ladder. */
|
|
138
|
+
async function detectLlamaServerSetup(ctx) {
|
|
139
|
+
const discovery = await discoverForSetup(ctx);
|
|
140
|
+
if (!discovery) return null;
|
|
141
|
+
const modelId = selectSetupModelId(discovery);
|
|
142
|
+
if (!modelId) return null;
|
|
143
|
+
return {
|
|
144
|
+
modelRef: `${LLAMA_CPP_PROVIDER_ID}/${modelId}`,
|
|
145
|
+
detail: `${modelId} at ${discovery.endpoint.origin}`
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/** Rechecks one guided candidate and returns the config needed for a live probe. */
|
|
149
|
+
async function prepareLlamaServerSetup(ctx) {
|
|
150
|
+
const discovery = await discoverForSetup(ctx);
|
|
151
|
+
if (!discovery) return null;
|
|
152
|
+
const prefix = `${LLAMA_CPP_PROVIDER_ID}/`;
|
|
153
|
+
const modelId = ctx.modelRef.startsWith(prefix) ? ctx.modelRef.slice(prefix.length) : "";
|
|
154
|
+
if (!modelId || !discovery.models.some((model) => model.config.id === modelId)) return null;
|
|
155
|
+
return buildSetupResult({
|
|
156
|
+
config: ctx.config,
|
|
157
|
+
discovery,
|
|
158
|
+
modelId,
|
|
159
|
+
resetEndpoint: false,
|
|
160
|
+
persistence: { kind: "preserve" }
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/** Interactive setup for an existing llama-server endpoint. */
|
|
164
|
+
async function runLlamaServerSetup(ctx) {
|
|
165
|
+
const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
166
|
+
const defaultOrigin = resolveLlamaServerEndpoint(existing?.baseUrl).origin;
|
|
167
|
+
const baseUrl = await ctx.prompter.text({
|
|
168
|
+
message: `${LLAMA_CPP_PROVIDER_LABEL} URL`,
|
|
169
|
+
initialValue: defaultOrigin,
|
|
170
|
+
placeholder: LLAMA_SERVER_DEFAULT_ORIGIN,
|
|
171
|
+
validate: (value) => {
|
|
172
|
+
if (!value?.trim()) return "Required";
|
|
173
|
+
try {
|
|
174
|
+
resolveLlamaServerEndpoint(value);
|
|
175
|
+
return;
|
|
176
|
+
} catch {
|
|
177
|
+
return "Enter a valid HTTP or HTTPS URL without embedded credentials (e.g. http://localhost:8080).";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
const endpoint = resolveLlamaServerEndpoint(baseUrl);
|
|
182
|
+
const endpointChanged = Boolean(existing?.localService) || hasEndpointChanged(existing, endpoint.inferenceBaseUrl);
|
|
183
|
+
const resolvedHeaders = endpointChanged ? void 0 : await resolveLlamaServerProviderHeaders({
|
|
184
|
+
config: ctx.config,
|
|
185
|
+
env: ctx.env,
|
|
186
|
+
headers: existing?.headers
|
|
187
|
+
});
|
|
188
|
+
const usesApiKey = await ctx.prompter.confirm({
|
|
189
|
+
message: "Does this llama-server require an API key?",
|
|
190
|
+
initialValue: false
|
|
191
|
+
});
|
|
192
|
+
let apiKey;
|
|
193
|
+
let headers = resolvedHeaders;
|
|
194
|
+
let persistence;
|
|
195
|
+
if (!usesApiKey) persistence = { kind: "remove" };
|
|
196
|
+
else {
|
|
197
|
+
const hasConfiguredProfile = Boolean(ctx.config.auth?.profiles?.[LLAMA_CPP_DEFAULT_PROFILE_ID]);
|
|
198
|
+
const profileApiKey = !endpointChanged && !hasLlamaServerAuthorizationHeader(resolvedHeaders) && hasConfiguredProfile ? await resolveLlamaServerRuntimeApiKey({
|
|
199
|
+
config: ctx.config,
|
|
200
|
+
agentDir: ctx.agentDir,
|
|
201
|
+
profileId: LLAMA_CPP_DEFAULT_PROFILE_ID
|
|
202
|
+
}) : void 0;
|
|
203
|
+
if (profileApiKey) {
|
|
204
|
+
apiKey = profileApiKey;
|
|
205
|
+
persistence = { kind: "preserve" };
|
|
206
|
+
} else {
|
|
207
|
+
let credentialInput;
|
|
208
|
+
apiKey = await ensureApiKeyFromEnvOrPrompt({
|
|
209
|
+
config: endpointChanged ? stripLlamaServerEndpointAuth(ctx.config) : ctx.config,
|
|
210
|
+
env: endpointChanged ? {} : ctx.env,
|
|
211
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
212
|
+
envLabel: LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR,
|
|
213
|
+
promptMessage: "Enter the llama-server API key",
|
|
214
|
+
normalize: (value) => value.trim(),
|
|
215
|
+
validate: (value) => value.trim() ? void 0 : "Required",
|
|
216
|
+
prompter: ctx.prompter,
|
|
217
|
+
secretInputMode: ctx.secretInputMode,
|
|
218
|
+
setCredential: async (input) => {
|
|
219
|
+
credentialInput = input;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
if (credentialInput === void 0) throw new Error("llama-server API-key setup did not produce a credential");
|
|
223
|
+
headers = stripAuthorizationHeader(resolvedHeaders);
|
|
224
|
+
persistence = {
|
|
225
|
+
kind: "upsert",
|
|
226
|
+
credential: credentialInput
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
const discovery = await discoverLlamaServer({
|
|
231
|
+
baseUrl: endpoint.inferenceBaseUrl,
|
|
232
|
+
apiKey,
|
|
233
|
+
headers,
|
|
234
|
+
allowPrivateNetwork: existing?.request?.allowPrivateNetwork,
|
|
235
|
+
signal: ctx.signal,
|
|
236
|
+
useRuntimeDefaults: false
|
|
237
|
+
});
|
|
238
|
+
if (discovery.kind !== "success") throw new Error(describeDiscoveryFailure(discovery));
|
|
239
|
+
const modelId = selectSetupModelId(discovery);
|
|
240
|
+
if (!modelId) throw new Error(`No llama-server text models were found at ${discovery.endpoint.origin}.`);
|
|
241
|
+
if (persistence.kind === "remove") await removeDefaultAuthProfile(ctx.config, ctx.agentDir);
|
|
242
|
+
return buildSetupResult({
|
|
243
|
+
config: ctx.config,
|
|
244
|
+
discovery,
|
|
245
|
+
modelId,
|
|
246
|
+
resetEndpoint: endpointChanged,
|
|
247
|
+
persistence
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
async function validateNonInteractiveDiscovery(ctx) {
|
|
251
|
+
const configuredProvider = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
|
|
252
|
+
const baseUrl = normalizeOptionalSecretInput(ctx.opts.customBaseUrl) ?? configuredProvider?.baseUrl ?? "http://127.0.0.1:8080";
|
|
253
|
+
const endpointChanged = Boolean(configuredProvider?.localService) || hasEndpointChanged(configuredProvider, baseUrl);
|
|
254
|
+
const providerApiKey = normalizeOptionalSecretInput(ctx.opts.llamaServerApiKey);
|
|
255
|
+
const customApiKey = normalizeOptionalSecretInput(ctx.opts.customApiKey);
|
|
256
|
+
const authoredApiKey = providerApiKey ?? customApiKey;
|
|
257
|
+
const hasAuthoredApiKey = authoredApiKey !== void 0;
|
|
258
|
+
const resolvedApiKey = await ctx.resolveApiKey({
|
|
259
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
260
|
+
flagValue: authoredApiKey,
|
|
261
|
+
flagName: providerApiKey === void 0 ? "--custom-api-key" : "--llama-server-api-key",
|
|
262
|
+
envVar: LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR,
|
|
263
|
+
envVarName: LLAMA_SERVER_DEFAULT_API_KEY_ENV_VAR,
|
|
264
|
+
required: false
|
|
265
|
+
});
|
|
266
|
+
const resolvedHeaders = endpointChanged ? void 0 : await resolveLlamaServerProviderHeaders({
|
|
267
|
+
config: ctx.config,
|
|
268
|
+
env: process.env,
|
|
269
|
+
headers: configuredProvider?.headers
|
|
270
|
+
});
|
|
271
|
+
let apiKey;
|
|
272
|
+
let headers = resolvedHeaders;
|
|
273
|
+
let persistence;
|
|
274
|
+
if (hasAuthoredApiKey && resolvedApiKey) {
|
|
275
|
+
apiKey = resolvedApiKey.key;
|
|
276
|
+
headers = stripAuthorizationHeader(resolvedHeaders);
|
|
277
|
+
persistence = {
|
|
278
|
+
kind: "upsert",
|
|
279
|
+
credential: resolvedApiKey
|
|
280
|
+
};
|
|
281
|
+
} else if (endpointChanged || hasLlamaServerAuthorizationHeader(resolvedHeaders)) persistence = { kind: "remove" };
|
|
282
|
+
else if (resolvedApiKey?.source === "profile") {
|
|
283
|
+
apiKey = resolvedApiKey.key;
|
|
284
|
+
persistence = { kind: "preserve" };
|
|
285
|
+
} else if (resolvedApiKey) {
|
|
286
|
+
apiKey = resolvedApiKey.key;
|
|
287
|
+
persistence = {
|
|
288
|
+
kind: "upsert",
|
|
289
|
+
credential: resolvedApiKey
|
|
290
|
+
};
|
|
291
|
+
} else persistence = { kind: "remove" };
|
|
292
|
+
const discovery = await discoverLlamaServer({
|
|
293
|
+
baseUrl,
|
|
294
|
+
apiKey,
|
|
295
|
+
headers,
|
|
296
|
+
allowPrivateNetwork: configuredProvider?.request?.allowPrivateNetwork,
|
|
297
|
+
useRuntimeDefaults: false
|
|
298
|
+
});
|
|
299
|
+
if (discovery.kind !== "success") throw new Error(describeDiscoveryFailure(discovery));
|
|
300
|
+
const requestedModelId = normalizeOptionalSecretInput(ctx.opts.customModelId);
|
|
301
|
+
const modelId = requestedModelId ?? selectSetupModelId(discovery);
|
|
302
|
+
if (!modelId || !discovery.models.some((model) => model.config.id === modelId)) {
|
|
303
|
+
const available = discovery.models.map((model) => model.config.id).join(", ");
|
|
304
|
+
throw new Error(requestedModelId ? `llama-server model ${requestedModelId} was not found. Available models: ${available}` : `No llama-server text models were found at ${discovery.endpoint.origin}.`);
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
discovery,
|
|
308
|
+
modelId,
|
|
309
|
+
resetEndpoint: endpointChanged,
|
|
310
|
+
persistence
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
async function validateLlamaServerNonInteractive(ctx) {
|
|
314
|
+
await validateNonInteractiveDiscovery(ctx);
|
|
315
|
+
return true;
|
|
316
|
+
}
|
|
317
|
+
/** Non-interactive setup with optional API-key persistence. */
|
|
318
|
+
async function configureLlamaServerNonInteractive(ctx) {
|
|
319
|
+
const validated = await validateNonInteractiveDiscovery(ctx);
|
|
320
|
+
const providerConfig = buildExistingProviderConfig({
|
|
321
|
+
config: ctx.config,
|
|
322
|
+
...validated
|
|
323
|
+
});
|
|
324
|
+
let config = {
|
|
325
|
+
...ctx.config,
|
|
326
|
+
models: {
|
|
327
|
+
...ctx.config.models,
|
|
328
|
+
mode: ctx.config.models?.mode ?? "merge",
|
|
329
|
+
providers: {
|
|
330
|
+
...ctx.config.models?.providers,
|
|
331
|
+
[LLAMA_CPP_PROVIDER_ID]: providerConfig
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
if (validated.persistence.kind === "upsert") {
|
|
336
|
+
const credential = ctx.toApiKeyCredential({
|
|
337
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
338
|
+
resolved: validated.persistence.credential
|
|
339
|
+
});
|
|
340
|
+
if (!credential) return null;
|
|
341
|
+
await upsertAuthProfileWithLockOrThrow({
|
|
342
|
+
profileId: LLAMA_CPP_DEFAULT_PROFILE_ID,
|
|
343
|
+
credential,
|
|
344
|
+
agentDir: ctx.agentDir
|
|
345
|
+
});
|
|
346
|
+
config = applyAuthProfileConfig(config, {
|
|
347
|
+
profileId: LLAMA_CPP_DEFAULT_PROFILE_ID,
|
|
348
|
+
provider: LLAMA_CPP_PROVIDER_ID,
|
|
349
|
+
mode: "api_key"
|
|
350
|
+
});
|
|
351
|
+
} else if (validated.persistence.kind === "remove") {
|
|
352
|
+
await removeDefaultAuthProfile(ctx.config, ctx.agentDir);
|
|
353
|
+
config = removeAuthProfileConfig(config, LLAMA_CPP_DEFAULT_PROFILE_ID);
|
|
354
|
+
}
|
|
355
|
+
ctx.runtime.log(`Default ${LLAMA_CPP_PROVIDER_LABEL} model: ${validated.modelId}`);
|
|
356
|
+
return applyProviderDefaultModel(config, `${LLAMA_CPP_PROVIDER_ID}/${validated.modelId}`);
|
|
357
|
+
}
|
|
358
|
+
//#endregion
|
|
359
|
+
export { configureLlamaServerNonInteractive, detectLlamaServerSetup, prepareLlamaServerSetup, runLlamaServerSetup, validateLlamaServerNonInteractive };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import "./defaults-CL2lz0cV.mjs";
|
|
2
|
+
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
|
+
import { streamSimple } from "openclaw/plugin-sdk/llm";
|
|
4
|
+
import { setQwenChatTemplateThinking } from "openclaw/plugin-sdk/provider-stream-shared";
|
|
5
|
+
//#region extensions/llama-cpp/src/external-server/stream.ts
|
|
6
|
+
/** Maps shared structured-output requests to the shape accepted by older llama-server builds. */
|
|
7
|
+
function normalizeLlamaServerResponseFormat(payload, requestedResponseFormat) {
|
|
8
|
+
const responseFormat = isRecord(payload.response_format) ? payload.response_format : requestedResponseFormat;
|
|
9
|
+
if (!responseFormat || responseFormat.type === "text") return;
|
|
10
|
+
const schema = responseFormat.type === "json_schema" ? isRecord(responseFormat.json_schema) ? responseFormat.json_schema.schema : responseFormat.schema : responseFormat.type === "json_object" ? responseFormat.schema : responseFormat;
|
|
11
|
+
if (isRecord(schema)) payload.response_format = {
|
|
12
|
+
type: "json_object",
|
|
13
|
+
schema
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Keeps the shared OpenAI transport and adjusts llama-server request compatibility. */
|
|
17
|
+
function wrapLlamaServerStream(ctx) {
|
|
18
|
+
const underlying = ctx.streamFn ?? streamSimple;
|
|
19
|
+
return (model, context, options) => {
|
|
20
|
+
if (model.provider !== "llama-cpp") return underlying(model, context, options);
|
|
21
|
+
const onPayload = options?.onPayload;
|
|
22
|
+
return underlying(model, context, {
|
|
23
|
+
...options,
|
|
24
|
+
onPayload: async (payload, requestModel) => {
|
|
25
|
+
const customized = await onPayload?.(payload, requestModel) ?? payload;
|
|
26
|
+
if (isRecord(customized)) {
|
|
27
|
+
if ((options?.reasoning ?? ctx.thinkingLevel) === "off") setQwenChatTemplateThinking(customized, false);
|
|
28
|
+
normalizeLlamaServerResponseFormat(customized, options?.responseFormat);
|
|
29
|
+
}
|
|
30
|
+
return customized;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { wrapLlamaServerStream };
|