MCPcopy Create free account
hub / github.com/astercloud/aster / ListWorkingMemory

Method ListWorkingMemory

server/handlers/memory.go:131–177  ·  view source on GitHub ↗

ListWorkingMemory lists working memory

(c *gin.Context)

Source from the content-addressed store, hash-verified

129
130// ListWorkingMemory lists working memory
131func (h *MemoryHandler) ListWorkingMemory(c *gin.Context) {
132 ctx := c.Request.Context()
133 sessionID := c.Query("session_id")
134 agentID := c.Query("agent_id")
135
136 records, err := (*h.store).List(ctx, "working_memory")
137 if err != nil {
138 c.JSON(http.StatusInternalServerError, gin.H{
139 "success": false,
140 "error": gin.H{
141 "code": "internal_error",
142 "message": "Failed to list working memory: " + err.Error(),
143 },
144 })
145 return
146 }
147
148 memories := make([]*WorkingMemoryRecord, 0)
149 now := time.Now()
150
151 for _, record := range records {
152 var memory WorkingMemoryRecord
153 if err := store.DecodeValue(record, &memory); err != nil {
154 continue
155 }
156
157 // 检查是否过期
158 if memory.ExpiresAt != nil && memory.ExpiresAt.Before(now) {
159 continue
160 }
161
162 // 过滤
163 if sessionID != "" && memory.SessionID != sessionID {
164 continue
165 }
166 if agentID != "" && memory.AgentID != agentID {
167 continue
168 }
169
170 memories = append(memories, &memory)
171 }
172
173 c.JSON(http.StatusOK, gin.H{
174 "success": true,
175 "data": memories,
176 })
177}
178
179// GetWorkingMemory gets a single working memory
180func (h *MemoryHandler) GetWorkingMemory(c *gin.Context) {

Callers

nothing calls this directly

Calls 6

DecodeValueFunction · 0.92
JSONMethod · 0.80
ContextMethod · 0.65
QueryMethod · 0.65
ListMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected