Create triggers for project item consumers
What does this MR do and why?
Create triggers for project item consumers
Get the service account from the parent item consumer, and create a flow trigger with the event types passed by the user.
References
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
- Enable the
ai_catalog_flowsandglobal_ai_catalogflags - Create a flow:
mutation {
aiCatalogFlowCreate(
input: {name: "Test flow", description: "Trigger test flow", projectId: "gid://gitlab/Project/1000000", public: true, definition: "version: v1\nenvironment: ambient\ncomponents:\n - name: main_agent\n type: AgentComponent\n prompt_id: test_prompt\nrouters: []\nflow:\n entry_point: main_agent"}
) {
errors
item {
id
}
}
}
- Attempt to create an item consumer for the flow with a trigger:
mutation {
aiCatalogItemConsumerCreate(
input: {itemId: "gid://gitlab/Ai::Catalog::Item/<REPLACE WITH ID ABOVE>", target: {projectId: "gid://gitlab/Project/1000000"}, triggerTypes: ["mention"]}
) {
itemConsumer {
id
}
errors
}
}
You should see the error "Item must be added to the top-level group before adding to the project"
- Try creating it along with triggers for the group:
mutation {
aiCatalogItemConsumerCreate(
input: {itemId: "gid://gitlab/Ai::Catalog::Item/<REPLACE WITH ID ABOVE>", target: {groupId: "gid://gitlab/Group/1000000"}, triggerTypes: ["mention"]}
) {
itemConsumer {
id
}
errors
}
}
-
You'll now see the error "Flow triggers can only be set for projects"
-
Create the item consumer for the group without triggers (NOTE: You'll need to check out the branch
578532-be-support-adding-a-flow-to-a-groupfor this step, as that creates the service account, then switch back):
mutation {
aiCatalogItemConsumerCreate(
input: {itemId: "gid://gitlab/Ai::Catalog::Item/<REPLACE WITH ID ABOVE>", target: {groupId: "gid://gitlab/Group/1000000"}}
) {
itemConsumer {
id
}
errors
}
}
- Now finally add it to the project, with triggers:
mutation {
aiCatalogItemConsumerCreate(
input: {itemId: "gid://gitlab/Ai::Catalog::Item/<REPLACE WITH ID ABOVE>", target: {projectId: "gid://gitlab/Project/1000000"}, triggerTypes: ["mention"], parentItemConsumerId: "gid://gitlab/Ai::Catalog::ItemConsumer/<PARENT ITEM CONSUMER CREATED ABOVE>"}
) {
itemConsumer {
id
}
errors
}
}
Find the item and confirm it has the right flow trigger:
i = Ai::Catalog::ItemConsumer.last
i.flow_trigger
i.event_types # [0] which is "mention"
i.flow_trigger.user # Service account `@ai-trigger-test-flow-gitlab-duo`
i.project # Project you added the flow to
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #578349 (closed)