Repository navigation
fix(ai): decode JSON-encoded tool arguments for Records, typeless unions and protocol-validated schemas - #6503
Open
surlymochan wants to merge 2 commits into
Open
surlymochan wants to merge 2 commits into
surlymochan wants to merge 2 commits into
Conversation
…ons and protocol-validated schemas Fixes code-yeongyu#6271
Owner
|
Thanks @surlymochan for closing the three shapes that #6266's pass left out (#6271): Record values resolved through The checks that ran are green. I've passed it on for maintainer review, including the full-CI run that a maintainer has to start on senpi. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6271.
What changes
packages/ai/src/utils/validation.ts:decodeJsonEncodedStructures()now covers the three shapes the #6266 pass missed:patternPropertiesas well asproperties/additionalProperties, so{k: '["a"]'}againstRecord(String, Array(String))decodes to{k: ["a"]}instead of validating as['["a"]'].type, decoding recurses into theanyOf/oneOfmembers that accept the value's kind, so JSON text nested inside e.g.Union([Array(Array(String)), Null])is decoded.validateToolArguments()now runs the decode before the protocol-validator early return, so those tools no longer keep the pre-fix(ai): decode JSON-encoded array/object tool arguments before conversion #6266 behaviour for JSON-encoded arrays/objects.packages/ai/test/validation.test.ts: table-driven regression tests for all three shapes (senpi#6271). All three failed before the fix for the intended reason (see below) and pass after it.Test evidence
RED (before fix,
test/validation.test.ts -t "6271"): 3 failed / 18 skipped — Record got{ values: { k: ['["a"]'] } }, the union kept the inner'["a"]'string, the protocol-validated call threwValidation failed.GREEN (after fix, full file): 21 passed / 0 failed.
Static checks:
oxlint --deny-warnings0 warnings,bun fmt --checkclean,bun check --no-scriptno type errors on the two touched files, and the repo pre-commit hook (fmt+oxlint --fix+npm run checkincl. browser-smoke) passed on commit.Change fragment
changes/unreleased/<this PR number>.mdfollows in a second push (named for the PR number perchanges/unreleased/README.md): tracker block forpackages/ai/src/utils/changes.mdcorrecting the #6266 MCP coverage sentence — the core fix covers MCP tools whose schemas no extension owns only for legacy MCP schemas; protocol-validated modern MCP schemas now get the decode too — plus aFixedchangelog bullet for@earendil-works/pi-ai.Summary by cubic
Fixes #6271 by decoding JSON-encoded tool arguments in the three shapes the #6266 fix missed: Record values under
patternProperties, JSON text nested in typeless unions, and protocol-validated modern MCP schemas.patternPropertiesas well asproperties/additionalProperties.typenow recurse intoanyOf/oneOfmembers that accept the value's kind.changes/unreleased/6503.mdfragment logging the fix.Written for commit 9e22b53. Summary will update on new commits.