-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Refactor Assistant Message Parsing for Issue #4692 #4693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Assistant Message Parsing for Issue #4692 #4693
Conversation
…ed increased log level
…conflict with numerous other things that just use the default.
- Add TextDirective alias for TextContent - Add ToolDirective alias for ToolUse - Add Directive union type for TextDirective | ToolDirective - Maintain backward compatibility with AssistantMessageContent alias - Update internal usage to use new type names
- Extract parsing logic from monolithic parseAssistantMessage function - Create StreamingParser with specialized handler classes: - TextContentHandler: handles text content parsing - ToolUseHandler: manages tool directive detection and parsing - ParameterHandler: processes tool parameters - Maintain original streaming behavior and backward compatibility - All tests pass, no breaking changes - Improve code organization and maintainability
- Extract TextContentHandler into TextContentHandler.ts - Extract ParameterHandler into ParameterHandler.ts - Extract ToolUseHandler into ToolUseHandler.ts - Create types.ts for shared type definitions - Update StreamingParser to import from separate files - Update index.ts exports to reference correct files - Update README.md to reflect new file structure - Maintain backward compatibility and streaming behavior - All tests pass, multi-contributor friendly structure
…d names - Moved StreamingParser to DirectiveStreamingParser in assistant-message/ - Renamed directives/ to parsers/ - Created new parser classes with updated names: TextContentParser, ToolUseParser, ParameterParser - Simplified method names to parse() and finalize() - Updated documentation in README.md
- Changed imports in DirectiveStreamingParser.ts to use the index.ts file in parsers/ for a cleaner import structure
| const toolContent = state.accumulator.slice(state.currentToolUseStartIndex) | ||
| const contentStartTag = `<${contentParamName}>` | ||
| const contentEndTag = `</${contentParamName}>` | ||
| const contentStartIndex = toolContent.indexOf(contentStartTag) + contentStartTag.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the write_to_file special case, compute the index for the start tag separately before adding its length. As is, if indexOf returns -1, adding tag length yields a false positive. Consider storing the raw index and checking it before computing contentStartIndex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a draft. I am reviewing more and I think this should be seriously refactored. PR coming after I am complete.
|
I rewrote the whole thing will submit under a new PR. |
Related GitHub Issue
Closes: #4692
Description
This PR refactors the assistant message parsing logic to improve maintainability and clarity, addressing issue #4692. The original monolithic structure in src/core/assistant-message/parseAssistantMessage.ts was difficult to maintain. The changes introduce a modular architecture with:
Test Procedure
pm test to confirm that all tests pass locally.
Type of Change
Pre-Submission Checklist
pm run lint).
pm test).
pm run changeset if this PR includes user-facing changes or dependency updates.
Screenshots / Videos
Not applicable for this change as it does not involve UI modifications.
Documentation Updates
Additional Notes
Please review the changes in src/core/assistant-message/ for the core refactoring of the parsing logic. The focus has been on ensuring backward compatibility and maintaining streaming behavior.
Get in Touch
Please provide your Discord username for reviewers or maintainers to reach you if they have questions about your PR.
Important
Refactor assistant message parsing by modularizing logic into specialized parsers, maintaining backward compatibility and streaming behavior.
DirectiveStreamingParserwith specialized parsers:TextContentParser,ToolUseParser,ParameterParser.src/core/assistant-message/parsers/.AssistantMessageContenttoDirectivewith alias for backward compatibility.parse()andfinalize().parseAssistantMessage.tsto useDirectiveStreamingParser.packages/evalsfiles to suppress prompts and update ports.This description was created by
for 2993a3a. You can customize this summary. It will automatically update as commits are pushed.