List handles GET /api/memories and returns all memories for an agent+user, ranked by access frequency
(w ErrorResponseWriter, r *http.Request)
| 245 | |
| 246 | // List handles GET /api/memories and returns all memories for an agent+user, ranked by access frequency |
| 247 | func (h *MemoryHandler) List(w ErrorResponseWriter, r *http.Request) { |
| 248 | log := ctrllog.FromContext(r.Context()) |
| 249 | agentName := r.URL.Query().Get("agent_name") |
| 250 | userID := r.URL.Query().Get("user_id") |
| 251 | |
| 252 | if agentName == "" || userID == "" { |
| 253 | RespondWithError(w, http.StatusBadRequest, "Missing required query parameters (agent_name, user_id)") |
| 254 | return |
| 255 | } |
| 256 | |
| 257 | memories, err := h.DatabaseService.ListAgentMemories(r.Context(), agentName, userID) |
| 258 | if err != nil { |
| 259 | log.Error(err, "failed to list agent memories") |
| 260 | RespondWithError(w, http.StatusInternalServerError, fmt.Sprintf("failed to list memories: %v", err)) |
| 261 | return |
| 262 | } |
| 263 | |
| 264 | response := make([]ListMemoryResponse, 0, len(memories)) |
| 265 | for _, m := range memories { |
| 266 | item := ListMemoryResponse{ |
| 267 | ID: m.ID, |
| 268 | Content: m.Content, |
| 269 | AccessCount: int(m.AccessCount), |
| 270 | CreatedAt: m.CreatedAt.Format(time.RFC3339), |
| 271 | } |
| 272 | if m.ExpiresAt != nil { |
| 273 | item.ExpiresAt = m.ExpiresAt.Format(time.RFC3339) |
| 274 | } |
| 275 | response = append(response, item) |
| 276 | } |
| 277 | |
| 278 | RespondWithJSON(w, http.StatusOK, response) |
| 279 | } |
| 280 | |
| 281 | // Delete handles DELETE /api/memories |
| 282 | func (h *MemoryHandler) Delete(w ErrorResponseWriter, r *http.Request) { |