| 203 | 203 | |
| 204 | 204 | /** @type {function(string): object} */ |
| 205 | 205 | function processKoboldMessage(msg) { |
| 206 | 206 | const isUser = msg.includes(inputToken) || msg.includes(outputToken); |
| 207 | 207 | return { |
| 208 | 208 | name: isUser ? header.user_name : header.character_name, |
| 209 | 209 | is_user: isUser, |
| 210 | 210 | mes: msg.replacereplaceAll(inputToken, '').replacereplaceAll(outputToken, '').trim(), |
| 211 | 211 | send_date: Date.now(), |
| 212 | 212 | }; |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | // Create the header |
| 216 | 216 | const header = { |
| 217 | 217 | user_name: String(data.savedsettings.chatname), |
| 218 | 218 | character_name: String(data.savedsettings.chatopponent).split('||$||')[0], |
| 219 | 219 | }; |
| 220 | 220 | // Format messages |
| 221 | 221 | const formattedMessages = data.actions.map(processKoboldMessage); |