MCPcopy Index your code
hub / github.com/coder/coder / AttachmentsFromMetadata

Function AttachmentsFromMetadata

coderd/x/chatd/chattool/attachment.go:150–171  ·  view source on GitHub ↗

AttachmentsFromMetadata decodes durable attachment metadata from a tool response so the persistence layer can promote them into assistant file parts.

(metadata string)

Source from the content-addressed store, hash-verified

148// AttachmentsFromMetadata decodes durable attachment metadata from a tool
149// response so the persistence layer can promote them into assistant file parts.
150func AttachmentsFromMetadata(metadata string) ([]AttachmentMetadata, error) {
151 if strings.TrimSpace(metadata) == "" {
152 return nil, nil
153 }
154
155 var decoded attachmentResponseMetadata
156 if err := json.Unmarshal([]byte(metadata), &decoded); err != nil {
157 return nil, xerrors.Errorf("unmarshal attachment metadata: %w", err)
158 }
159
160 attachments := make([]AttachmentMetadata, 0, len(decoded.Attachments))
161 for i, attachment := range decoded.Attachments {
162 if attachment.FileID == uuid.Nil {
163 return nil, xerrors.Errorf("attachment %d is missing file_id", i)
164 }
165 if attachment.MediaType == "" {
166 return nil, xerrors.Errorf("attachment %d is missing media_type", i)
167 }
168 attachments = append(attachments, attachment)
169 }
170 return attachments, nil
171}

Calls 2

UnmarshalMethod · 0.45
ErrorfMethod · 0.45