mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
764319223a |
No files matched your search
@@ -1,38 +1,85 @@
|
|||||||
# Shakespeare 🎭
|
# Shakespeare - AI-Powered Nostr Website Builder
|
||||||
|
|
||||||
[](https://shakespeare.diy/clone?url=https://gitlab.com/soapbox-pub/shakespeare.git)
|
Shakespeare is an AI chat application that allows users to build custom Nostr websites through natural language conversation. Simply describe what you want to build, and AI will help you create it.
|
||||||
|
|
||||||
AI-powered Nostr website builder. Describe what you want to build, and AI helps you create it.
|
|
||||||
|
|
||||||
https://shakespeare.diy
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- **AI Chat**: Build websites through natural conversation
|
- **AI-Powered Development**: Chat with an AI assistant to build your Nostr website
|
||||||
- **File Attachments**: Drag & drop files or paste images
|
- **File Attachments**: Attach files directly to chat messages with structured text parts, visual badges, and deduplication. Supports both file selection and clipboard image pasting
|
||||||
- **Live Preview**: See changes in real-time
|
- **Project Management**: Create and manage multiple projects with sidebar navigation
|
||||||
- **Code Editor**: Edit files with syntax highlighting
|
- **Real-time Editing**: Edit files directly in the browser with syntax highlighting
|
||||||
- **Git Integration**: Full version control with credential management
|
- **File Explorer**: Browse and manage your project files
|
||||||
- **Nostr Ready**: Built-in Nostr protocol support
|
- **Project Preview**: Preview your website as you build it
|
||||||
|
- **Template Cloning**: Start from a pre-configured Nostr template
|
||||||
## Quick Start
|
|
||||||
|
|
||||||
1. **Describe** your project in the textarea
|
|
||||||
2. **Chat** with AI to build features
|
|
||||||
3. **Preview** your website instantly
|
|
||||||
4. **Deploy** with one click
|
|
||||||
|
|
||||||
## Tech Stack
|
|
||||||
|
|
||||||
- React 18 + TypeScript
|
|
||||||
- Vite + TailwindCSS
|
|
||||||
- shadcn/ui + Nostrify
|
|
||||||
- LightningFS + isomorphic-git
|
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
Visit the homepage, enter your project idea, and start building with AI assistance.
|
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
|
||||||
|
3. **Attach Files**: Click the paperclip icon to attach files or paste images directly from your clipboard - they'll show as "Added file: /path/filename"
|
||||||
|
4. **Edit Code**: Switch to the code view to manually edit files if needed
|
||||||
|
5. **Preview**: View your website in the preview pane
|
||||||
|
|
||||||
## License
|
## Project Structure
|
||||||
|
|
||||||
AGPLv3
|
Each project includes:
|
||||||
|
- React 18 with TypeScript
|
||||||
|
- Vite for building
|
||||||
|
- TailwindCSS for styling
|
||||||
|
- Nostrify for Nostr integration
|
||||||
|
- shadcn/ui components
|
||||||
|
|
||||||
|
## AI Capabilities
|
||||||
|
|
||||||
|
The AI assistant can:
|
||||||
|
- Read and write project files
|
||||||
|
- Add new components and pages
|
||||||
|
- Configure Nostr functionality
|
||||||
|
- Build the project
|
||||||
|
- Search through files
|
||||||
|
- Provide project structure overview
|
||||||
|
- Add and remove npm packages
|
||||||
|
- Install dependencies and dev dependencies
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
1. **Homepage**: Enter a project description in the textarea to create new projects, with existing projects listed in the sidebar
|
||||||
|
2. **Project View**: Split-pane interface with AI chat on the left and preview/code on the right
|
||||||
|
3. **File Explorer**: Navigate your project files in the code view
|
||||||
|
4. **File Editor**: Edit files with syntax highlighting and save changes
|
||||||
|
|
||||||
|
## Git Integration
|
||||||
|
|
||||||
|
Shakespeare includes full Git functionality with credential management:
|
||||||
|
|
||||||
|
### Features
|
||||||
|
- **Version Control**: Full Git repository support with commit history and branch management
|
||||||
|
- **Global Credentials**: Configure Git credentials once and use them across all projects
|
||||||
|
- **Automatic Matching**: Credentials are automatically matched to repository origins
|
||||||
|
- **Popular Providers**: Built-in support for GitHub, GitLab, and custom Git providers
|
||||||
|
- **Secure Storage**: Credentials are stored locally in your browser using IndexedDB
|
||||||
|
|
||||||
|
### Setting Up Git Credentials
|
||||||
|
|
||||||
|
1. **Access Git Settings**: Click the gear icon in any Git dialog or use the Git Settings option
|
||||||
|
2. **Add Provider**: Choose from GitHub, GitLab, or add a custom Git provider
|
||||||
|
3. **Enter Token**: Use your username and personal access token for authentication
|
||||||
|
4. **Automatic Usage**: Credentials are automatically used for push/pull operations in matching repositories
|
||||||
|
|
||||||
|
### Repository Operations
|
||||||
|
|
||||||
|
- **Push/Pull**: Sync changes with remote repositories using configured credentials
|
||||||
|
- **Status Monitoring**: Real-time Git status with file changes and sync information
|
||||||
|
- **Commit History**: View commit history and repository information
|
||||||
|
- **Branch Management**: Work with different branches and track remote changes
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
Built with:
|
||||||
|
- React 18
|
||||||
|
- TypeScript
|
||||||
|
- Vite
|
||||||
|
- TailwindCSS
|
||||||
|
- shadcn/ui
|
||||||
|
- LightningFS for filesystem
|
||||||
|
- isomorphic-git for template cloning
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||||
import userEvent from '@testing-library/user-event';
|
|
||||||
import { Decimal } from 'decimal.js';
|
|
||||||
import { TestApp } from '@/test/TestApp';
|
import { TestApp } from '@/test/TestApp';
|
||||||
import { ModelSelector } from './ModelSelector';
|
import { ModelSelector } from './ModelSelector';
|
||||||
|
|
||||||
@@ -14,10 +12,6 @@ vi.mock('@/hooks/useProviderModels', () => ({
|
|||||||
useProviderModels: vi.fn(),
|
useProviderModels: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock('@/hooks/useIsMobile', () => ({
|
|
||||||
useIsMobile: vi.fn(),
|
|
||||||
}));
|
|
||||||
|
|
||||||
vi.mock('react-router-dom', async (importOriginal) => {
|
vi.mock('react-router-dom', async (importOriginal) => {
|
||||||
const actual = await importOriginal() as Record<string, unknown>;
|
const actual = await importOriginal() as Record<string, unknown>;
|
||||||
return {
|
return {
|
||||||
@@ -28,11 +22,9 @@ vi.mock('react-router-dom', async (importOriginal) => {
|
|||||||
|
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import { useProviderModels } from '@/hooks/useProviderModels';
|
import { useProviderModels } from '@/hooks/useProviderModels';
|
||||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
|
||||||
|
|
||||||
const mockUseAISettings = vi.mocked(useAISettings);
|
const mockUseAISettings = vi.mocked(useAISettings);
|
||||||
const mockUseProviderModels = vi.mocked(useProviderModels);
|
const mockUseProviderModels = vi.mocked(useProviderModels);
|
||||||
const mockUseIsMobile = vi.mocked(useIsMobile);
|
|
||||||
|
|
||||||
describe('ModelSelector', () => {
|
describe('ModelSelector', () => {
|
||||||
const mockOnChange = vi.fn();
|
const mockOnChange = vi.fn();
|
||||||
@@ -58,8 +50,6 @@ describe('ModelSelector', () => {
|
|||||||
error: null,
|
error: null,
|
||||||
refetch: vi.fn(),
|
refetch: vi.fn(),
|
||||||
});
|
});
|
||||||
|
|
||||||
mockUseIsMobile.mockReturnValue(false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('hides recently used section when less than 5 models and all recently used are available', async () => {
|
it('hides recently used section when less than 5 models and all recently used are available', async () => {
|
||||||
@@ -247,219 +237,4 @@ describe('ModelSelector', () => {
|
|||||||
// Recently used section should NOT be visible
|
// Recently used section should NOT be visible
|
||||||
expect(screen.queryByText('Recently Used')).not.toBeInTheDocument();
|
expect(screen.queryByText('Recently Used')).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows caution icon for free models', async () => {
|
|
||||||
const freeModel = {
|
|
||||||
fullId: 'provider1/free-model',
|
|
||||||
provider: 'provider1',
|
|
||||||
id: 'free-model',
|
|
||||||
pricing: {
|
|
||||||
prompt: new Decimal('0'),
|
|
||||||
completion: new Decimal('0'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const paidModel = {
|
|
||||||
fullId: 'provider1/paid-model',
|
|
||||||
provider: 'provider1',
|
|
||||||
id: 'paid-model',
|
|
||||||
pricing: {
|
|
||||||
prompt: new Decimal('0.01'),
|
|
||||||
completion: new Decimal('0.02'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mockUseProviderModels.mockReturnValue({
|
|
||||||
models: [freeModel, paidModel],
|
|
||||||
isLoading: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Test with free model selected
|
|
||||||
const { rerender } = render(
|
|
||||||
<TestApp>
|
|
||||||
<ModelSelector value="provider1/free-model" onChange={mockOnChange} />
|
|
||||||
</TestApp>
|
|
||||||
);
|
|
||||||
|
|
||||||
// Should show caution icon for free model
|
|
||||||
expect(screen.getByTestId('triangle-alert')).toBeInTheDocument();
|
|
||||||
|
|
||||||
// Test with paid model selected
|
|
||||||
rerender(
|
|
||||||
<TestApp>
|
|
||||||
<ModelSelector value="provider1/paid-model" onChange={mockOnChange} />
|
|
||||||
</TestApp>
|
|
||||||
);
|
|
||||||
|
|
||||||
// Should not show caution icon for paid model
|
|
||||||
expect(screen.queryByTestId('triangle-alert')).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not show caution icon when no model is selected', () => {
|
|
||||||
const freeModel = {
|
|
||||||
fullId: 'provider1/free-model',
|
|
||||||
provider: 'provider1',
|
|
||||||
id: 'free-model',
|
|
||||||
pricing: {
|
|
||||||
prompt: new Decimal('0'),
|
|
||||||
completion: new Decimal('0'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mockUseProviderModels.mockReturnValue({
|
|
||||||
models: [freeModel],
|
|
||||||
isLoading: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
|
||||||
<TestApp>
|
|
||||||
<ModelSelector value="" onChange={mockOnChange} />
|
|
||||||
</TestApp>
|
|
||||||
);
|
|
||||||
|
|
||||||
// Should not show caution icon when no model is selected
|
|
||||||
expect(screen.queryByTestId('triangle-alert')).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('does not show caution icon for models without pricing information', () => {
|
|
||||||
const modelWithoutPricing = {
|
|
||||||
fullId: 'provider1/unknown-pricing',
|
|
||||||
provider: 'provider1',
|
|
||||||
id: 'unknown-pricing',
|
|
||||||
// No pricing property
|
|
||||||
};
|
|
||||||
|
|
||||||
mockUseProviderModels.mockReturnValue({
|
|
||||||
models: [modelWithoutPricing],
|
|
||||||
isLoading: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
|
||||||
<TestApp>
|
|
||||||
<ModelSelector value="provider1/unknown-pricing" onChange={mockOnChange} />
|
|
||||||
</TestApp>
|
|
||||||
);
|
|
||||||
|
|
||||||
// Should not show caution icon for models without pricing info
|
|
||||||
expect(screen.queryByTestId('triangle-alert')).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('shows tooltip when hovering over caution icon', async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
|
|
||||||
const freeModel = {
|
|
||||||
fullId: 'provider1/free-model',
|
|
||||||
provider: 'provider1',
|
|
||||||
id: 'free-model',
|
|
||||||
pricing: {
|
|
||||||
prompt: new Decimal('0'),
|
|
||||||
completion: new Decimal('0'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mockUseProviderModels.mockReturnValue({
|
|
||||||
models: [freeModel],
|
|
||||||
isLoading: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
|
||||||
<TestApp>
|
|
||||||
<ModelSelector value="provider1/free-model" onChange={mockOnChange} />
|
|
||||||
</TestApp>
|
|
||||||
);
|
|
||||||
|
|
||||||
const cautionIcon = screen.getByTestId('triangle-alert');
|
|
||||||
expect(cautionIcon).toBeInTheDocument();
|
|
||||||
|
|
||||||
// Hover over the caution icon
|
|
||||||
await user.hover(cautionIcon);
|
|
||||||
|
|
||||||
// Wait for tooltip to appear
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(screen.getAllByText('You are using a free model. For better results, switch to a paid model.').length).toBeGreaterThan(0);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('makes caution icon tappable on mobile with click-to-toggle tooltip', async () => {
|
|
||||||
const user = userEvent.setup();
|
|
||||||
mockUseIsMobile.mockReturnValue(true);
|
|
||||||
|
|
||||||
const freeModel = {
|
|
||||||
fullId: 'provider1/free-model',
|
|
||||||
provider: 'provider1',
|
|
||||||
id: 'free-model',
|
|
||||||
pricing: {
|
|
||||||
prompt: new Decimal('0'),
|
|
||||||
completion: new Decimal('0'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mockUseProviderModels.mockReturnValue({
|
|
||||||
models: [freeModel],
|
|
||||||
isLoading: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
|
||||||
<TestApp>
|
|
||||||
<ModelSelector value="provider1/free-model" onChange={mockOnChange} />
|
|
||||||
</TestApp>
|
|
||||||
);
|
|
||||||
|
|
||||||
const cautionButton = screen.getByRole('button', { name: 'Free model warning' });
|
|
||||||
expect(cautionButton).toBeInTheDocument();
|
|
||||||
expect(cautionButton).toHaveAttribute('tabIndex', '0'); // Should be tappable on mobile
|
|
||||||
|
|
||||||
// Click to open tooltip - just verify the click works without errors
|
|
||||||
await user.click(cautionButton);
|
|
||||||
|
|
||||||
// Tooltip should appear
|
|
||||||
await waitFor(() => {
|
|
||||||
expect(screen.getAllByText('You are using a free model. For better results, switch to a paid model.').length).toBeGreaterThan(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
// The button should still be clickable (no errors)
|
|
||||||
await user.click(cautionButton);
|
|
||||||
expect(cautionButton).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('makes caution icon not focusable on desktop', () => {
|
|
||||||
mockUseIsMobile.mockReturnValue(false);
|
|
||||||
|
|
||||||
const freeModel = {
|
|
||||||
fullId: 'provider1/free-model',
|
|
||||||
provider: 'provider1',
|
|
||||||
id: 'free-model',
|
|
||||||
pricing: {
|
|
||||||
prompt: new Decimal('0'),
|
|
||||||
completion: new Decimal('0'),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mockUseProviderModels.mockReturnValue({
|
|
||||||
models: [freeModel],
|
|
||||||
isLoading: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
render(
|
|
||||||
<TestApp>
|
|
||||||
<ModelSelector value="provider1/free-model" onChange={mockOnChange} />
|
|
||||||
</TestApp>
|
|
||||||
);
|
|
||||||
|
|
||||||
const cautionButton = screen.getByRole('button', { name: 'Free model warning' });
|
|
||||||
expect(cautionButton).toBeInTheDocument();
|
|
||||||
expect(cautionButton).toHaveAttribute('tabIndex', '-1'); // Should not be focusable on desktop
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
+156
-247
@@ -1,16 +1,14 @@
|
|||||||
import { useState, useMemo, useEffect } from 'react';
|
import { useState, useMemo } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Check, ChevronDown, Edit3, RefreshCw, AlertCircle, Settings, TriangleAlert } from 'lucide-react';
|
import { Check, ChevronDown, Edit3, RefreshCw, AlertCircle, Settings } from 'lucide-react';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
||||||
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from '@/components/ui/command';
|
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator } from '@/components/ui/command';
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
||||||
import { useAISettings } from '@/hooks/useAISettings';
|
import { useAISettings } from '@/hooks/useAISettings';
|
||||||
import { useProviderModels } from '@/hooks/useProviderModels';
|
import { useProviderModels } from '@/hooks/useProviderModels';
|
||||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
interface ModelSelectorProps {
|
interface ModelSelectorProps {
|
||||||
@@ -34,7 +32,6 @@ export function ModelSelector({
|
|||||||
}: ModelSelectorProps) {
|
}: ModelSelectorProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
const [uncontrolledOpen, setUncontrolledOpen] = useState(false);
|
||||||
const [isTooltipOpen, setIsTooltipOpen] = useState(false);
|
|
||||||
|
|
||||||
// Use controlled state if provided, otherwise use local state
|
// Use controlled state if provided, otherwise use local state
|
||||||
const open = controlledOpen !== undefined ? controlledOpen : uncontrolledOpen;
|
const open = controlledOpen !== undefined ? controlledOpen : uncontrolledOpen;
|
||||||
@@ -45,7 +42,6 @@ export function ModelSelector({
|
|||||||
const { settings, addRecentlyUsedModel, isConfigured } = useAISettings();
|
const { settings, addRecentlyUsedModel, isConfigured } = useAISettings();
|
||||||
const { models, isLoading, error, refetch } = useProviderModels();
|
const { models, isLoading, error, refetch } = useProviderModels();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const isMobile = useIsMobile();
|
|
||||||
|
|
||||||
const defaultPlaceholder = t('selectOrEnterModel');
|
const defaultPlaceholder = t('selectOrEnterModel');
|
||||||
|
|
||||||
@@ -86,43 +82,9 @@ export function ModelSelector({
|
|||||||
return !allRecentlyUsedAreAvailable;
|
return !allRecentlyUsedAreAvailable;
|
||||||
}, [recentlyUsedModels, models]);
|
}, [recentlyUsedModels, models]);
|
||||||
|
|
||||||
// Check if the current model is free
|
|
||||||
const isCurrentModelFree = useMemo(() => {
|
|
||||||
if (!value) return false;
|
|
||||||
|
|
||||||
const currentModel = models.find(model => model.fullId === value);
|
|
||||||
if (!currentModel?.pricing) return false;
|
|
||||||
|
|
||||||
return currentModel.pricing.prompt.equals(0) && currentModel.pricing.completion.equals(0);
|
|
||||||
}, [value, models]);
|
|
||||||
|
|
||||||
// Don't auto-initialize with recently used models
|
// Don't auto-initialize with recently used models
|
||||||
// Let the parent component handle initialization
|
// Let the parent component handle initialization
|
||||||
|
|
||||||
// Close tooltip when clicking outside on mobile
|
|
||||||
useEffect(() => {
|
|
||||||
if (!isMobile || !isTooltipOpen) return;
|
|
||||||
|
|
||||||
const handleClickOutside = (event: MouseEvent | TouchEvent) => {
|
|
||||||
const target = event.target as Element;
|
|
||||||
// Check if the click is outside the tooltip and trigger
|
|
||||||
if (!target.closest('[data-radix-tooltip-content]') &&
|
|
||||||
!target.closest('[data-radix-tooltip-trigger]') &&
|
|
||||||
!target.closest('[data-testid="triangle-alert"]')) {
|
|
||||||
setIsTooltipOpen(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add both click and touch event listeners
|
|
||||||
document.addEventListener('click', handleClickOutside, true);
|
|
||||||
document.addEventListener('touchstart', handleClickOutside, true);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
document.removeEventListener('click', handleClickOutside, true);
|
|
||||||
document.removeEventListener('touchstart', handleClickOutside, true);
|
|
||||||
};
|
|
||||||
}, [isMobile, isTooltipOpen]);
|
|
||||||
|
|
||||||
const handleSelect = (selectedValue: string) => {
|
const handleSelect = (selectedValue: string) => {
|
||||||
if (selectedValue === '__custom__') {
|
if (selectedValue === '__custom__') {
|
||||||
setIsCustomInput(true);
|
setIsCustomInput(true);
|
||||||
@@ -163,222 +125,169 @@ export function ModelSelector({
|
|||||||
|
|
||||||
if (isCustomInput) {
|
if (isCustomInput) {
|
||||||
return (
|
return (
|
||||||
<TooltipProvider>
|
<div className={cn("flex items-center gap-1", className)}>
|
||||||
<div className={cn("flex items-center gap-1", className)}>
|
<Input
|
||||||
<Input
|
value={customValue}
|
||||||
value={customValue}
|
onChange={(e) => setCustomValue(e.target.value)}
|
||||||
onChange={(e) => setCustomValue(e.target.value)}
|
onKeyDown={handleCustomKeyDown}
|
||||||
onKeyDown={handleCustomKeyDown}
|
onBlur={handleCustomSubmit}
|
||||||
onBlur={handleCustomSubmit}
|
placeholder="provider/model (e.g., openrouter/anthropic/claude-sonnet-4)"
|
||||||
placeholder="provider/model (e.g., openrouter/anthropic/claude-sonnet-4)"
|
className="h-8 text-xs"
|
||||||
className="h-8 text-xs"
|
autoFocus
|
||||||
autoFocus
|
/>
|
||||||
/>
|
<Button
|
||||||
<Button
|
size="sm"
|
||||||
size="sm"
|
variant="ghost"
|
||||||
variant="ghost"
|
className="h-8 w-8 p-0"
|
||||||
className="h-8 w-8 p-0"
|
onClick={handleCustomSubmit}
|
||||||
onClick={handleCustomSubmit}
|
>
|
||||||
>
|
<Check className="h-3 w-3" />
|
||||||
<Check className="h-3 w-3" />
|
</Button>
|
||||||
</Button>
|
</div>
|
||||||
</div>
|
|
||||||
</TooltipProvider>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TooltipProvider>
|
<Popover open={open} onOpenChange={setOpen}>
|
||||||
<div className={cn("flex justify-end gap-0.5", className)}>
|
<PopoverTrigger asChild>
|
||||||
{isCurrentModelFree && (
|
<Button
|
||||||
<Tooltip
|
variant="ghost"
|
||||||
open={isMobile ? isTooltipOpen : undefined}
|
role="combobox"
|
||||||
onOpenChange={isMobile ? setIsTooltipOpen : undefined}
|
aria-expanded={open}
|
||||||
delayDuration={isMobile ? 0 : 700}
|
className={cn(
|
||||||
disableHoverableContent={isMobile}
|
"h-8 p-0 gap-0.5 justify-between text-xs border-0 bg-transparent hover:bg-transparent hover:text-foreground focus-visible:ring-0 focus-visible:ring-offset-0 text-muted-foreground text-right",
|
||||||
>
|
className
|
||||||
<TooltipTrigger asChild>
|
)}
|
||||||
<button
|
disabled={disabled}
|
||||||
type="button"
|
>
|
||||||
className="inline-flex items-center p-0 rounded-none border-0 bg-transparent hover:bg-transparent focus:bg-transparent active:bg-transparent focus:outline-none focus-visible:outline-none focus:ring-0 focus-visible:ring-0 focus:border-0 active:outline-none"
|
<span className="w-full truncate">
|
||||||
aria-label="Free model warning"
|
{value || placeholder || defaultPlaceholder}
|
||||||
tabIndex={isMobile ? 0 : -1}
|
</span>
|
||||||
onClick={isMobile ? (e) => {
|
<ChevronDown className="size-3 shrink-0 opacity-50" />
|
||||||
e.preventDefault();
|
</Button>
|
||||||
e.stopPropagation();
|
</PopoverTrigger>
|
||||||
setIsTooltipOpen(!isTooltipOpen);
|
<PopoverContent className="w-96 p-0" align="end">
|
||||||
} : undefined}
|
<Command>
|
||||||
onTouchStart={isMobile ? (e) => {
|
{(isConfigured && models.length >= 5) && (
|
||||||
e.preventDefault();
|
<CommandInput placeholder={t('searchModels')} className="h-9" />
|
||||||
e.stopPropagation();
|
)}
|
||||||
} : undefined}
|
<CommandList className="max-h-[300px]">
|
||||||
onTouchEnd={isMobile ? (e) => {
|
<CommandEmpty>
|
||||||
e.preventDefault();
|
<div className="py-6 text-center text-sm text-muted-foreground">
|
||||||
e.stopPropagation();
|
<p>{t('noModelsFound')}</p>
|
||||||
setIsTooltipOpen(!isTooltipOpen);
|
<p className="mt-2 text-xs">{t('tryCustomModel')}</p>
|
||||||
} : undefined}
|
</div>
|
||||||
style={{
|
</CommandEmpty>
|
||||||
WebkitTapHighlightColor: 'transparent',
|
|
||||||
outline: 'none',
|
|
||||||
border: 'none',
|
|
||||||
boxShadow: 'none'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<TriangleAlert className="h-3 w-3 text-amber-500 flex-shrink-0" data-testid="triangle-alert" />
|
|
||||||
</button>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent
|
|
||||||
side="top"
|
|
||||||
sideOffset={4}
|
|
||||||
className="max-w-xs text-center"
|
|
||||||
avoidCollisions={true}
|
|
||||||
collisionPadding={8}
|
|
||||||
>
|
|
||||||
<p>You are using a free model. For better results, switch to a paid model.</p>
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
)}
|
|
||||||
<Popover open={open} onOpenChange={setOpen}>
|
|
||||||
<PopoverTrigger asChild>
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
role="combobox"
|
|
||||||
aria-expanded={open}
|
|
||||||
className={cn(
|
|
||||||
"h-8 p-0 gap-0.5 text-xs border-0 bg-transparent hover:bg-transparent hover:text-foreground focus-visible:ring-0 focus-visible:ring-offset-0 text-muted-foreground text-right min-w-0"
|
|
||||||
)}
|
|
||||||
disabled={disabled}
|
|
||||||
>
|
|
||||||
<span className="truncate">
|
|
||||||
{value || placeholder || defaultPlaceholder}
|
|
||||||
</span>
|
|
||||||
<ChevronDown className="size-3 shrink-0 opacity-50" />
|
|
||||||
</Button>
|
|
||||||
</PopoverTrigger>
|
|
||||||
<PopoverContent className="p-0" align="end">
|
|
||||||
<Command>
|
|
||||||
{(isConfigured && models.length >= 5) && (
|
|
||||||
<CommandInput placeholder={t('searchModels')} className="h-9" />
|
|
||||||
)}
|
|
||||||
<CommandList className="max-h-[300px]">
|
|
||||||
<CommandEmpty>
|
|
||||||
<div className="py-6 text-center text-sm text-muted-foreground">
|
|
||||||
<p>{t('noModelsFound')}</p>
|
|
||||||
<p className="mt-2 text-xs">{t('tryCustomModel')}</p>
|
|
||||||
</div>
|
|
||||||
</CommandEmpty>
|
|
||||||
|
|
||||||
{shouldShowRecentlyUsed && (
|
{shouldShowRecentlyUsed && (
|
||||||
<CommandGroup heading={t('recentlyUsed')}>
|
<CommandGroup heading={t('recentlyUsed')}>
|
||||||
{recentlyUsedModels.map((model) => (
|
{recentlyUsedModels.map((model) => (
|
||||||
<CommandItem
|
|
||||||
key={model}
|
|
||||||
value={model}
|
|
||||||
onSelect={() => handleSelect(model)}
|
|
||||||
className="cursor-pointer"
|
|
||||||
>
|
|
||||||
<Check
|
|
||||||
className={cn(
|
|
||||||
"mr-2 h-4 w-4",
|
|
||||||
value === model ? "opacity-100" : "opacity-0"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<span className="truncate">{model}</span>
|
|
||||||
</CommandItem>
|
|
||||||
))}
|
|
||||||
</CommandGroup>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{shouldShowRecentlyUsed && <CommandSeparator />}
|
|
||||||
|
|
||||||
{/* Loading state */}
|
|
||||||
{isLoading && (
|
|
||||||
<CommandGroup heading={t('loading')}>
|
|
||||||
<div className="px-2 py-1.5">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Skeleton className="h-4 w-full" />
|
|
||||||
<Skeleton className="h-4 w-3/4" />
|
|
||||||
<Skeleton className="h-4 w-1/2" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CommandGroup>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Error state */}
|
|
||||||
{error && !isLoading && (
|
|
||||||
<CommandGroup heading={t('errorLoadingModels')}>
|
|
||||||
<div className="px-2 py-1.5 text-sm text-muted-foreground">
|
|
||||||
<div className="flex items-start gap-2">
|
|
||||||
<AlertCircle className="h-4 w-4 text-destructive flex-shrink-0 mt-0.5" />
|
|
||||||
<div className="space-y-2">
|
|
||||||
<p className="text-destructive">{error}</p>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
onClick={refetch}
|
|
||||||
className="h-7 text-xs"
|
|
||||||
>
|
|
||||||
<RefreshCw className="h-3 w-3 mr-1" />
|
|
||||||
{t('retry')}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</CommandGroup>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Provider models */}
|
|
||||||
{!isLoading && Object.entries(modelsByProvider).map(([provider, providerModels]) => (
|
|
||||||
<div key={provider}>
|
|
||||||
<CommandSeparator />
|
|
||||||
<CommandGroup heading={provider}>
|
|
||||||
{providerModels.map((model) => (
|
|
||||||
<CommandItem
|
|
||||||
key={model.fullId}
|
|
||||||
value={model.fullId}
|
|
||||||
onSelect={() => handleSelect(model.fullId)}
|
|
||||||
className="cursor-pointer"
|
|
||||||
>
|
|
||||||
<Check
|
|
||||||
className={cn(
|
|
||||||
"mr-2 h-4 w-4",
|
|
||||||
value === model.fullId ? "opacity-100" : "opacity-0"
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<span className="truncate">{model.fullId}</span>
|
|
||||||
</CommandItem>
|
|
||||||
))}
|
|
||||||
</CommandGroup>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
|
|
||||||
{/* Custom model option and manage providers - moved to bottom */}
|
|
||||||
<CommandSeparator />
|
|
||||||
<CommandGroup>
|
|
||||||
{isConfigured && (
|
|
||||||
<CommandItem
|
|
||||||
value="__custom_model_option__"
|
|
||||||
onSelect={() => handleSelect('__custom__')}
|
|
||||||
className="cursor-pointer"
|
|
||||||
>
|
|
||||||
<Edit3 className="mr-2 h-4 w-4" />
|
|
||||||
{t('enterCustomModel')}
|
|
||||||
</CommandItem>
|
|
||||||
)}
|
|
||||||
<CommandItem
|
<CommandItem
|
||||||
value="__manage_providers_option__"
|
key={model}
|
||||||
onSelect={() => handleSelect('__manage_providers__')}
|
value={model}
|
||||||
|
onSelect={() => handleSelect(model)}
|
||||||
className="cursor-pointer"
|
className="cursor-pointer"
|
||||||
>
|
>
|
||||||
<Settings className="mr-2 h-4 w-4" />
|
<Check
|
||||||
{t('manageProviders')}
|
className={cn(
|
||||||
|
"mr-2 h-4 w-4",
|
||||||
|
value === model ? "opacity-100" : "opacity-0"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<span className="truncate">{model}</span>
|
||||||
</CommandItem>
|
</CommandItem>
|
||||||
|
))}
|
||||||
|
</CommandGroup>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{shouldShowRecentlyUsed && <CommandSeparator />}
|
||||||
|
|
||||||
|
{/* Loading state */}
|
||||||
|
{isLoading && (
|
||||||
|
<CommandGroup heading={t('loading')}>
|
||||||
|
<div className="px-2 py-1.5">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-full" />
|
||||||
|
<Skeleton className="h-4 w-3/4" />
|
||||||
|
<Skeleton className="h-4 w-1/2" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CommandGroup>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Error state */}
|
||||||
|
{error && !isLoading && (
|
||||||
|
<CommandGroup heading={t('errorLoadingModels')}>
|
||||||
|
<div className="px-2 py-1.5 text-sm text-muted-foreground">
|
||||||
|
<div className="flex items-start gap-2">
|
||||||
|
<AlertCircle className="h-4 w-4 text-destructive flex-shrink-0 mt-0.5" />
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p className="text-destructive">{error}</p>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={refetch}
|
||||||
|
className="h-7 text-xs"
|
||||||
|
>
|
||||||
|
<RefreshCw className="h-3 w-3 mr-1" />
|
||||||
|
{t('retry')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CommandGroup>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Provider models */}
|
||||||
|
{!isLoading && Object.entries(modelsByProvider).map(([provider, providerModels]) => (
|
||||||
|
<div key={provider}>
|
||||||
|
<CommandSeparator />
|
||||||
|
<CommandGroup heading={provider}>
|
||||||
|
{providerModels.map((model) => (
|
||||||
|
<CommandItem
|
||||||
|
key={model.fullId}
|
||||||
|
value={model.fullId}
|
||||||
|
onSelect={() => handleSelect(model.fullId)}
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<Check
|
||||||
|
className={cn(
|
||||||
|
"mr-2 h-4 w-4",
|
||||||
|
value === model.fullId ? "opacity-100" : "opacity-0"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<span className="truncate">{model.fullId}</span>
|
||||||
|
</CommandItem>
|
||||||
|
))}
|
||||||
</CommandGroup>
|
</CommandGroup>
|
||||||
</CommandList>
|
</div>
|
||||||
</Command>
|
))}
|
||||||
</PopoverContent>
|
|
||||||
</Popover>
|
{/* Custom model option and manage providers - moved to bottom */}
|
||||||
</div>
|
<CommandSeparator />
|
||||||
</TooltipProvider>
|
<CommandGroup>
|
||||||
|
{isConfigured && (
|
||||||
|
<CommandItem
|
||||||
|
value="__custom_model_option__"
|
||||||
|
onSelect={() => handleSelect('__custom__')}
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<Edit3 className="mr-2 h-4 w-4" />
|
||||||
|
{t('enterCustomModel')}
|
||||||
|
</CommandItem>
|
||||||
|
)}
|
||||||
|
<CommandItem
|
||||||
|
value="__manage_providers_option__"
|
||||||
|
onSelect={() => handleSelect('__manage_providers__')}
|
||||||
|
className="cursor-pointer"
|
||||||
|
>
|
||||||
|
<Settings className="mr-2 h-4 w-4" />
|
||||||
|
{t('manageProviders')}
|
||||||
|
</CommandItem>
|
||||||
|
</CommandGroup>
|
||||||
|
</CommandList>
|
||||||
|
</Command>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -763,6 +763,7 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
|||||||
<ModelSelector
|
<ModelSelector
|
||||||
value={providerModel}
|
value={providerModel}
|
||||||
onChange={setProviderModel}
|
onChange={setProviderModel}
|
||||||
|
className="w-full"
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
placeholder={t('chooseModel')}
|
placeholder={t('chooseModel')}
|
||||||
open={isModelSelectorOpen}
|
open={isModelSelectorOpen}
|
||||||
|
|||||||
+1
-118
@@ -1,6 +1,5 @@
|
|||||||
import { getEsbuild } from "@/lib/esbuild";
|
import { getEsbuild } from "@/lib/esbuild";
|
||||||
import { copyFiles } from "@/lib/copyFiles";
|
import { copyFiles } from "@/lib/copyFiles";
|
||||||
import JSZip from "jszip";
|
|
||||||
|
|
||||||
import { shakespearePlugin } from "./shakespearePlugin";
|
import { shakespearePlugin } from "./shakespearePlugin";
|
||||||
import { esmPlugin } from "./esmPlugin";
|
import { esmPlugin } from "./esmPlugin";
|
||||||
@@ -89,15 +88,8 @@ export async function buildProject(options: BuildProjectOptions): Promise<{
|
|||||||
files: Record<string, Uint8Array>;
|
files: Record<string, Uint8Array>;
|
||||||
outputPath: string;
|
outputPath: string;
|
||||||
projectId?: string;
|
projectId?: string;
|
||||||
buildStats?: {
|
}> {
|
||||||
totalTime: number;
|
|
||||||
zipTime: number;
|
|
||||||
zipFileCount: number;
|
|
||||||
zipSize: number;
|
|
||||||
};
|
|
||||||
}> {
|
|
||||||
const { fs, projectPath, outputPath = `${projectPath}/dist` } = options;
|
const { fs, projectPath, outputPath = `${projectPath}/dist` } = options;
|
||||||
const buildStartTime = performance.now();
|
|
||||||
|
|
||||||
// Check if we're in a valid project directory
|
// Check if we're in a valid project directory
|
||||||
try {
|
try {
|
||||||
@@ -149,14 +141,6 @@ export async function buildProject(options: BuildProjectOptions): Promise<{
|
|||||||
// Expected format: /projects/{projectId}
|
// Expected format: /projects/{projectId}
|
||||||
const projectId = projectPath.split('/').pop();
|
const projectId = projectPath.split('/').pop();
|
||||||
|
|
||||||
// Generate source code zip for Shakespeare cloning
|
|
||||||
console.log('📦 Generating source code archive...');
|
|
||||||
const zipStartTime = performance.now();
|
|
||||||
const zipResult = await generateSourceCodeZip(fs, projectPath, outputPath);
|
|
||||||
const zipEndTime = performance.now();
|
|
||||||
const zipDuration = zipEndTime - zipStartTime;
|
|
||||||
console.log(`✅ Source code archive created: ${zipResult.fileCount} files, ${(zipResult.zipSize / 1024).toFixed(2)}KB (${zipDuration.toFixed(2)}ms)`);
|
|
||||||
|
|
||||||
// Emit build completion event for PreviewPane to listen to
|
// Emit build completion event for PreviewPane to listen to
|
||||||
if (projectId && typeof window !== 'undefined') {
|
if (projectId && typeof window !== 'undefined') {
|
||||||
const buildCompleteEvent = new CustomEvent('buildComplete', {
|
const buildCompleteEvent = new CustomEvent('buildComplete', {
|
||||||
@@ -165,20 +149,10 @@ export async function buildProject(options: BuildProjectOptions): Promise<{
|
|||||||
window.dispatchEvent(buildCompleteEvent);
|
window.dispatchEvent(buildCompleteEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
const buildEndTime = performance.now();
|
|
||||||
const totalTime = buildEndTime - buildStartTime;
|
|
||||||
console.log(`🚀 Build completed in ${totalTime.toFixed(2)}ms (${((zipDuration / totalTime) * 100).toFixed(1)}% spent on zip generation)`);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
files: dist,
|
files: dist,
|
||||||
outputPath,
|
outputPath,
|
||||||
projectId,
|
projectId,
|
||||||
buildStats: {
|
|
||||||
totalTime,
|
|
||||||
zipTime: zipDuration,
|
|
||||||
zipFileCount: zipResult.fileCount,
|
|
||||||
zipSize: zipResult.zipSize,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,94 +173,3 @@ function updateIndexHtml(doc: Document, dist: Record<string, Uint8Array>): void
|
|||||||
doc.head.appendChild(style);
|
doc.head.appendChild(style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a source code zip file containing all project files for Shakespeare cloning
|
|
||||||
*/
|
|
||||||
async function generateSourceCodeZip(fs: JSRuntimeFS, projectPath: string, outputPath: string): Promise<{ fileCount: number, zipSize: number }> {
|
|
||||||
const zip = new JSZip();
|
|
||||||
const fileCount = { count: 0 };
|
|
||||||
|
|
||||||
// Recursively add all files from project directory, excluding unwanted files
|
|
||||||
await addDirectoryToZip(fs, zip, projectPath, '', projectPath, fileCount);
|
|
||||||
|
|
||||||
// Generate and save zip directly to the dist folder
|
|
||||||
const zipBuffer = await zip.generateAsync({ type: 'uint8array' });
|
|
||||||
await fs.writeFile(`${outputPath}/sourcecode.zip`, zipBuffer);
|
|
||||||
|
|
||||||
return { fileCount: fileCount.count, zipSize: zipBuffer.length };
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Recursively add a directory and its contents to a zip file
|
|
||||||
*/
|
|
||||||
async function addDirectoryToZip(
|
|
||||||
fs: JSRuntimeFS,
|
|
||||||
zip: JSZip,
|
|
||||||
dirPath: string,
|
|
||||||
relativePath: string,
|
|
||||||
projectPath: string,
|
|
||||||
fileCount: { count: number }
|
|
||||||
): Promise<void> {
|
|
||||||
try {
|
|
||||||
const entries = await fs.readdir(dirPath);
|
|
||||||
|
|
||||||
for (const entry of entries) {
|
|
||||||
const fullEntryPath = `${dirPath}/${entry}`;
|
|
||||||
const relativeEntryPath = `${relativePath}/${entry}`;
|
|
||||||
|
|
||||||
// Skip excluded files and directories
|
|
||||||
if (shouldExcludeFromZip(entry)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const stat = await fs.stat(fullEntryPath);
|
|
||||||
|
|
||||||
if (stat.isFile()) {
|
|
||||||
const content = await fs.readFile(fullEntryPath, 'utf8');
|
|
||||||
zip.file(relativeEntryPath, content);
|
|
||||||
fileCount.count++;
|
|
||||||
} else if (stat.isDirectory()) {
|
|
||||||
await addDirectoryToZip(fs, zip, fullEntryPath, relativeEntryPath, projectPath, fileCount);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Skip files that can't be read
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
// Directory can't be read, skip it
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if a file or directory should be excluded from the source code zip
|
|
||||||
*/
|
|
||||||
function shouldExcludeFromZip(name: string): boolean {
|
|
||||||
const excludePatterns = [
|
|
||||||
'node_modules',
|
|
||||||
'dist',
|
|
||||||
'.git',
|
|
||||||
'.env',
|
|
||||||
'.env.local',
|
|
||||||
'.env.development',
|
|
||||||
'.env.production',
|
|
||||||
'sourcecode.zip', // Don't include the zip in itself
|
|
||||||
'.DS_Store',
|
|
||||||
'Thumbs.db',
|
|
||||||
'*.log',
|
|
||||||
'.vscode',
|
|
||||||
'.idea'
|
|
||||||
];
|
|
||||||
|
|
||||||
return excludePatterns.some(pattern => {
|
|
||||||
if (pattern.includes('*')) {
|
|
||||||
// Simple wildcard matching
|
|
||||||
const regex = new RegExp(pattern.replace('*', '.*'));
|
|
||||||
return regex.test(name);
|
|
||||||
}
|
|
||||||
return name === pattern;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
+73
-12
@@ -908,15 +908,16 @@ export class Git {
|
|||||||
'#d': [nostrURI.d],
|
'#d': [nostrURI.d],
|
||||||
};
|
};
|
||||||
|
|
||||||
const gitRelays = new Set<string>([
|
// Always prioritize git.shakespeare.diy
|
||||||
'wss://git.shakespeare.diy/',
|
const shakespeareRelayUrl = 'wss://git.shakespeare.diy/';
|
||||||
|
const otherGitRelays = [
|
||||||
'wss://relay.ngit.dev/',
|
'wss://relay.ngit.dev/',
|
||||||
'wss://relay.nostr.band/', // General purpose relay as fallback
|
'wss://relay.nostr.band/', // General purpose relay as fallback
|
||||||
]);
|
];
|
||||||
|
|
||||||
let events: NostrEvent[] = [];
|
let events: NostrEvent[] = [];
|
||||||
|
|
||||||
// Try the specified relay first, then fall back to known Git relays
|
// Try the specified relay first if provided
|
||||||
if (nostrURI.relay) {
|
if (nostrURI.relay) {
|
||||||
try {
|
try {
|
||||||
events = await this.nostr.relay(nostrURI.relay).query([filter], { signal: AbortSignal.timeout(1000) });
|
events = await this.nostr.relay(nostrURI.relay).query([filter], { signal: AbortSignal.timeout(1000) });
|
||||||
@@ -924,11 +925,30 @@ export class Git {
|
|||||||
console.error(`Error querying relay ${nostrURI.relay}: ${error}`);
|
console.error(`Error querying relay ${nostrURI.relay}: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no events from specified relay, try git.shakespeare.diy first
|
||||||
if (!events.length) {
|
if (!events.length) {
|
||||||
try {
|
try {
|
||||||
events = await this.nostr.group([...gitRelays]).query([filter], { signal: AbortSignal.timeout(5000) });
|
console.log(`Trying git.shakespeare.diy first...`);
|
||||||
|
events = await this.nostr.relay(shakespeareRelayUrl).query([filter], { signal: AbortSignal.timeout(3000) });
|
||||||
|
if (events.length > 0) {
|
||||||
|
console.log(`✓ Found events on ${shakespeareRelayUrl}`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error querying group relays: ${error}`);
|
console.error(`Error querying ${shakespeareRelayUrl}: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If still no events, try other git relays
|
||||||
|
if (!events.length) {
|
||||||
|
try {
|
||||||
|
console.log(`Trying other git relays: ${otherGitRelays.join(', ')}`);
|
||||||
|
events = await this.nostr.group(otherGitRelays).query([filter], { signal: AbortSignal.timeout(5000) });
|
||||||
|
if (events.length > 0) {
|
||||||
|
console.log(`✓ Found events on fallback relays`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error querying fallback relays: ${error}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!events.length) {
|
if (!events.length) {
|
||||||
@@ -1390,13 +1410,24 @@ export class Git {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure git.shakespeare.diy is always included and prioritized
|
||||||
|
const shakespeareRelay = 'wss://git.shakespeare.diy/';
|
||||||
|
|
||||||
|
// Remove git.shakespeare.diy from relayUrls if it exists (to avoid duplicates)
|
||||||
|
const filteredRelayUrls = relayUrls.filter(url => url !== shakespeareRelay);
|
||||||
|
|
||||||
|
// Always prioritize git.shakespeare.diy by putting it first
|
||||||
|
relayUrls.unshift(shakespeareRelay);
|
||||||
|
|
||||||
// If no relays specified in announcement, use default git-focused relays
|
// If no relays specified in announcement, use default git-focused relays
|
||||||
if (relayUrls.length === 0) {
|
if (filteredRelayUrls.length === 0 && relayUrls.length === 1) {
|
||||||
relayUrls.push(
|
relayUrls.push(
|
||||||
'wss://git.shakespeare.diy/',
|
|
||||||
'wss://relay.ngit.dev/',
|
'wss://relay.ngit.dev/',
|
||||||
'wss://relay.nostr.band/'
|
'wss://relay.nostr.band/'
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
// Add back the other relays after git.shakespeare.diy
|
||||||
|
relayUrls.push(...filteredRelayUrls);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get current repository state
|
// Get current repository state
|
||||||
@@ -1417,12 +1448,42 @@ export class Git {
|
|||||||
// Publish the state event to Nostr relays
|
// Publish the state event to Nostr relays
|
||||||
console.log(`Publishing repository state to ${relayUrls.length} relays`);
|
console.log(`Publishing repository state to ${relayUrls.length} relays`);
|
||||||
|
|
||||||
|
// Always publish to git.shakespeare.diy first
|
||||||
|
const shakespeareRelayUrl = 'wss://git.shakespeare.diy/';
|
||||||
|
const otherRelays = relayUrls.filter(url => url !== shakespeareRelayUrl);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.nostr.group(relayUrls).event(stateEvent);
|
// Publish to git.shakespeare.diy first
|
||||||
console.log('✓ Repository state published to Nostr successfully');
|
console.log(`Publishing to ${shakespeareRelayUrl} first...`);
|
||||||
|
await this.nostr.relay(shakespeareRelayUrl).event(stateEvent);
|
||||||
|
console.log(`✓ Repository state published to ${shakespeareRelayUrl} successfully`);
|
||||||
|
|
||||||
|
// Then publish to other relays
|
||||||
|
if (otherRelays.length > 0) {
|
||||||
|
console.log(`Publishing to ${otherRelays.length} additional relays...`);
|
||||||
|
try {
|
||||||
|
await this.nostr.group(otherRelays).event(stateEvent);
|
||||||
|
console.log('✓ Repository state published to additional relays successfully');
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to publish repository state to some additional relays:', error);
|
||||||
|
// Continue even if publishing to additional relays fails
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✓ Nostr push completed successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.warn('Failed to publish repository state to some relays:', error);
|
console.error('Failed to publish repository state to git.shakespeare.diy:', error);
|
||||||
// Continue with Git push even if Nostr publishing partially fails
|
// If git.shakespeare.diy fails, still try to publish to other relays as fallback
|
||||||
|
if (otherRelays.length > 0) {
|
||||||
|
console.log(`Attempting to publish to ${otherRelays.length} fallback relays...`);
|
||||||
|
try {
|
||||||
|
await this.nostr.group(otherRelays).event(stateEvent);
|
||||||
|
console.log('✓ Repository state published to fallback relays successfully');
|
||||||
|
} catch (fallbackError) {
|
||||||
|
console.warn('Failed to publish repository state to fallback relays:', fallbackError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Don't throw here - continue with Git push even if Nostr publishing fails
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push to each clone URL
|
// Push to each clone URL
|
||||||
|
|||||||
Reference in new issue
Block a user