From be737922306d3bad7544529bf066a0ff94e8b84c Mon Sep 17 00:00:00 2001 From: tofarr Date: Thu, 27 Feb 2025 09:02:31 -0700 Subject: [PATCH] Feat out of credits msg (#6969) Co-authored-by: openhands --- .../components/file-operations.test.tsx | 9 +++--- .../features/chat/expandable-message.tsx | 26 ++++++++++++++++ frontend/src/i18n/translation.json | 31 ++++++++++++++++++- openhands/controller/agent_controller.py | 2 ++ 4 files changed, 63 insertions(+), 5 deletions(-) diff --git a/frontend/__tests__/components/file-operations.test.tsx b/frontend/__tests__/components/file-operations.test.tsx index 2d2018df90..c0c3543933 100644 --- a/frontend/__tests__/components/file-operations.test.tsx +++ b/frontend/__tests__/components/file-operations.test.tsx @@ -2,6 +2,7 @@ import { render, screen } from "@testing-library/react"; import { describe, it, expect } from "vitest"; import { Messages } from "#/components/features/chat/messages"; import type { Message } from "#/message"; +import { renderWithProviders } from "test-utils"; describe("File Operations Messages", () => { it("should show success indicator for successful file read operation", () => { @@ -16,7 +17,7 @@ describe("File Operations Messages", () => { }, ]; - render(); + renderWithProviders(); const statusIcon = screen.getByTestId("status-icon"); expect(statusIcon).toBeInTheDocument(); @@ -35,7 +36,7 @@ describe("File Operations Messages", () => { }, ]; - render(); + renderWithProviders(); const statusIcon = screen.getByTestId("status-icon"); expect(statusIcon).toBeInTheDocument(); @@ -54,7 +55,7 @@ describe("File Operations Messages", () => { }, ]; - render(); + renderWithProviders(); const statusIcon = screen.getByTestId("status-icon"); expect(statusIcon).toBeInTheDocument(); @@ -73,7 +74,7 @@ describe("File Operations Messages", () => { }, ]; - render(); + renderWithProviders(); const statusIcon = screen.getByTestId("status-icon"); expect(statusIcon).toBeInTheDocument(); diff --git a/frontend/src/components/features/chat/expandable-message.tsx b/frontend/src/components/features/chat/expandable-message.tsx index 036ad9ce66..1fa8f636cf 100644 --- a/frontend/src/components/features/chat/expandable-message.tsx +++ b/frontend/src/components/features/chat/expandable-message.tsx @@ -2,6 +2,7 @@ import { useState, useEffect } from "react"; import { useTranslation } from "react-i18next"; import Markdown from "react-markdown"; import remarkGfm from "remark-gfm"; +import { Link } from "react-router"; import { code } from "../markdown/code"; import { ol, ul } from "../markdown/list"; import ArrowUp from "#/icons/angle-up-solid.svg?react"; @@ -9,6 +10,8 @@ import ArrowDown from "#/icons/angle-down-solid.svg?react"; import CheckCircle from "#/icons/check-circle-solid.svg?react"; import XCircle from "#/icons/x-circle-solid.svg?react"; import { cn } from "#/utils/utils"; +import { useConfig } from "#/hooks/query/use-config"; +import { BILLING_SETTINGS } from "#/utils/feature-flags"; interface ExpandableMessageProps { id?: string; @@ -23,6 +26,7 @@ export function ExpandableMessage({ type, success, }: ExpandableMessageProps) { + const { data: config } = useConfig(); const { t, i18n } = useTranslation(); const [showDetails, setShowDetails] = useState(true); const [headline, setHeadline] = useState(""); @@ -38,6 +42,28 @@ export function ExpandableMessage({ const statusIconClasses = "h-4 w-4 ml-2 inline"; + if ( + BILLING_SETTINGS() && + config?.APP_MODE === "saas" && + id === "STATUS$ERROR_LLM_OUT_OF_CREDITS" + ) { + return ( +
+
+
+ {t("STATUS$ERROR_LLM_OUT_OF_CREDITS")} +
+ + {t("BILLING$CLICK_TO_TOP_UP")} + +
+
+ ); + } + return (