@openclaw/llama-cpp-provider 2026.11.3 → 2026.11.5-beta.2

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.
@@ -1,12 +1,12 @@
1
- import { C as resolveLegacyLlamaCppModelCacheDir, D as resolveLlamaCppModelSource, E as resolveLlamaCppModelCacheDir, T as resolveLlamaCppEmbeddingModel, _ as LLAMA_CPP_PROVIDER_ID, b as buildLlamaCppProviderConfig, l as DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE, x as resolveCachedLlamaCppModelPath } from "./defaults-DX4XN2j1.mjs";
1
+ import { C as resolveLegacyLlamaCppModelCacheDir, D as resolveLlamaCppModelSource, E as resolveLlamaCppModelCacheDir, T as resolveLlamaCppEmbeddingModel, _ as LLAMA_CPP_PROVIDER_ID, b as buildLlamaCppProviderConfig, l as DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE, x as resolveCachedLlamaCppModelPath } from "./defaults-CZr5jpH7.mjs";
2
2
  import { o as resolveLlamaCppMediaModels } from "./media-config-CZ7CluNV.mjs";
3
- import { c as formatLlamaCppMemory, i as recommendLlamaCppModel, m as selectLlamaServerAsset, o as resolveLlamaCppModelCandidates, p as resolveManagedLlamaServerPaths, s as detectLlamaCppHardware } from "./media-catalog-BwFQGYtY.mjs";
4
- import { ensureLlamaCppModel, n as UnsupportedLlamaServerHostError, prepareManagedLlamaServer, r as ensureLlamaServerInstalled, resolveLlamaCppModelDownloadSize } from "./managed-server-Bjr1c5yX.mjs";
5
- import { n as buildLlamaCppAuthProfileRemovalPatch } from "./auth-config-Dx2WDi-G.mjs";
3
+ import { c as formatLlamaCppMemory, i as recommendLlamaCppModel, o as resolveLlamaCppModelCandidates, s as detectLlamaCppHardware } from "./media-catalog-DgRc3mpW.mjs";
4
+ import { a as resolveManagedLlamaServerPaths, ensureLlamaCppModel, n as UnsupportedLlamaServerHostError, o as selectLlamaServerAsset, prepareManagedLlamaServer, r as ensureLlamaServerInstalled, resolveLlamaCppModelDownloadSize } from "./managed-server-CZGhj7j8.mjs";
5
+ import { n as buildLlamaCppAuthProfileRemovalPatch } from "./auth-config-BJOlAPuO.mjs";
6
6
  import path from "node:path";
7
7
  import os from "node:os";
8
- import fs from "node:fs/promises";
9
8
  import { listAgentIds, resolveAgentConfig } from "openclaw/plugin-sdk/agent-scope-runtime";
9
+ import { safeStat } from "openclaw/plugin-sdk/path-existence-runtime";
10
10
  import { mergeDeep } from "openclaw/plugin-sdk/plugin-config-runtime";
11
11
  //#region extensions/llama-cpp/src/setup.ts
12
12
  const BYTES_PER_GB = 1e9;
@@ -37,9 +37,6 @@ async function configuredCandidates(config) {
37
37
  const primaryId = primary.provider === "llama-cpp" ? primary.model : void 0;
38
38
  return candidates.toSorted((a, b) => Number(b.model.id === primaryId) - Number(a.model.id === primaryId));
39
39
  }
40
- async function isFile(filePath) {
41
- return await fs.stat(filePath).then((stat) => stat.isFile()).catch(() => false);
42
- }
43
40
  async function resolveCachedArtifact(source, cacheDir, signal) {
44
41
  return await ensureLlamaCppModel({
45
42
  source,
@@ -53,10 +50,10 @@ async function resolveCachedArtifact(source, cacheDir, signal) {
53
50
  async function resolveCachedCandidate(candidate, signal) {
54
51
  const source = resolveLlamaCppModelSource(candidate.model);
55
52
  const resolved = resolveCachedLlamaCppModelPath(candidate);
56
- if (resolved && await isFile(resolved)) return resolved;
53
+ if (resolved && (await safeStat(resolved))?.isFile()) return resolved;
57
54
  if (candidate.model.id === "gemma-4-e4b-it-q4_k_m") {
58
55
  const legacy = path.join(resolveLegacyLlamaCppModelCacheDir(), DEFAULT_LLAMA_CPP_MODEL_CACHE_FILE);
59
- if (await isFile(legacy)) return legacy;
56
+ if ((await safeStat(legacy))?.isFile()) return legacy;
60
57
  }
61
58
  if (/^(?:hf|huggingface|https):/iu.test(source)) return await resolveCachedArtifact(source, resolveLlamaCppModelCacheDir(candidate.provider), signal);
62
59
  }
@@ -83,7 +80,7 @@ async function detectLlamaCppSetup(ctx) {
83
80
  const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
84
81
  const command = existing?.localService?.command;
85
82
  const presetPath = existing?.localService?.args?.find((_, index, args) => args[index - 1] === "--models-preset");
86
- if (!command || !path.isAbsolute(command) || !await isFile(command) || !presetPath || !await isFile(presetPath)) return null;
83
+ if (!command || !path.isAbsolute(command) || !(await safeStat(command))?.isFile() || !presetPath || !(await safeStat(presetPath))?.isFile()) return null;
87
84
  for (const candidate of await configuredCandidates(ctx.config)) if (await resolveCachedCandidate(candidate, ctx.signal)) return {
88
85
  modelRef: `${LLAMA_CPP_PROVIDER_ID}/${candidate.model.id}`,
89
86
  detail: "Managed llama.cpp server ready"
@@ -108,123 +105,6 @@ async function prepareLlamaCppSetup(ctx) {
108
105
  }
109
106
  });
110
107
  }
111
- function resolveEmbeddingSetup(config, cacheDir) {
112
- const defaults = config.memory?.search;
113
- const models = listAgentIds(config).flatMap((agentId) => {
114
- const override = resolveAgentConfig(config, agentId)?.memory?.search;
115
- if (!(override?.enabled ?? defaults?.enabled ?? true) || (override?.provider ?? defaults?.provider) !== "local") return [];
116
- return [resolveLlamaCppEmbeddingModel({
117
- modelPath: override?.local?.modelPath ?? defaults?.local?.modelPath,
118
- modelCacheDir: cacheDir
119
- })];
120
- });
121
- const model = models[0] ?? resolveLlamaCppEmbeddingModel({ modelCacheDir: cacheDir });
122
- return {
123
- model,
124
- localMemoryIntent: models.length > 0,
125
- conflict: models.some((candidate) => candidate.source !== model.source)
126
- };
127
- }
128
- async function resolveSetupPlan(ctx, candidates, embeddingModelIsDefault, localMemoryIntent, hardware, asset, runtimeNote) {
129
- if (ctx.embeddingOnly) return await resolveEmbeddingOnlyPlan(ctx, candidates, localMemoryIntent);
130
- let candidate = candidates[0];
131
- const configuredPath = candidate ? await resolveCachedCandidate(candidate, ctx.signal) : void 0;
132
- if (candidate && configuredPath) {
133
- if (runtimeNote && !await ctx.prompter.confirm({
134
- message: `${runtimeNote} Use cached ${candidate.model.name} on Gateway host ${os.hostname()} with the verified CPU runtime?`,
135
- initialValue: false
136
- })) return;
137
- return {
138
- kind: "chat",
139
- candidate,
140
- cachedPath: configuredPath
141
- };
142
- }
143
- const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
144
- const provider = existing?.localService ? existing : buildLlamaCppProviderConfig();
145
- const cacheDir = resolveLlamaCppModelCacheDir(provider);
146
- if (candidate) {
147
- const source = resolveLlamaCppModelSource(candidate.model);
148
- let size;
149
- try {
150
- if (path.isAbsolute(source) || !/^[a-z][a-z\d+.-]*:/iu.test(source)) {
151
- const cachedPath = await ensureLlamaCppModel({
152
- source,
153
- cacheDir,
154
- download: false,
155
- signal: ctx.signal
156
- });
157
- return {
158
- kind: "chat",
159
- candidate,
160
- cachedPath
161
- };
162
- }
163
- size = await resolveLlamaCppModelDownloadSize(source, cacheDir, ctx.signal);
164
- } catch (error) {
165
- ctx.signal?.throwIfAborted();
166
- await ctx.prompter.note(`Cannot use configured model ${candidate.model.name}: ${error instanceof Error ? error.message : String(error)} Check params.modelPath and retry llama.cpp setup.`, "Setup skipped");
167
- return;
168
- }
169
- return await ctx.prompter.confirm({
170
- message: `${runtimeNote ? `${runtimeNote}\n` : ""}Download ${candidate.model.name} (${size ? `${(size / BYTES_PER_GB).toFixed(1)} GB` : "size unknown"}), ${describeEmbeddingDownload(embeddingModelIsDefault)}, and the verified ${asset.backend.toUpperCase()} runtime on Gateway host ${os.hostname()}, then use this model?`,
171
- initialValue: false
172
- }) ? {
173
- kind: "chat",
174
- candidate
175
- } : void 0;
176
- }
177
- const cachedModels = /* @__PURE__ */ new Map();
178
- for (const recipe of resolveLlamaCppModelCandidates(hardware, asset.backend).recipes) {
179
- const cached = await resolveCachedArtifact(resolveLlamaCppModelSource(recipe.model), cacheDir, ctx.signal);
180
- if (cached) {
181
- cachedModels.set(recipe.model.id, cached);
182
- break;
183
- }
184
- }
185
- const cachedEmbedding = embeddingModelIsDefault && Boolean(await resolveCachedArtifact("hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf", cacheDir, ctx.signal));
186
- const recommendation = recommendLlamaCppModel(hardware, asset.backend, {
187
- modelIds: new Set(cachedModels.keys()),
188
- embedding: cachedEmbedding,
189
- runtime: await isFile(resolveManagedLlamaServerPaths(asset).command)
190
- });
191
- if (recommendation.kind === "recommended") {
192
- const { recipe } = recommendation;
193
- const cachedPath = cachedModels.get(recipe.model.id);
194
- candidate = {
195
- model: recipe.model,
196
- provider
197
- };
198
- const recommendationSummary = [
199
- `Runs on Gateway host ${os.hostname()} (${hardware.platform}/${hardware.arch}), using ${asset.backend === "metal" ? "Apple Metal" : asset.backend === "cuda" ? "NVIDIA CUDA" : "the CPU"}.`,
200
- `${formatLlamaCppMemory(hardware.totalMemoryBytes)} RAM; ${formatLlamaCppMemory(hardware.availableDiskBytes ?? 0)} free disk.`,
201
- !hardware.sharedDisk ? `${formatLlamaCppMemory(hardware.availableRuntimeDiskBytes ?? 0)} free on the runtime volume.` : void 0,
202
- runtimeNote,
203
- recommendation.reason,
204
- !embeddingModelIsDefault ? "This estimate includes the default embedding model; your configured embedding model may need more memory and disk space." : void 0,
205
- "OpenClaw will check a real tool call before making this your default model."
206
- ].filter(Boolean).join("\n");
207
- if (await ctx.prompter.confirm({
208
- message: `${recommendationSummary}\n\n${cachedPath ? `Use cached ${recipe.model.name}, download any missing embedding and ${asset.backend.toUpperCase()} runtime files, then use this model?` : `Download ${recipe.model.name} (${(recipe.sizeBytes / BYTES_PER_GB).toFixed(1)} GB), ${describeEmbeddingDownload(embeddingModelIsDefault)}, and the verified ${asset.backend.toUpperCase()} runtime, then use this model?`}`,
209
- initialValue: false
210
- })) return {
211
- kind: "chat",
212
- candidate,
213
- cachedPath
214
- };
215
- } else if (!localMemoryIntent) {
216
- await ctx.prompter.note(recommendation.reason, "Setup skipped");
217
- return;
218
- }
219
- const embeddingPlan = await resolveEmbeddingOnlyPlan(ctx, candidates, localMemoryIntent);
220
- if (embeddingPlan) {
221
- if (await ctx.prompter.confirm({
222
- message: `${runtimeNote ? `${runtimeNote} ` : ""}Install a verified ${asset.backend.toUpperCase()} llama.cpp server on Gateway host ${os.hostname()} and download only ${describeEmbeddingDownload(embeddingModelIsDefault)}? Your chat model will stay unchanged.`,
223
- initialValue: false
224
- })) return embeddingPlan;
225
- }
226
- await ctx.prompter.note("Local model setup skipped.", "Setup skipped");
227
- }
228
108
  async function resolveEmbeddingOnlyPlan(ctx, candidates, localMemoryIntent) {
229
109
  const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
230
110
  if (localMemoryIntent && existing && (!existing.localService || candidates.length > 0)) {
@@ -238,12 +118,21 @@ async function runLlamaCppSetup(ctx) {
238
118
  const managedExisting = existing?.localService ? existing : void 0;
239
119
  const mediaModels = resolveLlamaCppMediaModels(managedExisting);
240
120
  const cacheDir = resolveLlamaCppModelCacheDir(managedExisting);
241
- const embeddingSetup = resolveEmbeddingSetup(ctx.config, cacheDir);
242
- if (embeddingSetup.conflict) {
121
+ const defaults = ctx.config.memory?.search;
122
+ const models = listAgentIds(ctx.config).flatMap((agentId) => {
123
+ const override = resolveAgentConfig(ctx.config, agentId)?.memory?.search;
124
+ if (!(override?.enabled ?? defaults?.enabled ?? true) || (override?.provider ?? defaults?.provider) !== "local") return [];
125
+ return [resolveLlamaCppEmbeddingModel({
126
+ modelPath: override?.local?.modelPath ?? defaults?.local?.modelPath,
127
+ modelCacheDir: cacheDir
128
+ })];
129
+ });
130
+ const embeddingModel = models[0] ?? resolveLlamaCppEmbeddingModel({ modelCacheDir: cacheDir });
131
+ const localMemoryIntent = models.length > 0;
132
+ if (models.some((candidate) => candidate.source !== embeddingModel.source)) {
243
133
  await ctx.prompter.note("Configured agents resolve to different local embedding models. Set memory.search.local.modelPath and any per-agent overrides to the same value, then retry llama.cpp setup.", "Setup skipped");
244
134
  return { profiles: [] };
245
135
  }
246
- const embeddingModel = embeddingSetup.model;
247
136
  const hardware = await detectLlamaCppHardware({
248
137
  cacheDir,
249
138
  signal: ctx.signal
@@ -257,7 +146,109 @@ async function runLlamaCppSetup(ctx) {
257
146
  asset = selectLlamaServerAsset(hardware.platform, hardware.arch, { kind: "cpu" });
258
147
  runtimeNote = `${error instanceof Error ? error.message : String(error)} This recommendation uses CPU execution.`;
259
148
  }
260
- const plan = await resolveSetupPlan(ctx, await configuredCandidates(ctx.config), embeddingModel.isDefault, embeddingSetup.localMemoryIntent, hardware, asset, runtimeNote);
149
+ const candidates = await configuredCandidates(ctx.config);
150
+ async function resolveSetupPlan() {
151
+ const embeddingModelIsDefault = embeddingModel.isDefault;
152
+ if (ctx.embeddingOnly) return await resolveEmbeddingOnlyPlan(ctx, candidates, localMemoryIntent);
153
+ let candidate = candidates[0];
154
+ const configuredPath = candidate ? await resolveCachedCandidate(candidate, ctx.signal) : void 0;
155
+ if (candidate && configuredPath) {
156
+ if (runtimeNote && !await ctx.prompter.confirm({
157
+ message: `${runtimeNote} Use cached ${candidate.model.name} on Gateway host ${os.hostname()} with the verified CPU runtime?`,
158
+ initialValue: false
159
+ })) return;
160
+ return {
161
+ kind: "chat",
162
+ candidate,
163
+ cachedPath: configuredPath
164
+ };
165
+ }
166
+ const planExisting = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
167
+ const provider = planExisting?.localService ? planExisting : buildLlamaCppProviderConfig();
168
+ const planCacheDir = resolveLlamaCppModelCacheDir(provider);
169
+ if (candidate) {
170
+ const source = resolveLlamaCppModelSource(candidate.model);
171
+ let size;
172
+ try {
173
+ if (path.isAbsolute(source) || !/^[a-z][a-z\d+.-]*:/iu.test(source)) {
174
+ const cachedPath = await ensureLlamaCppModel({
175
+ source,
176
+ cacheDir: planCacheDir,
177
+ download: false,
178
+ signal: ctx.signal
179
+ });
180
+ return {
181
+ kind: "chat",
182
+ candidate,
183
+ cachedPath
184
+ };
185
+ }
186
+ size = await resolveLlamaCppModelDownloadSize(source, planCacheDir, ctx.signal);
187
+ } catch (error) {
188
+ ctx.signal?.throwIfAborted();
189
+ await ctx.prompter.note(`Cannot use configured model ${candidate.model.name}: ${error instanceof Error ? error.message : String(error)} Check params.modelPath and retry llama.cpp setup.`, "Setup skipped");
190
+ return;
191
+ }
192
+ return await ctx.prompter.confirm({
193
+ message: `${runtimeNote ? `${runtimeNote}\n` : ""}Download ${candidate.model.name} (${size ? `${(size / BYTES_PER_GB).toFixed(1)} GB` : "size unknown"}), ${describeEmbeddingDownload(embeddingModelIsDefault)}, and the verified ${asset.backend.toUpperCase()} runtime on Gateway host ${os.hostname()}, then use this model?`,
194
+ initialValue: false
195
+ }) ? {
196
+ kind: "chat",
197
+ candidate
198
+ } : void 0;
199
+ }
200
+ const cachedModels = /* @__PURE__ */ new Map();
201
+ for (const recipe of resolveLlamaCppModelCandidates(hardware, asset.backend).recipes) {
202
+ const cached = await resolveCachedArtifact(resolveLlamaCppModelSource(recipe.model), planCacheDir, ctx.signal);
203
+ if (cached) {
204
+ cachedModels.set(recipe.model.id, cached);
205
+ break;
206
+ }
207
+ }
208
+ const cachedEmbedding = embeddingModelIsDefault && Boolean(await resolveCachedArtifact("hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf", planCacheDir, ctx.signal));
209
+ const recommendation = recommendLlamaCppModel(hardware, asset.backend, {
210
+ modelIds: new Set(cachedModels.keys()),
211
+ embedding: cachedEmbedding,
212
+ runtime: (await safeStat(resolveManagedLlamaServerPaths(asset).command))?.isFile() === true
213
+ });
214
+ if (recommendation.kind === "recommended") {
215
+ const { recipe } = recommendation;
216
+ const cachedPath = cachedModels.get(recipe.model.id);
217
+ candidate = {
218
+ model: recipe.model,
219
+ provider
220
+ };
221
+ const recommendationSummary = [
222
+ `Runs on Gateway host ${os.hostname()} (${hardware.platform}/${hardware.arch}), using ${asset.backend === "metal" ? "Apple Metal" : asset.backend === "cuda" ? "NVIDIA CUDA" : "the CPU"}.`,
223
+ `${formatLlamaCppMemory(hardware.totalMemoryBytes)} RAM; ${formatLlamaCppMemory(hardware.availableDiskBytes ?? 0)} free disk.`,
224
+ !hardware.sharedDisk ? `${formatLlamaCppMemory(hardware.availableRuntimeDiskBytes ?? 0)} free on the runtime volume.` : void 0,
225
+ runtimeNote,
226
+ recommendation.reason,
227
+ !embeddingModelIsDefault ? "This estimate includes the default embedding model; your configured embedding model may need more memory and disk space." : void 0,
228
+ "OpenClaw will check a real tool call before making this your default model."
229
+ ].filter(Boolean).join("\n");
230
+ if (await ctx.prompter.confirm({
231
+ message: `${recommendationSummary}\n\n${cachedPath ? `Use cached ${recipe.model.name}, download any missing embedding and ${asset.backend.toUpperCase()} runtime files, then use this model?` : `Download ${recipe.model.name} (${(recipe.sizeBytes / BYTES_PER_GB).toFixed(1)} GB), ${describeEmbeddingDownload(embeddingModelIsDefault)}, and the verified ${asset.backend.toUpperCase()} runtime, then use this model?`}`,
232
+ initialValue: false
233
+ })) return {
234
+ kind: "chat",
235
+ candidate,
236
+ cachedPath
237
+ };
238
+ } else if (!localMemoryIntent) {
239
+ await ctx.prompter.note(recommendation.reason, "Setup skipped");
240
+ return;
241
+ }
242
+ const embeddingPlan = await resolveEmbeddingOnlyPlan(ctx, candidates, localMemoryIntent);
243
+ if (embeddingPlan) {
244
+ if (await ctx.prompter.confirm({
245
+ message: `${runtimeNote ? `${runtimeNote} ` : ""}Install a verified ${asset.backend.toUpperCase()} llama.cpp server on Gateway host ${os.hostname()} and download only ${describeEmbeddingDownload(embeddingModelIsDefault)}? Your chat model will stay unchanged.`,
246
+ initialValue: false
247
+ })) return embeddingPlan;
248
+ }
249
+ await ctx.prompter.note("Local model setup skipped.", "Setup skipped");
250
+ }
251
+ const plan = await resolveSetupPlan();
261
252
  if (!plan) return { profiles: [] };
262
253
  const progress = ctx.prompter.progress(`${ctx.embeddingOnly && runtimeNote ? `${runtimeNote}\n` : ""}Preparing managed llama.cpp server…`);
263
254
  try {
@@ -1,12 +1,12 @@
1
- import { _ as LLAMA_CPP_PROVIDER_ID, v as LLAMA_CPP_PROVIDER_LABEL } from "./defaults-DX4XN2j1.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-SxEYhgMV.mjs";
3
- import { i as resolveLlamaServerRuntimeApiKey, n as buildLlamaServerProviderConfig, r as resolveLlamaServerProviderHeaders, t as discoverLlamaServer } from "./discovery-osk0TXQN.mjs";
4
- import { n as buildLlamaCppAuthProfileRemovalPatch, t as LLAMA_CPP_DEFAULT_PROFILE_ID } from "./auth-config-Dx2WDi-G.mjs";
1
+ import { _ as LLAMA_CPP_PROVIDER_ID, v as LLAMA_CPP_PROVIDER_LABEL } from "./defaults-CZr5jpH7.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-D3_7fprf.mjs";
3
+ import { i as resolveLlamaServerRuntimeApiKey, n as buildLlamaServerProviderConfig, r as resolveLlamaServerProviderHeaders, t as discoverLlamaServer } from "./discovery-CghcMQy6.mjs";
4
+ import { n as buildLlamaCppAuthProfileRemovalPatch, t as LLAMA_CPP_DEFAULT_PROFILE_ID } from "./auth-config-BJOlAPuO.mjs";
5
5
  import { applyAuthProfileConfig, buildApiKeyCredential, ensureApiKeyFromEnvOrPrompt, normalizeOptionalSecretInput } from "openclaw/plugin-sdk/provider-auth";
6
6
  import { removeAuthProfileConfig, removeProviderAuthProfilesWithLock } from "openclaw/plugin-sdk/provider-auth-runtime";
7
7
  import { applyProviderDefaultModel } from "openclaw/plugin-sdk/provider-setup";
8
- import { selectPreferredLocalModelId } from "openclaw/plugin-sdk/provider-model-shared";
9
8
  import { upsertAuthProfileWithLockOrThrow } from "openclaw/plugin-sdk/provider-auth-api-key";
9
+ import { selectPreferredLocalModelId } from "openclaw/plugin-sdk/provider-model-shared";
10
10
  //#region extensions/llama-cpp/src/external-server/setup.ts
11
11
  function selectSetupModelId(discovery) {
12
12
  const candidates = discovery.models.filter((model) => !model.failed);
@@ -160,16 +160,14 @@ async function prepareLlamaServerSetup(ctx) {
160
160
  persistence: { kind: "preserve" }
161
161
  });
162
162
  }
163
- /** Interactive setup for an existing llama-server endpoint. */
164
163
  async function runLlamaServerSetup(ctx) {
165
164
  const existing = ctx.config.models?.providers?.[LLAMA_CPP_PROVIDER_ID];
166
- const defaultOrigin = resolveLlamaServerEndpoint(existing?.baseUrl).origin;
167
165
  const baseUrl = await ctx.prompter.text({
168
166
  message: `${LLAMA_CPP_PROVIDER_LABEL} URL`,
169
- initialValue: defaultOrigin,
167
+ initialValue: existing?.baseUrl ? resolveLlamaServerEndpoint(existing.baseUrl).origin : void 0,
170
168
  placeholder: LLAMA_SERVER_DEFAULT_ORIGIN,
171
169
  validate: (value) => {
172
- if (!value?.trim()) return "Required";
170
+ if (!value.trim()) return;
173
171
  try {
174
172
  resolveLlamaServerEndpoint(value);
175
173
  return;
@@ -178,7 +176,7 @@ async function runLlamaServerSetup(ctx) {
178
176
  }
179
177
  }
180
178
  });
181
- const endpoint = resolveLlamaServerEndpoint(baseUrl);
179
+ const endpoint = resolveLlamaServerEndpoint(baseUrl.trim() || existing?.baseUrl);
182
180
  const endpointChanged = Boolean(existing?.localService) || hasEndpointChanged(existing, endpoint.inferenceBaseUrl);
183
181
  const resolvedHeaders = endpointChanged ? void 0 : await resolveLlamaServerProviderHeaders({
184
182
  config: ctx.config,
@@ -1,7 +1,8 @@
1
- import "./defaults-DX4XN2j1.mjs";
1
+ import "./defaults-CZr5jpH7.mjs";
2
2
  import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { streamSimple } from "openclaw/plugin-sdk/llm";
4
4
  import { setQwenChatTemplateThinking } from "openclaw/plugin-sdk/provider-stream-shared";
5
+ import { createProviderWaitObserver } from "openclaw/plugin-sdk/provider-transport-runtime";
5
6
  //#region extensions/llama-cpp/src/external-server/stream.ts
6
7
  /** Maps shared structured-output requests to the shape accepted by older llama-server builds. */
7
8
  function normalizeLlamaServerResponseFormat(payload, requestedResponseFormat) {
@@ -19,17 +20,44 @@ function wrapLlamaServerStream(ctx) {
19
20
  return (model, context, options) => {
20
21
  if (model.provider !== "llama-cpp") return underlying(model, context, options);
21
22
  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);
23
+ const wait = createProviderWaitObserver(options);
24
+ try {
25
+ const source = underlying(model, context, {
26
+ ...options,
27
+ onPayload: async (payload, requestModel) => {
28
+ const customized = await onPayload?.(payload, requestModel) ?? payload;
29
+ if (isRecord(customized)) {
30
+ if ((options?.reasoning ?? ctx.thinkingLevel) === "off") setQwenChatTemplateThinking(customized, false);
31
+ normalizeLlamaServerResponseFormat(customized, options?.responseFormat);
32
+ }
33
+ wait.start();
34
+ return customized;
29
35
  }
30
- return customized;
31
- }
32
- });
36
+ });
37
+ if (!options?.onProviderWait) return source;
38
+ return Promise.resolve(source).then((stream) => {
39
+ stream.result().then(wait.stop, wait.stop);
40
+ return {
41
+ async *[Symbol.asyncIterator]() {
42
+ try {
43
+ for await (const event of stream) {
44
+ wait.stop();
45
+ yield event;
46
+ }
47
+ } finally {
48
+ wait.stop();
49
+ }
50
+ },
51
+ result: () => stream.result()
52
+ };
53
+ }, (error) => {
54
+ wait.stop();
55
+ throw error;
56
+ });
57
+ } catch (error) {
58
+ wait.stop();
59
+ throw error;
60
+ }
33
61
  };
34
62
  }
35
63
  //#endregion
@@ -0,0 +1 @@
1
+ {"version":3,"entries":[{"output":"index.js","source":"extensions/llama-cpp/index.ts"},{"output":"provider-discovery.js","source":"extensions/llama-cpp/provider-discovery.ts"},{"output":"provider-policy-api.js","source":"extensions/llama-cpp/provider-policy-api.ts"}],"chunks":[{"output":".setup/auth-config-BJOlAPuO.mjs","sha256":"517a75210f5da9692e00af2fcb9eee2fef8c7ffe29a7e11466a1fe76521981c2","facadeSource":null,"sources":["extensions/llama-cpp/src/auth-config.ts"]},{"output":".setup/defaults-CZr5jpH7.mjs","sha256":"c9584ca66482d9812286edc2882f767bc071e61fec679b2d02c29dcda3b0914d","facadeSource":null,"sources":["extensions/llama-cpp/src/defaults.ts"]},{"output":".setup/discovery-CghcMQy6.mjs","sha256":"82bb6e7c9979cedf70d225b7683803b2ebc67d874cae76486e5c41b5ab8bcb98","facadeSource":null,"sources":["extensions/llama-cpp/src/external-server/auth.ts","extensions/llama-cpp/src/external-server/discovery.ts","extensions/llama-cpp/src/external-server/models.ts"]},{"output":".setup/embedding-provider.runtime-Bb0UVBwq.mjs","sha256":"901b6d08b9f5cd9e2c82690859234cf37c29a6b7d6a1dd48c3cfb8d11eadf600","facadeSource":"extensions/llama-cpp/src/embedding-provider.runtime.ts","sources":["extensions/llama-cpp/src/embedding-provider.runtime.ts","extensions/llama-cpp/src/managed-server-inspection.ts"]},{"output":".setup/managed-provider-config-Dn-MKZjS.mjs","sha256":"e23a037098da33897ae4e815512344b47b2b7b25b709f3c42296183d58c3f8d8","facadeSource":null,"sources":["extensions/llama-cpp/src/managed-provider-config.ts"]},{"output":".setup/managed-server-CZGhj7j8.mjs","sha256":"0c56b075c297903091ef51884a3f90d2bbe5455692d9739692d73a4d1ed3d111","facadeSource":"extensions/llama-cpp/src/managed-server.ts","sources":["extensions/llama-cpp/src/llama-server-assets.ts","extensions/llama-cpp/src/llama-server-install.ts","extensions/llama-cpp/src/llama-server-preset.ts","extensions/llama-cpp/src/managed-server.ts","extensions/llama-cpp/src/runtime-error.ts"]},{"output":".setup/media-catalog-DgRc3mpW.mjs","sha256":"00f6ebc051b3ae3a111ef72cef42ca7327e6149c79347a02650bf3e2dde5ec23","facadeSource":null,"sources":["extensions/llama-cpp/src/hardware.ts","extensions/llama-cpp/src/media-catalog.ts","extensions/llama-cpp/src/model-catalog.ts"]},{"output":".setup/media-config-CZ7CluNV.mjs","sha256":"f5e2ffa90063a021dcbffa0c78eee3fbf3bfe3deb86cd62768001b5db432ad15","facadeSource":null,"sources":["extensions/llama-cpp/src/media-config.ts"]},{"output":".setup/media-provider.runtime-Cd4dOeAN.mjs","sha256":"2db93d8edc1a7895d7f45bef4119582d0b4577b3ffb7902ddba3719f8f7ae39e","facadeSource":"extensions/llama-cpp/src/media-provider.runtime.ts","sources":["extensions/llama-cpp/src/media-provider.runtime.ts"]},{"output":".setup/media-setup-CYVQ5us2.mjs","sha256":"cb95e5a329d73c911d652cf291a5b4af058b7a5483c7832f5d1409030284c539","facadeSource":"extensions/llama-cpp/src/media-setup.ts","sources":["extensions/llama-cpp/src/media-setup.ts","extensions/llama-cpp/src/media-verification-fixtures.ts"]},{"output":".setup/provider-CwnlpLK5.mjs","sha256":"4831dd5a56f85981726f1049584b7c39d6ffb3c134784e0a8f3f56a0230e7da6","facadeSource":"extensions/llama-cpp/src/external-server/provider.ts","sources":["extensions/llama-cpp/src/external-server/provider.ts"]},{"output":".setup/provider-discovery-D3_7fprf.mjs","sha256":"1f2cd0bf0af9e35458de458e340071bcf13d2cf0747543c475eb48f548135950","facadeSource":null,"sources":["extensions/llama-cpp/provider-discovery.ts","extensions/llama-cpp/src/external-server/auth-policy.ts","extensions/llama-cpp/src/external-server/defaults.ts","extensions/llama-cpp/src/external-server/endpoint.ts"]},{"output":".setup/setup-Cd7vqUzv.mjs","sha256":"0f4eb05e6896d28854e64e8224b9735d359f22343dbb9bff84827343214dffcd","facadeSource":"extensions/llama-cpp/src/setup.ts","sources":["extensions/llama-cpp/src/setup.ts"]},{"output":".setup/setup-DDuIGmUb.mjs","sha256":"e577ad098c68f06f76c758ba3d6584df38a875cd710123d1f95a3b41533b78f0","facadeSource":"extensions/llama-cpp/src/external-server/setup.ts","sources":["extensions/llama-cpp/src/external-server/setup.ts"]},{"output":".setup/stream-lxVe6M15.mjs","sha256":"84376e536e1ef879cfdff6bdbacdfb1cf990f40532e5c566a7e8cc13cd0fc69b","facadeSource":"extensions/llama-cpp/src/external-server/stream.ts","sources":["extensions/llama-cpp/src/external-server/stream.ts"]},{"output":"index.js","sha256":"46540bb6949578bf6f4626f7518f8cd3327a2e9a8c3daf658a6a315c3fd27ca7","facadeSource":"extensions/llama-cpp/index.ts","sources":["extensions/llama-cpp/index.ts","extensions/llama-cpp/src/embedding-provider.ts","extensions/llama-cpp/src/managed-provider.ts","extensions/llama-cpp/src/media-provider.ts"]},{"output":"provider-discovery.js","sha256":"3285b94435aebe17960bbdec159b9caaf16860439773529e70ad90ec31943d3f","facadeSource":"extensions/llama-cpp/provider-discovery.ts","sources":[]},{"output":"provider-policy-api.js","sha256":"df298f12d13b715d12771002a677156a92889df607e8f2a91c781ebd3b42bcaa","facadeSource":"extensions/llama-cpp/provider-policy-api.ts","sources":["extensions/llama-cpp/provider-policy-api.ts"]}],"unrenderedSources":[]}