@minns/openclaw-minns 0.3.2 → 0.3.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/dist/index.d.ts +3 -1
- package/dist/index.js +158 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,9 +1,162 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { loadConfig, buildClient } from "./config.js";
|
|
3
|
+
import { dispatch } from "./tools.js";
|
|
4
|
+
const PLUGIN_ID = "openclaw-minns";
|
|
5
|
+
function getPluginConfig(api) {
|
|
6
|
+
return (api.config?.plugins?.entries?.[PLUGIN_ID]?.config ?? {});
|
|
7
|
+
}
|
|
8
|
+
function mask(v) {
|
|
9
|
+
if (!v)
|
|
10
|
+
return "missing";
|
|
11
|
+
if (v.length <= 6)
|
|
12
|
+
return "***";
|
|
13
|
+
return `${v.slice(0, 3)}***${v.slice(-2)}`;
|
|
14
|
+
}
|
|
1
15
|
export default {
|
|
2
|
-
id:
|
|
16
|
+
id: PLUGIN_ID,
|
|
17
|
+
name: "Minns MCP Bridge",
|
|
3
18
|
register(api) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
19
|
+
let proc = null;
|
|
20
|
+
let startCount = 0;
|
|
21
|
+
let lastExit = null;
|
|
22
|
+
const stop = () => {
|
|
23
|
+
if (!proc)
|
|
24
|
+
return;
|
|
25
|
+
try {
|
|
26
|
+
proc.kill("SIGTERM");
|
|
27
|
+
}
|
|
28
|
+
catch { }
|
|
29
|
+
proc = null;
|
|
30
|
+
};
|
|
31
|
+
const start = () => {
|
|
32
|
+
if (proc)
|
|
33
|
+
return; // already running
|
|
34
|
+
const cfg = getPluginConfig(api);
|
|
35
|
+
const command = cfg.command?.trim() || "openclaw-minns-mcp";
|
|
36
|
+
const args = Array.isArray(cfg.args) ? cfg.args : [];
|
|
37
|
+
const env = {
|
|
38
|
+
...process.env,
|
|
39
|
+
...(cfg.env ?? {}),
|
|
40
|
+
};
|
|
41
|
+
proc = spawn(command, args, {
|
|
42
|
+
env,
|
|
43
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
44
|
+
});
|
|
45
|
+
startCount += 1;
|
|
46
|
+
api.logger.info?.(`[${PLUGIN_ID}] started: ${command} ${args.join(" ")}`.trim());
|
|
47
|
+
proc.stdout.on("data", (d) => {
|
|
48
|
+
api.logger.debug?.(`[${PLUGIN_ID}] stdout: ${String(d).trim()}`);
|
|
49
|
+
});
|
|
50
|
+
proc.stderr.on("data", (d) => {
|
|
51
|
+
api.logger.warn?.(`[${PLUGIN_ID}] stderr: ${String(d).trim()}`);
|
|
52
|
+
});
|
|
53
|
+
proc.on("exit", (code, signal) => {
|
|
54
|
+
lastExit = { code, signal, at: new Date().toISOString() };
|
|
55
|
+
api.logger.warn?.(`[${PLUGIN_ID}] exited code=${code} signal=${signal ?? "none"}`);
|
|
56
|
+
proc = null;
|
|
57
|
+
});
|
|
58
|
+
proc.on("error", (err) => {
|
|
59
|
+
api.logger.error?.(`[${PLUGIN_ID}] process error: ${err instanceof Error ? err.message : String(err)}`);
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
// start on plugin load
|
|
63
|
+
start();
|
|
64
|
+
// graceful shutdown on process exit
|
|
65
|
+
const shutdown = () => stop();
|
|
66
|
+
process.once("SIGINT", shutdown);
|
|
67
|
+
process.once("SIGTERM", shutdown);
|
|
68
|
+
api.registerCommand({
|
|
69
|
+
name: "minns",
|
|
70
|
+
description: "Minns MCP bridge controls: status|ping|restart|stop|start",
|
|
71
|
+
acceptsArgs: true,
|
|
72
|
+
handler: async (ctx) => {
|
|
73
|
+
const arg = (ctx.args ?? "").trim().toLowerCase();
|
|
74
|
+
const cfg = getPluginConfig(api);
|
|
75
|
+
const env = cfg.env ?? {};
|
|
76
|
+
if (arg === "ping") {
|
|
77
|
+
return { text: proc ? "pong (mcp running)" : "pong (plugin loaded, mcp stopped)" };
|
|
78
|
+
}
|
|
79
|
+
if (arg === "restart") {
|
|
80
|
+
stop();
|
|
81
|
+
start();
|
|
82
|
+
return { text: "Minns MCP restarted" };
|
|
83
|
+
}
|
|
84
|
+
if (arg === "stop") {
|
|
85
|
+
stop();
|
|
86
|
+
return { text: "Minns MCP stopped." };
|
|
87
|
+
}
|
|
88
|
+
if (arg === "start") {
|
|
89
|
+
start();
|
|
90
|
+
return { text: proc ? "Minns MCP running" : "Minns MCP failed to start" };
|
|
91
|
+
}
|
|
92
|
+
const cmd = cfg.command?.trim() || "openclaw-minns-mcp";
|
|
93
|
+
const cmdArgs = Array.isArray(cfg.args) ? cfg.args : [];
|
|
94
|
+
return {
|
|
95
|
+
text: [
|
|
96
|
+
"openclaw-minns status",
|
|
97
|
+
`running: ${proc ? "yes" : "no"}`,
|
|
98
|
+
`pid: ${proc?.pid ?? "-"}`,
|
|
99
|
+
`starts: ${startCount}`,
|
|
100
|
+
`command: ${cmd} ${cmdArgs.join(" ")}`.trim(),
|
|
101
|
+
`MINNS_BASE_URL: ${env.MINNS_BASE_URL ?? "(not set)"}`,
|
|
102
|
+
`MINNS_API_KEY: ${mask(env.MINNS_API_KEY)}`,
|
|
103
|
+
`lastExit: ${lastExit
|
|
104
|
+
? `${lastExit.at} (code=${lastExit.code}, signal=${lastExit.signal ?? "none"})`
|
|
105
|
+
: "none"}`,
|
|
106
|
+
"",
|
|
107
|
+
"Use: /minns ping | /minns restart | /minns stop | /minns start",
|
|
108
|
+
].join("\n"),
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
// ------------------------------------------------------------------
|
|
113
|
+
// Hook: inbound message → Minns SDK
|
|
114
|
+
// ------------------------------------------------------------------
|
|
115
|
+
const minnsCfg = loadConfig();
|
|
116
|
+
const minnsClient = buildClient(minnsCfg);
|
|
117
|
+
api.registerHook({
|
|
118
|
+
id: "minns-inbound",
|
|
119
|
+
description: "Send inbound DM messages to Minns for memory & claim extraction",
|
|
120
|
+
events: ["message.received"],
|
|
121
|
+
async handler(event) {
|
|
122
|
+
const text = (event.text ?? "").trim();
|
|
123
|
+
if (!text)
|
|
124
|
+
return;
|
|
125
|
+
// Only process DMs (skip group/channel noise)
|
|
126
|
+
const kind = event.peer?.kind ?? "";
|
|
127
|
+
if (kind && kind !== "direct" && kind !== "dm")
|
|
128
|
+
return;
|
|
129
|
+
const agentId = 1; // default plugin agent
|
|
130
|
+
const sessionId = event.timestamp ?? Date.now();
|
|
131
|
+
try {
|
|
132
|
+
// 1. Capture the message as a Context event (enables claim extraction)
|
|
133
|
+
await minnsClient
|
|
134
|
+
.event("openclaw", {
|
|
135
|
+
agentId,
|
|
136
|
+
sessionId,
|
|
137
|
+
enableSemantic: true,
|
|
138
|
+
})
|
|
139
|
+
.context(text, "dm_message")
|
|
140
|
+
.state({
|
|
141
|
+
channel: event.channel,
|
|
142
|
+
sender_id: event.senderId,
|
|
143
|
+
peer_kind: kind,
|
|
144
|
+
})
|
|
145
|
+
.send();
|
|
146
|
+
api.logger.debug?.(`[${PLUGIN_ID}] ingested message from ${event.senderId ?? "unknown"}`);
|
|
147
|
+
// 2. Search for relevant memories to provide context back
|
|
148
|
+
const memories = await dispatch(minnsClient, "memory.search", {
|
|
149
|
+
query: text,
|
|
150
|
+
limit: 5,
|
|
151
|
+
agent_id: agentId,
|
|
152
|
+
});
|
|
153
|
+
api.logger.debug?.(`[${PLUGIN_ID}] memory recall: ${JSON.stringify(memories)}`);
|
|
154
|
+
}
|
|
155
|
+
catch (err) {
|
|
156
|
+
api.logger.error?.(`[${PLUGIN_ID}] hook error: ${err instanceof Error ? err.message : String(err)}`);
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
});
|
|
160
|
+
},
|
|
8
161
|
};
|
|
9
162
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources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