Repository navigation
fix(tools): normalize optional fillers before validation #1523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
anandgupta42
merged 5 commits into
feat/analyst-harness-dab-2026-10
from
fix/filler-safe-tool-params
Oct 16, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af1174b
fix(tools): normalize optional fillers before validation
anandgupta42 aa8bc0e
fix(tools): strip optional fillers only when validation fails
anandgupta42 335b9eb
fix(tools): keep valid optional siblings when one filler is rejected
anandgupta42 20c6997
fix(tools): pass plugin tool arguments through when they do not validate
anandgupta42 01c89ca
Merge origin/feat/analyst-harness-dab-2026-10
anandgupta42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import type { JSONSchema7 } from "@ai-sdk/provider" | ||
| import { Result, Schema, SchemaGetter } from "effect" | ||
|
|
||
| const normalized = new WeakSet<Schema.Top>() | ||
|
|
||
| /** Retry a rejected call with optional fillers removed; required values and nested payloads retain their meaning. */ | ||
| export function fillerSafeParameters<T>(parameters: Schema.Decoder<T>, jsonSchema: JSONSchema7): Schema.Decoder<T> { | ||
| // Legacy tools may publish a simpler wire schema than their validation schema. | ||
| if (normalized.has(parameters)) return parameters | ||
| const decodeResult = Schema.decodeUnknownResult(parameters) | ||
| const stripped = Schema.Unknown.pipe( | ||
| Schema.decodeTo(parameters, { | ||
| decode: SchemaGetter.transform((input) => { | ||
| if (!input || typeof input !== "object" || Array.isArray(input)) return input | ||
| const args = input as Record<string, unknown> | ||
| const properties = new Set<string>() | ||
| const required = new Set<string>() | ||
| const collect = (schema: JSONSchema7 | boolean) => { | ||
| if (typeof schema === "boolean") return | ||
| for (const name of Object.keys(schema.properties ?? {})) properties.add(name) | ||
| for (const name of schema.required ?? []) required.add(name) | ||
| for (const child of schema.allOf ?? []) collect(child) | ||
| for (const child of schema.anyOf ?? schema.oneOf ?? []) { | ||
| // Literal discriminants determine which arguments are required for this call. | ||
| if ( | ||
| typeof child !== "boolean" && | ||
| Object.entries(child.properties ?? {}).some( | ||
| ([key, field]) => | ||
| typeof field !== "boolean" && | ||
| child.required?.includes(key) && | ||
| key in args && | ||
| ((field.const !== undefined && field.const !== args[key]) || | ||
| (field.enum !== undefined && !field.enum.includes(args[key] as never))), | ||
| ) | ||
| ) | ||
| continue | ||
| collect(child) | ||
| } | ||
| } | ||
| collect(jsonSchema) | ||
| const isFiller = (key: string, value: unknown) => | ||
| properties.has(key) && | ||
| !required.has(key) && | ||
| (value === null || value === "" || value === 0 || (Array.isArray(value) && value.length === 0)) | ||
| const base = Object.fromEntries(Object.entries(args).filter(([key, value]) => !isFiller(key, value))) | ||
| // Keep each filler that is valid on its own so intentional siblings survive an unrelated filler. | ||
| const valid = (candidate: Record<string, unknown>) => Result.isSuccess(decodeResult(candidate)) | ||
|
anandgupta42 marked this conversation as resolved.
|
||
| const kept = Object.entries(args).filter( | ||
| ([key, value]) => isFiller(key, value) && valid({ ...base, [key]: value }), | ||
| ) | ||
| const merged = { ...base, ...Object.fromEntries(kept) } | ||
| return kept.length > 0 && valid(merged) ? merged : base | ||
|
anandgupta42 marked this conversation as resolved.
|
||
| }), | ||
| encode: SchemaGetter.transform((value) => value), | ||
| }), | ||
| ) | ||
| // Validate the arguments as sent first so intentional zero/empty values survive; only a call the | ||
| // schema rejects is retried with optional fillers removed. | ||
| const result = Schema.Union([parameters, stripped]) as unknown as Schema.Decoder<T> | ||
|
anandgupta42 marked this conversation as resolved.
|
||
| normalized.add(result) | ||
| return result | ||
| } | ||
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.