Add deprecated user_name and character_name fields for backward compatibility
| @@ -43,6 +43,10 @@ declare global { | ||
| 43 | 43 | |
| 44 | 44 | interface ChatHeader { |
| 45 | 45 | chat_metadata: ChatMetadata; |
| 46 | + /** @deprecated For backward compatibility ONLY */ | |
| 47 | + user_name: 'unused'; | |
| 48 | + /** @deprecated For backward compatibility ONLY */ | |
| 49 | + character_name: 'unused'; | |
| 46 | 50 | } |
| 47 | 51 | |
| 48 | 52 | interface ChatMetadata { |
| @@ -6955,6 +6955,8 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false } | ||
| 6955 | 6955 | /** @type {ChatHeader} */ |
| 6956 | 6956 | const chatHeader = { |
| 6957 | 6957 | chat_metadata: metadata, |
| 6958 | + user_name: 'unused', | |
| 6959 | + character_name: 'unused', | |
| 6958 | 6960 | }; |
| 6959 | 6961 | |
| 6960 | 6962 | try { |
| @@ -303,7 +303,11 @@ export async function convertSoloToGroupChat() { | ||
| 303 | 303 | const metadata = Object.assign({}, chat_metadata); |
| 304 | 304 | delete metadata.main_chat; |
| 305 | 305 | /** @type {ChatHeader} */ |
| 306 | 306 | const chatHeader = { chat_metadata: metadata }; |
| 307 | + chat_metadata: metadata, | |
| 308 | + user_name: 'unused', | |
| 309 | + character_name: 'unused', | |
| 310 | + }; | |
| 307 | 311 | /** @type {Omit<Group, 'id'>} */ |
| 308 | 312 | const groupCreateModel = { |
| 309 | 313 | name: name, |
| @@ -2140,8 +2140,14 @@ export function initChatUtilities() { | ||
| 2140 | 2140 | }); |
| 2141 | 2141 | |
| 2142 | 2142 | $(document).on('click', '.assistant_note_export', async function (_e) { |
| 2143 | + /** @type {ChatHeader} */ | |
| 2144 | + const chatHeader = { | |
| 2145 | + chat_metadata: chat_metadata, | |
| 2146 | + user_name: 'unused', | |
| 2147 | + character_name: 'unused', | |
| 2148 | + }; | |
| 2143 | 2149 | const chatToSave = [ |
| 2144 | - { chat_metadata: chat_metadata }, | |
| 2150 | + chatHeader, | |
| 2145 | 2151 | ...chat.filter(x => x?.extra?.type !== system_message_types.ASSISTANT_NOTE), |
| 2146 | 2152 | ]; |
| 2147 | 2153 | |
| @@ -626,6 +626,8 @@ async function saveGroupChat(groupId, shouldSaveGroup, force = false) { | ||
| 626 | 626 | /** @type {ChatHeader} */ |
| 627 | 627 | const chatHeader = { |
| 628 | 628 | chat_metadata: { ...chat_metadata }, |
| 629 | + user_name: 'unused', | |
| 630 | + character_name: 'unused', | |
| 629 | 631 | }; |
| 630 | 632 | const response = await fetch('/api/chats/group/save', { |
| 631 | 633 | method: 'POST', |
| @@ -2334,6 +2336,8 @@ export async function saveGroupBookmarkChat(groupId, name, metadata, mesId) { | ||
| 2334 | 2336 | /** @type {ChatHeader} */ |
| 2335 | 2337 | const chatHeader = { |
| 2336 | 2338 | chat_metadata: { ...chat_metadata, ...(metadata || {}) }, |
| 2339 | + user_name: 'unused', | |
| 2340 | + character_name: 'unused', | |
| 2337 | 2341 | }; |
| 2338 | 2342 | |
| 2339 | 2343 | /** @type {ChatMessage[]} */ |
| @@ -334,6 +334,8 @@ export class ByafParser { | ||
| 334 | 334 | const chatBackground = chatBackgrounds.find(bg => bg.paths.includes(scenario?.backgroundImage || ''))?.name || ''; |
| 335 | 335 | /** @type {object[]} */ |
| 336 | 336 | const chat = [{ |
| 337 | + user_name: 'unused', | |
| 338 | + character_name: 'unused', | |
| 337 | 339 | chat_metadata: { |
| 338 | 340 | scenario: scenario?.narrative ?? '', |
| 339 | 341 | mes_example: ByafParser.formatExampleMessages(scenario?.exampleMessages), |
| @@ -107,6 +107,8 @@ function importOobaChat(userName, characterName, jsonData) { | ||
| 107 | 107 | /** @type {object[]} */ |
| 108 | 108 | const chat = [{ |
| 109 | 109 | chat_metadata: {}, |
| 110 | + user_name: 'unused', | |
| 111 | + character_name: 'unused', | |
| 110 | 112 | }]; |
| 111 | 113 | |
| 112 | 114 | for (const arr of jsonData.data_visible) { |
| @@ -146,6 +148,8 @@ function importAgnaiChat(userName, characterName, jsonData) { | ||
| 146 | 148 | /** @type {object[]} */ |
| 147 | 149 | const chat = [{ |
| 148 | 150 | chat_metadata: {}, |
| 151 | + user_name: 'unused', | |
| 152 | + character_name: 'unused', | |
| 149 | 153 | }]; |
| 150 | 154 | |
| 151 | 155 | for (const message of jsonData.messages) { |
| @@ -178,6 +182,8 @@ function importCAIChat(userName, characterName, jsonData) { | ||
| 178 | 182 | function convert(history) { |
| 179 | 183 | const starter = { |
| 180 | 184 | chat_metadata: {}, |
| 185 | + user_name: 'unused', | |
| 186 | + character_name: 'unused', | |
| 181 | 187 | }; |
| 182 | 188 | |
| 183 | 189 | const historyData = history.msgs.map((msg) => ({ |
| @@ -276,6 +282,8 @@ function importRisuChat(userName, characterName, jsonData) { | ||
| 276 | 282 | /** @type {object[]} */ |
| 277 | 283 | const chat = [{ |
| 278 | 284 | chat_metadata: {}, |
| 285 | + user_name: 'unused', | |
| 286 | + character_name: 'unused', | |
| 279 | 287 | }]; |
| 280 | 288 | |
| 281 | 289 | for (const message of jsonData.data.message) { |
| @@ -81,7 +81,7 @@ export async function migrateGroupChatsMetadataFormat(userDirectories) { | ||
| 81 | 81 | continue; |
| 82 | 82 | } |
| 83 | 83 | await fsPromises.copyFile(chatFilePath, path.join(backupPath, chatFileName)); |
| 84 | 84 | const chatHeader = { chat_metadata: chatMetadata, user_name: 'unused', character_name: 'unused' }; |
| 85 | 85 | const newChatData = [chatHeader, ...chatData]; |
| 86 | 86 | const newChatDataRaw = newChatData.map(entry => JSON.stringify(entry)).join('\n'); |
| 87 | 87 | await writeFileAtomic(chatFilePath, newChatDataRaw, 'utf8'); |