mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-16 12:36:07 +00:00
@@ -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} />;
|
||||
|
||||
@@ -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: {
|
||||
|
||||
+25
-20
@@ -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>
|
||||
);
|
||||
@@ -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;
|
||||
@@ -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');
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user