File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,16 @@ export const AIStates = {
1212 Thinking : 'AI_STATE_THINKING' ,
1313} ;
1414
15+ /**
16+ * A hook that returns the current state of the AI.
17+ * @param {Channel } channel - The channel for which we want to know the AI state.
18+ * @returns {{ aiState: AIState } } The current AI state for the given channel.
19+ */
1520export const useAIState = <
1621 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
1722> (
1823 channel ?: Channel < StreamChatGenerics > ,
19- ) => {
24+ ) : { aiState : AIState } => {
2025 const [ aiState , setAiState ] = useState < AIState > ( AIStates . Idle ) ;
2126
2227 useEffect ( ( ) => {
Original file line number Diff line number Diff line change @@ -13,13 +13,21 @@ export type UseMessageTextStreamingProps<
1313const DEFAULT_LETTER_INTERVAL = 30 ;
1414const DEFAULT_RENDERING_LETTER_COUNT = 2 ;
1515
16+ /**
17+ * A hook that returns text in a streamed, typewriter fashion. The speed of streaming is
18+ * configurable.
19+ * @param {number } [streamingLetterIntervalMs=30] - The timeout between each typing animation in milliseconds.
20+ * @param {number } [renderingLetterCount=2] - The number of letters to be rendered each time we update.
21+ * @param {string } text - The text that we want to render in a typewriter fashion.
22+ * @returns {{ streamedMessageText: string } } - A substring of the text property, up until we've finished rendering the typewriter animation.
23+ */
1624export const useMessageTextStreaming = <
1725 StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
1826> ( {
1927 streamingLetterIntervalMs = DEFAULT_LETTER_INTERVAL ,
2028 renderingLetterCount = DEFAULT_RENDERING_LETTER_COUNT ,
2129 text,
22- } : UseMessageTextStreamingProps < StreamChatGenerics > ) => {
30+ } : UseMessageTextStreamingProps < StreamChatGenerics > ) : { streamedMessageText : string } => {
2331 const [ streamedMessageText , setStreamedMessageText ] = useState < string > ( text ) ;
2432 const textCursor = useRef < number > ( text . length ) ;
2533
You can’t perform that action at this time.
0 commit comments