Commit ca6a22a
fix(core): handle null data in WaitFor and support array keyName in KeyboardPress (#1354)
* fix(core): handle null data in WaitFor and support array keyName in KeyboardPress
This commit fixes two critical bugs:
1. **Fix null data handling in task execution**
- Fixed TypeError when AI extract() returns null for WaitFor operations
- Added null/undefined check before accessing data properties
- WaitFor operations now return false when data is null (condition not met)
- Other operations (Assert, Query, String, Number) return null when data is null
- Location: src/agent/tasks.ts:936-938
2. **Add array support for keyName in KeyboardPress**
- Updated actionKeyboardPressParamSchema to accept string | string[]
- Allows key combinations like ['Control', 'A'] for keyboard shortcuts
- Maintains backward compatibility with string format
- Updated type definitions in aiKeyboardPress method
- Locations:
- src/device/index.ts:197-199
- src/agent/agent.ts:575-622
**Test Coverage:**
- Added comprehensive unit tests for null data handling (8 test cases)
- Added unit tests for keyName array validation (7 test cases)
- All tests verify edge cases and expected behavior
Fixes issue where executor crashed with:
"TypeError: Cannot read properties of null (reading 'StatementIsTruthy')"
And fixes parameter validation error:
"Invalid parameters for action KeyboardPress: Expected string, received array"
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(ios,android): handle array keyName in KeyboardPress action
- Updated iOS and Android device implementations to handle keyName as string | string[]
- For mobile devices, array keys are joined with '+' (e.g., ['Control', 'A'] becomes 'Control+A')
- This fixes TypeScript compilation errors in iOS and Android packages
- Maintains backward compatibility with string format
Related to the KeyboardPress array support added in the previous commit.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor(ios,android): improve KeyboardPress array handling
- Remove incorrect join('+') approach that doesn't work on mobile devices
- Use last key from array instead (e.g., ['Control', 'A'] → 'A')
- Add clear warning messages when array input is used on mobile platforms
- Mobile devices don't support keyboard combinations, this is a graceful degradation
This makes the behavior more predictable and provides better feedback to developers.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test(core): fix TaskExecutor constructor arguments in null data tests
- Fixed TaskExecutor constructor call to match actual signature
- Constructor requires (interface, insight, options) instead of (insight, interface)
- All 8 tests now passing
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(ios,android): improve logging for unsupported key combinations in device input
* fix(core): handle null data in WaitFor and improve keyName parameter description
This commit fixes the null data handling bug and improves the KeyboardPress parameter description.
## Changes:
### 1. Fix null data handling in task execution
- Fixed TypeError when AI extract() returns null for WaitFor operations
- Added null/undefined check before accessing data properties (tasks.ts:936-938)
- WaitFor operations now return false when data is null (condition not met)
- Other operations (Assert, Query, String, Number) return null when data is null
### 2. Improve KeyboardPress parameter description
- Reverted keyName to only accept string type (not array)
- Added clear description: "Use '+' for key combinations, e.g., 'Control+A', 'Shift+Enter'"
- This provides better guidance to AI for generating key combinations
- Simplified iOS/Android implementations (no special array handling needed)
### 3. Test coverage
- Added 8 unit tests for null data handling
- Updated KeyboardPress tests to validate string-only format
- Added test for key combination strings (e.g., 'Control+A')
- Added test to verify arrays are rejected
- Fixed unused variable warning in test file
## Fixed Issues:
**Issue 1:** Executor crashes with null data
```
TypeError: Cannot read properties of null (reading 'StatementIsTruthy')
```
**Issue 2:** Unclear how to specify key combinations
- Now clearly documented in parameter description with examples
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* docs(core): align KeyboardPress action description with parameter schema
Updated the KeyboardPress action description to explicitly mention
support for key combinations (e.g., "Control+A", "Shift+Enter"),
making it consistent with the keyName parameter description that
already documented this functionality.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(core): handle null and undefined data in WaitFor output processing
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c19cb5b commit ca6a22a
File tree
6 files changed
+388
-9
lines changed- packages
- android/src
- core
- src
- agent
- device
- tests/unit-test
- ios/src
6 files changed
+388
-9
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
215 | | - | |
216 | | - | |
| 215 | + | |
217 | 216 | | |
218 | 217 | | |
219 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
933 | 933 | | |
934 | 934 | | |
935 | 935 | | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
936 | 944 | | |
937 | 945 | | |
938 | | - | |
| 946 | + | |
939 | 947 | | |
940 | 948 | | |
941 | 949 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
198 | 202 | | |
199 | 203 | | |
200 | 204 | | |
| |||
210 | 214 | | |
211 | 215 | | |
212 | 216 | | |
213 | | - | |
| 217 | + | |
214 | 218 | | |
215 | 219 | | |
216 | 220 | | |
| |||
Lines changed: 66 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | | - | |
| 258 | + | |
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
324 | 388 | | |
0 commit comments