import { join } from 'path' import { getUserSpace, openFileExplorer } from '@janhq/core' import { Input, Textarea } from '@janhq/uikit' import { atom, useAtomValue } from 'jotai' import { twMerge } from 'tailwind-merge' import LogoMark from '@/containers/Brand/Logo/Mark' import CardSidebar from '@/containers/CardSidebar' import DropdownListSidebar, { selectedModelAtom, } from '@/containers/DropdownListSidebar' import { useCreateNewThread } from '@/hooks/useCreateNewThread' import ModelSetting from '../ModelSetting' import { activeThreadAtom, threadStatesAtom } from '@/helpers/atoms/Thread.atom' export const showRightSideBarAtom = atom(true) export default function Sidebar() { const showing = useAtomValue(showRightSideBarAtom) const activeThread = useAtomValue(activeThreadAtom) const selectedModel = useAtomValue(selectedModelAtom) const { updateThreadMetadata } = useCreateNewThread() const threadStates = useAtomValue(threadStatesAtom) const onReviewInFinderClick = async (type: string) => { if (!activeThread) return const activeThreadState = threadStates[activeThread.id] if (!activeThreadState.isFinishInit) { alert('Thread is not started yet') return } const userSpace = await getUserSpace() let filePath = undefined const assistantId = activeThread.assistants[0]?.assistant_id switch (type) { case 'Thread': filePath = join('threads', activeThread.id) break case 'Model': if (!selectedModel) return filePath = join('models', selectedModel.id) break case 'Assistant': if (!assistantId) return filePath = join('assistants', assistantId) break default: break } if (!filePath) return const fullPath = join(userSpace, filePath) openFileExplorer(fullPath) } const onViewJsonClick = async (type: string) => { if (!activeThread) return const activeThreadState = threadStates[activeThread.id] if (!activeThreadState.isFinishInit) { alert('Thread is not started yet') return } const userSpace = await getUserSpace() let filePath = undefined const assistantId = activeThread.assistants[0]?.assistant_id switch (type) { case 'Thread': filePath = join('threads', activeThread.id, 'thread.json') break case 'Model': if (!selectedModel) return filePath = join('models', selectedModel.id, 'model.json') break case 'Assistant': if (!assistantId) return filePath = join('assistants', assistantId, 'assistant.json') break default: break } if (!filePath) return const fullPath = join(userSpace, filePath) openFileExplorer(fullPath) } return (
{ if (activeThread) updateThreadMetadata({ ...activeThread, title: e.target.value || '', }) }} />
{activeThread?.id || '-'}
{activeThread?.assistants[0].assistant_name ?? '-'}