mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-22 21:50:42 -05:00
refac
This commit is contained in:
1 parent
c1faae570b
commit
d7b3d08b4f
14 files changed
+392
-358
No files matched your search
@@ -21,6 +21,9 @@ class PanelTab(ViewModel):
|
||||
terminalId: str | None = None
|
||||
terminalNumber: int | None = None
|
||||
chatId: str | None = None
|
||||
chatNumber: int | None = None
|
||||
parentChatId: str | None = None
|
||||
# Accept layouts from older clients; current clients normalize these on read.
|
||||
sideChatNumber: int | None = None
|
||||
sideChat: bool | None = None
|
||||
path: str | None = None
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
chatId as _chatId,
|
||||
config,
|
||||
type Model,
|
||||
models,
|
||||
models as _models,
|
||||
tags as allTags,
|
||||
settings,
|
||||
showSidebar,
|
||||
@@ -40,14 +40,14 @@
|
||||
audioQueue as _audioQueue,
|
||||
showTabs as _showTabs,
|
||||
sideChatRequest,
|
||||
openSideChatIds,
|
||||
openEmbeddedChatIds,
|
||||
showCallOverlay as _showCallOverlay,
|
||||
temporaryChatEnabled as _temporaryChatEnabled,
|
||||
mobile,
|
||||
chatTitle as _chatTitle,
|
||||
tools,
|
||||
skills,
|
||||
terminalSkills,
|
||||
terminalSkills as _terminalSkills,
|
||||
terminalServers,
|
||||
functions,
|
||||
selectedFolder as _selectedFolder,
|
||||
@@ -148,6 +148,7 @@
|
||||
import MessageInput from '$lib/components/chat/MessageInput.svelte';
|
||||
import Messages from '$lib/components/chat/Messages.svelte';
|
||||
import Navbar from '$lib/components/chat/Navbar.svelte';
|
||||
import Sparkles from '$lib/components/layout/Sidebar/icons/Sparkles.svelte';
|
||||
import Tabs from './Tabs.svelte';
|
||||
import EventConfirmDialog from '../common/ConfirmDialog.svelte';
|
||||
import ElicitationDialog from './ElicitationDialog.svelte';
|
||||
@@ -171,7 +172,7 @@
|
||||
let mainChatHref = '/';
|
||||
$: if ($chatId) mainChatHref = `/c/${$chatId}`;
|
||||
export let embedded = false;
|
||||
export let side = false;
|
||||
export let tabbed = false;
|
||||
const chatId = embedded ? writable('') : _chatId;
|
||||
const chatTitle = embedded ? writable('') : _chatTitle;
|
||||
const audioQueue = embedded ? writable<AudioQueue | null>(null) : _audioQueue;
|
||||
@@ -180,10 +181,10 @@
|
||||
const showTabs = embedded ? writable(get(_showTabs)) : _showTabs;
|
||||
const showCallOverlay = embedded ? writable(false) : _showCallOverlay;
|
||||
const showEmbeds = embedded ? writable(false) : _showEmbeds;
|
||||
// A side chat uses the main chat's terminal and never changes it.
|
||||
const selectedTerminalId = side
|
||||
? { subscribe: _selectedTerminalId.subscribe, set: () => {} }
|
||||
: _selectedTerminalId;
|
||||
const selectedTerminalId = tabbed ? writable(get(_selectedTerminalId)) : _selectedTerminalId;
|
||||
const terminalSkills = tabbed ? writable<any[]>([]) : _terminalSkills;
|
||||
const models = tabbed ? writable(get(_models)) : _models;
|
||||
setContext('chatModels', models);
|
||||
export let embeddedTitle = '';
|
||||
export let embeddedChats = [];
|
||||
export let embeddedDraftKey = '';
|
||||
@@ -198,6 +199,8 @@
|
||||
} | null = null;
|
||||
export let initialPrompt = '';
|
||||
export let parentChatId = '';
|
||||
export let draftTitle = '';
|
||||
export let draftFolderId: string | null = null;
|
||||
export let suggestedPrompts = [];
|
||||
export let selectedText = '';
|
||||
export let notePageId = '';
|
||||
@@ -229,8 +232,8 @@
|
||||
let audioElement: HTMLAudioElement;
|
||||
$: chatContainerId = embedded ? `note-chat-container-${instanceId}` : 'chat-container';
|
||||
$: messageInputDropzoneId = embedded ? `note-chat-input-dropzone-${instanceId}` : 'chat-pane';
|
||||
$: dropzoneId = side ? chatContainerId : messageInputDropzoneId;
|
||||
const onTemporaryChange = side
|
||||
$: dropzoneId = tabbed ? chatContainerId : messageInputDropzoneId;
|
||||
const onTemporaryChange = tabbed
|
||||
? (value: boolean) => {
|
||||
if (!processing) temporaryChatEnabled.set(value);
|
||||
}
|
||||
@@ -247,8 +250,6 @@
|
||||
let processing = '';
|
||||
let messagesContainerElement: HTMLDivElement;
|
||||
|
||||
let navbarElement: { startRename?: () => void } | undefined;
|
||||
|
||||
let showEventConfirmation = false;
|
||||
let pendingUrlActions: { urls: string[]; call: boolean } | null = null;
|
||||
let eventConfirmationTitle = '';
|
||||
@@ -562,7 +563,7 @@
|
||||
messages: {},
|
||||
currentId: null
|
||||
};
|
||||
// A side chat hides its parent's context up to here.
|
||||
// Context inherited at creation is hidden up to this message.
|
||||
let branchPointMessageId: string | null = null;
|
||||
$: contextOnly = !!branchPointMessageId && history.currentId === branchPointMessageId;
|
||||
$: inputHistory = contextOnly ? { messages: {}, currentId: null } : history;
|
||||
@@ -592,7 +593,7 @@
|
||||
|
||||
// Chat Input
|
||||
export let prompt = '';
|
||||
let chatFiles = [];
|
||||
let chatFiles: any[] = [];
|
||||
export let files: any[] = [];
|
||||
let terminalContext: TerminalContext | null = null;
|
||||
const askFile = async (instruction: string, file: FilesystemFile) => {
|
||||
@@ -1108,7 +1109,7 @@
|
||||
const saveSessionSelectedModels = () => {
|
||||
const selectedModelsString = JSON.stringify(selectedModels);
|
||||
if (
|
||||
side ||
|
||||
tabbed ||
|
||||
selectedModels.length === 0 ||
|
||||
(selectedModels.length === 1 && selectedModels[0] === '') ||
|
||||
sessionStorage.selectedModels === selectedModelsString
|
||||
@@ -1120,7 +1121,7 @@
|
||||
};
|
||||
|
||||
const continueOAuthRedirect = async () => {
|
||||
if (side) {
|
||||
if (tabbed) {
|
||||
pendingOAuthTools = [];
|
||||
return;
|
||||
}
|
||||
@@ -1202,7 +1203,6 @@
|
||||
folder: FolderDetails | null = null,
|
||||
signal = chatLoadController.signal
|
||||
) => {
|
||||
if (side) return;
|
||||
const terminalId = $selectedTerminalId;
|
||||
const environment = folder ? null : getAgentEnvironment();
|
||||
loadedAgentEnvironment = null;
|
||||
@@ -1264,7 +1264,7 @@
|
||||
$: if ($selectedTerminalId !== lastTerminalSkillSelector) {
|
||||
if (terminalContext?.terminalId !== $selectedTerminalId) terminalContext = null;
|
||||
selectedSkillIds = selectedSkillIds.filter((id) => !id.startsWith('terminal:'));
|
||||
if (!side) terminalSkills.set([]);
|
||||
terminalSkills.set([]);
|
||||
lastTerminalSkillSelector = $selectedTerminalId;
|
||||
// Folder initialization already requests this exact environment.
|
||||
if (
|
||||
@@ -1671,15 +1671,15 @@
|
||||
});
|
||||
};
|
||||
$: syncChatRoom($socket, $chatId, $temporaryChatEnabled);
|
||||
let openSideChatId: string = '';
|
||||
$: if (embedded && $chatId !== openSideChatId) {
|
||||
openSideChatIds.update((ids) => {
|
||||
let openEmbeddedChatId: string = '';
|
||||
$: if (embedded && $chatId !== openEmbeddedChatId) {
|
||||
openEmbeddedChatIds.update((ids) => {
|
||||
const next = new Set(ids);
|
||||
next.delete(openSideChatId);
|
||||
next.delete(openEmbeddedChatId);
|
||||
if ($chatId) next.add($chatId);
|
||||
return next;
|
||||
});
|
||||
openSideChatId = $chatId;
|
||||
openEmbeddedChatId = $chatId;
|
||||
}
|
||||
|
||||
const chatEventHandler = async (event, cb) => {
|
||||
@@ -1707,7 +1707,7 @@
|
||||
}
|
||||
if (event.shared && event.user_id === $user?.id && event.data?.type !== 'chat:messages') return;
|
||||
// The first event can identify a new chat before the HTTP response arrives.
|
||||
if (!side && !$chatId && event.chat_id && history.messages[event.message_id]) {
|
||||
if (!tabbed && !$chatId && event.chat_id && history.messages[event.message_id]) {
|
||||
chatId.set(event.chat_id);
|
||||
}
|
||||
const interactionType = event?.data?.type;
|
||||
@@ -1729,7 +1729,7 @@
|
||||
) {
|
||||
if (!cb) return;
|
||||
if (event.chat_id !== $chatId) {
|
||||
if (!embedded && !$openSideChatIds.has(event.chat_id))
|
||||
if (!embedded && !$openEmbeddedChatIds.has(event.chat_id))
|
||||
cb({ status: 'cancelled', answers: {} });
|
||||
return;
|
||||
}
|
||||
@@ -2157,7 +2157,7 @@
|
||||
loading = true;
|
||||
console.log('mounted');
|
||||
if (!embedded && appLayout) appLayout.initNewChat = initNewChat;
|
||||
if (!side) window.addEventListener('message', onMessageHandler);
|
||||
if (!tabbed) window.addEventListener('message', onMessageHandler);
|
||||
$socket?.on('events', chatEventHandler);
|
||||
$socket?.on('connect', handleSocketConnect);
|
||||
$socket?.on('disconnect', clearTyping);
|
||||
@@ -2256,7 +2256,7 @@
|
||||
if (embedded && $chatId) {
|
||||
if ($temporaryChatEnabled)
|
||||
stopTasksByChatId(localStorage.token, $chatId).catch(console.error);
|
||||
openSideChatIds.update((ids) => {
|
||||
openEmbeddedChatIds.update((ids) => {
|
||||
const next = new Set(ids);
|
||||
next.delete($chatId);
|
||||
return next;
|
||||
@@ -3212,7 +3212,7 @@
|
||||
|
||||
const id = $chatId;
|
||||
const loadedChat = await getChatById(localStorage.token, id, signal).catch(async (error) => {
|
||||
if (side && !signal.aborted) toast.error(`${error}`);
|
||||
if (tabbed && !signal.aborted) toast.error(`${error}`);
|
||||
console.error('[note-chat] getChatById failed', {
|
||||
chatIdProp,
|
||||
activeChatId: $chatId,
|
||||
@@ -3324,7 +3324,7 @@
|
||||
chatContent.originalChatId === parentChatId
|
||||
? (chatContent.branchPointMessageId ?? null)
|
||||
: null;
|
||||
if (side) await onEmbeddedChatTitle?.(id, chatContent.title);
|
||||
if (tabbed) await onEmbeddedChatTitle?.(id, chatContent.title);
|
||||
|
||||
params = structuredClone(chatContent?.params ?? {});
|
||||
delete params.note_id;
|
||||
@@ -4194,7 +4194,7 @@
|
||||
if (!embedded) {
|
||||
await goto(`/c/${result.id}`);
|
||||
await refreshChatList(localStorage.token, { refreshPinned: true });
|
||||
} else if (side) {
|
||||
} else if (tabbed) {
|
||||
await onSelectEmbeddedChat?.(result.id);
|
||||
await refreshChatList(localStorage.token, { refreshPinned: true });
|
||||
}
|
||||
@@ -4219,7 +4219,84 @@
|
||||
let mainChatActive = false;
|
||||
let mainChatStyle = '';
|
||||
let mainChatGroupId = '';
|
||||
let tabTitleEditor: import('svelte').Snippet | undefined;
|
||||
export let tabTitleEditor: import('svelte').Snippet | undefined = undefined;
|
||||
let editingTitle = false;
|
||||
let titleDraft = '';
|
||||
let titleInput: HTMLInputElement;
|
||||
let generatingTitle = false;
|
||||
let titleEditChatId = '';
|
||||
$: if (loading || isShared || $temporaryChatEnabled || $chatId !== titleEditChatId)
|
||||
editingTitle = false;
|
||||
$: tabTitleEditor = editingTitle ? renderTitleEditor : undefined;
|
||||
|
||||
export const startRename = async () => {
|
||||
if (
|
||||
loading ||
|
||||
isShared ||
|
||||
!$chatId ||
|
||||
$temporaryChatEnabled ||
|
||||
isTemporaryChatId($chatId) ||
|
||||
generatingTitle
|
||||
)
|
||||
return;
|
||||
titleEditChatId = $chatId;
|
||||
titleDraft = $chatTitle;
|
||||
editingTitle = true;
|
||||
await tick();
|
||||
setTimeout(() => {
|
||||
titleInput?.focus();
|
||||
titleInput?.select();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
const editChatTitle = async () => {
|
||||
// Generating a title disables and blurs the field; wait for the generated value.
|
||||
if (!editingTitle || generatingTitle) return;
|
||||
editingTitle = false;
|
||||
const title = titleDraft.trim();
|
||||
if (title === $chatTitle) return;
|
||||
if (!title) {
|
||||
toast.error($i18n.t('Title cannot be an empty string.'));
|
||||
return;
|
||||
}
|
||||
const id = $chatId;
|
||||
try {
|
||||
const updated = await updateChatById(localStorage.token, id, { title });
|
||||
if (!updated) return;
|
||||
updateFolderChatLists({ id, title });
|
||||
if ($chatId === id) {
|
||||
chatTitle.set(title);
|
||||
if (embedded) await onEmbeddedChatTitle?.(id, title);
|
||||
}
|
||||
await refreshChatList(localStorage.token, { refreshPinned: true });
|
||||
await refreshFolderChatLists();
|
||||
} catch (error) {
|
||||
toast.error(`${error}`);
|
||||
}
|
||||
};
|
||||
|
||||
const generateChatTitle = async () => {
|
||||
const id = $chatId;
|
||||
generatingTitle = true;
|
||||
titleDraft = '';
|
||||
const messages = createMessagesList(history, history.currentId).map((message) => ({
|
||||
role: message.role,
|
||||
content: getOutputText(message.output) || message.content || ''
|
||||
}));
|
||||
const generatedTitle = await generateTitle(
|
||||
localStorage.token,
|
||||
selectedModels.find((modelId: string) => modelId) ?? '',
|
||||
messages
|
||||
).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
});
|
||||
generatingTitle = false;
|
||||
if ($chatId !== id || !editingTitle) return;
|
||||
titleDraft = generatedTitle || $chatTitle;
|
||||
await editChatTitle();
|
||||
};
|
||||
|
||||
let tabActions: import('svelte').Snippet | undefined;
|
||||
let folderTabActions: import('svelte').Snippet | undefined;
|
||||
|
||||
@@ -4299,7 +4376,7 @@
|
||||
_chatId = createTemporaryChatId($socket?.id);
|
||||
await chatId.set(_chatId);
|
||||
}
|
||||
if (!_chatId && (context?.currentDirectory || terminalTabs?.hasTerminals())) {
|
||||
if (!_chatId && (tabbed || context?.currentDirectory || terminalTabs?.hasTerminals())) {
|
||||
_chatId = await initChatHandler(_history);
|
||||
}
|
||||
await tick();
|
||||
@@ -5260,7 +5337,7 @@
|
||||
|
||||
const initChatHandler = async (_history: typeof history) => {
|
||||
let _chatId = $chatId;
|
||||
const selectedFolderId = $selectedFolder?.id;
|
||||
const selectedFolderId = $selectedFolder?.id ?? draftFolderId;
|
||||
const context = terminalContext;
|
||||
|
||||
if (!$temporaryChatEnabled) {
|
||||
@@ -5268,7 +5345,8 @@
|
||||
localStorage.token,
|
||||
{
|
||||
id: _chatId,
|
||||
title: $i18n.t('New Chat'),
|
||||
title: draftTitle || $i18n.t('New Chat'),
|
||||
...(parentChatId && { originalChatId: parentChatId, branchPointMessageId }),
|
||||
models: selectedModels,
|
||||
terminal_id: $selectedTerminalId,
|
||||
working_directory:
|
||||
@@ -5276,11 +5354,12 @@
|
||||
system: $settings.system ?? undefined,
|
||||
params: params,
|
||||
history: _history,
|
||||
files: chatFiles,
|
||||
messages: createMessagesList(_history, _history.currentId),
|
||||
tags: [],
|
||||
timestamp: Date.now()
|
||||
},
|
||||
$selectedFolder?.id,
|
||||
selectedFolderId,
|
||||
chatVariables
|
||||
);
|
||||
|
||||
@@ -5290,6 +5369,11 @@
|
||||
if (selectedFolderId) updateFolderChatLists(createdChat, selectedFolderId);
|
||||
_chatId = chat.id;
|
||||
await chatId.set(_chatId);
|
||||
if (tabbed) {
|
||||
loadedChatIdProp = _chatId;
|
||||
chatTitle.set(createdChat.chat?.title ?? createdChat.title);
|
||||
await onSelectEmbeddedChat?.(_chatId);
|
||||
}
|
||||
|
||||
if (!embedded) {
|
||||
saveDraft(getChatInputDraft(), _chatId, false);
|
||||
@@ -5298,9 +5382,7 @@
|
||||
|
||||
await tick();
|
||||
|
||||
if (!embedded) {
|
||||
await refreshChatList(localStorage.token);
|
||||
}
|
||||
await refreshChatList(localStorage.token);
|
||||
|
||||
if (selectedFolderId) {
|
||||
await refreshFolderChatLists(selectedFolderId, chat);
|
||||
@@ -5408,7 +5490,7 @@
|
||||
},
|
||||
draft = getChatInputDraft()
|
||||
) => {
|
||||
if (side) return;
|
||||
if (tabbed) return;
|
||||
await tick();
|
||||
saveSessionSelectedModels();
|
||||
await saveDraft(draft, null, false);
|
||||
@@ -5499,6 +5581,46 @@
|
||||
};
|
||||
</script>
|
||||
|
||||
{#snippet renderTitleEditor()}
|
||||
<input
|
||||
bind:this={titleInput}
|
||||
bind:value={titleDraft}
|
||||
class="min-w-0 flex-1 bg-transparent {tabbed || fullWidthTabs
|
||||
? 'text-sm'
|
||||
: 'md:py-1 text-[0.9375rem]'} font-normal text-gray-700 outline-hidden dark:text-gray-300"
|
||||
aria-label={$i18n.t('Title')}
|
||||
placeholder={generatingTitle ? $i18n.t('Generating...') : ''}
|
||||
disabled={generatingTitle}
|
||||
on:click|stopPropagation
|
||||
on:keydown={(e) => {
|
||||
if (e.isComposing || e.keyCode === 229) return;
|
||||
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
editChatTitle();
|
||||
} else if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
editingTitle = false;
|
||||
}
|
||||
}}
|
||||
on:blur={editChatTitle}
|
||||
/>
|
||||
|
||||
<Tooltip content={$i18n.t('Generate')}>
|
||||
<button
|
||||
class="flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-lg text-gray-500 transition hover:bg-gray-50/40 hover:text-gray-700 disabled:cursor-not-allowed dark:text-gray-400 dark:hover:bg-gray-800/40 dark:hover:text-gray-200"
|
||||
aria-label={$i18n.t('Generate')}
|
||||
disabled={generatingTitle}
|
||||
on:mousedown={(e) => e.preventDefault()}
|
||||
on:click|stopPropagation={() => {
|
||||
generateChatTitle();
|
||||
}}
|
||||
>
|
||||
<Sparkles className={tabbed || fullWidthTabs ? 'size-3.5' : 'size-4'} strokeWidth="1.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/snippet}
|
||||
|
||||
<audio bind:this={audioElement} style="display: none;"></audio>
|
||||
|
||||
{#if getChatVariablesForm(selectedModelIds, chatVariables, $models).conflicts.length > 0}
|
||||
@@ -5703,7 +5825,7 @@
|
||||
{/if}
|
||||
{:else}
|
||||
<FilesOverlay show={dragged} />
|
||||
{#if embedded && !side}
|
||||
{#if embedded && !tabbed}
|
||||
<div
|
||||
class="h-8 shrink-0 flex items-center justify-between gap-2 border-b border-gray-50/80 px-3 pb-1 text-gray-700 dark:border-gray-850/40 dark:text-gray-200"
|
||||
>
|
||||
@@ -5733,11 +5855,11 @@
|
||||
{:else if !embedded}
|
||||
<Navbar
|
||||
tabbed={fullWidthTabs}
|
||||
bind:tabTitleEditor
|
||||
{tabTitleEditor}
|
||||
renameHandler={startRename}
|
||||
bind:tabActions
|
||||
bind:tabBarActions
|
||||
{liveParticipants}
|
||||
bind:this={navbarElement}
|
||||
readOnly={isShared}
|
||||
chat={{
|
||||
id: $chatId,
|
||||
@@ -5807,7 +5929,7 @@
|
||||
{/if}
|
||||
<div id="chat-pane" class="flex min-h-0 flex-col flex-auto z-10 w-full @container overflow-auto">
|
||||
<div class="sr-only" aria-live="polite" aria-atomic="true">{liveStatus}</div>
|
||||
{#if (!side && $settings?.landingPageMode === 'chat' && !$selectedFolder) || (!contextOnly && createMessagesList(history, history.currentId).length > 0)}
|
||||
{#if (!tabbed && $settings?.landingPageMode === 'chat' && !$selectedFolder) || (!contextOnly && createMessagesList(history, history.currentId).length > 0)}
|
||||
<div
|
||||
class=" pb-2.5 flex flex-col justify-between w-full flex-auto overflow-auto h-0 max-w-full z-10 scrollbar-hidden"
|
||||
id={messagesContainerId}
|
||||
@@ -5889,7 +6011,6 @@
|
||||
temporary={$temporaryChatEnabled}
|
||||
{onTemporaryChange}
|
||||
bind:terminalContext
|
||||
terminalSelectionEnabled={!side}
|
||||
{typingUsers}
|
||||
on:typing={(event) => emitTyping(event.detail)}
|
||||
callActive={!!(bridge?.connected || bridge?.connecting)}
|
||||
@@ -5965,7 +6086,7 @@
|
||||
{/if}
|
||||
{:else if embedded}
|
||||
<div class="flex h-full min-h-0 flex-col justify-end">
|
||||
{#if side}
|
||||
{#if tabbed}
|
||||
<div class="flex flex-1 items-center justify-center px-6">
|
||||
<div class="max-w-56 text-center">
|
||||
<p class="text-sm font-normal text-gray-600 dark:text-gray-300">
|
||||
@@ -6010,7 +6131,6 @@
|
||||
temporary={$temporaryChatEnabled}
|
||||
{onTemporaryChange}
|
||||
bind:terminalContext
|
||||
terminalSelectionEnabled={!side}
|
||||
{typingUsers}
|
||||
on:typing={(event) => emitTyping(event.detail)}
|
||||
callActive={!!(bridge?.connected || bridge?.connecting)}
|
||||
@@ -6156,7 +6276,7 @@
|
||||
title={$chatTitle || $i18n.t('New Chat')}
|
||||
mainTabFolder={!$chatId && $selectedFolder ? { id: $selectedFolder.id, name: $selectedFolder.name, icon: $selectedFolder.meta?.icon, canEdit: $user?.role === 'admin' || $selectedFolder.user_id === $user?.id || $selectedFolder.write_access } : null}
|
||||
tabTitleEditor={loading ? undefined : tabTitleEditor}
|
||||
onRenameMainTab={() => navbarElement?.startRename?.()}
|
||||
onRenameMainTab={startRename}
|
||||
onRenameFolder={renameFolder}
|
||||
tabActions={loading ? undefined : !$chatId && $selectedFolder ? folderTabActions : tabActions}
|
||||
tabBarActions={loading ? undefined : tabBarActions}
|
||||
@@ -6169,7 +6289,7 @@
|
||||
folderId={chat ? (chat.folder_id ?? null) : ($selectedFolder?.id ?? null)}
|
||||
chatUser={chatOwner}
|
||||
modelId={selectedModelIds?.at(0) ?? null}
|
||||
canSideChat={sideChatAllowed}
|
||||
canBranchChat={sideChatAllowed}
|
||||
systemPrompt={params?.system || $settings.system || ''}
|
||||
submitPrompt={submitHandler}
|
||||
onAskFile={askFile}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
type Model,
|
||||
mobile,
|
||||
settings,
|
||||
models,
|
||||
models as _models,
|
||||
config,
|
||||
showCallOverlay,
|
||||
tools,
|
||||
@@ -132,6 +132,8 @@
|
||||
import QueuedMessageItem from './MessageInput/QueuedMessageItem.svelte';
|
||||
import TaskList from './Messages/ResponseMessage/TaskList.svelte';
|
||||
|
||||
const models = getContext<typeof _models>('chatModels') ?? _models;
|
||||
|
||||
const i18n: any = getContext('i18n');
|
||||
export let selectedTerminalId: Pick<Writable<string | null>, 'subscribe' | 'set'>;
|
||||
export let terminalSkills: Writable<any[]>;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { getContext, tick } from 'svelte';
|
||||
import { models, mobile, settings, user, type Model } from '$lib/stores';
|
||||
import { models as _models, mobile, settings, user, type Model } from '$lib/stores';
|
||||
import Controls from '../Controls/Controls.svelte';
|
||||
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
|
||||
import Dropdown from '$lib/components/common/Dropdown.svelte';
|
||||
@@ -17,6 +17,8 @@
|
||||
import Knobs from '$lib/components/icons/Knobs.svelte';
|
||||
import { localizeModelControls, resolveLocalizedModelName } from '$lib/utils/localizedContent';
|
||||
|
||||
const models = getContext<typeof _models>('chatModels') ?? _models;
|
||||
|
||||
const i18n: any = getContext('i18n');
|
||||
export let selectedModels: string[] = [];
|
||||
export let chatFiles: any[] = [];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { models, pinnedModels, settings, user } from '$lib/stores';
|
||||
import { models as _models, pinnedModels, settings, user } from '$lib/stores';
|
||||
import { getContext } from 'svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import Selector from './ModelSelector/Selector.svelte';
|
||||
@@ -7,6 +7,8 @@
|
||||
import { updateUserSettings } from '$lib/apis/users';
|
||||
import { resolveLocalizedModelName } from '$lib/utils/localizedContent';
|
||||
import equal from 'fast-deep-equal';
|
||||
const models = getContext<typeof _models>('chatModels') ?? _models;
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
export let selectedModels = [''];
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
user,
|
||||
MODEL_DOWNLOAD_POOL,
|
||||
mobile,
|
||||
models,
|
||||
models as _models,
|
||||
temporaryChatEnabled,
|
||||
settings,
|
||||
config,
|
||||
@@ -57,6 +57,8 @@
|
||||
|
||||
import ModelItem from './ModelItem.svelte';
|
||||
|
||||
const models = getContext<typeof _models>('chatModels') ?? _models;
|
||||
|
||||
const i18n: any = getContext('i18n');
|
||||
|
||||
export let id = '';
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { updateFolderChatLists } from '$lib/stores/folderStates';
|
||||
import { getContext, tick, type Snippet } from 'svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { getContext, type Snippet } from 'svelte';
|
||||
|
||||
import {
|
||||
WEBUI_NAME,
|
||||
banners,
|
||||
chatId,
|
||||
chatTitle as _chatTitle,
|
||||
config,
|
||||
mobile,
|
||||
selectedFolder,
|
||||
@@ -39,13 +36,7 @@
|
||||
import ChatPlus from '../icons/ChatPlus.svelte';
|
||||
import ChatCheck from '../icons/ChatCheck.svelte';
|
||||
import SplitPanel from '../icons/SplitPanel.svelte';
|
||||
import Sparkles from '$lib/components/layout/Sidebar/icons/Sparkles.svelte';
|
||||
import { isTemporaryChatId } from '$lib/utils/chatId';
|
||||
import { createMessagesList } from '$lib/utils';
|
||||
import { generateTitle } from '$lib/apis';
|
||||
import { updateChatById } from '$lib/apis/chats';
|
||||
import { getOutputText } from './Messages/structuredOutput';
|
||||
import { refreshChatList, refreshFolderChatLists } from '$lib/stores/chatList';
|
||||
import ChatParticipants from '$lib/components/common/ChatParticipants.svelte';
|
||||
|
||||
const i18n: any = getContext('i18n');
|
||||
@@ -64,7 +55,7 @@
|
||||
export let tabTitleEditor: Snippet | undefined = undefined;
|
||||
export let tabActions: Snippet | undefined = undefined;
|
||||
export let tabBarActions: Snippet | undefined = undefined;
|
||||
$: tabTitleEditor = confirmEdit ? renderTitleEditor : undefined;
|
||||
export let renameHandler: () => void;
|
||||
$: tabActions = renderChatActions;
|
||||
$: tabBarActions = renderTabBarActions;
|
||||
export let onSaveTempChat: () => {};
|
||||
@@ -84,120 +75,8 @@
|
||||
|
||||
let showShareChatModal = false;
|
||||
let showDownloadChatModal = false;
|
||||
|
||||
let confirmEdit = false;
|
||||
let chatTitle = '';
|
||||
let chatTitleInput: HTMLInputElement;
|
||||
let generating = false;
|
||||
|
||||
const renameHandler = async () => {
|
||||
chatTitle = title || chat?.chat?.title || '';
|
||||
confirmEdit = true;
|
||||
|
||||
await tick();
|
||||
setTimeout(() => {
|
||||
chatTitleInput?.focus();
|
||||
chatTitleInput?.select();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
// Lets the tab strip start a rename on double-click, same as the menu's Rename.
|
||||
export const startRename = () => {
|
||||
if (readOnly || !chat?.id) return;
|
||||
void renameHandler();
|
||||
};
|
||||
|
||||
const editChatTitle = async () => {
|
||||
// Disabling the field to generate a title blurs it, which would save the empty field
|
||||
if (!confirmEdit || generating) return;
|
||||
confirmEdit = false;
|
||||
|
||||
const newTitle = chatTitle.trim();
|
||||
if (newTitle === (title || chat?.chat?.title)) return;
|
||||
if (!newTitle) {
|
||||
toast.error($i18n.t('Title cannot be an empty string.'));
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await updateChatById(localStorage.token, chat.id, { title: newTitle }).catch(
|
||||
(error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
if (!res) return;
|
||||
updateFolderChatLists({ id: chat.id, title: newTitle });
|
||||
|
||||
if (chat.id === $chatId) {
|
||||
_chatTitle.set(newTitle);
|
||||
}
|
||||
await refreshChatList(localStorage.token, { refreshPinned: true });
|
||||
await refreshFolderChatLists();
|
||||
};
|
||||
|
||||
const generateTitleHandler = async () => {
|
||||
generating = true;
|
||||
chatTitle = '';
|
||||
|
||||
const messages = createMessagesList(history, history.currentId).map((message) => ({
|
||||
role: message.role,
|
||||
content: getOutputText(message.output) || message.content || ''
|
||||
}));
|
||||
const model = chat.chat.models.find((modelId: string) => modelId) ?? '';
|
||||
|
||||
const generatedTitle = await generateTitle(localStorage.token, model, messages).catch(
|
||||
(error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
}
|
||||
);
|
||||
generating = false;
|
||||
|
||||
chatTitle = generatedTitle || title;
|
||||
await editChatTitle();
|
||||
};
|
||||
</script>
|
||||
|
||||
{#snippet renderTitleEditor()}
|
||||
<input
|
||||
bind:this={chatTitleInput}
|
||||
bind:value={chatTitle}
|
||||
class="min-w-0 flex-1 bg-transparent {tabbed
|
||||
? 'text-sm'
|
||||
: 'md:py-1 text-[0.9375rem]'} font-normal text-gray-700 outline-hidden dark:text-gray-300"
|
||||
aria-label={$i18n.t('Title')}
|
||||
placeholder={generating ? $i18n.t('Generating...') : ''}
|
||||
disabled={generating}
|
||||
on:keydown={(e) => {
|
||||
if (e.isComposing || e.keyCode === 229) return;
|
||||
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
editChatTitle();
|
||||
} else if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
confirmEdit = false;
|
||||
}
|
||||
}}
|
||||
on:blur={editChatTitle}
|
||||
/>
|
||||
|
||||
<Tooltip content={$i18n.t('Generate')}>
|
||||
<button
|
||||
class="flex size-6 shrink-0 cursor-pointer items-center justify-center rounded-lg text-gray-500 transition hover:bg-gray-50/40 hover:text-gray-700 disabled:cursor-not-allowed dark:text-gray-400 dark:hover:bg-gray-800/40 dark:hover:text-gray-200"
|
||||
id="generate-title-button"
|
||||
aria-label={$i18n.t('Generate')}
|
||||
disabled={generating}
|
||||
on:mousedown={(e) => e.preventDefault()}
|
||||
on:click={() => {
|
||||
generateTitleHandler();
|
||||
}}
|
||||
>
|
||||
<Sparkles className={tabbed ? 'size-3.5' : 'size-4'} strokeWidth="1.5" />
|
||||
</button>
|
||||
</Tooltip>
|
||||
{/snippet}
|
||||
|
||||
{#snippet renderTemporaryChatToggle()}
|
||||
{#if $user?.role === 'user' ? ($user?.permissions?.chat?.temporary ?? true) && !($user?.permissions?.chat?.temporary_enforced ?? false) : true}
|
||||
{#if !chat?.id}
|
||||
@@ -372,8 +251,8 @@
|
||||
>
|
||||
{#if chat?.id}
|
||||
<div class="flex max-w-full min-w-0 items-center gap-2 mr-2">
|
||||
{#if confirmEdit && !tabbed}
|
||||
{@render renderTitleEditor()}
|
||||
{#if tabTitleEditor && !tabbed}
|
||||
{@render tabTitleEditor()}
|
||||
{:else}
|
||||
<h1
|
||||
class="min-w-0 truncate md:py-1 text-left text-[0.9375rem] font-normal text-gray-700 dark:text-gray-300"
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { getContext, onMount, setContext, tick } from 'svelte';
|
||||
import { writable } from 'svelte/store';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { socket, selectedFolder, user } from '$lib/stores';
|
||||
import { config, socket, selectedFolder, user } from '$lib/stores';
|
||||
import {
|
||||
loadFolderChatPage,
|
||||
updateFolderDetails,
|
||||
@@ -71,22 +71,28 @@
|
||||
let automationsView: FolderAutomations;
|
||||
|
||||
async function loadAutomations() {
|
||||
const id = folder?.id;
|
||||
if (!id) return;
|
||||
const folderId = folder?.id;
|
||||
if (!folderId || !canUseAutomations) return;
|
||||
automationsLoading = true;
|
||||
try {
|
||||
const next = await getFolderAutomations(localStorage.token, id);
|
||||
if (folder?.id === id) automations = next;
|
||||
const folderAutomations = await getFolderAutomations(localStorage.token, folderId);
|
||||
if (folder?.id === folderId) automations = folderAutomations;
|
||||
} catch (error) {
|
||||
if (folder?.id === id) automations = [];
|
||||
if (folder?.id === folderId) automations = [];
|
||||
} finally {
|
||||
automationsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
function showSection(next: 'chats' | 'automations') {
|
||||
folderSection = next;
|
||||
if (next === 'automations') void loadAutomations();
|
||||
$: canUseAutomations =
|
||||
$config?.features?.enable_automations &&
|
||||
($user?.role === 'admin' || $user?.permissions?.features?.automations);
|
||||
|
||||
$: if (!canUseAutomations && folderSection === 'automations') folderSection = 'chats';
|
||||
|
||||
function showSection(section: 'chats' | 'automations') {
|
||||
folderSection = section;
|
||||
if (section === 'automations') void loadAutomations();
|
||||
}
|
||||
export let onNewChat: () => void = () => {};
|
||||
export let folderTabActions: import('svelte').Snippet | undefined = undefined;
|
||||
@@ -1013,55 +1019,66 @@
|
||||
className="mx-0.5 size-3 shrink-0 text-gray-400 rtl:rotate-180 dark:text-gray-500"
|
||||
strokeWidth="2"
|
||||
/>
|
||||
<Dropdown align="start" closeOnSelect>
|
||||
<button
|
||||
type="button"
|
||||
class="-mx-1 flex shrink-0 items-center gap-1 rounded-md px-1 transition-colors hover:bg-gray-100 dark:hover:bg-gray-850"
|
||||
aria-label={$i18n.t('Switch section')}
|
||||
>
|
||||
{#if folderSection === 'automations'}
|
||||
<span>{$i18n.t('Automations')}</span>
|
||||
{#if automations.length}<span class="text-sm opacity-60">{automations.length}</span
|
||||
>{/if}
|
||||
{:else}
|
||||
<span>{$i18n.t('Chats')}</span>
|
||||
{#if loading && hasData}
|
||||
<Spinner className="size-3 opacity-60" />
|
||||
{:else if hasData && !error}
|
||||
<span class="text-sm opacity-60">{formatNumber(total)}</span>
|
||||
{#if canUseAutomations}
|
||||
<Dropdown align="start" closeOnSelect>
|
||||
<button
|
||||
type="button"
|
||||
class="-mx-1 flex shrink-0 items-center gap-1 rounded-md px-1 transition-colors hover:bg-gray-100 dark:hover:bg-gray-850"
|
||||
aria-label={$i18n.t('Switch section')}
|
||||
>
|
||||
{#if folderSection === 'automations'}
|
||||
<span>{$i18n.t('Automations')}</span>
|
||||
{#if automations.length}<span class="text-sm opacity-60">{automations.length}</span
|
||||
>{/if}
|
||||
{:else}
|
||||
<span>{$i18n.t('Chats')}</span>
|
||||
{#if loading && hasData}
|
||||
<Spinner className="size-3 opacity-60" />
|
||||
{:else if hasData && !error}
|
||||
<span class="text-sm opacity-60">{formatNumber(total)}</span>
|
||||
{/if}
|
||||
{/if}
|
||||
<ChevronDown className="size-2.5 text-gray-400 dark:text-gray-500" strokeWidth="2.5" />
|
||||
</button>
|
||||
<DropdownMenu slot="content" className="w-44">
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={folderSection === 'chats'}
|
||||
on:click={() => showSection('chats')}
|
||||
>
|
||||
<Icon name="chat-bubble" size={14} />
|
||||
<span class="flex-1 text-left">{$i18n.t('Chats')}</span>
|
||||
{#if hasData}<span class="text-xs tabular-nums text-gray-400"
|
||||
>{formatNumber(total)}</span
|
||||
>{/if}
|
||||
{#if folderSection === 'chats'}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={folderSection === 'automations'}
|
||||
on:click={() => showSection('automations')}
|
||||
>
|
||||
<Icon name="clock" size={14} />
|
||||
<span class="flex-1 text-left">{$i18n.t('Automations')}</span>
|
||||
{#if automations.length}<span class="text-xs tabular-nums text-gray-400"
|
||||
>{automations.length}</span
|
||||
>{/if}
|
||||
{#if folderSection === 'automations'}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
{:else}
|
||||
<span class="flex shrink-0 items-center gap-1">
|
||||
<span>{$i18n.t('Chats')}</span>
|
||||
{#if loading && hasData}
|
||||
<Spinner className="size-3 opacity-60" />
|
||||
{:else if hasData && !error}
|
||||
<span class="text-sm opacity-60">{formatNumber(total)}</span>
|
||||
{/if}
|
||||
<ChevronDown className="size-2.5 text-gray-400 dark:text-gray-500" strokeWidth="2.5" />
|
||||
</button>
|
||||
<DropdownMenu slot="content" className="w-44">
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={folderSection === 'chats'}
|
||||
on:click={() => showSection('chats')}
|
||||
>
|
||||
<Icon name="chat-bubble" size={14} />
|
||||
<span class="flex-1 text-left">{$i18n.t('Chats')}</span>
|
||||
{#if hasData}<span class="text-xs tabular-nums text-gray-400"
|
||||
>{formatNumber(total)}</span
|
||||
>{/if}
|
||||
{#if folderSection === 'chats'}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitemradio"
|
||||
aria-checked={folderSection === 'automations'}
|
||||
on:click={() => showSection('automations')}
|
||||
>
|
||||
<Icon name="clock" size={14} />
|
||||
<span class="flex-1 text-left">{$i18n.t('Automations')}</span>
|
||||
{#if automations.length}<span class="text-xs tabular-nums text-gray-400"
|
||||
>{automations.length}</span
|
||||
>{/if}
|
||||
{#if folderSection === 'automations'}<Check className="size-3! shrink-0" />{/if}
|
||||
</button>
|
||||
</DropdownMenu>
|
||||
</Dropdown>
|
||||
</span>
|
||||
{/if}
|
||||
</h2>
|
||||
|
||||
<div class="ml-auto flex items-center gap-1">
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
import GitBar from './Tabs/GitBar.svelte';
|
||||
import Artifacts from './Artifacts.svelte';
|
||||
import Embeds from './Tabs/Embeds.svelte';
|
||||
import SideChat from './Tabs/SideChat.svelte';
|
||||
import ChatTab from './Tabs/ChatTab.svelte';
|
||||
import FileNav from './FileNav.svelte';
|
||||
import PyodideFileNav from './PyodideFileNav.svelte';
|
||||
import Overview from './Overview.svelte';
|
||||
@@ -149,7 +149,8 @@
|
||||
export let files: any[] = [];
|
||||
export let modelId: string | null = null;
|
||||
export let systemPrompt = '';
|
||||
export let canSideChat = false;
|
||||
export let canBranchChat = false;
|
||||
$: canOpenChat = $user?.role === 'admin' || $user?.role === 'user';
|
||||
|
||||
export let codeInterpreterEnabled = false;
|
||||
// Retired layout controls: keep their translations.
|
||||
@@ -213,13 +214,14 @@
|
||||
export const hasTerminals = () => tabs.tabs.some((tab) => tab.kind === 'terminal');
|
||||
let browserViews: Record<string, Browser> = {};
|
||||
let gitViews: Record<string, GitBar> = {};
|
||||
let sideViews: Record<string, SideChat> = {};
|
||||
let sideChatStreaming: Record<string, boolean> = {};
|
||||
// Each side chat writes its artifacts here; its artifacts tab reads them.
|
||||
const sideArtifacts: Record<string, Writable<{ type: string; content: string }[]>> = {};
|
||||
const sideArtifactsFor = (id: string) => (sideArtifacts[id] ??= writable([]));
|
||||
let chatViews: Record<string, ChatTab> = {};
|
||||
let chatTitleEditors: Record<string, import('svelte').Snippet | undefined> = {};
|
||||
let chatStreamingStates: Record<string, boolean> = {};
|
||||
// Each chat writes its artifacts here; its artifacts tab reads them.
|
||||
const chatArtifacts: Record<string, Writable<{ type: string; content: string }[]>> = {};
|
||||
const chatArtifactsFor = (id: string) => (chatArtifacts[id] ??= writable([]));
|
||||
const artifactsOf = (sourceTabId = mainChatTabId) =>
|
||||
sourceTabId === mainChatTabId ? mainArtifacts : sideArtifactsFor(sourceTabId);
|
||||
sourceTabId === mainChatTabId ? mainArtifacts : chatArtifactsFor(sourceTabId);
|
||||
// The code block each artifacts tab was last asked to show.
|
||||
let artifactSelections: Record<string, { code: string }> = {};
|
||||
let pendingArtifacts: { code?: string } | null = null;
|
||||
@@ -238,7 +240,7 @@
|
||||
const draft = fileViews[tab.id]?.captureView?.();
|
||||
if (draft) owner.drafts.set(tab.id, draft);
|
||||
if (gitViews[tab.id]) owner.transient[`git:${tab.id}`] = gitViews[tab.id].captureView();
|
||||
if (sideViews[tab.id]) owner.transient[`side:${tab.id}`] = sideViews[tab.id].captureView();
|
||||
if (chatViews[tab.id]) owner.transient[`chat:${tab.id}`] = chatViews[tab.id].captureView();
|
||||
}
|
||||
owner.transient.gitDiffModes = fileGitDiffModes;
|
||||
owner.transient.gitHideWhitespace = fileGitHideWhitespace;
|
||||
@@ -263,7 +265,8 @@
|
||||
if (preserveChatView) return;
|
||||
viewReady = false;
|
||||
tabs = emptyTabs();
|
||||
sideChatStreaming = {};
|
||||
chatStreamingStates = {};
|
||||
chatTitleEditors = {};
|
||||
pendingArtifacts = null;
|
||||
++switchVersion;
|
||||
tabsChatId = undefined;
|
||||
@@ -313,7 +316,8 @@
|
||||
viewError = '';
|
||||
terminalTitles = {};
|
||||
terminalProcesses = {};
|
||||
sideChatStreaming = {};
|
||||
chatStreamingStates = {};
|
||||
chatTitleEditors = {};
|
||||
tabsChatId = id;
|
||||
const owner = chatViewEntry($user.id, id, $temporaryChatEnabled);
|
||||
viewEntry = owner;
|
||||
@@ -333,7 +337,7 @@
|
||||
sessionFailures = {};
|
||||
sessionAttempts = {};
|
||||
viewReady = true;
|
||||
hasOpenedTabs = tabs.tabs.some((tab) => tab.kind !== 'chat');
|
||||
hasOpenedTabs = tabs.tabs.some((tab) => tab.id !== mainChatTabId);
|
||||
} catch (error) {
|
||||
if (version === switchVersion) viewError = String(error);
|
||||
}
|
||||
@@ -373,7 +377,8 @@
|
||||
viewReady = false;
|
||||
viewEntry = null;
|
||||
tabs = emptyTabs();
|
||||
sideChatStreaming = {};
|
||||
chatStreamingStates = {};
|
||||
chatTitleEditors = {};
|
||||
tabsChatId = undefined;
|
||||
clearChatViews();
|
||||
}
|
||||
@@ -507,14 +512,13 @@
|
||||
artifacts: 'code',
|
||||
preview: 'browser',
|
||||
voice: 'microphone',
|
||||
comments: 'chat-bubble',
|
||||
side: 'chat-lines'
|
||||
comments: 'chat-bubble'
|
||||
})[kind];
|
||||
const domId = (id: string) => `chat-panel-${encodeURIComponent(id)}`;
|
||||
$: activeTabId = tabs.activeId;
|
||||
$: activeTab = tabs.tabs.find((tab) => tab.id === tabs.activeId);
|
||||
$: contextTab =
|
||||
activeTab?.kind === 'chat'
|
||||
activeTab?.id === mainChatTabId
|
||||
? tabs.tabs.find((tab) => tab.id === tabs.history.at(-1))
|
||||
: activeTab;
|
||||
$: activeFileContext = (contextTab && fileContexts[contextTab.id]) ?? contextTab?.context ?? null;
|
||||
@@ -586,8 +590,8 @@
|
||||
const url = new URL(request.href, location.origin);
|
||||
const chat = url.pathname === '/' || url.pathname.startsWith('/c/');
|
||||
return {
|
||||
id: `${chat ? 'side' : 'page'}:${uuidv4()}`,
|
||||
kind: chat ? 'side' : 'page',
|
||||
id: `${chat ? 'chat' : 'page'}:${uuidv4()}`,
|
||||
kind: chat ? 'chat' : 'page',
|
||||
href: url.pathname + url.search + url.hash,
|
||||
chatId: url.pathname.startsWith('/c/')
|
||||
? decodeURIComponent(url.pathname.slice(3))
|
||||
@@ -755,16 +759,16 @@
|
||||
openArtifacts(code);
|
||||
}
|
||||
const openFeature = (
|
||||
kind: 'artifacts' | 'preview' | 'voice' | 'comments' | 'side',
|
||||
kind: 'artifacts' | 'preview' | 'voice' | 'comments' | 'chat',
|
||||
inSidePanel = false
|
||||
) => {
|
||||
if (!availableViews.some((view) => view.kind === kind && view.available)) return;
|
||||
if (kind === 'artifacts') return openArtifacts(undefined, mainChatTabId, inSidePanel);
|
||||
const view = availableViews.find((view) => view.kind === kind)!;
|
||||
if (kind === 'side') {
|
||||
let sideChatNumber = 1;
|
||||
while (tabs.tabs.some((tab) => tab.kind === 'side' && tab.sideChatNumber === sideChatNumber))
|
||||
sideChatNumber++;
|
||||
if (kind === 'chat') {
|
||||
let chatNumber = 1;
|
||||
while (tabs.tabs.some((tab) => tab.kind === 'chat' && tab.chatNumber === chatNumber))
|
||||
chatNumber++;
|
||||
const pending = $sideChatRequest;
|
||||
const initialPrompt = pending?.parentId === chatId ? pending.prompt : '';
|
||||
if (pending?.parentId === chatId) sideChatRequest.set(null);
|
||||
@@ -772,9 +776,9 @@
|
||||
{
|
||||
id: uuidv4(),
|
||||
kind,
|
||||
label: `${view.label} ${sideChatNumber}`,
|
||||
sideChatNumber,
|
||||
sideChat: true,
|
||||
label: `${view.label} ${chatNumber}`,
|
||||
chatNumber,
|
||||
parentChatId: pending?.parentId === chatId ? (chatId ?? undefined) : undefined,
|
||||
initialPrompt
|
||||
},
|
||||
inSidePanel
|
||||
@@ -790,7 +794,7 @@
|
||||
let pendingTabDrop: (() => void) | null = null;
|
||||
const clearChatDropPreview = () => (chatDropPreview = null);
|
||||
const canDropChat = (event: Pick<DragEvent, 'dataTransfer'>) =>
|
||||
canSideChat &&
|
||||
canOpenChat &&
|
||||
($user?.role === 'admin' ||
|
||||
!(
|
||||
($user?.permissions?.chat?.temporary ?? true) &&
|
||||
@@ -930,7 +934,7 @@
|
||||
id = droppedPage?.id ?? uuidv4();
|
||||
tabs = openTab(
|
||||
tabs,
|
||||
droppedPage ?? { id, kind: 'side', label: $i18n.t('Chat'), chatId: savedId }
|
||||
droppedPage ?? { id, kind: 'chat', label: $i18n.t('Chat'), chatId: savedId }
|
||||
);
|
||||
}
|
||||
tabs = bounds.edge
|
||||
@@ -1087,20 +1091,21 @@
|
||||
owner.drafts.delete(id);
|
||||
const previousPanels = owner.state.panels;
|
||||
let closedPanels = removeTab(previousPanels, id);
|
||||
// a side chat's artifacts have nothing to show once the chat is gone
|
||||
if (tab.kind === 'side') closedPanels = removeTab(closedPanels, `artifacts:${id}`);
|
||||
// a chat's artifacts have nothing to show once the chat is gone
|
||||
if (tab.kind === 'chat') closedPanels = removeTab(closedPanels, `artifacts:${id}`);
|
||||
changeChatView(owner, { ...owner.state, panels: closedPanels });
|
||||
if (owner === viewEntry) {
|
||||
tabs = owner.state.panels;
|
||||
delete dirtyFiles[id];
|
||||
delete fileContexts[id];
|
||||
delete sideChatStreaming[id];
|
||||
delete chatStreamingStates[id];
|
||||
delete chatTitleEditors[id];
|
||||
delete artifactSelections[id];
|
||||
if (tab.kind === 'side') {
|
||||
delete sideArtifacts[id];
|
||||
if (tab.kind === 'chat') {
|
||||
delete chatArtifacts[id];
|
||||
delete artifactSelections[`artifacts:${id}`];
|
||||
}
|
||||
if (!tabs.tabs.length || (!largeScreen && tabs.tabs.every((tab) => tab.kind === 'chat')))
|
||||
if (!tabs.tabs.length || (!largeScreen && tabs.tabs.every((tab) => tab.id === mainChatTabId)))
|
||||
showTabs.set(false);
|
||||
await tick();
|
||||
if (owner === viewEntry) document.getElementById(domId(tabs.activeId))?.focus();
|
||||
@@ -1305,7 +1310,7 @@
|
||||
...commentTarget
|
||||
}
|
||||
: null;
|
||||
// A side chat's artifacts tab names the chat it belongs to.
|
||||
// A chat's artifacts tab names the chat it belongs to.
|
||||
$: tabLabel = (tab: PanelTab) => {
|
||||
if (tab.kind === 'terminal') return terminalTitles[tab.sessionId ?? ''] || tab.label;
|
||||
const source =
|
||||
@@ -1319,9 +1324,9 @@
|
||||
$: availableViews = [
|
||||
{ kind: 'files', label: $i18n.t('Files'), available: showFilesTab },
|
||||
{
|
||||
kind: 'side',
|
||||
kind: 'chat',
|
||||
label: $i18n.t('New Chat'),
|
||||
available: canSideChat
|
||||
available: canOpenChat
|
||||
},
|
||||
{ kind: 'artifacts', label: $i18n.t('Artifacts'), available: showArtifactsTab },
|
||||
{ kind: 'preview', label: $i18n.t('Preview'), available: showPreviewTab },
|
||||
@@ -1340,7 +1345,7 @@
|
||||
const view = availableViews.find((view) => view.available);
|
||||
if (!view) return;
|
||||
if (view.kind === 'files') openFiles();
|
||||
else openFeature(view.kind as 'artifacts' | 'preview' | 'voice' | 'comments' | 'side');
|
||||
else openFeature(view.kind as 'artifacts' | 'preview' | 'voice' | 'comments' | 'chat');
|
||||
}
|
||||
tabs = setSplitTabs(tabs, true);
|
||||
};
|
||||
@@ -1380,7 +1385,7 @@
|
||||
if ((desktopEnabled && selectedTarget) || canSelectTerminal) action = openDesktop;
|
||||
break;
|
||||
case Shortcut.NEW_CHAT_TAB:
|
||||
if (canSideChat) action = () => openFeature('side');
|
||||
if (canOpenChat) action = () => openFeature('chat');
|
||||
break;
|
||||
case Shortcut.OPEN_COMMENTS:
|
||||
if (showCommentsTab) action = () => openFeature('comments');
|
||||
@@ -1512,10 +1517,10 @@
|
||||
) {
|
||||
const options = [
|
||||
...availableViews
|
||||
.filter((view) => view.available && view.kind !== 'side')
|
||||
.filter((view) => view.available && view.kind !== 'chat')
|
||||
.map((view) => () => {
|
||||
if (view.kind === 'files') openFiles();
|
||||
else openFeature(view.kind as 'artifacts' | 'preview' | 'voice' | 'comments' | 'side');
|
||||
else openFeature(view.kind as 'artifacts' | 'preview' | 'voice' | 'comments' | 'chat');
|
||||
}),
|
||||
...(terminalFilesAvailable ? [newFile] : []),
|
||||
...(terminalEnabled ? [newTerminal] : []),
|
||||
@@ -1524,7 +1529,7 @@
|
||||
];
|
||||
if (terminalFilesAvailable || (!hasOpenedTabs && showFilesTab)) openFiles();
|
||||
else if (options.length === 1) options[0]();
|
||||
else if (!options.length && !canSideChat) showTabs.set(false);
|
||||
else if (!options.length && !canOpenChat) showTabs.set(false);
|
||||
hasOpenedTabs = true;
|
||||
}
|
||||
$: if (
|
||||
@@ -1536,7 +1541,7 @@
|
||||
)
|
||||
sideChatRequest.set(null);
|
||||
$: if (viewReady && $showTabs === 'side') {
|
||||
if (canSideChat) openFeature('side', true);
|
||||
if (canBranchChat) openFeature('chat', true);
|
||||
else sideChatRequest.set(null);
|
||||
showTabs.set(tabs.tabs.length > 0);
|
||||
}
|
||||
@@ -1658,16 +1663,16 @@
|
||||
const href =
|
||||
active?.kind === 'page'
|
||||
? active.href
|
||||
: active?.kind === 'chat'
|
||||
: active?.id === mainChatTabId
|
||||
? mainChatHref
|
||||
: active?.kind === 'side'
|
||||
: active?.kind === 'chat'
|
||||
? active.chatId
|
||||
? `/c/${active.chatId}`
|
||||
: active.href
|
||||
: null;
|
||||
if (href) {
|
||||
const url = new URL(href, location.origin);
|
||||
if (active?.kind === 'chat' && !chatId) {
|
||||
if (active?.id === mainChatTabId && !chatId) {
|
||||
// delete() re-encodes the other parameters even when it removes nothing.
|
||||
if ($temporaryChatEnabled) url.searchParams.set('temporary-chat', 'true');
|
||||
else if (url.searchParams.has('temporary-chat')) url.searchParams.delete('temporary-chat');
|
||||
@@ -1706,7 +1711,7 @@
|
||||
Do not alter, remove, obscure, or replace it except as LICENSE permits:
|
||||
https://docs.openwebui.com/license. -->
|
||||
<title
|
||||
>{activeTab?.kind === 'page' || activeTab?.kind === 'side'
|
||||
>{activeTab?.kind === 'page' || (activeTab?.kind === 'chat' && activeTab.id !== mainChatTabId)
|
||||
? `${activeTab.label} / ${$WEBUI_NAME}`
|
||||
: $settings.showChatTitleInTab !== false && chatId && title
|
||||
? `${title.length > 30 ? `${title.slice(0, 30)}...` : title} / ${$WEBUI_NAME}`
|
||||
@@ -1926,7 +1931,7 @@
|
||||
></div>
|
||||
</div>
|
||||
{/each}
|
||||
{#each (viewReady ? tabs.tabs : []).filter((tab) => tab.kind !== 'chat') as tab (`${viewEntry?.instanceId}:${tab.id}`)}
|
||||
{#each (viewReady ? tabs.tabs : []).filter((tab) => tab.id !== mainChatTabId) as tab (`${viewEntry?.instanceId}:${tab.id}`)}
|
||||
{@const owner = viewEntry!}
|
||||
{@const target =
|
||||
mounted && $config && $user && $settings && $terminalServers !== null
|
||||
@@ -1984,23 +1989,23 @@
|
||||
overlay={dragged}
|
||||
artifacts={artifactsOf(tab.sourceTabId)}
|
||||
selection={artifactSelections[tab.id] ?? null}
|
||||
chatId={(source?.kind === 'side' ? source.chatId : owner.chatId) ?? ''}
|
||||
chatId={(source?.id !== mainChatTabId && source?.kind === 'chat' ? source.chatId : owner.chatId) ?? ''}
|
||||
/>
|
||||
{:else if tab.kind === 'side'}
|
||||
<SideChat
|
||||
standalone={!!tab.href}
|
||||
bind:this={sideViews[tab.id]}
|
||||
bind:streaming={sideChatStreaming[tab.id]}
|
||||
artifacts={sideArtifactsFor(tab.id)}
|
||||
{:else if tab.kind === 'chat'}
|
||||
<ChatTab
|
||||
bind:this={chatViews[tab.id]}
|
||||
bind:streaming={chatStreamingStates[tab.id]}
|
||||
bind:tabTitleEditor={chatTitleEditors[tab.id]}
|
||||
artifacts={chatArtifactsFor(tab.id)}
|
||||
onOpenArtifacts={(code) => openArtifacts(code, tab.id)}
|
||||
initialView={owner.transient[`side:${tab.id}`]}
|
||||
initialView={owner.transient[`chat:${tab.id}`]}
|
||||
chatId={tab.chatId ?? ''}
|
||||
onChatUpdate={(chat) =>
|
||||
updateViewTab(owner, tab.id, {
|
||||
chatId: chat.id,
|
||||
...(chat.title ? { label: chat.title } : {})
|
||||
})}
|
||||
parentChatId={tab.sideChat ? (owner.chatId ?? '') : ''}
|
||||
parentChatId={tab.parentChatId ?? ''}
|
||||
parentFolderId={tab.href ? null : folderId}
|
||||
{history}
|
||||
modelId={tab.href
|
||||
@@ -2257,6 +2262,10 @@
|
||||
}}
|
||||
>
|
||||
{#each group.tabIds.map((id) => tabs.tabs.find((tab) => tab.id === id)!) as tab (tab.id)}
|
||||
{@const titleEditor =
|
||||
tab.id === mainChatTabId
|
||||
? mainTabFolder ? undefined : tabTitleEditor
|
||||
: chatTitleEditors[tab.id]}
|
||||
{@const PageIcon =
|
||||
tab.kind === 'page' ? pageIcons[tab.href?.split(/[/?#]/)[1] ?? ''] : null}
|
||||
<div
|
||||
@@ -2271,26 +2280,27 @@
|
||||
>
|
||||
<button
|
||||
role="tab"
|
||||
aria-keyshortcuts={tab.kind === 'chat'
|
||||
aria-keyshortcuts={tab.id === mainChatTabId
|
||||
? undefined
|
||||
: 'Alt+Shift+ArrowLeft Alt+Shift+ArrowRight'}
|
||||
id={domId(tab.id)}
|
||||
aria-controls={`${domId(tab.id)}-view`}
|
||||
aria-selected={group.activeId === tab.id}
|
||||
tabindex={group.activeId === tab.id ? 0 : -1}
|
||||
title={tab.kind === 'chat' ? mainTabTitle : (tab.directory ?? tab.path ?? tabLabel(tab))}
|
||||
aria-label={tab.kind === 'chat' ? mainTabTitle : undefined}
|
||||
title={tab.id === mainChatTabId ? mainTabTitle : (tab.directory ?? tab.path ?? tabLabel(tab))}
|
||||
aria-label={tab.id === mainChatTabId ? mainTabTitle : undefined}
|
||||
class="flex h-full items-center gap-1.5 min-w-0"
|
||||
on:dblclick={() => {
|
||||
if (tab.kind !== 'chat') return;
|
||||
if (tab.kind === 'chat') void chatViews[tab.id]?.startRename();
|
||||
if (tab.id !== mainChatTabId) return;
|
||||
if (mainTabFolder) void startFolderRename();
|
||||
else onRenameMainTab?.();
|
||||
}}
|
||||
>
|
||||
{#if (tab.kind === 'chat' && chatStreaming) || (tab.kind === 'side' && sideChatStreaming[tab.id])}
|
||||
{#if (tab.id === mainChatTabId && chatStreaming) || (tab.kind === 'chat' && chatStreamingStates[tab.id])}
|
||||
<Spinner className="size-3.5" />
|
||||
<span class="sr-only">{$i18n.t('Generating...')}</span>
|
||||
{:else if tab.kind === 'chat' && mainTabFolder}
|
||||
{:else if tab.id === mainChatTabId && mainTabFolder}
|
||||
{#if mainTabFolder.icon}
|
||||
<Emoji shortCode={mainTabFolder.icon} className="size-3.5" />
|
||||
{:else}
|
||||
@@ -2310,20 +2320,21 @@
|
||||
{:else}
|
||||
<Icon name={tabIcon(tab.kind)} size={14} />
|
||||
{/if}
|
||||
{#if tab.kind !== 'chat' || (mainTabFolder ? !renamingFolder : !tabTitleEditor)}
|
||||
{#if !titleEditor && !(tab.id === mainChatTabId && mainTabFolder && renamingFolder)}
|
||||
<span class="max-w-30 overflow-hidden text-ellipsis"
|
||||
>{tab.kind === 'chat' ? mainTabTitle : tabLabel(tab)}</span
|
||||
>{tab.id === mainChatTabId ? mainTabTitle : tabLabel(tab)}</span
|
||||
>
|
||||
{/if}
|
||||
{#if tab.kind === 'comments' && commentCount}<span class="text-gray-400"
|
||||
>{commentCount}</span
|
||||
>{/if}
|
||||
</button>
|
||||
{@render titleEditor?.()}
|
||||
{#if tab.untitled || dirtyFiles[tab.id]}<span
|
||||
class="ms-1 size-1.5 shrink-0 rounded-full bg-gray-400"
|
||||
aria-label={$i18n.t('Unsaved changes')}
|
||||
></span>{/if}
|
||||
{#if tab.kind === 'chat'}
|
||||
{#if tab.id === mainChatTabId}
|
||||
{#if mainTabFolder && renamingFolder}
|
||||
<input
|
||||
data-folder-tab-rename
|
||||
@@ -2343,7 +2354,7 @@
|
||||
}}
|
||||
on:blur={saveFolderRename}
|
||||
/>
|
||||
{:else if !mainTabFolder}{@render tabTitleEditor?.()}{/if}
|
||||
{/if}
|
||||
{@render tabActions?.()}
|
||||
{:else}<button
|
||||
type="button"
|
||||
@@ -2410,7 +2421,7 @@
|
||||
<button
|
||||
on:click={() =>
|
||||
openFeature(
|
||||
view.kind as 'artifacts' | 'preview' | 'voice' | 'comments' | 'side'
|
||||
view.kind as 'artifacts' | 'preview' | 'voice' | 'comments' | 'chat'
|
||||
)}
|
||||
>
|
||||
{#if view.kind === 'comments'}
|
||||
@@ -2418,7 +2429,7 @@
|
||||
{:else}
|
||||
<Icon name={tabIcon(view.kind as PanelTab['kind'])} size={14} />
|
||||
{/if}<span class="flex-1 text-start">{view.label}</span>
|
||||
{#if view.kind === 'side'}
|
||||
{#if view.kind === 'chat'}
|
||||
<HotkeyHint name="newChatTab" className="ms-auto" />
|
||||
{:else if view.kind === 'comments'}
|
||||
<HotkeyHint name="openComments" className="ms-auto" />
|
||||
|
||||
+13
-39
@@ -3,13 +3,13 @@
|
||||
import { writable, type Writable } from 'svelte/store';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { user } from '$lib/stores';
|
||||
import { createNewChat } from '$lib/apis/chats';
|
||||
import { refreshChatList, refreshFolderChatLists } from '$lib/stores/chatList';
|
||||
import { convertMessagesToHistory, isRasterImageContentType } from '$lib/utils';
|
||||
import Chat from '../Chat.svelte';
|
||||
let chatView: Chat | undefined;
|
||||
export const startRename = () => chatView?.startRename();
|
||||
export let tabTitleEditor: import('svelte').Snippet | undefined = undefined;
|
||||
|
||||
export let initialPrompt = '';
|
||||
export let standalone = false;
|
||||
export let initialView: any = null;
|
||||
export const captureView = () => ({ draft, files, context });
|
||||
export let chatId = '';
|
||||
@@ -23,18 +23,18 @@
|
||||
export let modelId: string | null = null;
|
||||
export let systemPrompt = '';
|
||||
const i18n = getContext<any>('i18n');
|
||||
const originalChatId = parentChatId;
|
||||
const draftKey = uuidv4();
|
||||
const restored = !!initialView;
|
||||
let draft = initialView?.draft ?? initialPrompt;
|
||||
let files: any[] = initialView?.files ?? [];
|
||||
$: sideChatAllowed =
|
||||
$: chatAllowed =
|
||||
$user?.role === 'admin' ||
|
||||
($user?.role === 'user' && (standalone || ($user.permissions?.chat?.side_chat ?? false)));
|
||||
($user?.role === 'user' &&
|
||||
(chatId || !parentChatId || ($user.permissions?.chat?.side_chat ?? false)));
|
||||
// Snapshot the active branch once; later parent edits and streaming stay in the parent.
|
||||
let context = (() => {
|
||||
if (initialView?.context) return initialView.context;
|
||||
if (chatId || standalone) return [];
|
||||
if (chatId || !parentChatId) return [];
|
||||
const branch: any[] = [];
|
||||
let current = history?.currentId;
|
||||
const seen = new Set<string>();
|
||||
@@ -100,41 +100,14 @@
|
||||
let title = $i18n.t('New Chat');
|
||||
// Sending clears the input before the chat is created.
|
||||
$: if (draft || files.length) title = draft.trim().slice(0, 100) || $i18n.t('New Chat');
|
||||
|
||||
const createChat = async (chat: {
|
||||
models: string[];
|
||||
params: Record<string, any>;
|
||||
variables: Record<string, any>;
|
||||
}) => {
|
||||
const created = await createNewChat(
|
||||
localStorage.token,
|
||||
{
|
||||
title,
|
||||
...(originalChatId && {
|
||||
originalChatId,
|
||||
branchPointMessageId: context.at(-1)?.id ?? null
|
||||
}),
|
||||
models: chat.models,
|
||||
params: chat.params,
|
||||
history: convertMessagesToHistory(context),
|
||||
messages: context,
|
||||
files: contextFiles(),
|
||||
tags: [],
|
||||
timestamp: Date.now()
|
||||
},
|
||||
parentFolderId,
|
||||
chat.variables
|
||||
);
|
||||
void refreshChatList(localStorage.token);
|
||||
if (created.folder_id) void refreshFolderChatLists(created.folder_id, created);
|
||||
return created;
|
||||
};
|
||||
</script>
|
||||
|
||||
{#if sideChatAllowed}
|
||||
{#if chatAllowed}
|
||||
<Chat
|
||||
bind:this={chatView}
|
||||
bind:tabTitleEditor
|
||||
embedded={true}
|
||||
side={true}
|
||||
tabbed={true}
|
||||
{parentChatId}
|
||||
chatIdProp={chatId}
|
||||
embeddedDraftKey={chatId ? '' : draftKey}
|
||||
@@ -145,7 +118,8 @@
|
||||
bind:files
|
||||
{artifacts}
|
||||
{onOpenArtifacts}
|
||||
onCreateEmbeddedChat={createChat}
|
||||
draftTitle={title}
|
||||
draftFolderId={parentFolderId}
|
||||
onSelectEmbeddedChat={(id) => onChatUpdate({ id, title })}
|
||||
onEmbeddedChatTitle={(id, chatTitle) => onChatUpdate({ id, title: chatTitle })}
|
||||
/>
|
||||
@@ -13,8 +13,7 @@ export type PanelTabKind =
|
||||
| 'artifacts'
|
||||
| 'preview'
|
||||
| 'voice'
|
||||
| 'comments'
|
||||
| 'side';
|
||||
| 'comments';
|
||||
export type PanelTab = {
|
||||
id: string;
|
||||
kind: PanelTabKind;
|
||||
@@ -22,8 +21,9 @@ export type PanelTab = {
|
||||
href?: string;
|
||||
initialPrompt?: string;
|
||||
chatId?: string;
|
||||
sideChatNumber?: number;
|
||||
sideChat?: boolean;
|
||||
chatNumber?: number;
|
||||
/** Set only when a new conversation explicitly inherits another chat's context. */
|
||||
parentChatId?: string;
|
||||
/** For an artifacts tab: the tab of the chat whose artifacts it shows. */
|
||||
sourceTabId?: string;
|
||||
terminalId?: string;
|
||||
@@ -80,6 +80,28 @@ export const emptyTabs = (): PanelTabs => ({
|
||||
});
|
||||
export const mainChatTabId = 'main-chat';
|
||||
|
||||
/** Read layouts saved before all conversation tabs used kind: 'chat'. */
|
||||
export function normalizeChatTab(
|
||||
tab: Omit<PanelTab, 'kind'> & {
|
||||
kind: PanelTabKind | 'side';
|
||||
sideChatNumber?: number;
|
||||
sideChat?: boolean;
|
||||
},
|
||||
parentChatId: string | null
|
||||
): PanelTab {
|
||||
const { sideChatNumber, sideChat, ...current } = tab;
|
||||
return {
|
||||
...current,
|
||||
kind: current.kind === 'side' ? 'chat' : current.kind,
|
||||
chatNumber: current.chatNumber ?? sideChatNumber,
|
||||
parentChatId:
|
||||
current.parentChatId ??
|
||||
(current.kind === 'side' && (sideChat ?? (!current.href && !!sideChatNumber))
|
||||
? (parentChatId ?? undefined)
|
||||
: undefined)
|
||||
};
|
||||
}
|
||||
|
||||
export function setMainChatTab(state: PanelTabs, visible: boolean, label = 'Chat'): PanelTabs {
|
||||
if (!visible) {
|
||||
return setSplitTabs(removeTab(state, mainChatTabId), false);
|
||||
|
||||
@@ -7,6 +7,8 @@ import { createBrowserSession } from '$lib/apis/terminal/browser';
|
||||
import { isSavedChatId } from '$lib/utils/chatId';
|
||||
import {
|
||||
emptyTabs,
|
||||
mainChatTabId,
|
||||
normalizeChatTab,
|
||||
removeTab,
|
||||
type ChatViewState,
|
||||
type PanelTab
|
||||
@@ -53,7 +55,7 @@ export function serializeChatView(state: ChatViewState): ChatViewState {
|
||||
if (
|
||||
tab.untitled ||
|
||||
['voice', 'artifacts', 'preview'].includes(tab.kind) ||
|
||||
(tab.kind === 'side' && !isSavedChatId(tab.chatId))
|
||||
(tab.kind === 'chat' && tab.id !== mainChatTabId && !isSavedChatId(tab.chatId))
|
||||
)
|
||||
panels = removeTab(panels, tab.id);
|
||||
}
|
||||
@@ -70,8 +72,8 @@ export function serializeChatView(state: ChatViewState): ChatViewState {
|
||||
terminalId: tab.terminalId,
|
||||
terminalNumber: tab.terminalNumber,
|
||||
chatId: tab.chatId,
|
||||
sideChatNumber: tab.sideChatNumber,
|
||||
sideChat: tab.sideChat,
|
||||
chatNumber: tab.chatNumber,
|
||||
parentChatId: tab.parentChatId,
|
||||
path: tab.path,
|
||||
page: tab.page,
|
||||
sessionId: tab.sessionId,
|
||||
@@ -116,11 +118,9 @@ export async function loadChatView(entry: Entry) {
|
||||
throw new Error('Unsupported chat view version');
|
||||
if (!entry.loaded && result.state) {
|
||||
entry.state = result.state;
|
||||
// Older views used the display number to identify chats branched from the parent.
|
||||
for (const tab of entry.state.panels.tabs) {
|
||||
if (tab.kind === 'side')
|
||||
tab.sideChat ??= !tab.href && !!tab.sideChatNumber;
|
||||
}
|
||||
entry.state.panels.tabs = entry.state.panels.tabs.map((tab) =>
|
||||
normalizeChatTab(tab, entry.chatId)
|
||||
);
|
||||
}
|
||||
entry.loaded = true;
|
||||
entry.error = '';
|
||||
@@ -189,7 +189,7 @@ export function updateViewTab(entry: Entry, id: string, values: Partial<PanelTab
|
||||
export function closeChatTabs(chatId: string) {
|
||||
for (const entry of entries.values()) {
|
||||
const ids = entry.state.panels.tabs
|
||||
.filter((tab) => tab.kind === 'side' && tab.chatId === chatId)
|
||||
.filter((tab) => tab.kind === 'chat' && tab.id !== mainChatTabId && tab.chatId === chatId)
|
||||
.map((tab) => tab.id);
|
||||
if (!ids.length) continue;
|
||||
for (const id of ids) entry.drafts.delete(id);
|
||||
|
||||
@@ -193,7 +193,7 @@ export const selectedTerminalId: Writable<string | null> = writable(null);
|
||||
export const embed = writable(null);
|
||||
|
||||
export const temporaryChatEnabled = writable(false);
|
||||
export const openSideChatIds = writable<Set<string>>(new Set());
|
||||
export const openEmbeddedChatIds = writable<Set<string>>(new Set());
|
||||
export const sideChatRequest = writable<{ parentId: string; prompt: string } | null>(null);
|
||||
|
||||
export type QueryData = {
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
chatId,
|
||||
tags,
|
||||
temporaryChatEnabled,
|
||||
openSideChatIds,
|
||||
openEmbeddedChatIds,
|
||||
isLastActiveTab,
|
||||
isApp,
|
||||
appInfo,
|
||||
@@ -476,7 +476,7 @@
|
||||
// This prevents notifications from being sent to other tabs/devices
|
||||
// for privacy, since temporary chats are not meant to be persisted or visible elsewhere.
|
||||
const isTemporaryChat = isTemporaryChatId(event.chat_id);
|
||||
if (isTemporaryChat && event.chat_id !== $chatId && !$openSideChatIds.has(event.chat_id)) {
|
||||
if (isTemporaryChat && event.chat_id !== $chatId && !$openEmbeddedChatIds.has(event.chat_id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@
|
||||
if (
|
||||
!event?.internal &&
|
||||
((event.chat_id !== $chatId &&
|
||||
!$openSideChatIds.has(event.chat_id) &&
|
||||
!$openEmbeddedChatIds.has(event.chat_id) &&
|
||||
!$temporaryChatEnabled) ||
|
||||
isInBackground)
|
||||
) {
|
||||
|
||||
Reference in new issue
Block a user