Add new WI position 'outlet' to expose WI entries triggered to be placed as macros literally anywhere (#4523)
* feat: add outlet prompt support for world info entries * feat: add outlet name field with autocomplete for world info entries * feat: add outlet entries for world info support to WI parsing * feat: add tooltip and validation for WI outlet name entries * Trim macro outlet name Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * refactor: consolidate WI injection cleanup and fix strict equality comparison * fix: update outlet macro regex pattern to use double colon delimiter * fix: replace carriage returns with newlines in WI entry outlet tooltip * fix: add null checks and array validation for WI outlet entries handling * feat: add outletName field to world info entry definition schema (supports /setwientryfield command) * fix: add outletName field to export of character lore books * do not remove outlet name on position change, but filter out for auto complete * Match WI extensions field name Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com> * outlet name being used in char WI import too * docs: add outlet macro documentation to help template * be explicit about risu/novel/agnai wi not supporting outlets * Inject A/N and TC sysprompt after populating outlets --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { Handlebars, moment, seedrandom, droll } from '../lib.js';
|
||||
import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams, eventSource, event_types } from '../script.js';
|
||||
import { chat, chat_metadata, main_api, getMaxContextSize, getCurrentChatId, substituteParams, eventSource, event_types, extension_prompts } from '../script.js';
|
||||
import { timestampToMoment, isDigitsOnly, getStringHash, escapeRegex, uuidv4 } from './utils.js';
|
||||
import { textgenerationwebui_banned_in_macros } from './textgen-settings.js';
|
||||
import { getInstructMacros } from './instruct-mode.js';
|
||||
import { getVariableMacros } from './variables.js';
|
||||
import { isMobile } from './RossAscends-mods.js';
|
||||
import { inject_ids } from './constants.js';
|
||||
|
||||
/**
|
||||
* @typedef Macro
|
||||
@@ -458,6 +459,17 @@ function getTimeDiffMacro() {
|
||||
return { regex: timeDiffPattern, replace: timeDiffReplace };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the outlet prompt for a given outlet key.
|
||||
* @param {string} key - The outlet key
|
||||
* @returns {string} The outlet prompt
|
||||
*/
|
||||
function getOutletPrompt(key) {
|
||||
const value = extension_prompts[inject_ids.CUSTOM_WI_OUTLET(key)]?.value;
|
||||
// Macros should already be parsed, but we'll do it again just in case
|
||||
return substituteParams(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Substitutes {{macro}} parameters in a string.
|
||||
* @param {string} content - The string to substitute parameters in.
|
||||
@@ -518,6 +530,7 @@ export function evaluateMacros(content, env, postProcessFn) {
|
||||
{ regex: /{{datetimeformat +([^}]*)}}/gi, replace: (_, format) => moment().format(format) },
|
||||
{ regex: /{{idle_duration}}/gi, replace: () => getTimeSinceLastMessage() },
|
||||
{ regex: /{{time_UTC([-+]\d+)}}/gi, replace: (_, offset) => moment().utc().utcOffset(parseInt(offset, 10)).format('LT') },
|
||||
{ regex: /{{outlet::(.+?)}}/gi, replace: (_, key) => getOutletPrompt(key.trim()) || '' },
|
||||
getTimeDiffMacro(),
|
||||
getBannedWordsMacro(),
|
||||
getRandomReplaceMacro(),
|
||||
|
||||
Reference in New Issue
Block a user