💄 style: update ollama checker (#7650)

* update ollama

* fix file page
This commit is contained in:
Arvin Xu
2025-04-30 16:45:03 +08:00
committed by GitHub
parent 436a7351eb
commit 321fd2b979
9 changed files with 62 additions and 50 deletions
+3
View File
@@ -4,6 +4,7 @@ import { resolve } from 'node:path';
dotenv.config();
const isDev = process.env.NODE_ENV === 'development';
const updateChannel = process.env.UPDATE_CHANNEL;
console.log(`[electron-vite.config.ts] Detected UPDATE_CHANNEL: ${updateChannel}`); // 添加日志确认
@@ -11,6 +12,7 @@ export default defineConfig({
main: {
build: {
outDir: 'dist/main',
sourcemap: isDev,
},
// 这里是关键:在构建时进行文本替换
define: {
@@ -29,6 +31,7 @@ export default defineConfig({
preload: {
build: {
outDir: 'dist/preload',
sourcemap: isDev,
},
plugins: [externalizeDepsPlugin({})],
resolve: {
@@ -8,7 +8,7 @@ import Container from './Container';
const loading = () => <Skeleton active style={{ width: 400 }} />;
const OllamaSetupGuide = dynamic(() => import('@/components/OllamaSetupGuide'), {
const OllamaSetupGuide = dynamic(() => import('@/features/OllamaSetupGuide'), {
loading,
ssr: false,
});
@@ -40,10 +40,12 @@ const CheckError = ({
error?: ChatMessageError;
setError: (error?: ChatMessageError) => void;
}) => {
const errorBody: OllamaErrorResponse = (error as any)?.body;
const errorBody: OllamaErrorResponse = error?.body;
const errorMessage = errorBody.error?.message;
if (error?.type === 'OllamaServiceUnavailable') return <OllamaSetupGuide container={false} />;
// error of not pull the model
const unresolvedModel = errorMessage?.match(UNRESOLVED_MODEL_REGEXP)?.[1];
@@ -13,9 +13,9 @@ const useStyles = createStyles(({ css, token, responsive }) => ({
container: css`
position: relative;
width: min(50vw, 600px);
width: 100%;
padding-inline: 40px;
border: 1px solid ${token.colorBorderBg};
border: 1px solid ${token.colorBorderSecondary};
border-radius: 8px;
background: ${token.colorBgContainer};
@@ -1,14 +0,0 @@
import { memo } from 'react';
import OllamaSetupGuide from '@/components/OllamaSetupGuide';
import { ErrorActionContainer } from '@/features/Conversation/Error/style';
const SetupGuide = memo(() => {
return (
<ErrorActionContainer style={{ paddingBlock: 0 }}>
<OllamaSetupGuide />
</ErrorActionContainer>
);
});
export default SetupGuide;
@@ -8,7 +8,7 @@ import ErrorJsonViewer from '../ErrorJsonViewer';
const loading = () => <Skeleton active style={{ width: 300 }} />;
const SetupGuide = dynamic(() => import('./SetupGuide'), { loading, ssr: false });
const SetupGuide = dynamic(() => import('@/features/OllamaSetupGuide'), { loading, ssr: false });
const InvalidModel = dynamic(() => import('./InvalidOllamaModel'), { loading, ssr: false });
@@ -38,7 +38,7 @@ const OllamaBizError = memo<ChatMessage>(({ error, id }) => {
// error of not enable model or not set the CORS rules
if (errorMessage?.includes('Failed to fetch')) {
return <SetupGuide />;
return <SetupGuide id={id} />;
}
return <ErrorJsonViewer error={error} id={id} />;
+3 -10
View File
@@ -5,7 +5,6 @@ import dynamic from 'next/dynamic';
import { Suspense, memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { isDesktop } from '@/const/version';
import { useProviderName } from '@/hooks/useProviderName';
import { AgentRuntimeErrorType, ILobeAgentRuntimeErrorType } from '@/libs/agent-runtime';
import { ChatErrorType, ErrorType } from '@/types/fetch';
@@ -20,11 +19,8 @@ import { ErrorActionContainer } from './style';
const loading = () => <Skeleton active />;
const OllamaBizError = dynamic(() => import('./OllamaBizError'), { loading, ssr: false });
const OllamaSetupGuide = dynamic(() => import('./OllamaBizError/SetupGuide'), {
loading,
ssr: false,
});
const OllamaDesktopSetupGuide = dynamic(() => import('./OllamaDesktopSetupGuide'), {
const OllamaSetupGuide = dynamic(() => import('@/features/OllamaSetupGuide'), {
loading,
ssr: false,
});
@@ -95,11 +91,8 @@ const ErrorMessageExtra = memo<{ data: ChatMessage }>(({ data }) => {
if (!error?.type) return;
switch (error.type) {
// TODO: 优化 Ollama setup 的流程,isDesktop 模式下可以直接做到端到端检测
case AgentRuntimeErrorType.OllamaServiceUnavailable: {
if (isDesktop) return <OllamaDesktopSetupGuide id={data.id} />;
return <OllamaSetupGuide />;
return <OllamaSetupGuide id={data.id} />;
}
case AgentRuntimeErrorType.OllamaBizError: {
@@ -9,9 +9,10 @@ import { Center } from 'react-layout-kit';
import FormAction from '@/components/FormAction';
import { useChatStore } from '@/store/chat';
import { ErrorActionContainer } from '../style';
import { ErrorActionContainer } from '../Conversation/Error/style';
const OllamaDesktopSetupGuide = memo<{ id: string }>(({ id }) => {
// TODO: 优化 Ollama setup 的流程,isDesktop 模式下可以直接做到端到端检测
const OllamaDesktopSetupGuide = memo<{ id?: string }>(({ id }) => {
const theme = useTheme();
const { t } = useTranslation('components');
@@ -35,24 +36,28 @@ const OllamaDesktopSetupGuide = memo<{ id: string }>(({ id }) => {
}
title={t('OllamaSetupGuide.install.title')}
/>
<Button
block
onClick={() => {
delAndRegenerateMessage(id);
}}
style={{ marginTop: 8 }}
type={'primary'}
>
{t('OllamaSetupGuide.action.start')}
</Button>
<Button
block
onClick={() => {
deleteMessage(id);
}}
>
{t('OllamaSetupGuide.action.close')}
</Button>
{id && (
<>
<Button
block
onClick={() => {
delAndRegenerateMessage(id);
}}
style={{ marginTop: 8 }}
type={'primary'}
>
{t('OllamaSetupGuide.action.start')}
</Button>
<Button
block
onClick={() => {
deleteMessage(id);
}}
>
{t('OllamaSetupGuide.action.close')}
</Button>
</>
)}
</Center>
</ErrorActionContainer>
);
+17
View File
@@ -0,0 +1,17 @@
import { memo } from 'react';
import OllamaSetupGuide from '@/components/OllamaSetupGuide';
import { isDesktop } from '@/const/version';
import { ErrorActionContainer } from '@/features/Conversation/Error/style';
import OllamaDesktopSetupGuide from './Desktop';
const SetupGuide = memo<{ container?: boolean; id?: string }>(({ id, container = true }) => {
const content = isDesktop ? <OllamaDesktopSetupGuide id={id} /> : <OllamaSetupGuide />;
if (!container) return content;
return <ErrorActionContainer style={{ paddingBlock: 0 }}>{content}</ErrorActionContainer>;
});
export default SetupGuide;
+6
View File
@@ -1,4 +1,6 @@
import { enableClerk, enableNextAuth } from '@/const/auth';
import { DESKTOP_USER_ID } from '@/const/desktop';
import { isDesktop } from '@/const/version';
export const getUserAuth = async () => {
if (enableClerk) {
@@ -19,6 +21,10 @@ export const getUserAuth = async () => {
return { nextAuth: session, userId };
}
if (isDesktop) {
return { userId: DESKTOP_USER_ID };
}
throw new Error('Auth method is not enabled');
};