@cc-soul/openclaw 1.0.0

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.
@@ -0,0 +1,94 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { resolve } from "path";
4
+ import { DATA_DIR, loadJson, debouncedSave } from "./persistence.ts";
5
+ const LOREBOOK_PATH = resolve(DATA_DIR, "lorebook.json");
6
+ let entries = [];
7
+ function loadLorebook() {
8
+ entries = loadJson(LOREBOOK_PATH, []);
9
+ console.log(`[cc-soul][lorebook] loaded ${entries.length} entries`);
10
+ }
11
+ __name(loadLorebook, "loadLorebook");
12
+ function saveLorebook() {
13
+ debouncedSave(LOREBOOK_PATH, entries);
14
+ }
15
+ __name(saveLorebook, "saveLorebook");
16
+ function addLorebookEntry(entry) {
17
+ const existing = entries.find(
18
+ (e) => e.keywords.some((k) => entry.keywords.includes(k)) && e.content === entry.content
19
+ );
20
+ if (existing) return;
21
+ entries.push({
22
+ ...entry,
23
+ id: Date.now().toString(36) + Math.random().toString(36).slice(2, 6),
24
+ createdAt: Date.now(),
25
+ hitCount: 0
26
+ });
27
+ if (entries.length > 200) {
28
+ entries.sort((a, b) => b.hitCount - a.hitCount);
29
+ entries = entries.slice(0, 150);
30
+ }
31
+ saveLorebook();
32
+ }
33
+ __name(addLorebookEntry, "addLorebookEntry");
34
+ function removeLorebookEntry(keyword) {
35
+ const idx = entries.findIndex(
36
+ (e) => e.keywords.some((k) => k.includes(keyword)) || e.content.includes(keyword)
37
+ );
38
+ if (idx >= 0) {
39
+ entries.splice(idx, 1);
40
+ saveLorebook();
41
+ return true;
42
+ }
43
+ return false;
44
+ }
45
+ __name(removeLorebookEntry, "removeLorebookEntry");
46
+ function queryLorebook(msg) {
47
+ if (!msg || entries.length === 0) return [];
48
+ const lower = msg.toLowerCase();
49
+ const matched = [];
50
+ for (const entry of entries) {
51
+ if (!entry.enabled) continue;
52
+ const hit = entry.keywords.some((kw) => lower.includes(kw.toLowerCase()));
53
+ if (hit) {
54
+ entry.hitCount++;
55
+ matched.push(entry);
56
+ }
57
+ }
58
+ if (matched.length > 0) saveLorebook();
59
+ return matched.sort((a, b) => b.priority - a.priority).slice(0, 5);
60
+ }
61
+ __name(queryLorebook, "queryLorebook");
62
+ function autoPopulateFromMemories(memories) {
63
+ const candidates = memories.filter(
64
+ (m) => (m.scope === "fact" || m.scope === "preference") && m.content.length > 15 && m.emotion === "important"
65
+ );
66
+ for (const mem of candidates.slice(-10)) {
67
+ const words = (mem.content.match(/[\u4e00-\u9fff]{2,4}|[a-z]{3,}/gi) || []).map((w) => w.toLowerCase()).filter((w) => w.length >= 2).slice(0, 5);
68
+ if (words.length >= 1) {
69
+ addLorebookEntry({
70
+ keywords: words,
71
+ content: mem.content,
72
+ priority: 7,
73
+ enabled: true,
74
+ category: mem.scope === "preference" ? "preference" : "fact"
75
+ });
76
+ }
77
+ }
78
+ }
79
+ __name(autoPopulateFromMemories, "autoPopulateFromMemories");
80
+ function getLorebookStats() {
81
+ if (entries.length === 0) return "";
82
+ const enabled = entries.filter((e) => e.enabled).length;
83
+ return `\u77E5\u8BC6\u5E93: ${enabled}/${entries.length} \u6761`;
84
+ }
85
+ __name(getLorebookStats, "getLorebookStats");
86
+ export {
87
+ addLorebookEntry,
88
+ autoPopulateFromMemories,
89
+ getLorebookStats,
90
+ loadLorebook,
91
+ entries as lorebookEntries,
92
+ queryLorebook,
93
+ removeLorebookEntry
94
+ };