File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,10 +106,10 @@ func runListCmd(opts *ListOptions) error {
106106
107107 req := client .NewApiListAgentConversationsRequest (opts .AgentID )
108108 if opts .Page > 0 {
109- req = req .WithPage (int32 (opts .Page ))
109+ req = req .WithPage (shared . Int32 (opts .Page ))
110110 }
111111 if opts .PerPage > 0 {
112- req = req .WithLimit (int32 (opts .PerPage ))
112+ req = req .WithLimit (shared . Int32 (opts .PerPage ))
113113 }
114114 if opts .StartDate != "" {
115115 req = req .WithStartDate (opts .StartDate )
@@ -121,7 +121,7 @@ func runListCmd(opts *ListOptions) error {
121121 req = req .WithIncludeFeedback (true )
122122 }
123123 if opts .feedbackVoteSet {
124- req = req .WithFeedbackVote (int32 (opts .FeedbackVote ))
124+ req = req .WithFeedbackVote (shared . Int32 (opts .FeedbackVote ))
125125 }
126126
127127 opts .IO .StartProgressIndicatorWithLabel ("Fetching conversations" )
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ func runCreateCmd(opts *CreateOptions) error {
8686 body := & agentStudio.FeedbackCreationRequest {
8787 MessageId : opts .MessageID ,
8888 AgentId : opts .AgentID ,
89- Vote : agentStudio .VoteEnum (opts .Vote ),
89+ Vote : agentStudio .VoteEnum (shared . Int32 ( opts .Vote ) ),
9090 Tags : opts .Tags ,
9191 }
9292 if opts .Notes != "" {
Original file line number Diff line number Diff line change @@ -57,10 +57,10 @@ func runListCmd(opts *ListOptions) error {
5757 }
5858 req := client .NewApiListSecretKeysRequest ()
5959 if opts .Page > 0 {
60- req = req .WithPage (int32 (opts .Page ))
60+ req = req .WithPage (shared . Int32 (opts .Page ))
6161 }
6262 if opts .Limit > 0 {
63- req = req .WithLimit (int32 (opts .Limit ))
63+ req = req .WithLimit (shared . Int32 (opts .Limit ))
6464 }
6565 opts .IO .StartProgressIndicatorWithLabel ("Fetching secret keys" )
6666 res , err := client .ListSecretKeys (req , agentStudio .WithContext (shared .OrBackground (opts .Ctx )))
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import (
1010 "github.com/dustin/go-humanize"
1111 "github.com/spf13/cobra"
1212
13+ "github.com/algolia/cli/pkg/cmd/agents/shared"
1314 "github.com/algolia/cli/pkg/cmdutil"
1415 "github.com/algolia/cli/pkg/config"
1516 "github.com/algolia/cli/pkg/iostreams"
@@ -95,10 +96,10 @@ func runListCmd(opts *ListOptions) error {
9596
9697 req := client .NewApiListAgentsRequest ()
9798 if opts .Page > 0 {
98- req = req .WithPage (int32 (opts .Page ))
99+ req = req .WithPage (shared . Int32 (opts .Page ))
99100 }
100101 if opts .PerPage > 0 {
101- req = req .WithLimit (int32 (opts .PerPage ))
102+ req = req .WithLimit (shared . Int32 (opts .PerPage ))
102103 }
103104 if opts .ProviderID != "" {
104105 req = req .WithProviderId (opts .ProviderID )
Original file line number Diff line number Diff line change @@ -80,10 +80,10 @@ func runListCmd(opts *ListOptions) error {
8080
8181 req := client .NewApiListProvidersRequest ()
8282 if opts .Page > 0 {
83- req = req .WithPage (int32 (opts .Page ))
83+ req = req .WithPage (shared . Int32 (opts .Page ))
8484 }
8585 if opts .PerPage > 0 {
86- req = req .WithLimit (int32 (opts .PerPage ))
86+ req = req .WithLimit (shared . Int32 (opts .PerPage ))
8787 }
8888
8989 opts .IO .StartProgressIndicatorWithLabel ("Fetching providers" )
Original file line number Diff line number Diff line change 1+ package shared
2+
3+ import "math"
4+
5+ // Int32 safely converts an int to an int32, clamping to the int32 range so the
6+ // conversion can never overflow. The Agent Studio SDK takes pagination and
7+ // filter values as int32 while our flags are parsed as int; this keeps gosec
8+ // (G115) satisfied without scattering //nolint directives across call sites.
9+ func Int32 (v int ) int32 {
10+ if v > math .MaxInt32 {
11+ return math .MaxInt32
12+ }
13+ if v < math .MinInt32 {
14+ return math .MinInt32
15+ }
16+ return int32 (v )
17+ }
You can’t perform that action at this time.
0 commit comments