Merge branch 'main' into token-usage
This commit is contained in:
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user