Skip to content

Conversation

@loreto
Copy link
Contributor

@loreto loreto commented Jul 7, 2025

Summary

Add a new functional option to pass an entire options struct.

How was it tested?

Added unit tests.

Community Contribution License

All community contributions in this pull request are licensed to the project maintainers under the terms of the Apache 2 License.

By creating this pull request I represent that I have the right to license the contributions to the project maintainers under the Apache 2 License as stated in the Community Contribution License.

@loreto loreto requested review from Copilot and mikeland73 July 7, 2025 18:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Add a new functional option to accept a pre-built api.CallOptions struct and exercise it via unit tests.

  • Introduce WithCallOptions in options.go to set the entire CallOptions on a GenerateOptions instance.
  • Extend TestCallOptionBuilders in options_test.go with a case for WithCallOptions.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
aisdk/ai/options.go Adds the WithCallOptions builder function.
aisdk/ai/options_test.go Adds a unit test case covering WithCallOptions.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Functional Options Overwrite Instead of Merge

The WithCallOptions function completely overwrites the CallOptions struct. This causes order-dependent behavior, erasing previously set options from other functional options (e.g., WithMaxOutputTokens, WithProviderMetadata). It also wipes out the default ProviderMetadata initialization from buildGenerateConfig, potentially leading to nil pointer issues. This overwriting is inconsistent with the expected merging nature of functional options.

aisdk/ai/options.go#L131-L136

// This allows passing a pre-configured CallOptions instance.
func WithCallOptions(callOptions api.CallOptions) GenerateOption {
return func(o *GenerateOptions) {
o.CallOptions = callOptions
}
}

Fix in CursorFix in Web


BugBot free trial expires on July 22, 2025
You have used $0.00 of your $50.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@loreto loreto merged commit 3f47986 into main Jul 7, 2025
14 checks passed
@loreto loreto deleted the daniel/withoptions branch July 7, 2025 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants