-
Notifications
You must be signed in to change notification settings - Fork 3
/
ConversationManager.js
45 lines (33 loc) · 1.05 KB
/
ConversationManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use client'
import { createContext } from 'react'
import useConversationManager from '../hooks/useConversationManager.js'
export const ConversationContext = createContext(
/** @type {import('../hooks/useConversationManager.js').UseConversationManagerResult} */ ({
message: null,
messages: [],
thinking: false,
typing: false,
text: '',
setText: () => {},
error: null,
setError: () => {},
submit: async () => false,
trigger: async () => false,
request: async () => false,
})
)
/**
* Creates a conversation manager instance and context.
*
* @param {import('../hooks/useConversationManager.js').UseConversationManagerOptions & { children: import('react').ReactNode}} props
* @returns {import('react').ReactElement} The rendered component.
*/
export function ConversationManager({ children, ...options }) {
const manager = useConversationManager(options)
return (
<ConversationContext.Provider value={manager}>
{children}
</ConversationContext.Provider>
)
}
export default ConversationManager