@gravity-ui/aikit 1.3.5 → 1.4.0

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.
@@ -9,8 +9,8 @@ import { UserMessage } from '../UserMessage';
9
9
  import { ErrorAlert } from './ErrorAlert';
10
10
  import './MessageList.scss';
11
11
  const b = block('message-list');
12
- export function MessageList({ messages, messageRendererRegistry, transformOptions, shouldParseIncompleteMarkdown, showActionsOnHover, showTimestamp, showAvatar, userActions, assistantActions, loaderStatuses = ['submitted'], className, qa, status, errorMessage, onRetry, hasPreviousMessages = false, onLoadPreviousMessages, }) {
13
- const isStreaming = status === 'streaming';
12
+ export function MessageList({ messages, messageRendererRegistry, transformOptions, shouldParseIncompleteMarkdown, showActionsOnHover, showTimestamp, showAvatar, userActions, assistantActions, loaderStatuses = ['submitted', 'streaming_loading'], className, qa, status, errorMessage, onRetry, hasPreviousMessages = false, onLoadPreviousMessages, }) {
13
+ const isStreaming = status === 'streaming' || status === 'streaming_loading';
14
14
  const isSubmitted = status === 'submitted';
15
15
  const showLoader = status && loaderStatuses.includes(status);
16
16
  const { containerRef } = useSmartScroll({
@@ -16,6 +16,7 @@ export function usePromptInput(props) {
16
16
  // ChatStatus.ready → submitButtonState.enabled
17
17
  // ChatStatus.error → submitButtonState.enabled
18
18
  // ChatStatus.streaming → submitButtonState.cancelable
19
+ // ChatStatus.streaming_loading → submitButtonState.cancelable (same as streaming)
19
20
  // ChatStatus.submitted → submitButtonState.loading
20
21
  let submitButtonState = 'disabled';
21
22
  // disabled by props or empty value and status is ready
@@ -32,6 +33,7 @@ export function usePromptInput(props) {
32
33
  submitButtonState = 'enabled';
33
34
  break;
34
35
  case 'streaming':
36
+ case 'streaming_loading':
35
37
  submitButtonState = onCancel ? 'cancelable' : 'enabled';
36
38
  break;
37
39
  case 'submitted':
@@ -359,9 +359,16 @@ export const WithStreaming = {
359
359
  actions: createMessageActions(assistantMessageId, 'assistant'),
360
360
  },
361
361
  ]);
362
- // Simulate word-by-word streaming
362
+ // Simulate word-by-word streaming with a streaming_loading pause in the middle
363
363
  const words = fullResponse.split(' ');
364
+ const pauseIndex = Math.floor(words.length / 2);
364
365
  for (let i = 0; i < words.length; i++) {
366
+ // Pause streaming at the midpoint: switch to streaming_loading for 5 seconds
367
+ if (i === pauseIndex) {
368
+ setStatus('streaming_loading');
369
+ await new Promise((resolve) => setTimeout(resolve, 5000));
370
+ setStatus('streaming');
371
+ }
365
372
  await new Promise((resolve) => setTimeout(resolve, 100));
366
373
  const currentText = words.slice(0, i + 1).join(' ');
367
374
  setMessages((prev) => prev.map((msg) => msg.id === assistantMessageId
@@ -747,7 +754,10 @@ export const FullStreamingExample = {
747
754
  const [controller, setController] = useState(null);
748
755
  const isProcessingRef = React.useRef(false);
749
756
  const handleSendMessage = async (data) => {
750
- if (isProcessingRef.current || status === 'streaming' || status === 'submitted') {
757
+ if (isProcessingRef.current ||
758
+ status === 'streaming' ||
759
+ status === 'streaming_loading' ||
760
+ status === 'submitted') {
751
761
  return;
752
762
  }
753
763
  isProcessingRef.current = true;
@@ -5,7 +5,7 @@ export type ChatType = {
5
5
  lastMessage?: string;
6
6
  metadata?: Record<string, unknown>;
7
7
  };
8
- export type ChatStatus = 'submitted' | 'streaming' | 'ready' | 'error';
8
+ export type ChatStatus = 'submitted' | 'streaming' | 'streaming_loading' | 'ready' | 'error';
9
9
  /**
10
10
  * List item type for chat history that can be either a chat or a date header
11
11
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravity-ui/aikit",
3
- "version": "1.3.5",
3
+ "version": "1.4.0",
4
4
  "description": "Gravity UI base kit for building ai assistant chats",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.js",