diff --git a/src/lib/ChatOptionMenu.svelte b/src/lib/ChatOptionMenu.svelte
index 26f2796..1d40e40 100644
--- a/src/lib/ChatOptionMenu.svelte
+++ b/src/lib/ChatOptionMenu.svelte
@@ -18,14 +18,15 @@
faEyeSlash
} from '@fortawesome/free-solid-svg-icons/index'
import { faSquareMinus, faSquarePlus as faSquarePlusOutline } from '@fortawesome/free-regular-svg-icons/index'
- import { apiKeyStorage, addChatFromJSON, chatsStorage, checkStateChange, clearChats, clearMessages, copyChat, globalStorage, setGlobalSettingValueByKey, showSetChatSettings, pinMainMenu, getChat, deleteChat, saveChatStore } from './Storage.svelte'
+ import { apiKeyStorage, addChatFromJSON, chatsStorage, checkStateChange, clearChats, clearMessages, copyChat, globalStorage, setGlobalSettingValueByKey, showSetChatSettings, pinMainMenu, getChat, deleteChat, saveChatStore, saveCustomProfile } from './Storage.svelte'
import { exportAsMarkdown, exportChatAsJSON } from './Export.svelte'
- import { restartProfile } from './Profiles.svelte'
+ import { newNameForProfile, restartProfile } from './Profiles.svelte'
import { replace } from 'svelte-spa-router'
import { clickOutside } from 'svelte-use-click-outside'
import { openModal } from 'svelte-modals'
import PromptConfirm from './PromptConfirm.svelte'
- import { startNewChatWithWarning, startNewChatFromChatId } from './Util.svelte'
+ import { startNewChatWithWarning, startNewChatFromChatId, errorNotice, encodeHTMLEntities } from './Util.svelte'
+ import type { ChatSettings } from './Types.svelte'
export let chatId
export const show = (showHide:boolean = true) => {
@@ -37,10 +38,12 @@
let showChatMenu = false
let chatFileInput
+ let profileFileInput
const importChatFromFile = (e) => {
close()
const image = e.target.files[0]
+ e.target.value = null
const reader = new FileReader()
reader.readAsText(image)
reader.onload = e => {
@@ -121,6 +124,38 @@
})
}
+ const importProfileFromFile = (e) => {
+ const image = e.target.files[0]
+ e.target.value = null
+ const reader = new FileReader()
+ reader.onload = e => {
+ const json = (e.target || {}).result as string
+ try {
+ const profile = JSON.parse(json) as ChatSettings
+ profile.profileName = newNameForProfile(profile.profileName || '')
+ profile.profile = null as any
+ saveCustomProfile(profile)
+ openModal(PromptConfirm, {
+ title: 'Profile Restored',
+ class: 'is-info',
+ message: 'Profile restored as:
' + encodeHTMLEntities(profile.profileName) +
+ '
Start new chat with this profile?',
+ asHtml: true,
+ onConfirm: () => {
+ startNewChatWithWarning(chatId, profile)
+ },
+ onCancel: () => {}
+ })
+ } catch (e) {
+ errorNotice('Unable to import profile:', e)
+ }
+ }
+ reader.onerror = e => {
+ errorNotice('Unable to import profile:', new Error('Unknown error'))
+ }
+ reader.readAsText(image)
+ }
+