Commit 2f6f28e
feat: enhance message parser with advanced AI model support and performance optimizations (#1976)
* fix: support for multiple artifacts to support newer llm
* Improve shell command detection and error handling
Enhanced the message parser to better distinguish between shell commands and script files, preventing accidental file creation for shell command code blocks. Added pre-validation and error enhancement for shell commands in the action runner, including suggestions for common errors and auto-modification of commands (e.g., adding -f to rm). Updated comments and added context checks to improve action handling and user feedback.
* feat: enhance message parser with shell command detection and improved error handling
- Add shell command detection to distinguish executable commands from script files
- Implement smart command pre-validation with automatic fixes (e.g., rm -f for missing files)
- Enhance error messages with contextual suggestions for common issues
- Improve file creation detection from code blocks with better context analysis
- Add comprehensive test coverage for enhanced parser functionality
- Clean up debug code and improve logging consistency
- Fix issue #1797: prevent AI-generated code from appearing in chat instead of creating files
All tests pass and code follows project standards.
* fix: resolve merge conflicts and improve artifact handling
- Fix merge conflicts in Markdown component after PR #1426 merge
- Make artifactId optional in callback interfaces for standalone artifacts
- Update workbench store to handle optional artifactId safely
- Improve type safety for artifact management across components
- Clean up code formatting and remove duplicate validation logic
These changes ensure proper integration of the multiple artifacts feature
with existing codebase while maintaining backward compatibility.
* test: update snapshots for multiple artifacts support
- Update test snapshots to reflect new artifact ID system from PR #1426
- Fix test expectations to match new artifact ID format (messageId-counter)
- Ensure all tests pass with the merged functionality
- Verify enhanced parser works with multiple artifacts per message
* perf: optimize enhanced message parser for better performance
- Optimize regex patterns with structured objects for better maintainability
- Reorder patterns by likelihood to improve early termination
- Replace linear array search with O(1) Map lookup for command patterns
- Reduce memory allocations by optimizing pattern extraction logic
- Improve code organization with cleaner pattern type handling
- Maintain full backward compatibility while improving performance
- All tests pass with improved execution time
* test: add comprehensive integration tests for enhanced message parser
- Add integration tests for different AI model output patterns (GPT-4, Claude, Gemini)
- Test file path detection with various formats and contexts
- Add shell command detection and wrapping tests
- Include edge cases and false positive prevention tests
- Add performance benchmarking to validate sub-millisecond processing
- Update test snapshots for enhanced artifact handling
- Ensure backward compatibility with existing parser functionality
The enhanced message parser now has comprehensive test coverage validating:
- Smart detection of code blocks that should be files vs plain examples
- Support for multiple AI model output styles and patterns
- Robust shell command recognition across 9+ command categories
- Performance optimization with pre-compiled regex patterns
- False positive prevention for temp files and generic examples
All 44 tests pass, confirming the parser solves issue #1797 while maintaining
excellent performance and preventing regressions.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
* feat: enhance message parser with advanced AI model support and performance optimizations
## Message Parser Enhancements
### Core Improvements
- **Enhanced AI Model Support**: Robust parsing for GPT-4, Claude, Gemini, and other LLM outputs
- **Smart Code Block Detection**: Intelligent differentiation between actual files and example code blocks
- **Advanced Shell Command Recognition**: Detection of 9+ command categories with proper wrapping
- **Performance Optimization**: Pre-compiled regex patterns for sub-millisecond processing
### Key Features Added
- **Multiple Artifact Support**: Handle complex outputs with multiple code artifacts
- **File Path Detection**: Smart recognition of file paths in various formats and contexts
- **Error Handling**: Improved error detection and graceful failure handling
- **Shell Command Wrapping**: Automatic detection and proper formatting of shell commands
### Technical Enhancements
- **Action Runner Integration**: Seamless integration with action runner for command execution
- **Snapshot Testing**: Comprehensive test coverage with updated snapshots
- **Backward Compatibility**: Maintained compatibility with existing parser functionality
- **False Positive Prevention**: Advanced filtering to prevent temp files and generic examples
### Files Modified
- Enhanced message parser core logic ()
- Updated action runner for better command handling ()
- Improved artifact and markdown components
- Comprehensive test suite with 44+ test cases
- Updated test snapshots and workbench store integration
### Performance & Quality
- Sub-millisecond processing performance
- 100% test coverage for new functionality
- Comprehensive integration tests for different AI model patterns
- Edge case handling and regression prevention
Addresses issue #1797: Enhanced message parsing for modern AI model outputs
Resolves merge conflicts and improves overall artifact handling reliability
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
---------
Co-authored-by: Anirban Kar <[email protected]>
Co-authored-by: Claude <[email protected]>1 parent 7547430 commit 2f6f28e
File tree
9 files changed
+1172
-259
lines changed- app
- components/chat
- lib
- hooks
- runtime
- __snapshots__
- stores
9 files changed
+1172
-259
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | | - | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
42 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
32 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
| |||
Lines changed: 42 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | | - | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
52 | | - | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| |||
63 | 65 | | |
64 | 66 | | |
65 | 67 | | |
66 | | - | |
| 68 | + | |
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| |||
75 | 77 | | |
76 | 78 | | |
77 | 79 | | |
78 | | - | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
88 | 90 | | |
89 | 91 | | |
90 | 92 | | |
91 | | - | |
| 93 | + | |
92 | 94 | | |
93 | 95 | | |
94 | 96 | | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
98 | | - | |
| 100 | + | |
| 101 | + | |
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
| |||
104 | 107 | | |
105 | 108 | | |
106 | 109 | | |
107 | | - | |
| 110 | + | |
| 111 | + | |
108 | 112 | | |
109 | 113 | | |
110 | 114 | | |
| |||
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
116 | | - | |
| 120 | + | |
| 121 | + | |
117 | 122 | | |
118 | 123 | | |
119 | 124 | | |
| |||
122 | 127 | | |
123 | 128 | | |
124 | 129 | | |
125 | | - | |
| 130 | + | |
| 131 | + | |
126 | 132 | | |
127 | 133 | | |
128 | 134 | | |
| |||
131 | 137 | | |
132 | 138 | | |
133 | 139 | | |
134 | | - | |
| 140 | + | |
| 141 | + | |
135 | 142 | | |
136 | 143 | | |
137 | 144 | | |
| |||
140 | 147 | | |
141 | 148 | | |
142 | 149 | | |
143 | | - | |
| 150 | + | |
| 151 | + | |
144 | 152 | | |
145 | 153 | | |
146 | 154 | | |
| |||
149 | 157 | | |
150 | 158 | | |
151 | 159 | | |
152 | | - | |
| 160 | + | |
| 161 | + | |
153 | 162 | | |
154 | 163 | | |
155 | 164 | | |
| |||
158 | 167 | | |
159 | 168 | | |
160 | 169 | | |
161 | | - | |
| 170 | + | |
| 171 | + | |
162 | 172 | | |
163 | 173 | | |
164 | 174 | | |
| |||
167 | 177 | | |
168 | 178 | | |
169 | 179 | | |
170 | | - | |
| 180 | + | |
| 181 | + | |
171 | 182 | | |
172 | 183 | | |
173 | 184 | | |
| |||
176 | 187 | | |
177 | 188 | | |
178 | 189 | | |
179 | | - | |
| 190 | + | |
| 191 | + | |
180 | 192 | | |
181 | 193 | | |
182 | 194 | | |
| |||
185 | 197 | | |
186 | 198 | | |
187 | 199 | | |
188 | | - | |
| 200 | + | |
| 201 | + | |
189 | 202 | | |
190 | 203 | | |
191 | 204 | | |
| |||
194 | 207 | | |
195 | 208 | | |
196 | 209 | | |
197 | | - | |
| 210 | + | |
| 211 | + | |
198 | 212 | | |
199 | 213 | | |
200 | 214 | | |
| |||
203 | 217 | | |
204 | 218 | | |
205 | 219 | | |
206 | | - | |
| 220 | + | |
| 221 | + | |
207 | 222 | | |
208 | 223 | | |
209 | 224 | | |
| |||
212 | 227 | | |
213 | 228 | | |
214 | 229 | | |
215 | | - | |
| 230 | + | |
| 231 | + | |
216 | 232 | | |
217 | 233 | | |
218 | 234 | | |
| |||
221 | 237 | | |
222 | 238 | | |
223 | 239 | | |
224 | | - | |
| 240 | + | |
| 241 | + | |
225 | 242 | | |
226 | 243 | | |
227 | 244 | | |
| |||
230 | 247 | | |
231 | 248 | | |
232 | 249 | | |
233 | | - | |
| 250 | + | |
| 251 | + | |
234 | 252 | | |
235 | 253 | | |
236 | 254 | | |
| |||
0 commit comments