Add shallow character load mode

This commit is contained in:
Cohee
2025-03-04 10:00:12 +00:00
parent 70f762c006
commit 383806325a
6 changed files with 125 additions and 10 deletions

View File

@@ -1781,7 +1781,7 @@ export async function getCharacters() {
method: 'POST',
headers: getRequestHeaders(),
body: JSON.stringify({
'': '',
shallow: power_user.shallow_characters,
}),
});
if (response.ok === true) {
@@ -3658,6 +3658,9 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
setGenerationProgress(0);
generation_started = new Date();
// Prevent generation from shallow characters
await unshallowCharacter(this_chid);
// Occurs every time, even if the generation is aborted due to slash commands execution
await eventSource.emit(event_types.GENERATION_STARTED, type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage }, dryRun);
@@ -6704,9 +6707,42 @@ export function buildAvatarList(block, entities, { templateId = 'inline_avatar_t
}
}
/**
* Loads all the data of a shallow character.
* @param {string|undefined} characterId Array index
* @returns {Promise<void>} Promise that resolves when the character is unshallowed
*/
export async function unshallowCharacter(characterId) {
if (characterId === undefined) {
console.warn('Undefined character cannot be unshallowed');
return;
}
const character = characters[characterId];
if (!character) {
console.warn('Character not found:', characterId);
return;
}
// Character is not shallow
if (!character.shallow) {
return;
}
const avatar = character.avatar;
if (!avatar) {
console.warn('Character has no avatar field:', characterId);
return;
}
await getOneCharacter(avatar);
}
export async function getChat() {
//console.log('/api/chats/get -- entered for -- ' + characters[this_chid].name);
try {
await unshallowCharacter(this_chid);
const response = await $.ajax({
type: 'POST',
url: '/api/chats/get',