fix(go): use *Part for GenerateActionResume.Respond and Restart#5226
Open
fix(go): use *Part for GenerateActionResume.Respond and Restart#5226
Conversation
The Respond and Restart fields used the unexported `toolResponsePart` and `toolRequestPart` types, which are intended only for JSON marshaling. The rest of the codebase uses `*Part` with the appropriate `Kind` set, and the unexported types made the fields impossible for external callers to construct. Validation now lives in `handleResumeOption` so all entry points (including direct `GenerateWithRequest` calls) are covered.
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the GenerateActionResume struct to use the generic Part type for its Respond and Restart fields, replacing the specialized tool part types. This change simplifies the Generate function by removing manual conversion logic and moves the validation of these parts to handleResumeOption. Review feedback identifies potential nil pointer dereferences in the new validation loops within handleResumeOption and suggests adding nil checks before calling IsToolResponse() and IsToolRequest().
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.
The
RespondandRestartfields onGenerateActionResumeused the unexportedtoolResponsePartandtoolRequestParttypes, which are intended only for JSON marshaling. The rest of the codebase uses*Partwith the appropriateKindset, and the unexported types made these fields impossible for external callers to construct.This change:
schemas.configso codegen produces[]*Partfor both fields, and regeneratesgen.go.Generate()that copied*Partinto the private types —genOpts.RespondParts/RestartPartsnow flow through directly.handleResumeOption, the single consumer, so all entry points (including directGenerateWithRequestcalls with hand-builtGenerateActionOptions) are covered.The private
toolRequestPart/toolResponseParttypes remain ingen.goand are still used byPart.MarshalJSONfor the wire format, so JSON output is unchanged.Test plan
go build ./...cleango vet ./...cleango test ./...passes