mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Revert "Fix default settings overriding user's recently used models"
This reverts commit 2736f71687.
This commit is contained in:
5 files changed
+15
-58
No files matched your search
@@ -36,27 +36,17 @@ describe('AISettingsProvider', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should initialize with OpenCode defaults for new users (no providers)', async () => {
|
it('should initialize with empty recentlyUsedModels array', async () => {
|
||||||
const { result } = renderHook(() => useAISettings(), {
|
const { result } = renderHook(() => useAISettings(), {
|
||||||
wrapper: ({ children }) => <TestApp>{children}</TestApp>,
|
wrapper: ({ children }) => <TestApp>{children}</TestApp>,
|
||||||
});
|
});
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
// New users with no providers get OPENCODE_DEFAULT_SETTINGS with big-pickle
|
expect(result.current.settings.recentlyUsedModels).toEqual([]);
|
||||||
expect(result.current.settings.providers).toHaveLength(1);
|
|
||||||
expect(result.current.settings.providers[0].id).toBe('opencode');
|
|
||||||
expect(result.current.settings.recentlyUsedModels).toEqual(['opencode/big-pickle']);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should add recently used models correctly', async () => {
|
it('should add recently used models correctly', async () => {
|
||||||
// Simulate existing user with a provider configured
|
|
||||||
const { readAISettings } = await import('@/lib/configUtils');
|
|
||||||
vi.mocked(readAISettings).mockResolvedValue({
|
|
||||||
providers: [{ id: 'openrouter', name: 'OpenRouter', baseURL: 'https://openrouter.ai/api/v1', apiKey: 'test-key' }],
|
|
||||||
recentlyUsedModels: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
const { result } = renderHook(() => useAISettings(), {
|
const { result } = renderHook(() => useAISettings(), {
|
||||||
wrapper: ({ children }) => <TestApp>{children}</TestApp>,
|
wrapper: ({ children }) => <TestApp>{children}</TestApp>,
|
||||||
});
|
});
|
||||||
@@ -75,13 +65,6 @@ describe('AISettingsProvider', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should move existing model to front when used again', async () => {
|
it('should move existing model to front when used again', async () => {
|
||||||
// Simulate existing user with a provider configured
|
|
||||||
const { readAISettings } = await import('@/lib/configUtils');
|
|
||||||
vi.mocked(readAISettings).mockResolvedValue({
|
|
||||||
providers: [{ id: 'openrouter', name: 'OpenRouter', baseURL: 'https://openrouter.ai/api/v1', apiKey: 'test-key' }],
|
|
||||||
recentlyUsedModels: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
const { result } = renderHook(() => useAISettings(), {
|
const { result } = renderHook(() => useAISettings(), {
|
||||||
wrapper: ({ children }) => <TestApp>{children}</TestApp>,
|
wrapper: ({ children }) => <TestApp>{children}</TestApp>,
|
||||||
});
|
});
|
||||||
@@ -116,13 +99,6 @@ describe('AISettingsProvider', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should limit recently used models to 10 items', async () => {
|
it('should limit recently used models to 10 items', async () => {
|
||||||
// Simulate existing user with a provider configured
|
|
||||||
const { readAISettings } = await import('@/lib/configUtils');
|
|
||||||
vi.mocked(readAISettings).mockResolvedValue({
|
|
||||||
providers: [{ id: 'openrouter', name: 'OpenRouter', baseURL: 'https://openrouter.ai/api/v1', apiKey: 'test-key' }],
|
|
||||||
recentlyUsedModels: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
const { result } = renderHook(() => useAISettings(), {
|
const { result } = renderHook(() => useAISettings(), {
|
||||||
wrapper: ({ children }) => <TestApp>{children}</TestApp>,
|
wrapper: ({ children }) => <TestApp>{children}</TestApp>,
|
||||||
});
|
});
|
||||||
@@ -171,13 +147,6 @@ describe('AISettingsProvider', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should invalidate provider-models query when updateSettings is called with providers', async () => {
|
it('should invalidate provider-models query when updateSettings is called with providers', async () => {
|
||||||
// Simulate existing user with a provider configured
|
|
||||||
const { readAISettings } = await import('@/lib/configUtils');
|
|
||||||
vi.mocked(readAISettings).mockResolvedValue({
|
|
||||||
providers: [{ id: 'openrouter', name: 'OpenRouter', baseURL: 'https://openrouter.ai/api/v1', apiKey: 'test-key' }],
|
|
||||||
recentlyUsedModels: [],
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mock the QueryClient.invalidateQueries method
|
// Mock the QueryClient.invalidateQueries method
|
||||||
const mockInvalidateQueries = vi.fn();
|
const mockInvalidateQueries = vi.fn();
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { AISettingsContext, type AISettings, type AIProvider, type MCPServer, ty
|
|||||||
import { useFS } from '@/hooks/useFS';
|
import { useFS } from '@/hooks/useFS';
|
||||||
import { useFSPaths } from '@/hooks/useFSPaths';
|
import { useFSPaths } from '@/hooks/useFSPaths';
|
||||||
import { readAISettings, writeAISettings } from '@/lib/configUtils';
|
import { readAISettings, writeAISettings } from '@/lib/configUtils';
|
||||||
import { EMPTY_AI_SETTINGS, OPENCODE_DEFAULT_SETTINGS } from '@/lib/opencode-defaults';
|
import { OPENCODE_DEFAULT_SETTINGS } from '@/lib/opencode-defaults';
|
||||||
|
|
||||||
interface AISettingsProviderProps {
|
interface AISettingsProviderProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -14,23 +14,18 @@ export function AISettingsProvider({ children }: AISettingsProviderProps) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { fs } = useFS();
|
const { fs } = useFS();
|
||||||
const { configPath } = useFSPaths();
|
const { configPath } = useFSPaths();
|
||||||
const [settings, setSettings] = useState<AISettings>(EMPTY_AI_SETTINGS);
|
const [settings, setSettings] = useState<AISettings>(OPENCODE_DEFAULT_SETTINGS);
|
||||||
const [isInitialized, setIsInitialized] = useState(false);
|
const [isInitialized, setIsInitialized] = useState(false);
|
||||||
|
|
||||||
// Initialize settings from VFS on mount
|
// Initialize settings from VFS on mount
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const initializeSettings = async () => {
|
const initializeSettings = async () => {
|
||||||
try {
|
try {
|
||||||
const loaded = await readAISettings(fs, configPath);
|
const settings = await readAISettings(fs, configPath);
|
||||||
// Only apply OpenCode defaults for genuinely new users (no providers configured)
|
setSettings(settings);
|
||||||
if (loaded.providers.length === 0) {
|
|
||||||
setSettings(OPENCODE_DEFAULT_SETTINGS);
|
|
||||||
} else {
|
|
||||||
setSettings(loaded);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to initialize AI settings:', error);
|
console.error('Failed to initialize AI settings:', error);
|
||||||
setSettings(EMPTY_AI_SETTINGS);
|
setSettings(OPENCODE_DEFAULT_SETTINGS);
|
||||||
} finally {
|
} finally {
|
||||||
setIsInitialized(true);
|
setIsInitialized(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import {
|
|||||||
readDeploySettings,
|
readDeploySettings,
|
||||||
writeDeploySettings
|
writeDeploySettings
|
||||||
} from './configUtils';
|
} from './configUtils';
|
||||||
import { EMPTY_AI_SETTINGS } from './opencode-defaults';
|
import { OPENCODE_DEFAULT_SETTINGS } from './opencode-defaults';
|
||||||
import type { JSRuntimeFS } from './JSRuntime';
|
import type { JSRuntimeFS } from './JSRuntime';
|
||||||
import type { AISettings } from '@/contexts/AISettingsContext';
|
import type { AISettings } from '@/contexts/AISettingsContext';
|
||||||
import type { GitSettings } from '@/contexts/GitSettingsContext';
|
import type { GitSettings } from '@/contexts/GitSettingsContext';
|
||||||
@@ -90,22 +90,22 @@ describe('configUtils', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return empty settings if file does not exist and no localStorage data', async () => {
|
it('should return default settings with OpenCode Zen if file does not exist and no localStorage data', async () => {
|
||||||
vi.mocked(mockFS.readFile).mockRejectedValue(new Error('File not found'));
|
vi.mocked(mockFS.readFile).mockRejectedValue(new Error('File not found'));
|
||||||
mockLocalStorage.getItem.mockReturnValue(null);
|
mockLocalStorage.getItem.mockReturnValue(null);
|
||||||
|
|
||||||
const result = await readAISettings(mockFS);
|
const result = await readAISettings(mockFS);
|
||||||
|
|
||||||
expect(result).toEqual(EMPTY_AI_SETTINGS);
|
expect(result).toEqual(OPENCODE_DEFAULT_SETTINGS);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return empty settings if JSON is invalid and no localStorage data', async () => {
|
it('should return default settings with OpenCode Zen if JSON is invalid and no localStorage data', async () => {
|
||||||
vi.mocked(mockFS.readFile).mockResolvedValue('invalid json');
|
vi.mocked(mockFS.readFile).mockResolvedValue('invalid json');
|
||||||
mockLocalStorage.getItem.mockReturnValue(null);
|
mockLocalStorage.getItem.mockReturnValue(null);
|
||||||
|
|
||||||
const result = await readAISettings(mockFS);
|
const result = await readAISettings(mockFS);
|
||||||
|
|
||||||
expect(result).toEqual(EMPTY_AI_SETTINGS);
|
expect(result).toEqual(OPENCODE_DEFAULT_SETTINGS);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
import { filteredArray } from '@/lib/schema';
|
import { filteredArray } from '@/lib/schema';
|
||||||
import { AI_PROVIDER_PRESETS } from '@/lib/aiProviderPresets';
|
import { AI_PROVIDER_PRESETS } from '@/lib/aiProviderPresets';
|
||||||
import { EMPTY_AI_SETTINGS } from '@/lib/opencode-defaults';
|
import { OPENCODE_DEFAULT_SETTINGS } from '@/lib/opencode-defaults';
|
||||||
import type { JSRuntimeFS } from '@/lib/JSRuntime';
|
import type { JSRuntimeFS } from '@/lib/JSRuntime';
|
||||||
import type { AISettings, MCPServer } from '@/contexts/AISettingsContext';
|
import type { AISettings, MCPServer } from '@/contexts/AISettingsContext';
|
||||||
import type { GitSettings, GitCredential } from '@/contexts/GitSettingsContext';
|
import type { GitSettings, GitCredential } from '@/contexts/GitSettingsContext';
|
||||||
@@ -205,7 +205,7 @@ export async function readAISettings(fs: JSRuntimeFS, configPath = '/config'): P
|
|||||||
if (error instanceof z.ZodError) {
|
if (error instanceof z.ZodError) {
|
||||||
console.error('AI settings parsing error:', error.issues);
|
console.error('AI settings parsing error:', error.issues);
|
||||||
}
|
}
|
||||||
return EMPTY_AI_SETTINGS;
|
return OPENCODE_DEFAULT_SETTINGS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,14 +3,7 @@ import { AI_PROVIDER_PRESETS } from '@/lib/aiProviderPresets';
|
|||||||
|
|
||||||
const opencodePreset = AI_PROVIDER_PRESETS.find((p) => p.id === 'opencode')!;
|
const opencodePreset = AI_PROVIDER_PRESETS.find((p) => p.id === 'opencode')!;
|
||||||
|
|
||||||
/** Empty AI settings used as initial state and error fallback. Won't overwrite user data. */
|
/** Default AI settings with OpenCode Zen pre-configured and big-pickle selected. */
|
||||||
export const EMPTY_AI_SETTINGS: AISettings = {
|
|
||||||
providers: [],
|
|
||||||
recentlyUsedModels: [],
|
|
||||||
mcpServers: {},
|
|
||||||
};
|
|
||||||
|
|
||||||
/** Default AI settings with OpenCode Zen pre-configured and big-pickle selected. Only for genuinely new users. */
|
|
||||||
export const OPENCODE_DEFAULT_SETTINGS: AISettings = {
|
export const OPENCODE_DEFAULT_SETTINGS: AISettings = {
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user