WriteMemory creates or proposes one Memory v2 entry.
(c *gin.Context)
| 321 | |
| 322 | // WriteMemory creates or proposes one Memory v2 entry. |
| 323 | func (h *BaseHandlers) WriteMemory(c *gin.Context) { |
| 324 | var req contract.MemoryCreateRequest |
| 325 | if err := c.ShouldBindJSON(&req); err != nil { |
| 326 | h.respondMemoryError( |
| 327 | c, |
| 328 | http.StatusBadRequest, |
| 329 | fmt.Errorf("%s: decode memory write request: %w", h.transportName(), err), |
| 330 | nil, |
| 331 | ) |
| 332 | return |
| 333 | } |
| 334 | if err := validateMemoryCreateRequest(req); err != nil { |
| 335 | h.respondMemoryError(c, StatusForMemoryError(err), err, nil) |
| 336 | return |
| 337 | } |
| 338 | |
| 339 | selector, err := h.resolveMemoryCreateSelector(c.Request.Context(), req) |
| 340 | if err != nil { |
| 341 | h.respondMemoryError(c, StatusForMemoryError(err), err, nil) |
| 342 | return |
| 343 | } |
| 344 | selector.Scope = defaultMemorySelectorScope(selector) |
| 345 | store, err := h.memoryRecallStoreForSelector(c.Request.Context(), selector) |
| 346 | if err != nil { |
| 347 | h.respondMemoryError(c, StatusForMemoryError(err), err, nil) |
| 348 | return |
| 349 | } |
| 350 | |
| 351 | decision, err := store.ProposeCandidate( |
| 352 | c.Request.Context(), |
| 353 | h.memoryCandidateFromCreate(selector, req), |
| 354 | ) |
| 355 | if err != nil { |
| 356 | h.respondMemoryError(c, StatusForMemoryError(err), err, nil) |
| 357 | return |
| 358 | } |
| 359 | if decision.Op == memcontract.OpReject { |
| 360 | h.respondDecisionRejected(c, decision) |
| 361 | return |
| 362 | } |
| 363 | |
| 364 | c.JSON(http.StatusOK, contract.MemoryMutationDecisionResponse{ |
| 365 | Decision: MemoryDecisionPayload(decision, nil), |
| 366 | Applied: memoryDecisionApplied(decision), |
| 367 | DryRun: req.DryRun, |
| 368 | }) |
| 369 | } |
| 370 | |
| 371 | // EditMemory edits one memory document through the controller. |
| 372 | func (h *BaseHandlers) EditMemory(c *gin.Context) { |
nothing calls this directly
no test coverage detected