Merge branch 'main' into diff-view-v2
This commit is contained in:
@@ -2,8 +2,6 @@ import { useStore } from '@nanostores/react';
|
||||
import {
|
||||
isDebugMode,
|
||||
isEventLogsEnabled,
|
||||
isLocalModelsEnabled,
|
||||
LOCAL_PROVIDERS,
|
||||
promptStore,
|
||||
providersStore,
|
||||
latestBranchStore,
|
||||
@@ -17,7 +15,6 @@ import {
|
||||
updateAutoSelectTemplate,
|
||||
updateContextOptimization,
|
||||
updateEventLogs,
|
||||
updateLocalModels,
|
||||
updatePromptId,
|
||||
} from '~/lib/stores/settings';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
@@ -49,8 +46,6 @@ export interface UseSettingsReturn {
|
||||
providers: Record<string, IProviderConfig>;
|
||||
activeProviders: ProviderInfo[];
|
||||
updateProviderSettings: (provider: string, config: IProviderSetting) => void;
|
||||
isLocalModel: boolean;
|
||||
enableLocalModels: (enabled: boolean) => void;
|
||||
|
||||
// Debug and development settings
|
||||
debug: boolean;
|
||||
@@ -81,7 +76,6 @@ export function useSettings(): UseSettingsReturn {
|
||||
const debug = useStore(isDebugMode);
|
||||
const eventLogs = useStore(isEventLogsEnabled);
|
||||
const promptId = useStore(promptStore);
|
||||
const isLocalModel = useStore(isLocalModelsEnabled);
|
||||
const isLatestBranch = useStore(latestBranchStore);
|
||||
const autoSelectTemplate = useStore(autoSelectStarterTemplate);
|
||||
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
|
||||
@@ -100,16 +94,12 @@ export function useSettings(): UseSettingsReturn {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
let active = Object.entries(providers)
|
||||
const active = Object.entries(providers)
|
||||
.filter(([_key, provider]) => provider.settings.enabled)
|
||||
.map(([_k, p]) => p);
|
||||
|
||||
if (!isLocalModel) {
|
||||
active = active.filter((p) => !LOCAL_PROVIDERS.includes(p.name));
|
||||
}
|
||||
|
||||
setActiveProviders(active);
|
||||
}, [providers, isLocalModel]);
|
||||
}, [providers]);
|
||||
|
||||
const saveSettings = useCallback((newSettings: Partial<Settings>) => {
|
||||
setSettings((prev) => {
|
||||
@@ -135,11 +125,6 @@ export function useSettings(): UseSettingsReturn {
|
||||
logStore.logSystem(`Event logs ${enabled ? 'enabled' : 'disabled'}`);
|
||||
}, []);
|
||||
|
||||
const enableLocalModels = useCallback((enabled: boolean) => {
|
||||
updateLocalModels(enabled);
|
||||
logStore.logSystem(`Local models ${enabled ? 'enabled' : 'disabled'}`);
|
||||
}, []);
|
||||
|
||||
const setPromptId = useCallback((id: string) => {
|
||||
updatePromptId(id);
|
||||
logStore.logSystem(`Prompt template updated to ${id}`);
|
||||
@@ -188,14 +173,11 @@ export function useSettings(): UseSettingsReturn {
|
||||
[saveSettings],
|
||||
);
|
||||
|
||||
// Fix the providers cookie sync
|
||||
useEffect(() => {
|
||||
const providers = providersStore.get();
|
||||
const providerSetting: Record<string, { enabled: boolean }> = {};
|
||||
const providerSetting: Record<string, IProviderSetting> = {}; // preserve the entire settings object for each provider
|
||||
Object.keys(providers).forEach((provider) => {
|
||||
providerSetting[provider] = {
|
||||
enabled: providers[provider].settings.enabled || false, // Add fallback for undefined
|
||||
};
|
||||
providerSetting[provider] = providers[provider].settings;
|
||||
});
|
||||
Cookies.set('providers', JSON.stringify(providerSetting));
|
||||
}, [providers]);
|
||||
@@ -205,8 +187,6 @@ export function useSettings(): UseSettingsReturn {
|
||||
providers,
|
||||
activeProviders,
|
||||
updateProviderSettings,
|
||||
isLocalModel,
|
||||
enableLocalModels,
|
||||
debug,
|
||||
enableDebugMode,
|
||||
eventLogs,
|
||||
|
||||
@@ -20,6 +20,12 @@ export default class AmazonBedrockProvider extends BaseProvider {
|
||||
};
|
||||
|
||||
staticModels: ModelInfo[] = [
|
||||
{
|
||||
name: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
|
||||
label: 'Claude 3.5 Sonnet v2 (Bedrock)',
|
||||
provider: 'AmazonBedrock',
|
||||
maxTokenAllowed: 200000,
|
||||
},
|
||||
{
|
||||
name: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
|
||||
label: 'Claude 3.5 Sonnet (Bedrock)',
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { atom, map } from 'nanostores';
|
||||
import { workbenchStore } from './workbench';
|
||||
import { PROVIDER_LIST } from '~/utils/constants';
|
||||
import type { IProviderConfig } from '~/types/model';
|
||||
import type {
|
||||
@@ -11,7 +10,7 @@ import type {
|
||||
import { DEFAULT_TAB_CONFIG } from '~/components/@settings/core/constants';
|
||||
import Cookies from 'js-cookie';
|
||||
import { toggleTheme } from './theme';
|
||||
import { chatStore } from './chat';
|
||||
import { create } from 'zustand';
|
||||
|
||||
export interface Shortcut {
|
||||
key: string;
|
||||
@@ -26,10 +25,8 @@ export interface Shortcut {
|
||||
}
|
||||
|
||||
export interface Shortcuts {
|
||||
toggleTerminal: Shortcut;
|
||||
toggleTheme: Shortcut;
|
||||
toggleChat: Shortcut;
|
||||
toggleSettings: Shortcut;
|
||||
toggleTerminal: Shortcut;
|
||||
}
|
||||
|
||||
export const URL_CONFIGURABLE_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
|
||||
@@ -37,15 +34,8 @@ export const LOCAL_PROVIDERS = ['OpenAILike', 'LMStudio', 'Ollama'];
|
||||
|
||||
export type ProviderSetting = Record<string, IProviderConfig>;
|
||||
|
||||
// Define safer shortcuts that don't conflict with browser defaults
|
||||
// Simplified shortcuts store with only theme toggle
|
||||
export const shortcutsStore = map<Shortcuts>({
|
||||
toggleTerminal: {
|
||||
key: '`',
|
||||
ctrlOrMetaKey: true,
|
||||
action: () => workbenchStore.toggleTerminal(),
|
||||
description: 'Toggle terminal',
|
||||
isPreventDefault: true,
|
||||
},
|
||||
toggleTheme: {
|
||||
key: 'd',
|
||||
metaKey: true,
|
||||
@@ -55,22 +45,13 @@ export const shortcutsStore = map<Shortcuts>({
|
||||
description: 'Toggle theme',
|
||||
isPreventDefault: true,
|
||||
},
|
||||
toggleChat: {
|
||||
key: 'j', // Changed from 'k' to 'j' to avoid conflicts
|
||||
toggleTerminal: {
|
||||
key: '`',
|
||||
ctrlOrMetaKey: true,
|
||||
altKey: true, // Added alt key to make it more unique
|
||||
action: () => chatStore.setKey('showChat', !chatStore.get().showChat),
|
||||
description: 'Toggle chat',
|
||||
isPreventDefault: true,
|
||||
},
|
||||
toggleSettings: {
|
||||
key: 's',
|
||||
ctrlOrMetaKey: true,
|
||||
altKey: true,
|
||||
action: () => {
|
||||
document.dispatchEvent(new CustomEvent('toggle-settings'));
|
||||
// This will be handled by the terminal component
|
||||
},
|
||||
description: 'Toggle settings',
|
||||
description: 'Toggle terminal',
|
||||
isPreventDefault: true,
|
||||
},
|
||||
});
|
||||
@@ -148,7 +129,6 @@ const SETTINGS_KEYS = {
|
||||
AUTO_SELECT_TEMPLATE: 'autoSelectTemplate',
|
||||
CONTEXT_OPTIMIZATION: 'contextOptimizationEnabled',
|
||||
EVENT_LOGS: 'isEventLogsEnabled',
|
||||
LOCAL_MODELS: 'isLocalModelsEnabled',
|
||||
PROMPT_ID: 'promptId',
|
||||
DEVELOPER_MODE: 'isDeveloperMode',
|
||||
} as const;
|
||||
@@ -175,10 +155,9 @@ const getInitialSettings = () => {
|
||||
|
||||
return {
|
||||
latestBranch: getStoredBoolean(SETTINGS_KEYS.LATEST_BRANCH, false),
|
||||
autoSelectTemplate: getStoredBoolean(SETTINGS_KEYS.AUTO_SELECT_TEMPLATE, false),
|
||||
contextOptimization: getStoredBoolean(SETTINGS_KEYS.CONTEXT_OPTIMIZATION, false),
|
||||
autoSelectTemplate: getStoredBoolean(SETTINGS_KEYS.AUTO_SELECT_TEMPLATE, true),
|
||||
contextOptimization: getStoredBoolean(SETTINGS_KEYS.CONTEXT_OPTIMIZATION, true),
|
||||
eventLogs: getStoredBoolean(SETTINGS_KEYS.EVENT_LOGS, true),
|
||||
localModels: getStoredBoolean(SETTINGS_KEYS.LOCAL_MODELS, true),
|
||||
promptId: isBrowser ? localStorage.getItem(SETTINGS_KEYS.PROMPT_ID) || 'default' : 'default',
|
||||
developerMode: getStoredBoolean(SETTINGS_KEYS.DEVELOPER_MODE, false),
|
||||
};
|
||||
@@ -191,7 +170,6 @@ export const latestBranchStore = atom<boolean>(initialSettings.latestBranch);
|
||||
export const autoSelectStarterTemplate = atom<boolean>(initialSettings.autoSelectTemplate);
|
||||
export const enableContextOptimizationStore = atom<boolean>(initialSettings.contextOptimization);
|
||||
export const isEventLogsEnabled = atom<boolean>(initialSettings.eventLogs);
|
||||
export const isLocalModelsEnabled = atom<boolean>(initialSettings.localModels);
|
||||
export const promptStore = atom<string>(initialSettings.promptId);
|
||||
|
||||
// Helper functions to update settings with persistence
|
||||
@@ -215,11 +193,6 @@ export const updateEventLogs = (enabled: boolean) => {
|
||||
localStorage.setItem(SETTINGS_KEYS.EVENT_LOGS, JSON.stringify(enabled));
|
||||
};
|
||||
|
||||
export const updateLocalModels = (enabled: boolean) => {
|
||||
isLocalModelsEnabled.set(enabled);
|
||||
localStorage.setItem(SETTINGS_KEYS.LOCAL_MODELS, JSON.stringify(enabled));
|
||||
};
|
||||
|
||||
export const updatePromptId = (id: string) => {
|
||||
promptStore.set(id);
|
||||
localStorage.setItem(SETTINGS_KEYS.PROMPT_ID, id);
|
||||
@@ -319,3 +292,35 @@ export const setDeveloperMode = (value: boolean) => {
|
||||
localStorage.setItem(SETTINGS_KEYS.DEVELOPER_MODE, JSON.stringify(value));
|
||||
}
|
||||
};
|
||||
|
||||
// First, let's define the SettingsStore interface
|
||||
interface SettingsStore {
|
||||
isOpen: boolean;
|
||||
selectedTab: string;
|
||||
openSettings: () => void;
|
||||
closeSettings: () => void;
|
||||
setSelectedTab: (tab: string) => void;
|
||||
}
|
||||
|
||||
export const useSettingsStore = create<SettingsStore>((set) => ({
|
||||
isOpen: false,
|
||||
selectedTab: 'user', // Default tab
|
||||
|
||||
openSettings: () => {
|
||||
set({
|
||||
isOpen: true,
|
||||
selectedTab: 'user', // Always open to user tab
|
||||
});
|
||||
},
|
||||
|
||||
closeSettings: () => {
|
||||
set({
|
||||
isOpen: false,
|
||||
selectedTab: 'user', // Reset to user tab when closing
|
||||
});
|
||||
},
|
||||
|
||||
setSelectedTab: (tab: string) => {
|
||||
set({ selectedTab: tab });
|
||||
},
|
||||
}));
|
||||
|
||||
Reference in New Issue
Block a user