Add categorized suggested questions to Duo Chat context presets

Backend for the Duo Chat empty state redesign (design): aiChatContextPresets gains a questionCategories experiment field that groups suggested questions by category, with the current page's context first.

  • New AiChatQuestionCategory GraphQL type and questionCategories field (experiment, 19.4), resolved alongside the existing flat questions.
  • Gitlab::Duo::Chat::DefaultQuestions#categories returns a contextual category first, then six static ones: get_started, development, work_items, merge_requests, pipelines, security.
  • key names the type of page a category describes (issue, merge_request, blob, wiki, and so on), and contextual marks the single category about the current resource, so clients pick an icon without parsing the title.
  • Titles are always present and translated on the backend, so no client redefines them. Resources with a reference are titled with it, the rest after the page.
  • allowed_to_use? and the route lookup are memoized, so one instance serving both execute and categories checks entitlement and resolves the route once per request.
  • No feature flag: additive experiment field; the flat questions path is unchanged.

Rendered by the empty state MR later in this stack:

categories

How to test

This MR is backend only. The rendered UI lands in a later MR in this stack. Verify the response through GraphiQL at /-/graphql-explorer.

query {
  aiChatContextPresets(url: "http://gdk.test:3000/<group>/<project>/-/blob/master/README.md") {
    questions
    questionCategories {
      key
      title
      contextual
      questions
    }
  }
}

Edit the arguments to exercise each scenario:

  1. No arguments: six static categories, no contextual category.
  2. url pointing at a project blob page, for example http://gdk.test:3000/<group>/<project>/-/blob/master/README.md: a blob contextual category first, followed by the static ones.
  3. url pointing at a project or group wiki page: a wiki contextual category first.
  4. resourceId set to an issue or merge request global ID, for example gid://gitlab/Issue/1: a contextual category first with key set to issue or merge_request and title set to the reference (#1, !1).
  5. url pointing at a project overview page (no page-specific list matches): static categories only, no contextual category.

Every category now has a non-null title. At most one category has contextual: true.

Stacked on !248168 (merged).

Edited by Nick Leonard

Merge request reports

Loading
Loading