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

Function FromMetadata

pkg/memory/provenance.go:193–264  ·  view source on GitHub ↗

FromMetadata 从 metadata map 中提取 Provenance。

(meta map[string]any)

Source from the content-addressed store, hash-verified

191
192// FromMetadata 从 metadata map 中提取 Provenance。
193func FromMetadata(meta map[string]any) *MemoryProvenance {
194 if meta == nil {
195 return nil
196 }
197
198 provData, ok := meta["provenance"].(map[string]any)
199 if !ok {
200 return nil
201 }
202
203 p := &MemoryProvenance{}
204
205 if st, ok := provData["source_type"].(string); ok {
206 p.SourceType = SourceType(st)
207 }
208
209 if conf, ok := provData["confidence"].(float64); ok {
210 p.Confidence = conf
211 }
212
213 if sources, ok := provData["sources"].([]any); ok {
214 for _, s := range sources {
215 if str, ok := s.(string); ok {
216 p.Sources = append(p.Sources, str)
217 }
218 }
219 } else if sources, ok := provData["sources"].([]string); ok {
220 p.Sources = sources
221 }
222
223 if createdStr, ok := provData["created_at"].(string); ok {
224 if t, err := time.Parse(time.RFC3339, createdStr); err == nil {
225 p.CreatedAt = t
226 }
227 }
228
229 if updatedStr, ok := provData["updated_at"].(string); ok {
230 if t, err := time.Parse(time.RFC3339, updatedStr); err == nil {
231 p.UpdatedAt = t
232 }
233 }
234
235 if v, ok := provData["version"].(int); ok {
236 p.Version = v
237 }
238
239 if explicit, ok := provData["is_explicit"].(bool); ok {
240 p.IsExplicit = explicit
241 }
242
243 if count, ok := provData["corroboration_count"].(int); ok {
244 p.CorroborationCount = count
245 }
246
247 if accessedStr, ok := provData["last_accessed_at"].(string); ok {
248 if t, err := time.Parse(time.RFC3339, accessedStr); err == nil {
249 p.LastAccessedAt = &t
250 }

Callers 4

TestFromMetadataFunction · 0.85
SearchBySourceTypeMethod · 0.85
GetMemoryProvenanceMethod · 0.85

Calls 2

SourceTypeTypeAlias · 0.85
ParseMethod · 0.65

Tested by 1

TestFromMetadataFunction · 0.68