Skip to content

Render attachments & actions within Message component #184

@tobiasbueschel

Description

@tobiasbueschel

Now that we have an improved attachment layout for our <PromptInput /> component as per this PR #151, it would be great to also include an example of how attachments would look inside a user message in our documentation.

We could also consider adding a new component e.g., MessageAttachments that can render file parts automatically. Then it could look like this:

 <Message from={message.role}> 
   <MessageContent> 
     <Response> 
       {part.text} 
     </Response> 
   </MessageContent> 
  <MessageAttachments>
    {(attachment) => <MessageAttachment data={attachment} />}
  </MessageAttachments>
 </Message> 

References:

Which could work well with what we do in PromptInput too:

<PromptInputHeader>
<PromptInputAttachments>
{(attachment) => <PromptInputAttachment data={attachment} />}
</PromptInputAttachments>
</PromptInputHeader>

And we might need something like a Message Header / Footer / Actions so that one can trigger things such as edit user message and so on. Our current approach described in the docs renders actions outside the message component and only for assistant messages:

<Message from={message.role}>
<MessageContent>
<Response>
{part.text}
</Response>
</MessageContent>
</Message>
{message.role === 'assistant' && i === messages.length - 1 && (
<Actions className="mt-2">
<Action
onClick={() => regenerate()}
label="Retry"
>
<RefreshCcwIcon className="size-3" />
</Action>
<Action
onClick={() =>
navigator.clipboard.writeText(part.text)
}
label="Copy"
>
<CopyIcon className="size-3" />
</Action>
</Actions>
)}
</Fragment>

Slightly related issue: #183

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions