This commit is contained in:
Timothy Jaeryang Baek committed 2026-11-22 17:23:24 +04:00
1 parent 26e3c67191
commit b5a9aead84
14 files changed
+291 -227

No files matched your search

+3
View File
@@ -334,6 +334,9 @@ class SPAStaticFiles(StaticFiles):
if full_path.endswith('.html'):
# Stale cached HTML references chunks from an older build
response.headers['Cache-Control'] = 'no-cache'
elif '/_app/immutable/' in str(full_path).replace(os.sep, '/'):
# Content-hashed build output never changes under the same name
response.headers['Cache-Control'] = 'public, max-age=31536000, immutable'
return response
@@ -2,7 +2,6 @@
import { getContext } from 'svelte';
import Modal from '$lib/components/common/Modal.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import FileNav from '$lib/components/chat/FileNav.svelte';
import type { MachineTarget } from '$lib/apis/machines';
const i18n = getContext<any>('i18n');
@@ -25,7 +24,9 @@
>
</div>
<div class="h-[70dvh] min-h-0">
<FileNav {target} manageFileRequests={false} showTerminalDock={false} />
{#await import('$lib/components/chat/FileNav.svelte') then { default: FileNav }}
<FileNav {target} manageFileRequests={false} showTerminalDock={false} />
{/await}
</div>
</div>
</Modal>
@@ -17,7 +17,6 @@
import SearchInput from './InputMenu/SearchInput.svelte';
import Check from '$lib/components/icons/Check.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import FileNav from '../FileNav.svelte';
import { machineIdOf } from '$lib/utils/machines';
const i18n = getContext<any>('i18n');
@@ -341,14 +340,16 @@
</button>
</div>
<div class="h-[60dvh] min-h-0" aria-busy={saving}>
<FileNav
machineId={target.selector}
{chatId}
initialDirectory={directory || null}
manageFileRequests={false}
showTerminalDock={false}
onSelectDirectory={selectDirectory}
/>
{#await import('../FileNav.svelte') then { default: FileNav }}
<FileNav
machineId={target.selector}
{chatId}
initialDirectory={directory || null}
manageFileRequests={false}
showTerminalDock={false}
onSelectDirectory={selectDirectory}
/>
{/await}
</div>
</div>
</Modal>
@@ -13,7 +13,7 @@
import CheckCircle from '$lib/components/icons/CheckCircle.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import FullHeightIframe from '$lib/components/common/FullHeightIframe.svelte';
import MCPApp, { type MCPAppEmbed } from '$lib/components/chat/Messages/MCPApp.svelte';
import type { MCPAppEmbed } from '$lib/components/chat/Messages/MCPApp.svelte';
import { agentViewName, type AgentView } from '$lib/components/chat/Messages/agentViews';
import { toolCallLabel } from '$lib/components/chat/Messages/builtinToolLabels';
@@ -462,7 +462,9 @@
{#each allEmbeds as embedItem, idx}
<div id={`${id}-embed-${idx}`}>
{#if typeof embedItem.embed === 'object' && embedItem.embed?.type === 'mcp_app'}
{#key JSON.stringify(embedItem.embed)}<MCPApp app={embedItem.embed} />{/key}
{#key JSON.stringify(embedItem.embed)}{#await import('$lib/components/chat/Messages/MCPApp.svelte') then { default: MCPApp }}<MCPApp
app={embedItem.embed}
/>{/await}{/key}
{:else if typeof embedItem.embed === 'string'}
<FullHeightIframe
src={embedItem.embed}
@@ -62,7 +62,6 @@
import RegenerateMenu from './ResponseMessage/RegenerateMenu.svelte';
import StatusHistory from './ResponseMessage/StatusHistory.svelte';
import FullHeightIframe from '$lib/components/common/FullHeightIframe.svelte';
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';
@@ -798,7 +797,9 @@
{#each message.embeds as embed, idx}
<div class="my-2 w-full" id={`${message.id}-embeds-${idx}`}>
{#if typeof embed === 'object' && embed?.type === 'mcp_app'}
{#key JSON.stringify(embed)}<MCPApp app={embed} />{/key}
{#key JSON.stringify(embed)}{#await import('$lib/components/chat/Messages/MCPApp.svelte') then { default: MCPApp }}<MCPApp
app={embed}
/>{/await}{/key}
{:else if typeof embed === 'string'}
<FullHeightIframe
src={embed}
+71 -67
View File
@@ -114,9 +114,7 @@
import Artifacts from './Artifacts.svelte';
import Embeds from './Tabs/Embeds.svelte';
import ChatTab from './Tabs/ChatTab.svelte';
import FileNav from './FileNav.svelte';
import PyodideFileNav from './PyodideFileNav.svelte';
import Overview from './Overview.svelte';
import ConfirmDialog from '../common/ConfirmDialog.svelte';
let stopTerminalChoice: ((stop: boolean) => void) | null = null;
import SplitPanel from '../icons/SplitPanel.svelte';
@@ -2106,18 +2104,20 @@
: chatView.chatId) ?? ''}
/>
{:else if tab.kind === 'overview'}
<Overview
history={chatHistory}
{chatUser}
onNodeClick={(e: any) => {
const { node } = e;
chatHistory.messages[node.data.message.id].favorite = node.data.message.favorite
? true
: null;
if (!visibleTabIds.has(mainChatTabId)) focusMainChat();
showMessage(node.data.message, true);
}}
/>
{#await import('./Overview.svelte') then { default: Overview }}
<Overview
history={chatHistory}
{chatUser}
onNodeClick={(e: any) => {
const { node } = e;
chatHistory.messages[node.data.message.id].favorite = node.data.message.favorite
? true
: null;
if (!visibleTabIds.has(mainChatTabId)) focusMainChat();
showMessage(node.data.message, true);
}}
/>
{/await}
{:else if tab.kind === 'chat'}
<ChatTab
bind:this={chatViews[tab.id]}
@@ -2267,59 +2267,63 @@
{@const fileTarget = isMounted ? resolveTabConnection(tab) : null}
<div class="flex h-full min-h-0 flex-col">
<div class="min-h-0 flex-1">
<FileNav
target={fileTarget}
modelId={fileTarget?.context.modelId ?? null}
onFileSaved={(content) => {
const draft = chatView.drafts.get(tab.id);
if (draft?.preview) {
draft.preview.baseText = content;
draft.dirty = draft.preview.dirty = draft.preview.text !== content;
}
}}
initialView={chatView.drafts.get(tab.id)}
onViewChange={(view) => {
chatView.drafts.set(tab.id, view);
if (tab.kind === 'files')
updateViewTab(chatView, tab.id, {
directory: view.directory,
label: view.isHome
? $i18n.t('Home')
: view.directory?.split('/').filter(Boolean).pop() || $i18n.t('Files')
});
}}
onFilesMoved={() => {
if (chatView !== viewEntry) return;
for (const other of tabs.tabs) {
if (
other.id !== tab.id &&
other.kind === 'files' &&
other.machineId === tab.machineId
)
void fileViews[other.id]?.refreshDirectory?.();
}
}}
gitStatus={fileGitStatuses[tab.machineId] ?? null}
gitTarget={fileTarget}
gitDiffMode={fileGitDiffModes[tab.machineId] ?? 'unified'}
gitHideWhitespace={fileGitHideWhitespace[tab.machineId] ?? false}
bind:this={fileViews[tab.id]}
bind:dirty={dirtyFiles[tab.id]}
machineId={tab.machineId}
initialFile={tab.kind === 'file' ? { path: tab.path!, page: tab.page } : null}
initialDirectory={tab.kind === 'files' ? (tab.directory ?? tab.path ?? null) : null}
active={panelVisible && visibleTabIds.has(tab.id)}
manageFileRequests={false}
showTerminalDock={tab.kind === 'files'}
onOpenFile={(path, page) =>
openFile(path, tab.machineId!, page, fileTarget?.context.modelId)}
onBrowseDirectory={(path) =>
openFiles(tab.machineId, path, false, fileTarget?.context.modelId)}
{onAskFile}
overlay={isDragging}
chatId={chatView.chatId}
bind:machineContext={fileContexts[tab.id]}
/>
{#await import('./FileNav.svelte') then { default: FileNav }}
<FileNav
target={fileTarget}
modelId={fileTarget?.context.modelId ?? null}
onFileSaved={(content) => {
const draft = chatView.drafts.get(tab.id);
if (draft?.preview) {
draft.preview.baseText = content;
draft.dirty = draft.preview.dirty = draft.preview.text !== content;
}
}}
initialView={chatView.drafts.get(tab.id)}
onViewChange={(view) => {
chatView.drafts.set(tab.id, view);
if (tab.kind === 'files')
updateViewTab(chatView, tab.id, {
directory: view.directory,
label: view.isHome
? $i18n.t('Home')
: view.directory?.split('/').filter(Boolean).pop() || $i18n.t('Files')
});
}}
onFilesMoved={() => {
if (chatView !== viewEntry) return;
for (const other of tabs.tabs) {
if (
other.id !== tab.id &&
other.kind === 'files' &&
other.machineId === tab.machineId
)
void fileViews[other.id]?.refreshDirectory?.();
}
}}
gitStatus={fileGitStatuses[tab.machineId] ?? null}
gitTarget={fileTarget}
gitDiffMode={fileGitDiffModes[tab.machineId] ?? 'unified'}
gitHideWhitespace={fileGitHideWhitespace[tab.machineId] ?? false}
bind:this={fileViews[tab.id]}
bind:dirty={dirtyFiles[tab.id]}
machineId={tab.machineId}
initialFile={tab.kind === 'file' ? { path: tab.path!, page: tab.page } : null}
initialDirectory={tab.kind === 'files'
? (tab.directory ?? tab.path ?? null)
: null}
active={panelVisible && visibleTabIds.has(tab.id)}
manageFileRequests={false}
showTerminalDock={tab.kind === 'files'}
onOpenFile={(path, page) =>
openFile(path, tab.machineId!, page, fileTarget?.context.modelId)}
onBrowseDirectory={(path) =>
openFiles(tab.machineId, path, false, fileTarget?.context.modelId)}
{onAskFile}
overlay={isDragging}
chatId={chatView.chatId}
bind:machineContext={fileContexts[tab.id]}
/>
{/await}
</div>
{#if tab.kind === 'files' && fileTarget}
<GitBar
+17 -7
View File
@@ -1,10 +1,7 @@
<script lang="ts">
import { onMount, onDestroy } from 'svelte';
import { Terminal } from '@xterm/xterm';
import { FitAddon } from '@xterm/addon-fit';
import { WebLinksAddon } from '@xterm/addon-web-links';
import { WebglAddon } from '@xterm/addon-webgl';
import '@xterm/xterm/css/xterm.css';
import type { Terminal } from '@xterm/xterm';
import type { FitAddon } from '@xterm/addon-fit';
import { machineRequest, MachineRequestError, type MachineTarget } from '$lib/apis/machines';
import { assignTerminalChat, openMachineSocket } from '$lib/apis/machines/socket';
@@ -237,8 +234,16 @@
$: if (active && term) requestAnimationFrame(fit);
$: if (connected) reportActivity(active);
onMount(() => {
document.addEventListener('visibilitychange', reportVisibility);
// xterm is only needed once a terminal is on screen, so it stays out of the boot bundle.
const init = async () => {
const [{ Terminal }, { FitAddon }, { WebLinksAddon }, { WebglAddon }] = await Promise.all([
import('@xterm/xterm'),
import('@xterm/addon-fit'),
import('@xterm/addon-web-links'),
import('@xterm/addon-webgl'),
import('@xterm/xterm/css/xterm.css')
]);
if (destroyed) return;
term = new Terminal({
allowTransparency: true,
cursorBlink: !readOnly,
@@ -284,6 +289,11 @@
});
connect();
}
};
onMount(() => {
document.addEventListener('visibilitychange', reportVisibility);
void init();
});
onDestroy(() => {
@@ -18,7 +18,6 @@
import XMark from '../icons/XMark.svelte';
import Image from './Image.svelte';
import FullHeightIframe from './FullHeightIframe.svelte';
import MCPApp from '$lib/components/chat/Messages/MCPApp.svelte';
import DiffBlock from '$lib/components/chat/Messages/DiffBlock.svelte';
import {
agentViewName,
@@ -252,7 +251,9 @@
{#each embeds as embed, idx}
<div class="my-2" id={`${componentId}-tool-call-embed-${idx}`}>
{#if typeof embed === 'object' && embed?.type === 'mcp_app'}
{#key JSON.stringify(embed)}<MCPApp app={embed} />{/key}
{#key JSON.stringify(embed)}{#await import('$lib/components/chat/Messages/MCPApp.svelte') then { default: MCPApp }}<MCPApp
app={embed}
/>{/await}{/key}
{:else if typeof embed === 'string'}
<FullHeightIframe
src={embed}
@@ -20,7 +20,6 @@
import { baseModels, user, config, settings } from '$lib/stores';
import { getModels } from '$lib/apis';
import ModelSelector from '$lib/components/chat/ModelSelector/Selector.svelte';
import FileNav from '$lib/components/chat/FileNav.svelte';
import FolderOpen from '$lib/components/icons/FolderOpen.svelte';
import MachineMenu from '$lib/components/chat/MessageInput/MachineMenu.svelte';
import ChevronDown from '$lib/components/icons/ChevronDown.svelte';
@@ -549,16 +548,18 @@
>
</div>
<div class="h-[60dvh] min-h-0">
<FileNav
machineId={data.machine_id}
initialDirectory={data.working_directory || null}
manageFileRequests={false}
showTerminalDock={false}
onSelectDirectory={(path) => {
data.working_directory = path;
showDirectoryPicker = false;
}}
/>
{#await import('$lib/components/chat/FileNav.svelte') then { default: FileNav }}
<FileNav
machineId={data.machine_id}
initialDirectory={data.working_directory || null}
manageFileRequests={false}
showTerminalDock={false}
onSelectDirectory={(path) => {
data.working_directory = path;
showDirectoryPicker = false;
}}
/>
{/await}
</div>
</div>
</Modal>
+7 -2
View File
@@ -137,6 +137,9 @@
let savedCommentHashes: Record<string, string> = {};
let pageBusy = false;
let showNoteTabs = false;
let noteTabsWidth = 280;
// Width the docked pages panel takes from the editor column, divider included.
$: noteTabsSpace = showNoteTabs && !$mobile ? noteTabsWidth + 1 : 0;
let noteTabsPreferenceReady = false;
$: if (noteTabsPreferenceReady && !$mobile && $user?.id) {
localStorage.setItem(`note-tabs-open:${$user.id}`, String(showNoteTabs));
@@ -1477,7 +1480,7 @@ ${content}
bind:show={showNoteTabs}
ariaLabel={$i18n.t('Pages')}
side="left"
panelWidth={280}
bind:panelWidth={noteTabsWidth}
minWidth={180}
closeOnDragBelowMinWidth={false}
resizerId="note-tabs-resizer"
@@ -1611,12 +1614,14 @@ ${content}
? ''
: 'bg-linear-to-t from-base-0 from-40% to-transparent pt-8 dark:from-base-900'}"
>
<div class="flex justify-center">
<div class="flex">
<!-- Side padding lives on the column so the composer keeps its box in both states. -->
<!-- Centred on the whole note, so the pages panel only moves it when they would collide. -->
<div
class="pointer-events-auto flex w-full max-w-3xl flex-col rounded-t-3xl border border-b-0 {noteChatExpanded
? 'h-[min(60dvh,36rem)] border-base-100/40 bg-base-0 pt-1.5 dark:border-base-800/25 dark:bg-base-900'
: 'border-transparent'}"
style="margin-inline-start: max(0px, calc((100% - {noteTabsSpace}px - 48rem) / 2))"
>
{#if !noteChatExpanded}
<button
+122 -109
View File
@@ -1,114 +1,116 @@
import dayjs from 'dayjs';
// Import all locales
import 'dayjs/locale/af';
import 'dayjs/locale/am';
import 'dayjs/locale/ar';
import 'dayjs/locale/az';
import 'dayjs/locale/be';
import 'dayjs/locale/bg';
import 'dayjs/locale/bi';
import 'dayjs/locale/bm';
import 'dayjs/locale/bn';
import 'dayjs/locale/bo';
import 'dayjs/locale/br';
import 'dayjs/locale/bs';
import 'dayjs/locale/ca';
import 'dayjs/locale/cs';
import 'dayjs/locale/cv';
import 'dayjs/locale/cy';
import 'dayjs/locale/da';
import 'dayjs/locale/de';
import 'dayjs/locale/dv';
import 'dayjs/locale/el';
import 'dayjs/locale/en';
import 'dayjs/locale/eo';
import 'dayjs/locale/es';
import 'dayjs/locale/eu';
import 'dayjs/locale/fa';
import 'dayjs/locale/fi';
import 'dayjs/locale/fo';
import 'dayjs/locale/fr';
import 'dayjs/locale/fy';
import 'dayjs/locale/ga';
import 'dayjs/locale/gd';
import 'dayjs/locale/gl';
import 'dayjs/locale/gu';
import 'dayjs/locale/he';
import 'dayjs/locale/hi';
import 'dayjs/locale/hr';
import 'dayjs/locale/ht';
import 'dayjs/locale/hu';
import 'dayjs/locale/id';
import 'dayjs/locale/is';
import 'dayjs/locale/it';
import 'dayjs/locale/ja';
import 'dayjs/locale/jv';
import 'dayjs/locale/ka';
import 'dayjs/locale/kk';
import 'dayjs/locale/km';
import 'dayjs/locale/kn';
import 'dayjs/locale/ko';
import 'dayjs/locale/ku';
import 'dayjs/locale/ky';
import 'dayjs/locale/lb';
import 'dayjs/locale/lo';
import 'dayjs/locale/lt';
import 'dayjs/locale/lv';
import 'dayjs/locale/me';
import 'dayjs/locale/mi';
import 'dayjs/locale/mk';
import 'dayjs/locale/ml';
import 'dayjs/locale/mn';
import 'dayjs/locale/mr';
import 'dayjs/locale/ms';
import 'dayjs/locale/mt';
import 'dayjs/locale/my';
import 'dayjs/locale/nb';
import 'dayjs/locale/ne';
import 'dayjs/locale/nl';
import 'dayjs/locale/nn';
import 'dayjs/locale/pl';
import 'dayjs/locale/pt';
import 'dayjs/locale/ro';
import 'dayjs/locale/ru';
import 'dayjs/locale/rw';
import 'dayjs/locale/sd';
import 'dayjs/locale/se';
import 'dayjs/locale/si';
import 'dayjs/locale/sk';
import 'dayjs/locale/sl';
import 'dayjs/locale/sq';
import 'dayjs/locale/sr';
import 'dayjs/locale/ss';
import 'dayjs/locale/sv';
import 'dayjs/locale/sw';
import 'dayjs/locale/ta';
import 'dayjs/locale/te';
import 'dayjs/locale/tet';
import 'dayjs/locale/tg';
import 'dayjs/locale/th';
import 'dayjs/locale/tk';
import 'dayjs/locale/tlh';
import 'dayjs/locale/tr';
import 'dayjs/locale/tzl';
import 'dayjs/locale/tzm';
import 'dayjs/locale/uk';
import 'dayjs/locale/ur';
import 'dayjs/locale/uz';
import 'dayjs/locale/vi';
import 'dayjs/locale/yo';
import 'dayjs/locale/zh';
import 'dayjs/locale/zh-tw';
import 'dayjs/locale/et';
import 'dayjs/locale/en-gb';
import 'dayjs/locale/bn-bd';
import 'dayjs/locale/fr-ca';
import 'dayjs/locale/ms-my';
import 'dayjs/locale/pt-br';
import 'dayjs/locale/pa-in';
import 'dayjs/locale/ug-cn';
import 'dayjs/locale/zh-cn';
// Locales load on demand; English is built into dayjs.
/** @type {Record<string, () => Promise<unknown>>} */
const locales = {
af: () => import('dayjs/locale/af'),
am: () => import('dayjs/locale/am'),
ar: () => import('dayjs/locale/ar'),
az: () => import('dayjs/locale/az'),
be: () => import('dayjs/locale/be'),
bg: () => import('dayjs/locale/bg'),
bi: () => import('dayjs/locale/bi'),
bm: () => import('dayjs/locale/bm'),
bn: () => import('dayjs/locale/bn'),
bo: () => import('dayjs/locale/bo'),
br: () => import('dayjs/locale/br'),
bs: () => import('dayjs/locale/bs'),
ca: () => import('dayjs/locale/ca'),
cs: () => import('dayjs/locale/cs'),
cv: () => import('dayjs/locale/cv'),
cy: () => import('dayjs/locale/cy'),
da: () => import('dayjs/locale/da'),
de: () => import('dayjs/locale/de'),
dv: () => import('dayjs/locale/dv'),
el: () => import('dayjs/locale/el'),
eo: () => import('dayjs/locale/eo'),
es: () => import('dayjs/locale/es'),
eu: () => import('dayjs/locale/eu'),
fa: () => import('dayjs/locale/fa'),
fi: () => import('dayjs/locale/fi'),
fo: () => import('dayjs/locale/fo'),
fr: () => import('dayjs/locale/fr'),
fy: () => import('dayjs/locale/fy'),
ga: () => import('dayjs/locale/ga'),
gd: () => import('dayjs/locale/gd'),
gl: () => import('dayjs/locale/gl'),
gu: () => import('dayjs/locale/gu'),
he: () => import('dayjs/locale/he'),
hi: () => import('dayjs/locale/hi'),
hr: () => import('dayjs/locale/hr'),
ht: () => import('dayjs/locale/ht'),
hu: () => import('dayjs/locale/hu'),
id: () => import('dayjs/locale/id'),
is: () => import('dayjs/locale/is'),
it: () => import('dayjs/locale/it'),
ja: () => import('dayjs/locale/ja'),
jv: () => import('dayjs/locale/jv'),
ka: () => import('dayjs/locale/ka'),
kk: () => import('dayjs/locale/kk'),
km: () => import('dayjs/locale/km'),
kn: () => import('dayjs/locale/kn'),
ko: () => import('dayjs/locale/ko'),
ku: () => import('dayjs/locale/ku'),
ky: () => import('dayjs/locale/ky'),
lb: () => import('dayjs/locale/lb'),
lo: () => import('dayjs/locale/lo'),
lt: () => import('dayjs/locale/lt'),
lv: () => import('dayjs/locale/lv'),
me: () => import('dayjs/locale/me'),
mi: () => import('dayjs/locale/mi'),
mk: () => import('dayjs/locale/mk'),
ml: () => import('dayjs/locale/ml'),
mn: () => import('dayjs/locale/mn'),
mr: () => import('dayjs/locale/mr'),
ms: () => import('dayjs/locale/ms'),
mt: () => import('dayjs/locale/mt'),
my: () => import('dayjs/locale/my'),
nb: () => import('dayjs/locale/nb'),
ne: () => import('dayjs/locale/ne'),
nl: () => import('dayjs/locale/nl'),
nn: () => import('dayjs/locale/nn'),
pl: () => import('dayjs/locale/pl'),
pt: () => import('dayjs/locale/pt'),
ro: () => import('dayjs/locale/ro'),
ru: () => import('dayjs/locale/ru'),
rw: () => import('dayjs/locale/rw'),
sd: () => import('dayjs/locale/sd'),
se: () => import('dayjs/locale/se'),
si: () => import('dayjs/locale/si'),
sk: () => import('dayjs/locale/sk'),
sl: () => import('dayjs/locale/sl'),
sq: () => import('dayjs/locale/sq'),
sr: () => import('dayjs/locale/sr'),
ss: () => import('dayjs/locale/ss'),
sv: () => import('dayjs/locale/sv'),
sw: () => import('dayjs/locale/sw'),
ta: () => import('dayjs/locale/ta'),
te: () => import('dayjs/locale/te'),
tet: () => import('dayjs/locale/tet'),
tg: () => import('dayjs/locale/tg'),
th: () => import('dayjs/locale/th'),
tk: () => import('dayjs/locale/tk'),
tlh: () => import('dayjs/locale/tlh'),
tr: () => import('dayjs/locale/tr'),
tzl: () => import('dayjs/locale/tzl'),
tzm: () => import('dayjs/locale/tzm'),
uk: () => import('dayjs/locale/uk'),
ur: () => import('dayjs/locale/ur'),
uz: () => import('dayjs/locale/uz'),
vi: () => import('dayjs/locale/vi'),
yo: () => import('dayjs/locale/yo'),
zh: () => import('dayjs/locale/zh'),
'zh-tw': () => import('dayjs/locale/zh-tw'),
et: () => import('dayjs/locale/et'),
'en-gb': () => import('dayjs/locale/en-gb'),
'bn-bd': () => import('dayjs/locale/bn-bd'),
'fr-ca': () => import('dayjs/locale/fr-ca'),
'ms-my': () => import('dayjs/locale/ms-my'),
'pt-br': () => import('dayjs/locale/pt-br'),
'pa-in': () => import('dayjs/locale/pa-in'),
'ug-cn': () => import('dayjs/locale/ug-cn'),
'zh-cn': () => import('dayjs/locale/zh-cn')
};
/** @param {string | undefined} language */
export const getDayjsLocale = (language) => {
@@ -116,4 +118,15 @@ export const getDayjsLocale = (language) => {
return [code, code.split('-')[0], 'en'].find((candidate) => dayjs.Ls[candidate]);
};
/**
* Load the locale for a language, then return the name to pass to dayjs.locale().
* @param {string | undefined} language
*/
export const loadDayjsLocale = async (language) => {
const code = (language ?? 'en').toLowerCase();
const name = [code, code.split('-')[0]].find((candidate) => candidate in locales);
if (name && !dayjs.Ls[name]) await locales[name]().catch(() => {});
return getDayjsLocale(language);
};
export default dayjs;
+18 -4
View File
@@ -3,13 +3,19 @@ import resourcesToBackend from 'i18next-resources-to-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import type { i18n as i18nType } from 'i18next';
import { writable } from 'svelte/store';
import dayjs, { getDayjsLocale } from '$lib/dayjs';
import dayjs, { loadDayjsLocale } from '$lib/dayjs';
import type { I18nOverrides } from '$lib/utils/translationDictionary';
import { assembleSettingsTranslations } from './settings-translations';
import languages from './locales/languages.json';
let overrides: I18nOverrides = {};
let dayjsLocale: Promise<void> = Promise.resolve();
// Resolve language switches only once dates can be localized too.
const withDayjsLocale = async <T>(value: T) => {
await dayjsLocale;
return value;
};
export const loadBundledResource = async (language: string): Promise<Record<string, string>> =>
(await import(`./locales/${language}/translation.json`)).default;
@@ -48,7 +54,12 @@ const createI18nStore = (i18n: i18nType) => {
});
i18n.on('added', () => i18nWritable.set(i18n));
i18n.on('languageChanged', (lang) => {
dayjs.locale(getDayjsLocale(lang));
// The locale file loads on demand; update the store again once dates can be localized.
dayjsLocale = loadDayjsLocale(lang).then((locale) => {
if (i18n.language !== lang) return;
dayjs.locale(locale);
i18nWritable.set(i18n);
});
i18nWritable.set(i18n);
if (typeof document !== 'undefined') {
document.documentElement.setAttribute('lang', lang);
@@ -115,7 +126,8 @@ export const initI18n = (defaultLocale?: string, value: I18nOverrides = {}) => {
interpolation: {
escapeValue: false // not needed for svelte as it escapes by default
}
});
})
.then(withDayjsLocale);
};
const i18n = createI18nStore(i18next);
@@ -125,7 +137,9 @@ export const getLanguages = async () => languages;
// Serialize switches so a slower download cannot overwrite a newer selection.
let languageChange = Promise.resolve();
export const changeLanguage = (lang: string) => {
const change = languageChange.then(() => i18next.changeLanguage(toBundleCode(lang)));
const change = languageChange
.then(() => i18next.changeLanguage(toBundleCode(lang)))
.then(withDayjsLocale);
languageChange = change.then(
() => {},
() => {}
+7 -2
View File
@@ -1,13 +1,18 @@
import * as XLSX from 'xlsx';
import type * as SheetJS from 'xlsx';
import DOMPurify from 'dompurify';
import { OfficePackage, attr, children, elements } from './comments/package';
import type { CellObject, Range, WorkBook, WorkSheet } from 'xlsx';
// SheetJS is large, so it loads with the first workbook instead of with the app.
// Every other export here works on a workbook that readExcelWorkbook returned.
let XLSX: typeof SheetJS;
export type PreviewSheet = WorkSheet & { '!previewStyles'?: Record<string, string> };
// SheetJS CE reads values and number formats, but not fonts, borders or alignment.
// Keep presentation metadata separate from the workbook's editable cell values.
export async function readExcelWorkbook(data: ArrayBuffer): Promise<WorkBook> {
XLSX ??= await import('xlsx');
const workbook = XLSX.read(data, { type: 'array', cellStyles: true, cellNF: true });
if (new Uint8Array(data)[0] !== 0x50 || new Uint8Array(data)[1] !== 0x4b) return workbook; // XLS / CSV have no OOXML styles.
const pkg = await OfficePackage.open(data);
@@ -479,7 +484,7 @@ export class ExcelWorkbookEditor {
private changes = new Map<string, Change>();
private savedState = '[]';
private protectedSheets = new Set<string>();
private readOnlyRanges = new Map<string, XLSX.Range[]>();
private readOnlyRanges = new Map<string, Range[]>();
private sheetPaths = new Map<string, string>();
private original: ArrayBuffer;
private expected: ArrayBuffer;
+11 -8
View File
@@ -49,7 +49,6 @@
import Sidebar from '$lib/components/layout/Sidebar.svelte';
import Chat from '$lib/components/chat/Chat.svelte';
import { pageTabKey } from '$lib/components/chat/Tabs/tabs';
import SettingsModal from '$lib/components/chat/SettingsModal.svelte';
import ChangelogModal from '$lib/components/ChangelogModal.svelte';
import AccountPending from '$lib/components/layout/Overlay/AccountPending.svelte';
import UpdateInfoToast from '$lib/components/layout/UpdateInfoToast.svelte';
@@ -61,6 +60,9 @@
const appLayout = setContext<AppLayoutContext>('appLayout', {});
let loaded = false;
// Settings (including the admin panels) load on first open, then stay mounted.
let settingsRequested = false;
$: if ($showSettings) settingsRequested = true;
$: routeHasTabs = ['/(app)', '/(app)/c/[id]', '/(app)/folders/[folderId]'].includes(
$page.route.id ?? ''
);
@@ -255,9 +257,9 @@
await Promise.all([
setBanners().catch((e) => console.error('Failed to load banners:', e)),
setTools().catch((e) => console.error('Failed to load tools:', e)),
setUserSettings(async () => {
await setModels().catch((e) => console.error('Failed to load models:', e));
})
setUserSettings(),
setModels().catch((e) => console.error('Failed to load models:', e)),
refreshMachines().catch((e) => console.error('Failed to load machines:', e))
]);
} catch (e) {
console.error('Failed to load user settings:', e);
@@ -265,9 +267,6 @@
return;
}
await refreshMachines().catch((e) => {
console.error('Failed to load machines:', e);
});
// selectedTerminalId is the former key.
const storedMachineId = localStorage.selectedMachineId ?? localStorage.selectedTerminalId;
delete localStorage.selectedTerminalId;
@@ -458,7 +457,11 @@
};
</script>
<SettingsModal bind:show={$showSettings} />
{#if settingsRequested}
{#await import('$lib/components/chat/SettingsModal.svelte') then { default: SettingsModal }}
<SettingsModal bind:show={$showSettings} />
{/await}
{/if}
<ChangelogModal bind:show={$showChangelog} />
{#if WEBUI_BUILD_CHANNEL === 'main' && version && compareVersion(version.latest, version.current) && ($settings?.showUpdateToast ?? true)}