Merge branch 'main' into token-usage

This commit is contained in:
Anirban Kar
2024-12-16 19:56:20 +05:30
committed by GitHub
7 changed files with 49 additions and 55 deletions

View File

@@ -5,7 +5,7 @@ import {
isLocalModelsEnabled,
LOCAL_PROVIDERS,
providersStore,
latestBranch,
latestBranchStore,
} from '~/lib/stores/settings';
import { useCallback, useEffect, useState } from 'react';
import Cookies from 'js-cookie';
@@ -15,21 +15,24 @@ import commit from '~/commit.json';
interface CommitData {
commit: string;
version?: string;
}
const commitJson: CommitData = commit;
export function useSettings() {
const providers = useStore(providersStore);
const debug = useStore(isDebugMode);
const eventLogs = useStore(isEventLogsEnabled);
const isLocalModel = useStore(isLocalModelsEnabled);
const useLatest = useStore(latestBranch);
const latestBranch = useStore(latestBranchStore);
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
// Function to check if we're on stable version
const checkIsStableVersion = async () => {
try {
const stableResponse = await fetch(
'https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/stable/app/commit.json',
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/refs/tags/v${commitJson.version}/app/commit.json`,
);
if (!stableResponse.ok) {
@@ -90,17 +93,22 @@ export function useSettings() {
}
// load latest branch setting from cookies or determine based on version
const savedLatestBranch = Cookies.get('useLatestBranch');
const savedLatestBranch = Cookies.get('latestBranch');
let checkCommit = Cookies.get('commitHash');
if (savedLatestBranch === undefined) {
if (checkCommit === undefined) {
checkCommit = commit.commit;
}
if (savedLatestBranch === undefined || checkCommit !== commit.commit) {
// If setting hasn't been set by user, check version
checkIsStableVersion().then((isStable) => {
const shouldUseLatest = !isStable;
latestBranch.set(shouldUseLatest);
Cookies.set('useLatestBranch', String(shouldUseLatest));
latestBranchStore.set(shouldUseLatest);
Cookies.set('latestBranch', String(shouldUseLatest));
Cookies.set('commitHash', String(commit.commit));
});
} else {
latestBranch.set(savedLatestBranch === 'true');
latestBranchStore.set(savedLatestBranch === 'true');
}
}, []);
@@ -154,9 +162,9 @@ export function useSettings() {
}, []);
const enableLatestBranch = useCallback((enabled: boolean) => {
latestBranch.set(enabled);
latestBranchStore.set(enabled);
logStore.logSystem(`Main branch updates ${enabled ? 'enabled' : 'disabled'}`);
Cookies.set('useLatestBranch', String(enabled));
Cookies.set('latestBranch', String(enabled));
}, []);
return {
@@ -169,7 +177,7 @@ export function useSettings() {
enableEventLogs,
isLocalModel,
enableLocalModels,
useLatestBranch: useLatest,
latestBranch,
enableLatestBranch,
};
}