-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show all actions in the message window (#5190)
Co-authored-by: openhands <[email protected]> Co-authored-by: Graham Neubig <[email protected]> Co-authored-by: amanape <[email protected]>
- Loading branch information
1 parent
d617f6f
commit 793e142
Showing
15 changed files
with
452 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
frontend/src/components/features/chat/expandable-message.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { useState, useEffect } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import Markdown from "react-markdown"; | ||
import remarkGfm from "remark-gfm"; | ||
import { code } from "../markdown/code"; | ||
import { ol, ul } from "../markdown/list"; | ||
import ArrowUp from "#/icons/angle-up-solid.svg?react"; | ||
import ArrowDown from "#/icons/angle-down-solid.svg?react"; | ||
|
||
interface ExpandableMessageProps { | ||
id?: string; | ||
message: string; | ||
type: string; | ||
} | ||
|
||
export function ExpandableMessage({ | ||
id, | ||
message, | ||
type, | ||
}: ExpandableMessageProps) { | ||
const { t, i18n } = useTranslation(); | ||
const [showDetails, setShowDetails] = useState(true); | ||
const [headline, setHeadline] = useState(""); | ||
const [details, setDetails] = useState(message); | ||
|
||
useEffect(() => { | ||
if (id && i18n.exists(id)) { | ||
setHeadline(t(id)); | ||
setDetails(message); | ||
setShowDetails(false); | ||
} | ||
}, [id, message, i18n.language]); | ||
|
||
const border = type === "error" ? "border-danger" : "border-neutral-300"; | ||
const textColor = type === "error" ? "text-danger" : "text-neutral-300"; | ||
let arrowClasses = "h-4 w-4 ml-2 inline"; | ||
if (type === "error") { | ||
arrowClasses += " fill-danger"; | ||
} else { | ||
arrowClasses += " fill-neutral-300"; | ||
} | ||
|
||
return ( | ||
<div | ||
className={`flex gap-2 items-center justify-start border-l-2 pl-2 my-2 py-2 ${border}`} | ||
> | ||
<div className="text-sm leading-4 flex flex-col gap-2 max-w-full"> | ||
{headline && ( | ||
<p className={`${textColor} font-bold`}> | ||
{headline} | ||
<button | ||
type="button" | ||
onClick={() => setShowDetails(!showDetails)} | ||
className="cursor-pointer text-left" | ||
> | ||
{showDetails ? ( | ||
<ArrowUp className={arrowClasses} /> | ||
) : ( | ||
<ArrowDown className={arrowClasses} /> | ||
)} | ||
</button> | ||
</p> | ||
)} | ||
{showDetails && ( | ||
<Markdown | ||
className="text-sm overflow-auto" | ||
components={{ | ||
code, | ||
ul, | ||
ol, | ||
}} | ||
remarkPlugins={[remarkGfm]} | ||
> | ||
{details} | ||
</Markdown> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,39 @@ | ||
import { ChatMessage } from "#/components/features/chat/chat-message"; | ||
import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons"; | ||
import { ImageCarousel } from "../images/image-carousel"; | ||
import { ErrorMessage } from "./error-message"; | ||
|
||
const isErrorMessage = ( | ||
message: Message | ErrorMessage, | ||
): message is ErrorMessage => "error" in message; | ||
import { ExpandableMessage } from "./expandable-message"; | ||
|
||
interface MessagesProps { | ||
messages: (Message | ErrorMessage)[]; | ||
messages: Message[]; | ||
isAwaitingUserConfirmation: boolean; | ||
} | ||
|
||
export function Messages({ | ||
messages, | ||
isAwaitingUserConfirmation, | ||
}: MessagesProps) { | ||
return messages.map((message, index) => | ||
isErrorMessage(message) ? ( | ||
<ErrorMessage key={index} id={message.id} message={message.message} /> | ||
) : ( | ||
return messages.map((message, index) => { | ||
if (message.type === "error" || message.type === "action") { | ||
console.log("expando", message); | ||
return ( | ||
<ExpandableMessage | ||
key={index} | ||
type={message.type} | ||
id={message.translationID} | ||
message={message.content} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<ChatMessage key={index} type={message.sender} message={message.content}> | ||
{message.imageUrls.length > 0 && ( | ||
{message.imageUrls && message.imageUrls.length > 0 && ( | ||
<ImageCarousel size="small" images={message.imageUrls} /> | ||
)} | ||
{messages.length - 1 === index && | ||
message.sender === "assistant" && | ||
isAwaitingUserConfirmation && <ConfirmationButtons />} | ||
</ChatMessage> | ||
), | ||
); | ||
); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
type Message = { | ||
sender: "user" | "assistant"; | ||
content: string; | ||
imageUrls: string[]; | ||
timestamp: string; | ||
imageUrls?: string[]; | ||
type?: "thought" | "error" | "action"; | ||
pending?: boolean; | ||
}; | ||
|
||
type ErrorMessage = { | ||
error: boolean; | ||
id?: string; | ||
message: string; | ||
translationID?: string; | ||
eventID?: number; | ||
}; |
Oops, something went wrong.