diff --git a/src/lib/components/chat/Settings/Account.svelte b/src/lib/components/chat/Settings/Account.svelte index 4f5e6334ad..4f3e0fbdf8 100644 --- a/src/lib/components/chat/Settings/Account.svelte +++ b/src/lib/components/chat/Settings/Account.svelte @@ -3,19 +3,29 @@ import { onMount, getContext } from 'svelte'; import { user, config } from '$lib/stores'; - import { updateUserProfile, createAPIKey, getAPIKey, getSessionUser } from '$lib/apis/auths'; + import { + updateUserProfile, + createAPIKey, + deleteAPIKey, + getAPIKey, + getSessionUser + } from '$lib/apis/auths'; import { getUserVariables, updateUserVariables } from '$lib/apis/users'; - import { WEBUI_BASE_URL } from '$lib/constants'; import UpdatePassword from './Account/UpdatePassword.svelte'; - import { getGravatarUrl } from '$lib/apis/utils'; - import { generateInitialsImage, canvasPixelTest } from '$lib/utils'; + 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 UserProfileImage from './Account/UserProfileImage.svelte'; import UserSettingField from './UserSettingField.svelte'; import UserSettingRow from './UserSettingRow.svelte'; @@ -24,7 +34,7 @@ const i18n = getContext('i18n'); - export let saveHandler: Function; + export let saveHandler: () => void | Promise; let profileImageUrl = ''; let name = ''; @@ -40,6 +50,8 @@ 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; @@ -174,6 +186,18 @@ } }; + 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 () => { const user = await getSessionUser(localStorage.token).catch((error) => { toast.error(`${error}`); @@ -258,7 +282,7 @@ bind:value={_gender} className="w-full" ariaLabel={$i18n.t('Gender')} - on:change={(e) => { + on:change={() => { console.log(_gender); if (_gender === 'custom') { @@ -372,7 +396,7 @@ - - - + + + + +
+ + + +
+ + +
+
+ {:else} @@ -534,6 +574,17 @@ + +
+ {$i18n.t('This will revoke the current API key.')} +
+
+

diff --git a/src/lib/i18n/locales/en-US/translation.json b/src/lib/i18n/locales/en-US/translation.json index f3ba8331b2..f4c5b9be30 100644 --- a/src/lib/i18n/locales/en-US/translation.json +++ b/src/lib/i18n/locales/en-US/translation.json @@ -231,6 +231,7 @@ "API Key": "", "API Key / Token": "", "API Key created.": "", + "API Key deleted.": "", "API Key Endpoint Restrictions": "", "API key for embedding requests.": "", "API key sent to Docling.": "", @@ -743,6 +744,7 @@ "Defines the behavior used for spoken conversations.": "", "Delegate focused work to parallel sub-agents": "", "Delete": "", + "Delete API Key?": "", "Delete {{name}}": "", "Delete a model": "", "Delete All": "", @@ -2670,6 +2672,7 @@ "This will delete all models including custom models and cannot be undone.": "", "This will permanently delete the calendar \"{{name}}\" and all its events. This action cannot be undone.": "", "This will remove all files and directories from this knowledge base. This action cannot be undone.": "", + "This will revoke the current API key.": "", "Thorough explanation": "", "Thought": "", "Thought for {{DURATION}}": "",