New exports

This commit is contained in:
bmen25124
2025-03-16 23:44:02 +03:00
parent 8ec83fd5d9
commit 0e41db615e
5 changed files with 36 additions and 20 deletions

View File

@ -1985,15 +1985,21 @@ export function fuzzySearchGroups(searchValue, fuzzySearchCaches = null) {
/**
* Renders a story string template with the given parameters.
* @param {object} params Template parameters.
* @param {object} [options] Additional options.
* @param {string} [options.customStoryString] Custom story string template.
* @param {InstructSettings} [options.customInstructSettings] Custom instruct settings.
* @returns {string} The rendered story string.
*/
export function renderStoryString(params) {
export function renderStoryString(params, { customStoryString = null, customInstructSettings = null } = {}) {
try {
const storyString = customStoryString ?? power_user.context.story_string;
const instructSettings = customInstructSettings ?? power_user.instruct;
// Validate and log possible warnings/errors
validateStoryString(power_user.context.story_string, params);
validateStoryString(storyString, params);
// compile the story string template into a function, with no HTML escaping
const compiledTemplate = Handlebars.compile(power_user.context.story_string, { noEscape: true });
const compiledTemplate = Handlebars.compile(storyString, { noEscape: true });
// render the story string template with the given params
let output = compiledTemplate(params);
@ -2006,7 +2012,7 @@ export function renderStoryString(params) {
// add a newline to the end of the story string if it doesn't have one
if (output.length > 0 && !output.endsWith('\n')) {
if (!power_user.instruct.enabled || power_user.instruct.wrap) {
if (!instructSettings.enabled || instructSettings.wrap) {
output += '\n';
}
}