Skip to content

πŸ™Œ OpenHands: AI-Driven Development

refactor(frontend): event message (#11001)

Hiep Lefce66e94e777
diff --git a/frontend/src/components/features/chat/event-message-components/error-event-message.tsx b/frontend/src/components/features/chat/event-message-components/error-event-message.tsx
new file mode 100644
index 0000000000..9259f39db2
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/error-event-message.tsx
@@ -0,0 +1,68 @@
+import React from "react";
+import { OpenHandsObservation } from "#/types/core/observations";
+import { isErrorObservation } from "#/types/core/guards";
+import { ErrorMessage } from "../error-message";
+import { MicroagentStatusWrapper } from "./microagent-status-wrapper";
+import { LikertScaleWrapper } from "./likert-scale-wrapper";
+import { MicroagentStatus } from "#/types/microagent-status";
+
+interface ErrorEventMessageProps {
+ event: OpenHandsObservation;
+ microagentStatus?: MicroagentStatus | null;
+ microagentConversationId?: string;
+ microagentPRUrl?: string;
+ actions?: Array<{
+ icon: React.ReactNode;
+ onClick: () => void;
+ tooltip?: string;
+ }>;
+ isLastMessage: boolean;
+ isInLast10Actions: boolean;
+ config?: { APP_MODE?: string } | null;
+ isCheckingFeedback: boolean;
+ feedbackData: {
+ exists: boolean;
+ rating?: number;
+ reason?: string;
+ };
+}
+
+export function ErrorEventMessage({
+ event,
+ microagentStatus,
+ microagentConversationId,
+ microagentPRUrl,
+ actions,
+ isLastMessage,
+ isInLast10Actions,
+ config,
+ isCheckingFeedback,
+ feedbackData,
+}: ErrorEventMessageProps) {
+ if (!isErrorObservation(event)) {
+ return null;
+ }
+
+ return (
+ <div>
+ <ErrorMessage
+ errorId={event.extras.error_id}
+ defaultMessage={event.message}
+ />
+ <MicroagentStatusWrapper
+ microagentStatus={microagentStatus}
+ microagentConversationId={microagentConversationId}
+ microagentPRUrl={microagentPRUrl}
+ actions={actions}
+ />
+ <LikertScaleWrapper
+ event={event}
+ isLastMessage={isLastMessage}
+ isInLast10Actions={isInLast10Actions}
+ config={config}
+ isCheckingFeedback={isCheckingFeedback}
+ feedbackData={feedbackData}
+ />
+ </div>
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/finish-event-message.tsx b/frontend/src/components/features/chat/event-message-components/finish-event-message.tsx
new file mode 100644
index 0000000000..52bd9de7f2
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/finish-event-message.tsx
@@ -0,0 +1,70 @@
+import React from "react";
+import { OpenHandsAction } from "#/types/core/actions";
+import { isFinishAction } from "#/types/core/guards";
+import { ChatMessage } from "../chat-message";
+import { MicroagentStatusWrapper } from "./microagent-status-wrapper";
+import { LikertScaleWrapper } from "./likert-scale-wrapper";
+import { getEventContent } from "../event-content-helpers/get-event-content";
+import { MicroagentStatus } from "#/types/microagent-status";
+
+interface FinishEventMessageProps {
+ event: OpenHandsAction;
+ microagentStatus?: MicroagentStatus | null;
+ microagentConversationId?: string;
+ microagentPRUrl?: string;
+ actions?: Array<{
+ icon: React.ReactNode;
+ onClick: () => void;
+ tooltip?: string;
+ }>;
+ isLastMessage: boolean;
+ isInLast10Actions: boolean;
+ config?: { APP_MODE?: string } | null;
+ isCheckingFeedback: boolean;
+ feedbackData: {
+ exists: boolean;
+ rating?: number;
+ reason?: string;
+ };
+}
+
+export function FinishEventMessage({
+ event,
+ microagentStatus,
+ microagentConversationId,
+ microagentPRUrl,
+ actions,
+ isLastMessage,
+ isInLast10Actions,
+ config,
+ isCheckingFeedback,
+ feedbackData,
+}: FinishEventMessageProps) {
+ if (!isFinishAction(event)) {
+ return null;
+ }
+
+ return (
+ <>
+ <ChatMessage
+ type="agent"
+ message={getEventContent(event).details}
+ actions={actions}
+ />
+ <MicroagentStatusWrapper
+ microagentStatus={microagentStatus}
+ microagentConversationId={microagentConversationId}
+ microagentPRUrl={microagentPRUrl}
+ actions={actions}
+ />
+ <LikertScaleWrapper
+ event={event}
+ isLastMessage={isLastMessage}
+ isInLast10Actions={isInLast10Actions}
+ config={config}
+ isCheckingFeedback={isCheckingFeedback}
+ feedbackData={feedbackData}
+ />
+ </>
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/generic-event-message-wrapper.tsx b/frontend/src/components/features/chat/event-message-components/generic-event-message-wrapper.tsx
new file mode 100644
index 0000000000..145f73090b
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/generic-event-message-wrapper.tsx
@@ -0,0 +1,45 @@
+import React from "react";
+import { OpenHandsAction } from "#/types/core/actions";
+import { OpenHandsObservation } from "#/types/core/observations";
+import { isOpenHandsAction, isOpenHandsObservation } from "#/types/core/guards";
+import { ChatMessage } from "../chat-message";
+import { GenericEventMessage } from "../generic-event-message";
+import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons";
+import { getEventContent } from "../event-content-helpers/get-event-content";
+import { getObservationResult } from "../event-content-helpers/get-observation-result";
+
+const hasThoughtProperty = (
+ obj: Record<string, unknown>,
+): obj is { thought: string } => "thought" in obj && !!obj.thought;
+
+interface GenericEventMessageWrapperProps {
+ event: OpenHandsAction | OpenHandsObservation;
+ shouldShowConfirmationButtons: boolean;
+}
+
+export function GenericEventMessageWrapper({
+ event,
+ shouldShowConfirmationButtons,
+}: GenericEventMessageWrapperProps) {
+ return (
+ <div>
+ {isOpenHandsAction(event) &&
+ hasThoughtProperty(event.args) &&
+ event.action !== "think" && (
+ <ChatMessage type="agent" message={event.args.thought} />
+ )}
+
+ <GenericEventMessage
+ title={getEventContent(event).title}
+ details={getEventContent(event).details}
+ success={
+ isOpenHandsObservation(event)
+ ? getObservationResult(event)
+ : undefined
+ }
+ />
+
+ {shouldShowConfirmationButtons && <ConfirmationButtons />}
+ </div>
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/index.ts b/frontend/src/components/features/chat/event-message-components/index.ts
new file mode 100644
index 0000000000..c2db5a5f5a
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/index.ts
@@ -0,0 +1,10 @@
+export { ErrorEventMessage } from "./error-event-message";
+export { UserAssistantEventMessage } from "./user-assistant-event-message";
+export { FinishEventMessage } from "./finish-event-message";
+export { RejectEventMessage } from "./reject-event-message";
+export { McpEventMessage } from "./mcp-event-message";
+export { TaskTrackingEventMessage } from "./task-tracking-event-message";
+export { ObservationPairEventMessage } from "./observation-pair-event-message";
+export { GenericEventMessageWrapper } from "./generic-event-message-wrapper";
+export { MicroagentStatusWrapper } from "./microagent-status-wrapper";
+export { LikertScaleWrapper } from "./likert-scale-wrapper";
diff --git a/frontend/src/components/features/chat/event-message-components/likert-scale-wrapper.tsx b/frontend/src/components/features/chat/event-message-components/likert-scale-wrapper.tsx
new file mode 100644
index 0000000000..4ea7a5b442
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/likert-scale-wrapper.tsx
@@ -0,0 +1,50 @@
+import React from "react";
+import { OpenHandsAction } from "#/types/core/actions";
+import { OpenHandsObservation } from "#/types/core/observations";
+import { isErrorObservation } from "#/types/core/guards";
+import { LikertScale } from "../../feedback/likert-scale";
+
+interface LikertScaleWrapperProps {
+ event: OpenHandsAction | OpenHandsObservation;
+ isLastMessage: boolean;
+ isInLast10Actions: boolean;
+ config?: { APP_MODE?: string } | null;
+ isCheckingFeedback: boolean;
+ feedbackData: {
+ exists: boolean;
+ rating?: number;
+ reason?: string;
+ };
+}
+
+export function LikertScaleWrapper({
+ event,
+ isLastMessage,
+ isInLast10Actions,
+ config,
+ isCheckingFeedback,
+ feedbackData,
+}: LikertScaleWrapperProps) {
+ if (config?.APP_MODE !== "saas" || isCheckingFeedback) {
+ return null;
+ }
+
+ // For error observations, show if in last 10 actions
+ // For other events, show only if it's the last message
+ const shouldShow = isErrorObservation(event)
+ ? isInLast10Actions
+ : isLastMessage;
+
+ if (!shouldShow) {
+ return null;
+ }
+
+ return (
+ <LikertScale
+ eventId={event.id}
+ initiallySubmitted={feedbackData.exists}
+ initialRating={feedbackData.rating}
+ initialReason={feedbackData.reason}
+ />
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/mcp-event-message.tsx b/frontend/src/components/features/chat/event-message-components/mcp-event-message.tsx
new file mode 100644
index 0000000000..0793ad17d0
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/mcp-event-message.tsx
@@ -0,0 +1,33 @@
+import React from "react";
+import { OpenHandsObservation } from "#/types/core/observations";
+import { isMcpObservation } from "#/types/core/guards";
+import { GenericEventMessage } from "../generic-event-message";
+import { MCPObservationContent } from "../mcp-observation-content";
+import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons";
+import { getEventContent } from "../event-content-helpers/get-event-content";
+import { getObservationResult } from "../event-content-helpers/get-observation-result";
+
+interface McpEventMessageProps {
+ event: OpenHandsObservation;
+ shouldShowConfirmationButtons: boolean;
+}
+
+export function McpEventMessage({
+ event,
+ shouldShowConfirmationButtons,
+}: McpEventMessageProps) {
+ if (!isMcpObservation(event)) {
+ return null;
+ }
+
+ return (
+ <div>
+ <GenericEventMessage
+ title={getEventContent(event).title}
+ details={<MCPObservationContent event={event} />}
+ success={getObservationResult(event)}
+ />
+ {shouldShowConfirmationButtons && <ConfirmationButtons />}
+ </div>
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/microagent-status-wrapper.tsx b/frontend/src/components/features/chat/event-message-components/microagent-status-wrapper.tsx
new file mode 100644
index 0000000000..b58f8f5db0
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/microagent-status-wrapper.tsx
@@ -0,0 +1,33 @@
+import React from "react";
+import { MicroagentStatus } from "#/types/microagent-status";
+import { MicroagentStatusIndicator } from "../microagent/microagent-status-indicator";
+
+interface MicroagentStatusWrapperProps {
+ microagentStatus?: MicroagentStatus | null;
+ microagentConversationId?: string;
+ microagentPRUrl?: string;
+ actions?: Array<{
+ icon: React.ReactNode;
+ onClick: () => void;
+ tooltip?: string;
+ }>;
+}
+
+export function MicroagentStatusWrapper({
+ microagentStatus,
+ microagentConversationId,
+ microagentPRUrl,
+ actions,
+}: MicroagentStatusWrapperProps) {
+ if (!microagentStatus || !actions) {
+ return null;
+ }
+
+ return (
+ <MicroagentStatusIndicator
+ status={microagentStatus}
+ conversationId={microagentConversationId}
+ prUrl={microagentPRUrl}
+ />
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/observation-pair-event-message.tsx b/frontend/src/components/features/chat/event-message-components/observation-pair-event-message.tsx
new file mode 100644
index 0000000000..0c0110b6a8
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/observation-pair-event-message.tsx
@@ -0,0 +1,61 @@
+import React from "react";
+import { OpenHandsAction } from "#/types/core/actions";
+import { isOpenHandsAction } from "#/types/core/guards";
+import { ChatMessage } from "../chat-message";
+import { MicroagentStatusWrapper } from "./microagent-status-wrapper";
+import { MicroagentStatus } from "#/types/microagent-status";
+
+const hasThoughtProperty = (
+ obj: Record<string, unknown>,
+): obj is { thought: string } => "thought" in obj && !!obj.thought;
+
+interface ObservationPairEventMessageProps {
+ event: OpenHandsAction;
+ microagentStatus?: MicroagentStatus | null;
+ microagentConversationId?: string;
+ microagentPRUrl?: string;
+ actions?: Array<{
+ icon: React.ReactNode;
+ onClick: () => void;
+ tooltip?: string;
+ }>;
+}
+
+export function ObservationPairEventMessage({
+ event,
+ microagentStatus,
+ microagentConversationId,
+ microagentPRUrl,
+ actions,
+}: ObservationPairEventMessageProps) {
+ if (!isOpenHandsAction(event)) {
+ return null;
+ }
+
+ if (hasThoughtProperty(event.args) && event.action !== "think") {
+ return (
+ <div>
+ <ChatMessage
+ type="agent"
+ message={event.args.thought}
+ actions={actions}
+ />
+ <MicroagentStatusWrapper
+ microagentStatus={microagentStatus}
+ microagentConversationId={microagentConversationId}
+ microagentPRUrl={microagentPRUrl}
+ actions={actions}
+ />
+ </div>
+ );
+ }
+
+ return (
+ <MicroagentStatusWrapper
+ microagentStatus={microagentStatus}
+ microagentConversationId={microagentConversationId}
+ microagentPRUrl={microagentPRUrl}
+ actions={actions}
+ />
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/reject-event-message.tsx b/frontend/src/components/features/chat/event-message-components/reject-event-message.tsx
new file mode 100644
index 0000000000..967a61ce1c
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/reject-event-message.tsx
@@ -0,0 +1,20 @@
+import React from "react";
+import { OpenHandsObservation } from "#/types/core/observations";
+import { isRejectObservation } from "#/types/core/guards";
+import { ChatMessage } from "../chat-message";
+
+interface RejectEventMessageProps {
+ event: OpenHandsObservation;
+}
+
+export function RejectEventMessage({ event }: RejectEventMessageProps) {
+ if (!isRejectObservation(event)) {
+ return null;
+ }
+
+ return (
+ <div>
+ <ChatMessage type="agent" message={event.content} />
+ </div>
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/task-tracking-event-message.tsx b/frontend/src/components/features/chat/event-message-components/task-tracking-event-message.tsx
new file mode 100644
index 0000000000..785305333c
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/task-tracking-event-message.tsx
@@ -0,0 +1,50 @@
+import React from "react";
+import { useTranslation } from "react-i18next";
+import { OpenHandsObservation } from "#/types/core/observations";
+import { isTaskTrackingObservation } from "#/types/core/guards";
+import { GenericEventMessage } from "../generic-event-message";
+import { TaskTrackingObservationContent } from "../task-tracking-observation-content";
+import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons";
+import { getObservationResult } from "../event-content-helpers/get-observation-result";
+
+interface TaskTrackingEventMessageProps {
+ event: OpenHandsObservation;
+ shouldShowConfirmationButtons: boolean;
+}
+
+export function TaskTrackingEventMessage({
+ event,
+ shouldShowConfirmationButtons,
+}: TaskTrackingEventMessageProps) {
+ const { t } = useTranslation();
+
+ if (!isTaskTrackingObservation(event)) {
+ return null;
+ }
+
+ const { command } = event.extras;
+ let title: React.ReactNode;
+ let initiallyExpanded = false;
+
+ // Determine title and expansion state based on command
+ if (command === "plan") {
+ title = t("OBSERVATION_MESSAGE$TASK_TRACKING_PLAN");
+ initiallyExpanded = true;
+ } else {
+ // command === "view"
+ title = t("OBSERVATION_MESSAGE$TASK_TRACKING_VIEW");
+ initiallyExpanded = false;
+ }
+
+ return (
+ <div>
+ <GenericEventMessage
+ title={title}
+ details={<TaskTrackingObservationContent event={event} />}
+ success={getObservationResult(event)}
+ initiallyExpanded={initiallyExpanded}
+ />
+ {shouldShowConfirmationButtons && <ConfirmationButtons />}
+ </div>
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message-components/user-assistant-event-message.tsx b/frontend/src/components/features/chat/event-message-components/user-assistant-event-message.tsx
new file mode 100644
index 0000000000..62b7fab57a
--- /dev/null
+++ b/frontend/src/components/features/chat/event-message-components/user-assistant-event-message.tsx
@@ -0,0 +1,83 @@
+import React from "react";
+import { OpenHandsAction } from "#/types/core/actions";
+import { isUserMessage, isAssistantMessage } from "#/types/core/guards";
+import { ChatMessage } from "../chat-message";
+import { ImageCarousel } from "../../images/image-carousel";
+import { FileList } from "../../files/file-list";
+import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons";
+import { MicroagentStatusWrapper } from "./microagent-status-wrapper";
+import { LikertScaleWrapper } from "./likert-scale-wrapper";
+import { parseMessageFromEvent } from "../event-content-helpers/parse-message-from-event";
+import { MicroagentStatus } from "#/types/microagent-status";
+
+interface UserAssistantEventMessageProps {
+ event: OpenHandsAction;
+ shouldShowConfirmationButtons: boolean;
+ microagentStatus?: MicroagentStatus | null;
+ microagentConversationId?: string;
+ microagentPRUrl?: string;
+ actions?: Array<{
+ icon: React.ReactNode;
+ onClick: () => void;
+ tooltip?: string;
+ }>;
+ isLastMessage: boolean;
+ isInLast10Actions: boolean;
+ config?: { APP_MODE?: string } | null;
+ isCheckingFeedback: boolean;
+ feedbackData: {
+ exists: boolean;
+ rating?: number;
+ reason?: string;
+ };
+}
+
+export function UserAssistantEventMessage({
+ event,
+ shouldShowConfirmationButtons,
+ microagentStatus,
+ microagentConversationId,
+ microagentPRUrl,
+ actions,
+ isLastMessage,
+ isInLast10Actions,
+ config,
+ isCheckingFeedback,
+ feedbackData,
+}: UserAssistantEventMessageProps) {
+ if (!isUserMessage(event) && !isAssistantMessage(event)) {
+ return null;
+ }
+
+ const message = parseMessageFromEvent(event);
+
+ return (
+ <>
+ <ChatMessage type={event.source} message={message} actions={actions}>
+ {event.args.image_urls && event.args.image_urls.length > 0 && (
+ <ImageCarousel size="small" images={event.args.image_urls} />
+ )}
+ {event.args.file_urls && event.args.file_urls.length > 0 && (
+ <FileList files={event.args.file_urls} />
+ )}
+ {shouldShowConfirmationButtons && <ConfirmationButtons />}
+ </ChatMessage>
+ <MicroagentStatusWrapper
+ microagentStatus={microagentStatus}
+ microagentConversationId={microagentConversationId}
+ microagentPRUrl={microagentPRUrl}
+ actions={actions}
+ />
+ {isAssistantMessage(event) && event.action === "message" && (
+ <LikertScaleWrapper
+ event={event}
+ isLastMessage={isLastMessage}
+ isInLast10Actions={isInLast10Actions}
+ config={config}
+ isCheckingFeedback={isCheckingFeedback}
+ feedbackData={feedbackData}
+ />
+ )}
+ </>
+ );
+}
diff --git a/frontend/src/components/features/chat/event-message.tsx b/frontend/src/components/features/chat/event-message.tsx
index 7bffbb5e83..db5121c24e 100644
--- a/frontend/src/components/features/chat/event-message.tsx
+++ b/frontend/src/components/features/chat/event-message.tsx
@@ -1,39 +1,29 @@
import React from "react";
-import { useTranslation } from "react-i18next";
-import { ConfirmationButtons } from "#/components/shared/buttons/confirmation-buttons";
import { OpenHandsAction } from "#/types/core/actions";
import {
isUserMessage,
isErrorObservation,
isAssistantMessage,
isOpenHandsAction,
- isOpenHandsObservation,
isFinishAction,
isRejectObservation,
isMcpObservation,
isTaskTrackingObservation,
} from "#/types/core/guards";
import { OpenHandsObservation } from "#/types/core/observations";
-import { ImageCarousel } from "../images/image-carousel";
-import { ChatMessage } from "./chat-message";
-import { ErrorMessage } from "./error-message";
-import { MCPObservationContent } from "./mcp-observation-content";
-import { TaskTrackingObservationContent } from "./task-tracking-observation-content";
-import { getObservationResult } from "./event-content-helpers/get-observation-result";
-import { getEventContent } from "./event-content-helpers/get-event-content";
-import { GenericEventMessage } from "./generic-event-message";
import { MicroagentStatus } from "#/types/microagent-status";
-import { MicroagentStatusIndicator } from "./microagent/microagent-status-indicator";
-import { FileList } from "../files/file-list";
-import { parseMessageFromEvent } from "./event-content-helpers/parse-message-from-event";
-import { LikertScale } from "../feedback/likert-scale";
-
import { useConfig } from "#/hooks/query/use-config";
import { useFeedbackExists } from "#/hooks/query/use-feedback-exists";
-
-const hasThoughtProperty = (
- obj: Record<string, unknown>,
-): obj is { thought: string } => "thought" in obj && !!obj.thought;
+import {
+ ErrorEventMessage,
+ UserAssistantEventMessage,
+ FinishEventMessage,
+ RejectEventMessage,
+ McpEventMessage,
+ TaskTrackingEventMessage,
+ ObservationPairEventMessage,
+ GenericEventMessageWrapper,
+} from "./event-message-components";
interface EventMessageProps {
event: OpenHandsAction | OpenHandsObservation;
@@ -51,6 +41,7 @@ interface EventMessageProps {
isInLast10Actions: boolean;
}
+/* eslint-disable react/jsx-props-no-spreading */
export function EventMessage({
event,
hasObservationPair,
@@ -62,7 +53,6 @@ export function EventMessage({
actions,
isInLast10Actions,
}: EventMessageProps) {
- const { t } = useTranslation();
const shouldShowConfirmationButtons =
isLastMessage && event.source === "agent" && isAwaitingUserConfirmation;
@@ -73,194 +63,83 @@ export function EventMessage({
isLoading: isCheckingFeedback,
} = useFeedbackExists(event.id);
- const renderLikertScale = () => {
- if (config?.APP_MODE !== "saas" || isCheckingFeedback) {
- return null;
- }
-
- // For error observations, show if in last 10 actions
- // For other events, show only if it's the last message
- const shouldShow = isErrorObservation(event)
- ? isInLast10Actions
- : isLastMessage;
-
- if (!shouldShow) {
- return null;
- }
-
- return (
- <LikertScale
- eventId={event.id}
- initiallySubmitted={feedbackData.exists}
- initialRating={feedbackData.rating}
- initialReason={feedbackData.reason}
- />
- );
+ // Common props for components that need them
+ const commonProps = {
+ microagentStatus,
+ microagentConversationId,
+ microagentPRUrl,
+ actions,
+ isLastMessage,
+ isInLast10Actions,
+ config,
+ isCheckingFeedback,
+ feedbackData,
};
+ // Error observations
if (isErrorObservation(event)) {
- return (
- <div>
- <ErrorMessage
- errorId={event.extras.error_id}
- defaultMessage={event.message}
- />
- {microagentStatus && actions && (
- <MicroagentStatusIndicator
- status={microagentStatus}
- conversationId={microagentConversationId}
- prUrl={microagentPRUrl}
- />
- )}
- {renderLikertScale()}
- </div>
- );
+ return <ErrorEventMessage event={event} {...commonProps} />;
}
+ // Observation pairs with OpenHands actions
if (hasObservationPair && isOpenHandsAction(event)) {
- if (hasThoughtProperty(event.args) && event.action !== "think") {
- return (
- <div>
- <ChatMessage
- type="agent"
- message={event.args.thought}
- actions={actions}
- />
- {microagentStatus && actions && (
- <MicroagentStatusIndicator
- status={microagentStatus}
- conversationId={microagentConversationId}
- prUrl={microagentPRUrl}
- />
- )}
- </div>
- );
- }
- return microagentStatus && actions ? (
- <MicroagentStatusIndicator
- status={microagentStatus}
- conversationId={microagentConversationId}
- prUrl={microagentPRUrl}
+ return (
+ <ObservationPairEventMessage
+ event={event}
+ microagentStatus={microagentStatus}
+ microagentConversationId={microagentConversationId}
+ microagentPRUrl={microagentPRUrl}
+ actions={actions}
/>
- ) : null;
+ );
}
+ // Finish actions
if (isFinishAction(event)) {
- return (
- <>
- <ChatMessage
- type="agent"
- message={getEventContent(event).details}
- actions={actions}
- />
- {microagentStatus && actions && (
- <MicroagentStatusIndicator
- status={microagentStatus}
- conversationId={microagentConversationId}
- prUrl={microagentPRUrl}
- />
- )}
- {renderLikertScale()}
- </>
- );
+ return <FinishEventMessage event={event} {...commonProps} />;
}
+ // User and assistant messages
if (isUserMessage(event) || isAssistantMessage(event)) {
- const message = parseMessageFromEvent(event);
-
return (
- <>
- <ChatMessage type={event.source} message={message} actions={actions}>
- {event.args.image_urls && event.args.image_urls.length > 0 && (
- <ImageCarousel size="small" images={event.args.image_urls} />
- )}
- {event.args.file_urls && event.args.file_urls.length > 0 && (
- <FileList files={event.args.file_urls} />
- )}
- {shouldShowConfirmationButtons && <ConfirmationButtons />}
- </ChatMessage>
- {microagentStatus && actions && (
- <MicroagentStatusIndicator
- status={microagentStatus}
- conversationId={microagentConversationId}
- prUrl={microagentPRUrl}
- />
- )}
- {isAssistantMessage(event) &&
- event.action === "message" &&
- renderLikertScale()}
- </>
+ <UserAssistantEventMessage
+ event={event}
+ shouldShowConfirmationButtons={shouldShowConfirmationButtons}
+ {...commonProps}
+ />
);
}
+ // Reject observations
if (isRejectObservation(event)) {
- return (
- <div>
- <ChatMessage type="agent" message={event.content} />
- </div>
- );
+ return <RejectEventMessage event={event} />;
}
+ // MCP observations
if (isMcpObservation(event)) {
return (
- <div>
- <GenericEventMessage
- title={getEventContent(event).title}
- details={<MCPObservationContent event={event} />}
- success={getObservationResult(event)}
- />
- {shouldShowConfirmationButtons && <ConfirmationButtons />}
- </div>
+ <McpEventMessage
+ event={event}
+ shouldShowConfirmationButtons={shouldShowConfirmationButtons}
+ />
);
}
+ // Task tracking observations
if (isTaskTrackingObservation(event)) {
- const { command } = event.extras;
- let title: React.ReactNode;
- let initiallyExpanded = false;
-
- // Determine title and expansion state based on command
- if (command === "plan") {
- title = t("OBSERVATION_MESSAGE$TASK_TRACKING_PLAN");
- initiallyExpanded = true;
- } else {
- // command === "view"
- title = t("OBSERVATION_MESSAGE$TASK_TRACKING_VIEW");
- initiallyExpanded = false;
- }
-
return (
- <div>
- <GenericEventMessage
- title={title}
- details={<TaskTrackingObservationContent event={event} />}
- success={getObservationResult(event)}
- initiallyExpanded={initiallyExpanded}
- />
- {shouldShowConfirmationButtons && <ConfirmationButtons />}
- </div>
+ <TaskTrackingEventMessage
+ event={event}
+ shouldShowConfirmationButtons={shouldShowConfirmationButtons}
+ />
);
}
+ // Generic fallback
return (
- <div>
- {isOpenHandsAction(event) &&
- hasThoughtProperty(event.args) &&
- event.action !== "think" && (
- <ChatMessage type="agent" message={event.args.thought} />
- )}
-
- <GenericEventMessage
- title={getEventContent(event).title}
- details={getEventContent(event).details}
- success={
- isOpenHandsObservation(event)
- ? getObservationResult(event)
- : undefined
- }
- />
-
- {shouldShowConfirmationButtons && <ConfirmationButtons />}
- </div>
+ <GenericEventMessageWrapper
+ event={event}
+ shouldShowConfirmationButtons={shouldShowConfirmationButtons}
+ />
);
}
diff --git a/frontend/src/components/features/chat/microagent/launch-microagent-modal.tsx b/frontend/src/components/features/chat/microagent/launch-microagent-modal.tsx
index b96379d7c2..4a09f6bf34 100644
--- a/frontend/src/components/features/chat/microagent/launch-microagent-modal.tsx
+++ b/frontend/src/components/features/chat/microagent/launch-microagent-modal.tsx
@@ -13,6 +13,7 @@ import { useHandleRuntimeActive } from "#/hooks/use-handle-runtime-active";
import { LoadingMicroagentBody } from "./loading-microagent-body";
import { LoadingMicroagentTextarea } from "./loading-microagent-textarea";
import { useGetMicroagents } from "#/hooks/query/use-get-microagents";
+import { Typography } from "#/ui/typography";
interface LaunchMicroagentModalProps {
onClose: () => void;
@@ -76,9 +77,9 @@ export function LaunchMicroagentModal({
</button>
</div>
- <span className="text-sm text-[#A3A3A3] font-normal leading-5">
+ <Typography.Text className="text-sm text-[#A3A3A3] font-normal leading-5">
{t("MICROAGENT$DEFINITION")}
- </span>
+ </Typography.Text>
<form
data-testid="launch-microagent-modal"
diff --git a/frontend/src/components/features/chat/microagent/loading-microagent-body.tsx b/frontend/src/components/features/chat/microagent/loading-microagent-body.tsx
index 5f960a9e93..f0fc25a67e 100644
--- a/frontend/src/components/features/chat/microagent/loading-microagent-body.tsx
+++ b/frontend/src/components/features/chat/microagent/loading-microagent-body.tsx
@@ -1,6 +1,7 @@
import { Spinner } from "@heroui/react";
import { useTranslation } from "react-i18next";
import { ModalBody } from "#/components/shared/modals/modal-body";
+import { Typography } from "#/ui/typography";
export function LoadingMicroagentBody() {
const { t } = useTranslation();
@@ -10,7 +11,7 @@ export function LoadingMicroagentBody() {
{t("MICROAGENT$ADD_TO_MICROAGENT")}
</h2>
<Spinner size="lg" />
- <p>{t("MICROAGENT$WAIT_FOR_RUNTIME")}</p>
+ <Typography.Text>{t("MICROAGENT$WAIT_FOR_RUNTIME")}</Typography.Text>
</ModalBody>
);
}
diff --git a/frontend/src/components/features/chat/microagent/microagent-status-indicator.tsx b/frontend/src/components/features/chat/microagent/microagent-status-indicator.tsx
index 8d81f468ed..bbcd1af052 100644
--- a/frontend/src/components/features/chat/microagent/microagent-status-indicator.tsx
+++ b/frontend/src/components/features/chat/microagent/microagent-status-indicator.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { Spinner } from "@heroui/react";
import { MicroagentStatus } from "#/types/microagent-status";
import { SuccessIndicator } from "../success-indicator";
+import { Typography } from "#/ui/typography";
interface MicroagentStatusIndicatorProps {
status: MicroagentStatus;
@@ -81,7 +82,9 @@ export function MicroagentStatusIndicator({
);
}
- return <span className="underline">{statusText}</span>;
+ return (
+ <Typography.Text className="underline">{statusText}</Typography.Text>
+ );
};
return (