This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-16 19:14:07 +09:00
1 parent 5d55ce7246
commit 21605e268d
35 files changed
+387 -174

No files matched your search

+50 -24
View File
@@ -2,6 +2,7 @@
import { getTerminalServers } from '$lib/apis/terminal';
import { resolveToolApprovalMode } from '$lib/utils/toolPermissions';
import type { AppLayoutContext, TerminalContext } from '$lib/types';
import { setChatContext } from './context';
import {
estimateTokens,
estimateMessagesTokens,
@@ -11,7 +12,7 @@
import { v4 as uuidv4 } from 'uuid';
import { toast } from 'svelte-sonner';
import { getContext, setContext, onDestroy, onMount, tick } from 'svelte';
import { getContext, onDestroy, onMount, tick } from 'svelte';
import { fade } from 'svelte/transition';
const i18n: Writable<i18nType> = getContext('i18n');
const appLayout = getContext<AppLayoutContext | undefined>('appLayout');
@@ -41,7 +42,7 @@
showTabs as _showTabs,
chatTabRequest,
openEmbeddedChatIds,
showCallOverlay as _showCallOverlay,
voiceCall as _voiceCall,
temporaryChatEnabled as _temporaryChatEnabled,
mobile,
chatTitle as _chatTitle,
@@ -183,12 +184,21 @@
const temporaryChatEnabled = embedded ? writable(false) : _temporaryChatEnabled;
const selectedFolder = embedded ? writable<FolderDetails | null>(null) : _selectedFolder;
const showTabs = embedded ? writable(get(_showTabs)) : _showTabs;
const showCallOverlay = embedded ? writable(false) : _showCallOverlay;
// the call lives in the main chat's voice tab, so a side chat is never in it
const voiceCall = embedded ? writable(false) : _voiceCall;
const showEmbeds = embedded ? writable(false) : _showEmbeds;
const selectedTerminalId = tabbed ? writable(get(_selectedTerminalId)) : _selectedTerminalId;
const terminalSkills = tabbed ? writable<any[]>([]) : _terminalSkills;
const models = tabbed ? writable(get(_models)) : _models;
setContext('chatModels', models);
const contextCompactions = writable<Record<string, 'in_progress' | { error: string }>>({});
setChatContext({
chatId,
models,
temporary: temporaryChatEnabled,
audioQueue,
contextCompactions,
submitPrompt: (prompt) => submitHandler(prompt)
});
export let embeddedTitle = '';
export let embeddedChats = [];
export let embeddedDraftKey = '';
@@ -489,8 +499,6 @@
let generating = false;
let dragged = false;
let generationController = null;
const contextCompactions = writable<Record<string, 'in_progress' | { error: string }>>({});
setContext('contextCompactions', contextCompactions);
const openArtifacts = (code?: string) => {
// the list is rebuilt after a debounce, so it can lag behind the block being opened
getContents();
@@ -510,7 +518,7 @@
// Non-owners may reply when the sharing mode allows it, but cannot save chat edits.
$: isShared = chat != null && chat.user_id !== $user?.id;
$: if (isShared && $showCallOverlay) showCallOverlay.set(false);
$: if (isShared && $voiceCall) voiceCall.set(false);
$: canClone = isShared && ($user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true));
$: canOpenChatTab =
$user?.role === 'admin' ||
@@ -606,7 +614,7 @@
if (fullWidthTabs) {
tabs?.focusMainChat();
await tick();
if (!$showCallOverlay) messageInput?.focus({ preventScroll: true });
if (!$voiceCall) messageInput?.focus({ preventScroll: true });
}
const last = history.currentId ? history.messages[history.currentId] : null;
if (last?.role === 'assistant' && !last.done) {
@@ -1700,7 +1708,7 @@
if (event?.data?.type === 'voice:play_animation') {
cb?.(
routeAvatarAnimation(eventTarget, event, {
active: $showCallOverlay && callMode === 'current' && selectedModelIds.length === 1,
active: $voiceCall && callMode === 'current' && selectedModelIds.length === 1,
chatId: $chatId,
modelId: selectedModelIds[0],
messageId: history.currentId,
@@ -2542,7 +2550,7 @@
releaseCallWakeLock = active ? acquireWakeLock() : () => {};
};
$: callInProgress =
($showCallOverlay && callMode === 'current') || !!(bridge?.connected || bridge?.connecting);
($voiceCall && callMode === 'current') || !!(bridge?.connected || bridge?.connecting);
$: updateCallWakeLock(callInProgress);
onDestroy(() => releaseCallWakeLock());
@@ -2758,7 +2766,7 @@
$: if (selectedModelIds && $models && $config) bridge?.syncModel();
const dispatchCallOverlayAudio = (message, final = false) => {
if (message.error || !$showCallOverlay || callMode !== 'current') {
if (message.error || !$voiceCall || callMode !== 'current') {
return;
}
@@ -2883,7 +2891,7 @@
return;
}
showCallOverlay.set(true);
voiceCall.set(true);
showTabs.set(true);
};
@@ -3050,7 +3058,7 @@
if ($mobile) {
await showTabs.set(false);
}
await showCallOverlay.set(false);
await voiceCall.set(false);
if (!embedded && !preserveTabs && $page.url.pathname.includes('/c/')) {
window.history.replaceState(window.history.state, '', `/`);
@@ -3159,7 +3167,7 @@
} else if (event.type === 'call' || event.type === 'voice') {
openCallOverlay();
event.handoff?.complete(
$showCallOverlay
$voiceCall
? undefined
: 'Voice mode is unavailable. Check your model, permissions and voice settings in WebUI.'
);
@@ -3949,7 +3957,7 @@
copyToClipboard(visibleContent);
}
if ($settings.responseAutoPlayback && !$showCallOverlay && !bridge?.connected) {
if ($settings.responseAutoPlayback && !$voiceCall && !bridge?.connected) {
await tick();
document.getElementById(`speak-button-${message.id}`)?.click();
}
@@ -4039,7 +4047,7 @@
history.currentId = userMessageId;
// focus on chat input (skip during voice call to avoid triggering mobile keyboard)
if (!$showCallOverlay) {
if (!$voiceCall) {
messageInput?.focus({ preventScroll: true });
}
@@ -4777,7 +4785,7 @@
if ($config?.features)
features = {
voice: ($showCallOverlay && callMode === 'current') || !!bridge?.connected,
voice: ($voiceCall && callMode === 'current') || !!bridge?.connected,
image_generation:
$config?.features?.enable_image_generation &&
($user?.role === 'admin' || $user?.permissions?.features?.image_generation)
@@ -5996,7 +6004,10 @@
}}
/>
{/if}
<div id="chat-pane" class="flex min-h-0 flex-col flex-auto z-10 w-full @container overflow-auto">
<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 (!tabbed && $settings?.landingPageMode === 'chat' && !$selectedFolder) || (!contextOnly && createMessagesList(history, history.currentId).length > 0)}
<div
@@ -6018,7 +6029,6 @@
<Messages
{messagesContainerId}
{branchPointMessageId}
temporary={$temporaryChatEnabled}
bind:this={messagesRef}
chatId={$chatId}
user={chatOwner ?? (chat ? { id: chat.user_id } : $user)}
@@ -6077,7 +6087,6 @@
{terminalSkills}
{messagesContainerId}
{inputId}
temporary={$temporaryChatEnabled}
{onTemporaryChange}
bind:terminalContext
{typingUsers}
@@ -6197,7 +6206,6 @@
{terminalSkills}
{messagesContainerId}
{inputId}
temporary={$temporaryChatEnabled}
{onTemporaryChange}
bind:terminalContext
{typingUsers}
@@ -6267,7 +6275,11 @@
</div>
</div>
{:else}
<div class="flex h-full {$selectedFolder ? 'min-h-0 flex-1 overflow-hidden' : 'items-center'}">
<div
class="flex h-full {$selectedFolder
? 'min-h-0 flex-1 overflow-hidden'
: 'items-center'}"
>
<Placeholder
bind:folderTabActions
{selectedTerminalId}
@@ -6343,11 +6355,25 @@
bind:mainChatStyle
bind:mainChatGroupId
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}
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={startRename}
onRenameFolder={renameFolder}
tabActions={loading ? undefined : !$chatId && $selectedFolder ? folderTabActions : tabActions}
tabActions={loading
? undefined
: !$chatId && $selectedFolder
? folderTabActions
: tabActions}
tabBarActions={loading ? undefined : tabBarActions}
{terminalContext}
bind:chatHistory={history}
@@ -3,7 +3,7 @@
import { marked } from 'marked';
import DOMPurify from 'dompurify';
import { config, user, models as _models, temporaryChatEnabled } from '$lib/stores';
import { config, user } from '$lib/stores';
import { onMount, getContext } from 'svelte';
import { blur, fade } from 'svelte/transition';
@@ -18,6 +18,9 @@
} from '$lib/utils/localizedContent';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import EyeSlash from '$lib/components/icons/EyeSlash.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models: _models, temporary } = getChatContext();
const i18n: any = getContext('i18n');
@@ -101,7 +104,7 @@
</div>
</div>
{#if $temporaryChatEnabled}
{#if $temporary}
<Tooltip
content={$i18n.t("This chat won't appear in history and your messages will not be saved.")}
className="w-full flex justify-start mb-0.5"
@@ -2,7 +2,7 @@
import { resolveLocalizedResource } from '$lib/utils/localizedContent';
import { toast } from 'svelte-sonner';
import { config, functions, models, settings, tools, user } from '$lib/stores';
import { config, functions, settings, tools, user } from '$lib/stores';
import { createEventDispatcher, onMount, getContext, tick } from 'svelte';
import {
@@ -21,6 +21,9 @@
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import Valves from '$lib/components/common/Valves.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const dispatch = createEventDispatcher();
@@ -1,12 +1,14 @@
<script lang="ts">
import { getContext } from 'svelte';
import { chatId } from '$lib/stores';
import Dropdown from '$lib/components/common/Dropdown.svelte';
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
import EditPencilIcon from '$lib/components/layout/Sidebar/icons/EditPencil.svelte';
import EmbeddedChatHistoryItem from './EmbeddedChatHistoryItem.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { chatId } = getChatContext();
const i18n = getContext('i18n');
+23 -28
View File
@@ -35,9 +35,8 @@
type Model,
mobile,
settings,
models as _models,
config,
showCallOverlay,
voiceCall,
tools,
skills,
terminalServers,
@@ -46,7 +45,6 @@
showSettings,
showFileNavDir,
TTSWorker,
temporaryChatEnabled,
chatTabRequest,
visibleControls
} from '$lib/stores';
@@ -131,8 +129,9 @@
import Expand from '../icons/Expand.svelte';
import QueuedMessageItem from './MessageInput/QueuedMessageItem.svelte';
import TaskList from './Messages/ResponseMessage/TaskList.svelte';
import { getChatContext } from '$lib/components/chat/context';
const models = getContext<typeof _models>('chatModels') ?? _models;
const { models, temporary } = getChatContext();
const i18n: any = getContext('i18n');
export let selectedTerminalId: Pick<Writable<string | null>, 'subscribe' | 'set'>;
@@ -166,9 +165,7 @@
export let chatId = '';
export let inputId = 'chat-input';
export let messagesContainerId = 'messages-container';
export let temporary: boolean | undefined = undefined;
export let onTemporaryChange: ((value: boolean) => void) | null = null;
$: isTemporary = temporary ?? $temporaryChatEnabled;
export let terminalContext: TerminalContext | null = null;
export let terminalSelectionEnabled = true;
export let contextUsage = null;
@@ -226,7 +223,7 @@
$config?.features?.enable_comments &&
$_user &&
isSavedChatId(chatId) &&
!isTemporary
!$temporary
);
export const openComments = () => {
if (canComments) showTabs.set('comments');
@@ -529,7 +526,7 @@
export const setText = (text: string = '') => {
chatInputElement?.setText(text);
if (!$showCallOverlay) {
if (!$voiceCall) {
focus();
}
};
@@ -663,21 +660,21 @@
const temporaryHandler = async () => {
if (!canToggleTemporary) return;
if (onTemporaryChange) {
onTemporaryChange(!isTemporary);
onTemporaryChange(!$temporary);
return;
}
if (($settings?.temporaryChatByDefault ?? false) && isTemporary) {
await temporaryChatEnabled.set(null);
if (($settings?.temporaryChatByDefault ?? false) && $temporary) {
await temporary.set(null);
} else {
await temporaryChatEnabled.set(!isTemporary);
await temporary.set(!$temporary);
}
if (location.pathname !== '/' && !location.pathname.startsWith('/folders/')) {
await goto('/');
}
if (isTemporary) {
if ($temporary) {
window.history.replaceState(window.history.state, '', '?temporary-chat=true');
} else {
window.history.replaceState(window.history.state, '', location.pathname);
@@ -931,8 +928,7 @@
);
$: showTerminalSelector =
$config?.features?.enable_tool_servers &&
($terminalServers ?? []).some((t) => t.id);
$config?.features?.enable_tool_servers && ($terminalServers ?? []).some((t) => t.id);
let canCreateSkill: boolean = false;
$: canCreateSkill = selectedModelIds.every(
@@ -1175,7 +1171,7 @@
return;
}
if (!isTemporary) {
if (!$temporary) {
try {
// If the file is an audio file, provide the language for STT.
let metadata = null;
@@ -1351,7 +1347,7 @@
// Compress the image if settings or config require it
imageUrl = await compressImageHandler(imageUrl, $settings, $config);
if (isTemporary) {
if ($temporary) {
files = [
...files,
{
@@ -1740,13 +1736,13 @@
canSide: () => canSide,
canFork: () =>
!!history?.currentId &&
!isTemporary &&
!$temporary &&
($_user?.role === 'admin' || ($_user?.permissions?.chat?.import ?? true)),
forkDisabled: () => isActive,
canTemporary: () => canToggleTemporary,
hasChatContent: hasChatContent,
canCreateSkill: () => canCreateSkill,
temporaryEnabled: () => isTemporary === true,
temporaryEnabled: () => $temporary === true,
contextUsage: () => statusContextUsage,
onCompact: compactHandler,
onStatus: statusHandler,
@@ -1882,7 +1878,7 @@
loaded = true;
window.setTimeout(() => {
if (!$showCallOverlay) {
if (!$voiceCall) {
const chatInput = document.getElementById(inputId);
chatInput?.focus();
}
@@ -1988,7 +1984,7 @@
<div class="w-full">
<div class=" mx-auto inset-x-0 bg-transparent flex justify-center">
<div
class="flex flex-col px-3 {$settings?.widescreenMode ?? null
class="flex flex-col px-3 {($settings?.widescreenMode ?? null)
? 'max-w-full'
: 'max-w-[58rem]'} w-full"
>
@@ -2041,7 +2037,7 @@
<div class="bg-transparent">
<div
class="{$settings?.widescreenMode ?? null
class="{($settings?.widescreenMode ?? null)
? 'max-w-full'
: 'max-w-[58rem]'} px-2 mx-auto inset-x-0"
>
@@ -2235,10 +2231,9 @@
<div
id={inputId === 'chat-input' ? 'message-input-container' : `${inputId}-wrapper`}
data-composer-id={inputId}
class="flex-1 flex flex-col relative w-full shadow-[0_6px_24px_-4px_rgba(0,0,0,0.1)] rounded-3xl border {isTemporary
class="flex-1 flex flex-col relative w-full shadow-[0_6px_24px_-4px_rgba(0,0,0,0.1)] rounded-3xl border {$temporary
? 'border-dashed border-gray-300/70 dark:border-gray-700/70'
: ' border-gray-200 dark:border-gray-850'} {($settings?.highContrastMode ??
false)
: ' border-gray-200 dark:border-gray-850'} {($settings?.highContrastMode ?? false)
? 'focus-within:outline focus-within:outline-2 focus-within:-outline-offset-2 focus-within:outline-blue-500 [&_.ProseMirror:focus-visible]:outline-none!'
: ''} transition px-0.5 bg-white/5 dark:bg-gray-500/5 backdrop-blur-sm dark:text-gray-100"
dir={$settings?.chatDirection ?? 'auto'}
@@ -3059,7 +3054,7 @@
type="button"
on:click={async () => {
if (callActive) {
showCallOverlay.set(true);
voiceCall.set(true);
showTabs.set('voice');
return;
}
@@ -3070,7 +3065,7 @@
}
if ($config?.audio?.realtime?.enabled) {
showCallOverlay.set(true);
voiceCall.set(true);
showTabs.set(true);
return;
}
@@ -3102,7 +3097,7 @@
}
}
showCallOverlay.set(true);
voiceCall.set(true);
showTabs.set(true);
} catch (err) {
// If the user denies the permission or an error occurs, show an error message
@@ -1,5 +1,5 @@
<script lang="ts">
import { config, models, settings, showCallOverlay, TTSWorker } from '$lib/stores';
import { config, settings, voiceCall, TTSWorker } from '$lib/stores';
import { onMount, tick, getContext, onDestroy, createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
@@ -18,6 +18,9 @@
import type { RealtimeCall } from '$lib/utils/realtime';
import VoiceAvatar from './CallOverlay/VoiceAvatar.svelte';
import type { AvatarAnimationCommand } from '$lib/utils/voice-avatar';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const i18n: any = getContext('i18n');
@@ -82,7 +85,7 @@
command.result = { status: 'cancelled' };
} else if (
!destroyed &&
$showCallOverlay &&
$voiceCall &&
showAvatar &&
!camera &&
readyAvatar === avatar?.file_id
@@ -274,8 +277,8 @@
};
const stopRecordingCallback = async (_continue = true) => {
// $showCallOverlay stays true when the chat page unmounts
if ($showCallOverlay && !destroyed) {
// $voiceCall stays true when the chat page unmounts
if ($voiceCall && !destroyed) {
console.log('%c%s', 'color: red; font-size: 20px;', '🚨 stopRecordingCallback 🚨');
// deep copy the audioChunks array
@@ -322,7 +325,7 @@
};
const startRecording = async () => {
if ($showCallOverlay && !destroyed) {
if ($voiceCall && !destroyed) {
if (!audioStream) {
audioStream = await navigator.mediaDevices.getUserMedia({
audio: {
@@ -416,7 +419,7 @@
const detectSound = () => {
const processFrame = () => {
if (!mediaRecorder || !$showCallOverlay) {
if (!mediaRecorder || !$voiceCall) {
return;
}
@@ -497,7 +500,7 @@
};
const speakSpeechSynthesisHandler = (content) => {
if (!$showCallOverlay) return Promise.resolve();
if (!$voiceCall) return Promise.resolve();
const signal = audioAbortController.signal;
return new Promise<void>((resolve) => {
let utterance: SpeechSynthesisUtterance | null = null;
@@ -534,7 +537,7 @@
};
const playAudio = (audio: HTMLAudioElement) => {
if ($showCallOverlay) {
if ($voiceCall) {
return new Promise((resolve) => {
const audioElement = callAudioElement;
if (!audioElement) {
@@ -910,7 +913,7 @@
});
</script>
{#if $showCallOverlay}
{#if $voiceCall}
<!-- A media element can only have one Web Audio source, even after its context closes. -->
<audio bind:this={callAudioElement} class="hidden"></audio>
<div
@@ -1019,7 +1022,7 @@
speaking={avatarSpeaking}
listening={hasStartedSpeaking && !muted && !avatarSpeaking}
level={outputLevel}
active={!destroyed && $showCallOverlay}
active={!destroyed && $voiceCall}
on:ready={() => {
readyAvatar = selectedAvatar.file_id;
}}
@@ -1309,7 +1312,7 @@
await stopVideoStream();
}
showCallOverlay.set(false);
voiceCall.set(false);
dispatch('close');
}}
type="button"
@@ -1,10 +1,13 @@
<script lang="ts">
import { createEventDispatcher, getContext, onMount } from 'svelte';
import { models, showCallOverlay } from '$lib/stores';
import { voiceCall } from '$lib/stores';
import type { RealtimeCall } from '$lib/utils/realtime';
import Spinner from '$lib/components/common/Spinner.svelte';
import VoiceOrb from './VoiceOrb.svelte';
import VoiceAvatar from './VoiceAvatar.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
export let bridge: RealtimeCall;
export let modelId = '';
@@ -31,7 +34,7 @@
const endCall = () => {
bridge.end();
showCallOverlay.set(false);
voiceCall.set(false);
dispatch('close');
};
@@ -1,6 +1,6 @@
<script lang="ts">
import { createEventDispatcher, getContext, onMount } from 'svelte';
import { config, showCallOverlay } from '$lib/stores';
import { config, voiceCall } from '$lib/stores';
import type { RealtimeCall } from '$lib/utils/realtime';
import CallOverlay from './CallOverlay.svelte';
import BridgeCallOverlay from './CallOverlay/BridgeCallOverlay.svelte';
@@ -19,7 +19,7 @@
const dispatch = createEventDispatcher();
const close = () => {
showCallOverlay.set(false);
voiceCall.set(false);
dispatch('close');
};
@@ -4,15 +4,7 @@
import { getContext, onDestroy, onMount, tick } from 'svelte';
import type { Readable } from 'svelte/store';
import {
chatId as activeChatId,
folders,
models,
settings,
terminalServers,
temporaryChatEnabled,
user
} from '$lib/stores';
import { folders, settings, terminalServers, user } from '$lib/stores';
import { WEBUI_API_BASE_URL } from '$lib/constants';
import { getFolders } from '$lib/apis/folders';
import { searchKnowledgeBases, searchKnowledgeFiles } from '$lib/apis/knowledge';
@@ -31,6 +23,9 @@
import GlobeAlt from '$lib/components/icons/GlobeAlt.svelte';
import Youtube from '$lib/components/icons/Youtube.svelte';
import { toast } from 'svelte-sonner';
import { getChatContext } from '$lib/components/chat/context';
const { chatId: activeChatId, models, temporary } = getChatContext();
const i18n = getContext<any>('i18n');
@@ -161,7 +156,7 @@
if (
($terminalServers ?? []).find((server) => server.id === $selectedTerminalId)?.scope ===
'chat' &&
($temporaryChatEnabled || isTemporaryChatId($activeChatId))
($temporary || isTemporaryChatId($activeChatId))
)
return null;
return target;
@@ -4,13 +4,15 @@
import { createEventDispatcher, onDestroy, onMount } from 'svelte';
import { tick, getContext } from 'svelte';
import { models } from '$lib/stores';
import { WEBUI_API_BASE_URL, WEBUI_BASE_URL } from '$lib/constants';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import {
resolveLocalizedModelDescription,
resolveLocalizedModelName
} from '$lib/utils/localizedContent';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
@@ -9,9 +9,12 @@
resolveTerminalTarget,
type TerminalSkill
} from '$lib/apis/terminal';
import { chatId, settings, terminalServers } from '$lib/stores';
import { settings, terminalServers } from '$lib/stores';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Cube from '$lib/components/icons/Cube.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { chatId } = getChatContext();
const i18n = getContext('i18n');
@@ -10,7 +10,7 @@
resolveTerminalTarget,
type TerminalSkill
} from '$lib/apis/terminal';
import { user, chatId, settings, terminalServers, visibleControls } from '$lib/stores';
import { user, settings, terminalServers, visibleControls } from '$lib/stores';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import ChatBubbleDotted from '$lib/components/icons/ChatBubbleDotted.svelte';
import ChatBubbleDottedChecked from '$lib/components/icons/ChatBubbleDottedChecked.svelte';
@@ -20,6 +20,9 @@
import Icon from '$lib/components/chat/FileNav/Icon.svelte';
import Plus from '$lib/components/icons/Plus.svelte';
import Sparkles from '$lib/components/icons/Sparkles.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { chatId } = getChatContext();
const i18n: any = getContext('i18n');
@@ -1,6 +1,6 @@
<script lang="ts">
import { getContext, onMount, tick } from 'svelte';
import { models, config } from '$lib/stores';
import { config } from '$lib/stores';
import { toast } from 'svelte-sonner';
import { copyToClipboard } from '$lib/utils';
@@ -9,6 +9,9 @@
import Modal from '$lib/components/common/Modal.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import MapSelector from '$lib/components/common/Valves/MapSelector.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
@@ -6,7 +6,6 @@
import { fly } from 'svelte/transition';
import {
chatId,
config,
settings,
terminalServers,
@@ -40,6 +39,9 @@
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
import ChevronLeft from '$lib/components/icons/ChevronLeft.svelte';
import LinkSlash from '$lib/components/icons/LinkSlash.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { chatId } = getChatContext();
const i18n = getContext('i18n') as any;
export let selectedTerminalId: Readable<string | null>;
@@ -1,6 +1,6 @@
<script lang="ts">
import { getContext, tick } from 'svelte';
import { models as _models, mobile, settings, user, type Model } from '$lib/stores';
import { 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';
@@ -16,8 +16,9 @@
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Knobs from '$lib/components/icons/Knobs.svelte';
import { localizeModelControls, resolveLocalizedModelName } from '$lib/utils/localizedContent';
import { getChatContext } from '$lib/components/chat/context';
const models = getContext<typeof _models>('chatModels') ?? _models;
const { models } = getChatContext();
const i18n: any = getContext('i18n');
export let selectedModels: string[] = [];
@@ -11,15 +11,7 @@
import WorkingDirectoryMenu from './WorkingDirectoryMenu.svelte';
import type { TerminalContext } from '$lib/types';
import {
chatId as activeChatId,
config,
settings,
showSettings,
terminalServers,
temporaryChatEnabled,
user
} from '$lib/stores';
import { config, settings, showSettings, terminalServers, user } from '$lib/stores';
import { selectTerminal } from '$lib/utils/terminal';
import { isTemporaryChatId, isSavedChatId } from '$lib/utils/chatId';
@@ -36,6 +28,9 @@
import TerminalItemMenu from './TerminalItemMenu.svelte';
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import Check from '$lib/components/icons/Check.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { chatId: activeChatId, temporary } = getChatContext();
const i18n = getContext<any>('i18n');
export let selectedTerminalId: Pick<Writable<string | null>, 'subscribe' | 'set'>;
@@ -121,8 +116,7 @@
};
$: systemTerminals = ($terminalServers ?? []).filter(
(t) =>
t.id && !(($temporaryChatEnabled || isTemporaryChatId($activeChatId)) && t.scope === 'chat')
(t) => t.id && !(($temporary || isTemporaryChatId($activeChatId)) && t.scope === 'chat')
);
// Tether presences are the user's own paired devices, listed apart from servers.
const isDevice = (terminal: any) => terminal.id.startsWith('tether:');
+5 -4
View File
@@ -1,6 +1,6 @@
<script lang="ts">
import { v4 as uuidv4 } from 'uuid';
import { config, settings, user as _user, mobile, temporaryChatEnabled } from '$lib/stores';
import { config, settings, user as _user, mobile } from '$lib/stores';
import { refreshChatList } from '$lib/stores/chatList';
import { tick, getContext, onMount, onDestroy, createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
@@ -15,13 +15,14 @@
import Spinner from '../common/Spinner.svelte';
import ChatPlaceholder from './ChatPlaceholder.svelte';
import { getChatContext } from './context';
const i18n = getContext('i18n');
export let className = 'h-full flex pt-18';
export let chatId = '';
export let temporary = $temporaryChatEnabled;
const { temporary } = getChatContext();
export let user = $_user;
export let prompt;
@@ -197,7 +198,7 @@
};
const updateChat = async () => {
if (!temporary) {
if (!$temporary) {
history = history;
await tick();
const res = await updateChatById(localStorage.token, chatId, {
@@ -491,7 +492,7 @@
history.currentId = getDeepestChildId(history, parentMessageId);
history = history;
if (!temporary) {
if (!$temporary) {
const res = await deleteChatMessageById(localStorage.token, chatId, messageId);
if (res?.chat?.history) {
history = res.chat.history;
@@ -18,9 +18,11 @@
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import { injectCsp } from '$lib/utils/csp';
import { getChatContext } from '$lib/components/chat/context';
export let app: MCPAppEmbed;
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
const { submitPrompt } = getChatContext();
const lifetime = new AbortController();
let iframe: HTMLIFrameElement;
let bridge: AppBridge | undefined;
@@ -126,9 +128,13 @@
.flatMap((block) => (block.type === 'text' ? [block.text] : []))
.join('\n\n');
const signal = AbortSignal.any([lifetime.signal, extra.mcpReq.signal]);
if (!text || !(await requestConfirmation($i18n.t('Confirm Prompt from Embed'), text, signal)))
if (
!text ||
!submitPrompt ||
!(await requestConfirmation($i18n.t('Confirm Prompt from Embed'), text, signal))
)
throw new Error('Message cancelled');
window.postMessage({ type: 'input:prompt:submit', text }, window.origin);
submitPrompt(text);
return {};
};
bridge.onopenlink = async ({ url }) => {
@@ -23,8 +23,11 @@
import { goto } from '$app/navigation';
import type { AppLayoutContext } from '$lib/types';
import { channels, models } from '$lib/stores';
import { channels } from '$lib/stores';
import UserStatusLinkPreview from '$lib/components/channel/Messages/Message/UserStatusLinkPreview.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
const appLayout = getContext<AppLayoutContext | undefined>('appLayout');
@@ -2,7 +2,7 @@
import { onMount, tick, getContext } from 'svelte';
import { createEventDispatcher } from 'svelte';
import { mobile, models, settings, visibleControls } from '$lib/stores';
import { mobile, settings, visibleControls } from '$lib/stores';
import { generateMoACompletion } from '$lib/apis';
import { updateChatById } from '$lib/apis/chats';
@@ -24,6 +24,9 @@
formatMessageTimestampFull,
getDeepestChildId
} from '$lib/utils';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
export let chatId;
@@ -2,10 +2,13 @@
import { toast } from 'svelte-sonner';
import { createEventDispatcher, onMount, getContext } from 'svelte';
import { config, models, tags as _tags } from '$lib/stores';
import { config, tags as _tags } from '$lib/stores';
import Tags from '$lib/components/common/Tags.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const i18n = getContext('i18n');
@@ -13,8 +13,6 @@
import type { i18n as i18nType, t } from 'i18next';
const i18n = getContext<Writable<i18nType>>('i18n');
const contextCompactions =
getContext<Writable<Record<string, 'in_progress' | { error: string }>>>('contextCompactions');
const dispatch = createEventDispatcher();
@@ -22,15 +20,7 @@
import { getChatById } from '$lib/apis/chats';
import { generateTags } from '$lib/apis';
import {
audioQueue,
config,
models,
settings,
TTSWorker,
user,
visibleControls
} from '$lib/stores';
import { config, settings, TTSWorker, user, visibleControls } from '$lib/stores';
import { synthesizeOpenAISpeech } from '$lib/apis/audio';
import { imageGenerations } from '$lib/apis/images';
import {
@@ -75,6 +65,9 @@
import MCPApp from '$lib/components/chat/Messages/MCPApp.svelte';
import OutputEditView from './OutputEditView.svelte';
import { getOutputText, replaceOutputMessageText, type OutputItem } from './structuredOutput';
import { getChatContext } from '$lib/components/chat/context';
const { audioQueue, models, contextCompactions } = getChatContext();
interface MessageType {
user_id?: string;
@@ -6,9 +6,8 @@
import ChevronRightIcon from '$lib/components/layout/Sidebar/icons/ChevronRight.svelte';
import { toast } from 'svelte-sonner';
import { tick, getContext, onMount } from 'svelte';
import type { Writable } from 'svelte/store';
import { models, settings } from '$lib/stores';
import { settings } from '$lib/stores';
import { user as _user } from '$lib/stores';
import {
copyToClipboard as _copyToClipboard,
@@ -29,10 +28,11 @@
import Image from '$lib/components/common/Image.svelte';
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import SubagentResultRow from './SubagentResultRow.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models, contextCompactions } = getChatContext();
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
const contextCompactions =
getContext<Writable<Record<string, 'in_progress' | { error: string }>>>('contextCompactions');
export let user;
export let chatId;
@@ -1,7 +1,8 @@
<script lang="ts">
import { getContext, onDestroy } from 'svelte';
import { get } from 'svelte/store';
import { chatId as activeChatId, config, settings } from '$lib/stores';
import { config, settings } from '$lib/stores';
import { getChatContext } from '../context';
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import ToolCallDisplay from '$lib/components/common/ToolCallDisplay.svelte';
import { buildToolCallToken, getToolResultText, type OutputItem } from './structuredOutput';
@@ -27,6 +28,7 @@
export let resolving = false;
export let onResolve: (approved: boolean) => void = () => {};
const i18n = getContext<typeof import('$lib/i18n').default>('i18n');
const { chatId: activeChatId, submitPrompt } = getChatContext();
const decoder = createVisualizationArgumentDecoder();
let ready = false,
initialized = false;
@@ -155,6 +157,7 @@
if (
!initialized ||
!execute ||
!submitPrompt ||
confirmCall ||
get(activeChatId) !== chatId ||
typeof data.requestId !== 'string' ||
@@ -172,7 +175,7 @@
showConfirmation = false;
confirmCall = undefined;
const sent = accept && current === generation && get(activeChatId) === chatId;
if (sent) window.postMessage({ type: 'input:prompt:submit', text: data.text }, window.origin);
if (sent) submitPrompt?.(data.text);
reply(sent);
};
}
@@ -271,6 +271,115 @@ export function agentView(item: OutputItem, result: string): AgentView | null {
return null;
}
const parseObject = (text: unknown): Data => {
try {
return obj(JSON.parse(str(text) || '{}'));
} catch {
return {};
}
};
const lines = (entries: Data[], line: (entry: Data) => string) =>
entries.map(line).filter(Boolean).join('\n');
const pathOf = (entry: Data) => str(entry.relative_path ?? entry.path ?? entry.name ?? entry.file);
// Open WebUI's own Open Terminal tools, by name. Each finished result must have the shape
// Open Terminal returns, so a different tool with the same name keeps the generic card.
export function terminalView(item: OutputItem, result: string): AgentView | null {
if (item.type !== 'function_call' || item.provider_data || item.native) return null;
const args = parseObject(item.arguments);
const data = parseObject(result);
const shaped = (...keys: string[]) => !result || keys.some((key) => key in data);
const path = str(args.path);
switch (item.name) {
case 'run_command':
case 'get_process_status': {
// A command still running when the call returns is followed by get_process_status,
// whose result names the command again.
const command = str(args.command ?? data.command);
if (!command || !shaped('status')) return null;
return {
kind: 'command',
command,
output: list(data.output)
.map((entry) => str(entry.data))
.join(''),
exitCode: exitCode(data.exit_code)
};
}
case 'read_file':
return path && shaped('content', 'path')
? { kind: 'read', paths: [path], output: str(data.content) }
: null;
case 'grep_search':
return args.query && shaped('matches')
? {
kind: 'search',
query: str(args.query),
output: lines(list(data.matches), (match) =>
match.line != null
? `${str(match.file)}:${str(match.line)}: ${str(match.content)}`
: str(match.file)
)
}
: null;
case 'glob_search':
case 'search_files':
case 'match_files': {
const query = str(args.pattern ?? args.query);
return query && shaped('matches', 'results')
? {
kind: 'search',
query,
output: lines(list(data.matches ?? data.results), pathOf)
}
: null;
}
case 'list_files':
return shaped('entries')
? {
kind: 'list',
path: str(args.directory) || '.',
output: lines(list(data.entries), (entry) =>
entry.type === 'directory' ? `${pathOf(entry)}/` : pathOf(entry)
)
}
: null;
case 'write_file': {
if (!path || !shaped('size')) return null;
const finished = str(data.patch);
// Without a patch, only a new file's diff is known: its content, numbered from 1.
const diff = isPatch(finished)
? finished
: data.created === false
? ''
: patch(path, '', str(args.content), true);
return { kind: 'edit', files: [{ path, diff }] };
}
case 'replace_file_content': {
if (!path || !shaped('size')) return null;
const finished = str(data.patch);
return {
kind: 'edit',
files: [
isPatch(finished)
? { path, diff: finished }
: editFile(
path,
list(args.replacements).map((chunk) => ({
oldText: chunk.target,
newText: chunk.replacement
}))
)
]
};
}
}
return null;
}
const fileName = (path: string) => path.split('/').filter(Boolean).pop() || path;
export const agentViewName = (view: AgentView) => {
@@ -1,6 +1,6 @@
import { encode } from 'html-entities';
import { getDispatchedVisualizationPreviews } from '$lib/utils/visualizations/dispatch';
import { agentView, type AgentView } from './agentViews';
import { agentView, terminalView, type AgentView } from './agentViews';
export type OutputContentPart = {
type?: string;
@@ -251,7 +251,7 @@ export function buildToolCallToken(
? 'Executing...'
: 'Preparing...',
text,
view: agentView(item, text),
view: agentView(item, text) ?? terminalView(item, text),
attributes: {
type: 'tool_calls',
id: callId,
+3 -2
View File
@@ -1,5 +1,5 @@
<script lang="ts">
import { models as _models, pinnedModels, settings, user } from '$lib/stores';
import { pinnedModels, settings, user } from '$lib/stores';
import { getContext } from 'svelte';
import { toast } from 'svelte-sonner';
import Selector from './ModelSelector/Selector.svelte';
@@ -7,7 +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;
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const i18n = getContext('i18n');
@@ -30,8 +30,6 @@
user,
MODEL_DOWNLOAD_POOL,
mobile,
models as _models,
temporaryChatEnabled,
settings,
config,
showSettings,
@@ -56,8 +54,9 @@
import TagSelector from '$lib/components/workspace/common/TagSelector.svelte';
import ModelItem from './ModelItem.svelte';
import { getChatContext } from '$lib/components/chat/context';
const models = getContext<typeof _models>('chatModels') ?? _models;
const { models, temporary } = getChatContext();
const i18n: any = getContext('i18n');
+4 -1
View File
@@ -9,12 +9,15 @@
} from '@xyflow/svelte';
import { writable } from 'svelte/store';
import { models, user } from '$lib/stores';
import { user } from '$lib/stores';
import '@xyflow/svelte/dist/style.css';
import CustomNode from './Node.svelte';
import Flow from './Flow.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models } = getChatContext();
const { width, height } = useStore();
+8 -9
View File
@@ -12,13 +12,7 @@
import { updateFolderById } from '$lib/apis/folders';
import {
config,
user,
models as _models,
temporaryChatEnabled,
selectedFolder
} from '$lib/stores';
import { config, user, selectedFolder } from '$lib/stores';
import { sanitizeResponseContent, extractCurlyBraceWords } from '$lib/utils';
import {
resolveLocalizedModelDescription,
@@ -33,6 +27,9 @@
import EyeSlash from '$lib/components/icons/EyeSlash.svelte';
import MessageInput from './MessageInput.svelte';
import FolderPlaceholder from './Placeholder/FolderPlaceholder.svelte';
import { getChatContext } from '$lib/components/chat/context';
const { models: _models, temporary } = getChatContext();
const i18n: any = getContext('i18n');
@@ -187,7 +184,7 @@
: 'm-auto max-w-[58rem] px-1 md:@3xl:px-20 translate-y-6 py-24'} text-center"
>
<!-- In a folder, temporary mode shows on the composer alone. -->
{#if $temporaryChatEnabled && !$selectedFolder}
{#if $temporary && !$selectedFolder}
<Tooltip
content={$i18n.t("This chat won't appear in history and your messages will not be saved.")}
className="w-full flex justify-center mb-0.5"
@@ -202,7 +199,9 @@
{#if $selectedFolder}
<div
class="relative min-h-0 w-full flex-1"
style="--folder-composer-space: {folderReadOnly || folderSection !== 'chats' ? 0 : composerHeight}px"
style="--folder-composer-space: {folderReadOnly || folderSection !== 'chats'
? 0
: composerHeight}px"
>
<FolderPlaceholder
folder={$selectedFolder}
+53 -28
View File
@@ -37,7 +37,7 @@
chatTabRequest,
showSidebar,
mobile,
showCallOverlay,
voiceCall,
showEmbeds,
settings,
showFileNav,
@@ -159,8 +159,12 @@
export let mainChatGroupId = '';
let paneCanvas: HTMLDivElement;
export let title = '';
export let mainTabFolder: { id: string; name: string; icon?: string | null; canEdit?: boolean } | null =
null;
export let mainTabFolder: {
id: string;
name: string;
icon?: string | null;
canEdit?: boolean;
} | null = null;
/** Double-clicking the folder tab renames the folder inline. */
export let onRenameFolder: ((folderId: string, name: string) => Promise<void>) | null = null;
let isRenamingFolder = false;
@@ -419,11 +423,7 @@
void attachChatViewTo(id).catch(() => {});
else void restoreChatView(id);
}
const persistPanels = (
nextTabs: typeof tabs,
terminalId: string | null,
ready: boolean
) => {
const persistPanels = (nextTabs: typeof tabs, terminalId: string | null, ready: boolean) => {
if (!ready || !viewEntry || chatLoading || viewEntry.promoting) return;
// The Files tab follows the terminal picked for the chat and starts over there.
if (terminalId && terminalId !== viewEntry.state.selectedTerminalId) {
@@ -474,7 +474,8 @@
}
dirtyFiles = { ...dirtyFiles };
};
$: if (isMounted && viewReady) forgetDraftsForUnreachableTerminals($terminalServers, $settings, $config, $user);
$: if (isMounted && viewReady)
forgetDraftsForUnreachableTerminals($terminalServers, $settings, $config, $user);
const resolveTabConnection = (tab: Tab) => {
if (!tab.terminalId || !isTerminalReachable(tab.terminalId)) return null;
const target = resolveTerminalTarget(
@@ -817,7 +818,9 @@
target: { ...selectedConnection },
untitled: true,
context:
activeFileContext?.terminalId === selectedConnection.selector ? activeFileContext : undefined
activeFileContext?.terminalId === selectedConnection.selector
? activeFileContext
: undefined
});
};
/** Opens the artifacts tab of the chat in `sourceTabId` beside that chat. */
@@ -1083,7 +1086,11 @@
const openDesktop = () => {
if (!selectedConnection) return askForTerminal(openDesktop);
openPanel({
id: JSON.stringify(['desktop', selectedConnection.baseUrl, selectedConnection.context.modelId]),
id: JSON.stringify([
'desktop',
selectedConnection.baseUrl,
selectedConnection.context.modelId
]),
kind: 'desktop',
label: $i18n.t('Desktop'),
terminalId: selectedConnection.selector,
@@ -1173,7 +1180,7 @@
}
if (tab.kind === 'voice') {
bridge?.end();
showCallOverlay.set(false);
voiceCall.set(false);
}
if (tab.kind === 'preview') showEmbeds.set(false);
chatView.drafts.delete(id);
@@ -1194,7 +1201,10 @@
delete chatArtifacts[id];
delete artifactSelections[`artifacts:${id}`];
}
if (!tabs.tabs.length || (!isLargeScreen && tabs.tabs.every((tab) => tab.id === mainChatTabId)))
if (
!tabs.tabs.length ||
(!isLargeScreen && tabs.tabs.every((tab) => tab.id === mainChatTabId))
)
showTabs.set(false);
await tick();
if (chatView === viewEntry) document.getElementById(toTabDomId(tabs.activeId))?.focus();
@@ -1418,7 +1428,7 @@
},
{ kind: 'artifacts', label: $i18n.t('Artifacts'), available: showArtifactsTab },
{ kind: 'preview', label: $i18n.t('Preview'), available: showPreviewTab },
{ kind: 'voice', label: $i18n.t('Voice'), available: !!bridge && $showCallOverlay },
{ kind: 'voice', label: $i18n.t('Voice'), available: !!bridge && $voiceCall },
{ kind: 'comments', label: $i18n.t('Comments'), available: showCommentsTab }
];
@@ -1426,7 +1436,11 @@
(view) => view.kind !== 'files' && view.kind !== 'voice' && view.available
);
$: canOpenNewTab =
showFilesTab || supportsTerminalFiles || canSelectTerminal || newTabViews.length > 0 || hasMessages;
showFilesTab ||
supportsTerminalFiles ||
canSelectTerminal ||
newTabViews.length > 0 ||
hasMessages;
const splitWithSuggestedTab = () => {
if (tabs.tabs.length < 2) {
@@ -1479,13 +1493,16 @@
if (showCommentsTab) action = () => openFeatureTab('comments');
break;
case Shortcut.NEW_FILE:
if ((supportsTerminalFiles && selectedConnection) || canSelectTerminal) action = openNewFileTab;
if ((supportsTerminalFiles && selectedConnection) || canSelectTerminal)
action = openNewFileTab;
break;
case Shortcut.NEW_TERMINAL:
if ((supportsTerminal && selectedConnection) || canSelectTerminal) action = openNewTerminalTab;
if ((supportsTerminal && selectedConnection) || canSelectTerminal)
action = openNewTerminalTab;
break;
case Shortcut.NEW_BROWSER:
if ((supportsBrowser && selectedConnection) || canSelectTerminal) action = () => openBrowser();
if ((supportsBrowser && selectedConnection) || canSelectTerminal)
action = () => openBrowser();
break;
case Shortcut.CLOSE_TAB:
if (panelVisible && tabs.activeId)
@@ -1612,8 +1629,7 @@
else if (!options.length && !canOpenChat) showTabs.set(false);
hasExtraTabs = true;
}
$: if (!canOpenChatTab && $chatTabRequest?.parentChatId === chatId)
chatTabRequest.set(null);
$: if (!canOpenChatTab && $chatTabRequest?.parentChatId === chatId) chatTabRequest.set(null);
$: if (viewReady && $showTabs === 'chat') {
if (canOpenChatTab) openFeatureTab('chat', true);
else chatTabRequest.set(null);
@@ -1631,8 +1647,8 @@
openFeatureTab('preview');
showEmbeds.set(false);
}
$: if (viewReady && $showCallOverlay) openFeatureTab('voice');
$: if (viewReady && !$showCallOverlay && tabs.tabs.some((tab) => tab.kind === 'voice'))
$: if (viewReady && $voiceCall) openFeatureTab('voice');
$: if (viewReady && !$voiceCall && tabs.tabs.some((tab) => tab.kind === 'voice'))
closeTab('voice');
$: if (viewReady && $showTabs === 'voice') openFeatureTab('voice');
$: if (viewReady && $showFileNav) {
@@ -2031,7 +2047,9 @@
overlay={isDragging}
artifacts={getArtifactsStore(tab.sourceTabId)}
selection={artifactSelections[tab.id] ?? null}
chatId={(source?.id !== mainChatTabId && source?.kind === 'chat' ? source.chatId : chatView.chatId) ?? ''}
chatId={(source?.id !== mainChatTabId && source?.kind === 'chat'
? source.chatId
: chatView.chatId) ?? ''}
/>
{:else if tab.kind === 'overview'}
<Overview
@@ -2320,7 +2338,9 @@
{#each group.tabIds.map((id) => tabs.tabs.find((tab) => tab.id === id)!) as tab (tab.id)}
{@const titleEditor =
tab.id === mainChatTabId
? mainTabFolder ? undefined : tabTitleEditor
? mainTabFolder
? undefined
: tabTitleEditor
: chatTitleEditors[tab.id]}
{@const PageIcon =
tab.kind === 'page' ? pageIcons[tab.href?.split(/[/?#]/)[1] ?? ''] : null}
@@ -2343,7 +2363,9 @@
aria-controls={`${toTabDomId(tab.id)}-view`}
aria-selected={group.activeId === tab.id}
tabindex={group.activeId === tab.id ? 0 : -1}
title={tab.id === mainChatTabId ? mainTabTitle : (tab.directory ?? tab.path ?? tabLabel(tab))}
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={() => {
@@ -2366,7 +2388,10 @@
<Icon name={fileIconName(tab.label)} size={14} strokeWidth={1.4} />
{:else if tab.kind === 'terminal'}
<Icon
name={terminalIconName(terminalProcesses[tab.sessionId ?? ''] ?? '', tabLabel(tab))}
name={terminalIconName(
terminalProcesses[tab.sessionId ?? ''] ?? '',
tabLabel(tab)
)}
size={14}
/>
{:else if tab.kind === 'comments'}
@@ -2415,8 +2440,8 @@
{/if}
{@render tabActions?.()}
{:else if !titleEditor}{#if chatTabActions[tab.id]}<span class="-me-1 flex"
>{@render chatTabActions[tab.id]?.()}</span
>{/if}<button
>{@render chatTabActions[tab.id]?.()}</span
>{/if}<button
type="button"
class="flex items-center justify-center w-4 h-4 rounded text-gray-400 hover:bg-gray-200 hover:text-gray-700 dark:hover:bg-white/10 dark:hover:text-white"
title={[
+14
View File
@@ -0,0 +1,14 @@
import { getContext, setContext } from 'svelte';
import { chatId, models, temporaryChatEnabled, audioQueue } from '$lib/stores';
import type { ChatContext } from '$lib/types';
export const setChatContext = (context: ChatContext) => setContext('chat', context);
/** The enclosing chat's state, or the main chat's stores outside any chat. */
export const getChatContext = (): ChatContext =>
getContext<ChatContext | undefined>('chat') ?? {
chatId,
models,
temporary: temporaryChatEnabled,
audioQueue
};
@@ -4,7 +4,7 @@
import { toast } from 'svelte-sonner';
import { copyToClipboard } from '$lib/utils';
import { equalEditorJSON } from '$lib/utils/editorJson';
import { showCallOverlay, skills, terminalSkills } from '$lib/stores';
import { voiceCall, skills, terminalSkills } from '$lib/stores';
marked.use({
breaks: true,
@@ -425,7 +425,7 @@
export let floatingMenuPlacement = 'bottom-start';
// Keep focus off the chat input during a call so the call overlay's M shortcut works
$: suppressAutoFocus = messageInput && $showCallOverlay;
$: suppressAutoFocus = messageInput && $voiceCall;
let content = null;
let htmlValue = '';
@@ -1100,7 +1100,7 @@
],
content: provider ? undefined : content,
editable,
autofocus: messageInput && !$showCallOverlay,
autofocus: messageInput && !$voiceCall,
onTransaction: ({ transaction }) => {
if (!editor) return;
+2 -1
View File
@@ -178,7 +178,8 @@ export const showTabs = writable<
| (CommentTarget & { tab: 'comments'; comment_id?: string })
>(false);
export const showEmbeds = writable(false);
export const showCallOverlay = writable(false);
/** A voice call is open in the main chat's voice tab. */
export const voiceCall = writable(false);
export const showFileNav = writable<{
terminalId: string;
directory: string;
+12
View File
@@ -26,6 +26,18 @@ export type AppLayoutContext = {
initNewChat?: (preserveTabs?: boolean, keepDraft?: boolean) => Promise<void>;
};
/** State of the chat a component is rendered in, so a side chat doesn't read the main chat's. */
export type ChatContext = {
chatId: typeof import('$lib/stores').chatId;
models: typeof import('$lib/stores').models;
temporary: typeof import('$lib/stores').temporaryChatEnabled;
audioQueue: typeof import('$lib/stores').audioQueue;
contextCompactions?: import('svelte/store').Writable<
Record<string, 'in_progress' | { error: string }>
>;
submitPrompt?: (prompt: string) => void;
};
export type WorkspaceContext = {
workspaceActions: import('svelte/store').Writable<import('$lib/stores').WorkspaceAction[]>;
workspaceCounts: import('svelte/store').Writable<