Add Optional Item Consumer Creation to Catalog Item Creation Endpoint
Overview
This issue focuses on updating the existing catalog item creation endpoint to optionally handle item consumer creation atomically. This enhancement is needed to support the refactoring of the AI Catalog Item UI where catalog item creation functionality is being moved from the Explore area to the project area. But also in the status quo it improves the UX, so that users do not have to manually add the agent to the same project anymore.
Current State
- Users browse catalog items in the Explore area (
/explore/ai_catalog
) - Users click "Add to project" which creates an
ItemConsumer
viacreateAiCatalogItemConsumer
mutation
Proposed Solution
Update the existing catalog item creation endpoint with an optional field that controls whether it should be automatically enabled for the project it was created in.
Implementation Details
- Add an optional boolean parameter to the existing endpoint to control automatic item consumer creation
- In the first iteration, the frontend will pass
true
for this flag when 'private' is selected - We won't show a UI field for users to select this option initially, as we currently plan to create the item consumer every time
- This can be reconsidered in future UX iterations
UI Considerations
- Later enhancement: In the UI we will disable the 'add to project' button for private agents and show a tooltip explaining why
-
For now: Leave the 'add to project' button enabled because:
- Users can technically remove the item consumer in the project area and might want to add it again
- We don't know on the explore page whether the item consumer exists or not
Acceptance Criteria
-
Optional boolean parameter added to existing catalog item creation endpoint -
Endpoint ensures atomic creation of both catalog item and item consumer when enabled -
Frontend passes true
for private agents in first iteration -
Frontend gracefully reports sensible error to user in the case where item
is created byitem consumer
could not be created - the 3rd scenario in !207672 (comment 2818558990) which will be whenitem
is present anderrors
is not an empty array -
Documentation updated to reflect the endpoint changes
QA backend changes
GraphQL mutation
mutation createAgent {
aiCatalogAgentCreate(
input: {
projectId: "gid://gitlab/Project/1000000",
name: "My name",
description: "My description",
release: true,
public: false,
addToProjectWhenCreated: true,
systemPrompt: "My system prompt",
userPrompt: "My user prompt"
}
) {
errors
item {
id
name
description
latestVersion{
id
released
}
}
}
}
1. Response when an agent is created and successfully enabled in the project
{
"data": {
"aiCatalogAgentCreate": {
"errors": [],
"item": {
"id": "gid://gitlab/Ai::Catalog::Item/193",
"name": "My name",
"description": "My description",
"latestVersion": {
"id": "gid://gitlab/Ai::Catalog::ItemVersion/217",
"released": true
}
}
}
},
"correlationId": "91daf121-7862-4a73-9200-a0df948d8faa"
}
2. Response when an agent is created but fails to be enabled in the project
Apply the patch below to simulate an error when enabling an item for a project.
diff --git a/ee/app/services/ai/catalog/item_consumers/create_service.rb b/ee/app/services/ai/catalog/item_consumers/create_service.rb
index d3260a8eb347887..b9f45a7e7b0c5ee 100644
--- a/ee/app/services/ai/catalog/item_consumers/create_service.rb
+++ b/ee/app/services/ai/catalog/item_consumers/create_service.rb
@@ -15,6 +15,8 @@ def execute
params[:enabled] = true
item_consumer = ::Ai::Catalog::ItemConsumer.new(params)
+ return error_creating(item_consumer)
+
if item_consumer.save
track_item_consumer_event(item_consumer, 'create_ai_catalog_item_consumer')
ServiceResponse.success(payload: { item_consumer: item_consumer })
{
"data": {
"aiCatalogAgentCreate": {
"errors": [
"Failed to create item consumer"
],
"item": {
"id": "gid://gitlab/Ai::Catalog::Item/191",
"name": "My name",
"description": "My description",
"latestVersion": {
"id": "gid://gitlab/Ai::Catalog::ItemVersion/215",
"released": true
}
}
}
},
"correlationId": "11c75330-2845-44b0-8867-551d9ce3d95f"
}
Edited by Jaydip Pansuriya