Skip to content

Commit d37e500

Browse files
committed
fix(llama-cpp): make endpoint auth transitions reproducible
1 parent 8b15dc9 commit d37e500

18 files changed

Lines changed: 456 additions & 598 deletions

‎docs/plugins/llama-cpp.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ remain authoritative over discovered rows with the same ID.
110110

111111
Existing endpoints support no auth, API keys, SecretRefs, auth profiles, and
112112
explicit authorization headers. An explicit `Authorization` header wins over
113-
ambient API-key discovery. Endpoint URLs containing a username or password are
114-
rejected.
113+
ambient API-key discovery unless setup receives a new key. Choosing no API key
114+
removes the default llama.cpp auth profile and stale inline key fields while
115+
preserving an explicit `Authorization` header and unrelated headers. Endpoint
116+
URLs containing a username or password are rejected.
115117

116118
```bash
117119
export LLAMA_SERVER_API_KEY="<API_KEY>"

‎extensions/llama-cpp/doctor-contract-api.test.ts‎

Lines changed: 0 additions & 106 deletions
This file was deleted.

‎extensions/llama-cpp/doctor-contract-api.ts‎

Lines changed: 0 additions & 65 deletions
This file was deleted.

‎extensions/llama-cpp/index.test.ts‎

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import os from "node:os";
22
import path from "node:path";
33
import { expectDefined } from "@openclaw/normalization-core";
44
import { createLocalEmbeddingProvider } from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
5-
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
65
import { createTestPluginApi } from "openclaw/plugin-sdk/plugin-test-api";
76
import {
87
createPluginRegistryFixture,
@@ -75,19 +74,13 @@ beforeEach(() => {
7574
});
7675

7776
afterEach(() => {
78-
clearEmbeddingProviders();
7977
clearEmbeddingProviders();
8078
setActivePluginRegistry(previousPluginRegistry ?? createEmptyPluginRegistry());
8179
vi.clearAllMocks();
8280
});
8381

84-
function captureTextRegistration(): {
85-
providers: ProviderPlugin[];
86-
catalogProviders: Array<Parameters<OpenClawPluginApi["registerModelCatalogProvider"]>[0]>;
87-
} {
82+
function captureTextRegistration(): { providers: ProviderPlugin[] } {
8883
const providers: ProviderPlugin[] = [];
89-
const catalogProviders: Array<Parameters<OpenClawPluginApi["registerModelCatalogProvider"]>[0]> =
90-
[];
9184
llamaCppPlugin.register(
9285
createTestPluginApi({
9386
id: LLAMA_CPP_PROVIDER_ID,
@@ -97,10 +90,9 @@ function captureTextRegistration(): {
9790
pluginConfig: {},
9891
runtime: {} as never,
9992
registerProvider: (provider) => providers.push(provider),
100-
registerModelCatalogProvider: (provider) => catalogProviders.push(provider),
10193
}),
10294
);
103-
return { providers, catalogProviders };
95+
return { providers };
10496
}
10597

10698
function registerTextProvider(): ProviderPlugin {
@@ -155,7 +147,7 @@ describe("llama.cpp provider plugin", () => {
155147
});
156148

157149
it("uses the normal OpenAI-compatible text transport", () => {
158-
const { providers, catalogProviders } = captureTextRegistration();
150+
const { providers } = captureTextRegistration();
159151
const provider = expectDefined(providers[0], "llama.cpp provider");
160152

161153
expect(providers.map((registered) => registered.id)).toEqual([LLAMA_CPP_PROVIDER_ID]);
@@ -177,9 +169,6 @@ describe("llama.cpp provider plugin", () => {
177169
"llama-cpp-existing-server",
178170
]);
179171
expect(provider).not.toHaveProperty("createStreamFn");
180-
expect(catalogProviders).toEqual([
181-
expect.objectContaining({ provider: LLAMA_CPP_PROVIDER_ID, kinds: ["text"] }),
182-
]);
183172
});
184173

185174
it("registers local embeddings through the generic provider contract", () => {

‎extensions/llama-cpp/openclaw.plugin.json‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
"id": "llama-cpp",
33
"name": "llama.cpp Provider",
44
"description": "Managed and external llama.cpp servers for GGUF chat and embeddings.",
5-
"doctorContract": {
6-
"configRepair": true
7-
},
85
"activation": {
96
"onStartup": false
107
},
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
2+
import { describe, expect, it } from "vitest";
3+
import { inspectEmbeddingProviderSetup } from "./provider-policy-api.js";
4+
import { buildLlamaCppProviderConfig } from "./src/defaults.js";
5+
6+
describe("llama.cpp embedding setup policy", () => {
7+
it("reports the direct-start managed setup blocker with the supported CLI remediation", () => {
8+
expect(
9+
inspectEmbeddingProviderSetup({ config: {}, env: {}, agentId: "main", provider: "local" }),
10+
).toEqual({
11+
provider: "local",
12+
reason: expect.stringContaining("Local embeddings need the managed llama.cpp server config"),
13+
requirement: "managed-llama-cpp-setup",
14+
fixHint:
15+
"Run `openclaw models --agent main auth login --provider llama-cpp --method local` in an interactive terminal, then rerun this check.",
16+
});
17+
});
18+
19+
it("accepts managed config produced by the models auth CLI without mutating it", () => {
20+
const provider = buildLlamaCppProviderConfig(undefined, {
21+
command: "/managed/llama-server",
22+
baseUrl: "http://127.0.0.1:19432/v1",
23+
healthUrl: "http://127.0.0.1:19432/health",
24+
args: ["--models-preset", "/managed/models.ini"],
25+
});
26+
const config: OpenClawConfig = { models: { providers: { "llama-cpp": provider } } };
27+
const configBefore = JSON.stringify(config);
28+
29+
expect(
30+
inspectEmbeddingProviderSetup({ config, env: {}, agentId: "main", provider: "local" }),
31+
).toBeNull();
32+
expect(JSON.stringify(config)).toBe(configBefore);
33+
});
34+
35+
it("does not apply managed setup to a non-local memory provider", () => {
36+
expect(
37+
inspectEmbeddingProviderSetup({ config: {}, env: {}, agentId: "main", provider: "openai" }),
38+
).toBeNull();
39+
});
40+
});

‎extensions/llama-cpp/src/external-server/discovery.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ describe("llama-server discovery projection", () => {
3939
discoverLlamaServer({ baseUrl: "http://localhost:8080/v1", cacheTtlMs: 0 }),
4040
).resolves.toMatchObject({
4141
kind: "success",
42-
health: "loading",
4342
endpoint: {
4443
origin: "http://localhost:8080",
4544
inferenceBaseUrl: "http://localhost:8080/v1",

‎extensions/llama-cpp/src/external-server/discovery.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export type LlamaServerDiscoveryResult =
1212
| {
1313
kind: "success";
1414
endpoint: ReturnType<typeof resolveLlamaServerEndpoint>;
15-
health: "ready" | "loading" | "unknown";
1615
models: LlamaServerDiscoveredModel[];
17-
fetchedAt: number;
1816
}
1917
| {
2018
kind: "unreachable";
@@ -76,8 +74,6 @@ export async function discoverLlamaServer(params: {
7674
return {
7775
kind: "success" as const,
7876
endpoint,
79-
health: result.health,
80-
fetchedAt: result.fetchedAt,
8177
models: result.rows.flatMap(({ model, props }) => {
8278
const mapped = mapLlamaServerModel(model, props);
8379
return mapped ? [mapped] : [];

‎extensions/llama-cpp/src/external-server/models.test.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ describe("llama-server model mapping", () => {
1515
n_ctx: 65536,
1616
params: { max_tokens: 4096 },
1717
},
18-
total_slots: 2,
19-
build_info: "b10000-deadbeef",
2018
chat_template_caps: {
2119
supports_tools: true,
2220
supports_tool_calls: true,
@@ -26,8 +24,6 @@ describe("llama-server model mapping", () => {
2624
),
2725
).toMatchObject({
2826
status: "loaded",
29-
buildInfo: "b10000-deadbeef",
30-
totalSlots: 2,
3127
config: {
3228
id: "ggml-org/model:Q4_K_M",
3329
contextWindow: 65536,

0 commit comments

Comments
 (0)