/inject: auto-generate ID and fix argument description (#4253) * /inject: auto-generate ID and fix argument description * Fix default depth and role handling * Return ID of the new inject

febb02ffcb9149b364acd48a0fc1525010ba5d45

Cohee <18619528+Cohee1207@users.noreply.github.com>

Signed
1 files changed, +8 -13Showing whitespace changes
public/scripts/slash-commands.js+8 -13
@@ -2266,13 +2266,14 @@ export function initDefaultSlashCommands() {
2266 }));2266 }));
2267 SlashCommandParser.addCommandObject(SlashCommand.fromProps({2267 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
2268 name: 'inject',2268 name: 'inject',
2269 returns: 'injection ID',
2269 callback: injectCallback,2270 callback: injectCallback,
2270 namedArgumentList: [2271 namedArgumentList: [
2271 SlashCommandNamedArgument.fromProps({2272 SlashCommandNamedArgument.fromProps({
2272 name: 'id',2273 name: 'id',
2273 description: 'injection ID or variable name pointing to ID',2274 description: 'injection ID',
2274 typeList: [ARGUMENT_TYPE.STRING],2275 typeList: [ARGUMENT_TYPE.STRING],
2275 isRequired: true,2276 isRequired: false,
2276 enumProvider: commonEnumProviders.injects,2277 enumProvider: commonEnumProviders.injects,
2277 }),2278 }),
2278 new SlashCommandNamedArgument(2279 new SlashCommandNamedArgument(
@@ -2311,7 +2312,7 @@ export function initDefaultSlashCommands() {
2311 'text', [ARGUMENT_TYPE.STRING], false,2312 'text', [ARGUMENT_TYPE.STRING], false,
2312 ),2313 ),
2313 ],2314 ],
2314 helpString: 'Injects a text into the LLM prompt for the current chat. Requires a unique injection ID. Positions: "before" main prompt, "after" main prompt, in-"chat", hidden with "none" (default: after). Depth: injection depth for the prompt (default: 4). Role: role for in-chat injections (default: system). Scan: include injection content into World Info scans (default: false). Hidden injects in "none" position are not inserted into the prompt but can be used for triggering WI entries.',2315 helpString: 'Injects a text into the LLM prompt for the current chat. Requires a unique injection ID (will be auto-generated if not provided). Positions: "before" main prompt, "after" main prompt, in-"chat", hidden with "none" (default: after). Depth: injection depth for the prompt (default: 4). Role: role for in-chat injections (default: system). Scan: include injection content into World Info scans (default: false). Hidden injects in "none" position are not inserted into the prompt but can be used for triggering WI entries. Returns the injection ID.',
2315 }));2316 }));
2316 SlashCommandParser.addCommandObject(SlashCommand.fromProps({2317 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
2317 name: 'listinjects',2318 name: 'listinjects',
@@ -2987,23 +2988,17 @@ function injectCallback(args, value) {
2987 'assistant': extension_prompt_roles.ASSISTANT,2988 'assistant': extension_prompt_roles.ASSISTANT,
2988 };2989 };
29892990
2990 const id = String(args?.id ?? '');2991 const id = String(args?.id ?? '') || Math.random().toString(36).substring(2);
2991 const ephemeral = isTrueBoolean(String(args?.ephemeral ?? ''));2992 const ephemeral = isTrueBoolean(String(args?.ephemeral ?? ''));
29922993
2993 if (!id) {
2994 console.warn('WARN: No ID provided for /inject command');
2995 toastr.warning('No ID provided for /inject command');
2996 return '';
2997 }
2998
2999 const defaultPosition = 'after';2994 const defaultPosition = 'after';
3000 const defaultDepth = 4;2995 const defaultDepth = 4;
3001 const positionValue = args?.position ?? defaultPosition;2996 const positionValue = args?.position ?? defaultPosition;
3002 const position = positions[positionValue] ?? positions[defaultPosition];2997 const position = positions[positionValue] ?? positions[defaultPosition];
3003 const depthValue = Number(args?.depth) ?? defaultDepth;2998 const depthValue = Number(args?.depth ?? defaultDepth);
3004 const depth = isNaN(depthValue) ? defaultDepth : depthValue;2999 const depth = isNaN(depthValue) ? defaultDepth : depthValue;
3005 const roleValue = typeof args?.role === 'string' ? args.role.toLowerCase().trim() : Number(args?.role ?? extension_prompt_roles.SYSTEM);3000 const roleValue = typeof args?.role === 'string' ? args.role.toLowerCase().trim() : Number(args?.role ?? extension_prompt_roles.SYSTEM);
3006 const role = roles[roleValue] ?? roles[extension_prompt_roles.SYSTEM];3001 const role = roles[roleValue] ?? extension_prompt_roles.SYSTEM;
3007 const scan = isTrueBoolean(String(args?.scan));3002 const scan = isTrueBoolean(String(args?.scan));
3008 const filter = args?.filter instanceof SlashCommandClosure ? args.filter.rawText : null;3003 const filter = args?.filter instanceof SlashCommandClosure ? args.filter.rawText : null;
3009 const filterFunction = args?.filter instanceof SlashCommandClosure ? closureToFilter(args.filter) : null;3004 const filterFunction = args?.filter instanceof SlashCommandClosure ? closureToFilter(args.filter) : null;
@@ -3045,7 +3040,7 @@ function injectCallback(args, value) {
3045 eventSource.once(event_types.GENERATION_STOPPED, unsetInject);3040 eventSource.once(event_types.GENERATION_STOPPED, unsetInject);
3046 }3041 }
30473042
3048 return '';3043 return id;
3049}3044}
30503045
3051async function listInjectsCallback(args) {3046async function listInjectsCallback(args) {