Compare commits
3 Commits
main
...
fix/quick-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d2f24ac3a | ||
|
|
97b7eebf7d | ||
|
|
4d553beb85 |
@@ -755,7 +755,8 @@
|
|||||||
"backspace_clear": "Backspace to clear",
|
"backspace_clear": "Backspace to clear",
|
||||||
"esc": "ESC to {{action}}",
|
"esc": "ESC to {{action}}",
|
||||||
"esc_back": "return",
|
"esc_back": "return",
|
||||||
"esc_close": "close"
|
"esc_close": "close",
|
||||||
|
"esc_pause": "pause"
|
||||||
},
|
},
|
||||||
"input": {
|
"input": {
|
||||||
"placeholder": {
|
"placeholder": {
|
||||||
|
|||||||
@@ -752,10 +752,11 @@
|
|||||||
},
|
},
|
||||||
"footer": {
|
"footer": {
|
||||||
"copy_last_message": "C キーを押してコピー",
|
"copy_last_message": "C キーを押してコピー",
|
||||||
|
"backspace_clear": "バックスペースを押してクリアします",
|
||||||
"esc": "ESC キーを押して{{action}}",
|
"esc": "ESC キーを押して{{action}}",
|
||||||
"esc_back": "戻る",
|
"esc_back": "戻る",
|
||||||
"esc_close": "ウィンドウを閉じる",
|
"esc_close": "ウィンドウを閉じる",
|
||||||
"backspace_clear": "バックスペースを押してクリアします"
|
"esc_pause": "一時停止"
|
||||||
},
|
},
|
||||||
"input": {
|
"input": {
|
||||||
"placeholder": {
|
"placeholder": {
|
||||||
|
|||||||
@@ -752,10 +752,11 @@
|
|||||||
},
|
},
|
||||||
"footer": {
|
"footer": {
|
||||||
"copy_last_message": "Нажмите C для копирования",
|
"copy_last_message": "Нажмите C для копирования",
|
||||||
|
"backspace_clear": "Нажмите Backspace, чтобы очистить",
|
||||||
"esc": "Нажмите ESC {{action}}",
|
"esc": "Нажмите ESC {{action}}",
|
||||||
"esc_back": "возвращения",
|
"esc_back": "возвращения",
|
||||||
"esc_close": "закрытия окна",
|
"esc_close": "закрытия окна",
|
||||||
"backspace_clear": "Нажмите Backspace, чтобы очистить"
|
"esc_pause": "пауза"
|
||||||
},
|
},
|
||||||
"input": {
|
"input": {
|
||||||
"placeholder": {
|
"placeholder": {
|
||||||
|
|||||||
@@ -755,7 +755,8 @@
|
|||||||
"backspace_clear": "按 Backspace 清空",
|
"backspace_clear": "按 Backspace 清空",
|
||||||
"esc": "按 ESC {{action}}",
|
"esc": "按 ESC {{action}}",
|
||||||
"esc_back": "返回",
|
"esc_back": "返回",
|
||||||
"esc_close": "关闭"
|
"esc_close": "关闭",
|
||||||
|
"esc_pause": "暂停"
|
||||||
},
|
},
|
||||||
"input": {
|
"input": {
|
||||||
"placeholder": {
|
"placeholder": {
|
||||||
|
|||||||
@@ -752,10 +752,11 @@
|
|||||||
},
|
},
|
||||||
"footer": {
|
"footer": {
|
||||||
"copy_last_message": "按 C 鍵複製",
|
"copy_last_message": "按 C 鍵複製",
|
||||||
|
"backspace_clear": "按 Backspace 清空",
|
||||||
"esc": "按 ESC {{action}}",
|
"esc": "按 ESC {{action}}",
|
||||||
"esc_back": "返回",
|
"esc_back": "返回",
|
||||||
"esc_close": "關閉視窗",
|
"esc_close": "關閉視窗",
|
||||||
"backspace_clear": "按 Backspace 清空"
|
"esc_pause": "暫停"
|
||||||
},
|
},
|
||||||
"input": {
|
"input": {
|
||||||
"placeholder": {
|
"placeholder": {
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ const ModelSettings: FC = () => {
|
|||||||
<HStack alignItems="center" gap={0}>
|
<HStack alignItems="center" gap={0}>
|
||||||
<StyledButton
|
<StyledButton
|
||||||
type={!quickAssistantId ? 'primary' : 'default'}
|
type={!quickAssistantId ? 'primary' : 'default'}
|
||||||
onClick={() => dispatch(setQuickAssistantId(null))}
|
onClick={() => dispatch(setQuickAssistantId(''))}
|
||||||
selected={!quickAssistantId}>
|
selected={!quickAssistantId}>
|
||||||
{t('settings.models.use_model')}
|
{t('settings.models.use_model')}
|
||||||
</StyledButton>
|
</StyledButton>
|
||||||
@@ -188,22 +188,29 @@ const ModelSettings: FC = () => {
|
|||||||
{!quickAssistantId ? null : (
|
{!quickAssistantId ? null : (
|
||||||
<HStack alignItems="center" style={{ marginTop: 12 }}>
|
<HStack alignItems="center" style={{ marginTop: 12 }}>
|
||||||
<Select
|
<Select
|
||||||
value={quickAssistantId}
|
value={quickAssistantId || defaultAssistant.id}
|
||||||
style={{ width: 360 }}
|
style={{ width: 360 }}
|
||||||
onChange={(value) => dispatch(setQuickAssistantId(value))}
|
onChange={(value) => dispatch(setQuickAssistantId(value))}
|
||||||
placeholder={t('settings.models.quick_assistant_selection')}>
|
placeholder={t('settings.models.quick_assistant_selection')}>
|
||||||
{assistants.map((a) => (
|
<Select.Option key={defaultAssistant.id} value={defaultAssistant.id}>
|
||||||
<Select.Option key={a.id} value={a.id}>
|
<AssistantItem>
|
||||||
<AssistantItem>
|
<ModelAvatar model={defaultAssistant.model || defaultModel} size={18} />
|
||||||
<ModelAvatar model={a.model || defaultModel} size={18} />
|
<AssistantName>{defaultAssistant.name}</AssistantName>
|
||||||
<AssistantName>{a.name}</AssistantName>
|
<Spacer />
|
||||||
<Spacer />
|
<DefaultTag isCurrent={true}>{t('settings.models.quick_assistant_default_tag')}</DefaultTag>
|
||||||
{a.id === defaultAssistant.id && (
|
</AssistantItem>
|
||||||
<DefaultTag isCurrent={true}>{t('settings.models.quick_assistant_default_tag')}</DefaultTag>
|
</Select.Option>
|
||||||
)}
|
{assistants
|
||||||
</AssistantItem>
|
.filter((a) => a.id !== defaultAssistant.id)
|
||||||
</Select.Option>
|
.map((a) => (
|
||||||
))}
|
<Select.Option key={a.id} value={a.id}>
|
||||||
|
<AssistantItem>
|
||||||
|
<ModelAvatar model={a.model || defaultModel} size={18} />
|
||||||
|
<AssistantName>{a.name}</AssistantName>
|
||||||
|
<Spacer />
|
||||||
|
</AssistantItem>
|
||||||
|
</Select.Option>
|
||||||
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
</HStack>
|
</HStack>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export interface LlmState {
|
|||||||
defaultModel: Model
|
defaultModel: Model
|
||||||
topicNamingModel: Model
|
topicNamingModel: Model
|
||||||
translateModel: Model
|
translateModel: Model
|
||||||
quickAssistantId: string | null
|
quickAssistantId: string
|
||||||
settings: LlmSettings
|
settings: LlmSettings
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -534,7 +534,7 @@ export const initialState: LlmState = {
|
|||||||
defaultModel: SYSTEM_MODELS.defaultModel[0],
|
defaultModel: SYSTEM_MODELS.defaultModel[0],
|
||||||
topicNamingModel: SYSTEM_MODELS.defaultModel[1],
|
topicNamingModel: SYSTEM_MODELS.defaultModel[1],
|
||||||
translateModel: SYSTEM_MODELS.defaultModel[2],
|
translateModel: SYSTEM_MODELS.defaultModel[2],
|
||||||
quickAssistantId: null,
|
quickAssistantId: '',
|
||||||
providers: INITIAL_PROVIDERS,
|
providers: INITIAL_PROVIDERS,
|
||||||
settings: {
|
settings: {
|
||||||
ollama: {
|
ollama: {
|
||||||
@@ -650,7 +650,7 @@ const llmSlice = createSlice({
|
|||||||
state.translateModel = action.payload.model
|
state.translateModel = action.payload.model
|
||||||
},
|
},
|
||||||
|
|
||||||
setQuickAssistantId: (state, action: PayloadAction<string | null>) => {
|
setQuickAssistantId: (state, action: PayloadAction<string>) => {
|
||||||
state.quickAssistantId = action.payload
|
state.quickAssistantId = action.payload
|
||||||
},
|
},
|
||||||
setOllamaKeepAliveTime: (state, action: PayloadAction<number>) => {
|
setOllamaKeepAliveTime: (state, action: PayloadAction<number>) => {
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
import Scrollbar from '@renderer/components/Scrollbar'
|
import Scrollbar from '@renderer/components/Scrollbar'
|
||||||
import { Assistant } from '@renderer/types'
|
import { Assistant, Topic } from '@renderer/types'
|
||||||
import { FC } from 'react'
|
import { FC } from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
import Messages from './components/Messages'
|
import Messages from './components/Messages'
|
||||||
interface Props {
|
interface Props {
|
||||||
route: string
|
route: string
|
||||||
assistant: Assistant
|
assistant: Assistant | null
|
||||||
|
topic: Topic | null
|
||||||
|
isOutputted: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChatWindow: FC<Props> = ({ route, assistant }) => {
|
const ChatWindow: FC<Props> = ({ route, assistant, topic, isOutputted }) => {
|
||||||
|
if (!assistant || !topic) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Main className="bubble">
|
<Main className="bubble">
|
||||||
<Messages assistant={{ ...assistant }} route={route} />
|
<Messages assistant={assistant} topic={topic} route={route} isOutputted={isOutputted} />
|
||||||
</Main>
|
</Main>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
import { LoadingOutlined } from '@ant-design/icons'
|
||||||
import Scrollbar from '@renderer/components/Scrollbar'
|
import Scrollbar from '@renderer/components/Scrollbar'
|
||||||
import { useTopicMessages } from '@renderer/hooks/useMessageOperations'
|
import { useTopicMessages } from '@renderer/hooks/useMessageOperations'
|
||||||
import { Assistant } from '@renderer/types'
|
import { Assistant, Topic } from '@renderer/types'
|
||||||
import { getMainTextContent } from '@renderer/utils/messageUtils/find'
|
import { getMainTextContent } from '@renderer/utils/messageUtils/find'
|
||||||
import { last } from 'lodash'
|
import { last } from 'lodash'
|
||||||
import { FC, useRef } from 'react'
|
import { FC } from 'react'
|
||||||
import { useHotkeys } from 'react-hotkeys-hook'
|
import { useHotkeys } from 'react-hotkeys-hook'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
@@ -12,40 +13,19 @@ import MessageItem from './Message'
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
assistant: Assistant
|
assistant: Assistant
|
||||||
|
topic: Topic
|
||||||
route: string
|
route: string
|
||||||
|
isOutputted: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ContainerProps {
|
interface ContainerProps {
|
||||||
right?: boolean
|
right?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const Messages: FC<Props> = ({ assistant, route }) => {
|
const Messages: FC<Props> = ({ assistant, topic, route, isOutputted }) => {
|
||||||
// const [messages, setMessages] = useState<Message[]>([])
|
const messages = useTopicMessages(topic.id)
|
||||||
const messages = useTopicMessages(assistant.topics[0].id)
|
|
||||||
const containerRef = useRef<HTMLDivElement>(null)
|
|
||||||
const messagesRef = useRef(messages)
|
|
||||||
|
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
|
||||||
messagesRef.current = messages
|
|
||||||
|
|
||||||
// const onSendMessage = useCallback(
|
|
||||||
// async (message: Message) => {
|
|
||||||
// setMessages((prev) => {
|
|
||||||
// const assistantMessage = getAssistantMessage({ assistant, topic: assistant.topics[0] })
|
|
||||||
// store.dispatch(newMessagesActions.addMessage({ topicId: assistant.topics[0].id, message: assistantMessage }))
|
|
||||||
// const messages = prev.concat([message, assistantMessage])
|
|
||||||
// return messages
|
|
||||||
// })
|
|
||||||
// },
|
|
||||||
// [assistant]
|
|
||||||
// )
|
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// const unsubscribes = [EventEmitter.on(EVENT_NAMES.SEND_MESSAGE, onSendMessage)]
|
|
||||||
// return () => unsubscribes.forEach((unsub) => unsub())
|
|
||||||
// }, [assistant.id])
|
|
||||||
|
|
||||||
useHotkeys('c', () => {
|
useHotkeys('c', () => {
|
||||||
const lastMessage = last(messages)
|
const lastMessage = last(messages)
|
||||||
if (lastMessage) {
|
if (lastMessage) {
|
||||||
@@ -55,7 +35,8 @@ const Messages: FC<Props> = ({ assistant, route }) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
return (
|
return (
|
||||||
<Container id="messages" key={assistant.id} ref={containerRef}>
|
<Container id="messages" key={assistant.id}>
|
||||||
|
{!isOutputted && <LoadingOutlined style={{ fontSize: 16 }} spin />}
|
||||||
{[...messages].reverse().map((message, index) => (
|
{[...messages].reverse().map((message, index) => (
|
||||||
<MessageItem key={message.id} message={message} index={index} total={messages.length} route={route} />
|
<MessageItem key={message.id} message={message} index={index} total={messages.length} route={route} />
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,27 +1,32 @@
|
|||||||
import { isMac } from '@renderer/config/constant'
|
import { isMac } from '@renderer/config/constant'
|
||||||
import { useTheme } from '@renderer/context/ThemeProvider'
|
import { useTheme } from '@renderer/context/ThemeProvider'
|
||||||
import { useDefaultAssistant, useDefaultModel } from '@renderer/hooks/useAssistant'
|
|
||||||
import { useSettings } from '@renderer/hooks/useSettings'
|
import { useSettings } from '@renderer/hooks/useSettings'
|
||||||
import i18n from '@renderer/i18n'
|
import i18n from '@renderer/i18n'
|
||||||
import { fetchChatCompletion } from '@renderer/services/ApiService'
|
import { fetchChatCompletion } from '@renderer/services/ApiService'
|
||||||
import { getAssistantById } from '@renderer/services/AssistantService'
|
import {
|
||||||
|
getAssistantById,
|
||||||
|
getDefaultAssistant,
|
||||||
|
getDefaultModel,
|
||||||
|
getDefaultTopic
|
||||||
|
} from '@renderer/services/AssistantService'
|
||||||
import { getAssistantMessage, getUserMessage } from '@renderer/services/MessagesService'
|
import { getAssistantMessage, getUserMessage } from '@renderer/services/MessagesService'
|
||||||
import store, { useAppSelector } from '@renderer/store'
|
import store, { useAppSelector } from '@renderer/store'
|
||||||
import { upsertManyBlocks } from '@renderer/store/messageBlock'
|
import { upsertManyBlocks } from '@renderer/store/messageBlock'
|
||||||
import { updateOneBlock, upsertOneBlock } from '@renderer/store/messageBlock'
|
import { updateOneBlock, upsertOneBlock } from '@renderer/store/messageBlock'
|
||||||
import { newMessagesActions } from '@renderer/store/newMessage'
|
import { newMessagesActions } from '@renderer/store/newMessage'
|
||||||
import { Assistant, ThemeMode } from '@renderer/types'
|
import { selectMessagesForTopic } from '@renderer/store/newMessage'
|
||||||
|
import { Assistant, ThemeMode, Topic } from '@renderer/types'
|
||||||
import { Chunk, ChunkType } from '@renderer/types/chunk'
|
import { Chunk, ChunkType } from '@renderer/types/chunk'
|
||||||
import { AssistantMessageStatus } from '@renderer/types/newMessage'
|
import { AssistantMessageStatus } from '@renderer/types/newMessage'
|
||||||
import { MessageBlockStatus } from '@renderer/types/newMessage'
|
import { MessageBlockStatus } from '@renderer/types/newMessage'
|
||||||
import { createMainTextBlock } from '@renderer/utils/messageUtils/create'
|
import { abortCompletion } from '@renderer/utils/abortController'
|
||||||
|
import { isAbortError } from '@renderer/utils/error'
|
||||||
|
import { createMainTextBlock, createThinkingBlock } from '@renderer/utils/messageUtils/create'
|
||||||
import { defaultLanguage } from '@shared/config/constant'
|
import { defaultLanguage } from '@shared/config/constant'
|
||||||
import { IpcChannel } from '@shared/IpcChannel'
|
import { IpcChannel } from '@shared/IpcChannel'
|
||||||
import { Divider } from 'antd'
|
import { Divider } from 'antd'
|
||||||
import dayjs from 'dayjs'
|
|
||||||
import { isEmpty } from 'lodash'
|
import { isEmpty } from 'lodash'
|
||||||
import React, { FC, useCallback, useEffect, useRef, useState } from 'react'
|
import React, { FC, useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import { useHotkeys } from 'react-hotkeys-hook'
|
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
@@ -33,28 +38,63 @@ import Footer from './components/Footer'
|
|||||||
import InputBar from './components/InputBar'
|
import InputBar from './components/InputBar'
|
||||||
|
|
||||||
const HomeWindow: FC = () => {
|
const HomeWindow: FC = () => {
|
||||||
|
const { language, readClipboardAtStartup, windowStyle } = useSettings()
|
||||||
|
const { theme } = useTheme()
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
const [route, setRoute] = useState<'home' | 'chat' | 'translate' | 'summary' | 'explanation'>('home')
|
const [route, setRoute] = useState<'home' | 'chat' | 'translate' | 'summary' | 'explanation'>('home')
|
||||||
const [isFirstMessage, setIsFirstMessage] = useState(true)
|
const [isFirstMessage, setIsFirstMessage] = useState(true)
|
||||||
const [clipboardText, setClipboardText] = useState('')
|
const [clipboardText, setClipboardText] = useState('')
|
||||||
const [selectedText, setSelectedText] = useState('')
|
const [selectedText, setSelectedText] = useState('')
|
||||||
const [currentAssistant, setCurrentAssistant] = useState<Assistant>({} as Assistant)
|
|
||||||
const [text, setText] = useState('')
|
const [userInputText, setUserInputText] = useState('')
|
||||||
const [lastClipboardText, setLastClipboardText] = useState<string | null>(null)
|
const [lastClipboardText, setLastClipboardText] = useState<string | null>(null)
|
||||||
const textChange = useState(() => {})[1]
|
const textChange = useState(() => {})[1]
|
||||||
const { defaultAssistant } = useDefaultAssistant()
|
|
||||||
const topic = defaultAssistant.topics[0]
|
|
||||||
const { defaultModel } = useDefaultModel()
|
|
||||||
const model = currentAssistant.model || defaultModel
|
|
||||||
const { language, readClipboardAtStartup, windowStyle } = useSettings()
|
|
||||||
const { theme } = useTheme()
|
|
||||||
const { t } = useTranslation()
|
|
||||||
const inputBarRef = useRef<HTMLDivElement>(null)
|
|
||||||
const featureMenusRef = useRef<FeatureMenusRef>(null)
|
|
||||||
const referenceText = selectedText || clipboardText || text
|
|
||||||
|
|
||||||
const content = isFirstMessage ? (referenceText === text ? text : `${referenceText}\n\n${text}`).trim() : text.trim()
|
//indicator for loading(thinking/streaming)
|
||||||
|
const [isLoading, setIsLoading] = useState(false)
|
||||||
|
//indicator for wether the first message is outputted
|
||||||
|
const [isOutputted, setIsOutputted] = useState(false)
|
||||||
|
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
|
||||||
const { quickAssistantId } = useAppSelector((state) => state.llm)
|
const { quickAssistantId } = useAppSelector((state) => state.llm)
|
||||||
|
const currentAssistant = useRef<Assistant | null>(null)
|
||||||
|
const currentTopic = useRef<Topic | null>(null)
|
||||||
|
const currentAskId = useRef('')
|
||||||
|
|
||||||
|
const inputBarRef = useRef<HTMLDivElement>(null)
|
||||||
|
const featureMenusRef = useRef<FeatureMenusRef>(null)
|
||||||
|
const referenceText = selectedText || clipboardText || userInputText
|
||||||
|
|
||||||
|
const content = isFirstMessage
|
||||||
|
? (referenceText === userInputText ? userInputText : `${referenceText}\n\n${userInputText}`).trim()
|
||||||
|
: userInputText.trim()
|
||||||
|
|
||||||
|
//init the assistant and topic
|
||||||
|
useEffect(() => {
|
||||||
|
if (quickAssistantId) {
|
||||||
|
currentAssistant.current = getAssistantById(quickAssistantId) || getDefaultAssistant()
|
||||||
|
} else {
|
||||||
|
currentAssistant.current = getDefaultAssistant()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentAssistant.current?.model) {
|
||||||
|
currentAssistant.current.model = getDefaultModel()
|
||||||
|
}
|
||||||
|
currentTopic.current = getDefaultTopic(currentAssistant.current?.id)
|
||||||
|
}, [quickAssistantId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
i18n.changeLanguage(language || navigator.language || defaultLanguage)
|
||||||
|
}, [language])
|
||||||
|
|
||||||
|
// 当路由为home时,初始化isFirstMessage为true
|
||||||
|
useEffect(() => {
|
||||||
|
if (route === 'home') {
|
||||||
|
setIsFirstMessage(true)
|
||||||
|
}
|
||||||
|
}, [route])
|
||||||
|
|
||||||
const readClipboard = useCallback(async () => {
|
const readClipboard = useCallback(async () => {
|
||||||
if (!readClipboardAtStartup) return
|
if (!readClipboardAtStartup) return
|
||||||
@@ -66,6 +106,12 @@ const HomeWindow: FC = () => {
|
|||||||
}
|
}
|
||||||
}, [readClipboardAtStartup, lastClipboardText])
|
}, [readClipboardAtStartup, lastClipboardText])
|
||||||
|
|
||||||
|
const clearClipboard = () => {
|
||||||
|
setClipboardText('')
|
||||||
|
setSelectedText('')
|
||||||
|
focusInput()
|
||||||
|
}
|
||||||
|
|
||||||
const focusInput = () => {
|
const focusInput = () => {
|
||||||
if (inputBarRef.current) {
|
if (inputBarRef.current) {
|
||||||
const input = inputBarRef.current.querySelector('input')
|
const input = inputBarRef.current.querySelector('input')
|
||||||
@@ -81,15 +127,19 @@ const HomeWindow: FC = () => {
|
|||||||
focusInput()
|
focusInput()
|
||||||
}, [readClipboard])
|
}, [readClipboard])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
window.electron.ipcRenderer.on(IpcChannel.ShowMiniWindow, onWindowShow)
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.electron.ipcRenderer.removeAllListeners(IpcChannel.ShowMiniWindow)
|
||||||
|
}
|
||||||
|
}, [onWindowShow])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
readClipboard()
|
readClipboard()
|
||||||
}, [readClipboard])
|
}, [readClipboard])
|
||||||
|
|
||||||
useEffect(() => {
|
const handleCloseWindow = () => window.api.miniWindow.hide()
|
||||||
i18n.changeLanguage(language || navigator.language || defaultLanguage)
|
|
||||||
}, [language])
|
|
||||||
|
|
||||||
const onCloseWindow = () => window.api.miniWindow.hide()
|
|
||||||
|
|
||||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
// 使用非直接输入法时(例如中文、日文输入法),存在输入法键入过程
|
// 使用非直接输入法时(例如中文、日文输入法),存在输入法键入过程
|
||||||
@@ -115,7 +165,7 @@ const HomeWindow: FC = () => {
|
|||||||
} else {
|
} else {
|
||||||
// 目前文本框只在'chat'时可以继续输入,这里相当于 route === 'chat'
|
// 目前文本框只在'chat'时可以继续输入,这里相当于 route === 'chat'
|
||||||
setRoute('chat')
|
setRoute('chat')
|
||||||
onSendMessage().then()
|
handleSendMessage().then()
|
||||||
focusInput()
|
focusInput()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,7 +174,7 @@ const HomeWindow: FC = () => {
|
|||||||
case 'Backspace':
|
case 'Backspace':
|
||||||
{
|
{
|
||||||
textChange(() => {
|
textChange(() => {
|
||||||
if (text.length === 0) {
|
if (userInputText.length === 0) {
|
||||||
clearClipboard()
|
clearClipboard()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -148,137 +198,233 @@ const HomeWindow: FC = () => {
|
|||||||
break
|
break
|
||||||
case 'Escape':
|
case 'Escape':
|
||||||
{
|
{
|
||||||
setText('')
|
handleEsc()
|
||||||
setRoute('home')
|
|
||||||
route === 'home' && onCloseWindow()
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setText(e.target.value)
|
setUserInputText(e.target.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
const handleError = (error: Error) => {
|
||||||
const defaultCurrentAssistant = {
|
setIsLoading(false)
|
||||||
...defaultAssistant,
|
setError(error.message)
|
||||||
model: defaultModel
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (quickAssistantId) {
|
const handleSendMessage = useCallback(
|
||||||
// 獲取指定助手,如果不存在則使用默認助手
|
|
||||||
const assistantFromId = getAssistantById(quickAssistantId)
|
|
||||||
const currentAssistant = assistantFromId || defaultCurrentAssistant
|
|
||||||
// 如果助手本身沒有設定模型,則使用預設模型
|
|
||||||
if (!currentAssistant.model) {
|
|
||||||
currentAssistant.model = defaultModel
|
|
||||||
}
|
|
||||||
setCurrentAssistant(currentAssistant)
|
|
||||||
} else {
|
|
||||||
setCurrentAssistant(defaultCurrentAssistant)
|
|
||||||
}
|
|
||||||
}, [quickAssistantId, defaultAssistant, defaultModel])
|
|
||||||
|
|
||||||
const onSendMessage = useCallback(
|
|
||||||
async (prompt?: string) => {
|
async (prompt?: string) => {
|
||||||
if (isEmpty(content)) {
|
if (isEmpty(content) || !currentAssistant.current || !currentTopic.current) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const topic = currentAssistant.topics[0]
|
|
||||||
const messageParams = {
|
|
||||||
role: 'user',
|
|
||||||
content: [prompt, content].filter(Boolean).join('\n\n'),
|
|
||||||
assistant: currentAssistant,
|
|
||||||
topic,
|
|
||||||
createdAt: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
||||||
status: 'success'
|
|
||||||
}
|
|
||||||
const topicId = topic.id
|
|
||||||
const { message: userMessage, blocks } = getUserMessage(messageParams)
|
|
||||||
|
|
||||||
store.dispatch(newMessagesActions.addMessage({ topicId, message: userMessage }))
|
try {
|
||||||
store.dispatch(upsertManyBlocks(blocks))
|
const topicId = currentTopic.current.id
|
||||||
|
|
||||||
const assistant = currentAssistant
|
const { message: userMessage, blocks } = getUserMessage({
|
||||||
let blockId: string | null = null
|
content: [prompt, content].filter(Boolean).join('\n\n'),
|
||||||
let blockContent: string = ''
|
assistant: currentAssistant.current,
|
||||||
|
topic: currentTopic.current
|
||||||
|
})
|
||||||
|
|
||||||
const assistantMessage = getAssistantMessage({ assistant, topic: assistant.topics[0] })
|
store.dispatch(newMessagesActions.addMessage({ topicId, message: userMessage }))
|
||||||
store.dispatch(newMessagesActions.addMessage({ topicId, message: assistantMessage }))
|
store.dispatch(upsertManyBlocks(blocks))
|
||||||
|
|
||||||
fetchChatCompletion({
|
const assistantMessage = getAssistantMessage({
|
||||||
messages: [userMessage],
|
assistant: currentAssistant.current,
|
||||||
assistant: { ...assistant, settings: { streamOutput: true } },
|
topic: currentTopic.current
|
||||||
onChunkReceived: (chunk: Chunk) => {
|
})
|
||||||
if (chunk.type === ChunkType.TEXT_DELTA) {
|
assistantMessage.askId = userMessage.id
|
||||||
blockContent += chunk.text
|
currentAskId.current = userMessage.id
|
||||||
if (!blockId) {
|
|
||||||
const block = createMainTextBlock(assistantMessage.id, chunk.text, {
|
store.dispatch(newMessagesActions.addMessage({ topicId, message: assistantMessage }))
|
||||||
status: MessageBlockStatus.STREAMING
|
|
||||||
})
|
const allMessagesForTopic = selectMessagesForTopic(store.getState(), topicId)
|
||||||
blockId = block.id
|
const userMessageIndex = allMessagesForTopic.findIndex((m) => m?.id === userMessage.id)
|
||||||
store.dispatch(
|
|
||||||
newMessagesActions.updateMessage({
|
const messagesForContext = allMessagesForTopic
|
||||||
topicId,
|
.slice(0, userMessageIndex + 1)
|
||||||
messageId: assistantMessage.id,
|
.filter((m) => m && !m.status?.includes('ing'))
|
||||||
updates: { blockInstruction: { id: block.id } }
|
|
||||||
})
|
let blockId: string | null = null
|
||||||
)
|
let blockContent: string = ''
|
||||||
store.dispatch(upsertOneBlock(block))
|
let thinkingBlockId: string | null = null
|
||||||
} else {
|
let thinkingBlockContent: string = ''
|
||||||
store.dispatch(updateOneBlock({ id: blockId, changes: { content: blockContent } }))
|
|
||||||
|
setIsLoading(true)
|
||||||
|
setIsOutputted(false)
|
||||||
|
setError(null)
|
||||||
|
|
||||||
|
setIsFirstMessage(false)
|
||||||
|
setUserInputText('')
|
||||||
|
|
||||||
|
await fetchChatCompletion({
|
||||||
|
messages: messagesForContext,
|
||||||
|
assistant: { ...currentAssistant.current, settings: { streamOutput: true } },
|
||||||
|
onChunkReceived: (chunk: Chunk) => {
|
||||||
|
switch (chunk.type) {
|
||||||
|
case ChunkType.THINKING_DELTA:
|
||||||
|
{
|
||||||
|
thinkingBlockContent += chunk.text
|
||||||
|
setIsOutputted(true)
|
||||||
|
if (!thinkingBlockId) {
|
||||||
|
const block = createThinkingBlock(assistantMessage.id, chunk.text, {
|
||||||
|
status: MessageBlockStatus.STREAMING,
|
||||||
|
thinking_millsec: chunk.thinking_millsec
|
||||||
|
})
|
||||||
|
thinkingBlockId = block.id
|
||||||
|
store.dispatch(
|
||||||
|
newMessagesActions.updateMessage({
|
||||||
|
topicId,
|
||||||
|
messageId: assistantMessage.id,
|
||||||
|
updates: { blockInstruction: { id: block.id } }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
store.dispatch(upsertOneBlock(block))
|
||||||
|
} else {
|
||||||
|
store.dispatch(
|
||||||
|
updateOneBlock({
|
||||||
|
id: thinkingBlockId,
|
||||||
|
changes: { content: thinkingBlockContent, thinking_millsec: chunk.thinking_millsec }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case ChunkType.THINKING_COMPLETE:
|
||||||
|
{
|
||||||
|
if (thinkingBlockId) {
|
||||||
|
store.dispatch(
|
||||||
|
updateOneBlock({
|
||||||
|
id: thinkingBlockId,
|
||||||
|
changes: { status: MessageBlockStatus.SUCCESS, thinking_millsec: chunk.thinking_millsec }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case ChunkType.TEXT_DELTA:
|
||||||
|
{
|
||||||
|
blockContent += chunk.text
|
||||||
|
setIsOutputted(true)
|
||||||
|
if (!blockId) {
|
||||||
|
const block = createMainTextBlock(assistantMessage.id, chunk.text, {
|
||||||
|
status: MessageBlockStatus.STREAMING
|
||||||
|
})
|
||||||
|
blockId = block.id
|
||||||
|
store.dispatch(
|
||||||
|
newMessagesActions.updateMessage({
|
||||||
|
topicId,
|
||||||
|
messageId: assistantMessage.id,
|
||||||
|
updates: { blockInstruction: { id: block.id } }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
store.dispatch(upsertOneBlock(block))
|
||||||
|
} else {
|
||||||
|
store.dispatch(updateOneBlock({ id: blockId, changes: { content: blockContent } }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
|
||||||
|
case ChunkType.TEXT_COMPLETE:
|
||||||
|
{
|
||||||
|
blockId &&
|
||||||
|
store.dispatch(updateOneBlock({ id: blockId, changes: { status: MessageBlockStatus.SUCCESS } }))
|
||||||
|
store.dispatch(
|
||||||
|
newMessagesActions.updateMessage({
|
||||||
|
topicId,
|
||||||
|
messageId: assistantMessage.id,
|
||||||
|
updates: { status: AssistantMessageStatus.SUCCESS }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case ChunkType.ERROR: {
|
||||||
|
const possibleBlockId = thinkingBlockId || blockId
|
||||||
|
if (possibleBlockId) {
|
||||||
|
store.dispatch(
|
||||||
|
updateOneBlock({
|
||||||
|
id: possibleBlockId,
|
||||||
|
changes: {
|
||||||
|
status: isAbortError(chunk.error) ? MessageBlockStatus.PAUSED : MessageBlockStatus.ERROR
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (!isAbortError(chunk.error)) {
|
||||||
|
throw new Error(chunk.error.message)
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
//fall through
|
||||||
|
case ChunkType.BLOCK_COMPLETE:
|
||||||
|
setIsLoading(false)
|
||||||
|
setIsOutputted(true)
|
||||||
|
currentAskId.current = ''
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chunk.type === ChunkType.TEXT_COMPLETE) {
|
})
|
||||||
blockId && store.dispatch(updateOneBlock({ id: blockId, changes: { status: MessageBlockStatus.SUCCESS } }))
|
} catch (err) {
|
||||||
store.dispatch(
|
if (isAbortError(err)) return
|
||||||
newMessagesActions.updateMessage({
|
handleError(err instanceof Error ? err : new Error('An error occurred'))
|
||||||
topicId,
|
console.error('Error fetching result:', err)
|
||||||
messageId: assistantMessage.id,
|
} finally {
|
||||||
updates: { status: AssistantMessageStatus.SUCCESS }
|
setIsLoading(false)
|
||||||
})
|
setIsOutputted(true)
|
||||||
)
|
currentAskId.current = ''
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setIsFirstMessage(false)
|
|
||||||
setText('') // ✅ 清除输入框内容
|
|
||||||
},
|
},
|
||||||
[content, currentAssistant, topic]
|
[content, currentAssistant]
|
||||||
)
|
)
|
||||||
|
|
||||||
const clearClipboard = () => {
|
const handleEsc = () => {
|
||||||
setClipboardText('')
|
if (isLoading) {
|
||||||
setSelectedText('')
|
handlePause()
|
||||||
focusInput()
|
} else {
|
||||||
|
if (route === 'home') {
|
||||||
|
handleCloseWindow()
|
||||||
|
} else {
|
||||||
|
//if we go back to home, we should clear the topic
|
||||||
|
|
||||||
|
//clear the topic messages in order to reduce memory usage
|
||||||
|
store.dispatch(newMessagesActions.clearTopicMessages(currentTopic.current!.id))
|
||||||
|
|
||||||
|
//reset the topic
|
||||||
|
if (currentAssistant.current?.id) {
|
||||||
|
currentTopic.current = getDefaultTopic(currentAssistant.current.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
setError(null)
|
||||||
|
setRoute('home')
|
||||||
|
setUserInputText('')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the input is focused, the `Esc` callback will not be triggered here.
|
const handlePause = () => {
|
||||||
useHotkeys('esc', () => {
|
if (currentAskId.current) {
|
||||||
if (route === 'home') {
|
// const topicId = currentTopic.current!.id
|
||||||
onCloseWindow()
|
|
||||||
} else {
|
|
||||||
setRoute('home')
|
|
||||||
setText('')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
useEffect(() => {
|
// const topicMessages = selectMessagesForTopic(store.getState(), topicId)
|
||||||
window.electron.ipcRenderer.on(IpcChannel.ShowMiniWindow, onWindowShow)
|
// if (!topicMessages) return
|
||||||
|
|
||||||
return () => {
|
// const streamingMessages = topicMessages.filter((m) => m.status === 'processing' || m.status === 'pending')
|
||||||
window.electron.ipcRenderer.removeAllListeners(IpcChannel.ShowMiniWindow)
|
// const askIds = [...new Set(streamingMessages?.map((m) => m.askId).filter((id) => !!id) as string[])]
|
||||||
}
|
|
||||||
}, [onWindowShow, onSendMessage, setRoute])
|
|
||||||
|
|
||||||
// 当路由为home时,初始化isFirstMessage为true
|
// for (const askId of askIds) {
|
||||||
useEffect(() => {
|
// abortCompletion(askId)
|
||||||
if (route === 'home') {
|
// }
|
||||||
setIsFirstMessage(true)
|
// store.dispatch(newMessagesActions.setTopicLoading({ topicId: topicId, loading: false }))
|
||||||
|
|
||||||
|
abortCompletion(currentAskId.current)
|
||||||
|
// store.dispatch(newMessagesActions.setTopicLoading({ topicId: currentTopic.current!.id, loading: false }))
|
||||||
|
setIsLoading(false)
|
||||||
|
setIsOutputted(true)
|
||||||
|
currentAskId.current = ''
|
||||||
}
|
}
|
||||||
}, [route])
|
}
|
||||||
|
|
||||||
const backgroundColor = () => {
|
const backgroundColor = () => {
|
||||||
// ONLY MAC: when transparent style + light theme: use vibrancy effect
|
// ONLY MAC: when transparent style + light theme: use vibrancy effect
|
||||||
@@ -286,88 +432,96 @@ const HomeWindow: FC = () => {
|
|||||||
if (isMac && windowStyle === 'transparent' && theme === ThemeMode.light) {
|
if (isMac && windowStyle === 'transparent' && theme === ThemeMode.light) {
|
||||||
return 'transparent'
|
return 'transparent'
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'var(--color-background)'
|
return 'var(--color-background)'
|
||||||
}
|
}
|
||||||
|
|
||||||
if (['chat', 'summary', 'explanation'].includes(route)) {
|
switch (route) {
|
||||||
return (
|
case 'chat':
|
||||||
<Container style={{ backgroundColor: backgroundColor() }}>
|
case 'summary':
|
||||||
{route === 'chat' && (
|
case 'explanation':
|
||||||
<>
|
return (
|
||||||
<InputBar
|
<Container style={{ backgroundColor: backgroundColor() }}>
|
||||||
text={text}
|
{route === 'chat' && (
|
||||||
model={model}
|
<>
|
||||||
referenceText={referenceText}
|
<InputBar
|
||||||
placeholder={
|
text={userInputText}
|
||||||
quickAssistantId
|
model={currentAssistant.current?.model}
|
||||||
? t('miniwindow.input.placeholder.empty', { model: currentAssistant.name })
|
referenceText={referenceText}
|
||||||
: t('miniwindow.input.placeholder.empty', { model: model.name })
|
placeholder={t('miniwindow.input.placeholder.empty', {
|
||||||
}
|
model: quickAssistantId ? currentAssistant.current?.name : getDefaultModel().name
|
||||||
handleKeyDown={handleKeyDown}
|
})}
|
||||||
handleChange={handleChange}
|
loading={isLoading}
|
||||||
ref={inputBarRef}
|
handleKeyDown={handleKeyDown}
|
||||||
/>
|
handleChange={handleChange}
|
||||||
<Divider style={{ margin: '10px 0' }} />
|
ref={inputBarRef}
|
||||||
</>
|
/>
|
||||||
)}
|
<Divider style={{ margin: '10px 0' }} />
|
||||||
{['summary', 'explanation'].includes(route) && (
|
</>
|
||||||
<div style={{ marginTop: 10 }}>
|
)}
|
||||||
<ClipboardPreview referenceText={referenceText} clearClipboard={clearClipboard} t={t} />
|
{['summary', 'explanation'].includes(route) && (
|
||||||
</div>
|
<div style={{ marginTop: 10 }}>
|
||||||
)}
|
<ClipboardPreview referenceText={referenceText} clearClipboard={clearClipboard} t={t} />
|
||||||
<ChatWindow route={route} assistant={currentAssistant ?? defaultAssistant} />
|
</div>
|
||||||
<Divider style={{ margin: '10px 0' }} />
|
)}
|
||||||
<Footer route={route} onExit={() => setRoute('home')} />
|
<ChatWindow
|
||||||
</Container>
|
route={route}
|
||||||
)
|
assistant={currentAssistant.current!}
|
||||||
}
|
topic={currentTopic.current!}
|
||||||
|
isOutputted={isOutputted}
|
||||||
|
/>
|
||||||
|
{error && <ErrorMsg>{error}</ErrorMsg>}
|
||||||
|
|
||||||
if (route === 'translate') {
|
<Divider style={{ margin: '10px 0' }} />
|
||||||
return (
|
<Footer key="footer" route={route} loading={isLoading} onEsc={handleEsc} />
|
||||||
<Container style={{ backgroundColor: backgroundColor() }}>
|
</Container>
|
||||||
<TranslateWindow text={referenceText} />
|
)
|
||||||
<Divider style={{ margin: '10px 0' }} />
|
|
||||||
<Footer route={route} onExit={() => setRoute('home')} />
|
|
||||||
</Container>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
case 'translate':
|
||||||
<Container style={{ backgroundColor: backgroundColor() }}>
|
return (
|
||||||
<InputBar
|
<Container style={{ backgroundColor: backgroundColor() }}>
|
||||||
text={text}
|
<TranslateWindow text={referenceText} />
|
||||||
model={model}
|
<Divider style={{ margin: '10px 0' }} />
|
||||||
referenceText={referenceText}
|
<Footer key="footer" route={route} onEsc={handleEsc} />
|
||||||
placeholder={
|
</Container>
|
||||||
referenceText && route === 'home'
|
)
|
||||||
? t('miniwindow.input.placeholder.title')
|
|
||||||
: quickAssistantId
|
//Home
|
||||||
? t('miniwindow.input.placeholder.empty', { model: currentAssistant.name })
|
default:
|
||||||
: t('miniwindow.input.placeholder.empty', { model: model.name })
|
return (
|
||||||
}
|
<Container style={{ backgroundColor: backgroundColor() }}>
|
||||||
handleKeyDown={handleKeyDown}
|
<InputBar
|
||||||
handleChange={handleChange}
|
text={userInputText}
|
||||||
ref={inputBarRef}
|
model={currentAssistant.current?.model}
|
||||||
/>
|
referenceText={referenceText}
|
||||||
<Divider style={{ margin: '10px 0' }} />
|
placeholder={
|
||||||
<ClipboardPreview referenceText={referenceText} clearClipboard={clearClipboard} t={t} />
|
referenceText && route === 'home'
|
||||||
<Main>
|
? t('miniwindow.input.placeholder.title')
|
||||||
<FeatureMenus setRoute={setRoute} onSendMessage={onSendMessage} text={content} ref={featureMenusRef} />
|
: t('miniwindow.input.placeholder.empty', {
|
||||||
</Main>
|
model: quickAssistantId ? currentAssistant.current?.name : getDefaultModel().name
|
||||||
<Divider style={{ margin: '10px 0' }} />
|
})
|
||||||
<Footer
|
}
|
||||||
route={route}
|
loading={isLoading}
|
||||||
canUseBackspace={text.length > 0 || clipboardText.length == 0}
|
handleKeyDown={handleKeyDown}
|
||||||
clearClipboard={clearClipboard}
|
handleChange={handleChange}
|
||||||
onExit={() => {
|
ref={inputBarRef}
|
||||||
setRoute('home')
|
/>
|
||||||
setText('')
|
<Divider style={{ margin: '10px 0' }} />
|
||||||
onCloseWindow()
|
<ClipboardPreview referenceText={referenceText} clearClipboard={clearClipboard} t={t} />
|
||||||
}}
|
<Main>
|
||||||
/>
|
<FeatureMenus setRoute={setRoute} onSendMessage={handleSendMessage} text={content} ref={featureMenusRef} />
|
||||||
</Container>
|
</Main>
|
||||||
)
|
<Divider style={{ margin: '10px 0' }} />
|
||||||
|
<Footer
|
||||||
|
key="footer"
|
||||||
|
route={route}
|
||||||
|
canUseBackspace={userInputText.length > 0 || clipboardText.length == 0}
|
||||||
|
loading={isLoading}
|
||||||
|
clearClipboard={clearClipboard}
|
||||||
|
onEsc={handleEsc}
|
||||||
|
/>
|
||||||
|
</Container>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Container = styled.div`
|
const Container = styled.div`
|
||||||
@@ -388,4 +542,15 @@ const Main = styled.main`
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const ErrorMsg = styled.div`
|
||||||
|
color: var(--color-error);
|
||||||
|
background: rgba(255, 0, 0, 0.15);
|
||||||
|
border: 1px solid var(--color-error);
|
||||||
|
padding: 8px 12px;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
font-size: 13px;
|
||||||
|
word-break: break-all;
|
||||||
|
`
|
||||||
|
|
||||||
export default HomeWindow
|
export default HomeWindow
|
||||||
|
|||||||
@@ -1,37 +1,53 @@
|
|||||||
import { ArrowLeftOutlined } from '@ant-design/icons'
|
import { ArrowLeftOutlined, LoadingOutlined } from '@ant-design/icons'
|
||||||
import { Tag as AntdTag, Tooltip } from 'antd'
|
import { Tag as AntdTag, Tooltip } from 'antd'
|
||||||
import { CircleArrowLeft, Copy, Pin } from 'lucide-react'
|
import { CircleArrowLeft, Copy, Pin } from 'lucide-react'
|
||||||
import { FC, useState } from 'react'
|
import { FC, useState } from 'react'
|
||||||
|
import { useHotkeys } from 'react-hotkeys-hook'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
|
|
||||||
interface FooterProps {
|
interface FooterProps {
|
||||||
route: string
|
route: string
|
||||||
canUseBackspace?: boolean
|
canUseBackspace?: boolean
|
||||||
|
loading?: boolean
|
||||||
clearClipboard?: () => void
|
clearClipboard?: () => void
|
||||||
onExit: () => void
|
onEsc: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const Footer: FC<FooterProps> = ({ route, canUseBackspace, clearClipboard, onExit }) => {
|
const Footer: FC<FooterProps> = ({ route, canUseBackspace, loading, clearClipboard, onEsc }) => {
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const [isPinned, setIsPinned] = useState(false)
|
const [isPinned, setIsPinned] = useState(false)
|
||||||
|
|
||||||
const onClickPin = () => {
|
const handlePin = () => {
|
||||||
window.api.miniWindow.setPin(!isPinned).then(() => {
|
window.api.miniWindow.setPin(!isPinned).then(() => {
|
||||||
setIsPinned(!isPinned)
|
setIsPinned(!isPinned)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useHotkeys('esc', () => {
|
||||||
|
onEsc()
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WindowFooter className="drag">
|
<WindowFooter className="drag">
|
||||||
<FooterText>
|
<FooterText>
|
||||||
<Tag
|
<Tag
|
||||||
bordered={false}
|
bordered={false}
|
||||||
icon={<CircleArrowLeft size={14} color="var(--color-text)" />}
|
icon={
|
||||||
|
loading ? (
|
||||||
|
<LoadingOutlined style={{ fontSize: 12, color: 'var(--color-error)', padding: 0 }} spin />
|
||||||
|
) : (
|
||||||
|
<CircleArrowLeft size={14} color="var(--color-text)" />
|
||||||
|
)
|
||||||
|
}
|
||||||
className="nodrag"
|
className="nodrag"
|
||||||
onClick={() => onExit()}>
|
onClick={onEsc}>
|
||||||
{t('miniwindow.footer.esc', {
|
{t('miniwindow.footer.esc', {
|
||||||
action: route === 'home' ? t('miniwindow.footer.esc_close') : t('miniwindow.footer.esc_back')
|
action: loading
|
||||||
|
? t('miniwindow.footer.esc_pause')
|
||||||
|
: route === 'home'
|
||||||
|
? t('miniwindow.footer.esc_close')
|
||||||
|
: t('miniwindow.footer.esc_back')
|
||||||
})}
|
})}
|
||||||
</Tag>
|
</Tag>
|
||||||
{route === 'home' && !canUseBackspace && (
|
{route === 'home' && !canUseBackspace && (
|
||||||
@@ -54,7 +70,7 @@ const Footer: FC<FooterProps> = ({ route, canUseBackspace, clearClipboard, onExi
|
|||||||
</Tag>
|
</Tag>
|
||||||
)}
|
)}
|
||||||
</FooterText>
|
</FooterText>
|
||||||
<PinButtonArea onClick={() => onClickPin()} className="nodrag">
|
<PinButtonArea onClick={() => handlePin()} className="nodrag">
|
||||||
<Tooltip title={t('miniwindow.tooltip.pin')} mouseEnterDelay={0.8} placement="left">
|
<Tooltip title={t('miniwindow.tooltip.pin')} mouseEnterDelay={0.8} placement="left">
|
||||||
<Pin size={14} stroke={isPinned ? 'var(--color-primary)' : 'var(--color-text)'} />
|
<Pin size={14} stroke={isPinned ? 'var(--color-primary)' : 'var(--color-text)'} />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import ModelAvatar from '@renderer/components/Avatar/ModelAvatar'
|
import ModelAvatar from '@renderer/components/Avatar/ModelAvatar'
|
||||||
import { useRuntime } from '@renderer/hooks/useRuntime'
|
|
||||||
import { Input as AntdInput } from 'antd'
|
import { Input as AntdInput } from 'antd'
|
||||||
import { InputRef } from 'rc-input/lib/interface'
|
import { InputRef } from 'rc-input/lib/interface'
|
||||||
import React, { useRef } from 'react'
|
import React, { useRef } from 'react'
|
||||||
@@ -10,6 +9,7 @@ interface InputBarProps {
|
|||||||
model: any
|
model: any
|
||||||
referenceText: string
|
referenceText: string
|
||||||
placeholder: string
|
placeholder: string
|
||||||
|
loading: boolean
|
||||||
handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void
|
handleKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => void
|
||||||
handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void
|
handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void
|
||||||
}
|
}
|
||||||
@@ -19,12 +19,12 @@ const InputBar = ({
|
|||||||
text,
|
text,
|
||||||
model,
|
model,
|
||||||
placeholder,
|
placeholder,
|
||||||
|
loading,
|
||||||
handleKeyDown,
|
handleKeyDown,
|
||||||
handleChange
|
handleChange
|
||||||
}: InputBarProps & { ref?: React.RefObject<HTMLDivElement | null> }) => {
|
}: InputBarProps & { ref?: React.RefObject<HTMLDivElement | null> }) => {
|
||||||
const { generating } = useRuntime()
|
|
||||||
const inputRef = useRef<InputRef>(null)
|
const inputRef = useRef<InputRef>(null)
|
||||||
if (!generating) {
|
if (!loading) {
|
||||||
setTimeout(() => inputRef.current?.input?.focus(), 0)
|
setTimeout(() => inputRef.current?.input?.focus(), 0)
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
@@ -37,7 +37,7 @@ const InputBar = ({
|
|||||||
autoFocus
|
autoFocus
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
disabled={generating}
|
disabled={loading}
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
/>
|
/>
|
||||||
</InputWrapper>
|
</InputWrapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user