From dbaf33ea2547f3658fdb70bab1422bfa535ffd6f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eva=20Kadlecov=C3=A1?= <ekadlecova@gitlab.com>
Date: Thu, 27 Feb 2025 10:07:49 +0000
Subject: [PATCH] Support duo_chat_2 conversation type

Changelog: added
EE: true
---
 doc/api/graphql/reference/_index.md                   |  1 +
 ee/app/models/ai/conversation/thread.rb               |  5 +++--
 ee/lib/gitlab/llm/chat_storage/postgresql.rb          |  2 +-
 .../resolvers/ai/chat_messages_resolver_spec.rb       |  2 +-
 .../threads/conversation_type_enum_spec.rb            | 11 +++++++++++
 ee/spec/lib/gitlab/llm/chat_message_spec.rb           |  2 +-
 .../lib/gitlab/llm/chat_storage/postgresql_spec.rb    |  2 +-
 ee/spec/models/ai/conversation/thread_spec.rb         |  5 +++--
 8 files changed, 22 insertions(+), 8 deletions(-)
 create mode 100644 ee/spec/graphql/types/ai/conversations/threads/conversation_type_enum_spec.rb

diff --git a/doc/api/graphql/reference/_index.md b/doc/api/graphql/reference/_index.md
index 17d445da84ef2..703a21a6e406d 100644
--- a/doc/api/graphql/reference/_index.md
+++ b/doc/api/graphql/reference/_index.md
@@ -40358,6 +40358,7 @@ Conversation type of the thread.
 | Value | Description |
 | ----- | ----------- |
 | <a id="aiconversationsthreadsconversationtypeduo_chat"></a>`DUO_CHAT` | duo_chat thread. |
+| <a id="aiconversationsthreadsconversationtypeduo_chat_legacy"></a>`DUO_CHAT_LEGACY` | duo_chat_legacy thread. |
 | <a id="aiconversationsthreadsconversationtypeduo_code_review"></a>`DUO_CODE_REVIEW` | duo_code_review thread. |
 | <a id="aiconversationsthreadsconversationtypeduo_quick_chat"></a>`DUO_QUICK_CHAT` | duo_quick_chat thread. |
 
diff --git a/ee/app/models/ai/conversation/thread.rb b/ee/app/models/ai/conversation/thread.rb
index 644e9deec15d4..32a941709977d 100644
--- a/ee/app/models/ai/conversation/thread.rb
+++ b/ee/app/models/ai/conversation/thread.rb
@@ -18,9 +18,10 @@ class Thread < ApplicationRecord
       scope :ordered, -> { order(last_updated_at: :desc) }
 
       enum conversation_type: {
-        duo_chat: 1,
+        duo_chat_legacy: 1,
         duo_code_review: 2,
-        duo_quick_chat: 3
+        duo_quick_chat: 3,
+        duo_chat: 4
       }
 
       before_create :populate_organization
diff --git a/ee/lib/gitlab/llm/chat_storage/postgresql.rb b/ee/lib/gitlab/llm/chat_storage/postgresql.rb
index b44e819406806..5f1f2d479aa06 100644
--- a/ee/lib/gitlab/llm/chat_storage/postgresql.rb
+++ b/ee/lib/gitlab/llm/chat_storage/postgresql.rb
@@ -4,7 +4,7 @@ module Gitlab
   module Llm
     class ChatStorage
       class Postgresql < Base
-        DEFAULT_CONVERSATION_TYPE = :duo_chat
+        DEFAULT_CONVERSATION_TYPE = :duo_chat_legacy
         MAX_MESSAGES = 50
 
         def add(message)
diff --git a/ee/spec/graphql/resolvers/ai/chat_messages_resolver_spec.rb b/ee/spec/graphql/resolvers/ai/chat_messages_resolver_spec.rb
index 7f7353cb77d19..62bde044ec499 100644
--- a/ee/spec/graphql/resolvers/ai/chat_messages_resolver_spec.rb
+++ b/ee/spec/graphql/resolvers/ai/chat_messages_resolver_spec.rb
@@ -19,7 +19,7 @@
     end
 
     context 'when there is a message' do
-      let!(:thread) { create(:ai_conversation_thread, user: user) }
+      let!(:thread) { create(:ai_conversation_thread, user: user, conversation_type: :duo_chat_legacy) }
       let!(:message) do
         create(:ai_conversation_message, created_at: Time.new(2020, 2, 2, 17, 30, 45, '+00:00'),
           thread: thread, message_xid: 'message_xid')
diff --git a/ee/spec/graphql/types/ai/conversations/threads/conversation_type_enum_spec.rb b/ee/spec/graphql/types/ai/conversations/threads/conversation_type_enum_spec.rb
new file mode 100644
index 0000000000000..7453354f9f207
--- /dev/null
+++ b/ee/spec/graphql/types/ai/conversations/threads/conversation_type_enum_spec.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GitlabSchema.types['AiConversationsThreadsConversationType'], feature_category: :duo_chat do
+  let(:expected_values) { %w[DUO_CHAT_LEGACY DUO_CODE_REVIEW DUO_QUICK_CHAT DUO_CHAT] }
+
+  subject { described_class.values.keys }
+
+  it { is_expected.to match_array(expected_values) }
+end
diff --git a/ee/spec/lib/gitlab/llm/chat_message_spec.rb b/ee/spec/lib/gitlab/llm/chat_message_spec.rb
index 19ef767f6ecd7..a6c91c5330e4e 100644
--- a/ee/spec/lib/gitlab/llm/chat_message_spec.rb
+++ b/ee/spec/lib/gitlab/llm/chat_message_spec.rb
@@ -65,7 +65,7 @@
     end
 
     context 'when a thread exists for the user' do
-      let!(:thread) { create(:ai_conversation_thread, user: user) }
+      let!(:thread) { create(:ai_conversation_thread, user: user, conversation_type: :duo_chat_legacy) }
 
       it 'fetches the thread and assign it to the message' do
         expect(subject.thread).to be_nil
diff --git a/ee/spec/lib/gitlab/llm/chat_storage/postgresql_spec.rb b/ee/spec/lib/gitlab/llm/chat_storage/postgresql_spec.rb
index c6981c905c9f9..7b10f3d2d01b4 100644
--- a/ee/spec/lib/gitlab/llm/chat_storage/postgresql_spec.rb
+++ b/ee/spec/lib/gitlab/llm/chat_storage/postgresql_spec.rb
@@ -156,7 +156,7 @@
       end
 
       context 'when a thread exists for the user' do
-        let!(:existing_thread) { create(:ai_conversation_thread, user: user) }
+        let!(:existing_thread) { create(:ai_conversation_thread, user: user, conversation_type: :duo_chat_legacy) }
 
         it 'returns the latest thread' do
           expect(current_thread).to eq(existing_thread)
diff --git a/ee/spec/models/ai/conversation/thread_spec.rb b/ee/spec/models/ai/conversation/thread_spec.rb
index 552bd2667c7aa..fbb958a92fe41 100644
--- a/ee/spec/models/ai/conversation/thread_spec.rb
+++ b/ee/spec/models/ai/conversation/thread_spec.rb
@@ -17,9 +17,10 @@
   describe 'enums' do
     it 'defines enum' do
       is_expected.to define_enum_for(:conversation_type).with_values(
-        duo_chat: 1,
+        duo_chat_legacy: 1,
         duo_code_review: 2,
-        duo_quick_chat: 3
+        duo_quick_chat: 3,
+        duo_chat: 4
       )
     end
   end
-- 
GitLab