Bladeren bron

Fix issue #5676: [Bug]: Frontend Hyperlink in Chat window should open link in a new tab (#5677)

Co-authored-by: Xingyao Wang <xingyao6@illinois.edu>
OpenHands 1 jaar geleden
bovenliggende
commit
2a66439ca6

+ 2 - 0
frontend/src/components/features/chat/chat-message.tsx

@@ -5,6 +5,7 @@ import { code } from "../markdown/code";
 import { cn } from "#/utils/utils";
 import { ul, ol } from "../markdown/list";
 import { CopyToClipboardButton } from "#/components/shared/buttons/copy-to-clipboard-button";
+import { anchor } from "../markdown/anchor";
 
 interface ChatMessageProps {
   type: "user" | "assistant";
@@ -62,6 +63,7 @@ export function ChatMessage({
           code,
           ul,
           ol,
+          a: anchor,
         }}
         remarkPlugins={[remarkGfm]}
       >

+ 20 - 0
frontend/src/components/features/markdown/anchor.tsx

@@ -0,0 +1,20 @@
+import React from "react";
+import { ExtraProps } from "react-markdown";
+
+export function anchor({
+  href,
+  children,
+}: React.ClassAttributes<HTMLAnchorElement> &
+  React.AnchorHTMLAttributes<HTMLAnchorElement> &
+  ExtraProps) {
+  return (
+    <a
+      className="text-blue-500 hover:underline"
+      href={href}
+      target="_blank"
+      rel="noopener noreferrer"
+    >
+      {children}
+    </a>
+  );
+}

+ 1 - 0
openhands/server/session/manager.py

@@ -202,6 +202,7 @@ class SessionManager:
             except Exception:
                 logger.warning('error_cleaning_detached_conversations', exc_info=True)
                 await asyncio.sleep(15)
+
     async def init_or_join_session(
         self, sid: str, connection_id: str, session_init_data: SessionInitData
     ):

+ 2 - 0
pyproject.toml

@@ -100,6 +100,7 @@ reportlab = "*"
 [tool.coverage.run]
 concurrency = ["gevent"]
 
+
 [tool.poetry.group.runtime.dependencies]
 jupyterlab = "*"
 notebook = "*"
@@ -129,6 +130,7 @@ ignore = ["D1"]
 [tool.ruff.lint.pydocstyle]
 convention = "google"
 
+
 [tool.poetry.group.evaluation.dependencies]
 streamlit = "*"
 whatthepatch = "*"