This commit is contained in:
Timothy Jaeryang Baek committed 2026-06-06 09:05:29 +01:00
1 parent ddf6772b3a
commit d44ea99882
23 files changed
+1390 -333

No files matched your search

+9 -2
View File
@@ -44,12 +44,19 @@
/* Scrollbar - Open WebUI style */
::-webkit-scrollbar-thumb {
background-color: rgba(67, 67, 67, 0.6);
border-color: rgba(0, 0, 0, 1);
--tw-border-opacity: 1;
background-color: rgba(215, 215, 215, 0.6);
border-color: rgba(255, 255, 255, var(--tw-border-opacity));
border-radius: 9999px;
border-width: 1px;
}
/* Dark theme scrollbar styles */
.dark ::-webkit-scrollbar-thumb {
background-color: rgba(67, 67, 67, 0.6);
border-color: rgba(0, 0, 0, var(--tw-border-opacity));
}
::-webkit-scrollbar {
height: 0.45rem;
width: 0.45rem;
+13 -3
View File
@@ -40,8 +40,16 @@ export interface SendMessageResult {
// ── Queries ─────────────────────────────────────────────────
export const getChats = (workspace: string) =>
fetchJSON<{ chats: ChatInfo[] }>(`/api/chats?workspace=${encodeURIComponent(workspace)}`);
export const getChats = (
workspace: string,
limit = 50,
offset = 0,
sortBy: 'title' | 'updated_at' = 'updated_at',
sortDir: 'asc' | 'desc' = 'desc'
) =>
fetchJSON<{ chats: ChatInfo[]; total: number; has_more: boolean }>(
`/api/chats?workspace=${encodeURIComponent(workspace)}&limit=${limit}&offset=${offset}&sort_by=${sortBy}&sort_dir=${sortDir}`
);
export const getChat = (chatId: string) =>
fetchJSON<ChatDetail>(`/api/chats/${chatId}`);
@@ -58,7 +66,8 @@ export const sendMessage = (
chatId?: string,
parentId?: string | null,
params: { tool_approval_mode?: string } = {},
regenerationPrompt?: string
regenerationPrompt?: string,
files?: string[]
) =>
fetchJSON<SendMessageResult>(
'/api/chats',
@@ -69,6 +78,7 @@ export const sendMessage = (
chat_id: chatId,
parent_id: parentId ?? null,
regeneration_prompt: regenerationPrompt,
files: files ?? [],
params
})
);
@@ -350,7 +350,7 @@
data-index={i}
class="flex items-center gap-2 w-full h-7 px-2 rounded-lg text-left transition-colors duration-75
{i === selectedIndex
? 'bg-gray-100 text-gray-900 dark:bg-white/6 dark:text-white'
? 'bg-gray-200/50 text-gray-900 dark:bg-white/6 dark:text-white'
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
onclick={() => navigateTo(dir.name)}
ondblclick={(e) => { e.stopPropagation(); const fullPath = currentPath === '/' ? `/${dir.name}` : `${currentPath}/${dir.name}`; addWorkspace(fullPath); goto(`/?workspace=${encodeURIComponent(fullPath)}`); onclose(); }}
@@ -9,6 +9,7 @@
import { systemEvents } from '$lib/stores/systemEvents.svelte';
import { tooltip } from '$lib/tooltip';
import { listDir, downloadArchive, deleteFiles, moveFile, uploadFiles as apiUpload, createEntry } from '$lib/apis/files';
import { fileIconName } from '$lib/utils/fileIcon';
import Icon from './Icon.svelte';
import DropdownMenu from './DropdownMenu.svelte';
import { t } from '$lib/i18n';
@@ -269,30 +270,7 @@
setFileBrowserCwd(path);
}
function fileIconName(entry: FileEntry): string {
if (entry.type === 'directory') return 'folder';
const ext = entry.name.split('.').pop()?.toLowerCase() ?? '';
if (entry.name === 'Dockerfile') return 'docker';
if (entry.name === 'LICENSE' || entry.name === 'LICENSE.md') return 'page-text';
if (entry.name.endsWith('.lock')) return 'lock';
switch (ext) {
case 'md': return 'page-text';
case 'ts': case 'tsx': case 'js': case 'jsx':
case 'py': case 'rs': case 'go': case 'java':
case 'c': case 'cpp': case 'h': case 'hpp':
case 'rb': case 'php': case 'swift': case 'kt':
case 'svelte': case 'vue':
return 'code';
case 'json': case 'yaml': case 'yml': case 'toml':
case 'ini': case 'cfg': case 'conf':
return 'settings';
case 'sh': case 'bash': case 'zsh':
return 'terminal';
case 'css': case 'html': case 'xml':
return 'code';
default: return 'empty-page';
}
}
// fileIconName imported from $lib/utils/fileIcon
function formatSize(bytes: number | null): string {
if (bytes === null || bytes === undefined) return '';
@@ -755,7 +733,7 @@
{#if renamingEntry === entry.path}
<!-- Inline rename -->
<div class="flex items-center gap-2 h-7" style="padding-left: {8 + entry.depth * 16}px; padding-right: 8px;">
<Icon name={fileIconName(entry)} size={14} class="text-gray-400 shrink-0" />
<Icon name={fileIconName(entry.name, entry.type)} size={14} class="text-gray-400 shrink-0" />
<input
type="text"
class="flex-1 border-none outline-none bg-transparent text-xs text-gray-900 dark:text-white"
@@ -789,7 +767,7 @@
<span class="w-4 shrink-0"></span>
{/if}
<span class="flex items-center justify-center w-4 shrink-0 {entry.type === 'directory' ? 'text-gray-500 dark:text-gray-400' : 'text-gray-400 dark:text-gray-500'}">
<Icon name={fileIconName(entry)} size={14} strokeWidth={1.4} />
<Icon name={fileIconName(entry.name, entry.type)} size={14} strokeWidth={1.4} />
</span>
{#if entry.type === 'directory'}
<!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -424,12 +424,12 @@
<!-- Tabs (always visible) -->
<button
class="px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors duration-75
{view === 'changes' ? 'bg-gray-100 dark:bg-white/8 text-gray-900 dark:text-white' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
{view === 'changes' ? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
onclick={() => switchView('changes')}
>Changes{#if totalChanges > 0}<span class="ml-1 text-gray-400 dark:text-gray-500">{totalChanges}</span>{/if}</button>
<button
class="px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors duration-75
{view === 'history' ? 'bg-gray-100 dark:bg-white/8 text-gray-900 dark:text-white' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
{view === 'history' ? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white' : 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
onclick={() => switchView('history')}
>{$t('git.history')}</button>
@@ -253,7 +253,7 @@
<button
class="flex items-center gap-1.5 px-2.5 h-7 rounded-lg text-xs font-medium whitespace-nowrap shrink-0 transition-all duration-100
{isActive
? 'bg-gray-200 text-gray-900 dark:bg-white/8 dark:text-white'
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
data-tab-id={tab.id}
onclick={() => handleTabClick(tab)}
@@ -271,7 +271,7 @@
{#if !tab.permanent}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<span
class="flex items-center justify-center w-4 h-4 rounded text-gray-400 hover:bg-gray-300 hover:text-gray-700 dark:hover:bg-white/10 dark:hover:text-white"
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"
onclick={(e) => handleClose(e, tab.id)}
onkeydown={(e) => { if (e.key === 'Enter') handleClose(e, tab.id); }}
role="button"
@@ -305,7 +305,7 @@
bind:this={splitBtnEl}
class="flex items-center justify-center w-7 h-7 rounded-lg transition-colors duration-100 shrink-0
{$splitActive
? 'bg-gray-200 text-gray-900 dark:bg-white/8 dark:text-white'
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
: 'text-gray-400 hover:text-gray-600 dark:hover:text-gray-300'}"
onclick={() => showSplitMenu = !showSplitMenu}
aria-label="Split Editor"
@@ -182,7 +182,7 @@
data-index={i}
class="flex items-center gap-2 w-full h-7 px-2 rounded-lg text-left transition-colors duration-75
{i === selectedIndex
? 'bg-gray-100 text-gray-900 dark:bg-white/6 dark:text-white'
? 'bg-gray-200/50 text-gray-900 dark:bg-white/6 dark:text-white'
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
onclick={() => navigateTo(dir.name)}
onmouseenter={() => { selectedIndex = i; }}
@@ -20,7 +20,7 @@
] as opt}
<button
class="flex items-center gap-1.5 h-7 px-2.5 rounded-lg text-xs transition-colors duration-100
{$theme === opt.value ? 'bg-gray-100 dark:bg-white/8 text-gray-900 dark:text-white font-medium' : 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
{$theme === opt.value ? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white font-medium' : 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
onclick={() => setTheme(opt.value)}
>
<Icon name={opt.icon} size={13} />
@@ -48,7 +48,7 @@
] as opt}
<button
class="flex items-center gap-1.5 h-7 px-2.5 rounded-lg text-xs transition-colors duration-100
{$streamingBehavior === opt.value ? 'bg-gray-100 dark:bg-white/8 text-gray-900 dark:text-white font-medium' : 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
{$streamingBehavior === opt.value ? 'bg-gray-200/50 dark:bg-white/8 text-gray-900 dark:text-white font-medium' : 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
onclick={() => streamingBehavior.set(opt.value)}
>
{opt.label}
@@ -7,6 +7,7 @@
removeWorkspace,
reorderWorkspaces,
sidebarOpen,
sidebarWidth,
} from '$lib/stores';
import Sortable from 'sortablejs';
import Icon from './Icon.svelte';
@@ -33,6 +34,38 @@
let wsListEl: HTMLDivElement | undefined = $state();
let sortable: Sortable | null = null;
const MIN_WIDTH = 160;
const MAX_WIDTH = 400;
let isResizing = $state(false);
function startResize(e: PointerEvent) {
// Only allow resize on md+ screens
if (typeof window !== 'undefined' && window.innerWidth < 768) return;
e.preventDefault();
isResizing = true;
const startX = e.clientX;
const startWidth = $sidebarWidth;
function onMove(ev: PointerEvent) {
const delta = ev.clientX - startX;
const newWidth = Math.round(Math.min(MAX_WIDTH, Math.max(MIN_WIDTH, startWidth + delta)));
sidebarWidth.set(newWidth);
}
function onUp() {
isResizing = false;
window.removeEventListener('pointermove', onMove);
window.removeEventListener('pointerup', onUp);
document.body.style.cursor = '';
document.body.style.userSelect = '';
}
window.addEventListener('pointermove', onMove);
window.addEventListener('pointerup', onUp);
document.body.style.cursor = 'col-resize';
document.body.style.userSelect = 'none';
}
// Current workspace path from URL
const currentPath = $derived($page.url.searchParams.get('workspace'));
@@ -113,7 +146,16 @@
{#if $sidebarOpen}
<button class="fixed inset-0 bg-black/50 z-40 cursor-default md:hidden" onclick={closeSidebar} aria-label={$t('sidebar.closeSidebar')}></button>
<aside class="sidebar">
<aside class="sidebar" style="--sw: {$sidebarWidth}px;">
<!-- Resize handle (md+ only) -->
<div
class="resize-handle"
class:active={isResizing}
role="separator"
aria-orientation="vertical"
onpointerdown={startResize}
ondblclick={() => sidebarWidth.set(220)}
></div>
<!-- Logo header with collapse button -->
<div class="flex items-center justify-between h-9 pl-3.5 pr-1.5 shrink-0 border-b border-gray-200 dark:border-white/6">
<a
@@ -151,14 +193,14 @@
href="/?workspace={encodeURIComponent(ws.path)}"
class="group flex items-center gap-1.5 w-full h-7 px-2 rounded-lg text-xs font-medium transition-colors duration-100 no-underline
{ws.path === currentPath
? 'bg-gray-200 text-gray-900 dark:bg-white/8 dark:text-white'
? 'bg-gray-200/50 text-gray-900 dark:bg-white/8 dark:text-white'
: 'text-gray-500 hover:text-gray-700 dark:hover:text-gray-300'}"
onclick={(e) => handleWorkspaceClick(e, ws.path)}
>
<Icon name="folder" size={14} />
<span class="flex-1 text-left overflow-hidden text-ellipsis whitespace-nowrap">{ws.name}</span>
<span
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-400 opacity-0 group-hover:opacity-100 hover:bg-gray-300 dark:hover:bg-white/10 transition-all duration-75"
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-400 opacity-0 group-hover:opacity-100 hover:bg-gray-200 dark:hover:bg-white/10 transition-all duration-75"
role="button"
tabindex="-1"
onclick={(e) => openWsMenu(e, ws.path)}
@@ -261,6 +303,30 @@
.sidebar {
position: relative;
z-index: auto;
width: var(--sw, 220px);
}
}
.resize-handle {
display: none;
}
@media (min-width: 768px) {
.resize-handle {
display: block;
position: absolute;
right: -3px;
top: 0;
bottom: 0;
width: 6px;
cursor: col-resize;
z-index: 10;
transition: background 0.15s;
}
.resize-handle:hover,
.resize-handle.active {
background: rgba(150, 150, 150, 0.12);
}
}
</style>
@@ -1,12 +1,41 @@
<script lang="ts">
import type { ChatInfo } from '$lib/apis/chat';
import DropdownMenu from '../DropdownMenu.svelte';
interface Props {
chats: ChatInfo[];
onopen: (id: string) => void;
ondelete: (id: string) => void;
hasMore?: boolean;
onloadmore?: () => void;
sortBy?: 'title' | 'updated_at';
sortDir?: 'asc' | 'desc';
onsort?: (field: 'title' | 'updated_at') => void;
}
let {
chats,
onopen,
ondelete,
hasMore = false,
onloadmore,
sortBy = 'updated_at',
sortDir = 'desc',
onsort,
}: Props = $props();
let menuChatId = $state<string | null>(null);
let menuAnchor = $state<HTMLElement | null>(null);
function openMenu(e: MouseEvent, chatId: string) {
e.stopPropagation();
menuChatId = chatId;
menuAnchor = e.currentTarget as HTMLElement;
}
function closeMenu() {
menuChatId = null;
menuAnchor = null;
}
let { chats, onopen, ondelete }: Props = $props();
function formatTime(ts: number): string {
const d = new Date(ts);
@@ -20,8 +49,56 @@
}
</script>
{#snippet chevronUp()}
<svg class="w-2 h-2" viewBox="0 0 10 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M1 5L5 1L9 5" />
</svg>
{/snippet}
{#snippet chevronDown()}
<svg class="w-2 h-2" viewBox="0 0 10 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M1 1L5 5L9 1" />
</svg>
{/snippet}
{#if chats.length > 0}
<div class="w-full mt-4 pt-2">
<!-- Sort header -->
{#if onsort}
<div class="flex items-center text-[10px] font-medium text-gray-400 dark:text-gray-600 mb-1 px-2 select-none">
<button
class="flex-1 flex items-center gap-1 hover:text-gray-600 dark:hover:text-gray-400 transition-colors"
onclick={() => onsort?.('title')}
>
Title
{#if sortBy === 'title'}
{#if sortDir === 'asc'}
{@render chevronUp()}
{:else}
{@render chevronDown()}
{/if}
{:else}
<span class="invisible">{@render chevronUp()}</span>
{/if}
</button>
<button
class="shrink-0 flex items-center gap-1 hover:text-gray-600 dark:hover:text-gray-400 transition-colors"
onclick={() => onsort?.('updated_at')}
>
Updated
{#if sortBy === 'updated_at'}
{#if sortDir === 'asc'}
{@render chevronUp()}
{:else}
{@render chevronDown()}
{/if}
{:else}
<span class="invisible">{@render chevronUp()}</span>
{/if}
</button>
</div>
{/if}
{#each chats as chat (chat.id)}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div
@@ -31,21 +108,39 @@
onclick={() => onopen(chat.id)}
onkeydown={(e) => { if (e.key === 'Enter') onopen(chat.id); }}
>
<svg class="w-3.5 h-3.5 shrink-0 text-gray-300 dark:text-gray-700" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />
</svg>
<span class="flex-1 text-xs text-gray-500 dark:text-gray-500 truncate">{chat.title}</span>
<span class="text-[10px] text-gray-300 dark:text-gray-700 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity duration-75">{formatTime(chat.updated_at)}</span>
<span class="text-[10px] text-gray-300 dark:text-gray-700 shrink-0">{formatTime(chat.updated_at)}</span>
<button
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-300 dark:text-gray-700 opacity-0 group-hover:opacity-100 hover:text-red-400 dark:hover:text-red-400 transition-all duration-75"
onclick={(e) => { e.stopPropagation(); ondelete(chat.id); }}
aria-label="Delete chat"
class="flex items-center justify-center w-5 h-5 rounded shrink-0 text-gray-300 dark:text-gray-700 hover:text-gray-500 dark:hover:text-gray-400 transition-all duration-75"
onclick={(e) => openMenu(e, chat.id)}
aria-label="Chat options"
>
<svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
<svg width="11" height="11" viewBox="0 0 16 16" fill="currentColor">
<circle cx="3" cy="8" r="1.5" />
<circle cx="8" cy="8" r="1.5" />
<circle cx="13" cy="8" r="1.5" />
</svg>
</button>
</div>
{/each}
{#if hasMore && onloadmore}
<button
class="w-full h-7 mt-1 text-[11px] text-gray-400 dark:text-gray-600 hover:text-gray-600 dark:hover:text-gray-400 transition-colors duration-75"
onclick={onloadmore}
>
Show more
</button>
{/if}
</div>
{/if}
{#if menuChatId && menuAnchor}
<DropdownMenu
anchor={menuAnchor}
align="end"
items={[
{ label: 'Delete', icon: 'trash', onclick: () => { if (menuChatId) ondelete(menuChatId); } },
]}
onclose={closeMenu}
/>
{/if}
@@ -1,5 +1,6 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { mount, unmount } from 'svelte';
import { Editor } from '@tiptap/core';
import StarterKit from '@tiptap/starter-kit';
import { Markdown } from '@tiptap/markdown';
@@ -7,6 +8,9 @@
import CodeBlockLowlight from '@tiptap/extension-code-block-lowlight';
import { all, createLowlight } from 'lowlight';
import { createFileMention, extractMentionedFiles, type FileMentionAttrs } from './FileMention';
import FileSuggestionPopup from './FileSuggestionPopup.svelte';
import { searchFiles } from '$lib/apis/files';
import ModelSelector from './ModelSelector.svelte';
import SendButton from './SendButton.svelte';
import PlusMenu from './PlusMenu.svelte';
@@ -18,6 +22,7 @@
selectedModel: string;
sending: boolean;
streaming?: boolean;
workspace?: string;
placeholder?: string;
queuedMessages?: { id: string; content: string }[];
onsend: () => void;
@@ -31,6 +36,7 @@
selectedModel = $bindable(),
sending,
streaming = false,
workspace = '',
placeholder = 'Message...',
queuedMessages = [],
onsend,
@@ -51,10 +57,128 @@
return _origHighlight(lang, value, opts);
};
// ── @file mention suggestion ────────────────────
let popupEl: HTMLDivElement | null = null;
let popupComponent: Record<string, any> | null = null;
async function fetchSuggestions({ query }: { query: string }): Promise<FileMentionAttrs[]> {
if (!workspace) return [];
try {
const data = await searchFiles(query || '', workspace);
const results = (data as any).results ?? [];
return results.slice(0, 10).map((r: any) => ({
id: r.path,
label: r.name,
type: r.type === 'directory' ? 'directory' : 'file',
}));
} catch {
return [];
}
}
function mountPopup(items: FileMentionAttrs[], selectedIdx: number, onselect: (i: number) => void) {
// Destroy previous instance
if (popupComponent) {
try { unmount(popupComponent); } catch {}
popupComponent = null;
}
if (!popupEl) {
popupEl = document.createElement('div');
document.body.appendChild(popupEl);
}
popupComponent = mount(FileSuggestionPopup, {
target: popupEl,
props: { items, selectedIndex: selectedIdx, onselect },
});
}
function createSuggestionRenderer() {
let selectedIndex = 0;
let currentItems: FileMentionAttrs[] = [];
let command: ((attrs: FileMentionAttrs) => void) | null = null;
function doSelect(index: number) {
const item = currentItems[index];
if (item && command) command(item);
}
function remount() {
mountPopup(currentItems, selectedIndex, doSelect);
}
return {
onStart(props: any) {
command = props.command;
currentItems = props.items;
selectedIndex = 0;
remount();
updatePopupPosition(props.clientRect?.());
},
onUpdate(props: any) {
command = props.command;
currentItems = props.items;
selectedIndex = 0;
remount();
updatePopupPosition(props.clientRect?.());
},
onKeyDown({ event }: { event: KeyboardEvent }) {
if (event.key === 'ArrowDown') {
selectedIndex = (selectedIndex + 1) % Math.max(currentItems.length, 1);
remount();
return true;
}
if (event.key === 'ArrowUp') {
selectedIndex = (selectedIndex - 1 + currentItems.length) % Math.max(currentItems.length, 1);
remount();
return true;
}
if (event.key === 'Enter') {
const item = currentItems[selectedIndex];
if (item && command) command(item);
return true;
}
if (event.key === 'Escape') {
destroyPopup();
return true;
}
return false;
},
onExit() {
destroyPopup();
},
};
}
function updatePopupPosition(rect: DOMRect | null) {
if (!popupEl || !rect) return;
const child = popupEl.firstElementChild as HTMLElement | null;
if (!child) return;
const popupHeight = child.offsetHeight || 200;
child.style.position = 'fixed';
child.style.left = `${Math.max(8, Math.min(rect.left, window.innerWidth - 320))}px`;
child.style.top = `${rect.top - popupHeight - 8}px`;
}
function destroyPopup() {
if (popupComponent) {
try { unmount(popupComponent); } catch {}
popupComponent = null;
}
if (popupEl) {
popupEl.remove();
popupEl = null;
}
}
// ── Editor lifecycle ────────────────────────────
onMount(() => {
if (!editorEl) return;
const fileMention = createFileMention({
items: fetchSuggestions,
render: createSuggestionRenderer,
});
editor = new Editor({
element: editorEl,
extensions: [
@@ -65,6 +189,7 @@
Markdown,
Placeholder.configure({ placeholder }),
CodeBlockLowlight.configure({ lowlight }),
fileMention,
],
content: inputText || '',
contentType: inputText ? 'markdown' : undefined,
@@ -76,6 +201,8 @@
},
handleKeyDown: (view, event) => {
if (event.key === 'Enter' && !event.shiftKey) {
// Don't send while suggestion popup is open — let it confirm selection
if (popupComponent) return false;
const { state } = view;
const head = state.selection.$head;
@@ -103,6 +230,7 @@
});
onDestroy(() => {
destroyPopup();
editor?.destroy();
editor = null;
});
@@ -128,6 +256,12 @@
// TipTap auto-sizes; no-op kept for API compat
}
/** Get file paths from @mentions in the current editor content. */
export function getFiles(): string[] {
if (!editor) return [];
return extractMentionedFiles(editor.getJSON());
}
// Allow sending during streaming (message will be enqueued server-side)
const canSend = $derived(inputText.trim() && selectedModel && !sending);
</script>
@@ -212,15 +212,42 @@
}
}
const CHATS_PAGE_SIZE = 50;
let hasMoreChats = $state(false);
let chatSortBy = $state<'title' | 'updated_at'>('updated_at');
let chatSortDir = $state<'asc' | 'desc'>('desc');
async function loadPreviousChats() {
try {
const data = await getChats(workspace);
const data = await getChats(workspace, CHATS_PAGE_SIZE, 0, chatSortBy, chatSortDir);
previousChats = data.chats || [];
hasMoreChats = data.has_more;
} catch {
previousChats = [];
hasMoreChats = false;
}
}
async function loadMoreChats() {
try {
const data = await getChats(workspace, CHATS_PAGE_SIZE, previousChats.length, chatSortBy, chatSortDir);
previousChats = [...previousChats, ...(data.chats || [])];
hasMoreChats = data.has_more;
} catch {
hasMoreChats = false;
}
}
function handleSort(field: 'title' | 'updated_at') {
if (chatSortBy === field) {
chatSortDir = chatSortDir === 'asc' ? 'desc' : 'asc';
} else {
chatSortBy = field;
chatSortDir = field === 'title' ? 'asc' : 'desc';
}
loadPreviousChats();
}
async function openChat(id: string) {
await loadChat(id);
const chat = previousChats.find((c) => c.id === id);
@@ -400,10 +427,16 @@
// ── Actions ─────────────────────────────────────────────────
async function send() {
const text = inputText.trim();
let text = inputText.trim();
if (!text || !selectedModel) return;
if (sending) return;
sending = true;
const files = chatInputEl?.getFiles() ?? [];
// Transform TipTap mention format to markdown file links
text = text.replace(
/\[@\s+id="([^"]+)"\s+label="([^"]+)"\]/g,
(_: string, id: string, label: string) => `[${label}](file://${id})`
);
inputText = '';
autoScroll = true;
await tick();
@@ -428,7 +461,7 @@
} else {
try {
const mode = get(toolApprovalMode);
const result = await apiSendMessage(text, selectedModel, workspace, chatId, parentId, { tool_approval_mode: mode });
const result = await apiSendMessage(text, selectedModel, workspace, chatId, parentId, { tool_approval_mode: mode }, undefined, files);
if (result.queued) {
// Add directly to allMessages so it appears in queue UI instantly
allMessages = [...allMessages, {
@@ -480,7 +513,7 @@
try {
const mode = get(toolApprovalMode);
const result = await apiSendMessage(text, selectedModel, workspace, chatId ?? undefined, parentId, { tool_approval_mode: mode });
const result = await apiSendMessage(text, selectedModel, workspace, chatId ?? undefined, parentId, { tool_approval_mode: mode }, undefined, files);
await loadChat(result.chat_id);
if (isNew && tabId) {
updateTab(tabId, result.chat_id, text.slice(0, 40) || 'Chat');
@@ -700,8 +733,8 @@
<div class="flex flex-col h-full bg-white dark:bg-black">
{#if isLanding}
<!-- Landing: input + recent chats -->
<div class="flex-1 overflow-y-auto">
<div class="max-w-xl mx-auto px-4 flex flex-col" style="padding-top: max(14vh, 48px);">
<div class="flex-1 overflow-y-auto flex items-center justify-center">
<div class="max-w-xl w-full mx-auto px-4 flex flex-col pb-[5vh]">
<!-- Greeting -->
<div class="mb-8 text-center">
<h1 class="text-lg font-normal text-gray-800 dark:text-gray-200 tracking-tight">
@@ -714,6 +747,7 @@
bind:inputText
bind:selectedModel
{sending}
{workspace}
placeholder="Ask anything about {workspaceName}..."
onsend={send}
{queuedMessages}
@@ -721,7 +755,7 @@
onqueueedit={handleQueueEdit}
onqueuedelete={handleQueueDelete}
/>
<ChatHistory chats={previousChats} onopen={openChat} ondelete={deleteChat} />
<ChatHistory chats={previousChats} onopen={openChat} ondelete={deleteChat} hasMore={hasMoreChats} onloadmore={loadMoreChats} sortBy={chatSortBy} sortDir={chatSortDir} onsort={handleSort} />
</div>
</div>
{:else}
@@ -791,6 +825,7 @@
bind:selectedModel
{sending}
{streaming}
{workspace}
onsend={send}
oncancel={handleCancel}
{queuedMessages}
@@ -0,0 +1,65 @@
/**
* TipTap Mention extension configured for @file mentions.
*
* Wraps @tiptap/extension-mention with file-specific rendering
* and suggestion config wired to the workspace file search API.
*/
import Mention from '@tiptap/extension-mention';
export interface FileMentionAttrs {
id: string; // full file path
label: string; // display name (basename)
type: string; // 'file' | 'directory'
}
/**
* Create the configured Mention extension.
* `suggestionOptions` is passed in from the component that owns
* the lifecycle of the suggestion popup.
*/
export function createFileMention(suggestionOptions: {
items: (props: { query: string }) => Promise<FileMentionAttrs[]> | FileMentionAttrs[];
render: () => {
onStart: (props: any) => void;
onUpdate: (props: any) => void;
onKeyDown: (props: any) => boolean;
onExit: () => void;
};
}) {
return Mention.configure({
HTMLAttributes: {
class: 'bg-blue-500/10 text-blue-400 rounded px-1 py-px text-xs font-mono',
},
renderText({ node }) {
const label = node.attrs.label ?? node.attrs.id;
return `[${label}](file://${node.attrs.id})`;
},
suggestion: {
char: '@',
allowSpaces: false,
...suggestionOptions,
},
});
}
/**
* Extract all file mention paths from a TipTap editor JSON doc.
*/
export function extractMentionedFiles(doc: any): string[] {
const files: string[] = [];
function walk(node: any) {
if (node.type === 'mention' && node.attrs?.id) {
files.push(node.attrs.id);
}
if (node.content) {
for (const child of node.content) {
walk(child);
}
}
}
if (doc) walk(doc);
return [...new Set(files)];
}
@@ -0,0 +1,67 @@
<script lang="ts">
import Icon from '../Icon.svelte';
import { fileIconName } from '$lib/utils/fileIcon';
interface SuggestionItem {
id: string;
label: string;
type: string;
}
interface Props {
items: SuggestionItem[];
selectedIndex: number;
onselect: (index: number) => void;
}
let { items, selectedIndex, onselect }: Props = $props();
let listEl: HTMLDivElement | undefined = $state();
// Scroll selected item into view
$effect(() => {
if (listEl && selectedIndex >= 0) {
const el = listEl.children[selectedIndex] as HTMLElement | undefined;
el?.scrollIntoView({ block: 'nearest' });
}
});
function relativePath(fullPath: string): string {
// Show last 2 path segments as context
const parts = fullPath.split('/');
if (parts.length <= 2) return '';
return parts.slice(-3, -1).join('/');
}
</script>
<div
class="fixed z-[200] w-56 max-h-40 overflow-y-auto rounded-xl bg-white dark:bg-[#1a1a1a] border border-gray-150 dark:border-white/6 shadow-xl p-0.5"
>
{#if items.length === 0}
<div class="px-3 py-2 text-xs text-gray-400 dark:text-gray-600">No files found</div>
{:else}
<div class="text-[10px] font-medium text-gray-400 dark:text-gray-600 px-2.5 pt-1.5 pb-0.5">Files</div>
<div bind:this={listEl}>
{#each items as item, i (item.id)}
<!-- svelte-ignore a11y_no_static_element_interactions -->
<button
class="flex items-center gap-2 w-full px-2.5 py-1.5 rounded-lg text-left transition-colors duration-75
{i === selectedIndex
? 'bg-gray-50 dark:bg-white/8 text-gray-900 dark:text-white'
: 'text-gray-600 dark:text-gray-400 hover:bg-gray-50 dark:hover:bg-white/4'}"
onmousedown={(e) => { e.preventDefault(); onselect(i); }}
onmouseenter={() => selectedIndex = i}
>
<span class="flex items-center justify-center w-4 shrink-0 {item.type === 'directory' ? 'text-gray-500 dark:text-gray-400' : 'text-gray-400 dark:text-gray-500'}">
<Icon name={fileIconName(item.label, item.type)} size={12} />
</span>
<span class="flex-1 min-w-0 flex items-baseline gap-1.5 overflow-hidden">
<span class="text-xs font-medium truncate text-gray-900 dark:text-gray-200">{item.label}</span>
{#if relativePath(item.id)}
<span class="text-[10px] text-gray-400 dark:text-gray-600 truncate shrink-0">{relativePath(item.id)}</span>
{/if}
</span>
</button>
{/each}
</div>
{/if}
</div>
@@ -1,5 +1,7 @@
<script lang="ts">
import { tick } from 'svelte';
import Icon from '../Icon.svelte';
import { fileIconName } from '$lib/utils/fileIcon';
interface Props {
content: string;
@@ -10,6 +12,29 @@
}
let { content, siblingIndex = 0, siblingTotal = 1, onedit, onnavigate }: Props = $props();
type Segment = { type: 'text'; value: string } | { type: 'file'; label: string; path: string };
// Matches both [label](file://path) and TipTap's [@ id="path" label="name"]
const FILE_LINK_RE = /\[([^\]]+)\]\(file:\/\/([^)]+)\)/g;
const TIPTAP_MENTION_RE = /\[@\s+id="([^"]+)"\s+label="([^"]+)"\]/g;
const parsedContent: Segment[] = $derived.by(() => {
// Normalize TipTap format to markdown links first
const normalized = content.replace(
TIPTAP_MENTION_RE,
(_: string, id: string, label: string) => `[${label}](file://${id})`
);
const segments: Segment[] = [];
let last = 0;
for (const m of normalized.matchAll(FILE_LINK_RE)) {
if (m.index > last) segments.push({ type: 'text', value: normalized.slice(last, m.index) });
segments.push({ type: 'file', label: m[1], path: m[2] });
last = m.index + m[0].length;
}
if (last < normalized.length) segments.push({ type: 'text', value: normalized.slice(last) });
return segments.length ? segments : [{ type: 'text' as const, value: content }];
});
let edit = $state(false);
let editedContent = $state('');
let copied = $state(false);
@@ -99,7 +124,7 @@
<!-- Bubble: right-aligned -->
<div class="flex justify-end">
<div class="max-w-[90%] px-4 py-2 rounded-3xl bg-gray-50 dark:bg-white/[0.06]">
<div class="text-[13px] leading-relaxed text-gray-900 dark:text-gray-200 whitespace-pre-wrap break-words">{content}</div>
<div class="text-[13px] leading-relaxed text-gray-900 dark:text-gray-200 whitespace-pre-wrap break-words">{#each parsedContent as segment}{#if segment.type === 'text'}{segment.value}{:else}<span class="inline-flex items-center gap-0.5 bg-blue-500/10 text-blue-400 rounded px-1.5 py-px mx-0.5 text-xs font-mono align-baseline"><Icon name={fileIconName(segment.label, 'file')} size={11} />{segment.label}</span>{/if}{/each}</div>
</div>
</div>
{#if siblingTotal > 1 || onedit}
@@ -1,287 +1,241 @@
<script lang="ts">
import type { HighlighterCore } from "shiki/core";
interface Props {
language: string;
code: string;
/** Optional diff-style callbacks for chat tool approval */
onapply?: ((code: string) => void) | undefined;
onreject?: (() => void) | undefined;
}
interface Props {
language: string;
code: string;
/** Optional diff-style callbacks for chat tool approval */
onapply?: ((code: string) => void) | undefined;
onreject?: (() => void) | undefined;
}
let { language, code, onapply, onreject }: Props = $props();
let { language, code, onapply, onreject }: Props = $props();
let codeEl: HTMLElement | undefined = $state();
let highlighted = $state(false);
let copied = $state(false);
let codeEl: HTMLElement | undefined = $state();
let copied = $state(false);
// Detect diff blocks
let isDiff = $derived(language === 'diff');
// Detect diff blocks
let isDiff = $derived(language === "diff");
// Parse diff lines for coloring
let diffLines = $derived.by(() => {
if (!isDiff) return [];
return code.split('\n').map(line => ({
text: line,
type: line.startsWith('+') ? 'add' as const
: line.startsWith('-') ? 'del' as const
: line.startsWith('@@') ? 'range' as const
: 'ctx' as const,
}));
});
// Parse diff lines for coloring
let diffLines = $derived.by(() => {
if (!isDiff) return [];
return code.split("\n").map((line) => ({
text: line,
type: line.startsWith("+")
? ("add" as const)
: line.startsWith("-")
? ("del" as const)
: line.startsWith("@@")
? ("range" as const)
: ("ctx" as const),
}));
});
// Cache hljs module
let hljsModule: any = null;
// Lazy-loaded Shiki highlighter singleton
let highlighterPromise: Promise<HighlighterCore> | null = null;
// Highlight non-diff code: reactive so it re-runs on prop changes (streaming)
$effect(() => {
if (isDiff || !codeEl) return;
const currentCode = code;
const currentLang = language;
async function getHighlighter(): Promise<HighlighterCore> {
if (!highlighterPromise) {
highlighterPromise = (async () => {
const { createHighlighterCore } = await import("shiki/core");
const { createOnigurumaEngine } = await import(
"shiki/engine/oniguruma"
);
const hl = await createHighlighterCore({
themes: [
import("shiki/themes/github-light.mjs"),
import("shiki/themes/github-dark.mjs"),
],
langs: [
import("shiki/langs/javascript.mjs"),
import("shiki/langs/typescript.mjs"),
import("shiki/langs/python.mjs"),
import("shiki/langs/bash.mjs"),
import("shiki/langs/shell.mjs"),
import("shiki/langs/json.mjs"),
import("shiki/langs/html.mjs"),
import("shiki/langs/css.mjs"),
import("shiki/langs/markdown.mjs"),
import("shiki/langs/yaml.mjs"),
import("shiki/langs/toml.mjs"),
import("shiki/langs/rust.mjs"),
import("shiki/langs/go.mjs"),
import("shiki/langs/c.mjs"),
import("shiki/langs/cpp.mjs"),
import("shiki/langs/java.mjs"),
import("shiki/langs/sql.mjs"),
import("shiki/langs/svelte.mjs"),
import("shiki/langs/dockerfile.mjs"),
import("shiki/langs/xml.mjs"),
import("shiki/langs/ruby.mjs"),
import("shiki/langs/php.mjs"),
import("shiki/langs/swift.mjs"),
import("shiki/langs/kotlin.mjs"),
import("shiki/langs/lua.mjs"),
import("shiki/langs/tsx.mjs"),
import("shiki/langs/jsx.mjs"),
import("shiki/langs/scss.mjs"),
import("shiki/langs/graphql.mjs"),
import("shiki/langs/makefile.mjs"),
],
engine: createOnigurumaEngine(import("shiki/wasm")),
});
return hl;
})();
}
return highlighterPromise;
}
(async () => {
try {
if (!hljsModule) {
hljsModule = (await import('highlight.js')).default;
}
if (codeEl && currentCode === code) {
if (currentLang && hljsModule.getLanguage(currentLang)) {
codeEl.innerHTML = hljsModule.highlight(currentCode, { language: currentLang }).value;
} else {
codeEl.innerHTML = hljsModule.highlightAuto(currentCode).value;
}
highlighted = true;
}
} catch {
// Fallback: just show plain text
}
})();
});
// Highlight non-diff code: reactive so it re-runs on prop changes (streaming)
$effect(() => {
if (isDiff || !codeEl) return;
const currentCode = code;
const currentLang = language;
function handleCopy() {
navigator.clipboard.writeText(code);
copied = true;
setTimeout(() => { copied = false; }, 2000);
}
(async () => {
try {
const hl = await getHighlighter();
if (!codeEl || currentCode !== code) return;
const lang =
currentLang && hl.getLoadedLanguages().includes(currentLang)
? currentLang
: "text";
const html = hl.codeToHtml(currentCode, {
lang,
themes: { light: "github-light", dark: "github-dark" },
defaultColor: false, // use CSS variables for theme switching
});
// Shiki wraps in <pre style="--shiki-light:...;--shiki-dark:..."><code>...</code></pre>
// We extract the <code> innerHTML but must also transfer the CSS vars
// from <pre> onto our own <code> so base-color vars resolve.
const tmp = document.createElement("div");
tmp.innerHTML = html;
const shikiPre = tmp.querySelector("pre");
const shikiCode = tmp.querySelector("code");
if (shikiCode && codeEl) {
codeEl.innerHTML = shikiCode.innerHTML;
// Copy --shiki-* CSS vars from the discarded <pre> onto our <code>
if (shikiPre) {
const preStyle = shikiPre.getAttribute("style") || "";
const vars =
preStyle.match(/--shiki[\w-]*:[^;]+/g) || [];
vars.forEach((v) => {
const [name, val] = v.split(":");
if (name && val)
codeEl!.style.setProperty(
name.trim(),
val.trim(),
);
});
}
}
} catch {
// Fallback: just show plain text
}
})();
});
function handleCopy() {
navigator.clipboard.writeText(code);
copied = true;
setTimeout(() => {
copied = false;
}, 2000);
}
</script>
<div class="code-block">
<div class="code-header">
<span class="code-lang">{language || 'text'}</span>
<div class="code-actions">
{#if isDiff && onapply}
<button class="code-action apply" onclick={() => onapply?.(code)}>Apply</button>
<button class="code-action reject" onclick={() => onreject?.()}>Reject</button>
{/if}
<button class="code-action copy" onclick={handleCopy}>
{copied ? '✓' : 'Copy'}
</button>
</div>
</div>
<div
class="not-prose rounded-2xl overflow-hidden bg-black/[0.03] dark:bg-white/[0.03] border border-black/[0.06] dark:border-white/[0.06]"
>
<div class="flex items-center justify-between h-[30px] px-2.5">
<span class="text-[11px] font-medium text-gray-500 lowercase"
>{language || "text"}</span
>
<div class="flex items-center gap-1">
{#if isDiff && onapply}
<button
class="text-[11px] px-2 py-0.5 rounded text-green-600 hover:bg-green-600/10 transition-all duration-100"
onclick={() => onapply?.(code)}>Apply</button
>
<button
class="text-[11px] px-2 py-0.5 rounded text-red-600 hover:bg-red-600/10 transition-all duration-100"
onclick={() => onreject?.()}>Reject</button
>
{/if}
<button
class="text-[11px] px-2 py-0.5 rounded text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-200 dark:hover:bg-white/[0.08] transition-all duration-100"
onclick={handleCopy}
>
{copied ? "✓" : "Copy"}
</button>
</div>
</div>
{#if isDiff}
<pre class="code-pre diff"><code>{#each diffLines as line}<span class="diff-line diff-{line.type}">{line.text}
</span>{/each}</code></pre>
{:else}
<pre class="code-pre"><code bind:this={codeEl}>{code}</code></pre>
{/if}
{#if isDiff}
<pre
class="!m-0 !pb-3 !px-4 overflow-x-auto text-[13px] leading-normal !bg-transparent font-mono"><code
>{#each diffLines as line}<span
class="diff-line diff-{line.type}"
>{line.text}
</span>{/each}</code
></pre>
{:else}
<pre
class="!m-0 !pb-3 !px-4 overflow-x-auto text-[13px] leading-normal !bg-transparent text-[#24292e] dark:text-[#e1e4e8] font-mono"><code
class="font-[inherit]"
bind:this={codeEl}>{code}</code
></pre>
{/if}
</div>
<style>
@reference "../../../app.css";
@reference "../../../app.css";
.code-block {
border-radius: 8px;
overflow: hidden;
background: var(--color-gray-100);
border: 1px solid var(--color-gray-200);
}
/* ── Shiki dual-theme: switch via CSS variables ── */
:global(.dark) .code-block {
background: rgba(255, 255, 255, 0.03);
border-color: rgba(255, 255, 255, 0.06);
}
pre :global(span) {
color: var(--shiki-light);
}
.code-header {
display: flex;
align-items: center;
justify-content: space-between;
height: 30px;
padding: 0 10px;
border-bottom: 1px solid var(--color-gray-200);
background: var(--color-gray-50);
}
:global(.dark) pre :global(span) {
color: var(--shiki-dark);
}
:global(.dark) .code-header {
border-bottom-color: rgba(255, 255, 255, 0.06);
background: rgba(255, 255, 255, 0.02);
}
/* ── Diff line coloring ──────────────────────── */
.code-lang {
font-size: 11px;
font-weight: 500;
color: var(--color-gray-500);
text-transform: lowercase;
}
.diff-line {
display: block;
}
.code-actions {
display: flex;
align-items: center;
gap: 4px;
}
.diff-line.diff-add {
background: rgba(22, 163, 74, 0.1);
color: #16a34a;
}
.code-action {
font-size: 11px;
padding: 2px 8px;
border-radius: 4px;
color: var(--color-gray-500);
transition: all 0.1s;
}
:global(.dark) .diff-line.diff-add {
background: rgba(34, 197, 94, 0.1);
color: #4ade80;
}
.code-action:hover {
color: var(--color-gray-700);
background: var(--color-gray-200);
}
.diff-line.diff-del {
background: rgba(220, 38, 38, 0.08);
color: #dc2626;
}
:global(.dark) .code-action:hover {
color: var(--color-gray-300);
background: rgba(255, 255, 255, 0.08);
}
:global(.dark) .diff-line.diff-del {
background: rgba(248, 113, 113, 0.1);
color: #f87171;
}
.code-action.apply {
color: #16a34a;
}
.diff-line.diff-range {
color: #8b5cf6;
}
.code-action.apply:hover {
background: rgba(22, 163, 74, 0.1);
}
.code-action.reject {
color: #dc2626;
}
.code-action.reject:hover {
background: rgba(220, 38, 38, 0.1);
}
.code-pre {
margin: 0;
padding: 12px 16px;
overflow-x: auto;
font-size: 13px;
line-height: 1.5;
font-family: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
}
.code-pre code {
font-family: inherit;
}
/* ── Diff line coloring ──────────────────────── */
.diff-line {
display: block;
}
.diff-line.diff-add {
background: rgba(22, 163, 74, 0.1);
color: #16a34a;
}
:global(.dark) .diff-line.diff-add {
background: rgba(34, 197, 94, 0.1);
color: #4ade80;
}
.diff-line.diff-del {
background: rgba(220, 38, 38, 0.08);
color: #dc2626;
}
:global(.dark) .diff-line.diff-del {
background: rgba(248, 113, 113, 0.1);
color: #f87171;
}
.diff-line.diff-range {
color: #8b5cf6;
}
:global(.dark) .diff-line.diff-range {
color: #a78bfa;
}
/* ── highlight.js token colors ────────────────── */
.code-pre :global(.hljs-keyword),
.code-pre :global(.hljs-selector-tag),
.code-pre :global(.hljs-built_in) {
color: #d73a49;
}
.code-pre :global(.hljs-string),
.code-pre :global(.hljs-attr) {
color: #032f62;
}
.code-pre :global(.hljs-comment),
.code-pre :global(.hljs-quote) {
color: #6a737d;
font-style: italic;
}
.code-pre :global(.hljs-number),
.code-pre :global(.hljs-literal) {
color: #005cc5;
}
.code-pre :global(.hljs-title),
.code-pre :global(.hljs-section) {
color: #6f42c1;
}
.code-pre :global(.hljs-type),
.code-pre :global(.hljs-name) {
color: #22863a;
}
.code-pre :global(.hljs-meta) {
color: #735c0f;
}
/* Dark mode hljs overrides */
:global(.dark) .code-pre :global(.hljs-keyword),
:global(.dark) .code-pre :global(.hljs-selector-tag),
:global(.dark) .code-pre :global(.hljs-built_in) {
color: #ff7b72;
}
:global(.dark) .code-pre :global(.hljs-string),
:global(.dark) .code-pre :global(.hljs-attr) {
color: #a5d6ff;
}
:global(.dark) .code-pre :global(.hljs-comment),
:global(.dark) .code-pre :global(.hljs-quote) {
color: #8b949e;
}
:global(.dark) .code-pre :global(.hljs-number),
:global(.dark) .code-pre :global(.hljs-literal) {
color: #79c0ff;
}
:global(.dark) .code-pre :global(.hljs-title),
:global(.dark) .code-pre :global(.hljs-section) {
color: #d2a8ff;
}
:global(.dark) .code-pre :global(.hljs-type),
:global(.dark) .code-pre :global(.hljs-name) {
color: #7ee787;
}
:global(.dark) .code-pre :global(.hljs-meta) {
color: #d29922;
}
:global(.dark) .diff-line.diff-range {
color: #a78bfa;
}
</style>
+5
View File
@@ -67,6 +67,7 @@ export type ToolApprovalMode = 'ask' | 'auto' | 'full';
export interface UserPreferences {
theme: Theme;
sidebarOpen: boolean;
sidebarWidth: number;
toolApprovalMode: ToolApprovalMode;
locale: string;
workspaceOrder?: string[]; // ordered paths for sidebar drag-reorder
@@ -114,6 +115,7 @@ export const workspaceList = writable<{ path: string; name: string }[]>([]);
/** Global user preferences. */
export const sidebarOpen = writable(typeof window !== 'undefined' ? window.innerWidth >= 768 : false);
export const sidebarWidth = writable(220);
export const theme = writable<Theme>('dark');
export const toolApprovalMode = writable<ToolApprovalMode>('auto');
/** @deprecated Use toolApprovalMode */
@@ -255,6 +257,7 @@ function persistPreferences(): void {
const prefs: UserPreferences = {
theme: get(theme),
sidebarOpen: get(sidebarOpen),
sidebarWidth: get(sidebarWidth),
toolApprovalMode: get(toolApprovalMode),
locale: i18next.language,
workspaceOrder: get(workspaceOrder),
@@ -270,6 +273,7 @@ function subscribeForPersistence() {
currentWorkspace.subscribe(() => { if (get(stateLoaded)) persistWorkspace(); });
theme.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
sidebarOpen.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
sidebarWidth.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
toolApprovalMode.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
workspaceOrder.subscribe(() => { if (get(stateLoaded)) persistPreferences(); });
i18next.on('languageChanged', () => { if (get(stateLoaded)) persistPreferences(); });
@@ -282,6 +286,7 @@ export async function loadPreferences(): Promise<void> {
const prefs = await getPreferences();
if (prefs.theme) theme.set(prefs.theme as Theme);
if (prefs.sidebarOpen !== undefined) sidebarOpen.set(prefs.sidebarOpen as boolean);
if (prefs.sidebarWidth !== undefined) sidebarWidth.set(prefs.sidebarWidth as number);
// Support new toolApprovalMode and legacy boolean autoApproveTools
if (prefs.toolApprovalMode) {
toolApprovalMode.set(prefs.toolApprovalMode as ToolApprovalMode);
+29
View File
@@ -0,0 +1,29 @@
/**
* Shared file icon name resolver.
* Maps file names/extensions to Icon component names.
*/
export function fileIconName(name: string, type: string = 'file'): string {
if (type === 'directory') return 'folder';
const ext = name.split('.').pop()?.toLowerCase() ?? '';
if (name === 'Dockerfile') return 'docker';
if (name === 'LICENSE' || name === 'LICENSE.md') return 'page-text';
if (name.endsWith('.lock')) return 'lock';
switch (ext) {
case 'md': return 'page-text';
case 'ts': case 'tsx': case 'js': case 'jsx':
case 'py': case 'rs': case 'go': case 'java':
case 'c': case 'cpp': case 'h': case 'hpp':
case 'rb': case 'php': case 'swift': case 'kt':
case 'svelte': case 'vue':
return 'code';
case 'json': case 'yaml': case 'yml': case 'toml':
case 'ini': case 'cfg': case 'conf':
return 'settings';
case 'sh': case 'bash': case 'zsh':
return 'terminal';
case 'css': case 'html': case 'xml':
return 'code';
default: return 'empty-page';
}
}