| 719 | 694 | setPersonaDescription(); |
| 720 | 695 | } |
| 721 | 696 | |
| 722 | | -async function bindUserNameToPersona() { |
| 723 | | - const avatarId = user_avatar; |
| 724 | | - |
| 725 | | - if (!avatarId) { |
| 726 | | - console.warn('No avatar id found'); |
| 727 | | - return; |
| 728 | | - } |
| 729 | | - |
| 730 | | - let personaUnbind = false; |
| 731 | | - const existingPersona = power_user.personas[avatarId]; |
| 732 | | - const personaName = await Popup.show.input( |
| 733 | | - t`Enter a name for this persona:`, |
| 734 | | - t`(If empty name is provided, this will unbind the name from this avatar)`, |
| 735 | | - existingPersona || '', |
| 736 | | - { onClose: (p) => { personaUnbind = p.value === '' && p.result === POPUP_RESULT.AFFIRMATIVE; } }); |
| 737 | | - |
| 738 | | - // If the user clicked cancel, don't do anything |
| 739 | | - if (personaName === null && !personaUnbind) { |
| 740 | | - return; |
| 741 | | - } |
| 742 | | - |
| 743 | | - if (personaName && personaName.length > 0) { |
| 744 | | - // If the user clicked ok and entered a name, bind the name to the persona |
| 745 | | - console.log(`Binding persona ${avatarId} to name ${personaName}`); |
| 746 | | - power_user.personas[avatarId] = personaName; |
| 747 | | - const descriptor = power_user.persona_descriptions[avatarId]; |
| 748 | | - const isCurrentPersona = avatarId === user_avatar; |
| 749 | | - |
| 750 | | - // Create a description object if it doesn't exist |
| 751 | | - if (!descriptor) { |
| 752 | | - // If the user is currently using this persona, set the description to the current description |
| 753 | | - power_user.persona_descriptions[avatarId] = { |
| 754 | | - description: isCurrentPersona ? power_user.persona_description : '', |
| 755 | | - position: isCurrentPersona ? power_user.persona_description_position : persona_description_positions.IN_PROMPT, |
| 756 | | - depth: isCurrentPersona ? power_user.persona_description_depth : DEFAULT_DEPTH, |
| 757 | | - role: isCurrentPersona ? power_user.persona_description_role : DEFAULT_ROLE, |
| 758 | | - lorebook: isCurrentPersona ? power_user.persona_description_lorebook : '', |
| 759 | | - }; |
| 760 | | - } |
| 761 | | - |
| 762 | | - // If the user is currently using this persona, update the name |
| 763 | | - if (isCurrentPersona) { |
| 764 | | - console.log(`Auto-updating user name to ${personaName}`); |
| 765 | | - setUserName(personaName); |
| 766 | | - await updatePersonaNameIfExists(user_avatar, personaName); |
| 767 | | - } |
| 768 | | - } else { |
| 769 | | - // If the user clicked ok, but didn't enter a name, delete the persona |
| 770 | | - console.log(`Unbinding persona ${avatarId}`); |
| 771 | | - delete power_user.personas[avatarId]; |
| 772 | | - delete power_user.persona_descriptions[avatarId]; |
| 773 | | - } |
| 774 | | - |
| 775 | | - saveSettingsDebounced(); |
| 776 | | - await getUserAvatars(true, avatarId); |
| 777 | | - setPersonaDescription(); |
| 778 | | - |
| 779 | | - retriggerFirstMessageOnEmptyChat(); |
| 780 | | -} |
| 781 | | - |
| 782 | 697 | function selectCurrentPersona({ toastPersonaNameChange = true } = {}) { |
| 783 | 698 | const personaName = power_user.personas[user_avatar]; |
| 784 | 699 | if (personaName) { |