MCPcopy
hub / github.com/sipeed/picoclaw / extractInlineMediaRefs

Function extractInlineMediaRefs

pkg/tools/normalization.go:137–176  ·  view source on GitHub ↗
(
	text string,
	toolName string,
	store media.MediaStore,
	channel string,
	chatID string,
	seen map[string]struct{},
)

Source from the content-addressed store, hash-verified

135}
136
137func extractInlineMediaRefs(
138 text string,
139 toolName string,
140 store media.MediaStore,
141 channel string,
142 chatID string,
143 seen map[string]struct{},
144) (cleaned string, refs []string, notes []string) {
145 cleaned = text
146
147 matches := inlineMarkdownDataURLRe.FindAllStringSubmatch(cleaned, -1)
148 for _, match := range matches {
149 if len(match) < 2 {
150 continue
151 }
152 dataURL := match[1]
153 ref, note := storeInlineDataURL(toolName, store, channel, chatID, dataURL, seen)
154 if ref != "" {
155 refs = append(refs, ref)
156 }
157 if note != "" {
158 notes = append(notes, note)
159 }
160 cleaned = strings.ReplaceAll(cleaned, match[0], "")
161 }
162
163 rawMatches := inlineRawDataURLRe.FindAllString(cleaned, -1)
164 for _, dataURL := range rawMatches {
165 ref, note := storeInlineDataURL(toolName, store, channel, chatID, dataURL, seen)
166 if ref != "" {
167 refs = append(refs, ref)
168 }
169 if note != "" {
170 notes = append(notes, note)
171 }
172 cleaned = strings.ReplaceAll(cleaned, dataURL, "")
173 }
174
175 return strings.TrimSpace(cleaned), refs, notes
176}
177
178func storeInlineDataURL(
179 toolName string,

Callers 1

normalizeToolResultFunction · 0.85

Calls 1

storeInlineDataURLFunction · 0.85

Tested by

no test coverage detected