Fix broken implementation AssistantModify implementation #685
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.
This resolves #684
both reverts the changes in #669
and modifies the code to actually match the intention of the #669
Currently the SDK does not match the API and requires all of the existing tools to be provided in every request to avoid an API error or deleting all of the tools. Please see the linked issue for repro steps and use cases including step by step cURL requests to demonstrate the existing functionality of the API
As specified in the inline documentation
A custom marshaller was required here to handle the various use cases of the API request with respect to GO-isms and to avoid breaking changes:
If Tools is nil (or undefined), the field is omitted from the JSON. > this reflects the functionality of the API and reverts the breaking change introduced in #669
If Tools is an empty slice, it's included in the JSON as an empty array ([]). > this matches the intention of #669 by allowing the ability to remove all Tools, something that was broken previously and the linked PR attempted to resolve
If Tools is populated, it's included in the JSON with the elements > and thusly replaces the Tools. This functionality existed already and simply is maintained in this PR
This is important to note because in Golang, omitempty will omit both a nil (uninitialized) slice as well as an empty slice. To provide support to allow both a non-existant slice, and an empty slice, and a populated slice and never a nil slice (see the linked issue to see the API error if it receives nil). A custom Marshaller and aliast was required
Additionally I wrapped the tests block into Run blocks to be able to isolate tests and remove variable shadowing. I also added explicit unit tests for this functionality, and the run blocks were necessary to be able to properly isolate them for testing and development.