Files
open-webui/src/lib/components/admin/Settings/Subagents.svelte
T
2026-11-02 17:49:51 +09:00

228 lines
8.3 KiB
Svelte

<script lang="ts">
import AdminSettingRow from './AdminSettingRow.svelte';
import { getContext, onMount } from 'svelte';
import { toast } from 'svelte-sonner';
import { config as appConfig } from '$lib/stores';
import { getBackendConfig } from '$lib/apis';
import { getSubagentsConfig, setSubagentsConfig } from '$lib/apis/configs';
import Spinner from '$lib/components/common/Spinner.svelte';
import Switch from '$lib/components/common/Switch.svelte';
const i18n = getContext('i18n');
let loading = true;
let saving = false;
let enabled = false;
let backgroundEnabled = false;
let maxConcurrent: number | null = null;
let maxAsync: number | null = null;
let maxIterations: number | null = null;
let maxOutput: number | null = null;
let systemPrompt = '';
onMount(async () => {
try {
const config = await getSubagentsConfig(localStorage.token);
enabled = config?.ENABLE_SUBAGENTS ?? false;
backgroundEnabled = config?.SUBAGENTS_BACKGROUND_ENABLED ?? false;
maxConcurrent = config?.SUBAGENTS_MAX_CONCURRENT ?? null;
maxAsync = config?.SUBAGENTS_MAX_ASYNC ?? null;
maxIterations = config?.SUBAGENTS_MAX_ITERATIONS ?? null;
maxOutput = config?.SUBAGENTS_MAX_OUTPUT ?? null;
systemPrompt = config?.SUBAGENTS_SYSTEM_PROMPT ?? '';
} catch (error) {
toast.error(`${error}`);
} finally {
loading = false;
}
});
const save = async () => {
saving = true;
try {
await setSubagentsConfig(localStorage.token, {
ENABLE_SUBAGENTS: enabled,
SUBAGENTS_BACKGROUND_ENABLED: backgroundEnabled,
SUBAGENTS_MAX_CONCURRENT: maxConcurrent ?? null,
SUBAGENTS_MAX_ASYNC: maxAsync ?? null,
SUBAGENTS_MAX_ITERATIONS: maxIterations ?? null,
SUBAGENTS_MAX_OUTPUT: maxOutput ?? null,
SUBAGENTS_SYSTEM_PROMPT: systemPrompt
});
await appConfig.set(await getBackendConfig());
toast.success($i18n.t('Settings saved successfully!'));
} catch (error) {
toast.error(`${error}`);
} finally {
saving = false;
}
};
</script>
<form class="flex h-full flex-col justify-between text-sm" on:submit|preventDefault={save}>
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">
{$i18n.t('settings.admin.subagents.title')}
</h2>
<div class="flex-1 min-h-0 overflow-y-auto scrollbar-hover pr-1.5">
{#if loading}
<div class="flex justify-center py-8"><Spinner className="size-6" /></div>
{:else}
<div class="flex flex-col gap-2.5">
<AdminSettingRow let:labelId>
<span slot="label">
{$i18n.t('settings.admin.subagents.enableSubAgents.label')}
</span>
<Switch ariaLabelledbyId={labelId} bind:state={enabled} />
</AdminSettingRow>
<p class="-mt-1 text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$i18n.t(
'Allow the AI to delegate tasks to sub-agents. Each sub-agent creates a real chat with full tool access. Uses additional LLM calls.'
)}
</p>
{#if enabled}
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="sa-concurrent">
{$i18n.t('settings.admin.subagents.maxConcurrent.label')}
</label>
<div class="mt-1 flex items-center gap-1.5">
<input
id="sa-concurrent"
type="number"
bind:value={maxConcurrent}
min="1"
step="1"
aria-describedby="sa-concurrent-help"
class="h-7 w-16 rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-xs text-gray-700 outline-hidden transition-colors focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:focus:border-blue-500"
/>
<span class="text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$i18n.t('simultaneous sub-agents')}
</span>
</div>
<p
id="sa-concurrent-help"
class="mt-1 text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{$i18n.t('Leave empty for unlimited')}
</p>
</div>
<div>
<AdminSettingRow let:labelId>
<span slot="label">
{$i18n.t('settings.admin.subagents.enableBackgroundSubAgents.label')}
</span>
<Switch ariaLabelledbyId={labelId} bind:state={backgroundEnabled} />
</AdminSettingRow>
<p class="mt-1 text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$i18n.t('settings.admin.subagents.enableBackgroundSubAgents.description')}
</p>
</div>
{#if backgroundEnabled}
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="sa-async">
{$i18n.t('settings.admin.subagents.maxBackground.label')}
</label>
<div class="mt-1 flex items-center gap-1.5">
<input
id="sa-async"
type="number"
bind:value={maxAsync}
min="1"
step="1"
aria-describedby="sa-async-help"
class="h-7 w-16 rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-xs text-gray-700 outline-hidden transition-colors focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:focus:border-blue-500"
/>
<span class="text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$i18n.t('background sub-agents')}
</span>
</div>
<p id="sa-async-help" class="mt-1 text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$i18n.t('Leave empty for unlimited')}
</p>
</div>
{/if}
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="sa-iterations">
{$i18n.t('settings.admin.subagents.maxIterations.label')}
</label>
<div class="mt-1 flex items-center gap-1.5">
<input
id="sa-iterations"
type="number"
bind:value={maxIterations}
min="1"
step="1"
aria-describedby="sa-iterations-help"
class="h-7 w-16 rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-xs text-gray-700 outline-hidden transition-colors focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:focus:border-blue-500"
/>
<span class="text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$i18n.t('tool loops per sub-agent')}
</span>
</div>
<p
id="sa-iterations-help"
class="mt-1 text-[0.6875rem] text-gray-400 dark:text-gray-600"
>
{$i18n.t('Leave empty for unlimited')}
</p>
</div>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="sa-output">
{$i18n.t('settings.admin.subagents.maxOutput.label')}
</label>
<div class="mt-1 flex items-center gap-1.5">
<input
id="sa-output"
type="number"
bind:value={maxOutput}
min="1"
step="1"
aria-describedby="sa-output-help"
class="h-7 w-20 rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-xs text-gray-700 outline-hidden transition-colors focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:focus:border-blue-500"
/>
<span class="text-[0.6875rem] text-gray-400 dark:text-gray-600">chars</span>
</div>
<p id="sa-output-help" class="mt-1 text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$i18n.t('Leave empty for unlimited')}
</p>
</div>
<div>
<label class="text-xs text-gray-600 dark:text-gray-400" for="sa-prompt">
{$i18n.t('settings.admin.subagents.systemPrompt.label')}
</label>
<textarea
id="sa-prompt"
bind:value={systemPrompt}
rows="4"
placeholder={$i18n.t('You are a sub-agent...')}
class="mt-1 w-full resize-y rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 py-1.5 font-mono text-xs text-gray-700 outline-hidden transition-colors focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:focus:border-blue-500"
></textarea>
<p class="mt-0.5 text-[0.6875rem] text-gray-400 dark:text-gray-600">
{$i18n.t('settings.admin.subagents.systemPrompt.description')}
</p>
</div>
{/if}
</div>
{/if}
</div>
{#if !loading}
<div class="flex justify-end pt-6 text-sm font-normal">
<button
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-gray-900 px-2.5 text-xs font-normal text-white transition hover:bg-black disabled:opacity-60 dark:bg-gray-100 dark:text-gray-900 dark:hover:bg-white"
type="submit"
disabled={saving}
>
{$i18n.t('Save')}
</button>
</div>
{/if}
</form>