diff --git a/web/hooks/useSendChatMessage.ts b/web/hooks/useSendChatMessage.ts index 1c9334fb5..3242b085c 100644 --- a/web/hooks/useSendChatMessage.ts +++ b/web/hooks/useSendChatMessage.ts @@ -13,6 +13,8 @@ import { ContentType, EngineManager, InferenceEngine, + MessageStatus, + ChatCompletionRole, } from '@janhq/core' import { extractInferenceParams, extractModelLoadParams } from '@janhq/core' import { atom, useAtom, useAtomValue, useSetAtom } from 'jotai' @@ -20,7 +22,7 @@ import { OpenAI } from 'openai' import { ChatCompletionMessageParam, - ChatCompletionRole, + ChatCompletionRole as OpenAIChatCompletionRole, ChatCompletionTool, } from 'openai/resources/chat' @@ -261,7 +263,7 @@ export default function useSendChatMessage() { const response = await openai.chat.completions.create({ messages: (data.messages ?? []).map((e) => { return { - role: e.role as ChatCompletionRole, + role: e.role as OpenAIChatCompletionRole, content: e.content, } }) as ChatCompletionMessageParam[], @@ -276,24 +278,24 @@ export default function useSendChatMessage() { thread_id: activeThreadRef.current.id, assistant_id: activeAssistantRef.current.assistant_id, attachments: [], - role: response.choices[0].message.role as any, + role: response.choices[0].message.role as ChatCompletionRole, content: [ { type: ContentType.Text, text: { value: response.choices[0].message.content - ? (response.choices[0].message.content as any) + ? response.choices[0].message.content : '', annotations: [], }, }, ], - status: 'ready' as any, + status: MessageStatus.Ready, created_at: Date.now(), completed_at: Date.now(), } requestBuilder.pushAssistantMessage( - (response.choices[0].message.content as any) ?? '' + response.choices[0].message.content ?? '' ) events.emit(MessageEvent.OnMessageUpdate, newMessage) } @@ -307,7 +309,7 @@ export default function useSendChatMessage() { thread_id: activeThreadRef.current.id, assistant_id: activeAssistantRef.current.assistant_id, attachments: [], - role: 'assistant' as any, + role: ChatCompletionRole.Assistant, content: [ { type: ContentType.Text, @@ -317,7 +319,7 @@ export default function useSendChatMessage() { }, }, ], - status: 'pending' as any, + status: MessageStatus.Pending, created_at: Date.now(), completed_at: Date.now(), } @@ -336,7 +338,7 @@ export default function useSendChatMessage() { thread_id: activeThreadRef.current.id, assistant_id: activeAssistantRef.current.assistant_id, attachments: [], - role: 'assistant' as any, + role: ChatCompletionRole.Assistant, content: [ { type: ContentType.Text, @@ -348,7 +350,7 @@ export default function useSendChatMessage() { }, }, ], - status: 'ready' as any, + status: MessageStatus.Ready, created_at: Date.now(), completed_at: Date.now(), } diff --git a/web/screens/Settings/Appearance/index.tsx b/web/screens/Settings/Appearance/index.tsx index 69c68dd52..c9bd0fb93 100644 --- a/web/screens/Settings/Appearance/index.tsx +++ b/web/screens/Settings/Appearance/index.tsx @@ -2,7 +2,6 @@ import { useCallback } from 'react' import { useTheme } from 'next-themes' -import { fs, joinPath } from '@janhq/core' import { Button, ScrollArea, Select, Switch } from '@janhq/joi' import { useAtom, useAtomValue } from 'jotai' @@ -51,9 +50,11 @@ export default function AppearanceOptions() { const handleClickTheme = useCallback( async (e: string) => { setSelectedIdTheme(e) - const janThemesPath = await joinPath([janDataFolderPath, 'themes']) - const filePath = await joinPath([`${janThemesPath}/${e}`, `theme.json`]) - const theme: Theme = JSON.parse(await fs.readFileSync(filePath, 'utf-8')) + const theme: Theme = JSON.parse( + await window.core.api.readTheme({ + themeName: e, + }) + ) setThemeData(theme) setTheme(String(theme?.nativeTheme)) },