Fix schemas for non-string widget options - #63
Conversation
Include observed typed choice values in advertised enums so select and multiselect models validate against their own schemas. Add a regression covering all affected widget kinds.\n\nFixes dkedar7#62
…one (dkedar7#62) Completes the non-string-option schema fix. Keying the enum off the current value alone made the reported value a member of its own enum, but left the schema unable to express any *other* option in its typed form: a selectbox([1,2,3]) sitting on 1 advertised {"enum": [1,"1","2","3"]}, so an agent following the schema was told only the string form of 2 was valid — while set_widget(id, 2) is in fact accepted (dkedar7#51). An agent must be able to construct any valid set from what's advertised, not merely echo back the selection it was handed. The current value's type is still the only evidence available (the widget protobuf carries options already stringified), but it is now used to recover the typed form of *every* option, guarded by a str(recovered) == option round-trip check so a typed member always denotes the option it came from. Non-recoverable options ('two' among ints) stay string-only, and bool gets its own mapping since bool('False') is True. Also restores the shared TYPED_OPTIONS_APP multiselect to its no-default form and covers that case separately: with nothing selected there is no type evidence, so the enum stays the string form — correct and settable, just less informative, now asserted so the fallback stays deliberate. Resolves the merge with dkedar7#61: the selectbox/radio null special-case this branch was written against is gone; _make_nullable now widens by value, so a placeholder with typed options still round-trips null through the shared path. Co-Authored-By: Sanjay Santhanam <Sanjays2402@users.noreply.github.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Jwy1qnSc3WhDHkXfxNb7jX
|
Thanks for this @Sanjays2402 — the core insight is right and it's the one I'd have reached for: the widget protobuf carries options already stringified ( I've pushed two commits on top (maintainer edits were enabled — shout if you'd rather I hadn't) to close two gaps: 1. The enum only expressed the selected option in its typed form. On That recovery is guarded by a 2. The I also resolved the merge against #61, which landed a few minutes ago — the selectbox/radio null special-case this branch was written against is gone, replaced by a value-keyed Verified on the CLI and over the real MCP stdio transport (this project's bar for a dogfood fix), plus 6 regression tests — 3 of which fail against the unfixed schema path. Merging this as yours. Genuinely useful contribution — thanks for digging into a subtle one. |
Fixes #62.
AppTest preserves the current value's type for non-string options but stringifies the option list. Include the observed typed value alongside the accepted string forms so selectbox, radio, select-slider, and multiselect values satisfy their advertised enum.
Added a regression covering all affected widget kinds; it fails without the source change and passes with it.