Skip to content

Commit

Permalink
prevent running button to display twice when cot is false and streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
willydouhard committed Jan 12, 2024
1 parent d76a35e commit 21a5fb1
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 20 deletions.
3 changes: 1 addition & 2 deletions libs/react-components/src/messages/Messages.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { MessageContext } from 'contexts/MessageContext';
import { memo, useContext } from 'react';
import { isLastMessage } from 'utils/message';

import type { IAction, IMessageElement, IStep } from 'client-types/';

Expand Down Expand Up @@ -45,7 +44,7 @@ const Messages = memo(
<>
{filtered.map((m, i) => {
const author = m.name;
const isLast = isLastMessage(filtered, i);
const isLast = filtered.length - 1 === i;
let messageRunning =
isRunning === undefined ? messageContext.loading : isRunning;
if (isRoot) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DetailsButton = ({ message, opened, onClick, loading }: Props) => {
const messageContext = useContext(MessageContext);

const nestedCount = message.steps?.length;
const nested = !!nestedCount;
const nested = !!nestedCount && !messageContext.hideCot;

const lastStep = nested ? message.steps![nestedCount - 1] : undefined;

Expand Down
18 changes: 1 addition & 17 deletions libs/react-components/utils/message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IMessageElement, IStep } from 'client-types/';
import type { IMessageElement } from 'client-types/';

const isForIdMatch = (id: string | number | undefined, forId: string) => {
if (!forId || !id) {
Expand Down Expand Up @@ -80,19 +80,3 @@ export const prepareContent = ({
refElements
};
};

export const isLastMessage = (messages: IStep[], index: number) => {
if (messages.length - 1 === index) {
return true;
}

for (let i = index + 1; i < messages.length; i++) {
if (messages[i].streaming) {
continue;
} else {
return false;
}
}

return true;
};

0 comments on commit 21a5fb1

Please sign in to comment.