diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 759a9274f2f4cc8c306ac0cc042de89cd1a25097..7c7ac4c6c1f3d320fe3e3dd865f8e7b56c73010d 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -134,7 +134,7 @@ func NewSessionAgent( } func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy.AgentResult, error) { - if call.Prompt == "" { + if call.Prompt == "" && !message.ContainsTextAttachment(call.Attachments) { return nil, ErrEmptyPrompt } if call.SessionID == "" { diff --git a/internal/message/attachment.go b/internal/message/attachment.go index 0e3b70a8766c74d37399c1ba8c38fe19e74f871d..c3c04aaea237e9ad060a8687c123a82643edba24 100644 --- a/internal/message/attachment.go +++ b/internal/message/attachment.go @@ -1,6 +1,9 @@ package message -import "strings" +import ( + "slices" + "strings" +) type Attachment struct { FilePath string @@ -11,3 +14,10 @@ type Attachment struct { func (a Attachment) IsText() bool { return strings.HasPrefix(a.MimeType, "text/") } func (a Attachment) IsImage() bool { return strings.HasPrefix(a.MimeType, "image/") } + +// ContainsTextAttachment returns true if any of the attachments is a text attachment. +func ContainsTextAttachment(attachments []Attachment) bool { + return slices.ContainsFunc(attachments, func(a Attachment) bool { + return a.IsText() + }) +} diff --git a/internal/ui/chat/user.go b/internal/ui/chat/user.go index 2b36c0a26896ca3fd87afc7e2826fabf21cfd4ae..5eb452b1fbc396f3c603af89dea9de000502fb94 100644 --- a/internal/ui/chat/user.go +++ b/internal/ui/chat/user.go @@ -60,7 +60,11 @@ func (m *UserMessageItem) Render(width int) string { if len(m.message.BinaryContent()) > 0 { attachmentsStr := m.renderAttachments(cappedWidth) - content = strings.Join([]string{content, "", attachmentsStr}, "\n") + if content == "" { + content = attachmentsStr + } else { + content = strings.Join([]string{content, "", attachmentsStr}, "\n") + } } height = lipgloss.Height(content) diff --git a/internal/ui/model/ui.go b/internal/ui/model/ui.go index 98685e0a2128e938d1439e2ab78b2a84398cab6d..d666cffc796ff309e75be5fc403bea01c4b049b5 100644 --- a/internal/ui/model/ui.go +++ b/internal/ui/model/ui.go @@ -872,7 +872,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd { attachments := m.attachments.List() m.attachments.Reset() - if len(value) == 0 { + if len(value) == 0 && !message.ContainsTextAttachment(attachments) { return nil }