| 40 | | 39 | |
| 41 | const bookmarkNameToken = 'Checkpoint #'; | 40 | const bookmarkNameToken = 'Checkpoint #'; |
| 42 | | 41 | |
| | 42 | /** |
| | 43 | * Gets the names of existing chats for the current character or group. |
| | 44 | * @returns {Promise<string[]>} - Returns a promise that resolves to an array of existing chat names. |
| | 45 | */ |
| 43 | async function getExistingChatNames() { | 46 | async function getExistingChatNames() { |
| 44 | if (selected_group) { | 47 | if (selected_group) { |
| 45 | const data = await getGroupPastChats(selected_group); | 48 | const group = groups.find(x => x.id == selected_group); |
| 46 | return data.map(x => x.file_name); | 49 | if (group && Array.isArray(group.chats)) { |
| 47 | } else { | 50 | return [...group.chats]; |
| | 51 | } |
| | 52 | |
| | 53 | return []; |
| | 54 | } |
| | 55 | |
| | 56 | if (this_chid === undefined) { |
| | 57 | return []; |
| | 58 | } |
| | 59 | |
| | 60 | const character = characters[this_chid]; |
| | 61 | if (!character) { |
| | 62 | return []; |
| | 63 | } |
| | 64 | |
| 48 | const response = await fetch('/api/characters/chats', { | 65 | const response = await fetch('/api/characters/chats', { |
| 49 | method: 'POST', | 66 | method: 'POST', |
| 50 | headers: getRequestHeaders(), | 67 | headers: getRequestHeaders(), |
| 51 | body: JSON.stringify({ avatar_url: characters[this_chid].avatar }), | 68 | body: JSON.stringify({ avatar_url: character.avatar, simple: true }), |
| 52 | }); | 69 | }); |
| 53 | | 70 | |
| 54 | if (response.ok) { | 71 | if (response.ok) { |
| 55 | const data = await response.json(); | 72 | const data = await response.json(); |
| 56 | return Object.values(data).map(x => x.file_name.replace('.jsonl', '')); | 73 | const chats = Object.values(data).map(x => x.file_name.replace('.jsonl', '')); |
| 57 | } | 74 | return [...chats]; |
| 58 | } | 75 | } |
| | 76 | |
| | 77 | return []; |
| 59 | } | 78 | } |
| 60 | | 79 | |
| 61 | async function getBookmarkName({ isReplace = false, forceName = null } = {}) { | 80 | async function getBookmarkName({ isReplace = false, forceName = null } = {}) { |