import React, { useCallback, useEffect, useState } from 'react' import { TextArea } from '@janhq/joi' import { useAtomValue } from 'jotai' import { useDebouncedCallback } from 'use-debounce' import useUpdateInstruction from '@/hooks/useUpdateInstruction' import { activeThreadAtom } from '@/helpers/atoms/Thread.atom' const AssistantSettingContainer: React.FC = () => { const activeThread = useAtomValue(activeThreadAtom) const [instructions, setInstructions] = useState( activeThread?.assistants[0]?.instructions || '' ) const { updateInstruction } = useUpdateInstruction() useEffect(() => { setInstructions(activeThread?.assistants[0]?.instructions || '') }, [activeThread]) const debounced = useDebouncedCallback(async (instruction: string) => { updateInstruction(instruction) }, 500) const onInstructionChanged = useCallback( (e: React.ChangeEvent) => { e.preventDefault() e.stopPropagation() setInstructions(e.target.value) debounced(e.target.value) }, [debounced] ) return (