buster/web/src/controllers/ReasoningController/ReasoningMessageContainer.tsx

108 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-03-05 04:52:33 +08:00
'use client';
2025-02-08 13:24:18 +08:00
import type { BusterChatMessageReasoning } from '@/api/asset_interfaces';
import React, { useMemo } from 'react';
import { ReasoningMessageSelector } from './ReasoningMessages';
import { createStyles } from 'antd-style';
export const ReasoningMessageContainer: React.FC<{
reasoningMessages: BusterChatMessageReasoning[];
isCompletedStream: boolean;
2025-02-11 06:21:59 +08:00
chatId: string;
}> = React.memo(({ reasoningMessages, isCompletedStream, chatId }) => {
2025-02-08 13:24:18 +08:00
const { cx, styles } = useStyles();
2025-02-09 05:37:46 +08:00
const lastMessageIndex = reasoningMessages.length - 1;
2025-02-08 13:24:18 +08:00
const typeClassRecord: Record<BusterChatMessageReasoning['type'], string> = useMemo(() => {
return {
text: cx(styles.textCard, 'text-card'),
2025-03-01 02:30:39 +08:00
pills: cx(styles.pillsCard, 'pills-card'),
2025-03-05 00:32:47 +08:00
files: cx(styles.fileCard, 'file-card')
2025-02-08 13:24:18 +08:00
};
}, []);
const getContainerClass = (item: BusterChatMessageReasoning) => {
return typeClassRecord[item.type];
};
return (
<div className="flex flex-col pb-4">
{reasoningMessages?.map((message, index) => (
2025-02-09 05:37:46 +08:00
<div key={message.id} className={getContainerClass(message)}>
2025-02-08 13:24:18 +08:00
<ReasoningMessageSelector
key={message.id}
reasoningMessage={message}
isCompletedStream={isCompletedStream}
isLastMessageItem={index === lastMessageIndex}
2025-02-11 06:21:59 +08:00
chatId={chatId}
2025-02-08 13:24:18 +08:00
/>
</div>
))}
</div>
);
});
ReasoningMessageContainer.displayName = 'ReasoningMessageContainer';
const VerticalDivider: React.FC<{ className?: string }> = React.memo(({ className }) => {
const { cx, styles } = useStyles();
return <div className={cx(styles.verticalDivider, 'vertical-divider', className)} />;
});
VerticalDivider.displayName = 'VerticalDivider';
const useStyles = createStyles(({ token, css }) => ({
textCard: css`
margin-bottom: 14px;
&:has(+ .text-card) {
margin-bottom: 8px;
}
.vertical-divider {
display: none;
}
`,
2025-03-01 02:30:39 +08:00
pillsCard: css`
2025-02-08 13:24:18 +08:00
.vertical-divider {
display: none;
}
margin-bottom: 4px;
2025-02-12 01:22:46 +08:00
&:has(+ .file-card) {
margin-bottom: 3px;
}
2025-02-12 07:46:22 +08:00
2025-03-01 02:19:27 +08:00
&:has(+ .pills-card) {
2025-02-12 07:46:22 +08:00
.vertical-divider {
display: none;
}
}
2025-02-08 13:24:18 +08:00
`,
2025-02-11 02:55:18 +08:00
fileCard: css`
margin-bottom: 4px;
2025-02-11 03:24:35 +08:00
.vertical-divider {
display: none;
}
2025-02-11 06:21:59 +08:00
&:has(+ .file-card) {
2025-02-12 01:22:46 +08:00
margin-bottom: 6px;
2025-02-11 06:21:59 +08:00
.vertical-divider {
2025-02-12 01:22:46 +08:00
display: none;
2025-02-11 06:21:59 +08:00
}
}
2025-03-01 02:19:27 +08:00
&:has(+ .pills-card) {
2025-02-12 01:22:46 +08:00
margin-bottom: 6px;
2025-02-11 06:21:59 +08:00
}
2025-02-11 02:55:18 +08:00
`,
2025-02-08 13:24:18 +08:00
verticalDivider: css`
transition: opacity 0.2s ease-in-out;
height: 9px;
width: 0.5px;
margin: 3px 0 3px 16px;
background: ${token.colorTextTertiary};
`
}));