Commit
·
c5c3eee
1
Parent(s):
69b1dc4
Update useSettings.tsx
Browse filesif it has not been set by the user yet set it correctly for them
app/lib/hooks/useSettings.tsx
CHANGED
@@ -11,6 +11,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|
11 |
import Cookies from 'js-cookie';
|
12 |
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
13 |
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
|
|
|
14 |
|
15 |
export function useSettings() {
|
16 |
const providers = useStore(providersStore);
|
@@ -20,6 +21,22 @@ export function useSettings() {
|
|
20 |
const useLatest = useStore(useLatestBranch);
|
21 |
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
// reading values from cookies on mount
|
24 |
useEffect(() => {
|
25 |
const savedProviders = Cookies.get('providers');
|
@@ -63,10 +80,16 @@ export function useSettings() {
|
|
63 |
isLocalModelsEnabled.set(savedLocalModels === 'true');
|
64 |
}
|
65 |
|
66 |
-
// load latest branch setting from cookies
|
67 |
const savedLatestBranch = Cookies.get('useLatestBranch');
|
68 |
-
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
useLatestBranch.set(savedLatestBranch === 'true');
|
71 |
}
|
72 |
}, []);
|
|
|
11 |
import Cookies from 'js-cookie';
|
12 |
import type { IProviderSetting, ProviderInfo } from '~/types/model';
|
13 |
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
|
14 |
+
import commit from '~/commit.json';
|
15 |
|
16 |
export function useSettings() {
|
17 |
const providers = useStore(providersStore);
|
|
|
21 |
const useLatest = useStore(useLatestBranch);
|
22 |
const [activeProviders, setActiveProviders] = useState<ProviderInfo[]>([]);
|
23 |
|
24 |
+
// Function to check if we're on stable version
|
25 |
+
const checkIsStableVersion = async () => {
|
26 |
+
try {
|
27 |
+
const stableResponse = await fetch('https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/stable/app/commit.json');
|
28 |
+
if (!stableResponse.ok) {
|
29 |
+
console.warn('Failed to fetch stable commit info');
|
30 |
+
return false;
|
31 |
+
}
|
32 |
+
const stableData = await stableResponse.json();
|
33 |
+
return commit.commit === stableData.commit;
|
34 |
+
} catch (error) {
|
35 |
+
console.warn('Error checking stable version:', error);
|
36 |
+
return false;
|
37 |
+
}
|
38 |
+
};
|
39 |
+
|
40 |
// reading values from cookies on mount
|
41 |
useEffect(() => {
|
42 |
const savedProviders = Cookies.get('providers');
|
|
|
80 |
isLocalModelsEnabled.set(savedLocalModels === 'true');
|
81 |
}
|
82 |
|
83 |
+
// load latest branch setting from cookies or determine based on version
|
84 |
const savedLatestBranch = Cookies.get('useLatestBranch');
|
85 |
+
if (savedLatestBranch === undefined) {
|
86 |
+
// If setting hasn't been set by user, check version
|
87 |
+
checkIsStableVersion().then(isStable => {
|
88 |
+
const shouldUseLatest = !isStable;
|
89 |
+
useLatestBranch.set(shouldUseLatest);
|
90 |
+
Cookies.set('useLatestBranch', String(shouldUseLatest));
|
91 |
+
});
|
92 |
+
} else {
|
93 |
useLatestBranch.set(savedLatestBranch === 'true');
|
94 |
}
|
95 |
}, []);
|