import React, { useContext } from 'react' import { getUserSpace, openFileExplorer, joinPath } 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 { FeatureToggleContext } from '@/context/FeatureToggle' import { useCreateNewThread } from '@/hooks/useCreateNewThread' import { toSettingParams } from '@/utils/model_param' import EngineSetting from '../EngineSetting' import ModelSetting from '../ModelSetting' import { activeThreadAtom, getActiveThreadModelParamsAtom, threadStatesAtom, } from '@/helpers/atoms/Thread.atom' export const showRightSideBarAtom = atom(true) const Sidebar: React.FC = () => { const showing = useAtomValue(showRightSideBarAtom) const activeThread = useAtomValue(activeThreadAtom) const selectedModel = useAtomValue(selectedModelAtom) const { updateThreadMetadata } = useCreateNewThread() const threadStates = useAtomValue(threadStatesAtom) const { experimentalFeatureEnabed } = useContext(FeatureToggleContext) const activeModelParams = useAtomValue(getActiveThreadModelParamsAtom) const modelSettingParams = toSettingParams(activeModelParams) 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 'Engine': case 'Thread': filePath = await joinPath(['threads', activeThread.id]) break case 'Model': if (!selectedModel) return filePath = await joinPath(['models', selectedModel.id]) break case 'Assistant': if (!assistantId) return filePath = await joinPath(['assistants', assistantId]) break default: break } if (!filePath) return const fullPath = await joinPath([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 'Engine': case 'Thread': filePath = await joinPath(['threads', activeThread.id, 'thread.json']) break case 'Model': if (!selectedModel) return filePath = await joinPath(['models', selectedModel.id, 'model.json']) break case 'Assistant': if (!assistantId) return filePath = await joinPath(['assistants', assistantId, 'assistant.json']) break default: break } if (!filePath) return const fullPath = await joinPath([userSpace, filePath]) openFileExplorer(fullPath) } return (
{ if (activeThread) updateThreadMetadata({ ...activeThread, title: e.target.value || '', }) }} />
{activeThread?.id || '-'}
{activeThread?.assistants[0].assistant_name ?? '-'}