-
Notifications
You must be signed in to change notification settings - Fork 115
feat(react-sdk): add PDF and text file support to message input #1194
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
BurhanCantCode
wants to merge
11
commits into
tambo-ai:main
Choose a base branch
from
BurhanCantCode:feat/pdf-text-file-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(react-sdk): add PDF and text file support to message input #1194
BurhanCantCode
wants to merge
11
commits into
tambo-ai:main
from
BurhanCantCode:feat/pdf-text-file-support
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Extends file upload functionality to support PDFs and text files (.txt, .md) in addition to images. Key Changes: - Added useMessageFiles hook replacing useMessageImages (backwards compatible) - Added pdfjs-dist dependency for client-side PDF text extraction - Implemented file type detection with content processing: - Images: converted to base64 data URLs - PDFs: text extracted via PDF.js - Text files: content read directly - Added file limits: 10 files max, 50MB per file, 100MB total - Implemented content truncation (100KB total, 50KB per file) to prevent payload size errors - Enhanced error handling for connection/timeout errors UI Improvements: - Professional file preview cards with loading states - File type icons (PDF, text, images) - Image thumbnails with hover-to-remove functionality - File counter and size display - Drag-and-drop support for all file types - MessageAttachments component for displaying file info in chat Tests: - Added comprehensive tests for useMessageFiles hook - Updated message-builder tests for file content handling - All 254 tests passing Backwards Compatibility: - Old useMessageImages API still works via exports - StagedImage type aliased to StagedFile
|
@BurhanCantCode is attempting to deploy a commit to the tambo ai Team on Vercel. A member of the Team first needs to authorize it. |
…action method to fetch from tambo-cloud Key Changes: - Removed pdfjs-dist dependency from package.json. - Updated extractPdfText function to use a fetch API for PDF text extraction instead of pdfjs-dist. - Adjusted tests to mock fetch for PDF API calls. This change streamlines the PDF extraction process and reduces package size.
Remove unused canvas dependencies that were pulled in by pdfjs-dist. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Resolved conflicts: - showcase/src/lib/thread-hooks.ts: Kept file content marker filtering logic needed for PDF/text file support feature - package-lock.json: Regenerated after accepting main version 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Fix lint warning for undeclared environment variable. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Remove fileToDataUrl, extractPdfText, readTextFile functions - Replace dataUrl/textContent with storagePath in StagedFile - Update ALLOWED_FILE_TYPES to include CSV and specific image formats - Remove text file content embedding from message builder - Prepare for storage-based file upload implementation
- Add uploadFile function that calls /extract/pdf endpoint - Upload files immediately when added to staged files - Store storagePath in StagedFile for message content - Handle upload errors and filter out failed uploads - Use TamboClient for API requests with proper auth
Check for pending uploads and failed uploads before allowing submission
- Images: Pass as image_url with storage:// URL - Documents: Pass as text with storage:// URL pattern - Backend will fetch from storage and convert to proper format for LLM
- Introduced new MIME type handling for various file formats including images, documents, and text files. - Updated file upload validation to support a wider range of file types in the message input. - Improved file icon representation based on MIME type in message components. - Added functions to infer MIME types from file extensions and storage references. - Enhanced error handling for unsupported file types during upload.
Update test assertions and mock data to use storagePath property and storage:// URL format instead of dataUrl/textContent. Remove blank lines within functions per coding standards.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Extends file upload functionality to support PDFs and text files (
.txt,.md) in addition to images. Files are processed client-side with appropriate extraction methods, and the UI provides professional preview cards with loading states.Changes
Core Functionality
useMessageFileshook to replaceuseMessageImages(fully backwards compatible)pdfjs-distdependency for client-side PDF text extractionUI Improvements
MessageAttachmentscomponent for displaying file metadata in chat messagesDeveloper Experience
use-message-files.test.tswith full test coveragemessage-builder.test.tsfor file content handlingBackwards Compatibility
useMessageImagesAPI still works via exportsStagedImagetype aliased toStagedFileTesting
Technical Details
File Processing:
Content Management:
Security:
Files Changed
react-sdk/package.json- Added pdfjs-dist dependencyreact-sdk/src/hooks/use-message-files.ts(NEW) - Core file handling hookreact-sdk/src/hooks/__tests__/use-message-files.test.ts(NEW) - Comprehensive testsreact-sdk/src/util/message-builder.ts- Content builder with truncationreact-sdk/src/providers/tambo-thread-input-provider.tsx- Updated providerreact-sdk/src/index.ts- Backwards-compatible exportsshowcase/src/components/ui/message-input.tsx- Professional file preview UIshowcase/src/components/ui/message.tsx- MessageAttachments componentshowcase/src/components/ui/thread-content.tsx- Renders attachmentsshowcase/src/lib/thread-hooks.ts- Content filtering utilitiesreact-sdk/src/util/__tests__/message-builder.test.tsScreenshots