From eba887432a42abbda24a123ec83685b6d3819223 Mon Sep 17 00:00:00 2001 From: Leonardo Cuco Date: Mon, 30 Nov 2026 14:39:24 +0100 Subject: [PATCH 1/4] feat(agentstudio): expose conversation impact analytics --- pkg/cmd/conversations/list/list.go | 24 +++++++--- pkg/cmd/conversations/list/list_test.go | 61 +++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/conversations/list/list.go b/pkg/cmd/conversations/list/list.go index b6cfebc9..6eea718d 100644 --- a/pkg/cmd/conversations/list/list.go +++ b/pkg/cmd/conversations/list/list.go @@ -18,13 +18,15 @@ type ListOptions struct { AgentStudioClient func() (*agentStudio.APIClient, error) PrintFlags *cmdutil.PrintFlags - AgentID string - Page int32 - Limit int32 - StartDate string - EndDate string - IncludeFeedback bool - SetFeedback bool + AgentID string + Page int32 + Limit int32 + StartDate string + EndDate string + IncludeFeedback bool + SetFeedback bool + IncludeImpactAnalytics bool + SetImpactAnalytics bool } // NewListCmd returns the `conversations list` command. @@ -52,10 +54,14 @@ func NewListCmd(f *cmdutil.Factory) *cobra.Command { # Filter by date range $ algolia agentstudio conversations list 11111111-1111-4111-8111-111111111111 --start-date 2026-01-01 --end-date 2026-01-31 + + # Include impact analytics + $ algolia agentstudio conversations list 11111111-1111-4111-8111-111111111111 --include-impact-analytics `), RunE: func(cmd *cobra.Command, args []string) error { opts.AgentID = args[0] opts.SetFeedback = cmd.Flags().Changed("include-feedback") + opts.SetImpactAnalytics = cmd.Flags().Changed("include-impact-analytics") return runListCmd(opts) }, } @@ -66,6 +72,7 @@ func NewListCmd(f *cmdutil.Factory) *cobra.Command { cmd.Flags().StringVar(&opts.EndDate, "end-date", "", "Created before this date (YYYY-MM-DD)") cmd.Flags(). BoolVar(&opts.IncludeFeedback, "include-feedback", false, "Include feedback per conversation") + cmd.Flags().BoolVar(&opts.IncludeImpactAnalytics, "include-impact-analytics", false, "Include impact analytics per conversation") opts.PrintFlags.AddFlags(cmd) return cmd @@ -98,6 +105,9 @@ func runListCmd(opts *ListOptions) error { if opts.SetFeedback { req = req.WithIncludeFeedback(opts.IncludeFeedback) } + if opts.SetImpactAnalytics { + req = req.WithIncludeImpactAnalytics(opts.IncludeImpactAnalytics) + } opts.IO.StartProgressIndicatorWithLabel("Fetching conversations") diff --git a/pkg/cmd/conversations/list/list_test.go b/pkg/cmd/conversations/list/list_test.go index 593a46df..58dcf74d 100644 --- a/pkg/cmd/conversations/list/list_test.go +++ b/pkg/cmd/conversations/list/list_test.go @@ -103,3 +103,64 @@ func TestListConversations_MissingArg(t *testing.T) { require.Error(t, err) assert.Contains(t, err.Error(), "agentstudio conversations list requires a argument") } + +func TestListConversations_ImpactAnalytics(t *testing.T) { + const response = `{ + "data": [{ + "id": "33333333-3333-4333-8333-333333333333", + "agentId": "11111111-1111-4111-8111-111111111111", + "createdAt": "2026-01-01T00:00:00Z", + "updatedAt": "2026-01-01T00:00:00Z", + "impactAnalytics": {"hasView": true, "hasClick": false, "hasConversion": false, "hasAlgoliaSearch": true} + }], + "pagination": {"page": 1, "limit": 10, "totalCount": 1, "totalPages": 1}, + "analyticsDegraded": false +}` + tests := []struct { + name string + flags string + want string + present bool + degraded bool + }{ + {name: "omitted"}, + {name: "enabled with filters", flags: " --include-impact-analytics --page 2 --limit 20 --start-date 2026-01-01 --include-feedback", want: "true", present: true}, + {name: "explicit false", flags: " --include-impact-analytics=false", want: "false", present: true}, + {name: "degraded analytics", flags: " --include-impact-analytics", want: "true", present: true, degraded: true}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + body := response + if tt.degraded { + body = strings.Replace(body, `{"hasView": true, "hasClick": false, "hasConversion": false, "hasAlgoliaSearch": true}`, `null`, 1) + body = strings.Replace(body, `"analyticsDegraded": false`, `"analyticsDegraded": true`, 1) + } + r := &httpmock.Registry{} + r.Register(httpmock.REST("GET", listPath), httpmock.StringResponse(body)) + f, out := test.NewFactory(false, r, nil, "") + _, err := test.Execute(list.NewListCmd(f), agentID+tt.flags, out) + require.NoError(t, err) + r.Verify(t) + require.Len(t, r.Requests, 1) + q := r.Requests[0].URL.Query() + values, present := q["includeImpactAnalytics"] + assert.Equal(t, tt.present, present) + if tt.present { + assert.Equal(t, []string{tt.want}, values) + } + if tt.name == "enabled with filters" { + assert.Equal(t, "2", q.Get("page")) + assert.Equal(t, "20", q.Get("limit")) + assert.Equal(t, "2026-01-01", q.Get("startDate")) + assert.Equal(t, "true", q.Get("includeFeedback")) + } + wantBody := body + if tt.degraded { + // The current SDK drops null impactAnalytics while preserving analyticsDegraded. + wantBody = strings.Replace(wantBody, `, + "impactAnalytics": null`, "", 1) + } + assert.JSONEq(t, wantBody, strings.TrimSpace(out.String())) + }) + } +} From df182cebca441f06f5a202a36d824864334c3aaf Mon Sep 17 00:00:00 2001 From: Leonardo Cuco Date: Mon, 30 Nov 2026 15:56:00 +0100 Subject: [PATCH 2/4] test(agentstudio): cover conversation analytics API errors --- pkg/cmd/conversations/list/list_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/cmd/conversations/list/list_test.go b/pkg/cmd/conversations/list/list_test.go index 58dcf74d..1eb25f68 100644 --- a/pkg/cmd/conversations/list/list_test.go +++ b/pkg/cmd/conversations/list/list_test.go @@ -164,3 +164,20 @@ func TestListConversations_ImpactAnalytics(t *testing.T) { }) } } + +func TestListConversations_ImpactAnalyticsAPIError(t *testing.T) { + r := &httpmock.Registry{} + r.Register(httpmock.REST("GET", listPath), httpmock.ErrorResponseWithBody(map[string]string{ + "message": "Impact analytics unavailable", + })) + f, out := test.NewFactory(false, r, nil, "") + + _, err := test.Execute(list.NewListCmd(f), agentID+" --include-impact-analytics", out) + + require.Error(t, err) + assert.Contains(t, err.Error(), "Impact analytics unavailable") + assert.Empty(t, strings.TrimSpace(out.String())) + r.Verify(t) + require.Len(t, r.Requests, 1) + assert.Equal(t, "true", r.Requests[0].URL.Query().Get("includeImpactAnalytics")) +} From 33a8d1b8c474d51570caa53a1cfe9bfc524f528a Mon Sep 17 00:00:00 2001 From: Leonardo Cuco Date: Mon, 30 Nov 2026 16:01:32 +0100 Subject: [PATCH 3/4] feat(agentstudio): add conversation list filters --- pkg/cmd/conversations/list/list.go | 42 +++++++++++++++++++ pkg/cmd/conversations/list/list_test.go | 56 +++++++++++++++++++++++++ 2 files changed, 98 insertions(+) diff --git a/pkg/cmd/conversations/list/list.go b/pkg/cmd/conversations/list/list.go index 6eea718d..0da617f4 100644 --- a/pkg/cmd/conversations/list/list.go +++ b/pkg/cmd/conversations/list/list.go @@ -1,6 +1,8 @@ package list import ( + "fmt" + "github.com/MakeNowJust/heredoc" agentStudio "github.com/algolia/algoliasearch-client-go/v4/algolia/agent-studio" "github.com/spf13/cobra" @@ -27,6 +29,14 @@ type ListOptions struct { SetFeedback bool IncludeImpactAnalytics bool SetImpactAnalytics bool + FeedbackVote int32 + SetFeedbackVote bool + Clicked bool + SetClicked bool + Converted bool + SetConverted bool + HasAlgoliaSearch bool + SetHasAlgoliaSearch bool } // NewListCmd returns the `conversations list` command. @@ -57,11 +67,27 @@ func NewListCmd(f *cmdutil.Factory) *cobra.Command { # Include impact analytics $ algolia agentstudio conversations list 11111111-1111-4111-8111-111111111111 --include-impact-analytics + + # Filter conversations by feedback and impact + $ algolia agentstudio conversations list 11111111-1111-4111-8111-111111111111 --include-feedback --feedback-vote 1 --include-impact-analytics --clicked `), RunE: func(cmd *cobra.Command, args []string) error { opts.AgentID = args[0] opts.SetFeedback = cmd.Flags().Changed("include-feedback") opts.SetImpactAnalytics = cmd.Flags().Changed("include-impact-analytics") + opts.SetFeedbackVote = cmd.Flags().Changed("feedback-vote") + opts.SetClicked = cmd.Flags().Changed("clicked") + opts.SetConverted = cmd.Flags().Changed("converted") + opts.SetHasAlgoliaSearch = cmd.Flags().Changed("has-algolia-search") + if opts.SetFeedbackVote && (opts.FeedbackVote < 0 || opts.FeedbackVote > 1) { + return fmt.Errorf("--feedback-vote must be 0 or 1") + } + if opts.SetFeedbackVote && !opts.IncludeFeedback { + return fmt.Errorf("--feedback-vote requires --include-feedback") + } + if (opts.SetClicked || opts.SetConverted || opts.SetHasAlgoliaSearch) && !opts.IncludeImpactAnalytics { + return fmt.Errorf("impact filters require --include-impact-analytics") + } return runListCmd(opts) }, } @@ -73,6 +99,10 @@ func NewListCmd(f *cmdutil.Factory) *cobra.Command { cmd.Flags(). BoolVar(&opts.IncludeFeedback, "include-feedback", false, "Include feedback per conversation") cmd.Flags().BoolVar(&opts.IncludeImpactAnalytics, "include-impact-analytics", false, "Include impact analytics per conversation") + cmd.Flags().Int32Var(&opts.FeedbackVote, "feedback-vote", 0, "Filter by feedback vote (0 or 1; requires --include-feedback)") + cmd.Flags().BoolVar(&opts.Clicked, "clicked", false, "Filter by item clicks (requires --include-impact-analytics)") + cmd.Flags().BoolVar(&opts.Converted, "converted", false, "Filter by conversions (requires --include-impact-analytics)") + cmd.Flags().BoolVar(&opts.HasAlgoliaSearch, "has-algolia-search", false, "Filter by search tool use (requires --include-impact-analytics)") opts.PrintFlags.AddFlags(cmd) return cmd @@ -108,6 +138,18 @@ func runListCmd(opts *ListOptions) error { if opts.SetImpactAnalytics { req = req.WithIncludeImpactAnalytics(opts.IncludeImpactAnalytics) } + if opts.SetFeedbackVote { + req = req.WithFeedbackVote(opts.FeedbackVote) + } + if opts.SetClicked { + req = req.WithClicked(opts.Clicked) + } + if opts.SetConverted { + req = req.WithConverted(opts.Converted) + } + if opts.SetHasAlgoliaSearch { + req = req.WithHasAlgoliaSearch(opts.HasAlgoliaSearch) + } opts.IO.StartProgressIndicatorWithLabel("Fetching conversations") diff --git a/pkg/cmd/conversations/list/list_test.go b/pkg/cmd/conversations/list/list_test.go index 1eb25f68..86b381ee 100644 --- a/pkg/cmd/conversations/list/list_test.go +++ b/pkg/cmd/conversations/list/list_test.go @@ -181,3 +181,59 @@ func TestListConversations_ImpactAnalyticsAPIError(t *testing.T) { require.Len(t, r.Requests, 1) assert.Equal(t, "true", r.Requests[0].URL.Query().Get("includeImpactAnalytics")) } + +func TestListConversations_Filters(t *testing.T) { + tests := []struct { + name string + flags string + want map[string]string + absent []string + }{ + {name: "omitted", absent: []string{"feedbackVote", "clicked", "converted", "hasAlgoliaSearch"}}, + {name: "positive votes and impact", flags: " --include-feedback --feedback-vote 1 --include-impact-analytics --clicked --converted --has-algolia-search --page 2 --limit 20", want: map[string]string{"includeFeedback": "true", "feedbackVote": "1", "includeImpactAnalytics": "true", "clicked": "true", "converted": "true", "hasAlgoliaSearch": "true", "page": "2", "limit": "20"}}, + {name: "zero vote and false impact", flags: " --include-feedback --feedback-vote 0 --include-impact-analytics --clicked=false --converted=false --has-algolia-search=false", want: map[string]string{"feedbackVote": "0", "clicked": "false", "converted": "false", "hasAlgoliaSearch": "false"}}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + r := &httpmock.Registry{} + r.Register(httpmock.REST("GET", listPath), httpmock.StringResponse(emptyListBody)) + f, out := test.NewFactory(false, r, nil, "") + _, err := test.Execute(list.NewListCmd(f), agentID+tt.flags, out) + require.NoError(t, err) + r.Verify(t) + require.Len(t, r.Requests, 1) + q := r.Requests[0].URL.Query() + for key, value := range tt.want { + assert.Equal(t, []string{value}, q[key], "query %s", key) + } + for _, key := range tt.absent { + assert.False(t, q.Has(key), "unexpected query %s", key) + } + assert.JSONEq(t, emptyListBody, strings.TrimSpace(out.String())) + }) + } +} + +func TestListConversations_InvalidFilters(t *testing.T) { + tests := []struct{ flags, message string }{ + {" --feedback-vote 1", "feedback-vote requires --include-feedback"}, + {" --include-feedback=false --feedback-vote 0", "feedback-vote requires --include-feedback"}, + {" --include-feedback --feedback-vote -1", "feedback-vote must be 0 or 1"}, + {" --include-feedback --feedback-vote 2", "feedback-vote must be 0 or 1"}, + {" --include-feedback --feedback-vote invalid", "invalid"}, + {" --clicked", "require --include-impact-analytics"}, + {" --converted=false", "require --include-impact-analytics"}, + {" --include-impact-analytics=false --has-algolia-search=false", "require --include-impact-analytics"}, + {" --include-impact-analytics --clicked=invalid", "invalid"}, + } + for _, tt := range tests { + t.Run(tt.flags, func(t *testing.T) { + r := &httpmock.Registry{} + f, out := test.NewFactory(false, r, nil, "") + _, err := test.Execute(list.NewListCmd(f), agentID+tt.flags, out) + require.Error(t, err) + assert.Contains(t, err.Error(), tt.message) + assert.Empty(t, r.Requests) + }) + } +} From d0683167f13b7119598099801f25f001b37ba18d Mon Sep 17 00:00:00 2001 From: Leonardo Cuco Date: Mon, 30 Nov 2026 16:46:43 +0100 Subject: [PATCH 4/4] fix(agentstudio): return flag errors from conversation list filter validation Use cmdutil.FlagErrorf for the feedback vote and impact filter validations so users get the standard flag-error guidance, as AGENTS.md requires. Co-Authored-By: Claude Sonnet 5.5 --- pkg/cmd/conversations/list/list.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/conversations/list/list.go b/pkg/cmd/conversations/list/list.go index 0da617f4..5dea10dc 100644 --- a/pkg/cmd/conversations/list/list.go +++ b/pkg/cmd/conversations/list/list.go @@ -1,8 +1,6 @@ package list import ( - "fmt" - "github.com/MakeNowJust/heredoc" agentStudio "github.com/algolia/algoliasearch-client-go/v4/algolia/agent-studio" "github.com/spf13/cobra" @@ -80,13 +78,13 @@ func NewListCmd(f *cmdutil.Factory) *cobra.Command { opts.SetConverted = cmd.Flags().Changed("converted") opts.SetHasAlgoliaSearch = cmd.Flags().Changed("has-algolia-search") if opts.SetFeedbackVote && (opts.FeedbackVote < 0 || opts.FeedbackVote > 1) { - return fmt.Errorf("--feedback-vote must be 0 or 1") + return cmdutil.FlagErrorf("--feedback-vote must be 0 or 1") } if opts.SetFeedbackVote && !opts.IncludeFeedback { - return fmt.Errorf("--feedback-vote requires --include-feedback") + return cmdutil.FlagErrorf("--feedback-vote requires --include-feedback") } if (opts.SetClicked || opts.SetConverted || opts.SetHasAlgoliaSearch) && !opts.IncludeImpactAnalytics { - return fmt.Errorf("impact filters require --include-impact-analytics") + return cmdutil.FlagErrorf("impact filters require --include-impact-analytics") } return runListCmd(opts) },