@openviking/openclaw-plugin 2026.11.23 → 2026.11.25-1
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/shared/recall-core.mjs +26 -35
- package/package.json +1 -1
- package/shared/recall-core.d.mts +2 -2
- package/shared/recall-core.mjs +21 -34
|
@@ -118,8 +118,8 @@ export function buildContextSearchBody(cfg = {}, options = {}) {
|
|
|
118
118
|
body.max_tokens = maxTokens;
|
|
119
119
|
if (cfg.recallPeerScope === "actor")
|
|
120
120
|
body.peer_scope = "actor";
|
|
121
|
-
const decayProtection = String(cfg.recallEventsDecayProtection
|
|
122
|
-
if (decayProtection)
|
|
121
|
+
const decayProtection = String(cfg.recallEventsDecayProtection ?? "").trim();
|
|
122
|
+
if (decayProtection && decayProtection !== "off")
|
|
123
123
|
body.events_time_decay_protection = decayProtection;
|
|
124
124
|
const sessionId = String(options.sessionId || "").trim();
|
|
125
125
|
if (sessionId) {
|
|
@@ -421,21 +421,9 @@ async function writeJsonFile(path, value) {
|
|
|
421
421
|
catch { /* best effort */ }
|
|
422
422
|
}
|
|
423
423
|
/**
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
|
|
427
|
-
export async function isContextFaceLegacy(path = stateFile("context-face.json"), now = Date.now()) {
|
|
428
|
-
const cached = await readJsonFile(path);
|
|
429
|
-
return Boolean(cached?.legacyUntil && Number(cached.legacyUntil) > now);
|
|
430
|
-
}
|
|
431
|
-
export async function markContextFaceLegacy(path = stateFile("context-face.json"), now = Date.now()) {
|
|
432
|
-
await writeJsonFile(path, { legacyUntil: now + LEGACY_CACHE_TTL_MS });
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* A `peer_scope` the server rejects is remembered the same way, but unlike the
|
|
436
|
-
* context face this one is not a silent capability probe: dropping the field
|
|
437
|
-
* widens recall from the caller's own peer to the whole user root, so doctor
|
|
438
|
-
* reads this file back and warns.
|
|
424
|
+
* Remember when the server rejects `peer_scope`. Dropping the field widens
|
|
425
|
+
* recall from the caller's own peer to the whole user root, so doctor reads
|
|
426
|
+
* this file back and warns.
|
|
439
427
|
*/
|
|
440
428
|
export function peerScopeMemoPath() {
|
|
441
429
|
return stateFile("peer-scope.json");
|
|
@@ -478,6 +466,7 @@ function wrapContext(body) {
|
|
|
478
466
|
* Server-assembled context: the context face when the deployment has it, else
|
|
479
467
|
* the deprecated /recall preset. Returns the injection block, "" when there was
|
|
480
468
|
* nothing relevant, or null when no server-side path was usable at all.
|
|
469
|
+
* A validation error is returned as { error }.
|
|
481
470
|
*/
|
|
482
471
|
export async function buildServerAssembledBlock(fetchJSON, cfg, query, options = {}) {
|
|
483
472
|
const actorPeerId = options.actorPeerId ?? cfg.peerId ?? "";
|
|
@@ -488,16 +477,12 @@ export async function buildServerAssembledBlock(fetchJSON, cfg, query, options =
|
|
|
488
477
|
return recallViaEndpoint(fetchJSON, cfg, query, { ...options, actorPeerId }, log);
|
|
489
478
|
}
|
|
490
479
|
/**
|
|
491
|
-
* Raw server-assembled context,
|
|
492
|
-
*
|
|
493
|
-
* (their own compression, their own envelope) use this instead of the block
|
|
494
|
-
* builders below.
|
|
480
|
+
* Raw server-assembled context, null when a fallback can be tried, or
|
|
481
|
+
* { error } when the server rejects the request parameters.
|
|
495
482
|
*/
|
|
496
483
|
export async function fetchAssembledContext(fetchJSON, cfg, query, options = {}) {
|
|
497
484
|
const actorPeerId = options.actorPeerId || "";
|
|
498
485
|
const log = options.log || (() => { });
|
|
499
|
-
if (await isContextFaceLegacy(options.legacyCachePath))
|
|
500
|
-
return null;
|
|
501
486
|
const body = buildContextSearchBody(cfg, options);
|
|
502
487
|
body.query = query;
|
|
503
488
|
const res = await fetchJSON("/api/v1/search/search", {
|
|
@@ -506,13 +491,12 @@ export async function fetchAssembledContext(fetchJSON, cfg, query, options = {})
|
|
|
506
491
|
}, { actorPeerId, timeoutMs: contextRequestTimeoutMs(cfg, body) });
|
|
507
492
|
if (!res.ok) {
|
|
508
493
|
const status = res.status || 0;
|
|
509
|
-
if (
|
|
510
|
-
|
|
511
|
-
log("
|
|
512
|
-
|
|
513
|
-
else {
|
|
514
|
-
log("recall_context_face_error", { status });
|
|
494
|
+
if (status === 400 || status === 422) {
|
|
495
|
+
const message = typeof res.error === "string" ? res.error : res.error?.message;
|
|
496
|
+
log("recall_context_request_rejected", { status, message });
|
|
497
|
+
return { error: `OpenViking auto recall failed (HTTP ${status}): ${message || "Invalid request parameters"}` };
|
|
515
498
|
}
|
|
499
|
+
log("recall_context_face_error", { status });
|
|
516
500
|
return null;
|
|
517
501
|
}
|
|
518
502
|
const result = res.result || {};
|
|
@@ -588,8 +572,8 @@ async function finalizeRecall(result, cfg, query, options, log, shortContext) {
|
|
|
588
572
|
}
|
|
589
573
|
async function recallViaContextFace(fetchJSON, cfg, query, options, log) {
|
|
590
574
|
const assembled = await fetchAssembledContext(fetchJSON, cfg, query, { ...options, log });
|
|
591
|
-
if (assembled === null)
|
|
592
|
-
return
|
|
575
|
+
if (assembled === null || assembled.error)
|
|
576
|
+
return assembled;
|
|
593
577
|
const text = await finalizeRecall(assembled, cfg, query, options, log);
|
|
594
578
|
return text ? wrapContext(text) : "";
|
|
595
579
|
}
|
|
@@ -657,12 +641,16 @@ export async function postRecall(fetchJSON, body, opts = {}) {
|
|
|
657
641
|
*/
|
|
658
642
|
export async function buildRecallBlockDetailed(fetchJSON, cfg, query, options = {}) {
|
|
659
643
|
const primary = await recallForPeer(fetchJSON, cfg, query, options);
|
|
644
|
+
if (primary.stage === "request_rejected")
|
|
645
|
+
return primary;
|
|
660
646
|
const legacyPeerId = String(options.legacyPeerId || "").trim();
|
|
661
647
|
const actorPeerId = options.actorPeerId ?? cfg.peerId ?? "";
|
|
662
648
|
if (cfg.recallPeerScope !== "actor" || !legacyPeerId || legacyPeerId === actorPeerId)
|
|
663
649
|
return primary;
|
|
664
650
|
const log = options.log || (() => { });
|
|
665
651
|
const legacy = await recallForPeer(fetchJSON, cfg, query, { ...options, actorPeerId: legacyPeerId });
|
|
652
|
+
if (legacy.error)
|
|
653
|
+
return { ...(primary.block ? primary : legacy), error: legacy.error };
|
|
666
654
|
if (!legacy.block)
|
|
667
655
|
return primary;
|
|
668
656
|
log("recall_legacy_peer_hit", { legacyPeerId });
|
|
@@ -674,9 +662,11 @@ export async function buildRecallBlockDetailed(fetchJSON, cfg, query, options =
|
|
|
674
662
|
stage: primary.block ? primary.stage : legacy.stage,
|
|
675
663
|
};
|
|
676
664
|
}
|
|
677
|
-
/** The block alone,
|
|
665
|
+
/** The block alone, with request errors reported to stderr. */
|
|
678
666
|
export async function buildRecallBlock(fetchJSON, cfg, query, options = {}) {
|
|
679
|
-
const { block } = await buildRecallBlockDetailed(fetchJSON, cfg, query, options);
|
|
667
|
+
const { block, error } = await buildRecallBlockDetailed(fetchJSON, cfg, query, options);
|
|
668
|
+
if (error)
|
|
669
|
+
console.error(error);
|
|
680
670
|
return block || null;
|
|
681
671
|
}
|
|
682
672
|
function emptyRecall(stage) {
|
|
@@ -688,13 +678,14 @@ async function recallForPeer(fetchJSON, cfg, query, options = {}) {
|
|
|
688
678
|
const trimmed = String(query || "").trim();
|
|
689
679
|
if (!trimmed)
|
|
690
680
|
return emptyRecall("no_results");
|
|
691
|
-
//
|
|
692
|
-
// older servers fall through to /recall, then to raw find.
|
|
681
|
+
// When Context is unavailable, fall back to /recall and then raw find.
|
|
693
682
|
const serverBlock = await buildServerAssembledBlock(fetchJSON, cfg, trimmed, {
|
|
694
683
|
...options,
|
|
695
684
|
actorPeerId,
|
|
696
685
|
log,
|
|
697
686
|
});
|
|
687
|
+
if (serverBlock?.error)
|
|
688
|
+
return { ...emptyRecall("request_rejected"), error: serverBlock.error };
|
|
698
689
|
if (serverBlock !== null) {
|
|
699
690
|
if (!serverBlock)
|
|
700
691
|
return emptyRecall("no_results");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openviking/openclaw-plugin",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.25-1",
|
|
4
4
|
"displayName": "OpenViking",
|
|
5
5
|
"description": "OpenClaw context-engine plugin — OpenViking AI memory, long-term memory, knowledge base, semantic search, RAG, context engine. 长期记忆 · 知识库 · 语义检索 · 上下文引擎",
|
|
6
6
|
"type": "module",
|
package/shared/recall-core.d.mts
CHANGED
|
@@ -55,7 +55,6 @@ export type RecallOptions = {
|
|
|
55
55
|
localCompressorAvailable?: boolean;
|
|
56
56
|
runCompressor?: ((prompt: string) => Promise<string | null>) | null;
|
|
57
57
|
digestCachePath?: string;
|
|
58
|
-
legacyCachePath?: string;
|
|
59
58
|
};
|
|
60
59
|
|
|
61
60
|
export type DetailedRecall = {
|
|
@@ -63,7 +62,8 @@ export type DetailedRecall = {
|
|
|
63
62
|
contentCount: number;
|
|
64
63
|
hintCount: number;
|
|
65
64
|
budgetUsed: number;
|
|
66
|
-
stage: "server_assembled" | "ranked" | "no_results" | "filtered_out";
|
|
65
|
+
stage: "server_assembled" | "ranked" | "no_results" | "filtered_out" | "request_rejected";
|
|
66
|
+
error?: string;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
export function buildRecallBlockDetailed(
|
package/shared/recall-core.mjs
CHANGED
|
@@ -129,8 +129,8 @@ export function buildContextSearchBody(cfg = {}, options = {}) {
|
|
|
129
129
|
if (limitConfigured) body.quotas = codingQuotas(limit);
|
|
130
130
|
if (maxTokensConfigured) body.max_tokens = maxTokens;
|
|
131
131
|
if (cfg.recallPeerScope === "actor") body.peer_scope = "actor";
|
|
132
|
-
const decayProtection = String(cfg.recallEventsDecayProtection
|
|
133
|
-
if (decayProtection) body.events_time_decay_protection = decayProtection;
|
|
132
|
+
const decayProtection = String(cfg.recallEventsDecayProtection ?? "").trim();
|
|
133
|
+
if (decayProtection && decayProtection !== "off") body.events_time_decay_protection = decayProtection;
|
|
134
134
|
|
|
135
135
|
const sessionId = String(options.sessionId || "").trim();
|
|
136
136
|
if (sessionId) {
|
|
@@ -433,23 +433,9 @@ async function writeJsonFile(path, value) {
|
|
|
433
433
|
}
|
|
434
434
|
|
|
435
435
|
/**
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
|
|
439
|
-
export async function isContextFaceLegacy(path = stateFile("context-face.json"), now = Date.now()) {
|
|
440
|
-
const cached = await readJsonFile(path);
|
|
441
|
-
return Boolean(cached?.legacyUntil && Number(cached.legacyUntil) > now);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
export async function markContextFaceLegacy(path = stateFile("context-face.json"), now = Date.now()) {
|
|
445
|
-
await writeJsonFile(path, { legacyUntil: now + LEGACY_CACHE_TTL_MS });
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* A `peer_scope` the server rejects is remembered the same way, but unlike the
|
|
450
|
-
* context face this one is not a silent capability probe: dropping the field
|
|
451
|
-
* widens recall from the caller's own peer to the whole user root, so doctor
|
|
452
|
-
* reads this file back and warns.
|
|
436
|
+
* Remember when the server rejects `peer_scope`. Dropping the field widens
|
|
437
|
+
* recall from the caller's own peer to the whole user root, so doctor reads
|
|
438
|
+
* this file back and warns.
|
|
453
439
|
*/
|
|
454
440
|
export function peerScopeMemoPath() {
|
|
455
441
|
return stateFile("peer-scope.json");
|
|
@@ -497,6 +483,7 @@ function wrapContext(body) {
|
|
|
497
483
|
* Server-assembled context: the context face when the deployment has it, else
|
|
498
484
|
* the deprecated /recall preset. Returns the injection block, "" when there was
|
|
499
485
|
* nothing relevant, or null when no server-side path was usable at all.
|
|
486
|
+
* A validation error is returned as { error }.
|
|
500
487
|
*/
|
|
501
488
|
export async function buildServerAssembledBlock(fetchJSON, cfg, query, options = {}) {
|
|
502
489
|
const actorPeerId = options.actorPeerId ?? cfg.peerId ?? "";
|
|
@@ -508,15 +495,12 @@ export async function buildServerAssembledBlock(fetchJSON, cfg, query, options =
|
|
|
508
495
|
}
|
|
509
496
|
|
|
510
497
|
/**
|
|
511
|
-
* Raw server-assembled context,
|
|
512
|
-
*
|
|
513
|
-
* (their own compression, their own envelope) use this instead of the block
|
|
514
|
-
* builders below.
|
|
498
|
+
* Raw server-assembled context, null when a fallback can be tried, or
|
|
499
|
+
* { error } when the server rejects the request parameters.
|
|
515
500
|
*/
|
|
516
501
|
export async function fetchAssembledContext(fetchJSON, cfg, query, options = {}) {
|
|
517
502
|
const actorPeerId = options.actorPeerId || "";
|
|
518
503
|
const log = options.log || (() => {});
|
|
519
|
-
if (await isContextFaceLegacy(options.legacyCachePath)) return null;
|
|
520
504
|
|
|
521
505
|
const body = buildContextSearchBody(cfg, options);
|
|
522
506
|
body.query = query;
|
|
@@ -527,12 +511,12 @@ export async function fetchAssembledContext(fetchJSON, cfg, query, options = {})
|
|
|
527
511
|
|
|
528
512
|
if (!res.ok) {
|
|
529
513
|
const status = res.status || 0;
|
|
530
|
-
if (
|
|
531
|
-
|
|
532
|
-
log("
|
|
533
|
-
|
|
534
|
-
log("recall_context_face_error", { status });
|
|
514
|
+
if (status === 400 || status === 422) {
|
|
515
|
+
const message = typeof res.error === "string" ? res.error : res.error?.message;
|
|
516
|
+
log("recall_context_request_rejected", { status, message });
|
|
517
|
+
return { error: `OpenViking auto recall failed (HTTP ${status}): ${message || "Invalid request parameters"}` };
|
|
535
518
|
}
|
|
519
|
+
log("recall_context_face_error", { status });
|
|
536
520
|
return null;
|
|
537
521
|
}
|
|
538
522
|
|
|
@@ -609,7 +593,7 @@ async function finalizeRecall(result, cfg, query, options, log, shortContext) {
|
|
|
609
593
|
|
|
610
594
|
async function recallViaContextFace(fetchJSON, cfg, query, options, log) {
|
|
611
595
|
const assembled = await fetchAssembledContext(fetchJSON, cfg, query, { ...options, log });
|
|
612
|
-
if (assembled === null) return
|
|
596
|
+
if (assembled === null || assembled.error) return assembled;
|
|
613
597
|
const text = await finalizeRecall(assembled, cfg, query, options, log);
|
|
614
598
|
return text ? wrapContext(text) : "";
|
|
615
599
|
}
|
|
@@ -683,6 +667,7 @@ export async function postRecall(fetchJSON, body, opts = {}) {
|
|
|
683
667
|
*/
|
|
684
668
|
export async function buildRecallBlockDetailed(fetchJSON, cfg, query, options = {}) {
|
|
685
669
|
const primary = await recallForPeer(fetchJSON, cfg, query, options);
|
|
670
|
+
if (primary.stage === "request_rejected") return primary;
|
|
686
671
|
|
|
687
672
|
const legacyPeerId = String(options.legacyPeerId || "").trim();
|
|
688
673
|
const actorPeerId = options.actorPeerId ?? cfg.peerId ?? "";
|
|
@@ -690,6 +675,7 @@ export async function buildRecallBlockDetailed(fetchJSON, cfg, query, options =
|
|
|
690
675
|
|
|
691
676
|
const log = options.log || (() => {});
|
|
692
677
|
const legacy = await recallForPeer(fetchJSON, cfg, query, { ...options, actorPeerId: legacyPeerId });
|
|
678
|
+
if (legacy.error) return { ...(primary.block ? primary : legacy), error: legacy.error };
|
|
693
679
|
if (!legacy.block) return primary;
|
|
694
680
|
log("recall_legacy_peer_hit", { legacyPeerId });
|
|
695
681
|
return {
|
|
@@ -701,9 +687,10 @@ export async function buildRecallBlockDetailed(fetchJSON, cfg, query, options =
|
|
|
701
687
|
};
|
|
702
688
|
}
|
|
703
689
|
|
|
704
|
-
/** The block alone,
|
|
690
|
+
/** The block alone, with request errors reported to stderr. */
|
|
705
691
|
export async function buildRecallBlock(fetchJSON, cfg, query, options = {}) {
|
|
706
|
-
const { block } = await buildRecallBlockDetailed(fetchJSON, cfg, query, options);
|
|
692
|
+
const { block, error } = await buildRecallBlockDetailed(fetchJSON, cfg, query, options);
|
|
693
|
+
if (error) console.error(error);
|
|
707
694
|
return block || null;
|
|
708
695
|
}
|
|
709
696
|
|
|
@@ -717,13 +704,13 @@ async function recallForPeer(fetchJSON, cfg, query, options = {}) {
|
|
|
717
704
|
const trimmed = String(query || "").trim();
|
|
718
705
|
if (!trimmed) return emptyRecall("no_results");
|
|
719
706
|
|
|
720
|
-
//
|
|
721
|
-
// older servers fall through to /recall, then to raw find.
|
|
707
|
+
// When Context is unavailable, fall back to /recall and then raw find.
|
|
722
708
|
const serverBlock = await buildServerAssembledBlock(fetchJSON, cfg, trimmed, {
|
|
723
709
|
...options,
|
|
724
710
|
actorPeerId,
|
|
725
711
|
log,
|
|
726
712
|
});
|
|
713
|
+
if (serverBlock?.error) return { ...emptyRecall("request_rejected"), error: serverBlock.error };
|
|
727
714
|
if (serverBlock !== null) {
|
|
728
715
|
if (!serverBlock) return emptyRecall("no_results");
|
|
729
716
|
// The server rendered one budgeted unit, so nothing here degraded to a
|