Skip to content

Conversation

@marcosmarf27
Copy link

Title: Add image paste feature to chat input

Description:

Summary
This PR adds the ability to paste images directly into the chat input using Ctrl+V (or Cmd+V on Mac), eliminating the need to manually select files through the file picker. Pasted images are automatically processed and sent to the LLM for analysis.

Changes
Added handlePaste event handler in TextInput.tsx (lines 106-137)
Automatically detects images in clipboard when pasting
Processes pasted images through the existing file upload system
Maintains full compatibility with existing upload configurations (isImageUploadAllowed, isFullFileUpload)
Supports pasting multiple images simultaneously
How to Use
Take a screenshot (Print Screen, Snipping Tool, etc.)
Go to the Flowise chat
Press Ctrl+V (or Cmd+V on Mac) in the text input field
The image will be automatically attached and ready to send to the LLM
Technical Details
Implementation location: src/components/inputs/textInput/components/TextInput.tsx:106-137
Event handler registered: onPaste on line 151
Respects existing upload permissions and file type restrictions
Works seamlessly with the current file handling infrastructure
Testing
✅ Build completed successfully
✅ TypeScript compilation without errors
✅ Maintains backward compatibility with existing upload features

Implementa a capacidade de colar screenshots e outras imagens diretamente
no chat usando Ctrl+V (ou Cmd+V), eliminando a necessidade de selecionar
arquivos manualmente. As imagens coladas são processadas automaticamente
e enviadas para o LLM analisar.

Mudanças:
- Adiciona event listener de paste no componente TextInput
- Detecta automaticamente imagens no clipboard
- Processa imagens coladas da mesma forma que uploads de arquivo
- Mantém compatibilidade com upload tradicional de arquivos
Atualiza yarn.lock e adiciona package-lock.json gerados durante
a instalação das dependências necessárias para o build.
@gemini-code-assist
Copy link

Summary of Changes

Hello @marcosmarf27, 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 introduces a significant quality-of-life improvement by enabling direct image pasting into the chat input field. This enhancement streamlines the user workflow for submitting visual content to the LLM, making the interaction more intuitive and efficient without altering existing file upload permissions or backend processing.

Highlights

  • Image Paste Functionality: Users can now paste images directly into the chat input using Ctrl+V (or Cmd+V on Mac), bypassing the need for manual file selection.
  • Automatic Processing: Pasted images are automatically detected, processed, and sent to the LLM for analysis, integrating seamlessly with the existing file upload system.
  • Compatibility and Support: The feature fully supports existing upload configurations and permissions (e.g., "isImageUploadAllowed", "isFullFileUpload") and can handle multiple images pasted simultaneously.
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.

Copy link

@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 introduces a valuable feature allowing users to paste images directly into the chat input. The implementation in TextInput.tsx is clean, adding an onPaste event handler that correctly identifies image files and integrates them with the existing file upload system. My review includes one suggestion to refactor the image extraction logic to be more concise and robust using modern JavaScript features and more specific type checks. Overall, this is a great enhancement to the user experience.

Comment on lines +110 to +121
const imageFiles: File[] = [];

// Check if any items in the clipboard are images
for (let i = 0; i < items.length; i++) {
const item = items[i];
if (item.type.indexOf('image') !== -1) {
const file = item.getAsFile();
if (file) {
imageFiles.push(file);
}
}
}

Choose a reason for hiding this comment

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

medium

The logic for extracting image files from the clipboard can be made more concise and robust by using modern array methods and more specific checks.

  • You can convert the DataTransferItemList to an array using Array.from() to leverage methods like filter and map.
  • It's good practice to also check item.kind === 'file' to ensure you're dealing with files.
  • Use item.type.startsWith('image/') for a more precise check for image MIME types.

The entire loop can be replaced with a single chained expression, which improves readability and maintainability.

    const imageFiles = Array.from(items)
      .filter((item) => item.kind === 'file' && item.type.startsWith('image/'))
      .map((item) => item.getAsFile())
      .filter((file): file is File => file !== null);

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