@openclaw/llama-cpp-provider 2026.6.6-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.
package/dist/index.js ADDED
@@ -0,0 +1,126 @@
1
+ import { createRequire } from "node:module";
2
+ import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
+ import { pathToFileURL } from "node:url";
4
+ import { createLocalEmbeddingProvider } from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
5
+ //#region extensions/llama-cpp/src/embedding-provider.ts
6
+ const LLAMA_CPP_EMBEDDING_PROVIDER_ID = "local";
7
+ const DEFAULT_LLAMA_CPP_EMBEDDING_MODEL = "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf";
8
+ function normalizeOptionalString(value) {
9
+ return typeof value === "string" && value.trim() ? value.trim() : void 0;
10
+ }
11
+ function readLocalOptions(options) {
12
+ return options.local ?? {};
13
+ }
14
+ function textFromEmbeddingInput(input) {
15
+ return typeof input === "string" ? input : input.text;
16
+ }
17
+ function toMemoryEmbeddingInput(input) {
18
+ return typeof input === "string" ? { text: input } : input;
19
+ }
20
+ function isNodeLlamaCppMissing(err) {
21
+ if (!(err instanceof Error)) return false;
22
+ return err.code === "ERR_MODULE_NOT_FOUND" && err.message.includes("node-llama-cpp");
23
+ }
24
+ function formatErrorMessage(err) {
25
+ if (err instanceof Error) return err.message;
26
+ return String(err);
27
+ }
28
+ function formatLlamaCppSetupError(err) {
29
+ const detail = formatErrorMessage(err);
30
+ const missing = isNodeLlamaCppMissing(err);
31
+ return [
32
+ "Local llama.cpp embeddings unavailable.",
33
+ missing ? "Reason: node-llama-cpp is missing or failed to install." : detail ? `Reason: ${detail}` : void 0,
34
+ missing && detail ? `Detail: ${detail}` : null,
35
+ "To enable local GGUF embeddings:",
36
+ "1) Install the official provider plugin: openclaw plugins install @openclaw/llama-cpp-provider",
37
+ "2) Use Node 24 for native installs/updates.",
38
+ "3) If you use pnpm from source: pnpm approve-builds, then pnpm rebuild node-llama-cpp.",
39
+ "Or set agents.defaults.memorySearch.provider to a remote embedding provider such as \"openai\", \"ollama\", \"lmstudio\", or \"voyage\"."
40
+ ].filter(Boolean).join("\n");
41
+ }
42
+ const requireFromPlugin = createRequire(import.meta.url);
43
+ function resolveNodeLlamaCppImportUrl() {
44
+ return pathToFileURL(requireFromPlugin.resolve("node-llama-cpp")).href;
45
+ }
46
+ function adaptMemoryEmbeddingProvider(provider) {
47
+ return {
48
+ id: LLAMA_CPP_EMBEDDING_PROVIDER_ID,
49
+ model: provider.model,
50
+ maxInputTokens: provider.maxInputTokens,
51
+ embed: async (input, callOptions) => await provider.embedQuery(textFromEmbeddingInput(input), { signal: callOptions?.signal }),
52
+ embedBatch: async (inputs, callOptions) => {
53
+ if (provider.embedBatchInputs) return await provider.embedBatchInputs(inputs.map(toMemoryEmbeddingInput), { signal: callOptions?.signal });
54
+ return await provider.embedBatch(inputs.map(textFromEmbeddingInput), { signal: callOptions?.signal });
55
+ },
56
+ close: provider.close
57
+ };
58
+ }
59
+ async function createLlamaCppEmbeddingProvider(options, runtimeOptions = {}) {
60
+ const result = await createLlamaCppMemoryEmbeddingProvider(buildMemoryCreateOptions(options, options.dimensions), runtimeOptions);
61
+ if (!result.provider) throw new Error("llama.cpp local embedding provider was unavailable");
62
+ return adaptMemoryEmbeddingProvider(result.provider);
63
+ }
64
+ async function createLlamaCppMemoryEmbeddingProvider(options, runtimeOptions = {}) {
65
+ const provider = await createLocalEmbeddingProvider(buildMemoryCreateOptions(options, options.outputDimensionality), { nodeLlamaCppImportUrl: runtimeOptions.nodeLlamaCppImportUrl ?? resolveNodeLlamaCppImportUrl() });
66
+ return {
67
+ provider,
68
+ runtime: createLlamaCppEmbeddingProviderRuntime(provider)
69
+ };
70
+ }
71
+ function buildMemoryCreateOptions(options, outputDimensionality) {
72
+ const local = readLocalOptions(options);
73
+ const modelPath = normalizeOptionalString(local.modelPath) || "hf:ggml-org/embeddinggemma-300m-qat-q8_0-GGUF/embeddinggemma-300m-qat-Q8_0.gguf";
74
+ return {
75
+ config: options.config,
76
+ agentDir: options.agentDir,
77
+ provider: LLAMA_CPP_EMBEDDING_PROVIDER_ID,
78
+ fallback: "none",
79
+ remote: options.remote,
80
+ model: modelPath,
81
+ inputType: options.inputType,
82
+ queryInputType: options.queryInputType,
83
+ documentInputType: options.documentInputType,
84
+ local: {
85
+ ...local,
86
+ modelPath
87
+ },
88
+ outputDimensionality
89
+ };
90
+ }
91
+ function createLlamaCppEmbeddingProviderRuntime(provider) {
92
+ return {
93
+ id: LLAMA_CPP_EMBEDDING_PROVIDER_ID,
94
+ inlineQueryTimeoutMs: 5 * 6e4,
95
+ inlineBatchTimeoutMs: 10 * 6e4,
96
+ cacheKeyData: {
97
+ provider: LLAMA_CPP_EMBEDDING_PROVIDER_ID,
98
+ model: provider.model
99
+ }
100
+ };
101
+ }
102
+ const llamaCppEmbeddingProviderAdapter = {
103
+ id: LLAMA_CPP_EMBEDDING_PROVIDER_ID,
104
+ defaultModel: DEFAULT_LLAMA_CPP_EMBEDDING_MODEL,
105
+ transport: "local",
106
+ formatSetupError: formatLlamaCppSetupError,
107
+ create: async (options) => {
108
+ const provider = await createLlamaCppEmbeddingProvider(options);
109
+ return {
110
+ provider,
111
+ runtime: createLlamaCppEmbeddingProviderRuntime(provider)
112
+ };
113
+ }
114
+ };
115
+ //#endregion
116
+ //#region extensions/llama-cpp/index.ts
117
+ var llama_cpp_default = definePluginEntry({
118
+ id: "llama-cpp",
119
+ name: "llama.cpp Provider",
120
+ description: "Local GGUF embeddings through node-llama-cpp",
121
+ register(api) {
122
+ api.registerEmbeddingProvider(llamaCppEmbeddingProviderAdapter);
123
+ }
124
+ });
125
+ //#endregion
126
+ export { llama_cpp_default as default };