-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "jan", | ||
"version": "0.1.3", | ||
"version": "0.1.1736316956", | ||
"main": "./build/main.js", | ||
"author": "Jan <[email protected]>", | ||
"license": "MIT", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,45 @@ | ||
import { useState, useEffect, useMemo } from 'react' | ||
import { useMemo } from 'react' | ||
|
||
import { useAtomValue } from 'jotai' | ||
|
||
import { isLocalEngine } from '@/utils/modelEngine' | ||
|
||
import { extensionManager } from '@/extension' | ||
import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom' | ||
import { threadsAtom } from '@/helpers/atoms/Thread.atom' | ||
Check failure on line 8 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-macos
Check failure on line 8 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-ubuntu
Check failure on line 8 in web/hooks/useStarterScreen.ts GitHub Actions / coverage-check
|
||
import { InferenceEngine, EngineConfig } from '@janhq/core/.' | ||
Check failure on line 9 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-macos
Check failure on line 9 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-macos
Check failure on line 9 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-ubuntu
Check failure on line 9 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-ubuntu
Check failure on line 9 in web/hooks/useStarterScreen.ts GitHub Actions / coverage-check
Check failure on line 9 in web/hooks/useStarterScreen.ts GitHub Actions / coverage-check
Check failure on line 9 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-windows-pr
|
||
import { useGetEngines } from './useEngineManagement' | ||
Check failure on line 10 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-macos
Check failure on line 10 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-ubuntu
Check failure on line 10 in web/hooks/useStarterScreen.ts GitHub Actions / coverage-check
|
||
|
||
export function useStarterScreen() { | ||
const downloadedModels = useAtomValue(downloadedModelsAtom) | ||
const threads = useAtomValue(threadsAtom) | ||
|
||
const { engines } = useGetEngines() | ||
|
||
const remoteEngines = | ||
engines && | ||
Object.entries(engines) | ||
.filter(([key]) => !isLocalEngine(key as InferenceEngine)) | ||
.flatMap(([_, engineArray]) => engineArray as EngineConfig) | ||
Check warning on line 22 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-macos
Check warning on line 22 in web/hooks/useStarterScreen.ts GitHub Actions / test-on-ubuntu
Check warning on line 22 in web/hooks/useStarterScreen.ts GitHub Actions / coverage-check
|
||
|
||
const isDownloadALocalModel = useMemo( | ||
() => downloadedModels.some((x) => isLocalEngine(x.engine)), | ||
[downloadedModels] | ||
) | ||
|
||
const [extensionHasSettings, setExtensionHasSettings] = useState< | ||
{ name?: string; setting: string; apiKey: string; provider: string }[] | ||
>([]) | ||
|
||
useEffect(() => { | ||
const getAllSettings = async () => { | ||
const extensionsMenu: { | ||
name?: string | ||
setting: string | ||
apiKey: string | ||
provider: string | ||
}[] = [] | ||
const extensions = extensionManager.getAll() | ||
|
||
for (const extension of extensions) { | ||
if (typeof extension.getSettings === 'function') { | ||
const settings = await extension.getSettings() | ||
|
||
if ( | ||
(settings && settings.length > 0) || | ||
(await extension.installationState()) !== 'NotRequired' | ||
) { | ||
extensionsMenu.push({ | ||
name: extension.productName, | ||
setting: extension.name, | ||
apiKey: | ||
'apiKey' in extension && typeof extension.apiKey === 'string' | ||
? extension.apiKey | ||
: '', | ||
provider: | ||
'provider' in extension && | ||
typeof extension.provider === 'string' | ||
? extension.provider | ||
: '', | ||
}) | ||
} | ||
} | ||
} | ||
setExtensionHasSettings(extensionsMenu) | ||
} | ||
getAllSettings() | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []) | ||
|
||
const isAnyRemoteModelConfigured = useMemo( | ||
() => extensionHasSettings.some((x) => x.apiKey.length > 1), | ||
[extensionHasSettings] | ||
() => (remoteEngines ?? []).some((x) => x.api_key && x.api_key.length > 0), | ||
[remoteEngines] | ||
) | ||
|
||
console.log(isAnyRemoteModelConfigured) | ||
|
||
const isShowStarterScreen = useMemo( | ||
() => | ||
!isAnyRemoteModelConfigured && !isDownloadALocalModel && !threads.length, | ||
[isAnyRemoteModelConfigured, isDownloadALocalModel, threads] | ||
) | ||
|
||
return { | ||
extensionHasSettings, | ||
isShowStarterScreen, | ||
} | ||
} |