on main help sign in
feat: allow to send the prompt if its empty but has text attachments (#1809)
030c8fcCarlos Alexandro Becker
internal/agent/agent.go+1−1
@@ -134,7 +134,7 @@ func NewSessionAgent(
134}
134}
135
135
136func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy.AgentResult, error) {
136func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy.AgentResult, error) {
137− if call.Prompt == "" {
137+ if call.Prompt == "" && !message.ContainsTextAttachment(call.Attachments) {
138 return nil, ErrEmptyPrompt
138 return nil, ErrEmptyPrompt
139 }
139 }
140 if call.SessionID == "" {
140 if call.SessionID == "" {
internal/message/attachment.go+11−1
@@ -1,6 +1,9 @@
1package message
1package message
2
2
3+import (
4+ "slices"
3−import "strings"
5+ "strings"
6+)
4
7
5type Attachment struct {
8type Attachment struct {
6 FilePath string
9 FilePath string
@@ -11,3 +14,10 @@ type Attachment struct {
11
14
12func (a Attachment) IsText() bool { return strings.HasPrefix(a.MimeType, "text/") }
15func (a Attachment) IsText() bool { return strings.HasPrefix(a.MimeType, "text/") }
13func (a Attachment) IsImage() bool { return strings.HasPrefix(a.MimeType, "image/") }
16func (a Attachment) IsImage() bool { return strings.HasPrefix(a.MimeType, "image/") }
17+
18+// ContainsTextAttachment returns true if any of the attachments is a text attachment.
19+func ContainsTextAttachment(attachments []Attachment) bool {
20+ return slices.ContainsFunc(attachments, func(a Attachment) bool {
21+ return a.IsText()
22+ })
23+}
internal/ui/chat/user.go+5−1
@@ -60,7 +60,11 @@ func (m *UserMessageItem) Render(width int) string {
60
60
61 if len(m.message.BinaryContent()) > 0 {
61 if len(m.message.BinaryContent()) > 0 {
62 attachmentsStr := m.renderAttachments(cappedWidth)
62 attachmentsStr := m.renderAttachments(cappedWidth)
63+ if content == "" {
64+ content = attachmentsStr
65+ } else {
63− content = strings.Join([]string{content, "", attachmentsStr}, "\n")
66+ content = strings.Join([]string{content, "", attachmentsStr}, "\n")
67+ }
64 }
68 }
65
69
66 height = lipgloss.Height(content)
70 height = lipgloss.Height(content)
internal/ui/model/ui.go+1−1
@@ -872,7 +872,7 @@ func (m *UI) handleKeyPressMsg(msg tea.KeyPressMsg) tea.Cmd {
872
872
873 attachments := m.attachments.List()
873 attachments := m.attachments.List()
874 m.attachments.Reset()
874 m.attachments.Reset()
875− if len(value) == 0 {
875+ if len(value) == 0 && !message.ContainsTextAttachment(attachments) {
876 return nil
876 return nil
877 }
877 }
878
878