65 lines
2.2 KiB
JavaScript
65 lines
2.2 KiB
JavaScript
const DAEMON_URL = process.env.SIGNET_DAEMON_URL || "http://localhost:3850";
|
|
|
|
async function fetchDaemon(path, body) {
|
|
const res = await fetch(`${DAEMON_URL}${path}`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"x-signet-runtime-path": "legacy",
|
|
},
|
|
body: JSON.stringify({ ...body, runtimePath: "legacy" }),
|
|
signal: AbortSignal.timeout(5000),
|
|
});
|
|
if (!res.ok) throw new Error(`daemon ${res.status}`);
|
|
return res.json();
|
|
}
|
|
|
|
const handler = async (event) => {
|
|
// When the plugin runtime path is active, legacy hooks are disabled
|
|
// to prevent duplicate capture/recall. Set SIGNET_RUNTIME_PATH=plugin
|
|
// in your environment to use the plugin path exclusively.
|
|
if (process.env.SIGNET_RUNTIME_PATH === "plugin") return;
|
|
|
|
if (event.type !== "command") return;
|
|
const args = event.context?.args || "";
|
|
|
|
switch (event.action) {
|
|
case "new":
|
|
case "reset":
|
|
case "context":
|
|
try {
|
|
const data = await fetchDaemon("/api/hooks/session-start", {
|
|
harness: "openclaw",
|
|
});
|
|
if (data.inject) event.messages.push(data.inject);
|
|
} catch (e) {
|
|
if (event.action === "context") event.messages.push(`Error: ${e.message}`);
|
|
}
|
|
break;
|
|
case "remember":
|
|
if (!args.trim()) { event.messages.push("Usage: /remember <content>"); return; }
|
|
try {
|
|
await fetchDaemon("/api/hooks/remember", {
|
|
harness: "openclaw", who: "openclaw", content: args.trim(),
|
|
});
|
|
event.messages.push(`saved: ${args.trim().slice(0, 50)}...`);
|
|
} catch (e) { event.messages.push(`Error: ${e.message}`); }
|
|
break;
|
|
case "recall":
|
|
if (!args.trim()) { event.messages.push("Usage: /recall <query>"); return; }
|
|
try {
|
|
const data = await fetchDaemon("/api/hooks/recall", {
|
|
harness: "openclaw", query: args.trim(),
|
|
});
|
|
if (data.results?.length) {
|
|
event.messages.push(data.results.map(r => `- ${r.content}`).join("\n"));
|
|
} else {
|
|
event.messages.push("No memories found.");
|
|
}
|
|
} catch (e) { event.messages.push(`Error: ${e.message}`); }
|
|
break;
|
|
}
|
|
};
|
|
|
|
export default handler;
|