/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
Signed| @@ -2266,13 +2266,14 @@ export function initDefaultSlashCommands() { | ||
| 2266 | 2266 | })); |
| 2267 | 2267 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 2268 | 2268 | name: 'inject', |
| 2269 | + returns: 'injection ID', | |
| 2269 | 2270 | callback: injectCallback, |
| 2270 | 2271 | namedArgumentList: [ |
| 2271 | 2272 | SlashCommandNamedArgument.fromProps({ |
| 2272 | 2273 | name: 'id', |
| 2273 | 2274 | description: 'injection ID or variable name pointing to ID', |
| 2274 | 2275 | typeList: [ARGUMENT_TYPE.STRING], |
| 2275 | 2276 | isRequired: truefalse, |
| 2276 | 2277 | enumProvider: commonEnumProviders.injects, |
| 2277 | 2278 | }), |
| 2278 | 2279 | new SlashCommandNamedArgument( |
| @@ -2311,7 +2312,7 @@ export function initDefaultSlashCommands() { | ||
| 2311 | 2312 | 'text', [ARGUMENT_TYPE.STRING], false, |
| 2312 | 2313 | ), |
| 2313 | 2314 | ], |
| 2314 | 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 | 2317 | SlashCommandParser.addCommandObject(SlashCommand.fromProps({ |
| 2317 | 2318 | name: 'listinjects', |
| @@ -2987,23 +2988,17 @@ function injectCallback(args, value) { | ||
| 2987 | 2988 | 'assistant': extension_prompt_roles.ASSISTANT, |
| 2988 | 2989 | }; |
| 2989 | 2990 | |
| 2990 | 2991 | const id = String(args?.id ?? '') || Math.random().toString(36).substring(2); |
| 2991 | 2992 | const ephemeral = isTrueBoolean(String(args?.ephemeral ?? '')); |
| 2992 | 2993 | |
| 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 | 2994 | const defaultPosition = 'after'; |
| 3000 | 2995 | const defaultDepth = 4; |
| 3001 | 2996 | const positionValue = args?.position ?? defaultPosition; |
| 3002 | 2997 | const position = positions[positionValue] ?? positions[defaultPosition]; |
| 3003 | 2998 | const depthValue = Number(args?.depth) ?? defaultDepth); |
| 3004 | 2999 | const depth = isNaN(depthValue) ? defaultDepth : depthValue; |
| 3005 | 3000 | const roleValue = typeof args?.role === 'string' ? args.role.toLowerCase().trim() : Number(args?.role ?? extension_prompt_roles.SYSTEM); |
| 3006 | 3001 | const role = roles[roleValue] ?? roles[extension_prompt_roles.SYSTEM]; |
| 3007 | 3002 | const scan = isTrueBoolean(String(args?.scan)); |
| 3008 | 3003 | const filter = args?.filter instanceof SlashCommandClosure ? args.filter.rawText : null; |
| 3009 | 3004 | const filterFunction = args?.filter instanceof SlashCommandClosure ? closureToFilter(args.filter) : null; |
| @@ -3045,7 +3040,7 @@ function injectCallback(args, value) { | ||
| 3045 | 3040 | eventSource.once(event_types.GENERATION_STOPPED, unsetInject); |
| 3046 | 3041 | } |
| 3047 | 3042 | |
| 3048 | 3043 | return ''id; |
| 3049 | 3044 | } |
| 3050 | 3045 | |
| 3051 | 3046 | async function listInjectsCallback(args) { |