@@ -700,6 +700,7 @@ static void parse_json_tool_calls(
700700 size_t from = std::string::npos;
701701 auto first = true ;
702702 while (true ) {
703+ auto start_pos = builder.pos ();
703704 auto res = function_regex_start_only && first
704705 ? builder.try_consume_regex (*function_regex_start_only)
705706 : function_regex
@@ -720,12 +721,7 @@ static void parse_json_tool_calls(
720721 from = res->groups [0 ].begin + 1 ;
721722 continue ;
722723 }
723- if (update_cursor) {
724- builder.move_to (res->groups [0 ].end );
725- from = builder.pos ();
726- } else {
727- from = std::string::npos;
728- }
724+ from = std::string::npos;
729725
730726 auto maybe_raw_python = name == " python" && allow_raw_python;
731727 if (builder.input ()[builder.pos ()] == ' {' || !maybe_raw_python) {
@@ -734,16 +730,8 @@ static void parse_json_tool_calls(
734730 throw common_chat_msg_partial_exception (" incomplete tool call" );
735731 }
736732 builder.consume_regex (close_regex);
737- if (update_cursor) {
738- from = builder.pos (); // continue after this call
739- continue ;
740- }
741- }
742- if (update_cursor) {
743- throw common_chat_msg_partial_exception (" incomplete tool call" );
744- } else {
745- continue ;
746733 }
734+ continue ;
747735 }
748736 if (maybe_raw_python) {
749737 auto arguments = wrap_code_as_arguments (builder, builder.consume_rest ());
@@ -753,22 +741,21 @@ static void parse_json_tool_calls(
753741 return ;
754742 }
755743 throw common_chat_msg_partial_exception (" incomplete tool call" );
744+ } else {
745+ if (update_cursor) {
746+ builder.move_to (start_pos);
747+ }
756748 }
757749 break ;
758750 }
759751 if (block_close) {
760- if (update_cursor) {
761- // ensure we’re right after the last call header/close
762- if (from != std::string::npos) builder.move_to (from);
763- }
764752 builder.consume_regex (*block_close);
765753 }
766754 builder.consume_spaces ();
767755 builder.add_content (builder.consume_rest ());
768756 };
769757 if (block_open) {
770758 if (auto res = builder.try_find_regex (*block_open)) {
771- if (update_cursor) builder.move_to (res->groups [0 ].end ); // consume opener
772759 parse_tool_calls ();
773760 } else {
774761 builder.add_content (builder.consume_rest ());
@@ -1519,7 +1506,7 @@ static void common_chat_parse_deepseek_v3_1_content(common_chat_msg_parser & bui
15191506 tool_calls_end,
15201507 false ,
15211508 nullptr ,
1522- true );
1509+ /* update_cursor */ true );
15231510}
15241511
15251512static void common_chat_parse_deepseek_v3_1 (common_chat_msg_parser & builder) {
0 commit comments