* feat: remote engine management * chore: fix linter issue * chore: remove unused imports * fix: populate engines, models and legacy settings (#4403) * fix: populate engines, models and legacy settings * chore: legacy logics update configured remote engine * fix: check exist path before reading * fix: engines and models persist - race condition * chore: update issue state * test: update test cases * chore: bring back Cortex extension settings * chore: setup button gear / plus based apikey * chore: fix remote engine from welcome screen * chore: resolve linter issue * chore: support request headers template * chore: update engines using header_template instead of api_key_template * chore: update models on changes * fix: anthropic response template * chore: fix welcome screen and debounce update value input * chore: update engines list on changes * chore: update engines list on change * chore: update desc form add modal remote engines * chore: bump cortex version to latest RC * chore: fix linter * fix: transform payload of Anthropic and OpenAI * fix: typo * fix: openrouter model id for auto routing * chore: remove remote engine URL setting * chore: add cohere engine and model support * fix: should not clean on app launch - models list display issue * fix: local engine check logic * chore: bump app version to latest release 0.5.13 * test: fix failed tests --------- Co-authored-by: Louis <louis@jan.ai>
115 lines
3.3 KiB
TypeScript
115 lines
3.3 KiB
TypeScript
import {
|
|
EngineManager,
|
|
ErrorCode,
|
|
InferenceEngine,
|
|
ThreadMessage,
|
|
} from '@janhq/core'
|
|
|
|
import { useAtomValue, useSetAtom } from 'jotai'
|
|
|
|
import AutoLink from '@/containers/AutoLink'
|
|
import ModalTroubleShooting, {
|
|
modalTroubleShootingAtom,
|
|
} from '@/containers/ModalTroubleShoot'
|
|
|
|
import { MainViewState } from '@/constants/screens'
|
|
|
|
import { mainViewStateAtom } from '@/helpers/atoms/App.atom'
|
|
|
|
import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
|
|
import { selectedSettingAtom } from '@/helpers/atoms/Setting.atom'
|
|
|
|
const ErrorMessage = ({ message }: { message: ThreadMessage }) => {
|
|
const setModalTroubleShooting = useSetAtom(modalTroubleShootingAtom)
|
|
const setMainState = useSetAtom(mainViewStateAtom)
|
|
const setSelectedSettingScreen = useSetAtom(selectedSettingAtom)
|
|
const activeAssistant = useAtomValue(activeAssistantAtom)
|
|
|
|
const defaultDesc = () => {
|
|
return (
|
|
<>
|
|
<p>
|
|
{`Something's wrong.`} Access
|
|
<span
|
|
className="cursor-pointer text-[hsla(var(--app-link))] underline"
|
|
onClick={() => setModalTroubleShooting(true)}
|
|
>
|
|
troubleshooting assistance
|
|
</span>
|
|
now.
|
|
</p>
|
|
<ModalTroubleShooting />
|
|
</>
|
|
)
|
|
}
|
|
|
|
const getEngine = () => {
|
|
const engineName = activeAssistant?.model?.engine
|
|
return engineName ? EngineManager.instance().get(engineName) : null
|
|
}
|
|
|
|
const getErrorTitle = () => {
|
|
const engine = getEngine()
|
|
|
|
switch (message.metadata?.error_code) {
|
|
case ErrorCode.InvalidApiKey:
|
|
case ErrorCode.AuthenticationError:
|
|
return (
|
|
<>
|
|
<span data-testid="invalid-API-key-error">
|
|
Invalid API key. Please check your API key from{' '}
|
|
<button
|
|
className="font-medium text-[hsla(var(--app-link))] underline"
|
|
onClick={() => {
|
|
setMainState(MainViewState.Settings)
|
|
engine?.name && setSelectedSettingScreen(engine.name)
|
|
}}
|
|
>
|
|
Settings
|
|
</button>{' '}
|
|
and try again.
|
|
</span>
|
|
{defaultDesc()}
|
|
</>
|
|
)
|
|
default:
|
|
return (
|
|
<p
|
|
data-testid="passthrough-error-message"
|
|
className="first-letter:uppercase"
|
|
>
|
|
{message.content[0]?.text?.value === 'Failed to fetch' &&
|
|
engine &&
|
|
engine?.name !== InferenceEngine.cortex_llamacpp ? (
|
|
<span>
|
|
No internet connection. <br /> Switch to an on-device model or
|
|
check connection.
|
|
</span>
|
|
) : (
|
|
<>
|
|
{message?.content[0]?.text?.value && (
|
|
<AutoLink text={message?.content[0]?.text?.value} />
|
|
)}
|
|
{defaultDesc()}
|
|
</>
|
|
)}
|
|
</p>
|
|
)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="mx-auto my-6 max-w-[700px]">
|
|
{!!message.metadata?.error && (
|
|
<div
|
|
key={message.id}
|
|
className="mx-6 flex flex-col items-center space-y-2 text-center font-medium text-[hsla(var(--text-secondary))]"
|
|
>
|
|
{getErrorTitle()}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
export default ErrorMessage
|