Skip to content
Snippets Groups Projects
Commit 265a8951 authored by Tetiana Chupryna's avatar Tetiana Chupryna :sunflower:
Browse files

Merge branch...

Merge branch 'ms/ai-agents/adds-agent-version-id-to-completion-response-subscription-be' into 'master' 

Adds agentVersionId to aiCompletionResponse

See merge request !146464



Merged-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Approved-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Co-authored-by: default avatarMarc Saleiko <marc.saleiko@komadesign.de>
parents fc3a7566 8aec4c0a
No related branches found
No related tags found
1 merge request!146464Adds agentVersionId to aiCompletionResponse
Pipeline #1199868206 passed
......@@ -11,6 +11,10 @@ def self.ai_completion_response(message)
ai_action: message.ai_action.to_s
}
if message.agent_version_id.present?
subscription_arguments[:agent_version_id] = Ai::AgentVersion.find_by_id(message.agent_version_id)&.to_gid
end
if message.client_subscription_id && !message.user?
subscription_arguments[:client_subscription_id] = message.client_subscription_id
end
......
......@@ -13,6 +13,10 @@ class AiCompletionResponse < BaseSubscription
required: false,
description: 'ID of the user.'
argument :agent_version_id, ::Types::GlobalIDType[::Ai::AgentVersion],
required: false,
description: 'ID of the AI agent version.'
argument :client_subscription_id, ::GraphQL::Types::String,
required: false,
description: 'Client generated ID that be subscribed to, to receive a response for the mutation.'
......
......@@ -116,5 +116,24 @@
end
end
end
context 'with agent_version_id' do
let(:agent_version) { create(:ai_agent_version) }
let(:message) { build(:ai_message, user: user, resource: user, agent_version_id: agent_version.id) }
it 'triggers ai_completion_response with agent_version_id as global id' do
expect(GitlabSchema.subscriptions).to receive(:trigger).with(
:ai_completion_response,
{
user_id: message.user.to_gid,
agent_version_id: agent_version.to_gid,
ai_action: message.ai_action.to_s
},
message.to_h
).and_call_original
subject
end
end
end
end
......@@ -9,6 +9,8 @@
let_it_be(:guest) { create(:user) }
let_it_be(:project) { create(:project) }
let_it_be(:resource) { create(:work_item, :task, project: project) }
let_it_be(:agent) { create(:ai_agent, project: project) }
let_it_be(:agent_version) { create(:ai_agent_version, agent: agent) }
let_it_be(:external_issue) { create(:issue) }
let_it_be(:external_issue_url) do
......@@ -21,7 +23,15 @@
let(:request_id) { 'uuid' }
let(:content) { "Some AI response #{external_issue_url}+" }
let(:extras) { { sources: [{ source_url: 'foo', source_some_metadata: 'bar' }] }.deep_stringify_keys }
let(:params) { { user_id: current_user&.to_gid, resource_id: resource.to_gid, client_subscription_id: 'id' } }
let(:params) do
{
user_id: current_user&.to_gid,
resource_id: resource.to_gid,
agent_version_id: agent_version.to_gid,
client_subscription_id: 'id'
}
end
let(:content_html) do
"<p data-sourcepos=\"1:1-1:#{content.size}\" dir=\"auto\">Some AI response " \
"<a href=\"#{external_issue_url}+\">#{external_issue_url}+</a></p>"
......@@ -144,6 +154,12 @@
it_behaves_like 'on success'
end
context 'when agent_version_id is null' do
let(:params) { { user_id: current_user.to_gid, agent_version_id: nil } }
it_behaves_like 'on success'
end
context 'when ai_action is null' do
let(:params) { { user_id: current_user.to_gid, ai_action: nil } }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment