-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Feat/copilot files #886
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
Merged
Merged
Feat/copilot files #886
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b8d6cef
Connects to s3
Sg312 aa8c2e7
Checkpoint
Sg312 c629a1c
File shows in message
Sg312 e10b384
Make files clickable
Sg312 ba057bc
User input image
Sg312 5055692
Persist thumbnails
Sg312 8195484
Drag and drop files
Sg312 060bc04
Lint
Sg312 fb879ad
Fix isdev
Sg312 b926171
Dont re-download files on rerender
Sg312 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| export interface FileAttachment { | ||
| id: string | ||
| s3_key: string | ||
| filename: string | ||
| media_type: string | ||
| size: number | ||
| } | ||
|
|
||
| export interface AnthropicMessageContent { | ||
| type: 'text' | 'image' | 'document' | ||
| text?: string | ||
| source?: { | ||
| type: 'base64' | ||
| media_type: string | ||
| data: string | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Mapping of MIME types to Anthropic content types | ||
| */ | ||
| export const MIME_TYPE_MAPPING: Record<string, 'image' | 'document'> = { | ||
| // Images | ||
| 'image/jpeg': 'image', | ||
| 'image/jpg': 'image', | ||
| 'image/png': 'image', | ||
| 'image/gif': 'image', | ||
| 'image/webp': 'image', | ||
| 'image/svg+xml': 'image', | ||
|
|
||
| // Documents | ||
| 'application/pdf': 'document', | ||
| 'text/plain': 'document', | ||
| 'text/csv': 'document', | ||
| 'application/json': 'document', | ||
| 'application/xml': 'document', | ||
| 'text/xml': 'document', | ||
| 'text/html': 'document', | ||
| 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'document', // .docx | ||
| 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'document', // .xlsx | ||
| 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'document', // .pptx | ||
| 'application/msword': 'document', // .doc | ||
| 'application/vnd.ms-excel': 'document', // .xls | ||
| 'application/vnd.ms-powerpoint': 'document', // .ppt | ||
| 'text/markdown': 'document', | ||
| 'application/rtf': 'document', | ||
| } | ||
|
|
||
| /** | ||
| * Get the Anthropic content type for a given MIME type | ||
| */ | ||
| export function getAnthropicContentType(mimeType: string): 'image' | 'document' | null { | ||
| return MIME_TYPE_MAPPING[mimeType.toLowerCase()] || null | ||
| } | ||
|
|
||
| /** | ||
| * Check if a MIME type is supported by Anthropic | ||
| */ | ||
| export function isSupportedFileType(mimeType: string): boolean { | ||
| return mimeType.toLowerCase() in MIME_TYPE_MAPPING | ||
| } | ||
|
|
||
| /** | ||
| * Convert a file buffer to base64 | ||
| */ | ||
| export function bufferToBase64(buffer: Buffer): string { | ||
| return buffer.toString('base64') | ||
| } | ||
|
|
||
| /** | ||
| * Create Anthropic message content from file data | ||
| */ | ||
| export function createAnthropicFileContent( | ||
| fileBuffer: Buffer, | ||
| mimeType: string | ||
| ): AnthropicMessageContent | null { | ||
| const contentType = getAnthropicContentType(mimeType) | ||
| if (!contentType) { | ||
| return null | ||
| } | ||
|
|
||
| return { | ||
| type: contentType, | ||
| source: { | ||
| type: 'base64', | ||
| media_type: mimeType, | ||
| data: bufferToBase64(fileBuffer), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extract file extension from filename | ||
| */ | ||
| export function getFileExtension(filename: string): string { | ||
| const lastDot = filename.lastIndexOf('.') | ||
| return lastDot !== -1 ? filename.slice(lastDot + 1).toLowerCase() : '' | ||
| } | ||
|
|
||
| /** | ||
| * Get MIME type from file extension (fallback if not provided) | ||
| */ | ||
| export function getMimeTypeFromExtension(extension: string): string { | ||
| const extensionMimeMap: Record<string, string> = { | ||
| // Images | ||
| jpg: 'image/jpeg', | ||
| jpeg: 'image/jpeg', | ||
| png: 'image/png', | ||
| gif: 'image/gif', | ||
| webp: 'image/webp', | ||
| svg: 'image/svg+xml', | ||
|
|
||
| // Documents | ||
| pdf: 'application/pdf', | ||
| txt: 'text/plain', | ||
| csv: 'text/csv', | ||
| json: 'application/json', | ||
| xml: 'application/xml', | ||
| html: 'text/html', | ||
| htm: 'text/html', | ||
| docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | ||
| xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
| pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | ||
| doc: 'application/msword', | ||
| xls: 'application/vnd.ms-excel', | ||
| ppt: 'application/vnd.ms-powerpoint', | ||
| md: 'text/markdown', | ||
| rtf: 'application/rtf', | ||
| } | ||
|
|
||
| return extensionMimeMap[extension.toLowerCase()] || 'application/octet-stream' | ||
| } | ||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.