diff --git a/extensions/llama-cpp/src/inference-provider.test.ts b/extensions/llama-cpp/src/inference-provider.test.ts index 214dacb61ede..630e0a416738 100644 --- a/extensions/llama-cpp/src/inference-provider.test.ts +++ b/extensions/llama-cpp/src/inference-provider.test.ts @@ -54,16 +54,15 @@ vi.mock("node-llama-cpp", () => ({ }, })); -import { - createLlamaCppInferenceRuntime, - llamaCppInferenceTestApi, - type LlamaCppInferenceRuntime, -} from "./inference-provider.js"; +import { createLlamaCppInferenceRuntime } from "./inference-provider.js"; -if (!llamaCppInferenceTestApi) { - throw new Error("expected llama.cpp inference test API"); -} -const { mapContextToLlamaChatHistory, mapToolsToLlamaFunctions } = llamaCppInferenceTestApi; +const { mapContextToLlamaChatHistory, mapToolsToLlamaFunctions } = ( + globalThis as Record +)[Symbol.for("openclaw.llamaCppInferenceTestApi")] as { + mapContextToLlamaChatHistory: (context: Context) => unknown[]; + mapToolsToLlamaFunctions: (context: Context) => Record | undefined; +}; +type LlamaCppInferenceRuntime = ReturnType; let inferenceRuntime: LlamaCppInferenceRuntime; const model: Model = { diff --git a/extensions/llama-cpp/src/inference-provider.ts b/extensions/llama-cpp/src/inference-provider.ts index f55dee5bd4d2..80eb7138f3af 100644 --- a/extensions/llama-cpp/src/inference-provider.ts +++ b/extensions/llama-cpp/src/inference-provider.ts @@ -49,7 +49,7 @@ type LlamaCppInferenceRuntimeState = { disposePromise?: Promise; }; -export type LlamaCppInferenceRuntime = { +type LlamaCppInferenceRuntime = { createStreamFn: (params: { providerConfig?: ModelProviderConfig }) => StreamFn; dispose: () => Promise; }; @@ -681,10 +681,9 @@ export function createLlamaCppInferenceRuntime(): LlamaCppInferenceRuntime { }; } -export const llamaCppInferenceTestApi = - process.env.VITEST || process.env.NODE_ENV === "test" - ? { - mapContextToLlamaChatHistory, - mapToolsToLlamaFunctions, - } - : undefined; +if (process.env.VITEST || process.env.NODE_ENV === "test") { + (globalThis as Record)[Symbol.for("openclaw.llamaCppInferenceTestApi")] = { + mapContextToLlamaChatHistory, + mapToolsToLlamaFunctions, + }; +}