@@ -30,7 +30,35 @@ function hasFunctionCallOpenTag(text) {
3030 if ( typeof text !== 'string' ) return false ;
3131 return / < f u n c t i o n _ c a l l s \s * > / i. test ( text )
3232 || / \[ f u n c t i o n _ c a l l s \] / i. test ( text )
33- || / \[ t o o l _ c a l l s \] \s * $ / m. test ( text ) ;
33+ || / \[ t o o l _ c a l l s \] \s * $ / m. test ( text )
34+ || / < ( [ a - z _ ] [ a - z 0 - 9 _ - ] * ) \b [ ^ < > ] * q u e s t i o n \s * = / i. test ( text ) ;
35+ }
36+
37+ function hasStandaloneToolCallTags ( text ) {
38+ if ( typeof text !== 'string' ) return false ;
39+ return / < ( [ a - z _ ] [ a - z 0 - 9 _ - ] * ) \b [ ^ < > ] * \/ > \s * $ / i. test ( text )
40+ || / < ( [ a - z _ ] [ a - z 0 - 9 _ - ] * ) \b [ ^ < > ] * > [ ^ < ] * < \/ \1> / i. test ( text ) ;
41+ }
42+
43+ function extractStandaloneToolCallTags ( text ) {
44+ if ( typeof text !== 'string' ) return [ ] ;
45+
46+ const toolCalls = [ ] ;
47+ const selfClosingRegex = / < ( [ a - z _ ] [ a - z 0 - 9 _ - ] * ) \b ( [ ^ > ] * ) \/ > / gi;
48+ let match ;
49+
50+ while ( ( match = selfClosingRegex . exec ( text ) ) !== null ) {
51+ const tagName = match [ 1 ] . trim ( ) ;
52+ const attrsText = match [ 2 ] || '' ;
53+
54+ if ( shouldSkipContainerTag ( tagName ) ) continue ;
55+ if ( ! / (?: q u e s t i o n | c o m m a n d | p a t h | f i l e _ p a t h | c o n t e n t | u r l | q u e r y | t e x t | f o l l o w _ u p ) \s * = / i. test ( attrsText ) ) continue ;
56+
57+ const argumentsParsed = parseXmlAttributes ( attrsText ) ;
58+ toolCalls . push ( buildToolCall ( toolCalls . length , tagName , argumentsParsed ) ) ;
59+ }
60+
61+ return toolCalls ;
3462}
3563
3664// 从文本中提取所有 function_calls / tool_calls 块
@@ -506,6 +534,8 @@ function extractTextToolCallField(block, fieldName) {
506534module . exports = {
507535 hasFunctionCalls,
508536 hasFunctionCallOpenTag,
537+ hasStandaloneToolCallTags,
538+ extractStandaloneToolCallTags,
509539 extractFunctionCallsBlocks,
510540 parseFunctionCallsBlock,
511541 parseXmlToolCallsFromText,
0 commit comments