Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat(frontend): add shine text effect to Plan Preview during streaming (planning agent) (#12676)

Hiep Lef5a9d289997b
diff --git a/frontend/__tests__/components/features/chat/plan-preview.test.tsx b/frontend/__tests__/components/features/chat/plan-preview.test.tsx
index d7e5134b0b..a8d3fb4a77 100644
--- a/frontend/__tests__/components/features/chat/plan-preview.test.tsx
+++ b/frontend/__tests__/components/features/chat/plan-preview.test.tsx
@@ -1,12 +1,32 @@
+import React from "react";
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
-import { screen, waitFor } from "@testing-library/react";
+import { screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { renderWithProviders } from "test-utils";
import { PlanPreview } from "#/components/features/chat/plan-preview";
+import { ScrollProvider } from "#/context/scroll-context";
import { useConversationStore } from "#/stores/conversation-store";
import { useOptimisticUserMessageStore } from "#/stores/optimistic-user-message-store";
import { createChatMessage } from "#/services/chat-service";
+// PlanPreview uses useScrollContext; wrap with ScrollProvider and a mock value.
+const mockScrollDomToBottom = vi.fn();
+const scrollContextValue = {
+ scrollRef: { current: null },
+ autoScroll: true,
+ setAutoScroll: vi.fn(),
+ scrollDomToBottom: mockScrollDomToBottom,
+ hitBottom: true,
+ setHitBottom: vi.fn(),
+ onChatBodyScroll: vi.fn(),
+};
+
+function renderPlanPreview(ui: React.ReactElement) {
+ return renderWithProviders(
+ <ScrollProvider value={scrollContextValue}>{ui}</ScrollProvider>,
+ );
+}
+
// Mock the feature flag to always return true (not testing feature flag behavior)
vi.mock("#/utils/feature-flags", () => ({
USE_PLANNING_AGENT: vi.fn(() => true),
@@ -72,7 +92,7 @@ describe("PlanPreview", () => {
});
it("should render nothing when planContent is null", () => {
- renderWithProviders(<PlanPreview planContent={null} />);
+ renderPlanPreview(<PlanPreview planContent={null} />);
const contentDiv = screen.getByTestId("plan-preview-content");
expect(contentDiv).toBeInTheDocument();
@@ -80,7 +100,7 @@ describe("PlanPreview", () => {
});
it("should render nothing when planContent is undefined", () => {
- renderWithProviders(<PlanPreview planContent={undefined} />);
+ renderPlanPreview(<PlanPreview planContent={undefined} />);
const contentDiv = screen.getByTestId("plan-preview-content");
expect(contentDiv).toBeInTheDocument();
@@ -90,7 +110,7 @@ describe("PlanPreview", () => {
it("should render markdown content when planContent is provided", () => {
const planContent = "# Plan Title\n\nThis is the plan content.";
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent={planContent} />,
);
@@ -103,7 +123,7 @@ describe("PlanPreview", () => {
it("should render full content when length is less than or equal to 300 characters", () => {
const planContent = "A".repeat(300);
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent={planContent} />,
);
@@ -115,7 +135,7 @@ describe("PlanPreview", () => {
it("should truncate content when length exceeds 300 characters", () => {
const longContent = "A".repeat(350);
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent={longContent} />,
);
@@ -126,7 +146,7 @@ describe("PlanPreview", () => {
});
it("should render Build button", () => {
- renderWithProviders(<PlanPreview planContent="Plan content" />);
+ renderPlanPreview(<PlanPreview planContent="Plan content" />);
const buildButton = screen.getByTestId("plan-preview-build-button");
expect(buildButton).toBeInTheDocument();
@@ -136,7 +156,7 @@ describe("PlanPreview", () => {
// Arrange
useConversationStore.setState({ conversationMode: "plan" });
const user = userEvent.setup();
- renderWithProviders(<PlanPreview planContent="Plan content" />);
+ renderPlanPreview(<PlanPreview planContent="Plan content" />);
const buildButton = screen.getByTestId("plan-preview-build-button");
// Act
@@ -151,7 +171,7 @@ describe("PlanPreview", () => {
const user = userEvent.setup();
const expectedPrompt =
"Execute the plan based on the workspace/project/PLAN.md file.";
- renderWithProviders(<PlanPreview planContent="Plan content" />);
+ renderPlanPreview(<PlanPreview planContent="Plan content" />);
const buildButton = screen.getByTestId("plan-preview-build-button");
// Act
@@ -182,7 +202,7 @@ describe("PlanPreview", () => {
const user = userEvent.setup();
const expectedPrompt =
"Execute the plan based on the workspace/project/PLAN.md file.";
- renderWithProviders(<PlanPreview planContent="Plan content" />);
+ renderPlanPreview(<PlanPreview planContent="Plan content" />);
const buildButton = screen.getByTestId("plan-preview-build-button");
// Act
@@ -196,7 +216,7 @@ describe("PlanPreview", () => {
it("should disable Build button when isBuildDisabled is true", () => {
// Arrange
- renderWithProviders(
+ renderPlanPreview(
<PlanPreview planContent="Plan content" isBuildDisabled={true} />,
);
@@ -209,7 +229,7 @@ describe("PlanPreview", () => {
it("should not disable Build button when isBuildDisabled is false", () => {
// Arrange
- renderWithProviders(
+ renderPlanPreview(
<PlanPreview planContent="Plan content" isBuildDisabled={false} />,
);
@@ -222,7 +242,7 @@ describe("PlanPreview", () => {
it("should not disable Build button when isBuildDisabled is undefined", () => {
// Arrange
- renderWithProviders(<PlanPreview planContent="Plan content" />);
+ renderPlanPreview(<PlanPreview planContent="Plan content" />);
// Act
const buildButton = screen.getByTestId("plan-preview-build-button");
@@ -236,7 +256,7 @@ describe("PlanPreview", () => {
const user = userEvent.setup();
const onBuildClick = vi.fn();
- renderWithProviders(
+ renderPlanPreview(
<PlanPreview planContent="Plan content" isBuildDisabled={true} />,
);
@@ -250,7 +270,7 @@ describe("PlanPreview", () => {
});
it("should render header with PLAN_MD text", () => {
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent="Plan content" />,
);
@@ -266,7 +286,7 @@ describe("PlanPreview", () => {
**Bold text** and *italic text*`;
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent={planContent} />,
);
@@ -279,7 +299,7 @@ describe("PlanPreview", () => {
const planContent = "# Main Title";
// Act
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent={planContent} />,
);
@@ -294,7 +314,7 @@ describe("PlanPreview", () => {
const planContent = "## Section Title";
// Act
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent={planContent} />,
);
@@ -309,7 +329,7 @@ describe("PlanPreview", () => {
const planContent = "### Subsection Title";
// Act
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent={planContent} />,
);
@@ -329,7 +349,7 @@ describe("PlanPreview", () => {
###### H6 Title`;
// Act
- const { container } = renderWithProviders(
+ const { container } = renderPlanPreview(
<PlanPreview planContent={planContent} />,
);
@@ -354,7 +374,7 @@ describe("PlanPreview", () => {
hasRightPanelToggled: false,
});
- renderWithProviders(<PlanPreview planContent={planContent} />);
+ renderPlanPreview(<PlanPreview planContent={planContent} />);
// Act: Click the View button
const viewButton = screen.getByTestId("plan-preview-view-button");
@@ -386,7 +406,7 @@ describe("PlanPreview", () => {
hasRightPanelToggled: false,
});
- renderWithProviders(<PlanPreview planContent={longContent} />);
+ renderPlanPreview(<PlanPreview planContent={longContent} />);
// Act: Click the Read more button
const readMoreButton = screen.getByTestId("plan-preview-read-more-button");
diff --git a/frontend/__tests__/components/features/markdown/plan-components.test.tsx b/frontend/__tests__/components/features/markdown/plan-components.test.tsx
new file mode 100644
index 0000000000..7cef6be19b
--- /dev/null
+++ b/frontend/__tests__/components/features/markdown/plan-components.test.tsx
@@ -0,0 +1,336 @@
+import { describe, it, expect } from "vitest";
+import { render, screen } from "@testing-library/react";
+import {
+ planComponents,
+ createPlanComponents,
+} from "#/components/features/markdown/plan-components";
+
+describe("planComponents", () => {
+ describe("h1", () => {
+ it("should render h1 with correct text content", () => {
+ // Arrange
+ const H1 = planComponents.h1;
+ const text = "Main Heading";
+
+ // Act
+ render(<H1>{text}</H1>);
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 1 });
+ expect(heading).toBeInTheDocument();
+ expect(heading).toHaveTextContent(text);
+ });
+
+ it("should handle undefined children gracefully", () => {
+ // Arrange
+ const H1 = planComponents.h1;
+
+ // Act
+ render(<H1>{undefined}</H1>);
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 1 });
+ expect(heading).toBeInTheDocument();
+ expect(heading).toBeEmptyDOMElement();
+ });
+
+ it("should render complex children content", () => {
+ // Arrange
+ const H1 = planComponents.h1;
+
+ // Act
+ render(
+ <H1>
+ <span>Nested</span> Content
+ </H1>,
+ );
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 1 });
+ expect(heading).toHaveTextContent("Nested Content");
+ expect(heading.querySelector("span")).toHaveTextContent("Nested");
+ });
+ });
+
+ describe("h2", () => {
+ it("should render h2 with correct text content", () => {
+ // Arrange
+ const H2 = planComponents.h2;
+ const text = "Section Heading";
+
+ // Act
+ render(<H2>{text}</H2>);
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 2 });
+ expect(heading).toBeInTheDocument();
+ expect(heading).toHaveTextContent(text);
+ });
+
+ it("should handle null children gracefully", () => {
+ // Arrange
+ const H2 = planComponents.h2;
+
+ // Act
+ render(<H2>{null}</H2>);
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 2 });
+ expect(heading).toBeInTheDocument();
+ expect(heading).toBeEmptyDOMElement();
+ });
+ });
+
+ describe("h3", () => {
+ it("should render h3 with correct text content", () => {
+ // Arrange
+ const H3 = planComponents.h3;
+ const text = "Subsection Heading";
+
+ // Act
+ render(<H3>{text}</H3>);
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 3 });
+ expect(heading).toBeInTheDocument();
+ expect(heading).toHaveTextContent(text);
+ });
+ });
+
+ describe("h4", () => {
+ it("should render h4 with correct text content", () => {
+ // Arrange
+ const H4 = planComponents.h4;
+ const text = "Level 4 Heading";
+
+ // Act
+ render(<H4>{text}</H4>);
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 4 });
+ expect(heading).toBeInTheDocument();
+ expect(heading).toHaveTextContent(text);
+ });
+ });
+
+ describe("h5", () => {
+ it("should render h5 with correct text content", () => {
+ // Arrange
+ const H5 = planComponents.h5;
+ const text = "Level 5 Heading";
+
+ // Act
+ render(<H5>{text}</H5>);
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 5 });
+ expect(heading).toBeInTheDocument();
+ expect(heading).toHaveTextContent(text);
+ });
+ });
+
+ describe("h6", () => {
+ it("should render h6 with correct text content", () => {
+ // Arrange
+ const H6 = planComponents.h6;
+ const text = "Level 6 Heading";
+
+ // Act
+ render(<H6>{text}</H6>);
+
+ // Assert
+ const heading = screen.getByRole("heading", { level: 6 });
+ expect(heading).toBeInTheDocument();
+ expect(heading).toHaveTextContent(text);
+ });
+ });
+
+ describe("heading hierarchy", () => {
+ it("should render all heading levels correctly in sequence", () => {
+ // Arrange
+ const H1 = planComponents.h1;
+ const H2 = planComponents.h2;
+ const H3 = planComponents.h3;
+ const H4 = planComponents.h4;
+ const H5 = planComponents.h5;
+ const H6 = planComponents.h6;
+
+ // Act
+ render(
+ <div>
+ <H1>Heading 1</H1>
+ <H2>Heading 2</H2>
+ <H3>Heading 3</H3>
+ <H4>Heading 4</H4>
+ <H5>Heading 5</H5>
+ <H6>Heading 6</H6>
+ </div>,
+ );
+
+ // Assert
+ expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
+ "Heading 1",
+ );
+ expect(screen.getByRole("heading", { level: 2 })).toHaveTextContent(
+ "Heading 2",
+ );
+ expect(screen.getByRole("heading", { level: 3 })).toHaveTextContent(
+ "Heading 3",
+ );
+ expect(screen.getByRole("heading", { level: 4 })).toHaveTextContent(
+ "Heading 4",
+ );
+ expect(screen.getByRole("heading", { level: 5 })).toHaveTextContent(
+ "Heading 5",
+ );
+ expect(screen.getByRole("heading", { level: 6 })).toHaveTextContent(
+ "Heading 6",
+ );
+ });
+ });
+
+ describe("p", () => {
+ it("should render paragraph with correct text content", () => {
+ // Arrange
+ const P = planComponents.p;
+ const text = "Paragraph text";
+
+ // Act
+ render(<P>{text}</P>);
+
+ // Assert
+ expect(screen.getByText(text)).toBeInTheDocument();
+ });
+ });
+
+ describe("ul", () => {
+ it("should render unordered list with correct content", () => {
+ // Arrange
+ const Ul = planComponents.ul;
+ const Li = planComponents.li;
+
+ // Act
+ render(
+ <Ul>
+ <Li>Item 1</Li>
+ <Li>Item 2</Li>
+ </Ul>,
+ );
+
+ // Assert
+ expect(screen.getByRole("list")).toBeInTheDocument();
+ expect(screen.getAllByRole("listitem")).toHaveLength(2);
+ });
+ });
+
+ describe("ol", () => {
+ it("should render ordered list with correct content", () => {
+ // Arrange
+ const Ol = planComponents.ol;
+ const Li = planComponents.li;
+
+ // Act
+ render(
+ <Ol>
+ <Li>Item 1</Li>
+ <Li>Item 2</Li>
+ </Ol>,
+ );
+
+ // Assert
+ expect(screen.getByRole("list")).toBeInTheDocument();
+ expect(screen.getAllByRole("listitem")).toHaveLength(2);
+ });
+
+ it("should support start attribute", () => {
+ // Arrange
+ const Ol = planComponents.ol;
+ const Li = planComponents.li;
+
+ // Act
+ const { container } = render(
+ <Ol start={5}>
+ <Li>Item 1</Li>
+ </Ol>,
+ );
+
+ // Assert
+ const ol = container.querySelector("ol");
+ expect(ol).toHaveAttribute("start", "5");
+ });
+ });
+
+ describe("a", () => {
+ it("should render anchor with correct href and content", () => {
+ // Arrange
+ const A = planComponents.a;
+ const href = "https://example.com";
+ const text = "Link text";
+
+ // Act
+ render(<A href={href}>{text}</A>);
+
+ // Assert
+ const link = screen.getByRole("link");
+ expect(link).toHaveTextContent(text);
+ expect(link).toHaveAttribute("href", href);
+ expect(link).toHaveAttribute("target", "_blank");
+ expect(link).toHaveAttribute("rel", "noopener noreferrer");
+ });
+ });
+
+ describe("code", () => {
+ it("should render inline code with correct content", () => {
+ // Arrange
+ const Code = planComponents.code;
+ const text = "const x = 1";
+
+ // Act
+ render(<Code>{text}</Code>);
+
+ // Assert
+ expect(screen.getByText(text)).toBeInTheDocument();
+ });
+ });
+});
+
+describe("createPlanComponents", () => {
+ it("should apply extraClassName to all elements when provided", () => {
+ // Arrange
+ const extraClassName = "test-extra-class";
+ const components = createPlanComponents(extraClassName);
+
+ // Act
+ const { container } = render(
+ <div>
+ <components.h1>H1</components.h1>
+ <components.p>Paragraph</components.p>
+ <components.ul>
+ <components.li>Item</components.li>
+ </components.ul>
+ <components.a href="#">Link</components.a>
+ <components.code>Code</components.code>
+ </div>,
+ );
+
+ // Assert
+ expect(container.querySelector("h1")).toHaveClass(extraClassName);
+ expect(container.querySelector("p")).toHaveClass(extraClassName);
+ expect(container.querySelector("ul")).toHaveClass(extraClassName);
+ expect(container.querySelector("li")).toHaveClass(extraClassName);
+ expect(container.querySelector("a")).toHaveClass(extraClassName);
+ expect(container.querySelector("code")).toHaveClass(extraClassName);
+ });
+
+ it("should not add undefined class when extraClassName is not provided", () => {
+ // Arrange
+ const components = createPlanComponents();
+
+ // Act
+ const { container } = render(<components.h1>H1</components.h1>);
+
+ // Assert
+ const h1 = container.querySelector("h1");
+ expect(h1?.className).not.toContain("undefined");
+ });
+});
diff --git a/frontend/__tests__/components/features/markdown/plan-headings.test.tsx b/frontend/__tests__/components/features/markdown/plan-headings.test.tsx
deleted file mode 100644
index c90f114aee..0000000000
--- a/frontend/__tests__/components/features/markdown/plan-headings.test.tsx
+++ /dev/null
@@ -1,188 +0,0 @@
-import { describe, it, expect } from "vitest";
-import { render, screen } from "@testing-library/react";
-import { planHeadings } from "#/components/features/markdown/plan-headings";
-
-describe("planHeadings", () => {
- describe("h1", () => {
- it("should render h1 with correct text content", () => {
- // Arrange
- const H1 = planHeadings.h1;
- const text = "Main Heading";
-
- // Act
- render(<H1>{text}</H1>);
-
- // Assert
- const heading = screen.getByRole("heading", { level: 1 });
- expect(heading).toBeInTheDocument();
- expect(heading).toHaveTextContent(text);
- });
-
- it("should handle undefined children gracefully", () => {
- // Arrange
- const H1 = planHeadings.h1;
-
- // Act
- render(<H1>{undefined}</H1>);
-
- // Assert
- const heading = screen.getByRole("heading", { level: 1 });
- expect(heading).toBeInTheDocument();
- expect(heading).toBeEmptyDOMElement();
- });
-
- it("should render complex children content", () => {
- // Arrange
- const H1 = planHeadings.h1;
-
- // Act
- render(
- <H1>
- <span>Nested</span> Content
- </H1>,
- );
-
- // Assert
- const heading = screen.getByRole("heading", { level: 1 });
- expect(heading).toHaveTextContent("Nested Content");
- expect(heading.querySelector("span")).toHaveTextContent("Nested");
- });
- });
-
- describe("h2", () => {
- it("should render h2 with correct text content", () => {
- // Arrange
- const H2 = planHeadings.h2;
- const text = "Section Heading";
-
- // Act
- render(<H2>{text}</H2>);
-
- // Assert
- const heading = screen.getByRole("heading", { level: 2 });
- expect(heading).toBeInTheDocument();
- expect(heading).toHaveTextContent(text);
- });
-
- it("should handle null children gracefully", () => {
- // Arrange
- const H2 = planHeadings.h2;
-
- // Act
- render(<H2>{null}</H2>);
-
- // Assert
- const heading = screen.getByRole("heading", { level: 2 });
- expect(heading).toBeInTheDocument();
- expect(heading).toBeEmptyDOMElement();
- });
- });
-
- describe("h3", () => {
- it("should render h3 with correct text content", () => {
- // Arrange
- const H3 = planHeadings.h3;
- const text = "Subsection Heading";
-
- // Act
- render(<H3>{text}</H3>);
-
- // Assert
- const heading = screen.getByRole("heading", { level: 3 });
- expect(heading).toBeInTheDocument();
- expect(heading).toHaveTextContent(text);
- });
- });
-
- describe("h4", () => {
- it("should render h4 with correct text content", () => {
- // Arrange
- const H4 = planHeadings.h4;
- const text = "Level 4 Heading";
-
- // Act
- render(<H4>{text}</H4>);
-
- // Assert
- const heading = screen.getByRole("heading", { level: 4 });
- expect(heading).toBeInTheDocument();
- expect(heading).toHaveTextContent(text);
- });
- });
-
- describe("h5", () => {
- it("should render h5 with correct text content", () => {
- // Arrange
- const H5 = planHeadings.h5;
- const text = "Level 5 Heading";
-
- // Act
- render(<H5>{text}</H5>);
-
- // Assert
- const heading = screen.getByRole("heading", { level: 5 });
- expect(heading).toBeInTheDocument();
- expect(heading).toHaveTextContent(text);
- });
- });
-
- describe("h6", () => {
- it("should render h6 with correct text content", () => {
- // Arrange
- const H6 = planHeadings.h6;
- const text = "Level 6 Heading";
-
- // Act
- render(<H6>{text}</H6>);
-
- // Assert
- const heading = screen.getByRole("heading", { level: 6 });
- expect(heading).toBeInTheDocument();
- expect(heading).toHaveTextContent(text);
- });
- });
-
- describe("heading hierarchy", () => {
- it("should render all heading levels correctly in sequence", () => {
- // Arrange
- const H1 = planHeadings.h1;
- const H2 = planHeadings.h2;
- const H3 = planHeadings.h3;
- const H4 = planHeadings.h4;
- const H5 = planHeadings.h5;
- const H6 = planHeadings.h6;
-
- // Act
- render(
- <div>
- <H1>Heading 1</H1>
- <H2>Heading 2</H2>
- <H3>Heading 3</H3>
- <H4>Heading 4</H4>
- <H5>Heading 5</H5>
- <H6>Heading 6</H6>
- </div>,
- );
-
- // Assert
- expect(screen.getByRole("heading", { level: 1 })).toHaveTextContent(
- "Heading 1",
- );
- expect(screen.getByRole("heading", { level: 2 })).toHaveTextContent(
- "Heading 2",
- );
- expect(screen.getByRole("heading", { level: 3 })).toHaveTextContent(
- "Heading 3",
- );
- expect(screen.getByRole("heading", { level: 4 })).toHaveTextContent(
- "Heading 4",
- );
- expect(screen.getByRole("heading", { level: 5 })).toHaveTextContent(
- "Heading 5",
- );
- expect(screen.getByRole("heading", { level: 6 })).toHaveTextContent(
- "Heading 6",
- );
- });
- });
-});
diff --git a/frontend/__tests__/components/v1/chat/event-message-plan-preview.test.tsx b/frontend/__tests__/components/v1/chat/event-message-plan-preview.test.tsx
index 8907a2177b..4f9af56ff4 100644
--- a/frontend/__tests__/components/v1/chat/event-message-plan-preview.test.tsx
+++ b/frontend/__tests__/components/v1/chat/event-message-plan-preview.test.tsx
@@ -1,7 +1,9 @@
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
-import { screen, render } from "@testing-library/react";
+import { screen } from "@testing-library/react";
import { EventMessage } from "#/components/v1/chat/event-message";
import { useConversationStore } from "#/stores/conversation-store";
+import { useAgentState } from "#/hooks/use-agent-state";
+import { AgentState } from "#/types/agent-state";
import {
renderWithProviders,
createPlanningObservationEvent,
@@ -19,6 +21,10 @@ vi.mock("#/hooks/query/use-config", () => ({
}),
}));
+// Mock useAgentState
+vi.mock("#/hooks/use-agent-state");
+
+// Mock PlanPreview component to verify it's rendered with correct props
// Mock useConversationId (EventMessage -> useAgentState -> useActiveConversation -> useConversationId)
vi.mock("#/hooks/use-conversation-id", () => ({
useConversationId: () => ({ conversationId: "test-conversation-id" }),
@@ -26,8 +32,16 @@ vi.mock("#/hooks/use-conversation-id", () => ({
// Mock PlanPreview component to verify it's rendered
vi.mock("#/components/features/chat/plan-preview", () => ({
- PlanPreview: ({ planContent }: { planContent?: string | null }) => (
- <div data-testid="plan-preview">Plan Preview: {planContent || "null"}</div>
+ PlanPreview: ({
+ planContent,
+ isStreaming,
+ }: {
+ planContent?: string | null;
+ isStreaming?: boolean;
+ }) => (
+ <div data-testid="plan-preview" data-is-streaming={isStreaming}>
+ Plan Preview: {planContent || "null"}
+ </div>
),
}));
@@ -38,6 +52,10 @@ describe("EventMessage - PlanPreview rendering", () => {
useConversationStore.setState({
planContent: null,
});
+ // Default mock for useAgentState
+ vi.mocked(useAgentState).mockReturnValue({
+ curAgentState: AgentState.INIT,
+ });
});
afterEach(() => {
@@ -161,4 +179,106 @@ describe("EventMessage - PlanPreview rendering", () => {
expect(screen.queryByTestId("plan-preview")).not.toBeInTheDocument();
expect(container.firstChild).toBeNull();
});
+
+ describe("isStreaming prop", () => {
+ it("should pass isStreaming=true when isLastMessage is true and agent state is RUNNING", () => {
+ const event = createPlanningObservationEvent("plan-obs-1");
+ const planPreviewEventIds = new Set(["plan-obs-1"]);
+ const planContent = "Streaming plan content";
+
+ useConversationStore.setState({ planContent });
+ vi.mocked(useAgentState).mockReturnValue({
+ curAgentState: AgentState.RUNNING,
+ });
+
+ renderWithProviders(
+ <EventMessage
+ event={event}
+ messages={[]}
+ isLastMessage={true}
+ isInLast10Actions={false}
+ planPreviewEventIds={planPreviewEventIds}
+ />,
+ );
+
+ const planPreview = screen.getByTestId("plan-preview");
+ expect(planPreview).toBeInTheDocument();
+ expect(planPreview).toHaveAttribute("data-is-streaming", "true");
+ });
+
+ it("should pass isStreaming=false when isLastMessage is false even if agent is RUNNING", () => {
+ const event = createPlanningObservationEvent("plan-obs-1");
+ const planPreviewEventIds = new Set(["plan-obs-1"]);
+ const planContent = "Plan content";
+
+ useConversationStore.setState({ planContent });
+ vi.mocked(useAgentState).mockReturnValue({
+ curAgentState: AgentState.RUNNING,
+ });
+
+ renderWithProviders(
+ <EventMessage
+ event={event}
+ messages={[]}
+ isLastMessage={false}
+ isInLast10Actions={false}
+ planPreviewEventIds={planPreviewEventIds}
+ />,
+ );
+
+ const planPreview = screen.getByTestId("plan-preview");
+ expect(planPreview).toBeInTheDocument();
+ expect(planPreview).toHaveAttribute("data-is-streaming", "false");
+ });
+
+ it("should pass isStreaming=false when agent state is not RUNNING even if isLastMessage is true", () => {
+ const event = createPlanningObservationEvent("plan-obs-1");
+ const planPreviewEventIds = new Set(["plan-obs-1"]);
+ const planContent = "Completed plan content";
+
+ useConversationStore.setState({ planContent });
+ vi.mocked(useAgentState).mockReturnValue({
+ curAgentState: AgentState.AWAITING_USER_INPUT,
+ });
+
+ renderWithProviders(
+ <EventMessage
+ event={event}
+ messages={[]}
+ isLastMessage={true}
+ isInLast10Actions={false}
+ planPreviewEventIds={planPreviewEventIds}
+ />,
+ );
+
+ const planPreview = screen.getByTestId("plan-preview");
+ expect(planPreview).toBeInTheDocument();
+ expect(planPreview).toHaveAttribute("data-is-streaming", "false");
+ });
+
+ it("should pass isStreaming=false when agent state is FINISHED", () => {
+ const event = createPlanningObservationEvent("plan-obs-1");
+ const planPreviewEventIds = new Set(["plan-obs-1"]);
+ const planContent = "Finished plan content";
+
+ useConversationStore.setState({ planContent });
+ vi.mocked(useAgentState).mockReturnValue({
+ curAgentState: AgentState.FINISHED,
+ });
+
+ renderWithProviders(
+ <EventMessage
+ event={event}
+ messages={[]}
+ isLastMessage={true}
+ isInLast10Actions={false}
+ planPreviewEventIds={planPreviewEventIds}
+ />,
+ );
+
+ const planPreview = screen.getByTestId("plan-preview");
+ expect(planPreview).toBeInTheDocument();
+ expect(planPreview).toHaveAttribute("data-is-streaming", "false");
+ });
+ });
});
diff --git a/frontend/src/components/features/chat/chat-interface.tsx b/frontend/src/components/features/chat/chat-interface.tsx
index d1a431e2ed..b239f845f8 100644
--- a/frontend/src/components/features/chat/chat-interface.tsx
+++ b/frontend/src/components/features/chat/chat-interface.tsx
@@ -18,6 +18,8 @@ import { ScrollProvider } from "#/context/scroll-context";
import { useInitialQueryStore } from "#/stores/initial-query-store";
import { useSendMessage } from "#/hooks/use-send-message";
import { useAgentState } from "#/hooks/use-agent-state";
+import { useHandleBuildPlanClick } from "#/hooks/use-handle-build-plan-click";
+import { USE_PLANNING_AGENT } from "#/utils/feature-flags";
import { ScrollToBottomButton } from "#/components/shared/buttons/scroll-to-bottom-button";
import { LoadingSpinner } from "#/components/shared/loading-spinner";
@@ -88,6 +90,43 @@ export function ChatInterface() {
const { data: config } = useConfig();
const { curAgentState } = useAgentState();
+ const { handleBuildPlanClick } = useHandleBuildPlanClick();
+ const shouldUsePlanningAgent = USE_PLANNING_AGENT();
+
+ // Disable Build button while agent is running (streaming)
+ const isAgentRunning =
+ curAgentState === AgentState.RUNNING ||
+ curAgentState === AgentState.LOADING;
+
+ // Global keyboard shortcut for Build button (Cmd+Enter / Ctrl+Enter)
+ // This is placed here instead of PlanPreview to avoid duplicate listeners
+ // when multiple PlanPreview components exist in the chat
+ React.useEffect(() => {
+ if (!shouldUsePlanningAgent || isAgentRunning) {
+ return undefined;
+ }
+
+ const handleKeyDown = (event: KeyboardEvent) => {
+ // Check for Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux)
+ if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
+ event.preventDefault();
+ event.stopPropagation();
+ handleBuildPlanClick(event);
+ scrollDomToBottom();
+ }
+ };
+
+ document.addEventListener("keydown", handleKeyDown);
+
+ return () => {
+ document.removeEventListener("keydown", handleKeyDown);
+ };
+ }, [
+ shouldUsePlanningAgent,
+ isAgentRunning,
+ handleBuildPlanClick,
+ scrollDomToBottom,
+ ]);
const [feedbackPolarity, setFeedbackPolarity] = React.useState<
"positive" | "negative"
diff --git a/frontend/src/components/features/chat/chat-message.tsx b/frontend/src/components/features/chat/chat-message.tsx
index 7a99af60b5..ad483d0d6e 100644
--- a/frontend/src/components/features/chat/chat-message.tsx
+++ b/frontend/src/components/features/chat/chat-message.tsx
@@ -55,7 +55,7 @@ export function ChatMessage({
"flex flex-col gap-2",
type === "user" && "p-4 bg-tertiary self-end",
type === "agent" && "mt-6 w-full max-w-full bg-transparent",
- isFromPlanningAgent && "border border-[#597ff4] bg-tertiary p-4",
+ isFromPlanningAgent && "border border-[#597ff4] bg-tertiary p-4 mt-2",
)}
>
<div
diff --git a/frontend/src/components/features/chat/plan-preview.tsx b/frontend/src/components/features/chat/plan-preview.tsx
index 9788985021..a1a1cb44dd 100644
--- a/frontend/src/components/features/chat/plan-preview.tsx
+++ b/frontend/src/components/features/chat/plan-preview.tsx
@@ -1,4 +1,4 @@
-import { useMemo } from "react";
+import { useMemo, useCallback } from "react";
import { useTranslation } from "react-i18next";
import { ArrowUpRight } from "lucide-react";
import LessonPlanIcon from "#/icons/lesson-plan.svg?react";
@@ -9,13 +9,25 @@ import { MarkdownRenderer } from "#/components/features/markdown/markdown-render
import { useHandleBuildPlanClick } from "#/hooks/use-handle-build-plan-click";
import { cn } from "#/utils/utils";
import { useSelectConversationTab } from "#/hooks/use-select-conversation-tab";
-import { planHeadings } from "#/components/features/markdown/plan-headings";
+import {
+ planComponents,
+ createPlanComponents,
+} from "#/components/features/markdown/plan-components";
+import { useScrollContext } from "#/context/scroll-context";
const MAX_CONTENT_LENGTH = 300;
+// Shine effect class for streaming text
+const SHINE_TEXT_CLASS = "shine-text";
+
+// Plan components with shine effect applied for streaming state
+const shineComponents = createPlanComponents(SHINE_TEXT_CLASS);
+
interface PlanPreviewProps {
/** Raw plan content from PLAN.md file */
planContent?: string | null;
+ /** Whether the plan content is actively being streamed */
+ isStreaming?: boolean;
/** Whether the Build button should be disabled (e.g., while streaming) */
isBuildDisabled?: boolean;
}
@@ -23,11 +35,13 @@ interface PlanPreviewProps {
/* eslint-disable i18next/no-literal-string */
export function PlanPreview({
planContent,
+ isStreaming,
isBuildDisabled,
}: PlanPreviewProps) {
const { t } = useTranslation();
const { selectTab } = useSelectConversationTab();
const { handleBuildPlanClick } = useHandleBuildPlanClick();
+ const { scrollDomToBottom } = useScrollContext();
const shouldUsePlanningAgent = USE_PLANNING_AGENT();
@@ -35,6 +49,15 @@ export function PlanPreview({
selectTab("planner");
};
+ // Handle Build action with scroll to bottom
+ const handleBuildClick = useCallback(
+ (event?: React.MouseEvent<HTMLButtonElement>) => {
+ handleBuildPlanClick(event);
+ scrollDomToBottom();
+ },
+ [handleBuildPlanClick, scrollDomToBottom],
+ );
+
// Truncate plan content for preview
const truncatedContent = useMemo(() => {
if (!planContent) return "";
@@ -47,7 +70,7 @@ export function PlanPreview({
}
return (
- <div className="bg-[#25272d] border border-[#597FF4] rounded-[12px] w-full mb-4 mt-2">
+ <div className="bg-[#25272d] border border-[#597FF4] rounded-[12px] w-full mt-2">
{/* Header */}
<div className="border-b border-[#525252] flex h-[41px] items-center px-2 gap-1">
<LessonPlanIcon width={18} height={18} color="#9299aa" />
@@ -75,7 +98,10 @@ export function PlanPreview({
>
{truncatedContent && (
<>
- <MarkdownRenderer includeStandard components={planHeadings}>
+ <MarkdownRenderer
+ includeStandard
+ components={isStreaming ? shineComponents : planComponents}
+ >
{truncatedContent}
</MarkdownRenderer>
{planContent && planContent.length > MAX_CONTENT_LENGTH && (
@@ -96,7 +122,7 @@ export function PlanPreview({
<div className="border-t border-[#525252] flex h-[54px] items-center justify-start px-4">
<button
type="button"
- onClick={handleBuildPlanClick}
+ onClick={handleBuildClick}
disabled={isBuildDisabled}
className={cn(
"bg-white flex items-center justify-center h-[26px] px-2 rounded-[4px] w-[93px] transition-opacity",
diff --git a/frontend/src/components/features/markdown/plan-components.tsx b/frontend/src/components/features/markdown/plan-components.tsx
new file mode 100644
index 0000000000..7522d9c378
--- /dev/null
+++ b/frontend/src/components/features/markdown/plan-components.tsx
@@ -0,0 +1,156 @@
+import React from "react";
+import { cn } from "#/utils/utils";
+
+interface ElementProps {
+ children?: React.ReactNode;
+ className?: string;
+}
+
+interface ListProps extends ElementProps {
+ start?: number;
+}
+
+interface AnchorProps extends ElementProps {
+ href?: string;
+}
+
+/**
+ * Creates custom markdown components for plan views with reduced font sizes and tighter spacing.
+ * Accepts an optional extraClassName that will be applied to all elements.
+ */
+export function createPlanComponents(extraClassName?: string) {
+ return {
+ h1: ({ children, className }: ElementProps) => (
+ <h1
+ className={cn(
+ "text-lg text-white font-bold leading-6 mb-1.5 mt-3 first:mt-0",
+ className,
+ extraClassName,
+ )}
+ >
+ {children}
+ </h1>
+ ),
+ h2: ({ children, className }: ElementProps) => (
+ <h2
+ className={cn(
+ "text-base font-semibold leading-5 text-white mb-1 mt-2.5 first:mt-0",
+ className,
+ extraClassName,
+ )}
+ >
+ {children}
+ </h2>
+ ),
+ h3: ({ children, className }: ElementProps) => (
+ <h3
+ className={cn(
+ "text-sm font-semibold text-white mb-1 mt-2 first:mt-0",
+ className,
+ extraClassName,
+ )}
+ >
+ {children}
+ </h3>
+ ),
+ h4: ({ children, className }: ElementProps) => (
+ <h4
+ className={cn(
+ "text-sm font-semibold text-white mb-1 mt-2 first:mt-0",
+ className,
+ extraClassName,
+ )}
+ >
+ {children}
+ </h4>
+ ),
+ h5: ({ children, className }: ElementProps) => (
+ <h5
+ className={cn(
+ "text-xs font-semibold text-white mb-0.5 mt-1.5 first:mt-0",
+ className,
+ extraClassName,
+ )}
+ >
+ {children}
+ </h5>
+ ),
+ h6: ({ children, className }: ElementProps) => (
+ <h6
+ className={cn(
+ "text-xs font-medium text-gray-300 mb-0.5 mt-1.5 first:mt-0",
+ className,
+ extraClassName,
+ )}
+ >
+ {children}
+ </h6>
+ ),
+ p: ({ children, className }: ElementProps) => (
+ <p
+ className={cn("py-2.5 first:pt-0 last:pb-0", className, extraClassName)}
+ >
+ {children}
+ </p>
+ ),
+ ul: ({ children, className }: ElementProps) => (
+ <ul
+ className={cn(
+ "list-disc ml-5 pl-2 whitespace-normal",
+ className,
+ extraClassName,
+ )}
+ >
+ {children}
+ </ul>
+ ),
+ ol: ({ children, className, start }: ListProps) => (
+ <ol
+ className={cn(
+ "list-decimal ml-5 pl-2 whitespace-normal",
+ className,
+ extraClassName,
+ )}
+ start={start}
+ >
+ {children}
+ </ol>
+ ),
+ li: ({ children, className }: ElementProps) => (
+ <li className={cn(className, extraClassName)}>{children}</li>
+ ),
+ a: ({ children, className, href }: AnchorProps) => (
+ <a
+ className={cn(
+ "text-blue-500 hover:underline",
+ className,
+ extraClassName,
+ )}
+ href={href}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
+ {children}
+ </a>
+ ),
+ code: ({ children, className }: ElementProps) => (
+ <code
+ className={cn(
+ "bg-[#2a3038] px-1.5 py-0.5 rounded text-[#e6edf3] border border-[#30363d]",
+ className,
+ extraClassName,
+ )}
+ >
+ {children}
+ </code>
+ ),
+ };
+}
+
+// Default plan components without extra className (for backward compatibility)
+export const planComponents = createPlanComponents();
+
+/**
+ * @deprecated Use planComponents instead
+ */
+export const planHeadings = planComponents;
diff --git a/frontend/src/components/features/markdown/plan-headings.tsx b/frontend/src/components/features/markdown/plan-headings.tsx
deleted file mode 100644
index 63dc77b6de..0000000000
--- a/frontend/src/components/features/markdown/plan-headings.tsx
+++ /dev/null
@@ -1,35 +0,0 @@
-import React from "react";
-
-// Custom heading components for plan views with reduced font sizes and tighter spacing
-export const planHeadings = {
- h1: ({ children }: { children?: React.ReactNode }) => (
- <h1 className="text-lg text-white font-bold leading-6 mb-1.5 mt-3 first:mt-0">
- {children}
- </h1>
- ),
- h2: ({ children }: { children?: React.ReactNode }) => (
- <h2 className="text-base font-semibold leading-5 text-white mb-1 mt-2.5 first:mt-0">
- {children}
- </h2>
- ),
- h3: ({ children }: { children?: React.ReactNode }) => (
- <h3 className="text-sm font-semibold text-white mb-1 mt-2 first:mt-0">
- {children}
- </h3>
- ),
- h4: ({ children }: { children?: React.ReactNode }) => (
- <h4 className="text-sm font-semibold text-white mb-1 mt-2 first:mt-0">
- {children}
- </h4>
- ),
- h5: ({ children }: { children?: React.ReactNode }) => (
- <h5 className="text-xs font-semibold text-white mb-0.5 mt-1.5 first:mt-0">
- {children}
- </h5>
- ),
- h6: ({ children }: { children?: React.ReactNode }) => (
- <h6 className="text-xs font-medium text-gray-300 mb-0.5 mt-1.5 first:mt-0">
- {children}
- </h6>
- ),
-};
diff --git a/frontend/src/components/v1/chat/event-message-components/finish-event-message.tsx b/frontend/src/components/v1/chat/event-message-components/finish-event-message.tsx
index 3a30b0c434..146c031dfb 100644
--- a/frontend/src/components/v1/chat/event-message-components/finish-event-message.tsx
+++ b/frontend/src/components/v1/chat/event-message-components/finish-event-message.tsx
@@ -18,6 +18,7 @@ interface FinishEventMessageProps {
onClick: () => void;
tooltip?: string;
}>;
+ isFromPlanningAgent?: boolean;
}
export function FinishEventMessage({
@@ -26,6 +27,7 @@ export function FinishEventMessage({
microagentConversationId,
microagentPRUrl,
actions,
+ isFromPlanningAgent = false,
}: FinishEventMessageProps) {
const eventContent = getEventContent(event);
// For FinishAction, details is always a string (getActionContent returns string)
@@ -36,7 +38,12 @@ export function FinishEventMessage({
return (
<>
- <ChatMessage type="agent" message={message} actions={actions} />
+ <ChatMessage
+ type="agent"
+ message={message}
+ actions={actions}
+ isFromPlanningAgent={isFromPlanningAgent}
+ />
<MicroagentStatusWrapper
microagentStatus={microagentStatus}
microagentConversationId={microagentConversationId}
diff --git a/frontend/src/components/v1/chat/event-message-components/generic-event-message-wrapper.tsx b/frontend/src/components/v1/chat/event-message-components/generic-event-message-wrapper.tsx
index 95c2652549..7c2f45e365 100644
--- a/frontend/src/components/v1/chat/event-message-components/generic-event-message-wrapper.tsx
+++ b/frontend/src/components/v1/chat/event-message-components/generic-event-message-wrapper.tsx
@@ -1,5 +1,6 @@
import { OpenHandsEvent } from "#/types/v1/core";
import { GenericEventMessage } from "../../../features/chat/generic-event-message";
+import { ChatMessage } from "../../../features/chat/chat-message";
import { getEventContent } from "../event-content-helpers/get-event-content";
import { getObservationResult } from "../event-content-helpers/get-observation-result";
import { isObservationEvent } from "#/types/v1/type-guards";
@@ -9,16 +10,17 @@ import {
} from "../event-content-helpers/create-skill-ready-event";
import { V1ConfirmationButtons } from "#/components/shared/buttons/v1-confirmation-buttons";
import { ObservationResultStatus } from "../../../features/chat/event-content-helpers/get-observation-result";
-import { MarkdownRenderer } from "#/components/features/markdown/markdown-renderer";
interface GenericEventMessageWrapperProps {
event: OpenHandsEvent | SkillReadyEvent;
isLastMessage: boolean;
+ isFromPlanningAgent?: boolean;
}
export function GenericEventMessageWrapper({
event,
isLastMessage,
+ isFromPlanningAgent = false,
}: GenericEventMessageWrapperProps) {
const { title, details } = getEventContent(event);
@@ -29,10 +31,14 @@ export function GenericEventMessageWrapper({
return <div>{details}</div>;
}
if (event.observation.kind === "FinishObservation") {
+ const message = typeof details === "string" ? details : String(details);
+ // Use ChatMessage for proper styling (blue border for planning agent, text-sm)
return (
- <MarkdownRenderer includeStandard includeHeadings>
- {details as string}
- </MarkdownRenderer>
+ <ChatMessage
+ type="agent"
+ message={message}
+ isFromPlanningAgent={isFromPlanningAgent}
+ />
);
}
}
diff --git a/frontend/src/components/v1/chat/event-message-components/thought-event-message.tsx b/frontend/src/components/v1/chat/event-message-components/thought-event-message.tsx
index 9d6dfdcea1..24f4a55c67 100644
--- a/frontend/src/components/v1/chat/event-message-components/thought-event-message.tsx
+++ b/frontend/src/components/v1/chat/event-message-components/thought-event-message.tsx
@@ -9,11 +9,13 @@ interface ThoughtEventMessageProps {
onClick: () => void;
tooltip?: string;
}>;
+ isFromPlanningAgent?: boolean;
}
export function ThoughtEventMessage({
event,
actions,
+ isFromPlanningAgent = false,
}: ThoughtEventMessageProps) {
// Extract thought content from the action event
const thoughtContent = event.thought
@@ -27,6 +29,11 @@ export function ThoughtEventMessage({
}
return (
- <ChatMessage type="agent" message={thoughtContent} actions={actions} />
+ <ChatMessage
+ type="agent"
+ message={thoughtContent}
+ actions={actions}
+ isFromPlanningAgent={isFromPlanningAgent}
+ />
);
}
diff --git a/frontend/src/components/v1/chat/event-message.tsx b/frontend/src/components/v1/chat/event-message.tsx
index d6c67a79f0..01383e0271 100644
--- a/frontend/src/components/v1/chat/event-message.tsx
+++ b/frontend/src/components/v1/chat/event-message.tsx
@@ -121,6 +121,7 @@ const renderUserMessageWithSkillReady = (
<GenericEventMessageWrapper
event={skillReadyEvent}
isLastMessage={isLastMessage}
+ isFromPlanningAgent={commonProps.isFromPlanningAgent}
/>
</>
);
@@ -203,10 +204,15 @@ export function EventMessage({
if (isActionEvent(event)) {
return (
<>
- <ThoughtEventMessage event={event} actions={actions} />
+ <ThoughtEventMessage
+ event={event}
+ actions={actions}
+ isFromPlanningAgent={isFromPlanningAgent}
+ />
<GenericEventMessageWrapper
event={event}
isLastMessage={isLastMessage}
+ isFromPlanningAgent={isFromPlanningAgent}
/>
</>
);
@@ -222,9 +228,13 @@ export function EventMessage({
planPreviewEventIds &&
shouldShowPlanPreview(event.id, planPreviewEventIds)
) {
+ // Show shine effect only if this is the last message AND agent is running
+ const isStreaming =
+ isLastMessage && curAgentState === AgentState.RUNNING;
return (
<PlanPreview
planContent={planContent}
+ isStreaming={isStreaming}
isBuildDisabled={isAgentRunning}
/>
);
@@ -242,11 +252,16 @@ export function EventMessage({
return (
<>
{correspondingAction && isActionEvent(correspondingAction) && (
- <ThoughtEventMessage event={correspondingAction} actions={actions} />
+ <ThoughtEventMessage
+ event={correspondingAction}
+ actions={actions}
+ isFromPlanningAgent={isFromPlanningAgent}
+ />
)}
<GenericEventMessageWrapper
event={event}
isLastMessage={isLastMessage}
+ isFromPlanningAgent={isFromPlanningAgent}
/>
</>
);
@@ -277,6 +292,10 @@ export function EventMessage({
// Generic fallback for all other events
return (
- <GenericEventMessageWrapper event={event} isLastMessage={isLastMessage} />
+ <GenericEventMessageWrapper
+ event={event}
+ isLastMessage={isLastMessage}
+ isFromPlanningAgent={isFromPlanningAgent}
+ />
);
}
diff --git a/frontend/src/routes/planner-tab.tsx b/frontend/src/routes/planner-tab.tsx
index 92f40a5bad..dfda9b9a8f 100644
--- a/frontend/src/routes/planner-tab.tsx
+++ b/frontend/src/routes/planner-tab.tsx
@@ -5,7 +5,7 @@ import LessonPlanIcon from "#/icons/lesson-plan.svg?react";
import { useConversationStore } from "#/stores/conversation-store";
import { useScrollToBottom } from "#/hooks/use-scroll-to-bottom";
import { MarkdownRenderer } from "#/components/features/markdown/markdown-renderer";
-import { planHeadings } from "#/components/features/markdown/plan-headings";
+import { planComponents } from "#/components/features/markdown/plan-components";
import { useHandlePlanClick } from "#/hooks/use-handle-plan-click";
function PlannerTab() {
@@ -24,7 +24,7 @@ function PlannerTab() {
onScroll={(e) => onChatBodyScroll(e.currentTarget)}
className="flex flex-col w-full h-full p-4 overflow-auto"
>
- <MarkdownRenderer includeStandard components={planHeadings}>
+ <MarkdownRenderer includeStandard components={planComponents}>
{planContent}
</MarkdownRenderer>
</div>
diff --git a/frontend/src/stores/use-event-store.ts b/frontend/src/stores/use-event-store.ts
index 9e00546634..2dfc66e37e 100644
--- a/frontend/src/stores/use-event-store.ts
+++ b/frontend/src/stores/use-event-store.ts
@@ -12,6 +12,44 @@ export type OHEvent = (OpenHandsEvent | OpenHandsParsedEvent) & {
const getEventId = (event: OHEvent): string | number | undefined =>
"id" in event ? event.id : undefined;
+const getEventTimestamp = (event: OHEvent): string | undefined =>
+ "timestamp" in event ? event.timestamp : undefined;
+
+/**
+ * Compare two events by timestamp for sorting.
+ * Events without timestamps are placed at the end.
+ */
+const compareEventsByTimestamp = (a: OHEvent, b: OHEvent): number => {
+ const timestampA = getEventTimestamp(a);
+ const timestampB = getEventTimestamp(b);
+
+ // Events without timestamps go to the end
+ if (!timestampA && !timestampB) return 0;
+ if (!timestampA) return 1;
+ if (!timestampB) return -1;
+
+ // Compare ISO timestamp strings (lexicographic comparison works for ISO format)
+ return timestampA.localeCompare(timestampB);
+};
+
+/**
+ * Check if the new event needs sorting (i.e., it's out of order).
+ * Returns true if the new event's timestamp is earlier than the last event's timestamp.
+ */
+const needsSorting = (events: OHEvent[], newEvent: OHEvent): boolean => {
+ if (events.length === 0) return false;
+
+ const lastEvent = events[events.length - 1];
+ const lastTimestamp = getEventTimestamp(lastEvent);
+ const newTimestamp = getEventTimestamp(newEvent);
+
+ // If either event doesn't have a timestamp, don't sort
+ if (!lastTimestamp || !newTimestamp) return false;
+
+ // Sort needed if new event's timestamp is earlier than last event's timestamp
+ return newTimestamp < lastTimestamp;
+};
+
export interface EventState {
events: OHEvent[];
eventIds: Set<string | number>;
@@ -32,16 +70,27 @@ export const useEventStore = create<EventState>()((set) => ({
return state;
}
- const newEvents = [...state.events, event];
+ // Add event and sort if needed to maintain chronological order
+ let newEvents = [...state.events, event];
+ if (needsSorting(state.events, event)) {
+ newEvents = newEvents.sort(compareEventsByTimestamp);
+ }
+
const newEventIds =
eventId !== undefined
? new Set(state.eventIds).add(eventId)
: state.eventIds;
- const newUiEvents = isV1Event(event)
+
+ // Process UI events and sort if needed
+ let newUiEvents = isV1Event(event)
? // @ts-expect-error - temporary, needs proper typing
handleEventForUI(event, state.uiEvents)
: [...state.uiEvents, event];
+ if (needsSorting(state.uiEvents, event)) {
+ newUiEvents = newUiEvents.sort(compareEventsByTimestamp);
+ }
+
return {
events: newEvents,
eventIds: newEventIds,
diff --git a/frontend/src/tailwind.css b/frontend/src/tailwind.css
index 1673288564..e5edcece15 100644
--- a/frontend/src/tailwind.css
+++ b/frontend/src/tailwind.css
@@ -350,3 +350,21 @@
.api-configuration-modal {
box-shadow: 0 183px 51px 0 rgba(0, 0, 0, 0.00), 0 117px 47px 0 rgba(0, 0, 0, 0.01), 0 66px 40px 0 rgba(0, 0, 0, 0.03), 0 29px 29px 0 rgba(0, 0, 0, 0.04), 0 7px 16px 0 rgba(0, 0, 0, 0.05);
}
+
+/* Shine text effect for streaming content */
+@keyframes shine {
+ 0% {
+ background-position: 200% 0%;
+ }
+ 100% {
+ background-position: -200% 0%;
+ }
+}
+
+.shine-text {
+ color: transparent;
+ -webkit-background-clip: text !important;
+ background-clip: text !important;
+ animation: shine 2s linear infinite;
+ background: radial-gradient(circle at center, rgb(24 24 27 / 85%), transparent) -200% 50% / 200% 100% no-repeat, #f4f4f5;
+}