mirror of
https://github.com/open-webui/computer.git
synced 2026-11-22 21:50:43 -05:00
refac
This commit is contained in:
1 parent
e7afb6cba3
commit
e68ece23ea
4 files changed
+42
-5
No files matched your search
@@ -95,6 +95,7 @@
|
||||
onqueueedit?: (id: string) => void;
|
||||
onqueuedelete?: (id: string) => void;
|
||||
onsettingschange?: () => void;
|
||||
ontoolapprovalchange?: (mode: ToolApprovalMode) => void;
|
||||
}
|
||||
let {
|
||||
inputText = $bindable(),
|
||||
@@ -123,7 +124,8 @@
|
||||
onqueuesendnow,
|
||||
onqueueedit,
|
||||
onqueuedelete,
|
||||
onsettingschange
|
||||
onsettingschange,
|
||||
ontoolapprovalchange
|
||||
}: Props = $props();
|
||||
|
||||
let editorEl: HTMLDivElement | undefined = $state();
|
||||
@@ -1507,6 +1509,7 @@
|
||||
bind:planMode
|
||||
bind:requestParams
|
||||
onchange={onsettingschange}
|
||||
{ontoolapprovalchange}
|
||||
onfiles={(files) => {
|
||||
if (files) processFiles(Array.from(files));
|
||||
}}
|
||||
|
||||
@@ -35,7 +35,13 @@
|
||||
import { socketStore } from '$lib/stores/socket.svelte';
|
||||
import { onMount, onDestroy, tick } from 'svelte';
|
||||
import { get } from 'svelte/store';
|
||||
import { currentWorkspace, openChatTab, streamingBehavior, widescreenMode } from '$lib/stores';
|
||||
import {
|
||||
currentWorkspace,
|
||||
openChatTab,
|
||||
streamingBehavior,
|
||||
toolApprovalMode as defaultToolApprovalMode,
|
||||
widescreenMode
|
||||
} from '$lib/stores';
|
||||
import { getPathDisplayName } from '$lib/utils/paths';
|
||||
import {
|
||||
ttsEnabled,
|
||||
@@ -663,7 +669,7 @@
|
||||
const dm = get(defaultModel);
|
||||
if (dm) selectedModel = dm;
|
||||
else if (models.length) selectedModel = models[0].id;
|
||||
toolApprovalMode = 'auto';
|
||||
toolApprovalMode = get(defaultToolApprovalMode);
|
||||
planMode = false;
|
||||
requestParams = {};
|
||||
voiceModeEnabled = false;
|
||||
@@ -1062,6 +1068,12 @@
|
||||
persistChatSettings();
|
||||
}
|
||||
|
||||
function handleToolApprovalModeChange(mode: ToolApprovalMode) {
|
||||
toolApprovalMode = mode;
|
||||
defaultToolApprovalMode.set(mode);
|
||||
persistChatSettings();
|
||||
}
|
||||
|
||||
function firstUserMessageTitle(): string {
|
||||
const message = allMessages.find((m) => m.role === 'user' && !isPendingHiddenMessage(m));
|
||||
return message ? message.content.replace(/\s+/g, ' ').trim().slice(0, 80) : '';
|
||||
@@ -1705,6 +1717,7 @@
|
||||
onsend={send}
|
||||
onplan={handlePlanCommand}
|
||||
onsettingschange={persistChatSettings}
|
||||
ontoolapprovalchange={handleToolApprovalModeChange}
|
||||
{queuedMessages}
|
||||
onqueuesendnow={handleQueueSendNow}
|
||||
onqueueedit={handleQueueEdit}
|
||||
@@ -1834,6 +1847,7 @@
|
||||
onfork={handleForkChat}
|
||||
onplan={handlePlanCommand}
|
||||
onsettingschange={persistChatSettings}
|
||||
ontoolapprovalchange={handleToolApprovalModeChange}
|
||||
onstatus={handleStatusCommand}
|
||||
onskillslist={handleSkillsListCommand}
|
||||
oncancel={handleCancel}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
planMode?: boolean;
|
||||
requestParams?: Record<string, unknown>;
|
||||
onchange?: () => void;
|
||||
ontoolapprovalchange?: (mode: ToolApprovalMode) => void;
|
||||
}
|
||||
let {
|
||||
onfiles,
|
||||
@@ -20,7 +21,8 @@
|
||||
toolApprovalMode = $bindable('auto'),
|
||||
planMode = $bindable(false),
|
||||
requestParams = $bindable({}),
|
||||
onchange
|
||||
onchange,
|
||||
ontoolapprovalchange
|
||||
}: Props = $props();
|
||||
|
||||
let open = $state(false);
|
||||
@@ -108,7 +110,8 @@
|
||||
|
||||
function selectMode(mode: ToolApprovalMode) {
|
||||
toolApprovalMode = mode;
|
||||
onchange?.();
|
||||
if (ontoolapprovalchange) ontoolapprovalchange(mode);
|
||||
else onchange?.();
|
||||
}
|
||||
|
||||
function triggerUpload() {
|
||||
|
||||
@@ -110,11 +110,14 @@ export interface HomeState {
|
||||
splitDirection: SplitDirection;
|
||||
}
|
||||
|
||||
export type ToolApprovalMode = 'ask' | 'auto' | 'full';
|
||||
|
||||
export interface UserPreferences {
|
||||
theme?: Theme;
|
||||
appearance?: AppearancePreferences;
|
||||
sidebarOpen: boolean;
|
||||
sidebarWidth: number;
|
||||
toolApprovalMode?: ToolApprovalMode;
|
||||
locale: string;
|
||||
workspaceOrder?: string[]; // ordered paths for sidebar drag-reorder
|
||||
keybindings?: Record<string, string>; // user-customised keyboard shortcuts
|
||||
@@ -298,6 +301,7 @@ if (typeof window !== 'undefined') {
|
||||
}
|
||||
export const sidebarWidth = writable(220);
|
||||
export const theme = writable<Theme>('dark');
|
||||
export const toolApprovalMode = writable<ToolApprovalMode>('auto');
|
||||
export const appVersion = writable('');
|
||||
export const lastSeenVersion = writable('');
|
||||
export const latestVersion = writable('');
|
||||
@@ -422,6 +426,7 @@ function persistPreferences(): void {
|
||||
},
|
||||
sidebarOpen: get(sidebarOpen),
|
||||
sidebarWidth: get(sidebarWidth),
|
||||
toolApprovalMode: get(toolApprovalMode),
|
||||
locale: i18next.language,
|
||||
workspaceOrder: get(workspaceOrder),
|
||||
keybindings: get(keybindings),
|
||||
@@ -459,6 +464,9 @@ function subscribeForPersistence() {
|
||||
sidebarWidth.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
toolApprovalMode.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
workspaceOrder.subscribe(() => {
|
||||
if (get(stateLoaded)) persistPreferences();
|
||||
});
|
||||
@@ -500,6 +508,15 @@ export async function loadPreferences(): Promise<void> {
|
||||
themeConfig.set(sanitizeThemeConfig(appearance.themeConfig));
|
||||
if (prefs.sidebarOpen !== undefined) sidebarOpen.set(prefs.sidebarOpen as boolean);
|
||||
if (prefs.sidebarWidth !== undefined) sidebarWidth.set(prefs.sidebarWidth as number);
|
||||
if (
|
||||
prefs.toolApprovalMode === 'ask' ||
|
||||
prefs.toolApprovalMode === 'auto' ||
|
||||
prefs.toolApprovalMode === 'full'
|
||||
) {
|
||||
toolApprovalMode.set(prefs.toolApprovalMode);
|
||||
} else if (prefs.autoApproveTools !== undefined) {
|
||||
toolApprovalMode.set((prefs.autoApproveTools as boolean) ? 'full' : 'ask');
|
||||
}
|
||||
if (prefs.locale) changeLocale(prefs.locale as string);
|
||||
if (Array.isArray(prefs.workspaceOrder)) workspaceOrder.set(prefs.workspaceOrder as string[]);
|
||||
if (prefs.keybindings) loadKeybindings(prefs.keybindings as Record<string, string>);
|
||||
|
||||
Reference in new issue
Block a user