twindex-openclaw-plugin 0.4.2 → 0.4.3
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/package.json +1 -1
- package/src/index.ts +29 -6
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,16 +1,35 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { homedir } from "os";
|
|
1
4
|
import * as twindex from "./client.js";
|
|
2
5
|
import { createNotificationService } from "./sse-service.js";
|
|
3
6
|
|
|
7
|
+
let bootstrapping = false;
|
|
8
|
+
|
|
4
9
|
export default function register(api: any) {
|
|
5
10
|
const cfg = () => api.config?.plugins?.entries?.twindex?.config ?? {};
|
|
6
11
|
|
|
7
12
|
function persistConfig(updates: Record<string, any>) {
|
|
8
13
|
if (!api.config?.plugins?.entries?.twindex) return;
|
|
14
|
+
// Update in-memory config
|
|
9
15
|
api.config.plugins.entries.twindex.config = {
|
|
10
16
|
...cfg(),
|
|
11
17
|
...updates,
|
|
12
18
|
};
|
|
13
|
-
|
|
19
|
+
// Write to disk — OpenClaw plugin API does not expose config.save()
|
|
20
|
+
try {
|
|
21
|
+
const configPath = join(homedir(), ".openclaw", "openclaw.json");
|
|
22
|
+
const raw = readFileSync(configPath, "utf-8");
|
|
23
|
+
const disk = JSON.parse(raw);
|
|
24
|
+
if (!disk.plugins) disk.plugins = {};
|
|
25
|
+
if (!disk.plugins.entries) disk.plugins.entries = {};
|
|
26
|
+
if (!disk.plugins.entries.twindex) disk.plugins.entries.twindex = {};
|
|
27
|
+
disk.plugins.entries.twindex.config = api.config.plugins.entries.twindex.config;
|
|
28
|
+
writeFileSync(configPath, JSON.stringify(disk, null, 2) + "\n", "utf-8");
|
|
29
|
+
api.logger?.info?.("Twindex: config persisted to disk");
|
|
30
|
+
} catch (err: any) {
|
|
31
|
+
api.logger?.warn?.(`Twindex: failed to persist config: ${err.message}`);
|
|
32
|
+
}
|
|
14
33
|
}
|
|
15
34
|
|
|
16
35
|
// ── SSE notification service ──────────────────────────────────────
|
|
@@ -20,9 +39,11 @@ export default function register(api: any) {
|
|
|
20
39
|
// ── Auto-bootstrap: register + subscribe ────────────────────────
|
|
21
40
|
|
|
22
41
|
(async () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
if (bootstrapping) return;
|
|
43
|
+
bootstrapping = true;
|
|
44
|
+
try {
|
|
45
|
+
const config = cfg();
|
|
46
|
+
if (config.artists?.length > 0 && config.frequency && !config.apiKey) {
|
|
26
47
|
const agentId =
|
|
27
48
|
api.agentId ?? api.config?.agentId ?? `openclaw-${crypto.randomUUID()}`;
|
|
28
49
|
const reg = await twindex.register(agentId);
|
|
@@ -44,9 +65,11 @@ export default function register(api: any) {
|
|
|
44
65
|
api.logger?.info?.(
|
|
45
66
|
"Twindex: auto-bootstrap complete. Delivery via SSE push.",
|
|
46
67
|
);
|
|
47
|
-
} catch (err: any) {
|
|
48
|
-
api.logger?.warn?.(`Twindex: auto-bootstrap failed: ${err.message}`);
|
|
49
68
|
}
|
|
69
|
+
} catch (err: any) {
|
|
70
|
+
api.logger?.warn?.(`Twindex: auto-bootstrap failed: ${err.message}`);
|
|
71
|
+
} finally {
|
|
72
|
+
bootstrapping = false;
|
|
50
73
|
}
|
|
51
74
|
})();
|
|
52
75
|
|