@decentchat/decentclaw 0.1.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.
- package/README.md +88 -0
- package/index.ts +17 -0
- package/openclaw.plugin.json +31 -0
- package/package.json +48 -0
- package/src/channel.ts +789 -0
- package/src/huddle/AudioPipeline.ts +174 -0
- package/src/huddle/BotHuddleManager.ts +882 -0
- package/src/huddle/SpeechToText.ts +223 -0
- package/src/huddle/TextToSpeech.ts +260 -0
- package/src/huddle/index.ts +8 -0
- package/src/monitor.ts +1266 -0
- package/src/peer/DecentChatNodePeer.ts +4570 -0
- package/src/peer/FileStore.ts +59 -0
- package/src/peer/NodeMessageProtocol.ts +1057 -0
- package/src/peer/SyncProtocol.ts +701 -0
- package/src/peer/polyfill.ts +43 -0
- package/src/peer-registry.ts +32 -0
- package/src/runtime.ts +63 -0
- package/src/types.ts +136 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FileStore — JSON file persistence for the DecentChat Node.js peer.
|
|
3
|
+
* Replaces PersistentStore (IndexedDB) for Node.js environments.
|
|
4
|
+
* Stores everything under dataDir (default: ~/.openclaw/data/decentchat/)
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync, writeFileSync, mkdirSync, existsSync, unlinkSync, readdirSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import { homedir } from 'node:os';
|
|
9
|
+
|
|
10
|
+
export class FileStore {
|
|
11
|
+
private readonly dir: string;
|
|
12
|
+
private cache = new Map<string, unknown>();
|
|
13
|
+
|
|
14
|
+
constructor(dataDir?: string) {
|
|
15
|
+
this.dir = dataDir ?? join(homedir(), '.openclaw', 'data', 'decentchat');
|
|
16
|
+
if (!existsSync(this.dir)) mkdirSync(this.dir, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get<T>(key: string, defaultValue: T): T {
|
|
20
|
+
if (this.cache.has(key)) return this.cache.get(key) as T;
|
|
21
|
+
const filePath = join(this.dir, `${key}.json`);
|
|
22
|
+
if (!existsSync(filePath)) return defaultValue;
|
|
23
|
+
try {
|
|
24
|
+
const data = JSON.parse(readFileSync(filePath, 'utf-8')) as T;
|
|
25
|
+
this.cache.set(key, data);
|
|
26
|
+
return data;
|
|
27
|
+
} catch {
|
|
28
|
+
return defaultValue;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
set<T>(key: string, value: T): void {
|
|
33
|
+
this.cache.set(key, value);
|
|
34
|
+
const filePath = join(this.dir, `${key}.json`);
|
|
35
|
+
writeFileSync(filePath, JSON.stringify(value, null, 2), 'utf-8');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
delete(key: string): void {
|
|
39
|
+
this.cache.delete(key);
|
|
40
|
+
const filePath = join(this.dir, `${key}.json`);
|
|
41
|
+
if (existsSync(filePath)) unlinkSync(filePath);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
keys(prefix = ''): string[] {
|
|
45
|
+
const keys = new Set<string>();
|
|
46
|
+
|
|
47
|
+
for (const key of this.cache.keys()) {
|
|
48
|
+
if (key.startsWith(prefix)) keys.add(key);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
for (const entry of readdirSync(this.dir, { withFileTypes: true })) {
|
|
52
|
+
if (!entry.isFile() || !entry.name.endsWith('.json')) continue;
|
|
53
|
+
const key = entry.name.slice(0, -'.json'.length);
|
|
54
|
+
if (key.startsWith(prefix)) keys.add(key);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return Array.from(keys);
|
|
58
|
+
}
|
|
59
|
+
}
|