Repository navigation
refactor(ai): remove redundant runtime type checks on schema-decoded values - #57605
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Looks good. I checked each removed guard against the schema-decoded type it relied on. In packages/ai on the PR head, bun run typecheck passed and bun test gave 1826 passed, 0 failed. The new optional-chained reads still return undefined safely if a metadata entry isn't the expected shape. ProviderShared.matchToolChoice already gives the same Mistral "requires a tool name" error, so removing the guard in mistral-chat.ts loses nothing. The only difference is ordering: if the provider options are also invalid, the options error now comes first.
Public API is unchanged: the changes are internal to packages/ai.
5 tasks
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.
Problem
Several protocol lowers and response handlers in
@opencode/aire-validated values that were already narrowed by Effect Schema or internal accessors (LLMResponse.toolCalls,ProviderMetadata,MediaPart.metadata,MediaPart.filename,MistralThinkingUnit.text, andToolChoicevalidation beforeProviderShared.matchToolChoice).Change
Drop the redundant runtime guards and rely on the existing Schema-decoded types across
llm.tsand the protocol adapters:Out of scope
unknownvalues insideRecord<string, unknown>metadata payloads still retain property-leveltypeoforProviderShared.isRecordchecks where their values are not schema-decoded.