Fall back to default namespace for workflow creation in REST

What does this MR do and why?

Adds equivalent fallback logic to the REST api as the existing graphQL mutation for creating workflows.

When a projectId is not provided, try fall back to provided namespaceId. If neither are provided, try fall back to users configured duo_default_namespace_with_fallback.

This will allow Duo CLI to be run outside of gitlab project folders, and make use of the existing duo_default_namespace_with_fallback setting.

References

#583694

Screenshots or screen recordings

Before After

How to set up and validate locally

Create workflows by providing a projectId, or a namespaceId, or neither (fall back to default namespace)

Click to expand
╭─ ~gl  on 583694-use-default-namespace-when-creating-workflows-via-rest-api *3 ▓▒░────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────░▒▓ ✔  took 12s  at 12:23:05 PM ─╮
╰─ curl -X POST "http://gdk.test:3000/api/v4/ai/duo_workflows/workflows" \                                                                                                                                                                                              ─╯
  -H "PRIVATE-TOKEN: REDACTED" \
  -H "Content-Type: application/json" \
  -d '{
    "project_id": "1000000",
    "goal": "Test workflow creation",
    "workflow_definition": "chat"
  }'
{"id":165,"project_id":1000000,"namespace_id":null,"agent_privileges":[1,2,3,4,5,6],"agent_privileges_names":["read_write_files","read_only_gitlab","read_write_gitlab","run_commands","use_git","run_mcp_tools"],"pre_approved_agent_privileges":[1,2],"pre_approved_agent_privileges_names":["read_write_files","read_only_gitlab"],"workflow_definition":"chat","status":"created","allow_agent_to_request_user":true,"image":null,"environment":null,"ai_catalog_item_version_id":null,"workload":{"id":null,"message":null},"mcp_enabled":false,"gitlab_url":"http://gdk.test:3000"}%                                                                                                                                                                                                                                       
╭─ ~gl  on 583694-use-default-namespace-when-creating-workflows-via-rest-api *3 ▓▒░───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────░▒▓ ✔  at 12:29:09 PM ─╮
╰─ curl -X POST "http://gdk.test:3000/api/v4/ai/duo_workflows/workflows" \                                                                                                                                                                                              ─╯
  -H "PRIVATE-TOKEN: REDACTED" \
  -H "Content-Type: application/json" \
  -d '{
    "namespace_id": "1000000",
    "goal": "Test workflow creation",
    "workflow_definition": "chat"
  }'
{"id":166,"project_id":null,"namespace_id":1000000,"agent_privileges":[1,2,3,4,5,6],"agent_privileges_names":["read_write_files","read_only_gitlab","read_write_gitlab","run_commands","use_git","run_mcp_tools"],"pre_approved_agent_privileges":[1,2],"pre_approved_agent_privileges_names":["read_write_files","read_only_gitlab"],"workflow_definition":"chat","status":"created","allow_agent_to_request_user":true,"image":null,"environment":null,"ai_catalog_item_version_id":null,"workload":{"id":null,"message":null},"mcp_enabled":false,"gitlab_url":"http://gdk.test:3000"}%                                                                                                                                                                                                                                       
╭─ ~gl  on 583694-use-default-namespace-when-creating-workflows-via-rest-api *3 ▓▒░───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────░▒▓ ✔  at 12:29:23 PM ─╮
╰─ curl -X POST "http://gdk.test:3000/api/v4/ai/duo_workflows/workflows" \                                                                                                                                                                                              ─╯
  -H "PRIVATE-TOKEN: REDACTED" \
  -H "Content-Type: application/json" \
  -d '{
    "goal": "Test workflow creation with default namespace fallback",
    "workflow_definition": "chat"
  }'
{"id":167,"project_id":null,"namespace_id":1000000,"agent_privileges":[1,2,3,4,5,6],"agent_privileges_names":["read_write_files","read_only_gitlab","read_write_gitlab","run_commands","use_git","run_mcp_tools"],"pre_approved_agent_privileges":[1,2],"pre_approved_agent_privileges_names":["read_write_files","read_only_gitlab"],"workflow_definition":"chat","status":"created","allow_agent_to_request_user":true,"image":null,"environment":null,"ai_catalog_item_version_id":null,"workload":{"id":null,"message":null},"mcp_enabled":false,"gitlab_url":"http://gdk.test:3000"}%           

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 #583694

Merge request reports

Loading