#21498: fix #20898: handle array type in tryFlattenLiteralAnyOf
agents
size: XS
Cluster:
Tool Schema Fixes and Enhancements
## Summary
`tryFlattenLiteralAnyOf` silently fails when a schema variant uses `type: ["string"]` instead of `type: "string"`, even though both are valid JSON Schema.
## Changes
- `src/agents/schema/clean-for-gemini.ts`: Handle array type (e.g., `type: ["string"]`) in addition to string type.
## Testing
- [x] Code compiles and passes format check
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Extended `tryFlattenLiteralAnyOf` to handle array type syntax (e.g., `type: ["string"]`) in addition to string type syntax (e.g., `type: "string"`), both valid per JSON Schema spec. This prevents silent failures when flattening literal anyOf variants.
- handled single-element array types in `tryFlattenLiteralAnyOf` logic
- aligns with existing `isNullSchema` pattern which already handles array types
- missing type validation: array element should be verified as string (see comment)
<h3>Confidence Score: 3/5</h3>
- This PR is mostly safe but has a minor type safety gap that should be addressed
- The change correctly handles array type syntax and aligns with JSON Schema spec and existing patterns in the file (like `isNullSchema`). However, missing type validation for the array element at line 72 creates a potential runtime issue - if `v.type[0]` is not a string, the subsequent type comparison logic could behave unexpectedly. This is a logical error that needs to be fixed.
- src/agents/schema/clean-for-gemini.ts requires attention for the type validation issue
<sub>Last reviewed commit: 2e8be7a</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#20990: fix: Handle single-element type arrays in tryFlattenLiteralAnyOf
by chilu18 · 2026-02-19
88.0%
#17885: fix: replace anyOf union type in image tool schema
by pierreeurope · 2026-02-16
68.9%
#23507: fix(tools): strip patternProperties from schemas for OpenAI-compati...
by long-pham · 2026-02-22
66.5%
#20249: fix(schema): ensure normalizeToolParameters always includes propert...
by aldoeliacim · 2026-02-18
66.0%
#22214: fix(tools): sanitize google-antigravity schemas for Gemini-compatib...
by Kansodata · 2026-02-20
65.8%
#21835: fix: apply schema cleaning for google-antigravity in normalizeToolP...
by ephraimm · 2026-02-20
65.2%
#10197: fix: add missing allowAgents to agent defaults subagents schema
by Yida-Dev · 2026-02-06
64.8%
#11141: Fix JSON schema conversion error when using llama.cpp backend
by 9nix00 · 2026-02-07
64.1%
#12642: feat(tools): typed tool schemas for xAI/Grok compatibility
by 2nd-ren · 2026-02-09
64.0%
#22321: fix: sanitize tool schemas for all Cloud Code Assist providers
by Sr-0w · 2026-02-21
63.6%