MCPcopy Create free account
hub / github.com/diillson/chatcli / parseProfileFields

Function parseProfileFields

cli/plugins/builtin_memory.go:361–380  ·  view source on GitHub ↗

parseProfileFields extracts the key/value map from a profile invocation. It accepts {"fields":{...}} as well as a bare object {key:value,...} so the LLM can omit the wrapper.

(inner string)

Source from the content-addressed store, hash-verified

359// It accepts {"fields":{...}} as well as a bare object {key:value,...} so
360// the LLM can omit the wrapper.
361func parseProfileFields(inner string) (map[string]string, error) {
362 inner = strings.TrimSpace(inner)
363 if inner == "" {
364 return nil, nil
365 }
366 var wrapped struct {
367 Fields json.RawMessage `json:"fields"`
368 }
369 if err := json.Unmarshal([]byte(inner), &wrapped); err == nil && len(wrapped.Fields) > 0 {
370 if m := decodeFieldsObject(wrapped.Fields); len(m) > 0 {
371 return stringifyMap(m), nil
372 }
373 }
374 var bare map[string]interface{}
375 if err := json.Unmarshal([]byte(inner), &bare); err != nil {
376 return nil, fmt.Errorf("invalid fields JSON: %w", err)
377 }
378 delete(bare, "fields")
379 return stringifyMap(bare), nil
380}
381
382// decodeFieldsObject reads a JSON object from raw, accepting the direct
383// object form and the JSON-encoded string the agent flattener produces when

Callers 2

TestParseProfileFieldsFunction · 0.85
ExecuteWithStreamMethod · 0.85

Calls 3

decodeFieldsObjectFunction · 0.85
stringifyMapFunction · 0.85
ErrorfMethod · 0.80

Tested by 1

TestParseProfileFieldsFunction · 0.68