Change File Added format

This commit is contained in:
Alex Gleason committed 2025-09-14 14:29:14 -05:00
1 parent 425976bb82
commit feaa767632
5 files changed
+34 -34

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@ Shakespeare is an AI chat application that allows users to build custom Nostr we
1. **Create a Project**: Enter a description of what you want to build in the prompt textarea 1. **Create a Project**: Enter a description of what you want to build in the prompt textarea
2. **Chat with AI**: Use the AI assistant to add features, edit files, and build your website 2. **Chat with AI**: Use the AI assistant to add features, edit files, and build your website
3. **Attach Files**: Click the paperclip icon to attach files to your messages for AI analysis 3. **Attach Files**: Click the paperclip icon to attach files to your messages - they'll show as "Added file: /path/filename"
4. **Edit Code**: Switch to the code view to manually edit files if needed 4. **Edit Code**: Switch to the code view to manually edit files if needed
5. **Preview**: View your website in the preview pane 5. **Preview**: View your website in the preview pane
+1 -1
View File
@@ -306,7 +306,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
const filePromises = attachedFiles.map(async (file) => { const filePromises = attachedFiles.map(async (file) => {
try { try {
const savedPath = await saveFileToTmp(fs, file); const savedPath = await saveFileToTmp(fs, file);
return `File added to ${savedPath}`; return `Added file: ${savedPath}`;
} catch (error) { } catch (error) {
console.error('Failed to save file:', error); console.error('Failed to save file:', error);
return `Failed to save file: ${file.name}`; return `Failed to save file: ${file.name}`;
+16 -16
View File
@@ -7,42 +7,42 @@ describe('UserMessage Integration', () => {
// Simulate the new text parts structure that ChatPane would create // Simulate the new text parts structure that ChatPane would create
const content = [ const content = [
{ type: 'text' as const, text: 'Please analyze this file:' }, { type: 'text' as const, text: 'Please analyze this file:' },
{ type: 'text' as const, text: 'File added to /tmp/data.csv' }, { type: 'text' as const, text: 'Added file: /tmp/data.csv' },
{ type: 'text' as const, text: 'Let me know what you find!' } { type: 'text' as const, text: 'Let me know what you find!' }
]; ];
render(<UserMessage content={content} />); render(<UserMessage content={content} />);
// Check that regular text is displayed // Check that regular text is displayed
expect(screen.getByText('Please analyze this file:')).toBeInTheDocument(); expect(screen.getByText('Please analyze this file:')).toBeInTheDocument();
expect(screen.getByText('Let me know what you find!')).toBeInTheDocument(); expect(screen.getByText('Let me know what you find!')).toBeInTheDocument();
// Check that file attachment is rendered as a badge // Check that file attachment is rendered as a badge
expect(screen.getByText('data.csv')).toBeInTheDocument(); expect(screen.getByText('data.csv')).toBeInTheDocument();
expect(screen.getByText('added to /tmp/data.csv')).toBeInTheDocument(); expect(screen.getByText('/tmp/data.csv')).toBeInTheDocument();
}); });
it('handles single text part with file attachment', () => { it('handles single text part with file attachment', () => {
const content = [ const content = [
{ type: 'text' as const, text: 'File added to /tmp/script.js' } { type: 'text' as const, text: 'Added file: /tmp/script.js' }
]; ];
render(<UserMessage content={content} />); render(<UserMessage content={content} />);
expect(screen.getByText('script.js')).toBeInTheDocument(); expect(screen.getByText('script.js')).toBeInTheDocument();
expect(screen.getByText('added to /tmp/script.js')).toBeInTheDocument(); expect(screen.getByText('/tmp/script.js')).toBeInTheDocument();
}); });
it('handles multiple file attachments in separate parts', () => { it('handles multiple file attachments in separate parts', () => {
const content = [ const content = [
{ type: 'text' as const, text: 'Here are my files:' }, { type: 'text' as const, text: 'Here are my files:' },
{ type: 'text' as const, text: 'File added to /tmp/config.json' }, { type: 'text' as const, text: 'Added file: /tmp/config.json' },
{ type: 'text' as const, text: 'File added to /tmp/styles.css' }, { type: 'text' as const, text: 'Added file: /tmp/styles.css' },
{ type: 'text' as const, text: 'File added to /tmp/main.js' } { type: 'text' as const, text: 'Added file: /tmp/main.js' }
]; ];
render(<UserMessage content={content} />); render(<UserMessage content={content} />);
expect(screen.getByText('Here are my files:')).toBeInTheDocument(); expect(screen.getByText('Here are my files:')).toBeInTheDocument();
expect(screen.getByText('config.json')).toBeInTheDocument(); expect(screen.getByText('config.json')).toBeInTheDocument();
expect(screen.getByText('styles.css')).toBeInTheDocument(); expect(screen.getByText('styles.css')).toBeInTheDocument();
@@ -51,9 +51,9 @@ describe('UserMessage Integration', () => {
it('handles empty content gracefully', () => { it('handles empty content gracefully', () => {
const content: Array<{ type: 'text'; text: string }> = []; const content: Array<{ type: 'text'; text: string }> = [];
const { container } = render(<UserMessage content={content} />); const { container } = render(<UserMessage content={content} />);
expect(container.firstChild).toBeNull(); expect(container.firstChild).toBeNull();
}); });
}); });
+12 -12
View File
@@ -12,7 +12,7 @@ describe('UserMessage', () => {
}); });
it('handles backward compatibility with string content containing file attachments', () => { it('handles backward compatibility with string content containing file attachments', () => {
const content = 'Here is my file: File added to /tmp/test.txt'; const content = 'Here is my file: Added file: /tmp/test.txt';
render(<UserMessage content={content} />); render(<UserMessage content={content} />);
@@ -23,21 +23,21 @@ describe('UserMessage', () => {
it('renders file attachment badges for single file with text parts', () => { it('renders file attachment badges for single file with text parts', () => {
const content = [ const content = [
{ type: 'text' as const, text: 'Here is my file:' }, { type: 'text' as const, text: 'Here is my file:' },
{ type: 'text' as const, text: 'File added to /tmp/test.txt' } { type: 'text' as const, text: 'Added file: /tmp/test.txt' }
]; ];
render(<UserMessage content={content} />); render(<UserMessage content={content} />);
expect(screen.getByText('Here is my file:')).toBeInTheDocument(); expect(screen.getByText('Here is my file:')).toBeInTheDocument();
expect(screen.getByText('test.txt')).toBeInTheDocument(); expect(screen.getByText('test.txt')).toBeInTheDocument();
expect(screen.getByText('added to /tmp/test.txt')).toBeInTheDocument(); expect(screen.getByText('/tmp/test.txt')).toBeInTheDocument();
}); });
it('renders multiple file attachments with text parts', () => { it('renders multiple file attachments with text parts', () => {
const content = [ const content = [
{ type: 'text' as const, text: 'Files uploaded:' }, { type: 'text' as const, text: 'Files uploaded:' },
{ type: 'text' as const, text: 'File added to /tmp/document.pdf' }, { type: 'text' as const, text: 'Added file: /tmp/document.pdf' },
{ type: 'text' as const, text: 'File added to /tmp/image.jpg' }, { type: 'text' as const, text: 'Added file: /tmp/image.jpg' },
{ type: 'text' as const, text: 'All done!' } { type: 'text' as const, text: 'All done!' }
]; ];
@@ -50,7 +50,7 @@ describe('UserMessage', () => {
}); });
it('renders text files with FileText icon', () => { it('renders text files with FileText icon', () => {
const content = [{ type: 'text' as const, text: 'File added to /tmp/script.js' }]; const content = [{ type: 'text' as const, text: 'Added file: /tmp/script.js' }];
render(<UserMessage content={content} />); render(<UserMessage content={content} />);
@@ -59,27 +59,27 @@ describe('UserMessage', () => {
}); });
it('handles files without extensions', () => { it('handles files without extensions', () => {
const content = [{ type: 'text' as const, text: 'File added to /tmp/README' }]; const content = [{ type: 'text' as const, text: 'Added file: /tmp/README' }];
render(<UserMessage content={content} />); render(<UserMessage content={content} />);
expect(screen.getByText('README')).toBeInTheDocument(); expect(screen.getByText('README')).toBeInTheDocument();
expect(screen.getByText('added to /tmp/README')).toBeInTheDocument(); expect(screen.getByText('/tmp/README')).toBeInTheDocument();
}); });
it('handles complex filenames with underscores and numbers', () => { it('handles complex filenames with underscores and numbers', () => {
const content = [{ type: 'text' as const, text: 'File added to /tmp/my_file_1.txt' }]; const content = [{ type: 'text' as const, text: 'Added file: /tmp/my_file_1.txt' }];
render(<UserMessage content={content} />); render(<UserMessage content={content} />);
expect(screen.getByText('my_file_1.txt')).toBeInTheDocument(); expect(screen.getByText('my_file_1.txt')).toBeInTheDocument();
expect(screen.getByText('added to /tmp/my_file_1.txt')).toBeInTheDocument(); expect(screen.getByText('/tmp/my_file_1.txt')).toBeInTheDocument();
}); });
it('preserves whitespace in text content', () => { it('preserves whitespace in text content', () => {
const content = [ const content = [
{ type: 'text' as const, text: 'Line 1\n\nLine 3 with spaces \n\nFinal line' }, { type: 'text' as const, text: 'Line 1\n\nLine 3 with spaces \n\nFinal line' },
{ type: 'text' as const, text: 'File added to /tmp/test.txt' } { type: 'text' as const, text: 'Added file: /tmp/test.txt' }
]; ];
const { container } = render(<UserMessage content={content} />); const { container } = render(<UserMessage content={content} />);
@@ -94,7 +94,7 @@ describe('UserMessage', () => {
it('handles mixed content with file attachments in the middle', () => { it('handles mixed content with file attachments in the middle', () => {
const content = [ const content = [
{ type: 'text' as const, text: 'Starting text' }, { type: 'text' as const, text: 'Starting text' },
{ type: 'text' as const, text: 'File added to /tmp/middle.txt' }, { type: 'text' as const, text: 'Added file: /tmp/middle.txt' },
{ type: 'text' as const, text: 'ending text' } { type: 'text' as const, text: 'ending text' }
]; ];
+4 -4
View File
@@ -9,7 +9,7 @@ interface UserMessageProps {
/** /**
* Component to render user messages nicely * Component to render user messages nicely
* Handles both string content and array content (text parts) * Handles both string content and array content (text parts)
* Detects "File added to /tmp/<filename>" patterns and renders them as badges * Detects "Added file: /tmp/<filename>" patterns and renders them as badges
*/ */
export function UserMessage({ content }: UserMessageProps) { export function UserMessage({ content }: UserMessageProps) {
// Convert content to array format for uniform processing // Convert content to array format for uniform processing
@@ -17,8 +17,8 @@ export function UserMessage({ content }: UserMessageProps) {
? [{ type: 'text' as const, text: content }] ? [{ type: 'text' as const, text: content }]
: content.filter(part => part.type === 'text') as Array<{ type: 'text'; text: string }>; : content.filter(part => part.type === 'text') as Array<{ type: 'text'; text: string }>;
// Regular expression to match "File added to /tmp/<filename>" patterns // Regular expression to match "Added file: /tmp/<filename>" patterns
const filePattern = /^File added to (\/tmp\/[^\s\n]+)$/; const filePattern = /^Added file: (\/tmp\/[^\s\n]+)$/;
// Process each content part and categorize as text or file // Process each content part and categorize as text or file
const processedParts: Array<{ type: 'text' | 'file'; content: string; filepath?: string }> = []; const processedParts: Array<{ type: 'text' | 'file'; content: string; filepath?: string }> = [];
@@ -75,7 +75,7 @@ export function UserMessage({ content }: UserMessageProps) {
<Badge variant="secondary" className="flex items-center gap-1.5 px-2 py-1"> <Badge variant="secondary" className="flex items-center gap-1.5 px-2 py-1">
{getFileIcon(filename)} {getFileIcon(filename)}
<span className="text-xs font-medium">{filename}</span> <span className="text-xs font-medium">{filename}</span>
<span className="text-xs text-muted-foreground">added to {part.filepath}</span> <span className="text-xs text-muted-foreground">{part.filepath}</span>
</Badge> </Badge>
</div> </div>
); );