@@ -538,11 +538,21 @@ export const PromptArea = forwardRef<HTMLTextAreaElement, PromptAreaProps>(
538538 ( agent : Agent ) => {
539539 const name = agent . i18n ?. [ lang ] ?. name ?? agent . name
540540 const escaped = name . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
541+ const hyphenatedName = name
542+ . replace ( / \s + / g, '-' )
543+ . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
541544 const noSpaceName = name . replace ( / \s + / g, '' )
542545 const newPrompt = prompt
543- . replace ( new RegExp ( `(^|\\s)@\\[${ escaped } \\]\\s?` , 'i' ) , '$1' )
544- . replace ( new RegExp ( `(^|\\s)@${ noSpaceName } \\b\\s?` , 'i' ) , '$1' )
545- . replace ( new RegExp ( `(^|\\s)@${ agent . id } \\b\\s?` , 'i' ) , '$1' )
546+ . replace ( new RegExp ( `(^|\\s)@\\[${ escaped } \\]\\s?` , 'iu' ) , '$1' )
547+ . replace (
548+ new RegExp ( `(^|\\s)@${ hyphenatedName } (?=[\\s]|$)\\s?` , 'iu' ) ,
549+ '$1' ,
550+ )
551+ . replace (
552+ new RegExp ( `(^|\\s)@${ noSpaceName } (?=[\\s]|$)\\s?` , 'iu' ) ,
553+ '$1' ,
554+ )
555+ . replace ( new RegExp ( `(^|\\s)@${ agent . id } (?=[\\s]|$)\\s?` , 'iu' ) , '$1' )
546556 . replace ( / \s + / g, ' ' )
547557 . trim ( )
548558 handlePromptChange ( newPrompt )
@@ -563,8 +573,8 @@ export const PromptArea = forwardRef<HTMLTextAreaElement, PromptAreaProps>(
563573 '\\$&' ,
564574 )
565575 const newPrompt = prompt
566- . replace ( new RegExp ( `#${ name } \\b \\s?` , 'i ' ) , '' )
567- . replace ( new RegExp ( `#${ id } \\b \\s?` , 'i ' ) , '' )
576+ . replace ( new RegExp ( `#${ name } (?=[\\s]|$) \\s?` , 'iu ' ) , '' )
577+ . replace ( new RegExp ( `#${ id } (?=[\\s]|$) \\s?` , 'iu ' ) , '' )
568578 . replace ( / \s + / g, ' ' )
569579 . trim ( )
570580 handlePromptChange ( newPrompt )
@@ -580,8 +590,8 @@ export const PromptArea = forwardRef<HTMLTextAreaElement, PromptAreaProps>(
580590 . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
581591 const id = skill . id . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
582592 const newPrompt = prompt
583- . replace ( new RegExp ( `(^|\\s)\\/${ name } \\b \\s?` , 'i ' ) , '$1' )
584- . replace ( new RegExp ( `(^|\\s)\\/${ id } \\b \\s?` , 'i ' ) , '$1' )
593+ . replace ( new RegExp ( `(^|\\s)\\/${ name } (?=[\\s]|$) \\s?` , 'iu ' ) , '$1' )
594+ . replace ( new RegExp ( `(^|\\s)\\/${ id } (?=[\\s]|$) \\s?` , 'iu ' ) , '$1' )
585595 . replace ( / \s + / g, ' ' )
586596 . trim ( )
587597 handlePromptChange ( newPrompt )
@@ -600,8 +610,11 @@ export const PromptArea = forwardRef<HTMLTextAreaElement, PromptAreaProps>(
600610 '\\$&' ,
601611 )
602612 const newPrompt = prompt
603- . replace ( new RegExp ( `(^|\\s)\\/${ name } \\b\\s?` , 'i' ) , '$1' )
604- . replace ( new RegExp ( `(^|\\s)\\/${ provider } \\b\\s?` , 'i' ) , '$1' )
613+ . replace ( new RegExp ( `(^|\\s)\\/${ name } (?=[\\s]|$)\\s?` , 'iu' ) , '$1' )
614+ . replace (
615+ new RegExp ( `(^|\\s)\\/${ provider } (?=[\\s]|$)\\s?` , 'iu' ) ,
616+ '$1' ,
617+ )
605618 . replace ( / \s + / g, ' ' )
606619 . trim ( )
607620 handlePromptChange ( newPrompt )
0 commit comments