Skip to content

Feat/145 add chat block #1173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

Conversation

Manikandan-Kanini
Copy link
Contributor

Description

Changes Made

How to Test

  1. Steps to reproduce/test the behavior
  2. Expected outcomes

Notes

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@Manikandan-Kanini Manikandan-Kanini requested a review from a team as a code owner May 19, 2025 16:57
Copy link

@CodiumAI-Agent /describe

@CodiumAI-Agent
Copy link

Title

Feat/145 add chat block


User description

Description

Changes Made

How to Test

  1. Steps to reproduce/test the behavior
  2. Expected outcomes

Notes


PR Type

Enhancement


Description

  • Introduce ChatBlock component for interactive chat UI

  • Add MARKDOWN_COMPONENTS for markdown rendering support

  • Register chat block in renderer config and registry

  • Include chat assets, menu entry, and unescapeMarkdown utility


Changes walkthrough 📝

Relevant files
Enhancement
3 files
ChatBlock.tsx
Implement chat block UI and logic                                               
+379/-0 
chat.constants.tsx
Define markdown rendering components                                         
+129/-0 
index.ts
Add unescapeMarkdown utility function                                       
+17/-0   
Configuration changes
6 files
config.tsx
Configure ChatBlock settings and listeners                             
+78/-0   
index.ts
Export chat block module                                                                 
+2/-0     
index.ts
Register ChatBlock in default blocks                                         
+6/-1     
state.constants.ts
Add 'chat' to input block types                                                   
+1/-0     
index.ts
Include chat block asset images                                                   
+2/-0     
default-menu.ts
Add Chat entry to default menu                                                     
+26/-0   

Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    @CodiumAI-Agent /review

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    …45-add-chatBlock
    @CodiumAI-Agent
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    History Parsing

    Parsing and synchronizing data.history via a local variable and relying on updateHistory.length may cause stale updates or inconsistent state. Consider deriving history from state or props using useMemo or useEffect dependencies directly on data.history.

    let updateHistory: { agent: string; user: string }[] = [];
    if (!isLoading && data.history) {
        try {
            updateHistory = JSON.parse(
                data.history as unknown as string,
            ) as ChatMessage[];
        } catch (e) {
            console.log(e);
        }
    }
    Ref Handling

    The copyRefs array is untyped and managed directly, which could lead to unexpected behavior or memory leaks. Consider using a typed RefObject<HTMLDivElement>[] or a ref map for better safety and cleanup.

    const copyRefs = useRef([]);
    // track if the loading screen is on

    Copy link

    @CodiumAI-Agent /improve

    @CodiumAI-Agent
    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix link target typo

    The target attribute has a typo; _black won’t open links in a new tab. Change it to
    the correct _blank value.

    libs/renderer/src/components/block-defaults/chat-block/chat.constants.tsx [109-114]

     <Link
         ref={ref as React.MutableRefObject<HTMLAnchorElement>}
         rel={"noreferrer"}
    -    target={"_black"}
    +    target={"_blank"}
         {...rest}
     />
    Suggestion importance[1-10]: 8

    __

    Why: This corrects a functional bug where links wouldn’t open properly due to a typo in target, ensuring external links open in a new tab.

    Medium
    Support array or string history

    Handle the case when data.history is already an array to avoid JSON parse errors.
    First check if it's an array and assign directly, otherwise parse the string.

    libs/renderer/src/components/block-defaults/chat-block/ChatBlock.tsx [160-167]

     if (!isLoading && data.history) {
    -    try {
    -        updateHistory = JSON.parse(
    -            data.history as unknown as string,
    -        ) as ChatMessage[];
    -    } catch (e) {
    -        console.log(e);
    +    if (Array.isArray(data.history)) {
    +        updateHistory = data.history;
    +    } else {
    +        try {
    +            updateHistory = JSON.parse(
    +                data.history as unknown as string,
    +            ) as ChatMessage[];
    +        } catch (e) {
    +            console.error("Invalid history format:", e);
    +        }
         }
     }
    Suggestion importance[1-10]: 7

    __

    Why: This handles both string and array formats for history based on the ChatBlockDef, preventing runtime JSON parse errors when history is already an array.

    Medium
    General
    Use history as dependency

    Relying only on updateHistory.length misses content changes when the array size
    stays the same. Use data.history (or a serialized version) as the effect dependency
    to react on all history updates.

    libs/renderer/src/components/block-defaults/chat-block/ChatBlock.tsx [191-200]

     useEffect(() => {
    -    // reset the ask
         if (updateHistory.length > 0) {
             setData("ask", "");
             setHistory(updateHistory);
    -        if (endRef.current) {
    -            endRef.current.scrollIntoView({ behavior: "smooth" });
    -        }
    +        endRef.current?.scrollIntoView({ behavior: "smooth" });
         }
    -}, [updateHistory.length]);
    +}, [data.history]);
    Suggestion importance[1-10]: 5

    __

    Why: Switching the effect dependency to data.history ensures updates trigger on content changes even when the length remains the same, improving update reliability.

    Low
    Add typed ref array

    Typing the ref array improves type safety. Declare the ref with an explicit element
    type to avoid any and help with autocompletion.

    libs/renderer/src/components/block-defaults/chat-block/ChatBlock.tsx [156]

    -const copyRefs = useRef([]);
    +const copyRefs = useRef<(HTMLDivElement | null)[]>([]);
    Suggestion importance[1-10]: 4

    __

    Why: Adding an explicit type to copyRefs increases type safety and improves autocompletion for the ref array.

    Low

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    2 participants