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

Function contextStringSlice

cli/plugins/builtin_context.go:502–523  ·  view source on GitHub ↗

contextStringSlice reads a string array OR a single string OR a comma-separated string from the first matching key.

(raw map[string]json.RawMessage, keys ...string)

Source from the content-addressed store, hash-verified

500// contextStringSlice reads a string array OR a single string OR a
501// comma-separated string from the first matching key.
502func contextStringSlice(raw map[string]json.RawMessage, keys ...string) []string {
503 for _, k := range keys {
504 v, ok := raw[k]
505 if !ok || len(v) == 0 {
506 continue
507 }
508 var arr []string
509 if err := json.Unmarshal(v, &arr); err == nil {
510 return trimNonEmpty(arr)
511 }
512 var s string
513 if err := json.Unmarshal(v, &s); err == nil {
514 if strings.Contains(s, ",") {
515 return trimNonEmpty(strings.Split(s, ","))
516 }
517 if t := strings.TrimSpace(s); t != "" {
518 return []string{t}
519 }
520 }
521 }
522 return nil
523}
524
525// trimNonEmpty trims each element and drops the empties.
526func trimNonEmpty(in []string) []string {

Callers 2

TestContextStringSliceFunction · 0.85
ExecuteWithStreamMethod · 0.85

Calls 1

trimNonEmptyFunction · 0.85

Tested by 1

TestContextStringSliceFunction · 0.68