(req: http.IncomingMessage, res: http.ServerResponse, urlPath: string)
| 1502 | } |
| 1503 | |
| 1504 | private handleUpdate(req: http.IncomingMessage, res: http.ServerResponse, urlPath: string): void { |
| 1505 | const chunkId = urlPath.replace("/api/memory/", ""); |
| 1506 | this.readBody(req, (body) => { |
| 1507 | try { |
| 1508 | const data = JSON.parse(body); |
| 1509 | if (data.content !== undefined && (typeof data.content !== "string" || !data.content.trim())) { |
| 1510 | res.writeHead(400, { "Content-Type": "application/json" }); |
| 1511 | res.end(JSON.stringify({ error: "content must be a non-empty string" })); |
| 1512 | return; |
| 1513 | } |
| 1514 | const ok = this.store.updateChunk(chunkId, { summary: data.summary, content: data.content, role: data.role, owner: data.owner }); |
| 1515 | if (ok) this.jsonResponse(res, { ok: true, message: "Memory updated" }); |
| 1516 | else { res.writeHead(404, { "Content-Type": "application/json" }); res.end(JSON.stringify({ error: "Not found" })); } |
| 1517 | } catch (err) { |
| 1518 | res.writeHead(400, { "Content-Type": "application/json" }); |
| 1519 | res.end(JSON.stringify({ error: String(err) })); |
| 1520 | } |
| 1521 | }); |
| 1522 | } |
| 1523 | |
| 1524 | private handleDelete(res: http.ServerResponse, urlPath: string): void { |
| 1525 | const chunkId = urlPath.replace("/api/memory/", ""); |
no test coverage detected