Commit a4dcb28
committed
fix(parser): Ensure sequential command extraction order
Refactored CommandParser.kt to correctly parse commands based on their order of appearance in the input text.
Previously, commands were searched by type in a fixed sequence, which could lead to commands being extracted in a different order than they were written if multiple command types were present in a single message.
The new implementation:
- Consolidates all regex patterns with associated command builders.
- Finds all potential matches for all patterns in the input text.
- Sorts these matches by their start index.
- Iterates through the sorted matches, selecting the first valid, non-overlapping command, thus preserving the original sequence.
- Retains logic for ensuring certain parameterless commands (e.g., TakeScreenshot) are only added once per parsing operation.
This change is crucial for ensuring that the command execution queue receives commands in the intended sequence.1 parent 4830719 commit a4dcb28
2 files changed
Lines changed: 211 additions & 629 deletions
File tree
- app/src/main/kotlin/com/google/ai/sample
- util
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| |||
0 commit comments