Refactor AIChat components to streamline error handling
- Removed isRetrying prop from AIChatErrorMessage and related components to simplify error management. - Updated AIChatErrorMessage to disable the retry button based on the streaming status instead of isRetrying. - Enhanced AIChatErrorMessageWithRecordsContext to directly pass error without isRetrying prop, improving clarity in error handling.
This commit is contained in:
@@ -45,19 +45,17 @@ const StyledErrorMessage = styled.div`
|
||||
|
||||
type AIChatErrorMessageProps = {
|
||||
error: Error;
|
||||
isRetrying?: boolean;
|
||||
records?: ObjectRecord[];
|
||||
};
|
||||
|
||||
export const AIChatErrorMessage = ({
|
||||
error,
|
||||
isRetrying = false,
|
||||
records,
|
||||
}: AIChatErrorMessageProps) => {
|
||||
const theme = useTheme();
|
||||
const { chat } = useAgentChatContextOrThrow();
|
||||
const { buildRequestBody } = useAgentChatRequestBody();
|
||||
const { regenerate } = useChat({ chat });
|
||||
const { regenerate, status } = useChat({ chat });
|
||||
|
||||
const handleRetry = () => {
|
||||
regenerate({
|
||||
@@ -81,7 +79,7 @@ export const AIChatErrorMessage = ({
|
||||
size="small"
|
||||
Icon={IconRefresh}
|
||||
onClick={handleRetry}
|
||||
disabled={isRetrying}
|
||||
disabled={status === 'streaming'}
|
||||
title={t`Retry`}
|
||||
/>
|
||||
</StyledErrorContainer>
|
||||
|
||||
@@ -145,12 +145,10 @@ export const AIChatMessage = ({
|
||||
message,
|
||||
isLastMessageStreaming,
|
||||
error,
|
||||
isRetrying,
|
||||
}: {
|
||||
message: UIMessageWithMetadata;
|
||||
isLastMessageStreaming: boolean;
|
||||
error?: Error | null;
|
||||
isRetrying?: boolean;
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
const { localeCatalog } = useRecoilValue(dateLocaleState);
|
||||
@@ -204,12 +202,9 @@ export const AIChatMessage = ({
|
||||
)}
|
||||
{showError &&
|
||||
(contextStoreCurrentObjectMetadataItemId ? (
|
||||
<AIChatErrorMessageWithRecordsContext
|
||||
error={error}
|
||||
isRetrying={isRetrying}
|
||||
/>
|
||||
<AIChatErrorMessageWithRecordsContext error={error} />
|
||||
) : (
|
||||
<AIChatErrorMessage error={error} isRetrying={isRetrying} />
|
||||
<AIChatErrorMessage error={error} />
|
||||
))}
|
||||
{message.parts.length > 0 && message.metadata?.createdAt && (
|
||||
<StyledMessageFooter className="message-footer">
|
||||
|
||||
@@ -106,7 +106,6 @@ export const AIChatTab = ({ agentId }: { agentId: string }) => {
|
||||
message={message}
|
||||
key={message.id}
|
||||
error={shouldShowError ? error : null}
|
||||
isRetrying={isStreaming}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
|
||||
+1
-9
@@ -3,20 +3,12 @@ import { useFindManyRecordsSelectedInContextStore } from '@/context-store/hooks/
|
||||
|
||||
export const AIChatErrorMessageWithRecordsContext = ({
|
||||
error,
|
||||
isRetrying,
|
||||
}: {
|
||||
error: Error;
|
||||
isRetrying?: boolean;
|
||||
}) => {
|
||||
const { records } = useFindManyRecordsSelectedInContextStore({
|
||||
limit: 10,
|
||||
});
|
||||
|
||||
return (
|
||||
<AIChatErrorMessage
|
||||
error={error}
|
||||
isRetrying={isRetrying}
|
||||
records={records}
|
||||
/>
|
||||
);
|
||||
return <AIChatErrorMessage error={error} records={records} />;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user