This commit is contained in:
Timothy Jaeryang Baek 2026-10-15 22:51:14 +04:00
parent 0c56e39335
commit 7ca62fdf93
6 changed files with 36 additions and 8 deletions

View file

@ -1,4 +1,5 @@
<script lang="ts">
import type { TerminalContext } from '$lib/types';
import { v4 as uuidv4 } from 'uuid';
import { toast } from 'svelte-sonner';
@ -473,6 +474,7 @@
let prompt = '';
let chatFiles = [];
let files: any[] = [];
let terminalContext: TerminalContext | null = null;
let params = {};
let chatVariables = {};
let showChatVariablesModal = false;
@ -938,6 +940,7 @@
};
const initEmbeddedDraft = async () => {
terminalContext = null;
clearTimeout(saveControlsTimer);
await saveControls();
@ -1062,6 +1065,7 @@
let lastTerminalSkillSelector: string | null = null;
$: if ($selectedTerminalId !== lastTerminalSkillSelector) {
terminalContext = null;
selectedSkillIds = selectedSkillIds.filter((id) => !id.startsWith('terminal:'));
terminalSkills.set([]);
lastTerminalSkillSelector = $selectedTerminalId;
@ -2544,6 +2548,7 @@
};
const initNewChat = async () => {
if ($chatId) terminalContext = null;
cancelBrowserInteractions();
bridge?.end();
console.log('initNewChat');
@ -2787,6 +2792,7 @@
};
const loadChat = async () => {
if (chatIdProp && chatIdProp !== $chatId) terminalContext = null;
noteChatDebug('loadChat start');
// chatIdProp is empty for chats started from the home page (URL set via replaceState)
chatId.set(chatIdProp || $chatId);
@ -5115,6 +5121,7 @@
class=" pb-2 {dragged ? 'z-0' : 'z-10'}"
>
<MessageInput
{terminalContext}
{typingUsers}
on:typing={(event) => emitTyping(event.detail)}
callActive={!!(bridge?.connected || bridge?.connecting)}
@ -5211,6 +5218,7 @@
{/if}
<div id={embedded ? messageInputDropzoneId : undefined} class="pb-2 z-10">
<MessageInput
{terminalContext}
{typingUsers}
on:typing={(event) => emitTyping(event.detail)}
callActive={!!(bridge?.connected || bridge?.connecting)}
@ -5276,6 +5284,7 @@
{:else}
<div class="flex items-center h-full">
<Placeholder
{terminalContext}
callActive={!!(bridge?.connected || bridge?.connecting)}
callEnabled={!isShared}
bind:selectedModelIdx
@ -5332,6 +5341,7 @@
{#if !embedded}
<ChatControls
bind:terminalContext
bind:history
bind:chatFiles
bind:params

View file

@ -3,6 +3,7 @@
</script>
<script lang="ts">
import type { TerminalContext } from '$lib/types';
import { onMount, tick, getContext } from 'svelte';
import {
config,
@ -34,6 +35,7 @@
export let models = [];
export let chatId = null;
export let terminalContext: TerminalContext | null = null;
export let chatUser = null;
export let chatFiles = [];
@ -298,7 +300,7 @@
}}
/>
{:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId}
<FileNav {chatId} />
<FileNav {chatId} bind:terminalContext />
{:else if activeTab === 'files' && codeInterpreterEnabled}
<PyodideFileNav />
{:else}
@ -428,7 +430,7 @@
}}
/>
{:else if activeTab === 'files' && terminalFilesAvailable && $selectedTerminalId}
<FileNav overlay={dragged} {chatId} />
<FileNav overlay={dragged} {chatId} bind:terminalContext />
{:else if activeTab === 'files' && codeInterpreterEnabled}
<PyodideFileNav overlay={dragged} />
{:else}

View file

@ -12,6 +12,7 @@
</script>
<script lang="ts">
import type { TerminalContext } from '$lib/types';
import { toast } from 'svelte-sonner';
import Plus from '$lib/components/icons/Plus.svelte';
import Folder from '$lib/components/icons/Folder.svelte';
@ -70,6 +71,7 @@
export let overlay = false;
export let chatId: string | null = null;
export let terminalContext: TerminalContext | null = null;
// ── Terminal panel state ────────────────────────────────────────────
let terminalExpanded = false;
@ -779,6 +781,7 @@
clearFilePreview();
clearSelection();
currentPath = directory;
terminalContext = { terminalId: $selectedTerminalId, currentDirectory: directory };
savedPath = directory;
pushNavHistory(directory);
@ -1552,12 +1555,11 @@
terminalEnabled = config?.features?.terminal !== false;
const serverCwd = await getCwd(terminal.url, terminal.key, chatId ?? undefined);
const useServerPath = !!chatId || savedPath === '/';
const serverPath = applyCwd(serverCwd);
if (useServerPath) {
// Fetch session-specific cwd from the server (or global default for new chats)
savedPath = serverPath;
}
savedPath =
terminalContext && terminalContext.terminalId === $selectedTerminalId
? terminalContext.currentDirectory
: serverPath;
savedPath = clampToFileRoot(savedPath);
loadDir(savedPath, { restoreTree: true });
})();

View file

@ -1,4 +1,5 @@
<script lang="ts">
import type { TerminalContext } from '$lib/types';
import { resolveLocalizedFunction } from '$lib/utils/localizedContent';
import { functions as localizedFunctions } from '$lib/stores';
import DOMPurify from 'dompurify';
@ -151,6 +152,7 @@
export let statusHandler: Function = () => {};
export let forkHandler: Function = () => {};
export let chatId = '';
export let terminalContext: TerminalContext | null = null;
export let contextUsage = null;
export let contextCompactionEnabled = false;
export let embedded = false;
@ -1014,13 +1016,17 @@
if (filesystemUploadTerminal) {
try {
const cwd =
(terminalContext?.terminalId === $selectedTerminalId
? terminalContext?.currentDirectory
: null) ||
(
await getCwd(
filesystemUploadTerminal.url,
filesystemUploadTerminal.key,
chatId || undefined
)
)?.cwd || '/';
)?.cwd;
if (!cwd) throw new Error($i18n.t('Could not determine the upload folder.'));
const uploadedFile = await uploadNewFileToTerminal(
filesystemUploadTerminal.url,
filesystemUploadTerminal.key,

View file

@ -1,4 +1,5 @@
<script lang="ts">
import type { TerminalContext } from '$lib/types';
import { toast } from 'svelte-sonner';
import { marked } from 'marked';
import DOMPurify from 'dompurify';
@ -50,6 +51,7 @@
export let prompt = '';
export let files = [];
export let terminalContext: TerminalContext | null = null;
export let messageInput = null;
export let selectedToolIds = [];
@ -243,6 +245,7 @@
<div class="text-base font-normal @md:max-w-3xl w-full py-3 {atSelectedModel ? 'mt-2' : ''}">
{#if !($selectedFolder && folderReadOnly)}
<MessageInput
{terminalContext}
{callActive}
{callEnabled}
bind:this={messageInput}

View file

@ -14,3 +14,8 @@ export enum TTS_RESPONSE_SPLIT {
PARAGRAPHS = 'paragraphs',
NONE = 'none'
}
export type TerminalContext = {
terminalId: string | null;
currentDirectory: string;
};