fix: apply feedback

This commit is contained in:
yassinedorbozgithub 2025-04-13 10:22:02 +01:00
parent 06b4c1a810
commit 2a08218b53
2 changed files with 12 additions and 4 deletions

View File

@ -30,7 +30,7 @@ export class ContextVarService extends BaseService<
* Retrieves a mapping of context variable names to their corresponding `ContextVar` objects for a given block.
*
* @param {Block | BlockFull} block - The block containing the capture variables to retrieve context variables for.
* @returns {Promise<Record<string, ContextVar>>} A promise that resolves to a record mapping context variable names to `ContextVar` objects.
* @returns {Promise<Record<string, ContextVar | undefined>>} A promise that resolves to a record mapping context variable names to `ContextVar` objects.
*/
async getContextVarsByBlock(
block: Block | BlockFull,

View File

@ -116,9 +116,17 @@ export class ConversationService extends BaseService<
const context_var = contextVars[capture.context_var];
const { permanent, pattern = '' } = context_var || {};
const isValidContextValue = new RegExp(pattern.slice(1, -1)).test(
`${contextValue}`,
);
const isValidContextValue = (() => {
try {
return new RegExp(pattern.slice(1, -1)).test(`${contextValue}`);
} catch (error) {
this.logger.error(
`Invalid regex pattern for ContextVar[${capture.context_var}]: ${pattern}`,
);
return false;
}
})();
if (isValidContextValue) {
if (profile.context?.vars && permanent) {
this.logger.debug(