Fix type errors

This commit is contained in:
Alex Gleason committed 2025-12-30 20:32:50 -06:00
1 parent 5a43a1ea61
commit 2acc0191ad
7 files changed
+121 -100

No files matched your search

+3 -9
View File
@@ -21,18 +21,12 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import type { AIProvider } from '@/contexts/AISettingsContext';
interface AddCustomAIProviderDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onAdd: (provider: {
id: string;
name: string;
baseURL: string;
apiKey?: string;
nostr?: boolean;
proxy?: boolean;
}) => void;
onAdd: (provider: AIProvider) => void;
existingIds: string[];
}
@@ -62,7 +56,7 @@ export function AddCustomAIProviderDialog({
const handleAdd = () => {
if (!customProviderName.trim() || !customProviderId.trim() || !customBaseURL.trim()) return;
const provider: any = {
const provider: AIProvider = {
id: customProviderId.trim(),
name: customProviderName.trim(),
baseURL: customBaseURL.trim(),
+82 -47
View File
@@ -21,24 +21,28 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import type {
ShakespeareDeployProvider,
NetlifyProvider,
VercelProvider,
NsiteProvider,
CloudflareProvider,
DenoDeployProvider,
} from '@/contexts/DeploySettingsContext';
// Type for provider without the 'id' field (will be generated)
type DeployProviderInput =
| Omit<ShakespeareDeployProvider, 'id'>
| Omit<NetlifyProvider, 'id'>
| Omit<VercelProvider, 'id'>
| Omit<NsiteProvider, 'id'>
| Omit<CloudflareProvider, 'id'>
| Omit<DenoDeployProvider, 'id'>;
interface AddCustomProviderDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
onAdd: (provider: {
type: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno';
name: string;
apiKey?: string;
accountId?: string;
organizationId?: string;
baseURL?: string;
baseDomain?: string;
host?: string;
proxy?: boolean;
gateway?: string;
relayUrls?: string[];
blossomServers?: string[];
}) => void;
onAdd: (provider: DeployProviderInput) => void;
}
export function AddCustomProviderDialog({
@@ -63,43 +67,74 @@ export function AddCustomProviderDialog({
const handleAdd = () => {
if (!customProviderType || !customName.trim()) return;
const provider: any = {
type: customProviderType,
name: customName.trim(),
};
// Build provider object based on type
let provider: DeployProviderInput;
if (customProviderType === 'shakespeare') {
if (customHost?.trim()) provider.host = customHost.trim();
if (customProxy) provider.proxy = true;
provider = {
type: 'shakespeare',
name: customName.trim(),
...(customHost?.trim() && { host: customHost.trim() }),
...(customProxy && { proxy: true }),
};
} else if (customProviderType === 'nsite') {
provider.gateway = customGateway.trim() || 'nsite.lol';
provider.relayUrls = customRelayUrls.trim()
? customRelayUrls.split(',').map(s => s.trim()).filter(Boolean)
: ['wss://relay.nostr.band'];
provider.blossomServers = customBlossomServers.trim()
? customBlossomServers.split(',').map(s => s.trim()).filter(Boolean)
: ['https://blossom.primal.net/'];
} else {
provider = {
type: 'nsite',
name: customName.trim(),
gateway: customGateway.trim() || 'nsite.lol',
relayUrls: customRelayUrls.trim()
? customRelayUrls.split(',').map(s => s.trim()).filter(Boolean)
: ['wss://relay.nostr.band'],
blossomServers: customBlossomServers.trim()
? customBlossomServers.split(',').map(s => s.trim()).filter(Boolean)
: ['https://blossom.primal.net/'],
};
} else if (customProviderType === 'netlify') {
if (!customApiKey.trim()) return;
provider.apiKey = customApiKey.trim();
if (customProviderType === 'cloudflare') {
if (!customAccountId.trim()) return;
provider.accountId = customAccountId.trim();
}
if (customProviderType === 'deno') {
if (!customOrganizationId.trim()) return;
provider.organizationId = customOrganizationId.trim();
}
if (customBaseURL?.trim()) provider.baseURL = customBaseURL.trim();
if (customBaseDomain?.trim()) provider.baseDomain = customBaseDomain.trim();
if (customProxy) provider.proxy = true;
provider = {
type: 'netlify',
name: customName.trim(),
apiKey: customApiKey.trim(),
...(customBaseURL?.trim() && { baseURL: customBaseURL.trim() }),
...(customProxy && { proxy: true }),
};
} else if (customProviderType === 'vercel') {
if (!customApiKey.trim()) return;
provider = {
type: 'vercel',
name: customName.trim(),
apiKey: customApiKey.trim(),
...(customBaseURL?.trim() && { baseURL: customBaseURL.trim() }),
...(customProxy && { proxy: true }),
};
} else if (customProviderType === 'cloudflare') {
if (!customApiKey.trim() || !customAccountId.trim()) return;
provider = {
type: 'cloudflare',
name: customName.trim(),
apiKey: customApiKey.trim(),
accountId: customAccountId.trim(),
...(customBaseURL?.trim() && { baseURL: customBaseURL.trim() }),
...(customBaseDomain?.trim() && { baseDomain: customBaseDomain.trim() }),
...(customProxy && { proxy: true }),
};
} else if (customProviderType === 'deno') {
if (!customApiKey.trim() || !customOrganizationId.trim()) return;
provider = {
type: 'deno',
name: customName.trim(),
apiKey: customApiKey.trim(),
organizationId: customOrganizationId.trim(),
...(customBaseURL?.trim() && { baseURL: customBaseURL.trim() }),
...(customBaseDomain?.trim() && { baseDomain: customBaseDomain.trim() }),
...(customProxy && { proxy: true }),
};
} else {
return; // Unknown type
}
onAdd(provider);
// Reset form
setCustomProviderType('');
setCustomName('');
@@ -113,13 +148,13 @@ export function AddCustomProviderDialog({
setCustomGateway('');
setCustomRelayUrls('');
setCustomBlossomServers('');
onOpenChange(false);
};
const isValid = customProviderType && customName.trim() &&
(customProviderType === 'shakespeare' || customProviderType === 'nsite' ||
(customApiKey.trim() &&
(customProviderType === 'shakespeare' || customProviderType === 'nsite' ||
(customApiKey.trim() &&
(customProviderType !== 'cloudflare' || customAccountId.trim()) &&
(customProviderType !== 'deno' || customOrganizationId.trim())));
-16
View File
@@ -2,7 +2,6 @@ import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Rocket, ChevronDown } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { ExternalInput } from '@/components/ui/external-input';
import {
Dialog,
@@ -54,21 +53,6 @@ interface AddProviderDialogProps {
onAdd: (apiKey: string, accountId?: string, organizationId?: string) => void;
}
/**
* Normalize a URL string to ensure it has a protocol
* @param url - The URL string to normalize
* @returns A fully-qualified URL string
*/
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}`;
}
function getProviderUrl(preset: PresetProvider): string | null {
switch (preset.type) {
case 'shakespeare':
+28 -19
View File
@@ -1,5 +1,6 @@
import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import type React from 'react';
import { TestApp } from '@/test/TestApp';
import { AISettings } from './AISettings';
@@ -18,6 +19,7 @@ vi.mock('@/hooks/useAISettings', () => ({
updateSettings: vi.fn(),
addRecentlyUsedModel: vi.fn(),
isConfigured: false,
isLoading: false,
})),
}));
@@ -46,39 +48,51 @@ describe('AISettings', () => {
users: [],
});
const user = userEvent.setup();
render(
<TestApp>
<AISettings />
</TestApp>
);
// Should show login requirement for Shakespeare AI (Nostr preset)
expect(screen.getByText('Log in to Nostr to use this provider')).toBeInTheDocument();
// Find and click on the Shakespeare AI tile (Nostr preset)
const shakespeareTile = screen.getByText('Shakespeare AI');
await user.click(shakespeareTile);
// Wait for dialog to open and show login requirement
await waitFor(() => {
expect(screen.getByText('Log in to Nostr to use this provider')).toBeInTheDocument();
});
expect(screen.getByText('Go to Nostr Settings')).toBeInTheDocument();
});
it('shows Add button for Nostr presets when user is logged in', async () => {
it('shows API key input for Nostr presets when user is logged in', async () => {
const { useCurrentUser } = await import('@/hooks/useCurrentUser');
vi.mocked(useCurrentUser).mockReturnValue({
user: { pubkey: 'test-pubkey' } as NonNullable<ReturnType<typeof useCurrentUser>['user']>,
users: [],
});
const user = userEvent.setup();
render(
<TestApp>
<AISettings />
</TestApp>
);
// Should show Add button for Shakespeare AI (Nostr preset)
const addButtons = screen.getAllByText('Add');
expect(addButtons.length).toBeGreaterThan(0);
// Find and click on the Shakespeare AI tile (Nostr preset)
const shakespeareTile = screen.getByText('Shakespeare AI');
await user.click(shakespeareTile);
// Should not show login requirement
expect(screen.queryByText('Log in to Nostr to use this provider')).not.toBeInTheDocument();
// Wait for dialog to open - should NOT show login requirement
await waitFor(() => {
expect(screen.queryByText('Log in to Nostr to use this provider')).not.toBeInTheDocument();
});
});
it('shows normal input and Add button for non-Nostr presets regardless of login status', async () => {
it('shows provider tiles for presets', async () => {
const { useCurrentUser } = await import('@/hooks/useCurrentUser');
vi.mocked(useCurrentUser).mockReturnValue({
user: undefined,
@@ -91,14 +105,9 @@ describe('AISettings', () => {
</TestApp>
);
// Should show API key inputs for non-Nostr presets like OpenAI
const openAIElements = screen.getAllByText('OpenAI');
expect(openAIElements.length).toBeGreaterThan(0);
const openRouterElements = screen.getAllByText('OpenRouter');
expect(openRouterElements.length).toBeGreaterThan(0);
// Should show Add buttons for non-Nostr presets
const addButtons = screen.getAllByText('Add');
expect(addButtons.length).toBeGreaterThan(0);
// Should show provider tiles for presets like OpenAI
expect(screen.getByText('OpenAI')).toBeInTheDocument();
expect(screen.getByText('OpenRouter')).toBeInTheDocument();
expect(screen.getByText('Shakespeare AI')).toBeInTheDocument();
});
});
+2 -3
View File
@@ -85,9 +85,8 @@ export function AISettings() {
setProvider(newProvider);
};
const handleAddCustomProvider = (provider: any) => {
const newProvider: AIProvider = provider;
setProvider(newProvider);
const handleAddCustomProvider = (provider: AIProvider) => {
setProvider(provider);
};
const handleRemoveProvider = (id: string) => {
+4 -4
View File
@@ -34,7 +34,7 @@ interface ProviderTileProps {
onClick: () => void;
}
function ProviderTile({ provider, preset, onClick }: ProviderTileProps) {
function ProviderTile({ provider, onClick }: ProviderTileProps) {
const url = getProviderUrl(provider);
return (
@@ -344,11 +344,11 @@ export function DeploySettings() {
setProviders([...settings.providers, newProvider]);
};
const handleAddCustomProvider = (provider: any) => {
const handleAddCustomProvider = (provider: Omit<DeployProvider, 'id'>) => {
const newProvider: DeployProvider = {
id: generateCustomProviderId(provider.type),
...provider,
};
} as DeployProvider;
setProviders([...settings.providers, newProvider]);
};
@@ -458,7 +458,7 @@ export function DeploySettings() {
isLoggedIntoNostr={!!user}
oauthHook={
selectedPreset.type === 'netlify' ? netlifyOAuth :
selectedPreset.type === 'vercel' ? vercelOAuth : null
selectedPreset.type === 'vercel' ? vercelOAuth : null
}
forceManualEntry={forceManualEntry[selectedPreset.id] || false}
onSetForceManualEntry={(force) =>
+2 -2
View File
@@ -84,10 +84,10 @@ export function GitSettings() {
addCredential(newCredential);
};
const handleAddCustomCredential = (credential: any) => {
const handleAddCustomCredential = (credential: Omit<GitCredential, 'id'>) => {
const newCredential: GitCredential = {
id: crypto.randomUUID(),
...credential,
id: crypto.randomUUID(),
};
addCredential(newCredential);