mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-04 08:13:34 +00:00
Compare commits
15
Commits
anthropicGetFix
...
webpm
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b22a19e6e | ||
|
|
71f82ed717 | ||
|
|
2e68c54dbe | ||
|
|
33a1747a65 | ||
|
|
7fdf69599b | ||
|
|
808ccb9266 | ||
|
|
e0e210bce9 | ||
|
|
47b1dd23d3 | ||
|
|
1093d6df85 | ||
|
|
547a879414 | ||
|
|
8fa8493c82 | ||
|
|
1ef60bf507 | ||
|
|
6c3c3d9d6d | ||
|
|
5d09b68843 | ||
|
|
17898607d1 |
No files matched your search
@@ -10,6 +10,7 @@
|
||||
<meta property="og:type" content="website">
|
||||
<meta property="og:title" content="Shakespeare - Open Source AI Builder">
|
||||
<meta property="og:description" content="Build custom apps with AI assistance using Shakespeare, an open-source development environment">
|
||||
<meta property="og:image" content="https://shakespeare.diy/og-image.png">
|
||||
<meta http-equiv="content-security-policy" content="default-src 'none'; script-src 'self' 'wasm-unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-src 'self' https:; font-src 'self'; base-uri 'self'; manifest-src 'self'; connect-src 'self' blob: https: http: wss: ws:; img-src 'self' data: blob: https:; media-src 'self' https:">
|
||||
<link rel="icon" type="image/png" href="/shakespeare-192x192.png">
|
||||
<link rel="apple-touch-icon" href="/shakespeare-192x192.png" sizes="192x192">
|
||||
|
||||
Generated
+1258
-73
File diff suppressed because it is too large.
Load diff
+6
-1
@@ -17,7 +17,6 @@
|
||||
"@fontsource-variable/inter": "^5.2.6",
|
||||
"@getalby/sdk": "^6.0.1",
|
||||
"@hookform/resolvers": "^3.9.0",
|
||||
"@icons-pack/react-simple-icons": "^13.8.0",
|
||||
"@isomorphic-git/lightning-fs": "^4.6.2",
|
||||
"@mozilla/readability": "^0.6.0",
|
||||
"@nostrify/nostrify": "npm:@jsr/nostrify__nostrify@^0.46.5",
|
||||
@@ -53,6 +52,8 @@
|
||||
"@tanstack/react-query": "^5.56.2",
|
||||
"@unhead/addons": "^2.0.10",
|
||||
"@unhead/react": "^2.0.10",
|
||||
"@webpm/store": "file:../webpm/packages/store",
|
||||
"@webpm/webpm": "file:../webpm/packages/webpm",
|
||||
"buffer": "^6.0.3",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
@@ -60,6 +61,7 @@
|
||||
"decimal.js": "^10.6.0",
|
||||
"embla-carousel-react": "^8.3.0",
|
||||
"esbuild-wasm": "^0.25.8",
|
||||
"fflate": "^0.8.2",
|
||||
"i18next": "^25.5.2",
|
||||
"ignore": "^7.0.5",
|
||||
"input-otp": "^1.2.4",
|
||||
@@ -67,6 +69,7 @@
|
||||
"jsonc-parser": "^3.3.1",
|
||||
"jszip": "^3.10.1",
|
||||
"lucide-react": "^0.525.0",
|
||||
"mime": "^4.1.0",
|
||||
"nostr-tools": "^2.15.2",
|
||||
"openai": "^5.15.0",
|
||||
"path-browserify": "^1.0.1",
|
||||
@@ -86,10 +89,12 @@
|
||||
"tailwind-merge": "^2.5.2",
|
||||
"tailwindcss-animate": "^1.0.7",
|
||||
"tailwindcss-safe-area": "^0.8.0",
|
||||
"tar-stream": "^3.1.7",
|
||||
"turndown": "^7.2.1",
|
||||
"uri-templates": "^0.2.0",
|
||||
"use-stick-to-bottom": "^1.1.1",
|
||||
"vaul": "^0.9.3",
|
||||
"vite-plugin-node-polyfills": "^0.24.0",
|
||||
"webln": "^0.3.2",
|
||||
"zod": "^3.25.76"
|
||||
},
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
@@ -46,6 +46,7 @@ const defaultConfig: AppConfig = {
|
||||
projectTemplate: "https://gitlab.com/soapbox-pub/mkstack.git",
|
||||
esmUrl: "https://esm.shakespeare.diy",
|
||||
corsProxy: "https://proxy.shakespeare.diy/?url={href}",
|
||||
faviconUrl: "https://external-content.duckduckgo.com/ip3/{hostname}.ico",
|
||||
previewDomain: "local-shakespeare.dev",
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc",
|
||||
|
||||
@@ -21,6 +21,7 @@ const AppConfigSchema = z.object({
|
||||
projectTemplate: z.string().url(),
|
||||
esmUrl: z.string().url(),
|
||||
corsProxy: z.string().url(),
|
||||
faviconUrl: z.string().url(),
|
||||
previewDomain: z.string().min(1),
|
||||
language: z.string(),
|
||||
showcaseEnabled: z.boolean(),
|
||||
|
||||
+109
-11
@@ -1,7 +1,7 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Rocket, ExternalLink, AlertCircle } from 'lucide-react';
|
||||
import { SiNetlify, SiVercel } from '@icons-pack/react-simple-icons';
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
@@ -25,12 +25,64 @@ import { useProjectDeploySettings } from '@/hooks/useProjectDeploySettings';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, DeployAdapter } from '@/lib/deploy';
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { ShakespeareAdapter, NetlifyAdapter, VercelAdapter, NsiteAdapter, DeployAdapter } from '@/lib/deploy';
|
||||
import { Link } from 'react-router-dom';
|
||||
import type { ShakespeareDeployProvider, NetlifyProvider, VercelProvider } from '@/contexts/DeploySettingsContext';
|
||||
import type { DeployProvider, ShakespeareDeployProvider, NetlifyProvider, VercelProvider } from '@/contexts/DeploySettingsContext';
|
||||
import { ShakespeareDeployForm } from '@/components/deploy/ShakespeareDeployForm';
|
||||
import { NetlifyDeployForm } from '@/components/deploy/NetlifyDeployForm';
|
||||
import { VercelDeployForm } from '@/components/deploy/VercelDeployForm';
|
||||
import { NsiteDeployForm } from '@/components/deploy/NsiteDeployForm';
|
||||
|
||||
/**
|
||||
* Helper function to get provider URL for favicon
|
||||
*/
|
||||
function getProviderUrl(provider: DeployProvider): string | null {
|
||||
switch (provider.type) {
|
||||
case 'shakespeare':
|
||||
if (provider.host) {
|
||||
return `https://${provider.host}`;
|
||||
}
|
||||
return 'https://shakespeare.diy';
|
||||
|
||||
case 'netlify':
|
||||
if (provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://netlify.com';
|
||||
|
||||
case 'vercel':
|
||||
if (provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://vercel.com';
|
||||
|
||||
case 'nsite':
|
||||
return null;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render provider icon using favicon or fallback
|
||||
*/
|
||||
function renderProviderIcon(provider: DeployProvider, size = 14) {
|
||||
const url = getProviderUrl(provider);
|
||||
|
||||
if (url) {
|
||||
return (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={size}
|
||||
fallback={<Rocket size={size} />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Rocket size={size} />;
|
||||
}
|
||||
|
||||
interface DeployDialogProps {
|
||||
projectId: string;
|
||||
@@ -43,6 +95,10 @@ interface ShakespeareFormData {
|
||||
subdomain: string;
|
||||
}
|
||||
|
||||
interface NsiteFormData {
|
||||
nsec: string;
|
||||
}
|
||||
|
||||
interface NetlifyFormData {
|
||||
siteId: string;
|
||||
siteName: string;
|
||||
@@ -60,6 +116,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
const { user } = useCurrentUser();
|
||||
const { fs } = useFS();
|
||||
const { config } = useAppContext();
|
||||
const { nostr } = useNostr();
|
||||
|
||||
const [selectedProviderId, setSelectedProviderId] = useState<string>('');
|
||||
const [isDeploying, setIsDeploying] = useState(false);
|
||||
@@ -70,6 +127,9 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
const [shakespeareForm, setShakespeareForm] = useState<ShakespeareFormData>({
|
||||
subdomain: projectId,
|
||||
});
|
||||
const [nsiteForm, setNsiteForm] = useState<NsiteFormData>({
|
||||
nsec: '',
|
||||
});
|
||||
const [netlifyForm, setNetlifyForm] = useState<NetlifyFormData>({
|
||||
siteId: '',
|
||||
siteName: '',
|
||||
@@ -122,6 +182,21 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
subdomain: shakespeareForm.subdomain || undefined,
|
||||
corsProxy: shakespeareProvider.proxy ? config.corsProxy : undefined,
|
||||
});
|
||||
} else if (selectedProvider.type === 'nsite') {
|
||||
const nsiteProvider = selectedProvider as import('@/contexts/DeploySettingsContext').NsiteProvider;
|
||||
|
||||
if (!nsiteForm.nsec) {
|
||||
throw new Error('Site private key (nsec) is required');
|
||||
}
|
||||
|
||||
adapter = new NsiteAdapter({
|
||||
fs,
|
||||
nostr,
|
||||
nsec: nsiteForm.nsec,
|
||||
gateway: nsiteProvider.gateway,
|
||||
relayUrls: nsiteProvider.relayUrls,
|
||||
blossomServers: nsiteProvider.blossomServers,
|
||||
});
|
||||
} else if (selectedProvider.type === 'netlify') {
|
||||
const netlifyProvider = selectedProvider as NetlifyProvider;
|
||||
if (!netlifyProvider.apiKey) {
|
||||
@@ -169,6 +244,13 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
subdomain: shakespeareForm.subdomain || undefined,
|
||||
},
|
||||
});
|
||||
} else if (selectedProvider.type === 'nsite') {
|
||||
await updateProjectSettings(selectedProviderId, {
|
||||
type: 'nsite',
|
||||
data: {
|
||||
nsec: nsiteForm.nsec,
|
||||
},
|
||||
});
|
||||
} else if (selectedProvider.type === 'netlify') {
|
||||
await updateProjectSettings(selectedProviderId, {
|
||||
type: 'netlify',
|
||||
@@ -200,6 +282,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
setError(null);
|
||||
// Reset forms
|
||||
setShakespeareForm({ subdomain: projectId });
|
||||
setNsiteForm({ nsec: '' });
|
||||
setNetlifyForm({ siteId: '', siteName: '' });
|
||||
setVercelForm({ projectName: projectName || projectId, teamId: '' });
|
||||
onOpenChange(false);
|
||||
@@ -209,6 +292,10 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
setShakespeareForm({ subdomain });
|
||||
}, []);
|
||||
|
||||
const handleNsiteNsecChange = useCallback((nsec: string) => {
|
||||
setNsiteForm({ nsec });
|
||||
}, []);
|
||||
|
||||
const handleNetlifySiteChange = useCallback((siteId: string, siteName: string) => {
|
||||
setNetlifyForm({ siteId, siteName });
|
||||
}, []);
|
||||
@@ -232,20 +319,32 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
);
|
||||
}
|
||||
|
||||
if (selectedProvider.type === 'nsite') {
|
||||
const savedConfig = projectSettings.providers[selectedProviderId];
|
||||
const savedNsec = savedConfig?.type === 'nsite' ? savedConfig.data.nsec : undefined;
|
||||
|
||||
return (
|
||||
<NsiteDeployForm
|
||||
gateway={selectedProvider.gateway}
|
||||
savedNsec={savedNsec}
|
||||
onNsecChange={handleNsiteNsecChange}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (selectedProvider.type === 'netlify') {
|
||||
const netlifyProvider = selectedProvider as NetlifyProvider;
|
||||
const savedConfig = projectSettings.providers[selectedProviderId];
|
||||
const savedSiteId = savedConfig?.type === 'netlify' ? savedConfig.data.siteId : undefined;
|
||||
|
||||
return (
|
||||
<NetlifyDeployForm
|
||||
apiKey={netlifyProvider.apiKey}
|
||||
baseURL={netlifyProvider.baseURL}
|
||||
apiKey={selectedProvider.apiKey}
|
||||
baseURL={selectedProvider.baseURL}
|
||||
projectId={projectId}
|
||||
projectName={projectName}
|
||||
savedSiteId={savedSiteId}
|
||||
onSiteChange={handleNetlifySiteChange}
|
||||
corsProxy={netlifyProvider.proxy ? config.corsProxy : undefined}
|
||||
corsProxy={selectedProvider.proxy ? config.corsProxy : undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -339,8 +438,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
<SelectTrigger id="provider">
|
||||
{selectedProvider ? (
|
||||
<div className="flex items-center gap-2">
|
||||
{selectedProvider.id === 'netlify' && <SiNetlify size={14} />}
|
||||
{selectedProvider.id === 'vercel' && <SiVercel size={14} />}
|
||||
{renderProviderIcon(selectedProvider, 14)}
|
||||
<span>{selectedProvider.name}</span>
|
||||
</div>
|
||||
) : (
|
||||
@@ -351,8 +449,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
{settings.providers.map((provider) => (
|
||||
<SelectItem key={provider.id} value={provider.id}>
|
||||
<div className="flex items-center gap-2">
|
||||
{provider.id === 'netlify' && <SiNetlify size={14} />}
|
||||
{provider.id === 'vercel' && <SiVercel size={14} />}
|
||||
{renderProviderIcon(provider, 14)}
|
||||
<span>{provider.name}</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
@@ -396,6 +493,7 @@ export function DeployDialog({ projectId, projectName, open, onOpenChange }: Dep
|
||||
!selectedProvider ||
|
||||
isDeploying ||
|
||||
(selectedProvider.type === 'shakespeare' && !user) ||
|
||||
(selectedProvider.type === 'nsite' && !nsiteForm.nsec) ||
|
||||
(selectedProvider.type === 'netlify' && !netlifyForm.siteId && !netlifyForm.siteName)
|
||||
}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { faviconUrl, normalizeUrl } from '@/lib/faviconUrl';
|
||||
import { ReactNode } from 'react';
|
||||
|
||||
interface ExternalFaviconProps {
|
||||
/** The URL to fetch the favicon for */
|
||||
url: string;
|
||||
/** Size of the favicon in pixels */
|
||||
size?: number;
|
||||
/** Fallback element to display if favicon fails to load */
|
||||
fallback?: ReactNode;
|
||||
/** Additional CSS classes */
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* ExternalFavicon component that fetches and displays a favicon for a given URL
|
||||
* using the configurable favicon service from app settings.
|
||||
*/
|
||||
export function ExternalFavicon({
|
||||
url,
|
||||
size = 16,
|
||||
fallback,
|
||||
className = '',
|
||||
}: ExternalFaviconProps) {
|
||||
const { config } = useAppContext();
|
||||
|
||||
// Normalize the URL to ensure it has a protocol
|
||||
const normalizedUrl = normalizeUrl(url);
|
||||
|
||||
// Generate the favicon URL using the configured template
|
||||
const faviconSrc = faviconUrl(config.faviconUrl, normalizedUrl);
|
||||
|
||||
return (
|
||||
<span className={`inline-flex items-center justify-center ${className}`}>
|
||||
<img
|
||||
src={faviconSrc}
|
||||
alt=""
|
||||
className="object-contain"
|
||||
style={{ width: size, height: size }}
|
||||
onError={(e) => {
|
||||
// Hide the image and show the fallback on error
|
||||
e.currentTarget.style.display = 'none';
|
||||
const fallbackElement = e.currentTarget.nextElementSibling as HTMLElement;
|
||||
if (fallbackElement) {
|
||||
fallbackElement.style.display = 'inline-block';
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{fallback && (
|
||||
<span style={{ display: 'none' }}>
|
||||
{fallback}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
import { useState, useEffect, useRef } from 'react';
|
||||
import { generateSecretKey, getPublicKey } from 'nostr-tools/pure';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { PasswordInput } from '@/components/ui/password-input';
|
||||
import { RefreshCw } from 'lucide-react';
|
||||
|
||||
interface NsiteDeployFormProps {
|
||||
gateway: string;
|
||||
savedNsec?: string;
|
||||
onNsecChange: (nsec: string) => void;
|
||||
}
|
||||
|
||||
export function NsiteDeployForm({
|
||||
gateway,
|
||||
savedNsec,
|
||||
onNsecChange,
|
||||
}: NsiteDeployFormProps) {
|
||||
const [nsec, setNsec] = useState(savedNsec || '');
|
||||
const [npub, setNpub] = useState('');
|
||||
const initialized = useRef(false);
|
||||
|
||||
// Initialize nsec on mount
|
||||
useEffect(() => {
|
||||
if (!initialized.current) {
|
||||
initialized.current = true;
|
||||
if (savedNsec) {
|
||||
// If we have a saved nsec, notify parent immediately
|
||||
onNsecChange(savedNsec);
|
||||
} else if (!nsec) {
|
||||
// Generate a new nsec if none exists
|
||||
const sk = generateSecretKey();
|
||||
const newNsec = nip19.nsecEncode(sk);
|
||||
setNsec(newNsec);
|
||||
onNsecChange(newNsec);
|
||||
}
|
||||
}
|
||||
}, [savedNsec, nsec, onNsecChange]);
|
||||
|
||||
// Update npub when nsec changes
|
||||
useEffect(() => {
|
||||
if (nsec) {
|
||||
try {
|
||||
const decoded = nip19.decode(nsec);
|
||||
if (decoded.type === 'nsec') {
|
||||
const pk = getPublicKey(decoded.data);
|
||||
const npubEncoded = nip19.npubEncode(pk);
|
||||
setNpub(npubEncoded);
|
||||
}
|
||||
} catch {
|
||||
setNpub('');
|
||||
}
|
||||
}
|
||||
}, [nsec]);
|
||||
|
||||
const handleNsecChange = (value: string) => {
|
||||
setNsec(value);
|
||||
onNsecChange(value);
|
||||
};
|
||||
|
||||
const handleGenerateNew = () => {
|
||||
const sk = generateSecretKey();
|
||||
const newNsec = nip19.nsecEncode(sk);
|
||||
setNsec(newNsec);
|
||||
onNsecChange(newNsec);
|
||||
};
|
||||
|
||||
const fullDomain = npub ? `${npub}.${gateway}` : `npub1...${gateway}`;
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Site URL</Label>
|
||||
<p className="text-sm font-mono bg-muted p-2 rounded-md break-all">
|
||||
{fullDomain}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Each site has a unique Nostr keypair
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="nsite-nsec">Site Private Key (nsec)</Label>
|
||||
<div className="flex gap-2">
|
||||
<PasswordInput
|
||||
id="nsite-nsec"
|
||||
value={nsec}
|
||||
onChange={(e) => handleNsecChange(e.target.value)}
|
||||
placeholder="nsec1..."
|
||||
className="flex-1"
|
||||
/>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={handleGenerateNew}
|
||||
title="Generate new key"
|
||||
>
|
||||
<RefreshCw className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Keep this private key secure. It's used to sign site metadata.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export { ShakespeareDeployForm } from './ShakespeareDeployForm';
|
||||
export { NetlifyDeployForm } from './NetlifyDeployForm';
|
||||
export { VercelDeployForm } from './VercelDeployForm';
|
||||
export { NsiteDeployForm } from './NsiteDeployForm';
|
||||
@@ -13,6 +13,8 @@ export interface AppConfig {
|
||||
esmUrl: string;
|
||||
/** HTTP proxy used to bypass CORS for AI and Git operations */
|
||||
corsProxy: string;
|
||||
/** Favicon URL template (e.g., "https://external-content.duckduckgo.com/ip3/{hostname}.ico") */
|
||||
faviconUrl: string;
|
||||
/** Preview domain for iframe sandboxing (e.g., "local-shakespeare.dev") */
|
||||
previewDomain: string;
|
||||
/** Selected language */
|
||||
|
||||
@@ -3,27 +3,36 @@ import { createContext } from 'react';
|
||||
export interface BaseDeployProvider {
|
||||
id: string;
|
||||
name: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
export interface ShakespeareDeployProvider extends BaseDeployProvider {
|
||||
type: 'shakespeare';
|
||||
host?: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
export interface NetlifyProvider extends BaseDeployProvider {
|
||||
type: 'netlify';
|
||||
apiKey: string;
|
||||
baseURL?: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
export interface VercelProvider extends BaseDeployProvider {
|
||||
type: 'vercel';
|
||||
apiKey: string;
|
||||
baseURL?: string;
|
||||
proxy?: boolean;
|
||||
}
|
||||
|
||||
export type DeployProvider = ShakespeareDeployProvider | NetlifyProvider | VercelProvider;
|
||||
export interface NsiteProvider extends BaseDeployProvider {
|
||||
type: 'nsite';
|
||||
gateway: string;
|
||||
relayUrls: string[];
|
||||
blossomServers: string[];
|
||||
}
|
||||
|
||||
export type DeployProvider = ShakespeareDeployProvider | NetlifyProvider | VercelProvider | NsiteProvider;
|
||||
|
||||
export interface DeploySettings {
|
||||
providers: DeployProvider[];
|
||||
|
||||
@@ -45,6 +45,7 @@ describe('useAIProjectId', () => {
|
||||
projectTemplate: 'https://github.com/example/template',
|
||||
esmUrl: 'https://esm.sh',
|
||||
corsProxy: 'https://proxy.example.com/{href}',
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
|
||||
@@ -37,6 +37,7 @@ function createWrapper(corsProxy: string) {
|
||||
projectTemplate: 'https://gitlab.com/soapbox-pub/mkstack.git',
|
||||
esmUrl: 'https://esm.test',
|
||||
corsProxy,
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
previewDomain: 'local-test.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
|
||||
@@ -8,6 +8,13 @@ export interface ShakespeareProjectConfig {
|
||||
};
|
||||
}
|
||||
|
||||
export interface NsiteProjectConfig {
|
||||
type: 'nsite';
|
||||
data: {
|
||||
nsec: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface NetlifyProjectConfig {
|
||||
type: 'netlify';
|
||||
data: {
|
||||
@@ -23,7 +30,7 @@ export interface VercelProjectConfig {
|
||||
};
|
||||
}
|
||||
|
||||
export type ProjectProviderConfig = ShakespeareProjectConfig | NetlifyProjectConfig | VercelProjectConfig;
|
||||
export type ProjectProviderConfig = ShakespeareProjectConfig | NsiteProjectConfig | NetlifyProjectConfig | VercelProjectConfig;
|
||||
|
||||
export interface ProjectDeploySettings {
|
||||
providers: Record<string, ProjectProviderConfig>;
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
*/
|
||||
export interface JSRuntimeFS {
|
||||
// Core file operations with proper overloads for type safety
|
||||
readFile(path: string): Promise<Uint8Array>;
|
||||
readFile(path: string): Promise<Uint8Array<ArrayBuffer>>;
|
||||
readFile(path: string, options: 'utf8'): Promise<string>;
|
||||
readFile(path: string, options: string): Promise<string>;
|
||||
readFile(path: string, options: { encoding: 'utf8' }): Promise<string>;
|
||||
readFile(path: string, options: { encoding: string }): Promise<string>;
|
||||
readFile(path: string, options?: string | { encoding?: string }): Promise<string | Uint8Array>;
|
||||
readFile(path: string, options?: string | { encoding?: string }): Promise<string | Uint8Array<ArrayBuffer>>;
|
||||
|
||||
writeFile(path: string, data: string | Uint8Array, options?: string | { encoding?: string }): Promise<void>;
|
||||
writeFile(path: string, data: string | Uint8Array<ArrayBuffer>, options?: string | { encoding?: string }): Promise<void>;
|
||||
|
||||
// readdir overloads for different return types
|
||||
readdir(path: string): Promise<string[]>;
|
||||
|
||||
@@ -71,10 +71,18 @@ const vercelProviderSchema = baseDeployProviderSchema.extend({
|
||||
baseURL: z.string().optional(),
|
||||
});
|
||||
|
||||
const nsiteProviderSchema = baseDeployProviderSchema.extend({
|
||||
type: z.literal('nsite'),
|
||||
gateway: z.string(),
|
||||
relayUrls: z.array(z.string()),
|
||||
blossomServers: z.array(z.string()),
|
||||
});
|
||||
|
||||
const deployProviderSchema: z.ZodType<DeployProvider> = z.discriminatedUnion('type', [
|
||||
shakespeareDeployProviderSchema,
|
||||
netlifyProviderSchema,
|
||||
vercelProviderSchema,
|
||||
nsiteProviderSchema,
|
||||
]);
|
||||
|
||||
const deploySettingsSchema = z.object({
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import { BlossomUploader } from '@nostrify/nostrify/uploaders';
|
||||
import { NSecSigner, NPool } from '@nostrify/nostrify';
|
||||
import type { NostrEvent } from '@nostrify/nostrify';
|
||||
import mime from 'mime';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
import type { DeployAdapter, DeployOptions, DeployResult, NsiteDeployConfig } from './types';
|
||||
|
||||
/**
|
||||
* Nsite Deploy Adapter
|
||||
* Deploys static sites to Nostr using kind 34128 events and Blossom file storage
|
||||
*/
|
||||
export class NsiteAdapter implements DeployAdapter {
|
||||
private fs: JSRuntimeFS;
|
||||
private nostr: NsiteDeployConfig['nostr'];
|
||||
private nsec: string;
|
||||
private gateway: string;
|
||||
private relayUrls: string[];
|
||||
private blossomServers: string[];
|
||||
|
||||
constructor(config: NsiteDeployConfig) {
|
||||
this.fs = config.fs;
|
||||
this.nostr = config.nostr;
|
||||
this.nsec = config.nsec;
|
||||
this.gateway = config.gateway;
|
||||
this.relayUrls = config.relayUrls;
|
||||
this.blossomServers = config.blossomServers;
|
||||
}
|
||||
|
||||
async deploy(options: DeployOptions): Promise<DeployResult> {
|
||||
const { projectPath } = options;
|
||||
|
||||
// Check if dist directory exists and contains index.html
|
||||
const distPath = `${projectPath}/dist`;
|
||||
try {
|
||||
await this.fs.readFile(`${distPath}/index.html`, 'utf8');
|
||||
} catch {
|
||||
throw new Error('No index.html found in dist directory. Please build the project first.');
|
||||
}
|
||||
|
||||
// Decode nsec to get the private key and create signer
|
||||
const decoded = nip19.decode(this.nsec);
|
||||
if (decoded.type !== 'nsec') {
|
||||
throw new Error('Invalid nsec format');
|
||||
}
|
||||
const signer = new NSecSigner(decoded.data);
|
||||
const pubkey = await signer.getPublicKey();
|
||||
|
||||
// Create a grouped Nostr client for the configured relays
|
||||
const relayClient = this.nostr.group(this.relayUrls);
|
||||
|
||||
// Initialize Blossom uploader
|
||||
const uploader = new BlossomUploader({
|
||||
servers: this.blossomServers,
|
||||
signer,
|
||||
});
|
||||
|
||||
// Collect all files and upload them
|
||||
const fileEvents: NostrEvent[] = [];
|
||||
await this.uploadDirectory(distPath, '', uploader, signer, fileEvents);
|
||||
|
||||
// Publish file events and other metadata to the relays
|
||||
await Promise.all([
|
||||
this.publishRelayList(signer, relayClient),
|
||||
this.publishServerList(signer, relayClient),
|
||||
...fileEvents.map(event => relayClient.event(event, { signal: AbortSignal.timeout(5000) })),
|
||||
]);
|
||||
|
||||
// Generate npub subdomain
|
||||
const npub = nip19.npubEncode(pubkey);
|
||||
const siteUrl = `https://${npub}.${this.gateway}`;
|
||||
|
||||
return {
|
||||
url: siteUrl,
|
||||
metadata: {
|
||||
pubkey,
|
||||
npub,
|
||||
filesPublished: fileEvents.length,
|
||||
provider: 'nsite',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private async uploadDirectory(
|
||||
dirPath: string,
|
||||
relativePath: string,
|
||||
uploader: BlossomUploader,
|
||||
signer: NSecSigner,
|
||||
fileEvents: NostrEvent[]
|
||||
): Promise<void> {
|
||||
const entries = await this.fs.readdir(dirPath, { withFileTypes: true });
|
||||
|
||||
for (const entry of entries) {
|
||||
const fullPath = `${dirPath}/${entry.name}`;
|
||||
const relPath = relativePath ? `${relativePath}/${entry.name}` : entry.name;
|
||||
|
||||
if (entry.isDirectory()) {
|
||||
await this.uploadDirectory(fullPath, relPath, uploader, signer, fileEvents);
|
||||
} else if (entry.isFile()) {
|
||||
await this.uploadFile(fullPath, relPath, uploader, signer, fileEvents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async uploadFile(
|
||||
filePath: string,
|
||||
relativePath: string,
|
||||
uploader: BlossomUploader,
|
||||
signer: NSecSigner,
|
||||
fileEvents: NostrEvent[]
|
||||
): Promise<void> {
|
||||
try {
|
||||
// Read file content
|
||||
const content = await this.fs.readFile(filePath);
|
||||
|
||||
// Convert to File object for upload
|
||||
const file = new File([content], relativePath.split('/').pop() || 'file', {
|
||||
type: mime.getType(filePath) || undefined,
|
||||
});
|
||||
|
||||
// Upload to Blossom and get tags
|
||||
const tags = await uploader.upload(file);
|
||||
|
||||
// Extract sha256 hash from tags
|
||||
// Tags format: [['url', 'https://...'], ['x', 'sha256hash'], ['size', '1234'], ...]
|
||||
const xTag = tags.find(([name]) => name === 'x');
|
||||
if (!xTag || !xTag[1]) {
|
||||
throw new Error(`Failed to get sha256 hash for ${relativePath}`);
|
||||
}
|
||||
const sha256 = xTag[1];
|
||||
|
||||
// Create absolute path (must start with /)
|
||||
const absolutePath = relativePath.startsWith('/') ? relativePath : `/${relativePath}`;
|
||||
|
||||
// Create kind 34128 event
|
||||
const event = await signer.signEvent({
|
||||
kind: 34128,
|
||||
content: '',
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [
|
||||
['d', absolutePath],
|
||||
['x', sha256],
|
||||
],
|
||||
});
|
||||
|
||||
fileEvents.push(event);
|
||||
} catch (error) {
|
||||
console.warn(`Failed to upload file ${filePath}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private async publishRelayList(signer: NSecSigner, relayClient: NPool): Promise<void> {
|
||||
const relayListEvent = await signer.signEvent({
|
||||
kind: 10002,
|
||||
content: '',
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: this.relayUrls.map(url => ['r', url]),
|
||||
});
|
||||
|
||||
await relayClient.event(relayListEvent, { signal: AbortSignal.timeout(5000) });
|
||||
}
|
||||
|
||||
private async publishServerList(signer: NSecSigner, relayClient: NPool): Promise<void> {
|
||||
const serverListEvent = await signer.signEvent({
|
||||
kind: 10063,
|
||||
content: '',
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: this.blossomServers.map(server => ['server', server]),
|
||||
});
|
||||
|
||||
await relayClient.event(serverListEvent, { signal: AbortSignal.timeout(5000) });
|
||||
}
|
||||
}
|
||||
@@ -2,3 +2,4 @@ export * from './types';
|
||||
export * from './ShakespeareAdapter';
|
||||
export * from './NetlifyAdapter';
|
||||
export * from './VercelAdapter';
|
||||
export * from './NsiteAdapter';
|
||||
+10
-1
@@ -1,5 +1,5 @@
|
||||
import type { JSRuntimeFS } from '../JSRuntime';
|
||||
import type { NostrSigner } from '@nostrify/nostrify';
|
||||
import type { NostrSigner, NPool } from '@nostrify/nostrify';
|
||||
|
||||
export interface DeployOptions {
|
||||
/** Project ID */
|
||||
@@ -45,3 +45,12 @@ export interface VercelDeployConfig {
|
||||
projectName?: string;
|
||||
corsProxy?: string;
|
||||
}
|
||||
|
||||
export interface NsiteDeployConfig {
|
||||
fs: JSRuntimeFS;
|
||||
nostr: NPool;
|
||||
nsec: string;
|
||||
gateway: string;
|
||||
relayUrls: string[];
|
||||
blossomServers: string[];
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import UriTemplate from 'uri-templates';
|
||||
|
||||
/**
|
||||
* Generate a favicon URL from a template and input URL
|
||||
* @param template - URL template with placeholders like {hostname}, {origin}, etc.
|
||||
* @param url - The URL to extract parts from
|
||||
* @returns The hydrated favicon URL
|
||||
*/
|
||||
export function faviconUrl(template: string, url: string | URL): string {
|
||||
const u = new URL(url);
|
||||
|
||||
return UriTemplate(template).fill({
|
||||
href: u.href,
|
||||
origin: u.origin,
|
||||
protocol: u.protocol,
|
||||
username: u.username,
|
||||
password: u.password,
|
||||
host: u.host,
|
||||
hostname: u.hostname,
|
||||
port: u.port,
|
||||
pathname: u.pathname,
|
||||
hash: u.hash,
|
||||
search: u.search,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a URL string to ensure it has a protocol
|
||||
* @param url - The URL string to normalize
|
||||
* @returns A fully-qualified URL string
|
||||
*/
|
||||
export function normalizeUrl(url: string): string {
|
||||
// If it already has a protocol, return as-is
|
||||
if (/^https?:\/\//i.test(url)) {
|
||||
return url;
|
||||
}
|
||||
|
||||
// Add https:// prefix
|
||||
return `https://${url}`;
|
||||
}
|
||||
@@ -92,8 +92,28 @@ describe('ReadConsoleMessagesTool', () => {
|
||||
const limitedResult = await tool.execute({ limit: 2 });
|
||||
expect(limitedResult).toContain('Found 2 console messages');
|
||||
|
||||
// No limit should return all messages
|
||||
// Default limit (50) should return all messages when total is less than 50
|
||||
const allResult = await tool.execute({});
|
||||
expect(allResult).toContain('Found 4 console messages');
|
||||
});
|
||||
|
||||
it('should show truncation note when messages exceed limit', async () => {
|
||||
clearConsoleMessages();
|
||||
// Add more messages than the limit
|
||||
for (let i = 1; i <= 60; i++) {
|
||||
addConsoleMessage('log', `Message ${i}`);
|
||||
}
|
||||
|
||||
const tool = new ReadConsoleMessagesTool();
|
||||
|
||||
// Default limit is 50
|
||||
const result = await tool.execute({});
|
||||
expect(result).toContain('(showing last 50 of 60)');
|
||||
expect(result).toContain('Message 60'); // Most recent
|
||||
expect(result).not.toContain('Message 10'); // Too old
|
||||
|
||||
// Custom limit
|
||||
const limitedResult = await tool.execute({ limit: 10 });
|
||||
expect(limitedResult).toContain('(showing last 10 of 60)');
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,4 @@
|
||||
import { z } from 'zod';
|
||||
import { Tool } from './Tool';
|
||||
import { getConsoleMessages } from '@/lib/consoleMessages';
|
||||
|
||||
@@ -11,15 +12,25 @@ export interface ReadConsoleMessagesParams {
|
||||
* This tool allows AI assistants to access console logs for debugging assistance.
|
||||
*/
|
||||
export class ReadConsoleMessagesTool implements Tool<ReadConsoleMessagesParams> {
|
||||
readonly description = 'Read console messages from the project preview. Can filter by level and limit results.';
|
||||
|
||||
readonly inputSchema = z.object({
|
||||
filter: z.enum(['error', 'warn', 'info', 'debug', 'log', 'all']).optional().describe(
|
||||
'Filter messages by level. Defaults to "all" to show all message types.'
|
||||
),
|
||||
limit: z.number().min(1).max(200).optional().describe(
|
||||
'Maximum number of most recent messages to return. Defaults to 50. Use smaller values (10-20) for quick checks, larger values (100-200) for comprehensive debugging.'
|
||||
),
|
||||
});
|
||||
|
||||
async execute(params: ReadConsoleMessagesParams): Promise<string> {
|
||||
const { filter = 'all', limit } = params;
|
||||
const { filter = 'all', limit = 50 } = params;
|
||||
|
||||
let messages = getConsoleMessages()
|
||||
.filter(msg => filter === 'all' || msg.level === filter);
|
||||
|
||||
if (limit && limit > 0) {
|
||||
messages = messages.slice(-limit);
|
||||
}
|
||||
// Always apply a limit to prevent unbounded output
|
||||
messages = messages.slice(-limit);
|
||||
|
||||
if (messages.length === 0) {
|
||||
return `No console messages found${filter !== 'all' ? ` for level: ${filter}` : ''}.`;
|
||||
@@ -30,8 +41,9 @@ export class ReadConsoleMessagesTool implements Tool<ReadConsoleMessagesParams>
|
||||
.join('\n');
|
||||
|
||||
const suffix = filter !== 'all' ? ` (level: ${filter})` : '';
|
||||
return `Found ${messages.length} console message${messages.length !== 1 ? 's' : ''}${suffix}:\n\n${formatted}`;
|
||||
}
|
||||
const totalAvailable = getConsoleMessages().filter(msg => filter === 'all' || msg.level === filter).length;
|
||||
const truncatedNote = totalAvailable > messages.length ? ` (showing last ${messages.length} of ${totalAvailable})` : '';
|
||||
|
||||
description = 'Read console messages from the project preview. Can filter by level and limit results.';
|
||||
return `Found ${messages.length} console message${messages.length !== 1 ? 's' : ''}${suffix}${truncatedNote}:\n\n${formatted}`;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createRoot } from 'react-dom/client';
|
||||
import { webpm, fileContentStore } from '@webpm/webpm';
|
||||
|
||||
// Import polyfills first
|
||||
import './lib/polyfills.ts';
|
||||
|
||||
+32
-15
@@ -1,7 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check, Bot, ArrowLeft, Trash2, GripVertical } from 'lucide-react';
|
||||
import { SiOpenai, SiAnthropic, SiGoogle, SiX } from '@icons-pack/react-simple-icons';
|
||||
import {
|
||||
DndContext,
|
||||
closestCenter,
|
||||
@@ -36,19 +35,25 @@ import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import type { AIProvider } from '@/contexts/AISettingsContext';
|
||||
import { AI_PROVIDER_PRESETS, type PresetProvider } from '@/lib/aiProviderPresets';
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
|
||||
function renderIcon(providerId: string, size = 16) {
|
||||
switch (providerId) {
|
||||
case 'openai':
|
||||
return <SiOpenai size={size} />;
|
||||
case 'anthropic':
|
||||
return <SiAnthropic size={size} />;
|
||||
case 'google':
|
||||
return <SiGoogle size={size} />;
|
||||
case 'xai':
|
||||
return <SiX size={size} />;
|
||||
default:
|
||||
return null;
|
||||
/** A few provider-specific icon hacks */
|
||||
function getProviderIconUrl(provider: { id: string; baseURL: string }): string {
|
||||
if (provider.id === 'ollama' && provider.baseURL === 'http://localhost:11434/v1') {
|
||||
return 'https://ollama.com/';
|
||||
} else if (provider.baseURL === 'https://generativelanguage.googleapis.com/v1beta/openai') {
|
||||
return 'https://gemini.google.com/';
|
||||
} else if (provider.baseURL === 'https://api.z.ai/api/paas/v4') {
|
||||
return 'https://docs.z.ai/';
|
||||
}
|
||||
try {
|
||||
// Strip .ai and .api subdomains for a better chance at finding a favicon
|
||||
const urlObj = new URL(provider.baseURL);
|
||||
urlObj.hostname = urlObj.hostname.replace(/^(ai\.|api\.)/, '');
|
||||
return urlObj.toString();
|
||||
} catch {
|
||||
// Fallback to baseURL
|
||||
return provider.baseURL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +101,15 @@ function SortableProviderItem({ provider, preset, onRemove, onSetProvider, onOpe
|
||||
<GripVertical className="h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
{renderIcon(provider.id)}
|
||||
{provider.baseURL ? (
|
||||
<ExternalFavicon
|
||||
url={getProviderIconUrl(provider)}
|
||||
size={16}
|
||||
fallback={<Bot size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Bot size={16} />
|
||||
)}
|
||||
<span className="font-medium">
|
||||
{preset?.name || provider.id}
|
||||
</span>
|
||||
@@ -376,7 +389,11 @@ export function AISettings() {
|
||||
<div key={preset.id} className="border rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
{renderIcon(preset.id)}
|
||||
<ExternalFavicon
|
||||
url={getProviderIconUrl(preset)}
|
||||
size={16}
|
||||
fallback={<Bot size={16} />}
|
||||
/>
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
{(preset.apiKeysURL && preset.id !== "routstr") && (
|
||||
|
||||
+263
-62
@@ -1,8 +1,13 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Rocket, ArrowLeft, Trash2, Check, GripVertical } from 'lucide-react';
|
||||
import { Rocket, ArrowLeft, Trash2, Check, GripVertical, ChevronDown } from 'lucide-react';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { SiNetlify, SiVercel } from '@icons-pack/react-simple-icons';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import {
|
||||
DndContext,
|
||||
closestCenter,
|
||||
@@ -35,10 +40,12 @@ import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import type { DeployProvider } from '@/contexts/DeploySettingsContext';
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
import { normalizeUrl } from '@/lib/faviconUrl';
|
||||
|
||||
interface PresetProvider {
|
||||
id: string;
|
||||
type: 'shakespeare' | 'netlify' | 'vercel';
|
||||
type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite';
|
||||
name: string;
|
||||
description: string;
|
||||
requiresNostr?: boolean;
|
||||
@@ -89,7 +96,18 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
<GripVertical className="h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
{renderIcon(provider.id)}
|
||||
{(() => {
|
||||
const url = getProviderUrl(provider);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<span className="font-medium">
|
||||
{provider.name}
|
||||
</span>
|
||||
@@ -123,6 +141,42 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : provider.type === 'nsite' ? (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-gateway`}>Gateway</Label>
|
||||
<Input
|
||||
id={`provider-${index}-gateway`}
|
||||
placeholder="nsite.lol"
|
||||
value={provider.gateway || ''}
|
||||
onChange={(e) => onUpdate(index, { ...provider, gateway: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-relays`}>Relay URLs (comma-separated)</Label>
|
||||
<Input
|
||||
id={`provider-${index}-relays`}
|
||||
placeholder="wss://relay.nostr.band, wss://relay.damus.io"
|
||||
value={provider.relayUrls?.join(', ') || ''}
|
||||
onChange={(e) => onUpdate(index, {
|
||||
...provider,
|
||||
relayUrls: e.target.value.split(',').map(s => s.trim()).filter(Boolean)
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`provider-${index}-blossom`}>Blossom Servers (comma-separated)</Label>
|
||||
<Input
|
||||
id={`provider-${index}-blossom`}
|
||||
placeholder="https://blossom.primal.net/"
|
||||
value={provider.blossomServers?.join(', ') || ''}
|
||||
onChange={(e) => onUpdate(index, {
|
||||
...provider,
|
||||
blossomServers: e.target.value.split(',').map(s => s.trim()).filter(Boolean)
|
||||
})}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
@@ -159,21 +213,21 @@ function SortableProviderItem({ provider, index, preset, onRemove, onUpdate, sho
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Checkbox
|
||||
id={`provider-${index}-proxy`}
|
||||
checked={provider.proxy || false}
|
||||
onCheckedChange={(checked) => onUpdate(index, { ...provider, proxy: checked === true })}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`provider-${index}-proxy`}
|
||||
className="text-sm font-normal cursor-pointer"
|
||||
>
|
||||
Use CORS Proxy
|
||||
</Label>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
<div className="flex items-center space-x-2">
|
||||
<Checkbox
|
||||
id={`provider-${index}-proxy`}
|
||||
checked={provider.proxy || false}
|
||||
onCheckedChange={(checked) => onUpdate(index, { ...provider, proxy: checked === true })}
|
||||
/>
|
||||
<Label
|
||||
htmlFor={`provider-${index}-proxy`}
|
||||
className="text-sm font-normal cursor-pointer"
|
||||
>
|
||||
Use CORS Proxy
|
||||
</Label>
|
||||
</div>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
@@ -196,6 +250,12 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
description: 'Deploy to Shakespeare hosting with Nostr authentication',
|
||||
requiresNostr: true,
|
||||
},
|
||||
{
|
||||
id: 'nsite',
|
||||
type: 'nsite',
|
||||
name: 'nsite',
|
||||
description: 'Deploy to Nostr as a static website',
|
||||
},
|
||||
{
|
||||
id: 'netlify',
|
||||
type: 'netlify',
|
||||
@@ -205,15 +265,15 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
apiKeyURL: 'https://app.netlify.com/user/applications#personal-access-tokens',
|
||||
proxy: true,
|
||||
},
|
||||
// {
|
||||
// id: 'vercel',
|
||||
// type: 'vercel',
|
||||
// name: 'Vercel',
|
||||
// description: 'Deploy to Vercel',
|
||||
// apiKeyLabel: 'Access Token',
|
||||
// apiKeyURL: 'https://vercel.com/account/tokens',
|
||||
// proxy: true,
|
||||
// },
|
||||
{
|
||||
id: 'vercel',
|
||||
type: 'vercel',
|
||||
name: 'Vercel',
|
||||
description: 'Deploy to Vercel',
|
||||
apiKeyLabel: 'Access Token',
|
||||
apiKeyURL: 'https://vercel.com/account/tokens',
|
||||
proxy: true,
|
||||
},
|
||||
];
|
||||
|
||||
// Helper function to generate custom provider ID
|
||||
@@ -223,12 +283,33 @@ function generateCustomProviderId(type: string): string {
|
||||
return `${type}-${randomSegment}`;
|
||||
}
|
||||
|
||||
function renderIcon(providerId: string, size = 16) {
|
||||
switch (providerId) {
|
||||
function getProviderUrl(provider: DeployProvider | PresetProvider): string | null {
|
||||
switch (provider.type) {
|
||||
case 'shakespeare':
|
||||
// For Shakespeare providers, check for custom host first, then use default
|
||||
if ('host' in provider && provider.host) {
|
||||
return normalizeUrl(provider.host);
|
||||
}
|
||||
return 'https://shakespeare.diy';
|
||||
|
||||
case 'netlify':
|
||||
return <SiNetlify size={size} />;
|
||||
// For Netlify providers, check for custom baseURL first, then use default
|
||||
if ('baseURL' in provider && provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://netlify.com';
|
||||
|
||||
case 'vercel':
|
||||
return <SiVercel size={size} />;
|
||||
// For Vercel providers, check for custom baseURL first, then use default
|
||||
if ('baseURL' in provider && provider.baseURL) {
|
||||
return provider.baseURL;
|
||||
}
|
||||
return 'https://vercel.com';
|
||||
|
||||
case 'nsite':
|
||||
// nsite uses Rocket icon fallback
|
||||
return null;
|
||||
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -246,14 +327,18 @@ export function DeploySettings() {
|
||||
const vercelOAuth = useVercelOAuth();
|
||||
|
||||
const [presetApiKeys, setPresetApiKeys] = useState<Record<string, string>>({});
|
||||
const [forceManualEntry, setForceManualEntry] = useState<Record<string, boolean>>({});
|
||||
|
||||
// Custom provider form state
|
||||
const [customProviderType, setCustomProviderType] = useState<'shakespeare' | 'netlify' | 'vercel' | ''>('');
|
||||
const [customProviderType, setCustomProviderType] = useState<'shakespeare' | 'netlify' | 'vercel' | 'nsite' | ''>('');
|
||||
const [customName, setCustomName] = useState('');
|
||||
const [customApiKey, setCustomApiKey] = useState('');
|
||||
const [customBaseURL, setCustomBaseURL] = useState('');
|
||||
const [customHost, setCustomHost] = useState('');
|
||||
const [customProxy, setCustomProxy] = useState(false);
|
||||
const [customGateway, setCustomGateway] = useState('');
|
||||
const [customRelayUrls, setCustomRelayUrls] = useState('');
|
||||
const [customBlossomServers, setCustomBlossomServers] = useState('');
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor),
|
||||
@@ -282,8 +367,8 @@ export function DeploySettings() {
|
||||
|
||||
const apiKey = presetApiKeys[preset.id];
|
||||
|
||||
// For non-Shakespeare providers, require API key
|
||||
if (!preset.requiresNostr && !apiKey?.trim()) {
|
||||
// For non-Shakespeare/non-nsite providers, require API key
|
||||
if (!preset.requiresNostr && preset.type !== 'nsite' && !apiKey?.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -296,6 +381,25 @@ export function DeploySettings() {
|
||||
type: 'shakespeare',
|
||||
...(preset.proxy && { proxy: true }),
|
||||
};
|
||||
} else if (preset.type === 'nsite') {
|
||||
newProvider = {
|
||||
id: preset.id, // Use preset ID for presets
|
||||
name: preset.name,
|
||||
type: 'nsite',
|
||||
gateway: 'nosto.re',
|
||||
relayUrls: [
|
||||
'wss://relay.nsite.lol',
|
||||
'wss://relay.nosto.re',
|
||||
'wss://relay.nostr.band',
|
||||
'wss://relay.primal.net',
|
||||
'wss://relay.damus.io',
|
||||
'wss://purplerelay.com',
|
||||
],
|
||||
blossomServers: [
|
||||
'https://blossom.primal.net',
|
||||
'https://cdn.sovbit.host',
|
||||
],
|
||||
};
|
||||
} else if (preset.type === 'netlify') {
|
||||
newProvider = {
|
||||
id: preset.id, // Use preset ID for presets
|
||||
@@ -333,6 +437,23 @@ export function DeploySettings() {
|
||||
...(customHost?.trim() && { host: customHost.trim() }),
|
||||
...(customProxy && { proxy: true }),
|
||||
};
|
||||
} else if (customProviderType === 'nsite') {
|
||||
const gateway = customGateway.trim() || 'nsite.lol';
|
||||
const relayUrls = customRelayUrls.trim()
|
||||
? customRelayUrls.split(',').map(s => s.trim()).filter(Boolean)
|
||||
: ['wss://relay.nostr.band'];
|
||||
const blossomServers = customBlossomServers.trim()
|
||||
? customBlossomServers.split(',').map(s => s.trim()).filter(Boolean)
|
||||
: ['https://blossom.primal.net/'];
|
||||
|
||||
newProvider = {
|
||||
id: generateCustomProviderId(customProviderType), // Generate custom ID
|
||||
name: customName.trim(),
|
||||
type: 'nsite',
|
||||
gateway,
|
||||
relayUrls,
|
||||
blossomServers,
|
||||
};
|
||||
} else if (customProviderType === 'netlify') {
|
||||
if (!customApiKey.trim()) return;
|
||||
newProvider = {
|
||||
@@ -473,7 +594,18 @@ export function DeploySettings() {
|
||||
<div key={preset.id} className="border rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
{renderIcon(preset.id)}
|
||||
{(() => {
|
||||
const url = getProviderUrl(preset);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
{preset.apiKeyURL && !isOAuthConfigured && (
|
||||
@@ -486,6 +618,7 @@ export function DeploySettings() {
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">{preset.description}</p>
|
||||
|
||||
{showNostrLoginRequired ? (
|
||||
<div className="space-y-2">
|
||||
@@ -498,29 +631,60 @@ export function DeploySettings() {
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
) : isOAuthConfigured ? (
|
||||
// Show OAuth button if OAuth is configured
|
||||
) : isOAuthConfigured && !forceManualEntry[preset.id] ? (
|
||||
// Show OAuth button if OAuth is configured and not forced to manual
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
onClick={() => oauthHook?.initiateOAuth()}
|
||||
disabled={isOAuthLoading}
|
||||
className="w-full max-w-full gap-2"
|
||||
variant="default"
|
||||
>
|
||||
{isOAuthLoading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
Connecting...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{renderIcon(preset.id)}
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to {preset.name}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<div className="flex gap-0">
|
||||
<Button
|
||||
onClick={() => oauthHook?.initiateOAuth()}
|
||||
disabled={isOAuthLoading}
|
||||
className="flex-1 rounded-r-none gap-2"
|
||||
variant="default"
|
||||
>
|
||||
{isOAuthLoading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
Connecting...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{(() => {
|
||||
const url = getProviderUrl(preset);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to {preset.name}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="default"
|
||||
className="rounded-l-none border-l border-primary-foreground/20 px-2"
|
||||
disabled={isOAuthLoading}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => setForceManualEntry(prev => ({ ...prev, [preset.id]: true }))}
|
||||
>
|
||||
Enter API key
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
{oauthError && (
|
||||
<p className="text-sm text-destructive">
|
||||
{oauthError}
|
||||
@@ -531,7 +695,7 @@ export function DeploySettings() {
|
||||
// Show manual token input
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-2">
|
||||
{!preset.requiresNostr && (
|
||||
{!preset.requiresNostr && preset.type !== 'nsite' && (
|
||||
<PasswordInput
|
||||
placeholder={preset.apiKeyLabel || t('enterApiKey')}
|
||||
className="flex-1"
|
||||
@@ -551,9 +715,9 @@ export function DeploySettings() {
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={
|
||||
(preset.requiresNostr && !isLoggedIntoNostr) ||
|
||||
(!preset.requiresNostr && !presetApiKeys[preset.id]?.trim())
|
||||
(!preset.requiresNostr && preset.type !== 'nsite' && !presetApiKeys[preset.id]?.trim())
|
||||
}
|
||||
className={preset.requiresNostr ? "w-full" : "h-10 px-4 ml-auto"}
|
||||
className={(preset.requiresNostr || preset.type === 'nsite') ? "w-full" : "h-10 px-4 ml-auto"}
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
@@ -580,13 +744,16 @@ export function DeploySettings() {
|
||||
<Label htmlFor="custom-provider-type">{t('providerType')}</Label>
|
||||
<Select
|
||||
value={customProviderType}
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel') => {
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel' | 'nsite') => {
|
||||
setCustomProviderType(value);
|
||||
// Reset form when provider type changes
|
||||
setCustomApiKey('');
|
||||
setCustomBaseURL('');
|
||||
setCustomHost('');
|
||||
setCustomProxy(false);
|
||||
setCustomGateway('');
|
||||
setCustomRelayUrls('');
|
||||
setCustomBlossomServers('');
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
@@ -594,8 +761,9 @@ export function DeploySettings() {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="shakespeare">Shakespeare Deploy</SelectItem>
|
||||
<SelectItem value="nsite">nsite</SelectItem>
|
||||
<SelectItem value="netlify">Netlify</SelectItem>
|
||||
{/* <SelectItem value="vercel">Vercel</SelectItem> */}
|
||||
<SelectItem value="vercel">Vercel</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -627,6 +795,39 @@ export function DeploySettings() {
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : customProviderType === 'nsite' ? (
|
||||
<>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Deploy to Nostr as a static website. Uses kind 34128 events and Blossom file storage.
|
||||
</p>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-gateway">Gateway</Label>
|
||||
<Input
|
||||
id="custom-gateway"
|
||||
placeholder="nsite.lol"
|
||||
value={customGateway}
|
||||
onChange={(e) => setCustomGateway(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-relays">Relay URLs (comma-separated)</Label>
|
||||
<Input
|
||||
id="custom-relays"
|
||||
placeholder="wss://relay.nostr.band, wss://relay.damus.io"
|
||||
value={customRelayUrls}
|
||||
onChange={(e) => setCustomRelayUrls(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-blossom">Blossom Servers (comma-separated)</Label>
|
||||
<Input
|
||||
id="custom-blossom"
|
||||
placeholder="https://blossom.primal.net/"
|
||||
value={customBlossomServers}
|
||||
onChange={(e) => setCustomBlossomServers(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
@@ -672,7 +873,7 @@ export function DeploySettings() {
|
||||
disabled={
|
||||
!customProviderType ||
|
||||
!customName.trim() ||
|
||||
(customProviderType !== 'shakespeare' && !customApiKey.trim())
|
||||
(customProviderType !== 'shakespeare' && customProviderType !== 'nsite' && !customApiKey.trim())
|
||||
}
|
||||
className="gap-2 ml-auto"
|
||||
>
|
||||
|
||||
+64
-36
@@ -1,19 +1,25 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check, GitBranch, ArrowLeft, Trash2 } from 'lucide-react';
|
||||
import { Check, GitBranch, ArrowLeft, Trash2, ChevronDown } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { SiGithub, SiGitlab } from '@icons-pack/react-simple-icons';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import { useGitSettings } from '@/hooks/useGitSettings';
|
||||
import { useGitHubOAuth } from '@/hooks/useGitHubOAuth';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { GitCredential } from '@/contexts/GitSettingsContext';
|
||||
import { PasswordInput } from '@/components/ui/password-input';
|
||||
import { ExternalFavicon } from '@/components/ExternalFavicon';
|
||||
|
||||
interface PresetProvider {
|
||||
id: string;
|
||||
@@ -40,17 +46,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
},
|
||||
];
|
||||
|
||||
function renderIcon(providerId: string, size = 16) {
|
||||
switch (providerId) {
|
||||
case 'github':
|
||||
return <SiGithub size={size} />;
|
||||
case 'gitlab':
|
||||
return <SiGitlab size={size} />;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function GitSettings() {
|
||||
const { t } = useTranslation();
|
||||
const { settings, addCredential, removeCredential, updateCredential, updateSettings } = useGitSettings();
|
||||
@@ -61,6 +56,7 @@ export function GitSettings() {
|
||||
const [customUsername, setCustomUsername] = useState('');
|
||||
const [customPassword, setCustomPassword] = useState('');
|
||||
const [presetTokens, setPresetTokens] = useState<Record<string, string>>({});
|
||||
const [forceManualEntry, setForceManualEntry] = useState<Record<string, boolean>>({});
|
||||
|
||||
const handleAddPresetProvider = (preset: PresetProvider) => {
|
||||
const token = presetTokens[preset.id] as string | undefined;
|
||||
@@ -163,7 +159,11 @@ export function GitSettings() {
|
||||
<AccordionItem key={origin} value={origin} className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
{preset && renderIcon(preset.id)}
|
||||
<ExternalFavicon
|
||||
url={origin}
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<span className="font-medium">
|
||||
{preset?.name || new URL(origin).hostname}
|
||||
</span>
|
||||
@@ -226,7 +226,11 @@ export function GitSettings() {
|
||||
<div key={preset.id} className="border rounded-lg p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
{renderIcon(preset.id)}
|
||||
<ExternalFavicon
|
||||
url={preset.origin}
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
{preset.tokenURL && (preset.id !== 'github' || !isOAuthConfigured) && (
|
||||
@@ -242,28 +246,52 @@ export function GitSettings() {
|
||||
|
||||
{preset.id === 'github' ? (
|
||||
// Special rendering for GitHub - OAuth button if configured, otherwise token input
|
||||
isOAuthConfigured ? (
|
||||
isOAuthConfigured && !forceManualEntry[preset.id] ? (
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
onClick={initiateOAuth}
|
||||
disabled={isOAuthLoading}
|
||||
className="w-full max-w-full gap-2"
|
||||
variant="default"
|
||||
>
|
||||
{isOAuthLoading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
Connecting...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<SiGithub size={16} />
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to GitHub
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<div className="flex gap-0">
|
||||
<Button
|
||||
onClick={initiateOAuth}
|
||||
disabled={isOAuthLoading}
|
||||
className="flex-1 rounded-r-none gap-2"
|
||||
variant="default"
|
||||
>
|
||||
{isOAuthLoading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
Connecting...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ExternalFavicon
|
||||
url="https://github.com"
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to GitHub
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="default"
|
||||
className="rounded-l-none border-l border-primary-foreground/20 px-2"
|
||||
disabled={isOAuthLoading}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => setForceManualEntry(prev => ({ ...prev, [preset.id]: true }))}
|
||||
>
|
||||
Enter API key
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
{oauthError && (
|
||||
<p className="text-sm text-destructive">
|
||||
{oauthError}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useParams, useSearchParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { type Project } from '@/lib/ProjectsManager';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
@@ -19,16 +19,20 @@ import { StarButton } from '@/components/StarButton';
|
||||
import { useBuildProject } from '@/hooks/useBuildProject';
|
||||
import { useIsProjectPreviewable } from '@/hooks/useIsProjectPreviewable';
|
||||
import { useConsoleError } from '@/hooks/useConsoleError';
|
||||
import { webpm } from '@webpm/webpm';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
|
||||
export function ProjectView() {
|
||||
const { projectId } = useParams<{ projectId: string }>();
|
||||
const { t } = useTranslation();
|
||||
const { fs } = useFS();
|
||||
const [project, setProject] = useState<Project | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [activeTab, setActiveTab] = useState<'preview' | 'code'>('preview');
|
||||
const [mobileView, setMobileView] = useState<'chat' | 'preview' | 'code'>('chat');
|
||||
const [isAILoading, setIsAILoading] = useState(false);
|
||||
const [isProjectDetailsOpen, setIsProjectDetailsOpen] = useState(false);
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
// Use console error state from provider
|
||||
const { consoleError, dismissConsoleError, clearErrors } = useConsoleError();
|
||||
@@ -112,6 +116,24 @@ export function ProjectView() {
|
||||
navigate('/');
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
if (project && searchParams.get('build')) {
|
||||
const packageJson = await fs.readFile(`/projects/${project.id}/package.json`, 'utf8');
|
||||
await webpm.installWithUntarHandler(JSON.parse(packageJson), {
|
||||
onProgress: (e) => {
|
||||
console.log(`Build progress:`, e.currentProgress);
|
||||
},
|
||||
onComplete: () => {
|
||||
console.log('Build complete');
|
||||
},
|
||||
}, {
|
||||
includeDevDependencies: false,
|
||||
});
|
||||
}
|
||||
})();
|
||||
}, [fs, project, searchParams]);
|
||||
|
||||
if (!project && !isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||
|
||||
@@ -18,6 +18,7 @@ export function SystemSettings() {
|
||||
const [projectTemplateInput, setProjectTemplateInput] = useState(config.projectTemplate);
|
||||
const [esmUrlInput, setEsmUrlInput] = useState(config.esmUrl);
|
||||
const [corsProxyInput, setCorsProxyInput] = useState(config.corsProxy);
|
||||
const [faviconUrlInput, setFaviconUrlInput] = useState(config.faviconUrl);
|
||||
const [previewDomainInput, setPreviewDomainInput] = useState(config.previewDomain);
|
||||
const [showcaseModeratorInput, setShowcaseModeratorInput] = useState(config.showcaseModerator);
|
||||
|
||||
@@ -119,6 +120,36 @@ export function SystemSettings() {
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* Favicon URL Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="favicon-url" className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<h4 className="text-sm font-medium">Favicon URL</h4>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="py-1 space-y-2">
|
||||
<Input
|
||||
id="favicon-url"
|
||||
type="url"
|
||||
placeholder="https://external-content.duckduckgo.com/ip3/{hostname}.ico"
|
||||
value={faviconUrlInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setFaviconUrlInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
faviconUrl: value,
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
URL template for fetching favicons. Available variables: {'{hostname}'}, {'{origin}'}, {'{href}'}, {'{protocol}'}, {'{pathname}'}
|
||||
</p>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
|
||||
{/* JavaScript CDN Configuration */}
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="esm-url" className="border rounded-lg">
|
||||
|
||||
@@ -33,6 +33,7 @@ export function TestApp({ children }: TestAppProps) {
|
||||
projectTemplate: 'https://gitlab.com/soapbox-pub/mkstack.git',
|
||||
esmUrl: 'https://esm.shakespeare.diy',
|
||||
corsProxy: 'https://proxy.shakespeare.diy/?url={href}',
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
language: 'en',
|
||||
showcaseEnabled: true,
|
||||
|
||||
@@ -2,6 +2,7 @@ import path from "node:path";
|
||||
|
||||
import react from "@vitejs/plugin-react-swc";
|
||||
import { defineConfig } from "vitest/config";
|
||||
import { nodePolyfills } from "vite-plugin-node-polyfills";
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(() => ({
|
||||
@@ -10,6 +11,16 @@ export default defineConfig(() => ({
|
||||
port: 8080,
|
||||
},
|
||||
plugins: [
|
||||
nodePolyfills({
|
||||
include: ["buffer", "process", "stream", "module"],
|
||||
exclude: ["http", "https", "net", "tls", "child_process"],
|
||||
globals: {
|
||||
Buffer: true,
|
||||
global: true,
|
||||
process: true,
|
||||
},
|
||||
protocolImports: true,
|
||||
}),
|
||||
react(),
|
||||
],
|
||||
build: {
|
||||
@@ -52,4 +63,7 @@ export default defineConfig(() => ({
|
||||
"@": path.resolve(__dirname, "./src"),
|
||||
},
|
||||
},
|
||||
optimizeDeps: {
|
||||
include: ["tar-stream", "fflate"],
|
||||
},
|
||||
}));
|
||||
Reference in new issue
Block a user