char-fork/llama.cpp
git clone https://git.t4t.associates/char-fork/llama.cpp
92d1bb0c9
char/aliceai-t5-moe
1// An `@` starts a mention only when preceded by start-of-string or one of 2// these; identifier chars are not delimiters, so a mid-word `@` does not. 3const TOKEN_BOUNDARY_CHARS = new Set ([ 4' ' , 5'\t' , 6'\n' , 7'\r' , 8'(' , 9')' , 10'[' , 11']' , 12',' , 13';' , 14':' , 15'"' , 16"'" 17]); 18 19/** 20* Find the most-recent `@`-mention token whose extent includes `cursor`; 21* the query covers the whole `@...` token regardless of caret position. 22*/ 23export function findMentionToken ( 24value :string , 25cursor :number 26) :{ start :number ; end :number ; query :string } | null { 27if ( cursor <= 0 || cursor > value . length ) return null ; 28 29let atIndex = - 1 ; 30 31for ( let i = cursor - 1 ; i >= 0 ; i -- ) { 32const ch = value [ i ]; 33 34if ( ch === '@' ) { 35const prev = i > 0 ?value [ i - 1 ] :'' ; 36 37if ( i === 0 || TOKEN_BOUNDARY_CHARS . has ( prev )) { 38atIndex = i ; 39} 40 41break ; 42} 43 44if ( TOKEN_BOUNDARY_CHARS . has ( ch )) break ; 45} 46 47if ( atIndex === - 1 ) return null ; 48 49let end = atIndex + 1 ; 50 51while ( end < value . length && ! TOKEN_BOUNDARY_CHARS . has ( value [ end ])) { 52end ++ ; 53} 54 55return { 56 end, 57query :value . slice ( atIndex + 1 , end ), 58start :atIndex 59}; 60} 61 62/** 63* Stable signature of a mention token for use as a "dismissed" marker: 64* while the picker is closed and this exact token is still intact, the 65* picker does not silently re-open on in-token edits. 66*/ 67export interface MentionDismissSnapshot { 68start :number ; 69query :string ; 70} 71 72export function takeMentionDismissSnapshot ( 73value :string , 74cursor :number 75) :MentionDismissSnapshot | null { 76const token = findMentionToken ( value , cursor ); 77 78if ( ! token ) return null ; 79 80return { query :token . query , start :token . start }; 81}