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

Method Get

pkg/memory/working.go:109–137  ·  view source on GitHub ↗

Get 获取 Working Memory 内容 根据配置的 scope 自动选择读取路径: - thread scope: /working_memory/threads/ .json - resource scope: /working_memory/resources/ .json

(ctx context.Context, threadID, resourceID string)

Source from the content-addressed store, hash-verified

107// - thread scope: /working_memory/threads/<threadID>.json
108// - resource scope: /working_memory/resources/<resourceID>.json
109func (wm *WorkingMemoryManager) Get(ctx context.Context, threadID, resourceID string) (string, error) {
110 if threadID == "" && resourceID == "" {
111 return "", errors.New("threadID and resourceID cannot both be empty")
112 }
113
114 path := wm.resolvePath(threadID, resourceID)
115
116 content, err := wm.backend.Read(ctx, path, 0, 0)
117 if err != nil {
118 // 文件不存在时返回空字符串,不报错
119 if strings.Contains(strings.ToLower(err.Error()), "not found") {
120 return "", nil
121 }
122 return "", fmt.Errorf("read working memory: %w", err)
123 }
124
125 // 解析 JSON
126 var data WorkingMemoryData
127 if err := json.Unmarshal([]byte(content), &data); err != nil {
128 return "", fmt.Errorf("parse working memory: %w", err)
129 }
130
131 // 检查是否过期
132 if data.Meta.ExpiresAt != nil && time.Now().After(*data.Meta.ExpiresAt) {
133 return "", nil // 已过期,返回空
134 }
135
136 return data.Content, nil
137}
138
139// Update 更新 Working Memory 内容
140// content: 新的内容(Markdown 或 JSON 字符串)

Calls 3

resolvePathMethod · 0.95
ReadMethod · 0.65
ErrorMethod · 0.65