mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Fix chatIdHash being empty on the first evaluation
This commit is contained in:
@ -3,11 +3,29 @@ import { timestampToMoment, isDigitsOnly, getStringHash } from './utils.js';
|
|||||||
import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';
|
import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';
|
||||||
import { replaceInstructMacros } from './instruct-mode.js';
|
import { replaceInstructMacros } from './instruct-mode.js';
|
||||||
import { replaceVariableMacros } from './variables.js';
|
import { replaceVariableMacros } from './variables.js';
|
||||||
import { saveMetadataDebounced } from './extensions.js';
|
|
||||||
|
|
||||||
// Register any macro that you want to leave in the compiled story string
|
// Register any macro that you want to leave in the compiled story string
|
||||||
Handlebars.registerHelper('trim', () => '{{trim}}');
|
Handlebars.registerHelper('trim', () => '{{trim}}');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a hashed id of the current chat from the metadata.
|
||||||
|
* If no metadata exists, creates a new hash and saves it.
|
||||||
|
* @returns {number} The hashed chat id
|
||||||
|
*/
|
||||||
|
function getChatIdHash() {
|
||||||
|
const cachedIdHash = chat_metadata['chat_id_hash'];
|
||||||
|
|
||||||
|
// If chat_id_hash is not already set, calculate it
|
||||||
|
if (!cachedIdHash) {
|
||||||
|
// Use the main_chat if it's available, otherwise get the current chat ID
|
||||||
|
const chatId = chat_metadata['main_chat'] ?? getCurrentChatId();
|
||||||
|
const chatIdHash = getStringHash(chatId);
|
||||||
|
chat_metadata['chat_id_hash'] = chatIdHash;
|
||||||
|
return chatIdHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachedIdHash;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the ID of the last message in the chat
|
* Returns the ID of the last message in the chat
|
||||||
@ -190,10 +208,7 @@ function pickReplace(input, rawContent, emptyListPlaceholder = '') {
|
|||||||
|
|
||||||
// We need to have a consistent chat hash, otherwise we'll lose rolls on chat file rename or branch switches
|
// We need to have a consistent chat hash, otherwise we'll lose rolls on chat file rename or branch switches
|
||||||
// No need to save metadata here - branching and renaming will implicitly do the save for us, and until then loading it like this is consistent
|
// No need to save metadata here - branching and renaming will implicitly do the save for us, and until then loading it like this is consistent
|
||||||
const chatIdHash = chat_metadata['chat_id_hash'];
|
const chatIdHash = getChatIdHash();
|
||||||
if (!chatIdHash) {
|
|
||||||
chat_metadata['chat_id_hash'] = getStringHash(chat_metadata['main_chat'] ?? getCurrentChatId());
|
|
||||||
}
|
|
||||||
const rawContentHash = getStringHash(rawContent);
|
const rawContentHash = getStringHash(rawContent);
|
||||||
|
|
||||||
return input.replace(pickPattern, (match, listString, offset) => {
|
return input.replace(pickPattern, (match, listString, offset) => {
|
||||||
|
Reference in New Issue
Block a user