mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Move project templates to AI settings
This commit is contained in:
6 files changed
+239
-158
No files matched your search
@@ -0,0 +1,218 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { FileCode2, Trash2, Plus } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
|
||||
interface ProjectTemplate {
|
||||
name: string;
|
||||
description: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export function ProjectTemplatesSection() {
|
||||
const { t } = useTranslation();
|
||||
const { config, updateConfig } = useAppContext();
|
||||
const { toast } = useToast();
|
||||
const [newTemplateName, setNewTemplateName] = useState('');
|
||||
const [newTemplateDescription, setNewTemplateDescription] = useState('');
|
||||
const [newTemplateUrl, setNewTemplateUrl] = useState('');
|
||||
|
||||
const templates = config.templates || [];
|
||||
|
||||
const handleAddTemplate = () => {
|
||||
if (!newTemplateName.trim() || !newTemplateDescription.trim() || !newTemplateUrl.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newTemplate: ProjectTemplate = {
|
||||
name: newTemplateName.trim(),
|
||||
description: newTemplateDescription.trim(),
|
||||
url: newTemplateUrl.trim(),
|
||||
};
|
||||
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
templates: [...(current.templates || []), newTemplate],
|
||||
}));
|
||||
|
||||
toast({
|
||||
title: t('templateAdded'),
|
||||
description: t('templateAddedDescription', { name: newTemplateName.trim() }),
|
||||
});
|
||||
|
||||
setNewTemplateName('');
|
||||
setNewTemplateDescription('');
|
||||
setNewTemplateUrl('');
|
||||
};
|
||||
|
||||
const handleRemoveTemplate = (index: number) => {
|
||||
const templateName = templates[index]?.name || 'template';
|
||||
const newTemplates = templates.filter((_, i) => i !== index);
|
||||
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
templates: newTemplates,
|
||||
}));
|
||||
|
||||
toast({
|
||||
title: t('templateDeleted'),
|
||||
description: t('templateDeletedDescription', { name: templateName }),
|
||||
});
|
||||
};
|
||||
|
||||
const handleUpdateTemplate = (index: number, updatedTemplate: ProjectTemplate) => {
|
||||
const newTemplates = [...templates];
|
||||
newTemplates[index] = updatedTemplate;
|
||||
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
templates: newTemplates,
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Divider */}
|
||||
<Separator className="my-6" />
|
||||
|
||||
{/* Project Templates Header */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<FileCode2 className="h-5 w-5 text-primary" />
|
||||
<h3 className="text-lg font-semibold">{t('projectTemplates')}</h3>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('projectTemplatesDescription')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Configured Templates List */}
|
||||
{templates.length > 0 ? (
|
||||
<div className="space-y-2">
|
||||
{templates.map((template, index) => (
|
||||
<Accordion key={index} type="single" collapsible className="w-full">
|
||||
<AccordionItem value={`template-${index}`} className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2 w-full mr-3">
|
||||
<FileCode2 size={16} className="text-primary" />
|
||||
<span className="font-medium">{template.name}</span>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`template-name-${index}`}>{t('templateName')}</Label>
|
||||
<Input
|
||||
id={`template-name-${index}`}
|
||||
placeholder="MKStack"
|
||||
value={template.name}
|
||||
onChange={(e) => handleUpdateTemplate(index, { ...template, name: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`template-description-${index}`}>{t('templateDescription')}</Label>
|
||||
<Textarea
|
||||
id={`template-description-${index}`}
|
||||
placeholder="Build Nostr clients with React."
|
||||
value={template.description}
|
||||
onChange={(e) => handleUpdateTemplate(index, { ...template, description: e.target.value })}
|
||||
className="min-h-[80px]"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`template-url-${index}`}>{t('templateGitUrl')}</Label>
|
||||
<Input
|
||||
id={`template-url-${index}`}
|
||||
type="url"
|
||||
placeholder="https://gitlab.com/soapbox-pub/mkstack.git"
|
||||
value={template.url}
|
||||
onChange={(e) => handleUpdateTemplate(index, { ...template, url: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
onClick={() => handleRemoveTemplate(index)}
|
||||
disabled={templates.length === 1}
|
||||
title={templates.length === 1 ? t('atLeastOneTemplateRequired') : t('delete')}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
{t('delete')}
|
||||
</Button>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<Alert>
|
||||
<AlertDescription className="text-sm">
|
||||
{t('noTemplatesConfigured')}
|
||||
</AlertDescription>
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{/* Add New Template */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="add-template">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
<span className="text-sm font-medium">{t('addProjectTemplate')}</span>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="new-template-name">{t('templateName')}</Label>
|
||||
<Input
|
||||
id="new-template-name"
|
||||
placeholder="MKStack"
|
||||
value={newTemplateName}
|
||||
onChange={(e) => setNewTemplateName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="new-template-description">{t('templateDescription')}</Label>
|
||||
<Textarea
|
||||
id="new-template-description"
|
||||
placeholder="Build Nostr clients with React."
|
||||
value={newTemplateDescription}
|
||||
onChange={(e) => setNewTemplateDescription(e.target.value)}
|
||||
className="min-h-[80px]"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="new-template-url">{t('templateGitUrl')}</Label>
|
||||
<Input
|
||||
id="new-template-url"
|
||||
type="url"
|
||||
placeholder="https://gitlab.com/soapbox-pub/mkstack.git"
|
||||
value={newTemplateUrl}
|
||||
onChange={(e) => setNewTemplateUrl(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleAddTemplate}
|
||||
disabled={!newTemplateName.trim() || !newTemplateDescription.trim() || !newTemplateUrl.trim()}
|
||||
className="gap-2 w-full"
|
||||
>
|
||||
<Plus className="h-4 w-4" />
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+1
-10
@@ -291,15 +291,6 @@ describe('makeSystemPrompt', () => {
|
||||
});
|
||||
|
||||
describe('CORS proxy section', () => {
|
||||
it('should not include CORS proxy section when not provided', async () => {
|
||||
const result = await makeSystemPrompt({
|
||||
...baseOpts,
|
||||
config: { ...testConfig, corsProxy: '' },
|
||||
});
|
||||
|
||||
expect(result).not.toContain('## Working Around CORS Issues');
|
||||
});
|
||||
|
||||
it('should include CORS proxy information when provided', async () => {
|
||||
const result = await makeSystemPrompt(baseOpts);
|
||||
|
||||
@@ -582,7 +573,7 @@ Skills: {{ skills.length }}`;
|
||||
expect(result).toContain('**MKStack**');
|
||||
expect(result).toContain('Build Nostr clients with React.');
|
||||
expect(result).toContain('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
expect(result).toContain('Settings > System');
|
||||
expect(result).toContain('Settings > AI');
|
||||
});
|
||||
|
||||
it('should highlight current template when it matches a configured template', async () => {
|
||||
|
||||
+4
-4
@@ -36,9 +36,9 @@ You are operating within **Shakespeare**, an AI-powered website builder that all
|
||||
- **Current Page**: {{ location.href }}
|
||||
- **Current Working Directory**: {{ cwd }}
|
||||
- **Repository URL**: {% if repositoryUrl %}{{ repositoryUrl }}{% else %}none{% endif %}
|
||||
- **Project Template**: {% if projectTemplate %}{{ projectTemplate.name }}{% else %}unknown{% endif %}
|
||||
{% if projectTemplate %}- **Project Template**: {{ projectTemplate.name }}{% endif %}
|
||||
|
||||
Users can add or remove templates in Settings > System (\`{{ location.origin }}/settings/system\`).
|
||||
Users can add or remove templates in Settings > AI (\`{{ location.origin }}/settings/ai\`).
|
||||
|
||||
## What Shakespeare Is
|
||||
|
||||
@@ -91,12 +91,12 @@ The Shakespeare interface consists of several key areas:
|
||||
|
||||
4. **Settings** (\`/settings\`): Accessible from the sidebar menu, includes:
|
||||
- **Preferences** (\`/settings/preferences\`): Theme and language settings
|
||||
- **AI Settings** (\`/settings/ai\`): Configure AI providers and API keys
|
||||
- **AI Settings** (\`/settings/ai\`): Configure AI providers, API keys, project templates, MCP servers, and plugins
|
||||
- **Git Settings** (\`/settings/git\`): Configure Git credentials for version control
|
||||
- **Deploy Settings** (\`/settings/deploy\`): Configure deployment providers (Shakespeare, Netlify, Vercel, nsite)
|
||||
- **Nostr Settings** (\`/settings/nostr\`): Manage Nostr accounts, relay connections, and ngit servers
|
||||
- **Storage Settings** (\`/settings/storage\`): Export/import project files, manage browser storage
|
||||
- **System Settings** (\`/settings/system\`): Advanced configuration (project template, ESM CDN, CORS proxy, etc.)
|
||||
- **System Settings** (\`/settings/system\`): Advanced configuration (ESM CDN, CORS proxy, service worker, etc.)
|
||||
- **About** (\`/settings/about\`): License information and project details
|
||||
|
||||
## User Actions
|
||||
|
||||
+11
-1
@@ -513,5 +513,15 @@
|
||||
"templateUpdateFailedDescription": "Failed to update the project template from the remote repository. Using the cached version instead.",
|
||||
"templatesDirectory": "Templates Directory",
|
||||
"templatesDirectoryDescription": "Directory where project templates are cached in the virtual filesystem.",
|
||||
"terminal": "Terminal"
|
||||
"terminal": "Terminal",
|
||||
"templateName": "Template Name",
|
||||
"templateDescription": "Description",
|
||||
"templateGitUrl": "Git URL",
|
||||
"addProjectTemplate": "Add Project Template",
|
||||
"templateAdded": "Template Added",
|
||||
"templateAddedDescription": "Project template '{{name}}' has been added successfully.",
|
||||
"templateDeleted": "Template Deleted",
|
||||
"templateDeletedDescription": "Project template '{{name}}' has been deleted.",
|
||||
"noTemplatesConfigured": "No project templates configured yet. Add a template to get started.",
|
||||
"atLeastOneTemplateRequired": "At least one template is required"
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPreset
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
import { MCPServersSection } from '@/components/MCPServersSection';
|
||||
import { PluginsSection } from '@/components/PluginsSection';
|
||||
import { ProjectTemplatesSection } from '@/components/ProjectTemplatesSection';
|
||||
|
||||
interface SortableProviderItemProps {
|
||||
provider: AIProvider;
|
||||
@@ -570,6 +571,9 @@ export function AISettings() {
|
||||
</Accordion>
|
||||
</div>
|
||||
|
||||
{/* Project Templates Section */}
|
||||
<ProjectTemplatesSection />
|
||||
|
||||
{/* MCP Servers Section */}
|
||||
<MCPServersSection />
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw, Plus } from "lucide-react";
|
||||
import { Settings, ArrowLeft, RefreshCw, Trash2, XCircle, Loader2, RotateCcw } from "lucide-react";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -23,7 +23,6 @@ export function SystemSettings() {
|
||||
const { toast } = useToast();
|
||||
const { serviceWorkerRegistration, updateServiceWorker, clearCache } = useOffline();
|
||||
|
||||
const [templatesInput, setTemplatesInput] = useState(config.templates);
|
||||
const [esmUrlInput, setEsmUrlInput] = useState(config.esmUrl);
|
||||
const [corsProxyInput, setCorsProxyInput] = useState(config.corsProxy);
|
||||
const [faviconUrlInput, setFaviconUrlInput] = useState(config.faviconUrl);
|
||||
@@ -39,7 +38,6 @@ export function SystemSettings() {
|
||||
|
||||
// Check which settings differ from defaults
|
||||
const isModified = useMemo(() => ({
|
||||
templates: JSON.stringify(config.templates) !== JSON.stringify(defaultConfig.templates),
|
||||
esmUrl: config.esmUrl !== defaultConfig.esmUrl,
|
||||
corsProxy: config.corsProxy !== defaultConfig.corsProxy,
|
||||
faviconUrl: config.faviconUrl !== defaultConfig.faviconUrl,
|
||||
@@ -56,15 +54,6 @@ export function SystemSettings() {
|
||||
}), [config, defaultConfig]);
|
||||
|
||||
// Restore functions - clear the value from config to use the default
|
||||
const restoreTemplates = () => {
|
||||
const defaultValue = defaultConfig.templates;
|
||||
setTemplatesInput(defaultValue);
|
||||
updateConfig((current) => {
|
||||
const { templates, ...rest } = current;
|
||||
return rest;
|
||||
});
|
||||
};
|
||||
|
||||
const restoreEsmUrl = () => {
|
||||
const defaultValue = defaultConfig.esmUrl;
|
||||
setEsmUrlInput(defaultValue);
|
||||
@@ -409,137 +398,6 @@ export function SystemSettings() {
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* Project Templates Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="project-templates">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<h4 className="text-sm font-medium">{t('projectTemplates')}</h4>
|
||||
{isModified.templates && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="py-1 space-y-4">
|
||||
{templatesInput.map((template, index) => (
|
||||
<div key={index} className="space-y-2 p-3 border rounded-lg">
|
||||
<div className="space-y-2">
|
||||
<div>
|
||||
<Label htmlFor={`template-name-${index}`} className="text-xs">Name</Label>
|
||||
<Input
|
||||
id={`template-name-${index}`}
|
||||
type="text"
|
||||
placeholder="MKStack"
|
||||
value={template.name}
|
||||
onChange={(e) => {
|
||||
const newTemplates = [...templatesInput];
|
||||
newTemplates[index] = { ...template, name: e.target.value };
|
||||
setTemplatesInput(newTemplates);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
templates: newTemplates,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor={`template-description-${index}`} className="text-xs">Description</Label>
|
||||
<Textarea
|
||||
id={`template-description-${index}`}
|
||||
placeholder="Build Nostr clients with React."
|
||||
value={template.description}
|
||||
onChange={(e) => {
|
||||
const newTemplates = [...templatesInput];
|
||||
newTemplates[index] = { ...template, description: e.target.value };
|
||||
setTemplatesInput(newTemplates);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
templates: newTemplates,
|
||||
}));
|
||||
}}
|
||||
className="min-h-[80px]"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<Label htmlFor={`template-url-${index}`} className="text-xs">Git URL</Label>
|
||||
<Input
|
||||
id={`template-url-${index}`}
|
||||
type="url"
|
||||
placeholder="https://gitlab.com/soapbox-pub/mkstack.git"
|
||||
value={template.url}
|
||||
onChange={(e) => {
|
||||
const newTemplates = [...templatesInput];
|
||||
newTemplates[index] = { ...template, url: e.target.value };
|
||||
setTemplatesInput(newTemplates);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
templates: newTemplates,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
const newTemplates = templatesInput.filter((_, i) => i !== index);
|
||||
setTemplatesInput(newTemplates);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
templates: newTemplates,
|
||||
}));
|
||||
}}
|
||||
disabled={templatesInput.length === 1}
|
||||
title={templatesInput.length === 1 ? "At least one template is required" : "Remove template"}
|
||||
className="w-full"
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
Remove Template
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => {
|
||||
const newTemplates = [
|
||||
...templatesInput,
|
||||
{ name: '', description: '', url: '' }
|
||||
];
|
||||
setTemplatesInput(newTemplates);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
templates: newTemplates,
|
||||
}));
|
||||
}}
|
||||
className="w-full"
|
||||
>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
Add Template
|
||||
</Button>
|
||||
{isModified.templates && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={restoreTemplates}
|
||||
title={t('restoreToDefault')}
|
||||
>
|
||||
<RotateCcw className="h-4 w-4 mr-2" />
|
||||
Reset
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('projectTemplatesDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* CORS Proxy Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="cors-proxy">
|
||||
|
||||
Reference in new issue
Block a user