@@ -8,6 +8,7 @@ import (
88 "time"
99
1010 "charm.land/catwalk/pkg/catwalk"
11+ "github.com/charmbracelet/crush/internal/message"
1112)
1213
1314// CreateMessageParams represents parameters for creating a message.
@@ -621,6 +622,47 @@ type Attachment struct {
621622 Content []byte `json:"content"`
622623}
623624
625+// ToMessage converts a proto Attachment to a [message.Attachment].
626+func (a Attachment) ToMessage() message.Attachment {
627+ return message.Attachment{
628+ FilePath: a.FilePath,
629+ FileName: a.FileName,
630+ MimeType: a.MimeType,
631+ Content: a.Content,
632+ }
633+}
634+
635+// AttachmentFromMessage converts a [message.Attachment] to a proto
636+// Attachment.
637+func AttachmentFromMessage(a message.Attachment) Attachment {
638+ return Attachment{
639+ FilePath: a.FilePath,
640+ FileName: a.FileName,
641+ MimeType: a.MimeType,
642+ Content: a.Content,
643+ }
644+}
645+
646+// AttachmentsToMessage converts a slice of proto Attachments to a slice
647+// of [message.Attachment].
648+func AttachmentsToMessage(as []Attachment) []message.Attachment {
649+ out := make([]message.Attachment, len(as))
650+ for i, a := range as {
651+ out[i] = a.ToMessage()
652+ }
653+ return out
654+}
655+
656+// AttachmentsFromMessage converts a slice of [message.Attachment] to a
657+// slice of proto Attachments.
658+func AttachmentsFromMessage(as []message.Attachment) []Attachment {
659+ out := make([]Attachment, len(as))
660+ for i, a := range as {
661+ out[i] = AttachmentFromMessage(a)
662+ }
663+ return out
664+}
665+
624666// MarshalJSON implements the [json.Marshaler] interface.
625667func (a Attachment) MarshalJSON() ([]byte, error) {
626668 type Alias Attachment