Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/components/Bot.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/components/bubbles/BotBubble.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Props = {
renderHTML?: boolean;
handleActionClick: (elem: any, action: IAction | undefined | null) => void;
handleSourceDocumentsClick: (src: any) => void;
onRegenerateResponse?: () => void;
isTTSEnabled?: boolean;
isTTSLoading?: Record<string, boolean>;
isTTSPlaying?: Record<string, boolean>;
Expand Down
2 changes: 1 addition & 1 deletion dist/components/bubbles/BotBubble.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions dist/components/buttons/RegenerateResponseButton.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { JSX } from 'solid-js';
type RegenerateResponseButtonProps = {
feedbackColor?: string;
isDisabled?: boolean;
isLoading?: boolean;
disableIcon?: boolean;
} & JSX.ButtonHTMLAttributes<HTMLButtonElement>;
export declare const RegenerateResponseButton: (props: RegenerateResponseButtonProps) => JSX.Element;
export {};
//# sourceMappingURL=RegenerateResponseButton.d.ts.map
1 change: 1 addition & 0 deletions dist/components/buttons/RegenerateResponseButton.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/web.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/web.umd.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/assets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ textarea {
stroke: var(--chatbot-button-color);
}

.regenerate-response-button > .icon-tabler-refresh {
width: 16px;
height: 16px;
}

.chatbot-chat-view {
max-width: 800px;
}
Expand Down
42 changes: 36 additions & 6 deletions src/components/Bot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,28 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
handleSubmit(prompt);
};

const handleRegenerateResponse = async (messageIndex: number) => {
if (loading()) return;
if (previews().length) return;
if (startInputType() === 'formInput') return;

const currentMessages = messages();
const targetMessage = currentMessages[messageIndex];
if (!targetMessage || targetMessage.type !== 'apiMessage') return;

const previousMessage = currentMessages[messageIndex - 1];
if (!previousMessage || previousMessage.type !== 'userMessage' || previousMessage.fileUploads?.length) return;

setFollowUpPrompts([]);
const updatedMessages = currentMessages.slice(0, messageIndex);
addChatMessage(updatedMessages);
setMessages(updatedMessages);

// Note: chatId is kept so the server retains conversation context up to this point.
// The server's history will still include messages that were removed client-side
await handleSubmit(previousMessage.message, undefined, undefined, { skipAddUserMessage: true });
};

const updateMetadata = (data: any, input: string) => {
if (data.chatId) {
setChatId(data.chatId);
Expand Down Expand Up @@ -1166,7 +1188,12 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
};

// Handle form submission
const handleSubmit = async (value: string | object, action?: IAction | undefined | null, humanInput?: any) => {
const handleSubmit = async (
value: string | object,
action?: IAction | undefined | null,
humanInput?: any,
options?: { skipAddUserMessage?: boolean },
) => {
if (typeof value === 'string' && value.trim() === '') {
const containsFile = previews().filter((item) => !item.mime.startsWith('image') && item.type !== 'audio').length > 0;
if (!previews().length || (previews().length && containsFile)) {
Expand Down Expand Up @@ -1203,11 +1230,13 @@ export const Bot = (botProps: BotProps & { class?: string }) => {

clearPreviews();

setMessages((prevMessages) => {
const messages: MessageType[] = [...prevMessages, { message: value as string, type: 'userMessage', fileUploads: uploads }];
addChatMessage(messages);
return messages;
});
if (!options?.skipAddUserMessage) {
setMessages((prevMessages) => {
const messages: MessageType[] = [...prevMessages, { message: value as string, type: 'userMessage', fileUploads: uploads }];
addChatMessage(messages);
return messages;
});
}

const body: IncomingInput = {
question: value,
Expand Down Expand Up @@ -2603,6 +2632,7 @@ export const Bot = (botProps: BotProps & { class?: string }) => {
showAvatar={props.botMessage?.showAvatar}
avatarSrc={props.botMessage?.avatarSrc}
chatFeedbackStatus={chatFeedbackStatus()}
onRegenerateResponse={() => handleRegenerateResponse(index())}
fontSize={props.fontSize}
isLoading={loading() && index() === messages().length - 1}
showAgentMessages={props.showAgentMessages}
Expand Down
3 changes: 3 additions & 0 deletions src/components/bubbles/BotBubble.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import DOMPurify from 'dompurify';
import { FeedbackRatingType, sendFeedbackQuery, sendFileDownloadQuery, updateFeedbackQuery } from '@/queries/sendMessageQuery';
import { FileUpload, IAction, MessageType } from '../Bot';
import { CopyToClipboardButton, ThumbsDownButton, ThumbsUpButton } from '../buttons/FeedbackButtons';
import { RegenerateResponseButton } from '../buttons/RegenerateResponseButton';
import { TTSButton } from '../buttons/TTSButton';
import FeedbackContentDialog from '../FeedbackContentDialog';
import { AgentReasoningBubble } from './AgentReasoningBubble';
Expand Down Expand Up @@ -35,6 +36,7 @@ type Props = {
renderHTML?: boolean;
handleActionClick: (elem: any, action: IAction | undefined | null) => void;
handleSourceDocumentsClick: (src: any) => void;
onRegenerateResponse?: () => void;
// TTS props
isTTSEnabled?: boolean;
isTTSLoading?: Record<string, boolean>;
Expand Down Expand Up @@ -581,6 +583,7 @@ export const BotBubble = (props: Props) => {
</Show>
{props.chatFeedbackStatus && props.message.messageId && (
<>
<RegenerateResponseButton class="regenerate-response-button" feedbackColor={props.feedbackColor} onClick={() => props.onRegenerateResponse?.()} />
<CopyToClipboardButton feedbackColor={props.feedbackColor} onClick={() => copyMessageToClipboard()} />
<Show when={copiedMessage()}>
<div class="copied-message" style={{ color: props.feedbackColor ?? defaultFeedbackColor }}>
Expand Down
32 changes: 32 additions & 0 deletions src/components/buttons/RegenerateResponseButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { JSX, Show } from 'solid-js';
import { Spinner } from './SendButton';
import { DeleteIcon as RefreshIcon } from '../icons';

type RegenerateResponseButtonProps = {
feedbackColor?: string;
isDisabled?: boolean;
isLoading?: boolean;
disableIcon?: boolean;
} & JSX.ButtonHTMLAttributes<HTMLButtonElement>;

const defaultFeedbackColor = '#3B81F6';

export const RegenerateResponseButton = (props: RegenerateResponseButtonProps) => {
return (
<button
type="button"
disabled={props.isDisabled || props.isLoading}
{...props}
class={
'p-2 justify-center font-semibold text-white focus:outline-none flex items-center disabled:opacity-50 disabled:cursor-not-allowed disabled:brightness-100 transition-all filter hover:brightness-90 active:brightness-75 chatbot-button ' +
props.class
}
style={{ background: 'transparent', border: 'none' }}
title="Regenerate response"
>
<Show when={!props.isLoading} fallback={<Spinner class="text-white" />}>
<RefreshIcon color={props.feedbackColor ?? defaultFeedbackColor} class={'send-icon flex ' + (props.disableIcon ? 'hidden' : '')} />
</Show>
</button>
);
};