From 2acc0191ad90d55687866779d3e4a14785b6c981 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 30 Dec 2025 20:32:50 -0600 Subject: [PATCH] Fix type errors --- src/components/AddCustomAIProviderDialog.tsx | 12 +- src/components/AddCustomProviderDialog.tsx | 129 ++++++++++++------- src/components/AddProviderDialog.tsx | 16 --- src/pages/AISettings.test.tsx | 47 ++++--- src/pages/AISettings.tsx | 5 +- src/pages/DeploySettings.tsx | 8 +- src/pages/GitSettings.tsx | 4 +- 7 files changed, 121 insertions(+), 100 deletions(-) diff --git a/src/components/AddCustomAIProviderDialog.tsx b/src/components/AddCustomAIProviderDialog.tsx index fd7f834e..9f74b6bb 100644 --- a/src/components/AddCustomAIProviderDialog.tsx +++ b/src/components/AddCustomAIProviderDialog.tsx @@ -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(), diff --git a/src/components/AddCustomProviderDialog.tsx b/src/components/AddCustomProviderDialog.tsx index 71860954..1bd97b3c 100644 --- a/src/components/AddCustomProviderDialog.tsx +++ b/src/components/AddCustomProviderDialog.tsx @@ -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 + | Omit + | Omit + | Omit + | Omit + | Omit; 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()))); diff --git a/src/components/AddProviderDialog.tsx b/src/components/AddProviderDialog.tsx index 6dd97a34..59e78bb8 100644 --- a/src/components/AddProviderDialog.tsx +++ b/src/components/AddProviderDialog.tsx @@ -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': diff --git a/src/pages/AISettings.test.tsx b/src/pages/AISettings.test.tsx index f945ec4d..f80e3a44 100644 --- a/src/pages/AISettings.test.tsx +++ b/src/pages/AISettings.test.tsx @@ -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( ); - // 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['user']>, users: [], }); + const user = userEvent.setup(); + render( ); - // 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', () => { ); - // 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(); }); }); \ No newline at end of file diff --git a/src/pages/AISettings.tsx b/src/pages/AISettings.tsx index a1793df3..fa7c2a04 100644 --- a/src/pages/AISettings.tsx +++ b/src/pages/AISettings.tsx @@ -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) => { diff --git a/src/pages/DeploySettings.tsx b/src/pages/DeploySettings.tsx index 7bc953a0..735984aa 100644 --- a/src/pages/DeploySettings.tsx +++ b/src/pages/DeploySettings.tsx @@ -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) => { 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) => diff --git a/src/pages/GitSettings.tsx b/src/pages/GitSettings.tsx index 2bac2809..ea585e53 100644 --- a/src/pages/GitSettings.tsx +++ b/src/pages/GitSettings.tsx @@ -84,10 +84,10 @@ export function GitSettings() { addCredential(newCredential); }; - const handleAddCustomCredential = (credential: any) => { + const handleAddCustomCredential = (credential: Omit) => { const newCredential: GitCredential = { - id: crypto.randomUUID(), ...credential, + id: crypto.randomUUID(), }; addCredential(newCredential);