Fix memory page to use local store
This commit is contained in:
@@ -929,10 +929,62 @@ document.querySelector("#approvals")?.addEventListener("click", async (event) =>
|
||||
|
||||
document.querySelector("#memory-search")?.addEventListener("click", async () => {
|
||||
const q = document.querySelector("#memory-query").value;
|
||||
document.querySelector("#memory-results").textContent =
|
||||
JSON.stringify(await jsonFetch(`/v1/memory/search?q=${encodeURIComponent(q)}`), null, 2);
|
||||
await renderMemoryPageResults(q);
|
||||
});
|
||||
|
||||
document.querySelector("#memory-list-all")?.addEventListener("click", async () => {
|
||||
await renderMemoryPageResults("");
|
||||
});
|
||||
|
||||
document.querySelector("#memory-page-form")?.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const textInput = document.querySelector("#memory-page-text");
|
||||
const workspaceInput = document.querySelector("#memory-page-workspace");
|
||||
const text = textInput?.value.trim() || "";
|
||||
if (!text) return;
|
||||
await jsonFetch("/v1/memory", {
|
||||
method: "POST",
|
||||
headers: {"Content-Type": "application/json"},
|
||||
body: JSON.stringify({
|
||||
text,
|
||||
workspace: workspaceInput?.value.trim() || null,
|
||||
memory_type: "note",
|
||||
importance: 0.6,
|
||||
}),
|
||||
});
|
||||
textInput.value = "";
|
||||
await renderMemoryPageResults("");
|
||||
});
|
||||
|
||||
async function renderMemoryPageResults(query) {
|
||||
const container = document.querySelector("#memory-results");
|
||||
if (!container) return;
|
||||
const payload = query.trim()
|
||||
? await jsonFetch(`/v1/memory/search?q=${encodeURIComponent(query.trim())}`)
|
||||
: await jsonFetch("/v1/memory?limit=100");
|
||||
const results = payload.results || [];
|
||||
container.innerHTML = "";
|
||||
if (!results.length) {
|
||||
const empty = document.createElement("p");
|
||||
empty.className = "compact-empty";
|
||||
empty.textContent = "No memories found.";
|
||||
container.append(empty);
|
||||
return;
|
||||
}
|
||||
for (const memory of results) {
|
||||
const item = document.createElement("article");
|
||||
item.className = "memory-item";
|
||||
const text = document.createElement("p");
|
||||
text.textContent = memory.text;
|
||||
const meta = document.createElement("span");
|
||||
meta.textContent = `${memory.scope || "memory"} · ${memory.workspace || "global"} · ${memory.memory_type || "note"}`;
|
||||
item.append(text, meta);
|
||||
container.append(item);
|
||||
}
|
||||
}
|
||||
|
||||
renderMemoryPageResults("").catch(console.error);
|
||||
|
||||
bindChat();
|
||||
checkRuntime();
|
||||
loadSimplePages().catch(console.error);
|
||||
|
||||
Reference in New Issue
Block a user