mirror of
https://github.com/open-webui/open-webui.git
synced 2026-12-03 18:17:56 -05:00
381 lines
14 KiB
Svelte
381 lines
14 KiB
Svelte
<script lang="ts">
|
|
import { onMount, getContext } from 'svelte';
|
|
import { getCodeExecutionConfig, setCodeExecutionConfig } from '$lib/apis/configs';
|
|
|
|
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
|
|
|
|
import Textarea from '$lib/components/common/Textarea.svelte';
|
|
import Switch from '$lib/components/common/Switch.svelte';
|
|
import AdminSettingField from './AdminSettingField.svelte';
|
|
import AdminSettingRow from './AdminSettingRow.svelte';
|
|
import AdminSettingSection from './AdminSettingSection.svelte';
|
|
import AdminSettingSaveButton from './AdminSettingSaveButton.svelte';
|
|
import { getChangedKeys } from '$lib/utils';
|
|
import SettingsSelect from '$lib/components/common/SettingsSelect.svelte';
|
|
|
|
const i18n: any = getContext('i18n');
|
|
|
|
export let saveHandler: Function;
|
|
|
|
let config: any = null;
|
|
let savedConfig: Record<string, any> | null = null;
|
|
|
|
export let dirty = false;
|
|
$: dirty = getChangedKeys(savedConfig, config).length > 0;
|
|
|
|
let engines = ['pyodide', 'jupyter'];
|
|
|
|
$: settingLabels = {
|
|
ENABLE_CODE_EXECUTION: $i18n.t('settings.admin.codeExecution.enableCodeExecution.label'),
|
|
CODE_EXECUTION_ENGINE: $i18n.t('settings.admin.codeExecution.codeExecutionEngine.label'),
|
|
CODE_EXECUTION_JUPYTER_URL: $i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterUrl.label'
|
|
),
|
|
CODE_EXECUTION_JUPYTER_AUTH: $i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterAuth.label'
|
|
),
|
|
CODE_EXECUTION_JUPYTER_AUTH_PASSWORD: $i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterAuthPassword.label'
|
|
),
|
|
CODE_EXECUTION_JUPYTER_AUTH_TOKEN: $i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterAuthToken.label'
|
|
),
|
|
CODE_EXECUTION_JUPYTER_TIMEOUT: $i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterTimeout.label'
|
|
),
|
|
ENABLE_CODE_INTERPRETER: $i18n.t('settings.admin.codeExecution.enableCodeInterpreter.label'),
|
|
CODE_INTERPRETER_ENGINE: $i18n.t('settings.admin.codeExecution.codeInterpreterEngine.label'),
|
|
CODE_INTERPRETER_JUPYTER_URL: $i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterUrl.label'
|
|
),
|
|
CODE_INTERPRETER_JUPYTER_AUTH: $i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterAuth.label'
|
|
),
|
|
CODE_INTERPRETER_JUPYTER_AUTH_PASSWORD: $i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterAuthPassword.label'
|
|
),
|
|
CODE_INTERPRETER_JUPYTER_AUTH_TOKEN: $i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterAuthToken.label'
|
|
),
|
|
CODE_INTERPRETER_JUPYTER_TIMEOUT: $i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterTimeout.label'
|
|
),
|
|
CODE_INTERPRETER_PROMPT_TEMPLATE: $i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterPromptTemplate.label'
|
|
)
|
|
};
|
|
const sensitiveKeys = [
|
|
'CODE_EXECUTION_JUPYTER_AUTH_PASSWORD',
|
|
'CODE_EXECUTION_JUPYTER_AUTH_TOKEN',
|
|
'CODE_INTERPRETER_JUPYTER_AUTH_PASSWORD',
|
|
'CODE_INTERPRETER_JUPYTER_AUTH_TOKEN'
|
|
];
|
|
const inputClass =
|
|
'w-full h-7 rounded-lg border border-base-100/50 bg-base-50/40 px-2 text-xs text-base-700 outline-hidden transition-colors placeholder:text-base-300 focus:border-blue-400 dark:border-base-0/[0.04] dark:bg-base-0/[0.03] dark:text-base-300 dark:placeholder:text-base-700 dark:focus:border-blue-500';
|
|
const textareaClass =
|
|
'w-full rounded-lg border border-base-100/50 bg-base-50/40 px-2 py-1.5 text-xs text-base-700 outline-hidden transition-colors placeholder:text-base-300 focus:border-blue-400 dark:border-base-0/[0.04] dark:bg-base-0/[0.03] dark:text-base-300 dark:placeholder:text-base-700 dark:focus:border-blue-500';
|
|
|
|
const submitHandler = async () => {
|
|
const res = await setCodeExecutionConfig(localStorage.token, config);
|
|
if (res) {
|
|
savedConfig = structuredClone(config);
|
|
}
|
|
};
|
|
|
|
onMount(async () => {
|
|
const res = await getCodeExecutionConfig(localStorage.token);
|
|
|
|
if (res) {
|
|
config = res;
|
|
savedConfig = structuredClone(res);
|
|
}
|
|
});
|
|
</script>
|
|
|
|
<form
|
|
class="flex h-full flex-col justify-between text-sm"
|
|
on:submit|preventDefault={async () => {
|
|
await submitHandler();
|
|
saveHandler();
|
|
}}
|
|
>
|
|
<h2 class="text-sm font-medium text-base-900 dark:text-base-0 mb-4">
|
|
{$i18n.t('settings.admin.codeExecution.title')}
|
|
</h2>
|
|
|
|
<div class="flex-1 min-h-0 overflow-y-auto scrollbar-hover pr-1.5">
|
|
{#if config}
|
|
<AdminSettingSection
|
|
title={$i18n.t('settings.admin.codeExecution.sections.codeExecution.title')}
|
|
first
|
|
>
|
|
<AdminSettingRow
|
|
label={$i18n.t('settings.admin.codeExecution.enableCodeExecution.label')}
|
|
description={$i18n.t('settings.admin.codeExecution.enableCodeExecution.description')}
|
|
let:labelId
|
|
>
|
|
<Switch bind:state={config.ENABLE_CODE_EXECUTION} ariaLabelledbyId={labelId} />
|
|
</AdminSettingRow>
|
|
|
|
{#if config.ENABLE_CODE_EXECUTION}
|
|
<AdminSettingRow
|
|
label={$i18n.t('settings.admin.codeExecution.codeExecutionEngine.label')}
|
|
description={config.CODE_EXECUTION_ENGINE === 'jupyter'
|
|
? $i18n.t(
|
|
'Warning: Jupyter execution enables arbitrary code execution, posing severe security risks\u2014proceed with extreme caution.'
|
|
)
|
|
: $i18n.t('settings.admin.codeExecution.codeExecutionEngine.description')}
|
|
let:labelId
|
|
>
|
|
<SettingsSelect
|
|
id={`${labelId}-control`}
|
|
bind:value={config.CODE_EXECUTION_ENGINE}
|
|
placeholder={$i18n.t('Select a engine')}
|
|
required
|
|
>
|
|
<option disabled selected value="">{$i18n.t('Select a engine')}</option>
|
|
{#each engines as engine}
|
|
<option value={engine}>{engine}{engine === 'jupyter' ? ' (Legacy)' : ''}</option>
|
|
{/each}
|
|
</SettingsSelect>
|
|
</AdminSettingRow>
|
|
|
|
{#if config.CODE_EXECUTION_ENGINE === 'jupyter'}
|
|
<AdminSettingField
|
|
label={$i18n.t('settings.admin.codeExecution.codeExecutionJupyterUrl.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterUrl.description'
|
|
)}
|
|
forId="code-execution-jupyter-url"
|
|
>
|
|
<input
|
|
id="code-execution-jupyter-url"
|
|
class={inputClass}
|
|
type="text"
|
|
placeholder={$i18n.t('Enter Jupyter URL')}
|
|
bind:value={config.CODE_EXECUTION_JUPYTER_URL}
|
|
autocomplete="off"
|
|
/>
|
|
</AdminSettingField>
|
|
|
|
<!-- LICENSE covers this Open WebUI wordmark.
|
|
Do not alter, remove, obscure, or replace it except as LICENSE permits:
|
|
https://docs.openwebui.com/license. -->
|
|
<AdminSettingRow
|
|
label={$i18n.t('settings.admin.codeExecution.codeExecutionJupyterAuth.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterAuth.description'
|
|
)}
|
|
let:labelId
|
|
>
|
|
<SettingsSelect
|
|
id={`${labelId}-control`}
|
|
bind:value={config.CODE_EXECUTION_JUPYTER_AUTH}
|
|
placeholder={$i18n.t('Select an auth method')}
|
|
>
|
|
<option selected value="">{$i18n.t('None')}</option>
|
|
<option value="token">{$i18n.t('Token')}</option>
|
|
<option value="password">{$i18n.t('Password')}</option>
|
|
</SettingsSelect>
|
|
</AdminSettingRow>
|
|
|
|
{#if config.CODE_EXECUTION_JUPYTER_AUTH}
|
|
<AdminSettingField
|
|
label={config.CODE_EXECUTION_JUPYTER_AUTH === 'password'
|
|
? $i18n.t('settings.admin.codeExecution.codeExecutionJupyterAuthPassword.label')
|
|
: $i18n.t('settings.admin.codeExecution.codeExecutionJupyterAuthToken.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterAuthPassword.description'
|
|
)}
|
|
>
|
|
{#if config.CODE_EXECUTION_JUPYTER_AUTH === 'password'}
|
|
<SensitiveInput
|
|
variant="settings"
|
|
type="text"
|
|
placeholder={$i18n.t('Enter Jupyter Password')}
|
|
bind:value={config.CODE_EXECUTION_JUPYTER_AUTH_PASSWORD}
|
|
autocomplete="off"
|
|
/>
|
|
{:else}
|
|
<SensitiveInput
|
|
variant="settings"
|
|
type="text"
|
|
placeholder={$i18n.t('Enter Jupyter Token')}
|
|
bind:value={config.CODE_EXECUTION_JUPYTER_AUTH_TOKEN}
|
|
autocomplete="off"
|
|
/>
|
|
{/if}
|
|
</AdminSettingField>
|
|
{/if}
|
|
|
|
<AdminSettingField
|
|
label={$i18n.t('settings.admin.codeExecution.codeExecutionJupyterTimeout.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeExecutionJupyterTimeout.description'
|
|
)}
|
|
forId="code-execution-jupyter-timeout"
|
|
>
|
|
<input
|
|
id="code-execution-jupyter-timeout"
|
|
class={inputClass}
|
|
type="number"
|
|
bind:value={config.CODE_EXECUTION_JUPYTER_TIMEOUT}
|
|
placeholder={$i18n.t('e.g. 60')}
|
|
autocomplete="off"
|
|
/>
|
|
</AdminSettingField>
|
|
{/if}
|
|
{/if}
|
|
</AdminSettingSection>
|
|
|
|
<AdminSettingSection
|
|
title={$i18n.t('settings.admin.codeExecution.sections.codeInterpreter.title')}
|
|
>
|
|
<AdminSettingRow
|
|
label={$i18n.t('settings.admin.codeExecution.enableCodeInterpreter.label')}
|
|
description={$i18n.t('settings.admin.codeExecution.enableCodeInterpreter.description')}
|
|
let:labelId
|
|
>
|
|
<Switch bind:state={config.ENABLE_CODE_INTERPRETER} ariaLabelledbyId={labelId} />
|
|
</AdminSettingRow>
|
|
|
|
{#if config.ENABLE_CODE_INTERPRETER}
|
|
<AdminSettingRow
|
|
label={$i18n.t('settings.admin.codeExecution.codeInterpreterEngine.label')}
|
|
description={config.CODE_INTERPRETER_ENGINE === 'jupyter'
|
|
? $i18n.t(
|
|
'Warning: Jupyter execution enables arbitrary code execution, posing severe security risks\u2014proceed with extreme caution.'
|
|
)
|
|
: $i18n.t('settings.admin.codeExecution.codeInterpreterEngine.description')}
|
|
let:labelId
|
|
>
|
|
<SettingsSelect
|
|
id={`${labelId}-control`}
|
|
bind:value={config.CODE_INTERPRETER_ENGINE}
|
|
placeholder={$i18n.t('Select a engine')}
|
|
required
|
|
>
|
|
<option disabled selected value="">{$i18n.t('Select a engine')}</option>
|
|
{#each engines as engine}
|
|
<option value={engine}>{engine}{engine === 'jupyter' ? ' (Legacy)' : ''}</option>
|
|
{/each}
|
|
</SettingsSelect>
|
|
</AdminSettingRow>
|
|
|
|
{#if config.CODE_INTERPRETER_ENGINE === 'jupyter'}
|
|
<AdminSettingField
|
|
label={$i18n.t('settings.admin.codeExecution.codeInterpreterJupyterUrl.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterUrl.description'
|
|
)}
|
|
forId="code-interpreter-jupyter-url"
|
|
>
|
|
<input
|
|
id="code-interpreter-jupyter-url"
|
|
class={inputClass}
|
|
type="text"
|
|
placeholder={$i18n.t('Enter Jupyter URL')}
|
|
bind:value={config.CODE_INTERPRETER_JUPYTER_URL}
|
|
autocomplete="off"
|
|
/>
|
|
</AdminSettingField>
|
|
|
|
<!-- LICENSE covers this Open WebUI wordmark.
|
|
Do not alter, remove, obscure, or replace it except as LICENSE permits:
|
|
https://docs.openwebui.com/license. -->
|
|
<AdminSettingRow
|
|
label={$i18n.t('settings.admin.codeExecution.codeInterpreterJupyterAuth.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterAuth.description'
|
|
)}
|
|
let:labelId
|
|
>
|
|
<SettingsSelect
|
|
id={`${labelId}-control`}
|
|
bind:value={config.CODE_INTERPRETER_JUPYTER_AUTH}
|
|
placeholder={$i18n.t('Select an auth method')}
|
|
>
|
|
<option selected value="">{$i18n.t('None')}</option>
|
|
<option value="token">{$i18n.t('Token')}</option>
|
|
<option value="password">{$i18n.t('Password')}</option>
|
|
</SettingsSelect>
|
|
</AdminSettingRow>
|
|
|
|
{#if config.CODE_INTERPRETER_JUPYTER_AUTH}
|
|
<AdminSettingField
|
|
label={config.CODE_INTERPRETER_JUPYTER_AUTH === 'password'
|
|
? $i18n.t('settings.admin.codeExecution.codeInterpreterJupyterAuthPassword.label')
|
|
: $i18n.t('settings.admin.codeExecution.codeInterpreterJupyterAuthToken.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterAuthPassword.description'
|
|
)}
|
|
>
|
|
{#if config.CODE_INTERPRETER_JUPYTER_AUTH === 'password'}
|
|
<SensitiveInput
|
|
variant="settings"
|
|
type="text"
|
|
placeholder={$i18n.t('Enter Jupyter Password')}
|
|
bind:value={config.CODE_INTERPRETER_JUPYTER_AUTH_PASSWORD}
|
|
autocomplete="off"
|
|
/>
|
|
{:else}
|
|
<SensitiveInput
|
|
variant="settings"
|
|
type="text"
|
|
placeholder={$i18n.t('Enter Jupyter Token')}
|
|
bind:value={config.CODE_INTERPRETER_JUPYTER_AUTH_TOKEN}
|
|
autocomplete="off"
|
|
/>
|
|
{/if}
|
|
</AdminSettingField>
|
|
{/if}
|
|
|
|
<AdminSettingField
|
|
label={$i18n.t('settings.admin.codeExecution.codeInterpreterJupyterTimeout.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterJupyterTimeout.description'
|
|
)}
|
|
forId="code-interpreter-jupyter-timeout"
|
|
>
|
|
<input
|
|
id="code-interpreter-jupyter-timeout"
|
|
class={inputClass}
|
|
type="number"
|
|
bind:value={config.CODE_INTERPRETER_JUPYTER_TIMEOUT}
|
|
placeholder={$i18n.t('e.g. 60')}
|
|
autocomplete="off"
|
|
/>
|
|
</AdminSettingField>
|
|
{/if}
|
|
|
|
<AdminSettingField
|
|
label={$i18n.t('settings.admin.codeExecution.codeInterpreterPromptTemplate.label')}
|
|
description={$i18n.t(
|
|
'settings.admin.codeExecution.codeInterpreterPromptTemplate.description'
|
|
)}
|
|
forId="code-interpreter-prompt-template"
|
|
>
|
|
<Textarea
|
|
id="code-interpreter-prompt-template"
|
|
className={textareaClass}
|
|
bind:value={config.CODE_INTERPRETER_PROMPT_TEMPLATE}
|
|
maxSize={300}
|
|
placeholder={$i18n.t(
|
|
'Leave empty to use the default prompt, or enter a custom prompt'
|
|
)}
|
|
/>
|
|
</AdminSettingField>
|
|
{/if}
|
|
</AdminSettingSection>
|
|
{/if}
|
|
</div>
|
|
<div class="flex justify-end pt-6 text-sm font-normal">
|
|
<AdminSettingSaveButton
|
|
settings={config}
|
|
{savedConfig}
|
|
labels={settingLabels}
|
|
{sensitiveKeys}
|
|
/>
|
|
</div>
|
|
</form>
|