({
pageId,
messages,
currentPath,
topics
}: UseChatTopicsOptions)
| 39 | } |
| 40 | |
| 41 | export function useChatTopics({ |
| 42 | pageId, |
| 43 | messages, |
| 44 | currentPath, |
| 45 | topics |
| 46 | }: UseChatTopicsOptions): UseChatTopicsResult { |
| 47 | const [isSegmenting, setIsSegmenting] = useState(false) |
| 48 | |
| 49 | const createTopic = useCallback( |
| 50 | async (messageId: string, name: string): Promise<Topic | undefined> => { |
| 51 | try { |
| 52 | return await messagesService.createTopic(pageId, name, messageId) |
| 53 | } catch (error) { |
| 54 | console.error('Failed to create topic:', error) |
| 55 | return undefined |
| 56 | } |
| 57 | }, |
| 58 | [pageId] |
| 59 | ) |
| 60 | |
| 61 | const updateTopic = useCallback( |
| 62 | async (topicId: string, updates: Partial<Omit<Topic, 'id'>>) => { |
| 63 | try { |
| 64 | await messagesService.updateTopic(pageId, topicId, updates) |
| 65 | } catch (error) { |
| 66 | console.error('Failed to update topic:', error) |
| 67 | } |
| 68 | }, |
| 69 | [pageId] |
| 70 | ) |
| 71 | |
| 72 | const deleteTopic = useCallback( |
| 73 | async (topicId: string) => { |
| 74 | try { |
| 75 | await messagesService.deleteTopic(pageId, topicId) |
| 76 | } catch (error) { |
| 77 | console.error('Failed to delete topic:', error) |
| 78 | } |
| 79 | }, |
| 80 | [pageId] |
| 81 | ) |
| 82 | |
| 83 | const toggleTopicCollapse = useCallback( |
| 84 | async (topicId: string) => { |
| 85 | try { |
| 86 | await messagesService.toggleTopicCollapse(pageId, topicId) |
| 87 | } catch (error) { |
| 88 | console.error('Failed to toggle topic collapse:', error) |
| 89 | } |
| 90 | }, |
| 91 | [pageId] |
| 92 | ) |
| 93 | |
| 94 | const findTopicByMessageId = useCallback( |
| 95 | (messageId: string): Topic | undefined => { |
| 96 | return messagesService.findTopicByStartMessageId(topics, messageId) |
| 97 | }, |
| 98 | [topics] |
no test coverage detected