Files
open-webui/src/lib/components/chat/Settings/Account.svelte
T
2026-12-02 23:39:17 +04:00

858 lines
29 KiB
Svelte

<script lang="ts">
import {
canEditParameters,
canEditSystemPrompt as allowSystemPrompt,
canUseApiKeys
} from '$lib/utils/settings-access';
import { toast } from 'svelte-sonner';
import { onMount, getContext } from 'svelte';
import { user, config, settings } from '$lib/stores';
import {
updateUserProfile,
createAPIKey,
deleteAPIKey,
getAPIKey,
getSessionUser
} from '$lib/apis/auths';
import { getUserVariables, updateUserBanner, updateUserVariables } from '$lib/apis/users';
import { WEBUI_API_BASE_URL } from '$lib/constants';
import UpdatePassword from './Account/UpdatePassword.svelte';
import Mfa from './Account/Mfa.svelte';
import { generateInitialsImage } from '$lib/utils';
import { copyToClipboard } from '$lib/utils';
import Dropdown from '$lib/components/common/Dropdown.svelte';
import DropdownMenu from '$lib/components/common/DropdownMenu.svelte';
import EllipsisHorizontal from '$lib/components/icons/EllipsisHorizontal.svelte';
import Plus from '$lib/components/icons/Plus.svelte';
import Refresh from '$lib/components/icons/Refresh.svelte';
import XMark from '$lib/components/icons/XMark.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import SensitiveInput from '$lib/components/common/SensitiveInput.svelte';
import Textarea from '$lib/components/common/Textarea.svelte';
import Modal from '$lib/components/common/Modal.svelte';
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
import UserProfileBanner from './Account/UserProfileBanner.svelte';
import UserProfileImage from './Account/UserProfileImage.svelte';
import UserSettingField from './UserSettingField.svelte';
import UserSettingRow from './UserSettingRow.svelte';
import SettingsSelect from '$lib/components/common/SettingsSelect.svelte';
import UserSettingSection from './UserSettingSection.svelte';
import AdvancedParams from './Advanced/AdvancedParams.svelte';
import ChevronRight from '$lib/components/icons/ChevronRight.svelte';
import ModelSettingsSection from '$lib/components/workspace/Models/ModelSettingsSection.svelte';
const i18n = getContext('i18n');
export let saveHandler: () => void | Promise<void>;
export let saveSettings: Function;
let profileImageUrl = '';
let savedBannerUrl: string | null = null;
let bannerUrl: string | null = null;
let bannerFile: File | null = null;
let name = '';
let bio = '';
let _gender = '';
let gender = '';
let dateOfBirth = '';
let showAPIKeys = false;
let JWTTokenCopied = false;
let APIKey = '';
let APIKeyCopied = false;
let showAPIKeyMenu = false;
let showDeleteAPIKeyConfirm = false;
let variableRows: { key: string; value: string }[] = [];
let variableModalOpen = false;
let variableFormIndex: number | null = null;
let variableFormKey = '';
let variableFormValue = '';
const textareaClass =
'w-full resize-y 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 inputClass =
'h-7 w-full 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 variableValueClass =
'w-full resize-none 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 actionButtonClass =
'text-xs text-base-500 transition-colors hover:text-base-900 dark:text-base-500 dark:hover:text-base-0';
const variableRowClass = 'flex w-full items-center gap-1.5';
const variableKeyRegex = /^[a-z][a-z0-9_]*$/;
const setVariableRows = (variables = {}) => {
variableRows = Object.entries(variables).map(([key, value]) => ({
key,
value: String(value ?? '')
}));
};
const openVariableModal = (idx: number | null = null) => {
const row = idx === null ? null : variableRows[idx];
variableFormIndex = idx;
variableFormKey = row?.key ?? '';
variableFormValue = row?.value ?? '';
variableModalOpen = true;
};
const removeVariable = (idx: number) => {
variableRows = variableRows.filter((_, rowIdx) => rowIdx !== idx);
};
const saveVariableForm = () => {
const key = variableFormKey.trim();
if (!variableKeyRegex.test(key)) {
toast.error($i18n.t('Variable keys must use lowercase snake case.'));
return;
}
if (variableRows.some((row, idx) => idx !== variableFormIndex && row.key === key)) {
toast.error($i18n.t('Variable keys must be unique.'));
return;
}
const row = { key, value: variableFormValue ?? '' };
variableRows =
variableFormIndex === null
? [...variableRows, row]
: variableRows.map((current, idx) => (idx === variableFormIndex ? row : current));
variableModalOpen = false;
};
const deleteVariableForm = () => {
if (variableFormIndex !== null) {
removeVariable(variableFormIndex);
}
variableModalOpen = false;
};
const getVariablesPayload = () => {
const variables: Record<string, string> = {};
for (const row of variableRows) {
const key = row.key.trim();
if (!key && !row.value) {
continue;
}
if (!variableKeyRegex.test(key)) {
throw $i18n.t('Variable keys must use lowercase snake case.');
}
if (Object.prototype.hasOwnProperty.call(variables, key)) {
throw $i18n.t('Variable keys must be unique.');
}
variables[key] = row.value ?? '';
}
return variables;
};
const bannerSrc = (userId: string, url: string | null) =>
url
? `${WEBUI_API_BASE_URL}/users/${userId}/profile/banner?v=${encodeURIComponent(url)}`
: null;
const saveBanner = async () => {
if (!bannerFile && bannerUrl === savedBannerUrl) return true;
const res = await updateUserBanner(localStorage.token, bannerFile).catch((error) => {
toast.error(`${error}`);
return null;
});
if (!res) return false;
savedBannerUrl = bannerUrl = bannerSrc($user?.id ?? '', res.profile_banner_image_url);
bannerFile = null;
return true;
};
// System prompt and model parameters, kept under the collapsed Advanced section.
let system = '';
const systemPromptTextareaClass =
'w-full resize-y 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';
let params = {
// Advanced
stream_response: null,
stream_delta_chunk_size: null,
compact_token_threshold: null,
function_calling: null,
reasoning_tags: null,
seed: null,
temperature: null,
reasoning_effort: null,
logit_bias: null,
frequency_penalty: null,
presence_penalty: null,
repeat_penalty: null,
repeat_last_n: null,
mirostat: null,
mirostat_eta: null,
mirostat_tau: null,
top_k: null,
top_p: null,
min_p: null,
stop: null,
tfs_z: null,
num_ctx: null,
num_batch: null,
num_keep: null,
max_tokens: null,
use_mmap: null,
use_mlock: null,
num_thread: null,
num_gpu: null,
think: null,
format: null,
keep_alive: null
};
$: canEditSystemPrompt = allowSystemPrompt({ user: $user, config: $config });
$: canEditParams = canEditParameters({ user: $user, config: $config });
const saveAdvancedSettings = async () => {
if (!canEditSystemPrompt && !canEditParams) return true;
const updated: Record<string, any> = {};
if (canEditSystemPrompt) {
updated.system = system !== '' ? system : null;
}
if (canEditParams) {
updated.params = {
...$settings.params,
stream_response: params.stream_response !== null ? params.stream_response : undefined,
stream_delta_chunk_size:
params.stream_delta_chunk_size !== null ? params.stream_delta_chunk_size : undefined,
compact_token_threshold:
params.compact_token_threshold !== null ? params.compact_token_threshold : undefined,
function_calling: params.function_calling !== null ? params.function_calling : undefined,
reasoning_tags: params.reasoning_tags !== null ? params.reasoning_tags : undefined,
seed: (params.seed !== null ? params.seed : undefined) ?? undefined,
stop: params.stop ? params.stop.split(',').filter((e) => e) : undefined,
temperature: params.temperature !== null ? params.temperature : undefined,
reasoning_effort: params.reasoning_effort !== null ? params.reasoning_effort : undefined,
logit_bias: params.logit_bias !== null ? params.logit_bias : undefined,
frequency_penalty: params.frequency_penalty !== null ? params.frequency_penalty : undefined,
presence_penalty: params.presence_penalty !== null ? params.presence_penalty : undefined,
repeat_penalty: params.repeat_penalty !== null ? params.repeat_penalty : undefined,
repeat_last_n: params.repeat_last_n !== null ? params.repeat_last_n : undefined,
mirostat: params.mirostat !== null ? params.mirostat : undefined,
mirostat_eta: params.mirostat_eta !== null ? params.mirostat_eta : undefined,
mirostat_tau: params.mirostat_tau !== null ? params.mirostat_tau : undefined,
top_k: params.top_k !== null ? params.top_k : undefined,
top_p: params.top_p !== null ? params.top_p : undefined,
min_p: params.min_p !== null ? params.min_p : undefined,
tfs_z: params.tfs_z !== null ? params.tfs_z : undefined,
num_ctx: params.num_ctx !== null ? params.num_ctx : undefined,
num_batch: params.num_batch !== null ? params.num_batch : undefined,
num_keep: params.num_keep !== null ? params.num_keep : undefined,
max_tokens: params.max_tokens !== null ? params.max_tokens : undefined,
use_mmap: params.use_mmap !== null ? params.use_mmap : undefined,
use_mlock: params.use_mlock !== null ? params.use_mlock : undefined,
num_thread: params.num_thread !== null ? params.num_thread : undefined,
num_gpu: params.num_gpu !== null ? params.num_gpu : undefined,
think: params.think !== null ? params.think : undefined,
keep_alive: params.keep_alive !== null ? params.keep_alive : undefined,
format: params.format !== null ? params.format : undefined,
custom_params:
params.custom_params && Object.keys(params.custom_params).length > 0
? params.custom_params
: undefined
};
}
try {
await saveSettings(updated);
return true;
} catch {
// The settings modal displays the save error; do not report success.
return false;
}
};
const submitHandler = async () => {
let variables: Record<string, string>;
try {
variables = getVariablesPayload();
} catch (error) {
toast.error(`${error}`);
return false;
}
if (name !== $user?.name) {
if (profileImageUrl === generateInitialsImage($user?.name) || profileImageUrl === '') {
profileImageUrl = generateInitialsImage(name);
}
}
const updatedUser = await updateUserProfile(localStorage.token, {
name: name,
profile_image_url: profileImageUrl,
bio: bio ? bio : null,
gender: gender ? gender : null,
date_of_birth: dateOfBirth ? dateOfBirth : null
}).catch((error) => {
toast.error(`${error}`);
});
const bannerSaved = await saveBanner();
const variablesRes = await updateUserVariables(localStorage.token, variables).catch((error) => {
toast.error(`${error}`);
return null;
});
if (updatedUser && bannerSaved && variablesRes) {
setVariableRows(variablesRes.variables ?? {});
// Get Session User Info
const sessionUser = await getSessionUser(localStorage.token).catch((error) => {
toast.error(`${error}`);
return null;
});
await user.set(sessionUser);
return true;
}
return false;
};
const createAPIKeyHandler = async () => {
APIKey = await createAPIKey(localStorage.token);
if (APIKey) {
toast.success($i18n.t('API Key created.'));
} else {
toast.error($i18n.t('Failed to create API Key.'));
}
};
const deleteAPIKeyHandler = async () => {
const res = await deleteAPIKey(localStorage.token).catch((error) => {
toast.error(`${error}`);
return false;
});
if (res) {
APIKey = '';
toast.success($i18n.t('API Key deleted.'));
}
};
onMount(async () => {
system = $settings.system ?? '';
params = { ...params, ...$settings.params };
params.stop = $settings?.params?.stop ? ($settings?.params?.stop ?? []).join(',') : null;
const user = await getSessionUser(localStorage.token).catch((error) => {
toast.error(`${error}`);
return null;
});
if (user) {
name = user?.name ?? '';
profileImageUrl = user?.profile_image_url ?? '';
savedBannerUrl = bannerUrl = bannerSrc(user.id, user?.profile_banner_image_url ?? null);
bio = user?.bio ?? '';
gender = user?.gender ?? '';
_gender = ['', 'male', 'female'].includes(gender) ? gender : 'custom';
dateOfBirth = user?.date_of_birth ?? '';
}
const userVariables = await getUserVariables(localStorage.token).catch((error) => {
toast.error(`${error}`);
return null;
});
setVariableRows(userVariables?.variables ?? {});
// Only fetch API key if the feature is enabled and user has permission
if (
user &&
($config?.features?.enable_api_keys ?? true) &&
(user?.role === 'admin' || (user?.permissions?.features?.api_keys ?? false))
) {
APIKey = await getAPIKey(localStorage.token).catch((error) => {
console.log(error);
return '';
});
}
});
</script>
<form
id="tab-account"
class="flex h-full flex-col text-sm"
on:submit|preventDefault={async () => {
const res = await submitHandler();
if (res && (await saveAdvancedSettings())) {
saveHandler();
}
}}
>
<div class="flex-1 min-h-0 w-full overflow-y-auto scrollbar-hover pr-1.5">
<UserSettingSection title={$i18n.t('settings.personal.account.sections.profile.title')} first>
<UserProfileBanner bind:src={bannerUrl} bind:file={bannerFile}>
<UserProfileImage
bind:profileImageUrl
user={$user}
variant="account"
displayName={$user?.name}
/>
</UserProfileBanner>
<UserSettingField
label={$i18n.t('settings.personal.account.name.label')}
description={$i18n.t('settings.personal.account.name.description')}
>
<input
class={inputClass}
type="text"
bind:value={name}
autocomplete="name"
aria-label={$i18n.t('settings.personal.account.name.label')}
required
placeholder={$i18n.t('Enter your name')}
/>
</UserSettingField>
<UserSettingField
label={$i18n.t('settings.personal.account.bio.label')}
description={$i18n.t('settings.personal.account.bio.description')}
>
<Textarea
className={textareaClass}
minSize={60}
bind:value={bio}
ariaLabel={$i18n.t('settings.personal.account.bio.label')}
placeholder={$i18n.t('Share your background and interests')}
/>
</UserSettingField>
<UserSettingField
label={$i18n.t('settings.personal.account.gender.label')}
description={$i18n.t('settings.personal.account.gender.description')}
>
<SettingsSelect
bind:value={_gender}
autocomplete="sex"
className="w-full"
ariaLabel={$i18n.t('settings.personal.account.gender.label')}
on:change={() => {
console.log(_gender);
if (_gender === 'custom') {
// Handle custom gender input
gender = '';
} else {
gender = _gender;
}
}}
>
<option value="" selected>{$i18n.t('Prefer not to say')}</option>
<option value="male">{$i18n.t('Male')}</option>
<option value="female">{$i18n.t('Female')}</option>
<option value="custom">{$i18n.t('Custom')}</option>
</SettingsSelect>
{#if _gender === 'custom'}
<input
class="mt-1 {inputClass}"
type="text"
required
aria-label={$i18n.t('Custom Gender')}
placeholder={$i18n.t('Enter your gender')}
bind:value={gender}
autocomplete="sex"
/>
{/if}
</UserSettingField>
<UserSettingField
label={$i18n.t('settings.personal.account.birthDate.label')}
description={$i18n.t('settings.personal.account.birthDate.description')}
>
<input
class="{inputClass} dark:scheme-dark"
type="date"
max={new Date().toISOString().slice(0, 10)}
aria-label={$i18n.t('settings.personal.account.birthDate.label')}
bind:value={dateOfBirth}
autocomplete="bday"
/>
</UserSettingField>
<ModelSettingsSection label={$i18n.t('Advanced')}>
<div class="flex flex-col">
{#if canEditSystemPrompt}
<ModelSettingsSection
label={$i18n.t('settings.personal.general.sections.systemPrompt.title')}
description={$i18n.t('settings.personal.general.sections.systemPrompt.description')}
summary={system.trim() || $i18n.t('Default')}
>
<Textarea
bind:value={system}
className={systemPromptTextareaClass}
rows="4"
placeholder={$i18n.t('Enter system prompt here')}
/>
</ModelSettingsSection>
{/if}
{#if canEditParams}
<ModelSettingsSection
label={$i18n.t('settings.personal.general.sections.advancedParameters.title')}
description={$i18n.t('settings.personal.general.modelParameters.description')}
>
<AdvancedParams
admin={$user?.role === 'admin'}
custom={true}
layout="grid"
bind:params
/>
</ModelSettingsSection>
{/if}
<ModelSettingsSection
label={$i18n.t('User Variables')}
summary={`${variableRows.length}`}
>
<div class="flex flex-col gap-1 py-1">
{#each variableRows as row, idx}
<div class={variableRowClass}>
<div class="min-w-0 truncate font-mono text-xs text-base-700 dark:text-base-300">
{row.key || $i18n.t('key_name')}
</div>
<div class="min-w-0 flex-1 truncate text-xs text-base-500 dark:text-base-400">
{row.value || $i18n.t('Empty')}
</div>
<button
class={actionButtonClass}
type="button"
on:click={() => openVariableModal(idx)}
>
{$i18n.t('Edit')}
</button>
</div>
{/each}
{#if variableRows.length === 0}
<div class="text-xs text-base-500 dark:text-base-400">
{$i18n.t('No user variables configured.')}
</div>
{/if}
</div>
<div class="text-[0.6875rem] text-base-500 dark:text-base-400">
{$i18n.t('Use these in model system prompts as {{example}}.', {
example: '{{user.variables.key_name}}'
})}
</div>
<div class="mt-1 flex justify-end">
<button class={actionButtonClass} type="button" on:click={() => openVariableModal()}>
{$i18n.t('Add')}
</button>
</div>
</ModelSettingsSection>
</div>
</ModelSettingsSection>
</UserSettingSection>
{#if $config?.features.enable_login_form && $config?.features.enable_password_change_form}
<UserSettingSection title={$i18n.t('settings.personal.account.sections.password.title')}>
<UpdatePassword />
</UserSettingSection>
{/if}
<Mfa />
{#if canUseApiKeys({ user: $user, config: $config })}
<UserSettingSection title={$i18n.t('settings.personal.account.sections.apiKeys.title')}>
<UserSettingRow
let:labelId
description={$i18n.t('settings.personal.account.secrets.description')}
>
<span slot="label">{$i18n.t('settings.personal.account.secrets.label')}</span>
<button
id={`${labelId}-control`}
class={actionButtonClass}
type="button"
on:click={() => {
showAPIKeys = !showAPIKeys;
}}>{showAPIKeys ? $i18n.t('Hide') : $i18n.t('Show')}</button
>
</UserSettingRow>
{#if showAPIKeys}
<div class="flex flex-col gap-2">
{#if $user?.role === 'admin'}
<UserSettingField
label={$i18n.t('settings.personal.account.jwtToken.label')}
description={$i18n.t('settings.personal.account.jwtToken.description')}
>
<div class="flex">
<SensitiveInput
variant="settings"
placeholder={$i18n.t('settings.personal.account.jwtToken.label')}
value={localStorage.token}
readOnly={true}
/>
<button
type="button"
class="ml-1.5 rounded-sm px-1.5 py-1 text-base-500 transition hover:text-base-700 dark:hover:text-base-300"
aria-label={$i18n.t('Copy Token')}
on:click={() => {
copyToClipboard(localStorage.token);
JWTTokenCopied = true;
setTimeout(() => {
JWTTokenCopied = false;
}, 2000);
}}
>
{#if JWTTokenCopied}
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
clip-rule="evenodd"
/>
</svg>
{:else}
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M11.986 3H12a2 2 0 0 1 2 2v6a2 2 0 0 1-1.5 1.937V7A2.5 2.5 0 0 0 10 4.5H4.063A2 2 0 0 1 6 3h.014A2.25 2.25 0 0 1 8.25 1h1.5a2.25 2.25 0 0 1 2.236 2ZM10.5 4v-.75a.75.75 0 0 0-.75-.75h-1.5a.75.75 0 0 0-.75.75V4h3Z"
clip-rule="evenodd"
/>
<path
fill-rule="evenodd"
d="M3 6a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1H3Zm1.75 2.5a.75.75 0 0 0 0 1.5h3.5a.75.75 0 0 0 0-1.5h-3.5ZM4 11.75a.75.75 0 0 1 .75-.75h3.5a.75.75 0 0 1 0 1.5h-3.5a.75.75 0 0 1-.75-.75Z"
clip-rule="evenodd"
/>
</svg>
{/if}
</button>
</div>
</UserSettingField>
{/if}
{#if canUseApiKeys({ user: $user, config: $config })}
<UserSettingField
label={$i18n.t('settings.personal.account.apiKey.label')}
description={$i18n.t('settings.personal.account.apiKey.description')}
>
<div class="flex">
{#if APIKey}
<SensitiveInput
variant="settings"
placeholder={$i18n.t('settings.personal.account.apiKey.label')}
value={APIKey}
readOnly={true}
/>
<button
type="button"
class="ml-1.5 rounded-sm px-1.5 py-1 text-base-500 transition hover:text-base-700 dark:hover:text-base-300"
aria-label={$i18n.t('Copy API Key')}
on:click={() => {
copyToClipboard(APIKey);
APIKeyCopied = true;
setTimeout(() => {
APIKeyCopied = false;
}, 2000);
}}
>
{#if APIKeyCopied}
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z"
clip-rule="evenodd"
/>
</svg>
{:else}
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 16 16"
fill="currentColor"
class="w-4 h-4"
>
<path
fill-rule="evenodd"
d="M11.986 3H12a2 2 0 0 1 2 2v6a2 2 0 0 1-1.5 1.937V7A2.5 2.5 0 0 0 10 4.5H4.063A2 2 0 0 1 6 3h.014A2.25 2.25 0 0 1 8.25 1h1.5a2.25 2.25 0 0 1 2.236 2ZM10.5 4v-.75a.75.75 0 0 0-.75-.75h-1.5a.75.75 0 0 0-.75.75V4h3Z"
clip-rule="evenodd"
/>
<path
fill-rule="evenodd"
d="M3 6a1 1 0 0 0-1 1v7a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V7a1 1 0 0 0-1-1H3Zm1.75 2.5a.75.75 0 0 0 0 1.5h3.5a.75.75 0 0 0 0-1.5h-3.5ZM4 11.75a.75.75 0 0 1 .75-.75h3.5a.75.75 0 0 1 0 1.5h-3.5a.75.75 0 0 1-.75-.75Z"
clip-rule="evenodd"
/>
</svg>
{/if}
</button>
<Dropdown bind:show={showAPIKeyMenu} align="end" sideOffset={4}>
<Tooltip content={$i18n.t('More')}>
<button
type="button"
class="rounded-sm px-1.5 py-1 text-base-500 transition hover:text-base-700 dark:hover:text-base-300"
aria-label={$i18n.t('More')}
>
<EllipsisHorizontal strokeWidth="2" className="size-4" />
</button>
</Tooltip>
<div slot="content">
<DropdownMenu className="min-w-[10.625rem]">
<button
type="button"
on:click={() => {
showAPIKeyMenu = false;
createAPIKeyHandler();
}}
>
<Refresh strokeWidth="2" className="size-3.5 scale-90" />
<div class="flex items-center">{$i18n.t('Create new key')}</div>
</button>
<hr class="border-base-50 dark:border-base-850/30" />
<button
type="button"
on:click={() => {
showAPIKeyMenu = false;
showDeleteAPIKeyConfirm = true;
}}
>
<XMark strokeWidth="2" className="size-3.5" />
<div class="flex items-center">{$i18n.t('Delete')}</div>
</button>
</DropdownMenu>
</div>
</Dropdown>
{:else}
<button
class="inline-flex items-center gap-1.5 {actionButtonClass}"
type="button"
on:click={() => {
createAPIKeyHandler();
}}
>
<Plus strokeWidth="2" className="size-3.5" />
{$i18n.t('settings.personal.account.createNewSecretKey.label')}</button
>
{/if}
</div>
</UserSettingField>
{/if}
</div>
{/if}
</UserSettingSection>
{/if}
</div>
<div class="shrink-0 flex w-full justify-end pt-3 text-sm font-normal">
<button
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-base-900 px-2.5 text-xs font-normal text-base-0 transition hover:bg-base-1000 disabled:opacity-60 dark:bg-base-100 dark:text-base-900 dark:hover:bg-base-0"
type="submit"
>
{$i18n.t('Save')}
</button>
</div>
</form>
<ConfirmDialog
bind:show={showDeleteAPIKeyConfirm}
title={$i18n.t('Delete API Key?')}
confirmLabel={$i18n.t('Delete')}
on:confirm={deleteAPIKeyHandler}
>
<div class="text-sm text-base-500">
{$i18n.t('This will revoke the current API key.')}
</div>
</ConfirmDialog>
<Modal
ariaLabel={variableFormIndex === null
? $i18n.t('Add User Variable')
: $i18n.t('Edit User Variable')}
size="sm"
bind:show={variableModalOpen}
>
<form class="p-4" on:submit|preventDefault={saveVariableForm}>
<h2 class="mb-3 text-sm font-medium text-base-900 dark:text-base-0">
{variableFormIndex === null ? $i18n.t('Add User Variable') : $i18n.t('Edit User Variable')}
</h2>
<div class="mb-1 text-[0.625rem] text-base-500 dark:text-base-400">
{$i18n.t('Key')}
</div>
<input
class={inputClass}
type="text"
bind:value={variableFormKey}
aria-label={$i18n.t('Variable key')}
placeholder={$i18n.t('key_name')}
autocomplete="off"
spellcheck="false"
/>
<div class="mb-1 mt-3 text-[0.625rem] text-base-500 dark:text-base-400">
{$i18n.t('Value')}
</div>
<Textarea
className={variableValueClass}
rows="6"
minSize={132}
bind:value={variableFormValue}
ariaLabel={$i18n.t('Variable value')}
placeholder={$i18n.t('Value')}
/>
<div class="mt-4 flex items-center justify-between gap-2">
<div>
{#if variableFormIndex !== null}
<button
class="text-xs text-base-500 transition-colors hover:text-base-900 dark:text-base-500 dark:hover:text-base-0"
type="button"
on:click={deleteVariableForm}
>
{$i18n.t('Delete')}
</button>
{/if}
</div>
<div class="flex items-center gap-3">
<button
class="text-xs text-base-500 transition-colors hover:text-base-900 dark:text-base-500 dark:hover:text-base-0"
type="button"
on:click={() => {
variableModalOpen = false;
}}
>
{$i18n.t('Cancel')}
</button>
<button
class="flex h-7 shrink-0 items-center justify-center gap-1.5 rounded-lg bg-base-900 px-2.5 text-xs font-normal text-base-0 transition hover:bg-base-1000 disabled:opacity-60 dark:bg-base-100 dark:text-base-900 dark:hover:bg-base-0"
type="submit"
>
{$i18n.t('Done')}
</button>
</div>
</div>
</form>
</Modal>