@@ -8,6 +8,7 @@ import (
10 "charm.land/catwalk/pkg/catwalk"
10 "charm.land/catwalk/pkg/catwalk"
11+ "github.com/charmbracelet/crush/internal/message"
13// CreateMessageParams represents parameters for creating a message.
14// CreateMessageParams represents parameters for creating a message.
@@ -621,6 +622,47 @@ type Attachment struct {
621 Content []byte `json:"content"`
622 Content []byte `json:"content"`
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,
635+// AttachmentFromMessage converts a [message.Attachment] to a proto
637+func AttachmentFromMessage(a message.Attachment) Attachment {
639+ FilePath: a.FilePath,
640+ FileName: a.FileName,
641+ MimeType: a.MimeType,
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()
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)
624// MarshalJSON implements the [json.Marshaler] interface.
666// MarshalJSON implements the [json.Marshaler] interface.
625func (a Attachment) MarshalJSON() ([]byte, error) {
667func (a Attachment) MarshalJSON() ([]byte, error) {
626 type Alias Attachment
668 type Alias Attachment