mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-15 09:31:21 +00:00
refac
This commit is contained in:
parent
34be5d8f67
commit
748e52b625
3 changed files with 28 additions and 18 deletions
|
|
@ -103,6 +103,7 @@
|
|||
let viewportWidth = 0;
|
||||
|
||||
let tabs = emptyTabs();
|
||||
let sideChatNumber = 0;
|
||||
let terminalViews: Record<string, XTerminal> = {};
|
||||
export const hasTerminals = () => tabs.tabs.some((tab) => tab.kind === 'terminal');
|
||||
export async function bindTerminalChat(id: string) {
|
||||
|
|
@ -259,6 +260,18 @@
|
|||
const openFeature = (kind: 'artifacts' | 'preview' | 'voice' | 'comments' | 'side') => {
|
||||
if (!availableViews.some((view) => view.kind === kind && view.available)) return;
|
||||
const view = availableViews.find((view) => view.kind === kind)!;
|
||||
if (kind === 'side') {
|
||||
const pending = $sideChatRequest;
|
||||
const initialPrompt = pending?.parentId === chatId ? pending.prompt : '';
|
||||
if (pending?.parentId === chatId) sideChatRequest.set(null);
|
||||
openPanel({
|
||||
id: crypto.randomUUID(),
|
||||
kind,
|
||||
label: `${view.label} ${++sideChatNumber}`,
|
||||
initialPrompt
|
||||
});
|
||||
return;
|
||||
}
|
||||
openPanel({ id: kind, kind, label: view.label });
|
||||
};
|
||||
const newTerminal = () => {
|
||||
|
|
@ -579,6 +592,7 @@
|
|||
$: if (chatId !== tabsChatId) {
|
||||
if (tabsChatId || !chatId) {
|
||||
tabs = emptyTabs();
|
||||
sideChatNumber = 0;
|
||||
hasOpenedTabs = false;
|
||||
dirtyFiles = {};
|
||||
fileContexts = {};
|
||||
|
|
@ -924,9 +938,9 @@
|
|||
<Embeds overlay={dragged} />
|
||||
{:else if tab.kind === 'artifacts'}
|
||||
<Artifacts overlay={dragged} />
|
||||
{:else if tab.kind === 'side' && chatId}
|
||||
<SideChat parentId={chatId} {history} {modelId} {systemPrompt} />
|
||||
{:else if tab.kind === 'comments' && currentComments}
|
||||
{:else if tab.kind === 'side' && chatId}
|
||||
<SideChat {history} {modelId} {systemPrompt} initialPrompt={tab.initialPrompt ?? ''} />
|
||||
{:else if tab.kind === 'comments' && currentComments}
|
||||
{#key `${$user?.id}:${chatId}:${currentComments.comment_id ?? ''}`}
|
||||
<CommentsPanel
|
||||
embedded={true}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
socket,
|
||||
user,
|
||||
openTemporaryChatIds,
|
||||
sideChatRequest,
|
||||
models,
|
||||
settings,
|
||||
config,
|
||||
|
|
@ -24,7 +23,7 @@
|
|||
import ElicitationDialog from '../ElicitationDialog.svelte';
|
||||
import { isRasterImageContentType } from '$lib/utils';
|
||||
|
||||
export let parentId: string;
|
||||
export let initialPrompt = '';
|
||||
export let history;
|
||||
export let modelId: string;
|
||||
export let systemPrompt = '';
|
||||
|
|
@ -95,7 +94,6 @@
|
|||
let draft = '';
|
||||
let error = '';
|
||||
let busy = false;
|
||||
let ready = false;
|
||||
let disposed = false;
|
||||
let request: Promise<any> | null = null;
|
||||
let scroller: HTMLDivElement;
|
||||
|
|
@ -356,23 +354,20 @@
|
|||
if (busy) void stop();
|
||||
}
|
||||
|
||||
$: if (ready && $sideChatRequest?.parentId === parentId) {
|
||||
const pending = $sideChatRequest;
|
||||
sideChatRequest.set(null);
|
||||
if (sideChatAllowed && pending.prompt) {
|
||||
draft = pending.prompt;
|
||||
input?.setText(draft);
|
||||
if (!busy) void send();
|
||||
}
|
||||
input?.focus();
|
||||
}
|
||||
onMount(() => {
|
||||
const connection = $socket;
|
||||
connection?.on('events', receive);
|
||||
connection?.on('connect', reconnect);
|
||||
connection?.on('disconnect', cancelInteractions);
|
||||
ready = true;
|
||||
input?.focus();
|
||||
void tick().then(() => {
|
||||
if (disposed) return;
|
||||
if (sideChatAllowed && initialPrompt) {
|
||||
draft = initialPrompt;
|
||||
input?.setText(draft);
|
||||
void send();
|
||||
}
|
||||
input?.focus();
|
||||
});
|
||||
return () => {
|
||||
disposed = true;
|
||||
connection?.off('events', receive);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ export type PanelTab = {
|
|||
id: string;
|
||||
kind: PanelTabKind;
|
||||
label: string;
|
||||
initialPrompt?: string;
|
||||
terminalId?: string;
|
||||
terminalNumber?: number;
|
||||
path?: string;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue