Skip to content

Commit b521e0a

Browse files
authored
fix(llama-cpp): stop hijacking explicitly configured HTTP provider routes (#118293)
* fix(llama-cpp): preserve configured HTTP routes * chore: drop release-owned CHANGELOG edit from PR branch
1 parent 2a635f2 commit b521e0a

3 files changed

Lines changed: 58 additions & 19 deletions

File tree

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

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
getRegisteredEmbeddingProvider,
1515
setActivePluginRegistry,
1616
} from "openclaw/plugin-sdk/plugin-test-runtime";
17+
import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-model-shared";
1718
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1819

1920
const memoryHostEmbeddingMocks = vi.hoisted(() => ({
@@ -26,6 +27,7 @@ vi.mock("openclaw/plugin-sdk/memory-core-host-engine-embeddings", () => ({
2627
}));
2728

2829
import llamaCppPlugin from "./index.js";
30+
import { LLAMA_CPP_LOCAL_BASE_URL } from "./src/defaults.js";
2931
import { llamaCppEmbeddingProviderAdapter } from "./src/embedding-provider.js";
3032

3133
const DEFAULT_LLAMA_CPP_EMBEDDING_MODEL =
@@ -41,6 +43,22 @@ beforeEach(() => {
4143
previousPluginRegistry = getActivePluginRegistry();
4244
});
4345

46+
function registerLlamaCppTextProvider(): ProviderPlugin {
47+
const providers: ProviderPlugin[] = [];
48+
llamaCppPlugin.register(
49+
createTestPluginApi({
50+
id: "llama-cpp",
51+
name: "llama.cpp Provider",
52+
source: "test",
53+
config: {},
54+
pluginConfig: {},
55+
runtime: {} as never,
56+
registerProvider: (provider) => providers.push(provider),
57+
}),
58+
);
59+
return expectDefined(providers[0], "llama.cpp text provider");
60+
}
61+
4462
async function createLlamaCppMemoryEmbeddingProvider(options: MemoryCreateTestOptions) {
4563
const { fallback: _fallback, outputDimensionality, ...adapterOptions } = options;
4664
return await llamaCppEmbeddingProviderAdapter.create({
@@ -58,21 +76,7 @@ afterEach(() => {
5876

5977
describe("llama.cpp provider plugin", () => {
6078
it("registers the local text-inference provider", () => {
61-
const registerProvider = vi.fn();
62-
63-
llamaCppPlugin.register(
64-
createTestPluginApi({
65-
id: "llama-cpp",
66-
name: "llama.cpp Provider",
67-
source: "test",
68-
config: {},
69-
pluginConfig: {},
70-
runtime: {} as never,
71-
registerProvider,
72-
}),
73-
);
74-
75-
expect(registerProvider).toHaveBeenCalledWith(
79+
expect(registerLlamaCppTextProvider()).toEqual(
7680
expect.objectContaining({
7781
id: "llama-cpp",
7882
label: "llama.cpp",
@@ -84,6 +88,35 @@ describe("llama.cpp provider plugin", () => {
8488
);
8589
});
8690

91+
it("keeps explicit HTTP routes on the configured transport", () => {
92+
const provider = registerLlamaCppTextProvider();
93+
const createStream = (baseUrl: string) =>
94+
provider.createStreamFn?.({
95+
config: {
96+
models: {
97+
providers: {
98+
"llama-cpp": {
99+
api: "openai-completions",
100+
baseUrl,
101+
models: [],
102+
},
103+
},
104+
},
105+
},
106+
model: {
107+
api: "openai-completions",
108+
baseUrl,
109+
id: "local-model",
110+
provider: "llama-cpp",
111+
},
112+
modelId: "local-model",
113+
provider: "llama-cpp",
114+
} as never);
115+
116+
expect(createStream("http://127.0.0.1:8080/v1")).toBeUndefined();
117+
expect(createStream(LLAMA_CPP_LOCAL_BASE_URL)).toBeTypeOf("function");
118+
});
119+
87120
it("registers the local embedding provider through the generic SDK contract", () => {
88121
const { config, registry } = createPluginRegistryFixture();
89122

‎extensions/llama-cpp/index.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { buildProviderToolCompatFamilyHooks } from "openclaw/plugin-sdk/provider
33
import {
44
LLAMA_CPP_PROVIDER_ID,
55
LLAMA_CPP_PROVIDER_LABEL,
6+
LLAMA_CPP_LOCAL_BASE_URL,
67
buildLlamaCppProviderConfig,
78
resolveLlamaCppSyntheticApiKey,
89
} from "./src/defaults.js";
@@ -45,10 +46,15 @@ export default definePluginEntry({
4546
order: "late",
4647
run: async () => ({ provider: buildLlamaCppProviderConfig() }),
4748
},
48-
createStreamFn: ({ config, provider }) =>
49-
createLlamaCppStreamFn({
49+
createStreamFn: ({ config, model, provider }) => {
50+
// Explicit HTTP routes sharing this provider id stay on the configured transport.
51+
if (model.baseUrl !== LLAMA_CPP_LOCAL_BASE_URL) {
52+
return undefined;
53+
}
54+
return createLlamaCppStreamFn({
5055
providerConfig: config?.models?.providers?.[provider],
51-
}),
56+
});
57+
},
5258
resolveSyntheticAuth: () => ({
5359
apiKey: resolveLlamaCppSyntheticApiKey(),
5460
source: "local llama.cpp runtime",

‎extensions/llama-cpp/src/defaults.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type {
88
export const LLAMA_CPP_PROVIDER_ID = "llama-cpp";
99
export const LLAMA_CPP_PROVIDER_LABEL = "llama.cpp";
1010
const LLAMA_CPP_LOCAL_AUTH_MARKER = "llama-cpp-local";
11-
const LLAMA_CPP_LOCAL_BASE_URL = "local://llama-cpp";
11+
export const LLAMA_CPP_LOCAL_BASE_URL = "local://llama-cpp";
1212

1313
export function resolveLlamaCppSyntheticApiKey(): string {
1414
return LLAMA_CPP_LOCAL_AUTH_MARKER;

0 commit comments

Comments
 (0)