Skip to content

Conversation

Ravishekhar7870
Copy link
Contributor

@Ravishekhar7870 Ravishekhar7870 commented Oct 9, 2025

Description

removed attachement upload if the chat is kb based

Testing

tested locally

Summary by CodeRabbit

  • New Features

    • Introduces a knowledge-base chat mode across document/knowledge-management views.
    • Hides attachment controls and disables file uploads/processing in knowledge-base chats for a focused, read-only experience.
    • Ensures chat behavior, message sending, and model configuration are adapted for knowledge-base context while standard chats remain unchanged.
  • Chores

    • Adds a new chat mode flag prop to enable the knowledge-base behavior.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Ravishekhar7870, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a fix to prevent attachment uploads in knowledge base (KB) based chat interfaces. By introducing a new isKnowledgeBaseChat prop, the system can now identify KB chats and dynamically disable file upload functionality, including hiding the attachment UI element. This ensures that users cannot upload files in contexts where such functionality is not intended or supported, improving the chat experience for KB interactions.

Highlights

  • New Prop Introduction: A new boolean prop, isKnowledgeBaseChat, has been added to both the ChatBoxProps and DocumentChatProps interfaces to explicitly identify chats that are knowledge base (KB) based.
  • Attachment Upload Disablement: The uploadFiles and processFiles functions within the ChatBox component now check the isKnowledgeBaseChat prop and will immediately return without processing or uploading files if it is set to true.
  • UI Element Hiding: The attachment button and its associated SmartTooltip are now conditionally rendered in the ChatBox component, becoming invisible when isKnowledgeBaseChat is true, preventing users from attempting to upload files in KB chats.
  • Integration with Knowledge Management: The DocumentChat component, when used within the KnowledgeManagementContent route, now explicitly passes isKnowledgeBaseChat={true} to its ChatBox child, activating the new behavior for KB-specific chats.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 9, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds an optional isKnowledgeBaseChat prop to ChatBox and DocumentChat, threads it through KnowledgeManagement, and conditionally disables/hides attachment UI and short-circuits upload/process/send flows when knowledge-base mode is active. (≤50 words)

Changes

Cohort / File(s) Summary of Changes
Chat UI: Knowledge-base mode and guards
frontend/src/components/ChatBox.tsx
Adds isKnowledgeBaseChat?: boolean to ChatBoxProps; threads flag through upload/send/processing paths; early-return guards in uploadFiles and processFiles; hides/disables attachment UI and related actions in KB mode; refactors send flow to include modelConfig and KB-aware attachment handling and cleanup.
Document chat: Prop threading
frontend/src/components/DocumentChat.tsx
Adds isKnowledgeBaseChat?: boolean to DocumentChatProps, defaults to false, and forwards isKnowledgeBaseChat to ChatBox.
Route usage: Enable KB mode
frontend/src/routes/_authenticated/knowledgeManagement.tsx
Passes isKnowledgeBaseChat={true} into DocumentChat when rendering Knowledge Management content.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant KM as KnowledgeManagement
  participant DC as DocumentChat
  participant CB as ChatBox
  participant API as Backend/API

  User->>KM: Open Knowledge Management page
  KM->>DC: Render DocumentChat (isKnowledgeBaseChat=true)
  DC->>CB: Render ChatBox (isKnowledgeBaseChat=true)

  rect rgba(230,246,255,0.6)
  note right of CB: Attachment UI hidden/disabled in KB mode
  User->>CB: Attempt attach files / click upload
  CB->>CB: uploadFiles() -> early return
  CB->>CB: processFiles() -> early return
  end

  User->>CB: Send message (text)
  CB->>API: sendMessage(payload + modelConfig, attachments skipped)
  API-->>CB: ack
  CB->>User: clear input, reset selected files and previews
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • zereraz
  • shivamashtikar
  • kalpadhwaryu
  • devesh-juspay

Poem

A rabbit taps keys in the night,
KB mode on, attachments out of sight.
Text hops forward, tidy and bright,
Cleans the drafts with nimble bite.
Cheerful burrow, code done right. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "fix: XYNE-152 attachment upload removal when chat is kb based" directly and clearly describes the main objective of the changeset. The modifications across ChatBox.tsx, DocumentChat.tsx, and knowledgeManagement.tsx all work cohesively to implement a single feature: preventing attachment uploads when the chat is knowledge-base based. The title is specific about what is being removed (attachment upload), why (when chat is kb based), and avoids vague language or irrelevant details. A teammate scanning the version history would immediately understand that this change disables attachment upload functionality for KB-based chats.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/kbChat-attachement

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request disables the file attachment feature for knowledge-base chats by introducing an isKnowledgeBaseChat prop. The implementation is mostly correct, but I've found a critical syntax error in the JSX that would prevent the application from compiling. I've also included a few suggestions to improve code style and clarity regarding prop definitions and destructuring. Please address the critical issue to ensure the UI renders correctly.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
frontend/src/components/ChatBox.tsx (3)

832-911: Add isKnowledgeBaseChat to the dependency array.

The uploadFiles callback uses isKnowledgeBaseChat (line 835) but doesn't include it in the dependency array (line 910). This violates React hooks rules and could lead to stale closure bugs where the callback doesn't see updated prop values.

Apply this diff to fix the dependency array:

   },
-  [toast],
+  [toast, isKnowledgeBaseChat],
 )

918-979: Add isKnowledgeBaseChat to the dependency array.

The processFiles callback uses isKnowledgeBaseChat (line 920) but doesn't include it in the dependency array (line 978). This violates React hooks rules and could lead to stale closure bugs.

Apply this diff to fix the dependency array:

   },
-  [selectedFiles.length, uploadFiles, toast],
+  [selectedFiles.length, uploadFiles, toast, isKnowledgeBaseChat],
 )

2515-2531: Misleading success feedback when pasting files in knowledge base mode.

When isKnowledgeBaseChat is true, the paste handler shows a success toast "File pasted...has been added to your message" (lines 2523-2527) even though processFiles silently rejects the file (guard at line 920). This misleads users into thinking their file was attached when it wasn't.

Apply this diff to provide accurate feedback:

                         if (isValid.length > 0) {
+                          if (isKnowledgeBaseChat) {
+                            toast.info({
+                              title: "Attachments not available",
+                              description: "File attachments are disabled in knowledge base chat mode.",
+                            })
+                            return
+                          }
                           // Process the pasted file
                           processFiles([file])
🧹 Nitpick comments (1)
frontend/src/components/ChatBox.tsx (1)

1006-1023: Provide user feedback when files are dropped in knowledge base mode.

When isKnowledgeBaseChat is true and users drag-and-drop files, processFiles silently rejects them (guard at line 920) without any user feedback. Users should be informed why their action had no effect.

Apply this diff to add informative feedback:

   const handleDrop = useCallback(
     (e: React.DragEvent) => {
       e.preventDefault()
       const files = Array.from(e.dataTransfer.files)
       if (files.length > 0) {
+        if (isKnowledgeBaseChat) {
+          toast.info({
+            title: "Attachments not available",
+            description: "File attachments are disabled in knowledge base chat mode.",
+          })
+          return
+        }
         // Check attachment limit before processing
         if (selectedFiles.length >= MAX_ATTACHMENTS) {
           toast.error({
             title: "Attachment limit reached",
             description: `You can only attach up to ${MAX_ATTACHMENTS} files at a time.`,
           })
           return
         }
         processFiles(files)
       }
     },
-    [processFiles, selectedFiles.length],
+    [processFiles, selectedFiles.length, toast, isKnowledgeBaseChat],
   )
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 69a289a and 095ea26.

📒 Files selected for processing (2)
  • frontend/src/components/ChatBox.tsx (9 hunks)
  • frontend/src/components/DocumentChat.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/DocumentChat.tsx
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/src/components/ChatBox.tsx (4)
frontend/src/types.ts (1)
  • ToolsListItem (58-61)
server/shared/types.ts (1)
  • AttachmentMetadata (693-693)
frontend/src/utils/fileUtils.ts (1)
  • cleanupPreviewUrls (42-48)
frontend/src/components/ui/smart-tooltip.tsx (1)
  • SmartTooltip (10-97)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
frontend/src/components/ChatBox.tsx (2)

832-909: KB mode still allows attachments via paste/drag/drop/programmatic input — block all intake paths.

Hiding the button isn’t enough. Users can still add files by drag‑and‑drop or paste. Also the hidden input can be triggered programmatically. Hard‑disable these in KB mode.

Apply these diffs:

@@
-    const uploadFiles = useCallback(
+    const uploadFiles = useCallback(
       async (files: SelectedFile[]) => {
         if (files.length === 0) return []
+        if (isKnowledgeBaseChat) {
+          toast.warning({
+            title: "Attachments disabled",
+            description: "Attachments are not allowed in Knowledge Base chats.",
+          })
+          return []
+        }
@@
-    const processFiles = useCallback(
+    const processFiles = useCallback(
       (files: FileList | File[]) => {
+        if (isKnowledgeBaseChat) {
+          toast.warning({
+            title: "Attachments disabled",
+            description: "Attachments are not allowed in Knowledge Base chats.",
+          })
+          return
+        }
@@
-    const handleDrop = useCallback(
+    const handleDrop = useCallback(
       (e: React.DragEvent) => {
         e.preventDefault()
+        if (isKnowledgeBaseChat) {
+          return
+        }
         const files = Array.from(e.dataTransfer.files)
@@
-        >
-          <div className="relative flex items-center">
+        >
+          <div className="relative flex items-center">
@@
-          onDragOver={handleDragOver}
-          onDragLeave={handleDragLeave}
-          onDrop={handleDrop}
+          onDragOver={isKnowledgeBaseChat ? undefined : handleDragOver}
+          onDragLeave={isKnowledgeBaseChat ? undefined : handleDragLeave}
+          onDrop={isKnowledgeBaseChat ? undefined : handleDrop}
@@
-              onPaste={(e: React.ClipboardEvent<HTMLDivElement>) => {
+              onPaste={(e: React.ClipboardEvent<HTMLDivElement>) => {
                 e.preventDefault()
 
                 const items = e.clipboardData?.items
-                if (items) {
-                  // Handle file paste (all supported file types)
-                  for (let i = 0; i < items.length; i++) {
-                    const item = items[i]
-                    if (item.kind === "file") {
-                      // Check attachment limit before processing
-                      if (selectedFiles.length >= MAX_ATTACHMENTS) {
-                        toast.error({
-                          title: "Attachment limit reached",
-                          description: `You can only attach up to ${MAX_ATTACHMENTS} files at a time.`,
-                        })
-                        return
-                      }
-
-                      const file = item.getAsFile()
-                      if (file) {
-                        // Check if the file type is supported
-                        const isValid = validateAndDeduplicateFiles(
-                          [file],
-                          toast,
-                        )
-                        if (isValid.length > 0) {
-                          // Process the pasted file
-                          processFiles([file])
-                          const fileType = getFileType({
-                            type: file.type,
-                            name: file.name,
-                          })
-
-                          toast.success({
-                            title: "File pasted",
-                            description: `${fileType} has been added to your message.`,
-                          })
-                          return // Exit early since we handled the file
-                        } else {
-                          return
-                        }
-                      }
-                    }
-                  }
-                }
+                if (items) {
+                  const hasFile = Array.from(items).some((it) => it.kind === "file")
+                  if (hasFile && isKnowledgeBaseChat) {
+                    toast.warning({
+                      title: "Attachments disabled",
+                      description: "Pasting files is disabled in Knowledge Base chats.",
+                    })
+                    // Fall through to text paste handling below
+                  } else if (hasFile) {
+                    // Handle file paste (all supported file types)
+                    for (let i = 0; i < items.length; i++) {
+                      const item = items[i]
+                      if (item.kind === "file") {
+                        if (selectedFiles.length >= MAX_ATTACHMENTS) {
+                          toast.error({
+                            title: "Attachment limit reached",
+                            description: `You can only attach up to ${MAX_ATTACHMENTS} files at a time.`,
+                          })
+                          return
+                        }
+                        const file = item.getAsFile()
+                        if (file) {
+                          const isValid = validateAndDeduplicateFiles([file], toast)
+                          if (isValid.length > 0) {
+                            processFiles([file])
+                            const fileType = getFileType({ type: file.type, name: file.name })
+                            toast.success({
+                              title: "File pasted",
+                              description: `${fileType} has been added to your message.`,
+                            })
+                            return // Exit early since we handled the file
+                          } else {
+                            return
+                          }
+                        }
+                      }
+                    }
+                  }
+                }
@@
-        <input
+        <input
           ref={fileInputRef}
           type="file"
           multiple
           className="hidden"
-          onChange={handleFileChange}
+          onChange={isKnowledgeBaseChat ? undefined : handleFileChange}

Also applies to: 916-975, 1003-1019, 2470-2473, 2486-2634, 3959-3968


2807-2930: Hide attachments preview in KB mode.

If attachments are disabled, don’t render the preview tray even if state is somehow populated.

Apply this diff:

-          {/* File Attachments Preview */}
-          {selectedFiles.length > 0 && (
+          {/* File Attachments Preview */}
+          {!isKnowledgeBaseChat && selectedFiles.length > 0 && (
             <div className="px-4 py-2 border-t border-gray-100 dark:border-gray-600">
♻️ Duplicate comments (1)
frontend/src/components/ChatBox.tsx (1)

213-214: Prop addition + sane default look good.

isKnowledgeBaseChat is optional on the type and defaulted to false in destructuring. Good alignment with prior feedback.

Also applies to: 381-382

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 095ea26 and cb0a1c2.

📒 Files selected for processing (1)
  • frontend/src/components/ChatBox.tsx (9 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/src/components/ChatBox.tsx (4)
frontend/src/types.ts (1)
  • ToolsListItem (58-61)
server/shared/types.ts (1)
  • AttachmentMetadata (693-693)
frontend/src/utils/fileUtils.ts (1)
  • cleanupPreviewUrls (42-48)
frontend/src/components/ui/smart-tooltip.tsx (1)
  • SmartTooltip (10-97)
🔇 Additional comments (1)
frontend/src/components/ChatBox.tsx (1)

2932-2952: Hiding the attach button in KB mode is correct.

UI correctly prevents manual selection. With the hard blocks above, behavior matches the PR goal.

@junaid-shirur junaid-shirur merged commit 3c84691 into main Oct 17, 2025
4 checks passed
@junaid-shirur junaid-shirur deleted the fix/kbChat-attachement branch October 17, 2025 07:24
Sithaarth24 pushed a commit that referenced this pull request Oct 17, 2025
## [3.18.5](v3.18.4...v3.18.5) (2025-10-17)

### Bug Fixes

* XYNE-152 attachment upload removal when chat is kb based ([#1069](#1069)) ([3c84691](3c84691))
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.

2 participants