Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(agent): Fix empty state condition + make storybook tests reliable (#15300)

Ben Bachemf7e76428b78c
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
index d41f537978..6b165741b3 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.stories.tsx
@@ -1117,15 +1117,11 @@ export const RateLimited = meta.story({
play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
const canvas = within(canvasElement);
const alert = canvas.getByRole("alert");
- const initialAlertText = alert.textContent;
await expect(alert).toHaveTextContent(
"You've reached the assistant request limit",
);
await expect(alert).toHaveTextContent("Try again in about");
- await waitFor(() => expect(alert.textContent).not.toBe(initialAlertText), {
- timeout: 2_000,
- });
await expect(
canvas.getByRole("textbox", { name: "Message the assistant" }),
).toBeDisabled();
@@ -1151,6 +1147,14 @@ export const RefocusAfterSubmit = meta.story({
const [isExpanded, setIsExpanded] = useState(args.isExpanded);
const [isInputDisabled, setIsInputDisabled] = useState(false);
const [messages, setMessages] = useState<InAppAgentWindowMessage[]>([
+ {
+ id: "user-1",
+ role: "user",
+ content: {
+ type: "text",
+ text: "Summarize the current trace.",
+ },
+ },
{
id: "assistant-1",
role: "assistant",
@@ -1202,14 +1206,18 @@ export const RefocusAfterSubmit = meta.story({
play: async ({ canvasElement }: { canvasElement: HTMLElement }) => {
const canvas = within(canvasElement);
const textarea = canvas.getByLabelText("Message the assistant");
+ const answer = "Answer for: Check the latest latency regression";
+ const previousAnswerCount = canvas.queryAllByText(answer).length;
+ await expect(
+ canvas.queryByText("Welcome to the Langfuse Assistant"),
+ ).not.toBeInTheDocument();
+ await userEvent.clear(textarea);
await userEvent.type(textarea, "Check the latest latency regression");
await userEvent.click(canvas.getByRole("button", { name: "Send message" }));
await waitFor(() => {
- expect(
- canvas.getByText("Answer for: Check the latest latency regression"),
- ).toBeInTheDocument();
+ expect(canvas.getAllByText(answer)).toHaveLength(previousAnswerCount + 1);
});
await waitFor(() => {
diff --git a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
index 2e0e7c7f32..d492af7555 100644
--- a/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
+++ b/web/src/ee/features/in-app-agent/components/InAppAgentWindow.tsx
@@ -702,7 +702,7 @@ export function InAppAgentWindow(props: InAppAgentWindowProps) {
isExpanded ? "px-0" : "px-3",
)}
>
- {!hasUserMessage ? (
+ {messages.length === 0 ? (
<div className="flex h-full w-full flex-1 flex-col items-center justify-center px-2">
<div>
<BotMessageSquare className="text-muted-foreground mx-auto h-7 w-7" />