From ebc9cb148ddf8557bef85674298ed6bfe79aa3b0 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Wed, 25 Mar 2026 10:24:20 -0300 Subject: [PATCH] chore: run modernize (#188) --- providers/google/google.go | 2 +- providers/openai/openai_test.go | 48 ++++++++++---------- providers/openai/provider_options.go | 4 +- providers/openai/responses_language_model.go | 4 +- providers/openai/responses_params_test.go | 22 ++++----- providers/openrouter/provider_options.go | 4 +- providers/vercel/provider_options.go | 4 +- providertests/anthropic_test.go | 6 +-- providertests/azure_responses_test.go | 2 +- providertests/common_test.go | 12 ++--- providertests/google_test.go | 6 +-- providertests/image_upload_test.go | 4 +- providertests/object_test.go | 8 ++-- providertests/openai_responses_test.go | 2 +- providertests/openai_web_search_test.go | 4 +- providertests/provider_registry_test.go | 12 ++--- schema/schema.go | 4 +- util.go | 4 +- 18 files changed, 79 insertions(+), 73 deletions(-) diff --git a/providers/google/google.go b/providers/google/google.go index 5d3f0515224860e8760f712373de327bca8bb1bc..700341f7c99b95ad74ea52a1970c571d33dc7071 100644 --- a/providers/google/google.go +++ b/providers/google/google.go @@ -255,7 +255,7 @@ func (g languageModel) prepareParams(call fantasy.Call) (*genai.GenerateContentC Type: fantasy.CallWarningTypeOther, Message: "The 'thinking_budget' option can not be under 128 and will be set to 128 by default", }) - providerOptions.ThinkingConfig.ThinkingBudget = fantasy.Opt(int64(128)) + providerOptions.ThinkingConfig.ThinkingBudget = new(int64(128)) } if providerOptions.ThinkingConfig.ThinkingLevel != nil && diff --git a/providers/openai/openai_test.go b/providers/openai/openai_test.go index 07bcdc98109537b02446aeefca950579e2e3ede8..254ae635412917fe6c5f9b46db4ec0d9eb6ccabd 100644 --- a/providers/openai/openai_test.go +++ b/providers/openai/openai_test.go @@ -947,7 +947,7 @@ func TestDoGenerate(t *testing.T) { result, err := model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - LogProbs: fantasy.Opt(true), + LogProbs: new(true), }), }) @@ -1068,8 +1068,8 @@ func TestDoGenerate(t *testing.T) { LogitBias: map[string]int64{ "50256": -100, }, - ParallelToolCalls: fantasy.Opt(false), - User: fantasy.Opt("test-user-id"), + ParallelToolCalls: new(false), + User: new("test-user-id"), }), }) @@ -1109,7 +1109,7 @@ func TestDoGenerate(t *testing.T) { Prompt: testPrompt, ProviderOptions: NewProviderOptions( &ProviderOptions{ - ReasoningEffort: ReasoningEffortOption(ReasoningEffortLow), + ReasoningEffort: new(ReasoningEffortLow), }, ), }) @@ -1149,7 +1149,7 @@ func TestDoGenerate(t *testing.T) { _, err = model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - TextVerbosity: fantasy.Opt("low"), + TextVerbosity: new("low"), }), }) @@ -1610,7 +1610,7 @@ func TestDoGenerate(t *testing.T) { _, err = model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - MaxCompletionTokens: fantasy.Opt(int64(255)), + MaxCompletionTokens: new(int64(255)), }), }) @@ -1694,7 +1694,7 @@ func TestDoGenerate(t *testing.T) { _, err = model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - Store: fantasy.Opt(true), + Store: new(true), }), }) @@ -1776,7 +1776,7 @@ func TestDoGenerate(t *testing.T) { _, err = model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - PromptCacheKey: fantasy.Opt("test-cache-key-123"), + PromptCacheKey: new("test-cache-key-123"), }), }) @@ -1815,7 +1815,7 @@ func TestDoGenerate(t *testing.T) { _, err = model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - SafetyIdentifier: fantasy.Opt("test-safety-identifier-123"), + SafetyIdentifier: new("test-safety-identifier-123"), }), }) @@ -1887,7 +1887,7 @@ func TestDoGenerate(t *testing.T) { _, err = model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - ServiceTier: fantasy.Opt("flex"), + ServiceTier: new("flex"), }), }) @@ -1924,7 +1924,7 @@ func TestDoGenerate(t *testing.T) { result, err := model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - ServiceTier: fantasy.Opt("flex"), + ServiceTier: new("flex"), }), }) @@ -1958,7 +1958,7 @@ func TestDoGenerate(t *testing.T) { _, err = model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - ServiceTier: fantasy.Opt("priority"), + ServiceTier: new("priority"), }), }) @@ -1995,7 +1995,7 @@ func TestDoGenerate(t *testing.T) { result, err := model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - ServiceTier: fantasy.Opt("priority"), + ServiceTier: new("priority"), }), }) @@ -2752,7 +2752,7 @@ func TestDoStream(t *testing.T) { _, err = model.Stream(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - Store: fantasy.Opt(true), + Store: new(true), }), }) @@ -2842,7 +2842,7 @@ func TestDoStream(t *testing.T) { _, err = model.Stream(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - ServiceTier: fantasy.Opt("flex"), + ServiceTier: new("flex"), }), }) @@ -2885,7 +2885,7 @@ func TestDoStream(t *testing.T) { _, err = model.Stream(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: NewProviderOptions(&ProviderOptions{ - ServiceTier: fantasy.Opt("priority"), + ServiceTier: new("priority"), }), }) @@ -3686,7 +3686,7 @@ func TestResponsesGenerate_StoreOption(t *testing.T) { Prompt: testPrompt, ProviderOptions: fantasy.ProviderOptions{ Name: &ResponsesProviderOptions{ - Store: fantasy.Opt(true), + Store: new(true), }, }, }) @@ -3710,8 +3710,8 @@ func TestResponsesGenerate_PreviousResponseIDOption(t *testing.T) { Prompt: testPrompt, ProviderOptions: fantasy.ProviderOptions{ Name: &ResponsesProviderOptions{ - PreviousResponseID: fantasy.Opt("resp_prev_123"), - Store: fantasy.Opt(true), + PreviousResponseID: new("resp_prev_123"), + Store: new(true), }, }, }) @@ -3758,7 +3758,7 @@ func TestResponsesGenerate_StateChainingAcrossTurns(t *testing.T) { first, err := model.Generate(context.Background(), fantasy.Call{ Prompt: testPrompt, ProviderOptions: fantasy.ProviderOptions{ - Name: &ResponsesProviderOptions{Store: fantasy.Opt(true)}, + Name: &ResponsesProviderOptions{Store: new(true)}, }, }) require.NoError(t, err) @@ -3799,7 +3799,7 @@ func TestResponsesGenerate_StateChainingAcrossTurns(t *testing.T) { }, ProviderOptions: fantasy.ProviderOptions{ Name: &ResponsesProviderOptions{ - Store: fantasy.Opt(true), + Store: new(true), PreviousResponseID: &meta.ResponseID, }, }, @@ -4164,7 +4164,7 @@ func TestResponsesStream_StoreOption(t *testing.T) { Prompt: testPrompt, ProviderOptions: fantasy.ProviderOptions{ Name: &ResponsesProviderOptions{ - Store: fantasy.Opt(true), + Store: new(true), }, }, }) @@ -4197,8 +4197,8 @@ func TestResponsesStream_PreviousResponseIDOption(t *testing.T) { Prompt: testPrompt, ProviderOptions: fantasy.ProviderOptions{ Name: &ResponsesProviderOptions{ - PreviousResponseID: fantasy.Opt("resp_prev_456"), - Store: fantasy.Opt(true), + PreviousResponseID: new("resp_prev_456"), + Store: new(true), }, }, }) diff --git a/providers/openai/provider_options.go b/providers/openai/provider_options.go index 50abadbb2b042af2a16c229f6f9f1ae69885b4be..141fd2dc477e71830f37b628880d79bc2fb692a5 100644 --- a/providers/openai/provider_options.go +++ b/providers/openai/provider_options.go @@ -146,8 +146,10 @@ func (o *ProviderFileOptions) UnmarshalJSON(data []byte) error { } // ReasoningEffortOption creates a pointer to a ReasoningEffort value. +// +//go:fix inline func ReasoningEffortOption(e ReasoningEffort) *ReasoningEffort { - return &e + return new(e) } // NewProviderOptions creates new provider options for OpenAI. diff --git a/providers/openai/responses_language_model.go b/providers/openai/responses_language_model.go index eb027109e8cfab898d5a7e605415ed5596bbda01..bd61a68ba0f2d2608c1c6512ada5ade2dae92c14 100644 --- a/providers/openai/responses_language_model.go +++ b/providers/openai/responses_language_model.go @@ -1090,8 +1090,8 @@ func (o responsesLanguageModel) Stream(ctx context.Context, call fantasy.Call) ( case "response.output_text.annotation.added": added := event.AsResponseOutputTextAnnotationAdded() // The Annotation field is typed as `any` in the SDK; - // it deserializes as map[string]interface{} from JSON. - annotationMap, ok := added.Annotation.(map[string]interface{}) + // it deserializes as map[string]any from JSON. + annotationMap, ok := added.Annotation.(map[string]any) if !ok { break } diff --git a/providers/openai/responses_params_test.go b/providers/openai/responses_params_test.go index 2687f1db57108e47f58c240500b90bf1bc5e8d8b..f533c0baeef115e212c293c8876698279696d530 100644 --- a/providers/openai/responses_params_test.go +++ b/providers/openai/responses_params_test.go @@ -21,12 +21,12 @@ func TestPrepareParams_Store(t *testing.T) { }{ { name: "store true", - opts: &ResponsesProviderOptions{Store: fantasy.Opt(true)}, + opts: &ResponsesProviderOptions{Store: new(true)}, wantStore: true, }, { name: "store false", - opts: &ResponsesProviderOptions{Store: fantasy.Opt(false)}, + opts: &ResponsesProviderOptions{Store: new(false)}, wantStore: false, }, { @@ -42,7 +42,6 @@ func TestPrepareParams_Store(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() @@ -65,8 +64,8 @@ func TestPrepareParams_PreviousResponseID(t *testing.T) { t.Parallel() params, warnings, err := lm.prepareParams(testCall(prompt, &ResponsesProviderOptions{ - PreviousResponseID: fantasy.Opt("resp_abc123"), - Store: fantasy.Opt(true), + PreviousResponseID: new("resp_abc123"), + Store: new(true), })) require.NoError(t, err) require.Empty(t, warnings) @@ -87,7 +86,7 @@ func TestPrepareParams_PreviousResponseID(t *testing.T) { t.Parallel() params, warnings, err := lm.prepareParams(testCall(prompt, &ResponsesProviderOptions{ - PreviousResponseID: fantasy.Opt(""), + PreviousResponseID: new(""), })) require.NoError(t, err) require.Empty(t, warnings) @@ -100,8 +99,8 @@ func TestPrepareParams_PreviousResponseID_Validation(t *testing.T) { lm := testResponsesLM() opts := &ResponsesProviderOptions{ - PreviousResponseID: fantasy.Opt("resp_abc123"), - Store: fantasy.Opt(true), + PreviousResponseID: new("resp_abc123"), + Store: new(true), } t.Run("rejects with assistant messages", func(t *testing.T) { @@ -152,7 +151,7 @@ func TestPrepareParams_PreviousResponseID_Validation(t *testing.T) { _, _, err := lm.prepareParams(testCall(fantasy.Prompt{ testTextMessage(fantasy.MessageRoleUser, "hello"), }, &ResponsesProviderOptions{ - PreviousResponseID: fantasy.Opt("resp_abc123"), + PreviousResponseID: new("resp_abc123"), })) require.EqualError(t, err, previousResponseIDStoreError) }) @@ -163,8 +162,8 @@ func TestPrepareParams_PreviousResponseID_Validation(t *testing.T) { _, _, err := lm.prepareParams(testCall(fantasy.Prompt{ testTextMessage(fantasy.MessageRoleUser, "hello"), }, &ResponsesProviderOptions{ - PreviousResponseID: fantasy.Opt("resp_abc123"), - Store: fantasy.Opt(false), + PreviousResponseID: new("resp_abc123"), + Store: new(false), })) require.EqualError(t, err, previousResponseIDStoreError) }) @@ -223,7 +222,6 @@ func TestValidatePreviousResponseIDPrompt(t *testing.T) { } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() diff --git a/providers/openrouter/provider_options.go b/providers/openrouter/provider_options.go index ed2d8f5edd714150b49301527b3dcb1e55184422..742e911031aa741e270e687d10a8b0e43c975903 100644 --- a/providers/openrouter/provider_options.go +++ b/providers/openrouter/provider_options.go @@ -189,8 +189,10 @@ type ReasoningData struct { } // ReasoningEffortOption creates a pointer to a ReasoningEffort value for OpenRouter. +// +//go:fix inline func ReasoningEffortOption(e ReasoningEffort) *ReasoningEffort { - return &e + return new(e) } // NewProviderOptions creates new provider options for OpenRouter. diff --git a/providers/vercel/provider_options.go b/providers/vercel/provider_options.go index 046ba940d981117234d72a10747708f699bd4c70..163921b97678926e65c3fd0e69eb6efcca27df85 100644 --- a/providers/vercel/provider_options.go +++ b/providers/vercel/provider_options.go @@ -170,8 +170,10 @@ type ReasoningData struct { } // ReasoningEffortOption creates a pointer to a ReasoningEffort value. +// +//go:fix inline func ReasoningEffortOption(e ReasoningEffort) *ReasoningEffort { - return &e + return new(e) } // NewProviderOptions creates new provider options for Vercel. diff --git a/providertests/anthropic_test.go b/providertests/anthropic_test.go index 940ec477d7c6bcc0ef487914a7ac6c89bdd3302c..f0ee726673e4c414d4569b261995570496a2c957 100644 --- a/providertests/anthropic_test.go +++ b/providertests/anthropic_test.go @@ -177,7 +177,7 @@ func TestAnthropicWebSearch(t *testing.T) { result, err := agent.Generate(t.Context(), fantasy.AgentCall{ Prompt: "What is the current population of Tokyo? Cite your source.", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), }) require.NoError(t, err) @@ -222,7 +222,7 @@ func TestAnthropicWebSearch(t *testing.T) { // Turn 1: initial query triggers web search. result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{ Prompt: "What is the current population of Tokyo? Cite your source.", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), }) require.NoError(t, err) @@ -266,7 +266,7 @@ func TestAnthropicWebSearch(t *testing.T) { result2, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{ Messages: history, Prompt: "How does that compare to Osaka?", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), }) require.NoError(t, err) diff --git a/providertests/azure_responses_test.go b/providertests/azure_responses_test.go index 8b3945ba4c5e702ff55ebc5608645150e23d61db..b7c89084b9d0611f2d8e4edca2c07e39f0d3e8d1 100644 --- a/providertests/azure_responses_test.go +++ b/providertests/azure_responses_test.go @@ -47,7 +47,7 @@ func TestAzureResponsesWithSummaryThinking(t *testing.T) { openai.IncludeReasoningEncryptedContent, }, ReasoningEffort: openai.ReasoningEffortOption(openai.ReasoningEffortHigh), - ReasoningSummary: fantasy.Opt("auto"), + ReasoningSummary: new("auto"), }, } var pairs []builderPair diff --git a/providertests/common_test.go b/providertests/common_test.go index 6878761ff49416c714240ad79ebe1efef737936b..f13c93a9250aebfd37e7614d8071b579693f2014 100644 --- a/providertests/common_test.go +++ b/providertests/common_test.go @@ -70,7 +70,7 @@ func testSimple(t *testing.T, pair builderPair) { result, err := agent.Generate(t.Context(), fantasy.AgentCall{ Prompt: "Say hi in Portuguese", ProviderOptions: pair.providerOptions, - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), PrepareStep: pair.prepareStep, }) require.NoError(t, err, "failed to generate") @@ -90,7 +90,7 @@ func testSimple(t *testing.T, pair builderPair) { result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{ Prompt: "Say hi in Portuguese", ProviderOptions: pair.providerOptions, - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), PrepareStep: pair.prepareStep, }) require.NoError(t, err, "failed to generate") @@ -149,7 +149,7 @@ func testTool(t *testing.T, pair builderPair) { result, err := agent.Generate(t.Context(), fantasy.AgentCall{ Prompt: "What's the weather in Florence,Italy?", ProviderOptions: pair.providerOptions, - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), PrepareStep: pair.prepareStep, }) require.NoError(t, err, "failed to generate") @@ -170,7 +170,7 @@ func testTool(t *testing.T, pair builderPair) { result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{ Prompt: "What's the weather in Florence,Italy?", ProviderOptions: pair.providerOptions, - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), PrepareStep: pair.prepareStep, }) require.NoError(t, err, "failed to generate") @@ -255,7 +255,7 @@ func testMultiTool(t *testing.T, pair builderPair) { result, err := agent.Generate(t.Context(), fantasy.AgentCall{ Prompt: "Add and multiply the number 2 and 3", ProviderOptions: pair.providerOptions, - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), PrepareStep: pair.prepareStep, }) require.NoError(t, err, "failed to generate") @@ -277,7 +277,7 @@ func testMultiTool(t *testing.T, pair builderPair) { result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{ Prompt: "Add and multiply the number 2 and 3", ProviderOptions: pair.providerOptions, - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), PrepareStep: pair.prepareStep, }) require.NoError(t, err, "failed to generate") diff --git a/providertests/google_test.go b/providertests/google_test.go index d49e13a2afb440825a97aa8bd80ecf8df831a2d5..cbd9fec8b8aa637eb07db0f7b4bdc3215994b741 100644 --- a/providertests/google_test.go +++ b/providertests/google_test.go @@ -41,8 +41,8 @@ func TestGoogleThinking(t *testing.T) { gemini2Opts := fantasy.ProviderOptions{ google.Name: &google.ProviderOptions{ ThinkingConfig: &google.ThinkingConfig{ - ThinkingBudget: fantasy.Opt(int64(100)), - IncludeThoughts: fantasy.Opt(true), + ThinkingBudget: new(int64(100)), + IncludeThoughts: new(true), }, }, } @@ -50,7 +50,7 @@ func TestGoogleThinking(t *testing.T) { google.Name: &google.ProviderOptions{ ThinkingConfig: &google.ThinkingConfig{ ThinkingLevel: fantasy.Opt(google.ThinkingLevelHigh), - IncludeThoughts: fantasy.Opt(true), + IncludeThoughts: new(true), }, }, } diff --git a/providertests/image_upload_test.go b/providertests/image_upload_test.go index cf7fad7cace821f9f8a2e8a5d9badbf1062160df..5ec3ea4f328f625cbe3f572459bb9e741149b887 100644 --- a/providertests/image_upload_test.go +++ b/providertests/image_upload_test.go @@ -90,7 +90,7 @@ func TestImageUploadAgent(t *testing.T) { Prompt: "Describe the image briefly in English.", Files: []fantasy.FilePart{file}, ProviderOptions: pair.providerOptions, - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), }) require.NoError(t, err) got := result.Response.Content.Text() @@ -136,7 +136,7 @@ func TestImageUploadAgentStreaming(t *testing.T) { Prompt: "Describe the image briefly in English.", Files: []fantasy.FilePart{file}, ProviderOptions: pair.providerOptions, - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), }) require.NoError(t, err) got := result.Response.Content.Text() diff --git a/providertests/object_test.go b/providertests/object_test.go index f5e9b791e227a629e4e3c8dbb9977f7124af4a3d..5a4c17e59f6b6c7f7f2850376ae0b6cd63385b0f 100644 --- a/providertests/object_test.go +++ b/providertests/object_test.go @@ -104,7 +104,7 @@ func testSimpleObject(t *testing.T, pair builderPair) { Schema: schema, SchemaName: "Person", SchemaDescription: "A person with name, age, and city", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), ProviderOptions: pair.providerOptions, }) require.NoError(t, err, "failed to generate object") @@ -127,7 +127,7 @@ func testSimpleObject(t *testing.T, pair builderPair) { Schema: schema, SchemaName: "Person", SchemaDescription: "A person with name, age, and city", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), ProviderOptions: pair.providerOptions, }) require.NoError(t, err, "failed to create object stream") @@ -277,7 +277,7 @@ func testComplexObject(t *testing.T, pair builderPair) { Schema: schema, SchemaName: "Book", SchemaDescription: "A book with title, author, genres, and publication year", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), ProviderOptions: pair.providerOptions, }) require.NoError(t, err, "failed to generate object") @@ -300,7 +300,7 @@ func testComplexObject(t *testing.T, pair builderPair) { Schema: schema, SchemaName: "Book", SchemaDescription: "A book with title, author, genres, and publication year", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), ProviderOptions: pair.providerOptions, }) require.NoError(t, err, "failed to create object stream") diff --git a/providertests/openai_responses_test.go b/providertests/openai_responses_test.go index db85f73d4963c893dc7e884773d07dd5ceb85454..38ad7ea7a90a30fe3521e26fdec9b5e758b2c138 100644 --- a/providertests/openai_responses_test.go +++ b/providertests/openai_responses_test.go @@ -40,7 +40,7 @@ func TestOpenAIResponsesWithSummaryThinking(t *testing.T) { openai.IncludeReasoningEncryptedContent, }, ReasoningEffort: openai.ReasoningEffortOption(openai.ReasoningEffortHigh), - ReasoningSummary: fantasy.Opt("auto"), + ReasoningSummary: new("auto"), }, } var pairs []builderPair diff --git a/providertests/openai_web_search_test.go b/providertests/openai_web_search_test.go index 1fe4418fa9d1400c30fcf2de510c77b4b88a1865..8e8eb50e20b159238e4a6491ce59262cc00e34d0 100644 --- a/providertests/openai_web_search_test.go +++ b/providertests/openai_web_search_test.go @@ -47,7 +47,7 @@ func TestOpenAIWebSearch(t *testing.T) { result, err := agent.Generate(t.Context(), fantasy.AgentCall{ Prompt: "What is the current population of Tokyo? Cite your source.", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), }) require.NoError(t, err) @@ -96,7 +96,7 @@ func TestOpenAIWebSearch(t *testing.T) { // Turn 1: initial query triggers web search. result, err := agent.Stream(t.Context(), fantasy.AgentStreamCall{ Prompt: "What is the current population of Tokyo? Cite your source.", - MaxOutputTokens: fantasy.Opt(int64(4000)), + MaxOutputTokens: new(int64(4000)), }) require.NoError(t, err) diff --git a/providertests/provider_registry_test.go b/providertests/provider_registry_test.go index 9340e50b6b3a1e9056a5fa229d0d578c26abd237..c0f3f848ea11825b8e439aa849a022706a778b9a 100644 --- a/providertests/provider_registry_test.go +++ b/providertests/provider_registry_test.go @@ -20,7 +20,7 @@ func TestProviderRegistry_Serialization_OpenAIOptions(t *testing.T) { fantasy.TextPart{Text: "hi"}, }, ProviderOptions: fantasy.ProviderOptions{ - openai.Name: &openai.ProviderOptions{User: fantasy.Opt("tester")}, + openai.Name: &openai.ProviderOptions{User: new("tester")}, }, } @@ -60,8 +60,8 @@ func TestProviderRegistry_Serialization_OpenAIResponses(t *testing.T) { }, ProviderOptions: fantasy.ProviderOptions{ openai.Name: &openai.ResponsesProviderOptions{ - PromptCacheKey: fantasy.Opt("cache-key-1"), - ParallelToolCalls: fantasy.Opt(true), + PromptCacheKey: new("cache-key-1"), + ParallelToolCalls: new(true), }, }, } @@ -215,7 +215,7 @@ func TestProviderRegistry_Serialization_OpenRouterOptions(t *testing.T) { ProviderOptions: fantasy.ProviderOptions{ openrouter.Name: &openrouter.ProviderOptions{ IncludeUsage: &includeUsage, - User: fantasy.Opt("test-user"), + User: new("test-user"), }, }, } @@ -245,7 +245,7 @@ func TestProviderRegistry_Serialization_OpenAICompatOptions(t *testing.T) { }, ProviderOptions: fantasy.ProviderOptions{ openaicompat.Name: &openaicompat.ProviderOptions{ - User: fantasy.Opt("test-user"), + User: new("test-user"), ReasoningEffort: &effort, }, }, @@ -276,7 +276,7 @@ func TestProviderRegistry_MultiProvider(t *testing.T) { fantasy.TextPart{Text: "test"}, }, ProviderOptions: fantasy.ProviderOptions{ - openai.Name: &openai.ProviderOptions{User: fantasy.Opt("user1")}, + openai.Name: &openai.ProviderOptions{User: new("user1")}, anthropic.Name: &anthropic.ProviderOptions{ SendReasoning: &sendReasoning, }, diff --git a/schema/schema.go b/schema/schema.go index c1cc46d2b480f07c86f98aebb95061755f819d42..92ccd7b3473cfdce53d38c8a4d020959924384b7 100644 --- a/schema/schema.go +++ b/schema/schema.go @@ -122,8 +122,8 @@ func generateSchemaRecursive(t reflect.Type, visited map[reflect.Type]bool) Sche Type: "object", Properties: make(map[string]*Schema), } - for i := range t.NumField() { - field := t.Field(i) + for field := range t.Fields() { + field := field if !field.IsExported() { continue diff --git a/util.go b/util.go index 7bb9f48ff874d31968b12e7f100383978736ef8f..74f02ede324ab6560b2c242da6abacc164c48399 100644 --- a/util.go +++ b/util.go @@ -3,8 +3,10 @@ package fantasy import "github.com/go-viper/mapstructure/v2" // Opt creates a pointer to the given value. +// +//go:fix inline func Opt[T any](v T) *T { - return &v + return new(v) } // ParseOptions parses the given options map into the provided struct.