stream-chat-react 13.13.2 → 13.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/components/AIStateIndicator/hooks/useAIState.d.ts +1 -0
- package/dist/components/AIStateIndicator/hooks/useAIState.js +8 -0
- package/dist/components/Chat/hooks/useChat.js +1 -1
- package/dist/components/Message/StreamedMessageText.js +9 -3
- package/dist/components/Message/hooks/useMessageTextStreaming.d.ts +2 -1
- package/dist/components/Message/hooks/useMessageTextStreaming.js +7 -1
- package/dist/index.browser.cjs +22 -3
- package/dist/index.browser.cjs.map +2 -2
- package/dist/index.node.cjs +22 -3
- package/dist/index.node.cjs.map +2 -2
- package/package.json +2 -2
- /package/{INTEGRATION_GUIDE.md → AI.md} +0 -0
package/README.md
CHANGED
|
@@ -117,3 +117,7 @@ The library source code is dynamically imported and used only if audio recording
|
|
|
117
117
|
|
|
118
118
|
You can obtain the source code for `lamejs` from the [lamejs repository](https://github.com/gideonstele/lamejs) that is a fork of [the original JS library](https://github.com/zhuker/lamejs).
|
|
119
119
|
You can find the source code for LAME at https://lame.sourceforge.net and its license at: https://lame.sourceforge.net/license.txt
|
|
120
|
+
|
|
121
|
+
Using AI assistants (Cursor/Codex/Copilot):
|
|
122
|
+
See [AI.md](./AI.md) for integration guide, rules and common pitfalls.
|
|
123
|
+
See [AGENTS.md](./AGENTS.md) about repository and project structure, contribution guides.
|
|
@@ -4,6 +4,7 @@ export const AIStates = {
|
|
|
4
4
|
ExternalSources: 'AI_STATE_EXTERNAL_SOURCES',
|
|
5
5
|
Generating: 'AI_STATE_GENERATING',
|
|
6
6
|
Idle: 'AI_STATE_IDLE',
|
|
7
|
+
Stop: 'AI_STATE_STOP',
|
|
7
8
|
Thinking: 'AI_STATE_THINKING',
|
|
8
9
|
};
|
|
9
10
|
/**
|
|
@@ -30,9 +31,16 @@ export const useAIState = (channel) => {
|
|
|
30
31
|
setAiState(AIStates.Idle);
|
|
31
32
|
}
|
|
32
33
|
});
|
|
34
|
+
const indicatorStoppedListener = channel.on('ai_indicator.stop', (event) => {
|
|
35
|
+
const { cid } = event;
|
|
36
|
+
if (channel.cid === cid) {
|
|
37
|
+
setAiState(AIStates.Stop);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
33
40
|
return () => {
|
|
34
41
|
indicatorChangedListener.unsubscribe();
|
|
35
42
|
indicatorClearedListener.unsubscribe();
|
|
43
|
+
indicatorStoppedListener.unsubscribe();
|
|
36
44
|
};
|
|
37
45
|
}, [channel]);
|
|
38
46
|
return { aiState };
|
|
@@ -24,7 +24,7 @@ export const useChat = ({ client, defaultLanguage = 'en', i18nInstance, initialN
|
|
|
24
24
|
useEffect(() => {
|
|
25
25
|
if (!client)
|
|
26
26
|
return;
|
|
27
|
-
const version = "13.13.
|
|
27
|
+
const version = "13.13.4";
|
|
28
28
|
const userAgent = client.getUserAgent();
|
|
29
29
|
if (!userAgent.includes('stream-chat-react')) {
|
|
30
30
|
// result looks like: 'stream-chat-react-2.3.2-stream-chat-javascript-client-browser-2.2.2'
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
2
|
import { MessageText } from './MessageText';
|
|
3
|
-
import { useMessageContext } from '../../context';
|
|
3
|
+
import { useChannelStateContext, useMessageContext } from '../../context';
|
|
4
4
|
import { useMessageTextStreaming } from './hooks';
|
|
5
5
|
export const StreamedMessageText = (props) => {
|
|
6
6
|
const { message: messageFromProps, renderingLetterCount, renderText, streamingLetterIntervalMs, } = props;
|
|
7
7
|
const { message: messageFromContext } = useMessageContext('StreamedMessageText');
|
|
8
|
+
const { channel } = useChannelStateContext();
|
|
8
9
|
const message = messageFromProps || messageFromContext;
|
|
9
10
|
const { text = '' } = message;
|
|
10
|
-
const { streamedMessageText } = useMessageTextStreaming({
|
|
11
|
+
const { skipAnimation, streamedMessageText } = useMessageTextStreaming({
|
|
11
12
|
renderingLetterCount,
|
|
12
13
|
streamingLetterIntervalMs,
|
|
13
14
|
text,
|
|
14
15
|
});
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
channel?.on('ai_indicator.stop', () => {
|
|
18
|
+
skipAnimation();
|
|
19
|
+
});
|
|
20
|
+
}, [channel, skipAnimation]);
|
|
15
21
|
return (React.createElement(MessageText, { message: { ...message, text: streamedMessageText }, renderText: renderText }));
|
|
16
22
|
};
|
|
@@ -11,5 +11,6 @@ export type UseMessageTextStreamingProps = Pick<StreamedMessageTextProps, 'strea
|
|
|
11
11
|
* @returns {{ streamedMessageText: string }} - A substring of the text property, up until we've finished rendering the typewriter animation.
|
|
12
12
|
*/
|
|
13
13
|
export declare const useMessageTextStreaming: ({ renderingLetterCount, streamingLetterIntervalMs, text, }: UseMessageTextStreamingProps) => {
|
|
14
|
-
|
|
14
|
+
readonly skipAnimation: import("../../../utils/useStableCallback").StableCallback<[], void>;
|
|
15
|
+
readonly streamedMessageText: string;
|
|
15
16
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useStableCallback } from '../../../utils/useStableCallback';
|
|
2
3
|
const DEFAULT_LETTER_INTERVAL = 30;
|
|
3
4
|
const DEFAULT_RENDERING_LETTER_COUNT = 2;
|
|
4
5
|
/**
|
|
@@ -17,6 +18,7 @@ export const useMessageTextStreaming = ({ renderingLetterCount = DEFAULT_RENDERI
|
|
|
17
18
|
const interval = setInterval(() => {
|
|
18
19
|
if (!text || textCursor.current >= textLength) {
|
|
19
20
|
clearInterval(interval);
|
|
21
|
+
return;
|
|
20
22
|
}
|
|
21
23
|
const newCursorValue = textCursor.current + renderingLetterCount;
|
|
22
24
|
const newText = text.substring(0, newCursorValue);
|
|
@@ -27,5 +29,9 @@ export const useMessageTextStreaming = ({ renderingLetterCount = DEFAULT_RENDERI
|
|
|
27
29
|
clearInterval(interval);
|
|
28
30
|
};
|
|
29
31
|
}, [streamingLetterIntervalMs, renderingLetterCount, text]);
|
|
30
|
-
|
|
32
|
+
const skipAnimation = useStableCallback(() => {
|
|
33
|
+
textCursor.current = text.length;
|
|
34
|
+
setStreamedMessageText(text);
|
|
35
|
+
});
|
|
36
|
+
return { skipAnimation, streamedMessageText };
|
|
31
37
|
};
|
package/dist/index.browser.cjs
CHANGED
|
@@ -729,6 +729,7 @@ var AIStates = {
|
|
|
729
729
|
ExternalSources: "AI_STATE_EXTERNAL_SOURCES",
|
|
730
730
|
Generating: "AI_STATE_GENERATING",
|
|
731
731
|
Idle: "AI_STATE_IDLE",
|
|
732
|
+
Stop: "AI_STATE_STOP",
|
|
732
733
|
Thinking: "AI_STATE_THINKING"
|
|
733
734
|
};
|
|
734
735
|
var useAIState = (channel) => {
|
|
@@ -750,9 +751,16 @@ var useAIState = (channel) => {
|
|
|
750
751
|
setAiState(AIStates.Idle);
|
|
751
752
|
}
|
|
752
753
|
});
|
|
754
|
+
const indicatorStoppedListener = channel.on("ai_indicator.stop", (event) => {
|
|
755
|
+
const { cid } = event;
|
|
756
|
+
if (channel.cid === cid) {
|
|
757
|
+
setAiState(AIStates.Stop);
|
|
758
|
+
}
|
|
759
|
+
});
|
|
753
760
|
return () => {
|
|
754
761
|
indicatorChangedListener.unsubscribe();
|
|
755
762
|
indicatorClearedListener.unsubscribe();
|
|
763
|
+
indicatorStoppedListener.unsubscribe();
|
|
756
764
|
};
|
|
757
765
|
}, [channel]);
|
|
758
766
|
return { aiState };
|
|
@@ -16927,6 +16935,7 @@ var useMessageTextStreaming = ({
|
|
|
16927
16935
|
const interval = setInterval(() => {
|
|
16928
16936
|
if (!text8 || textCursor.current >= textLength) {
|
|
16929
16937
|
clearInterval(interval);
|
|
16938
|
+
return;
|
|
16930
16939
|
}
|
|
16931
16940
|
const newCursorValue = textCursor.current + renderingLetterCount;
|
|
16932
16941
|
const newText = text8.substring(0, newCursorValue);
|
|
@@ -16937,7 +16946,11 @@ var useMessageTextStreaming = ({
|
|
|
16937
16946
|
clearInterval(interval);
|
|
16938
16947
|
};
|
|
16939
16948
|
}, [streamingLetterIntervalMs, renderingLetterCount, text8]);
|
|
16940
|
-
|
|
16949
|
+
const skipAnimation = useStableCallback(() => {
|
|
16950
|
+
textCursor.current = text8.length;
|
|
16951
|
+
setStreamedMessageText(text8);
|
|
16952
|
+
});
|
|
16953
|
+
return { skipAnimation, streamedMessageText };
|
|
16941
16954
|
};
|
|
16942
16955
|
|
|
16943
16956
|
// src/components/Message/hooks/useMessageReminder.ts
|
|
@@ -24077,13 +24090,19 @@ var StreamedMessageText = (props) => {
|
|
|
24077
24090
|
streamingLetterIntervalMs
|
|
24078
24091
|
} = props;
|
|
24079
24092
|
const { message: messageFromContext } = useMessageContext("StreamedMessageText");
|
|
24093
|
+
const { channel } = useChannelStateContext();
|
|
24080
24094
|
const message = messageFromProps || messageFromContext;
|
|
24081
24095
|
const { text: text8 = "" } = message;
|
|
24082
|
-
const { streamedMessageText } = useMessageTextStreaming({
|
|
24096
|
+
const { skipAnimation, streamedMessageText } = useMessageTextStreaming({
|
|
24083
24097
|
renderingLetterCount,
|
|
24084
24098
|
streamingLetterIntervalMs,
|
|
24085
24099
|
text: text8
|
|
24086
24100
|
});
|
|
24101
|
+
(0, import_react160.useEffect)(() => {
|
|
24102
|
+
channel?.on("ai_indicator.stop", () => {
|
|
24103
|
+
skipAnimation();
|
|
24104
|
+
});
|
|
24105
|
+
}, [channel, skipAnimation]);
|
|
24087
24106
|
return /* @__PURE__ */ import_react160.default.createElement(
|
|
24088
24107
|
MessageText,
|
|
24089
24108
|
{
|
|
@@ -37399,7 +37418,7 @@ var useChat = ({
|
|
|
37399
37418
|
};
|
|
37400
37419
|
(0, import_react289.useEffect)(() => {
|
|
37401
37420
|
if (!client) return;
|
|
37402
|
-
const version = "13.13.
|
|
37421
|
+
const version = "13.13.4";
|
|
37403
37422
|
const userAgent = client.getUserAgent();
|
|
37404
37423
|
if (!userAgent.includes("stream-chat-react")) {
|
|
37405
37424
|
client.setUserAgent(`stream-chat-react-${version}-${userAgent}`);
|