@openclaw/llama-cpp-provider 2026.7.2-beta.4 → 2026.7.2-beta.7

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 CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createRequire } from "node:module";
2
2
  import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
+ import { buildProviderToolCompatFamilyHooks } from "openclaw/plugin-sdk/provider-tools";
3
4
  import os from "node:os";
4
5
  import path from "node:path";
5
6
  import { createLocalEmbeddingProvider } from "openclaw/plugin-sdk/memory-core-host-engine-embeddings";
@@ -285,6 +286,18 @@ function extractText(content) {
285
286
  function normalizeArguments(value) {
286
287
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
287
288
  }
289
+ async function resolveLlamaCppResponseGrammar(params) {
290
+ const responseFormat = params.responseFormat;
291
+ if (!responseFormat) return;
292
+ if (Object.keys(responseFormat).length === 0) return await params.llama.getGrammarFor("json");
293
+ if (responseFormat.type === "json_object") return await params.llama.getGrammarFor("json");
294
+ if (responseFormat.type === "text") return;
295
+ if (responseFormat.type === "json_schema") {
296
+ const schema = normalizeArguments(normalizeArguments(responseFormat.json_schema).schema);
297
+ return Object.keys(schema).length > 0 ? await params.llama.createGrammarForJsonSchema(schema) : await params.llama.getGrammarFor("json");
298
+ }
299
+ return await params.llama.createGrammarForJsonSchema(responseFormat);
300
+ }
288
301
  function mapContextToLlamaChatHistory(context) {
289
302
  const history = [];
290
303
  if (context.systemPrompt?.trim()) history.push({
@@ -389,6 +402,7 @@ async function getLoadedModel(params) {
389
402
  const sequence = context.getSequence();
390
403
  loadedModel = {
391
404
  key,
405
+ llama,
392
406
  model,
393
407
  context,
394
408
  sequence
@@ -445,18 +459,20 @@ function createLlamaCppStreamFn(params) {
445
459
  signal?.removeEventListener("abort", abortWhileQueued);
446
460
  try {
447
461
  const runtime = await importNodeLlamaCpp();
448
- const sequence = (await getLoadedModel({
462
+ const loaded = await getLoadedModel({
449
463
  runtime,
450
464
  model,
451
465
  providerConfig: params.providerConfig,
452
466
  signal: options?.signal
453
- })).sequence;
467
+ });
468
+ const sequence = loaded.sequence;
454
469
  const chat = new runtime.LlamaChat({
455
470
  contextSequence: sequence,
456
471
  chatWrapper: "auto",
457
472
  autoDisposeSequence: false
458
473
  });
459
474
  const before = sequence.tokenMeter.getState();
475
+ const functions = mapToolsToLlamaFunctions(context);
460
476
  let textStarted = false;
461
477
  const partial = () => buildMessage({
462
478
  model,
@@ -488,15 +504,22 @@ function createLlamaCppStreamFn(params) {
488
504
  });
489
505
  };
490
506
  try {
491
- const result = await chat.generateResponse(mapContextToLlamaChatHistory(context), {
492
- functions: mapToolsToLlamaFunctions(context),
493
- documentFunctionParams: true,
507
+ const grammar = functions || !options?.responseFormat ? void 0 : await resolveLlamaCppResponseGrammar({
508
+ llama: loaded.llama,
509
+ responseFormat: options.responseFormat
510
+ });
511
+ const generationOptions = {
494
512
  signal: options?.signal,
495
513
  maxTokens: options?.maxTokens ?? model.maxTokens,
496
514
  temperature: options?.temperature,
497
515
  customStopTriggers: options?.stop,
498
- onTextChunk: appendTextDelta
499
- });
516
+ onTextChunk: appendTextDelta,
517
+ ...functions ? {
518
+ functions,
519
+ documentFunctionParams: true
520
+ } : grammar ? { grammar } : {}
521
+ };
522
+ const result = await chat.generateResponse(mapContextToLlamaChatHistory(context), generationOptions);
500
523
  if (result.metadata.stopReason === "abort" || signal?.aborted) {
501
524
  generationAborted = true;
502
525
  throw signal?.reason ?? /* @__PURE__ */ new Error("Request was aborted");
@@ -729,6 +752,7 @@ var llama_cpp_default = definePluginEntry({
729
752
  source: "local llama.cpp runtime",
730
753
  mode: "api-key"
731
754
  }),
755
+ ...buildProviderToolCompatFamilyHooks("llamacpp-gbnf"),
732
756
  wizard: {
733
757
  setup: {
734
758
  choiceId: LLAMA_CPP_PROVIDER_ID,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/llama-cpp-provider",
3
- "version": "2026.7.2-beta.4",
3
+ "version": "2026.7.2-beta.7",
4
4
  "description": "OpenClaw llama.cpp text inference and embedding provider plugin",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "type": "module",
10
10
  "optionalDependencies": {
11
- "node-llama-cpp": "3.19.0"
11
+ "node-llama-cpp": "3.19.1"
12
12
  },
13
13
  "devDependencies": {
14
14
  "@openclaw/plugin-sdk": "workspace:*"
@@ -23,10 +23,10 @@
23
23
  "minHostVersion": ">=2026.6.2"
24
24
  },
25
25
  "compat": {
26
- "pluginApi": ">=2026.7.2-beta.4"
26
+ "pluginApi": ">=2026.7.2-beta.7"
27
27
  },
28
28
  "build": {
29
- "openclawVersion": "2026.7.2-beta.4"
29
+ "openclawVersion": "2026.7.2-beta.7"
30
30
  },
31
31
  "release": {
32
32
  "bundleRuntimeDependencies": false,
@@ -40,11 +40,10 @@
40
40
  "files": [
41
41
  "dist/**",
42
42
  "openclaw.plugin.json",
43
- "npm-shrinkwrap.json",
44
43
  "README.md"
45
44
  ],
46
45
  "peerDependencies": {
47
- "openclaw": ">=2026.7.2-beta.4"
46
+ "openclaw": ">=2026.7.2-beta.7"
48
47
  },
49
48
  "peerDependenciesMeta": {
50
49
  "openclaw": {