/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() {
22662266 }));
22672267 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
22682268 name: 'inject',
2269+ returns: 'injection ID',
22692270 callback: injectCallback,
22702271 namedArgumentList: [
22712272 SlashCommandNamedArgument.fromProps({
22722273 name: 'id',
22732274 description: 'injection ID or variable name pointing to ID',
22742275 typeList: [ARGUMENT_TYPE.STRING],
22752276 isRequired: truefalse,
22762277 enumProvider: commonEnumProviders.injects,
22772278 }),
22782279 new SlashCommandNamedArgument(
@@ -2311,7 +2312,7 @@ export function initDefaultSlashCommands() {
23112312 'text', [ARGUMENT_TYPE.STRING], false,
23122313 ),
23132314 ],
23142315 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.',
23152316 }));
23162317 SlashCommandParser.addCommandObject(SlashCommand.fromProps({
23172318 name: 'listinjects',
@@ -2987,23 +2988,17 @@ function injectCallback(args, value) {
29872988 'assistant': extension_prompt_roles.ASSISTANT,
29882989 };
29892990
29902991 const id = String(args?.id ?? '') || Math.random().toString(36).substring(2);
29912992 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-
29992994 const defaultPosition = 'after';
30002995 const defaultDepth = 4;
30012996 const positionValue = args?.position ?? defaultPosition;
30022997 const position = positions[positionValue] ?? positions[defaultPosition];
30032998 const depthValue = Number(args?.depth) ?? defaultDepth);
30042999 const depth = isNaN(depthValue) ? defaultDepth : depthValue;
30053000 const roleValue = typeof args?.role === 'string' ? args.role.toLowerCase().trim() : Number(args?.role ?? extension_prompt_roles.SYSTEM);
30063001 const role = roles[roleValue] ?? roles[extension_prompt_roles.SYSTEM];
30073002 const scan = isTrueBoolean(String(args?.scan));
30083003 const filter = args?.filter instanceof SlashCommandClosure ? args.filter.rawText : null;
30093004 const filterFunction = args?.filter instanceof SlashCommandClosure ? closureToFilter(args.filter) : null;
@@ -3045,7 +3040,7 @@ function injectCallback(args, value) {
30453040 eventSource.once(event_types.GENERATION_STOPPED, unsetInject);
30463041 }
30473042
30483043 return ''id;
30493044}
30503045
30513046async function listInjectsCallback(args) {