diff --git a/src/renderer/src/pages/home/Chat.tsx b/src/renderer/src/pages/home/Chat.tsx index 5290d6285c..d5870add7f 100644 --- a/src/renderer/src/pages/home/Chat.tsx +++ b/src/renderer/src/pages/home/Chat.tsx @@ -1,3 +1,4 @@ +import { Alert } from '@heroui/react' import { loggerService } from '@logger' import { ContentSearch, ContentSearchRef } from '@renderer/components/ContentSearch' import { HStack } from '@renderer/components/Layout' @@ -49,6 +50,7 @@ const Chat: FC = (props) => { const chatMaxWidth = useChatMaxWidth() const { chat } = useRuntime() const { activeTopicOrSession, activeAgentId, activeSessionId } = chat + const { apiServer } = useSettings() const mainRef = React.useRef(null) const contentSearchRef = React.useRef(null) @@ -149,8 +151,15 @@ const Chat: FC = (props) => { if (!sessionId) { return () =>
Active Session ID is invalid.
} + if (!apiServer.enabled) { + return () => ( +
+ +
+ ) + } return () => - }, [activeAgentId, activeSessionId]) + }, [activeAgentId, activeSessionId, apiServer.enabled, t]) const SessionInputBar = useMemo(() => { if (activeAgentId === null) { diff --git a/src/renderer/src/pages/home/Inputbar/AgentSessionInputbar.tsx b/src/renderer/src/pages/home/Inputbar/AgentSessionInputbar.tsx index 000337152f..71d12a3929 100644 --- a/src/renderer/src/pages/home/Inputbar/AgentSessionInputbar.tsx +++ b/src/renderer/src/pages/home/Inputbar/AgentSessionInputbar.tsx @@ -36,6 +36,7 @@ const AgentSessionInputbar: FC = ({ agentId, sessionId }) => { const [text, setText] = useState(_text) const [inputFocus, setInputFocus] = useState(false) const { session } = useSession(agentId, sessionId) + const { apiServer } = useSettings() const { sendMessageShortcut, fontSize, enableSpellCheck } = useSettings() const textareaRef = useRef(null) @@ -52,6 +53,7 @@ const AgentSessionInputbar: FC = ({ agentId, sessionId }) => { }, []) const inputEmpty = isEmpty(text) + const sendDisabled = inputEmpty || !apiServer.enabled const handleKeyDown = (event: React.KeyboardEvent) => { //to check if the SendMessage key is pressed @@ -96,7 +98,7 @@ const AgentSessionInputbar: FC = ({ agentId, sessionId }) => { } const sendMessage = useCallback(async () => { - if (inputEmpty) { + if (sendDisabled) { return } @@ -158,7 +160,7 @@ const AgentSessionInputbar: FC = ({ agentId, sessionId }) => { }, [ agentId, dispatch, - inputEmpty, + sendDisabled, session?.agent_id, session?.instructions, session?.model, @@ -231,7 +233,7 @@ const AgentSessionInputbar: FC = ({ agentId, sessionId }) => { onBlur={() => setInputFocus(false)} />
- +
diff --git a/src/renderer/src/pages/home/Tabs/AssistantsTab.tsx b/src/renderer/src/pages/home/Tabs/AssistantsTab.tsx index 9299a75e2f..0fef9a968f 100644 --- a/src/renderer/src/pages/home/Tabs/AssistantsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/AssistantsTab.tsx @@ -3,7 +3,7 @@ import { Assistant } from '@renderer/types' import { FC, useRef } from 'react' import styled from 'styled-components' -import { Agents } from './components/Agents' +import { AgentSection } from './components/AgentSection' import Assistants from './components/Assistants' interface AssistantsTabProps { @@ -17,7 +17,7 @@ const AssistantsTab: FC = (props) => { const containerRef = useRef(null) return ( - + ) diff --git a/src/renderer/src/pages/home/Tabs/SessionsTab.tsx b/src/renderer/src/pages/home/Tabs/SessionsTab.tsx index eb0d994d6c..fd75efc1e3 100644 --- a/src/renderer/src/pages/home/Tabs/SessionsTab.tsx +++ b/src/renderer/src/pages/home/Tabs/SessionsTab.tsx @@ -1,5 +1,6 @@ -import { Spinner } from '@heroui/react' +import { Alert, Spinner } from '@heroui/react' import { useRuntime } from '@renderer/hooks/useRuntime' +import { useSettings } from '@renderer/hooks/useSettings' import { AnimatePresence, motion } from 'framer-motion' import { FC, memo } from 'react' import { useTranslation } from 'react-i18next' @@ -12,6 +13,15 @@ const SessionsTab: FC = () => { const { chat } = useRuntime() const { activeAgentId } = chat const { t } = useTranslation() + const { apiServer } = useSettings() + + if (!apiServer.enabled) { + return ( +
+ +
+ ) + } return ( diff --git a/src/renderer/src/pages/home/Tabs/components/AgentSection.tsx b/src/renderer/src/pages/home/Tabs/components/AgentSection.tsx new file mode 100644 index 0000000000..06eb072219 --- /dev/null +++ b/src/renderer/src/pages/home/Tabs/components/AgentSection.tsx @@ -0,0 +1,39 @@ +import { Alert } from '@heroui/react' +import { useRuntime } from '@renderer/hooks/useRuntime' +import { useSettings } from '@renderer/hooks/useSettings' +import { useAppDispatch } from '@renderer/store' +import { addIknowAction } from '@renderer/store/runtime' +import { useTranslation } from 'react-i18next' + +import { Agents } from './Agents' +import { SectionName } from './SectionName' + +const ALERT_KEY = 'enable_api_server_to_use_agent' + +export const AgentSection = () => { + const { t } = useTranslation() + const { apiServer } = useSettings() + const { iknow } = useRuntime() + const dispatch = useAppDispatch() + + if (!apiServer.enabled) { + if (iknow[ALERT_KEY]) return null + return ( + { + dispatch(addIknowAction(ALERT_KEY)) + }} + /> + ) + } + + return ( +
+ + +
+ ) +} diff --git a/src/renderer/src/pages/home/Tabs/components/Agents.tsx b/src/renderer/src/pages/home/Tabs/components/Agents.tsx index d6ef7b2c24..253f0888a0 100644 --- a/src/renderer/src/pages/home/Tabs/components/Agents.tsx +++ b/src/renderer/src/pages/home/Tabs/components/Agents.tsx @@ -9,7 +9,6 @@ import { FC, useCallback, useEffect } from 'react' import { useTranslation } from 'react-i18next' import AgentItem from './AgentItem' -import { SectionName } from './SectionName' interface AssistantsTabProps {} @@ -35,8 +34,7 @@ export const Agents: FC = () => { }, [isLoading, agents, activeAgentId, setActiveAgentId]) return ( -
- + <> {isLoading && } {error && } {!isLoading && @@ -65,6 +63,6 @@ export const Agents: FC = () => { ) }} /> -
+ ) } diff --git a/src/renderer/src/pages/home/Tabs/components/SessionsSection.tsx b/src/renderer/src/pages/home/Tabs/components/SessionsSection.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/renderer/src/store/runtime.ts b/src/renderer/src/store/runtime.ts index fafee81808..99dcc1914f 100644 --- a/src/renderer/src/store/runtime.ts +++ b/src/renderer/src/store/runtime.ts @@ -53,6 +53,7 @@ export interface RuntimeState { export: ExportState chat: ChatState websearch: WebSearchState + iknow: Record } export interface ExportState { @@ -93,7 +94,8 @@ const initialState: RuntimeState = { }, websearch: { activeSearches: {} - } + }, + iknow: {} } const runtimeSlice = createSlice({ @@ -179,6 +181,9 @@ const runtimeSlice = createSlice({ delete state.websearch.activeSearches[requestId] } state.websearch.activeSearches[requestId] = status + }, + addIknowAction: (state, action: PayloadAction) => { + state.iknow[action.payload] = true } } }) @@ -197,6 +202,7 @@ export const { setResourcesPath, setUpdateState, setExportState, + addIknowAction, // Chat related actions toggleMultiSelectMode, setSelectedMessageIds,