fix(client): handle JsonValue input in toParam conversion#351
Draft
packyg wants to merge 1 commit into
Draft
Conversation
Stainless commit e3b5adb generated toParam() code that calls it._additionalProperties() inside _input().map{}, but _input() returns JsonValue (JsonField<Nothing>) so `it` is Nothing. Manual patch until Stainless codegen handles this case.
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
Stainless commit e3b5adb ("fix(client): bad toParam conversion", part of #350) generated
toParam()code that does:.input( _input().map { ToolUseBlockParam.Input.builder() .additionalProperties(it._additionalProperties()) .build() } )This fails to compile because
_input()returnsJsonValue(which isJsonField<Nothing>), so inside.map { it -> ... }the lambda parameteritinfers asNothingandit._additionalProperties()is unresolved.Fix
Revert these call sites to
.input(_input()). This compiles becauseJsonField<out T>is covariant and the param builder acceptsJsonField<Input>, soJsonValue(=JsonField<Nothing>) is a valid argument. The free-form JSON input passes through unchanged, which is the desired behavior fortoParam()round-tripping.Files changed
anthropic-java-core/src/main/kotlin/com/anthropic/models/messages/ToolUseBlock.ktanthropic-java-core/src/main/kotlin/com/anthropic/models/messages/ServerToolUseBlock.ktanthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaToolUseBlock.ktanthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaServerToolUseBlock.ktanthropic-java-core/src/main/kotlin/com/anthropic/models/beta/messages/BetaMcpToolUseBlock.ktNotes
This is a manual patch over Stainless-generated code; it will be overwritten the next time Stainless regenerates these files unless the codegen is fixed upstream to special-case
JsonValue-typed source fields intoParam()conversions.Verified locally with
./gradlew :anthropic-java-core:compileKotlin(BUILD SUCCESSFUL).Context: #350