mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-14 09:21:22 +00:00
refac
This commit is contained in:
parent
e6beee3561
commit
1ef75436f6
4 changed files with 35 additions and 22 deletions
|
|
@ -538,7 +538,7 @@
|
|||
<Message
|
||||
{chatId}
|
||||
bind:history
|
||||
{selectedModels}
|
||||
selectedModels={atSelectedModel ? [atSelectedModel.id] : selectedModels}
|
||||
messageId={message.id}
|
||||
idx={messageIdx}
|
||||
{user}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@
|
|||
{#if history.messages[messageId]}
|
||||
{#if history.messages[messageId].role === 'user'}
|
||||
<UserMessage
|
||||
{selectedModels}
|
||||
{user}
|
||||
{chatId}
|
||||
{history}
|
||||
|
|
|
|||
|
|
@ -139,6 +139,8 @@
|
|||
|
||||
let messageSource = history.messages[messageId];
|
||||
let message: MessageType = structuredClone(messageSource);
|
||||
$: canBranch =
|
||||
!message.model?.startsWith('agent:') && !selectedModels.some((id) => id.startsWith('agent:'));
|
||||
$: if (history.messages) {
|
||||
const source = history.messages[messageId];
|
||||
if (source) {
|
||||
|
|
@ -461,6 +463,7 @@
|
|||
};
|
||||
|
||||
const saveAsCopyHandler = async () => {
|
||||
if (!canBranch) return;
|
||||
if (editedOutput) {
|
||||
editMessage(message.id, { output: editedOutput });
|
||||
} else {
|
||||
|
|
@ -832,15 +835,17 @@
|
|||
|
||||
<div class=" mt-2 flex justify-between text-sm font-normal">
|
||||
<div>
|
||||
<button
|
||||
id="save-new-message-button"
|
||||
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-gray-100 px-2.5 text-xs font-normal text-gray-800 transition hover:bg-gray-100/70 disabled:opacity-60 dark:bg-gray-850 dark:text-white dark:hover:bg-gray-850/60"
|
||||
on:click={() => {
|
||||
saveAsCopyHandler();
|
||||
}}
|
||||
>
|
||||
{$i18n.t('Save As Copy')}
|
||||
</button>
|
||||
{#if canBranch}
|
||||
<button
|
||||
id="save-new-message-button"
|
||||
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-gray-100 px-2.5 text-xs font-normal text-gray-800 transition hover:bg-gray-100/70 disabled:opacity-60 dark:bg-gray-850 dark:text-white dark:hover:bg-gray-850/60"
|
||||
on:click={() => {
|
||||
saveAsCopyHandler();
|
||||
}}
|
||||
>
|
||||
{$i18n.t('Save As Copy')}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<div class="flex space-x-1.5">
|
||||
|
|
@ -1420,7 +1425,7 @@
|
|||
</Tooltip>
|
||||
{/if}
|
||||
|
||||
{#if isLastMessage && ($user?.role === 'admin' || ($user?.permissions?.chat?.continue_response ?? true))}
|
||||
{#if canBranch && isLastMessage && ($user?.role === 'admin' || ($user?.permissions?.chat?.continue_response ?? true))}
|
||||
<Tooltip content={$i18n.t('Continue Response')} placement="bottom">
|
||||
<button
|
||||
aria-label={$i18n.t('Continue Response')}
|
||||
|
|
@ -1454,7 +1459,7 @@
|
|||
{/if}
|
||||
|
||||
{#if (!readOnly && (!message.user_id || message.user_id === $user?.id)) || shareMode === 'continue'}
|
||||
{#if $user?.role === 'admin' || ($user?.permissions?.chat?.regenerate_response ?? true)}
|
||||
{#if canBranch && ($user?.role === 'admin' || ($user?.permissions?.chat?.regenerate_response ?? true))}
|
||||
{#if $settings?.regenerateMenu ?? true}
|
||||
<button
|
||||
type="button"
|
||||
|
|
@ -1711,7 +1716,7 @@
|
|||
{/key}
|
||||
{/if}
|
||||
|
||||
{#if (isLastMessage || ($settings?.keepFollowUpPrompts ?? false)) && message.done && !readOnly && (message?.followUps ?? []).length > 0}
|
||||
{#if (isLastMessage || (canBranch && ($settings?.keepFollowUpPrompts ?? false))) && message.done && !readOnly && (message?.followUps ?? []).length > 0}
|
||||
<div class="my-2.5" in:fade={{ duration: 100 }}>
|
||||
<FollowUps
|
||||
followUps={message?.followUps}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
export let chatId;
|
||||
export let history;
|
||||
export let messageId;
|
||||
export let selectedModels: string[] = [];
|
||||
|
||||
export let siblings;
|
||||
|
||||
|
|
@ -69,6 +70,9 @@
|
|||
let editScrollContainer: HTMLDivElement;
|
||||
|
||||
let message = structuredClone(history.messages[messageId]);
|
||||
$: canBranch = ![...selectedModels, ...(message.models ?? [])].some((id) =>
|
||||
id.startsWith('agent:')
|
||||
);
|
||||
$: authorId = message.user_id || message.user?.id || user?.id;
|
||||
$: author =
|
||||
message.user?.id === authorId
|
||||
|
|
@ -118,6 +122,7 @@
|
|||
};
|
||||
|
||||
const editMessageConfirmHandler = async (submit = true) => {
|
||||
if (submit && !canBranch) return;
|
||||
if (!editedContent && (editedFiles ?? []).length === 0) {
|
||||
toast.error($i18n.t('Please enter a message or attach a file.'));
|
||||
return;
|
||||
|
|
@ -377,15 +382,17 @@
|
|||
{$i18n.t('Cancel')}
|
||||
</button>
|
||||
|
||||
<button
|
||||
id="confirm-edit-message-button"
|
||||
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-gray-900 px-2.5 text-xs font-normal text-white transition hover:bg-black disabled:opacity-60 dark:bg-gray-100 dark:text-gray-900 dark:hover:bg-white"
|
||||
on:click={() => {
|
||||
editMessageConfirmHandler();
|
||||
}}
|
||||
>
|
||||
{$i18n.t('Send')}
|
||||
</button>
|
||||
{#if canBranch}
|
||||
<button
|
||||
id="confirm-edit-message-button"
|
||||
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-gray-900 px-2.5 text-xs font-normal text-white transition hover:bg-black disabled:opacity-60 dark:bg-gray-100 dark:text-gray-900 dark:hover:bg-white"
|
||||
on:click={() => {
|
||||
editMessageConfirmHandler();
|
||||
}}
|
||||
>
|
||||
{$i18n.t('Send')}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue