mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add "ephemeral" option script /inject
This commit is contained in:
@ -1112,6 +1112,9 @@ SlashCommandParser.addCommandObject(SlashCommand.fromProps({
|
|||||||
new SlashCommandNamedArgument(
|
new SlashCommandNamedArgument(
|
||||||
'role', 'role for in-chat injections', [ARGUMENT_TYPE.STRING], false, false, 'system', ['system', 'user', 'assistant'],
|
'role', 'role for in-chat injections', [ARGUMENT_TYPE.STRING], false, false, 'system', ['system', 'user', 'assistant'],
|
||||||
),
|
),
|
||||||
|
new SlashCommandNamedArgument(
|
||||||
|
'ephemeral', 'remove injection after generation', [ARGUMENT_TYPE.BOOLEAN], false, false, 'false', ['true', 'false'],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
unnamedArgumentList: [
|
unnamedArgumentList: [
|
||||||
new SlashCommandArgument(
|
new SlashCommandArgument(
|
||||||
@ -1173,6 +1176,7 @@ function injectCallback(args, value) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const id = resolveVariable(args?.id);
|
const id = resolveVariable(args?.id);
|
||||||
|
const ephemeral = isTrueBoolean(args?.ephemeral);
|
||||||
|
|
||||||
if (!id) {
|
if (!id) {
|
||||||
console.warn('WARN: No ID provided for /inject command');
|
console.warn('WARN: No ID provided for /inject command');
|
||||||
@ -1206,6 +1210,16 @@ function injectCallback(args, value) {
|
|||||||
|
|
||||||
setExtensionPrompt(prefixedId, value, position, depth, scan, role);
|
setExtensionPrompt(prefixedId, value, position, depth, scan, role);
|
||||||
saveMetadataDebounced();
|
saveMetadataDebounced();
|
||||||
|
|
||||||
|
if (ephemeral) {
|
||||||
|
const unsetInject = () => {
|
||||||
|
console.log('Removing ephemeral script injection', id);
|
||||||
|
delete chat_metadata.script_injects[id];
|
||||||
|
};
|
||||||
|
eventSource.once(event_types.GENERATION_ENDED, unsetInject);
|
||||||
|
eventSource.once(event_types.GENERATION_STOPPED, unsetInject);
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user