MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / extractMessageContent

Function extractMessageContent

sdk/cliproxy/auth/selector.go:776–802  ·  view source on GitHub ↗

extractMessageContent extracts text content from a message content field. Handles both string content and array content (multimodal messages). For array content, extracts text from all text-type elements.

(content gjson.Result)

Source from the content-addressed store, hash-verified

774// Handles both string content and array content (multimodal messages).
775// For array content, extracts text from all text-type elements.
776func extractMessageContent(content gjson.Result) string {
777 // String content: "Hello world"
778 if content.Type == gjson.String {
779 return content.String()
780 }
781
782 // Array content: [{"type":"text","text":"Hello"},{"type":"image",...}]
783 if content.IsArray() {
784 var texts []string
785 content.ForEach(func(_, part gjson.Result) bool {
786 // Handle Claude format: {"type":"text","text":"content"}
787 if part.Get("type").String() == "text" {
788 if text := part.Get("text").String(); text != "" {
789 texts = append(texts, text)
790 }
791 }
792 // Handle OpenAI format: {"type":"text","text":"content"}
793 // Same structure as Claude, already handled above
794 return true
795 })
796 if len(texts) > 0 {
797 return strings.Join(texts, " ")
798 }
799 }
800
801 return ""
802}
803
804func extractResponsesAPIContent(content gjson.Result) string {
805 if !content.IsArray() {

Callers 1

extractMessageHashIDsFunction · 0.85

Calls 2

StringMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected