Support thread id in AiAction GraphQL mutation

Note: This is an important item for the groupduo chat 17.9 release. We would greatly appreciate if you could prioritize the review or, if needed, delegate it to someone with available capacity.

What does this MR do and why?

This MR adds thread_id and conversation_type to the AiAction mutation and the ChatMessage resolver to allow frontend to interact with threads. No user facing changes are introduced in this MR and it's backward compatible with the older clients.

Related to Accept/expose conversation thread ID to AI acti... (#425174 - closed)

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Example mutation query

Example mutation query - send a message in a new thread

mutation {
  aiAction(
    input: {
      chat: {
        resourceId: "gid://gitlab/User/1",
        content: "Hi"
      }
      conversationType: DUO_CHAT
    }
  ){
    requestId
    errors
    threadId
  }
}

Response:

{
  "data": {
    "aiAction": {
      "requestId": "f4ce3daf-df2e-4338-b2a6-56e63ec2d27b",
      "errors": [],
      "threadId": "gid://gitlab/Ai::Conversation::Thread/7"
    }
  },
  "correlationId": "01JHQ5WS252276QMYH8KXDCY6E"
}

Example mutation query - continue an conversation in the specific thread

mutation {
  aiAction(
    input: {
      chat: {
        resourceId: "gid://gitlab/User/1",
        content: "Can you elaborate?"
      }
      conversationType: DUO_CHAT,
      threadId: "gid://gitlab/Ai::Conversation::Thread/7"
    }
  ){
    requestId
    errors
    threadId
  }
}

Response:

{
  "data": {
    "aiAction": {
      "requestId": "21596337-b9ad-4f8d-b73c-87284c06c542",
      "errors": [],
      "threadId": "gid://gitlab/Ai::Conversation::Thread/7"
    }
  },
  "correlationId": "01JHQ607NKT7ZHGZ5XTJZK2SZV"
}

Example mutation query - old parameters:

mutation {
  aiAction(
    input: {
      chat: {
        resourceId: "gid://gitlab/User/1",
        content: "How can I create an issue?"
      }
    }
  ){
    requestId
    errors
    threadId
  }
}

Response:

{
  "data": {
    "aiAction": {
      "requestId": "e993609f-97a9-4238-a73e-52ad9bc06231",
      "errors": [],
      "threadId": "gid://gitlab/Ai::Conversation::Thread/7"
    }
  },
  "correlationId": "01JHQ61SYFADVP9KAAT4H2FFZS"
}
Example aiMessages query

Example aiMessages query - specific thread id

query {
  aiMessages(threadId: "gid://gitlab/Ai::Conversation::Thread/7") {
    nodes {
      requestId
      content
      role
      timestamp
      chunkId
      errors
    }
  }
}

Response:

{
  "data": {
    "aiMessages": {
      "nodes": [
        {
          "requestId": "f4ce3daf-df2e-4338-b2a6-56e63ec2d27b",
          "content": "Hi",
          "role": "USER",
          "timestamp": "2025-01-16T09:07:47Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "f4ce3daf-df2e-4338-b2a6-56e63ec2d27b",
          "content": "Hello! I'm GitLab Duo Chat, an AI assistant created by GitLab to help with DevSecOps-related questions and tasks. How can I assist you today? Whether you have questions about GitLab features, need help with code, or want information about software development practices, I'm here to help. Please feel free to ask any questions you may have!\n\nYour feedback is important to us. After our interaction, please don't hesitate to let me know how I did or if there's anything I can improve on. How may I help you today?",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:07:53Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "21596337-b9ad-4f8d-b73c-87284c06c542",
          "content": "Can you elaborate?",
          "role": "USER",
          "timestamp": "2025-01-16T09:09:40Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "21596337-b9ad-4f8d-b73c-87284c06c542",
          "content": "Certainly! I'd be happy to elaborate on how I can assist you. As GitLab Duo Chat, I'm designed to help with a wide range of DevSecOps and software development topics. Here's a more detailed overview of what I can do:\n\n1. GitLab Features: I can explain various GitLab features, such as projects, groups, issues, merge requests, epics, work items, milestones, labels, CI/CD pipelines, and git repositories.\n\n2. Code Assistance: I can help generate code examples, explain code snippets, and provide guidance on best practices in software development.\n\n3. DevSecOps Practices: I can offer information and advice on DevSecOps methodologies, including continuous integration, continuous deployment, and security practices in the development lifecycle.\n\n4. GitLab Resource Information: If you're viewing a specific GitLab resource (like an issue, merge request, epic, or commit) and provide the ID or URL, I can retrieve and explain information about that resource.\n\n5. Documentation: I can provide information based on GitLab's documentation to answer questions about how to use various GitLab features.\n\n6. General Software Development: I can assist with questions related to programming languages, development tools, methodologies, and best practices.\n\nTo get the most out of our interaction, it's helpful if you can provide specific questions or topics you'd like to discuss. For example, you might ask:\n\n- \"How do I set up a CI/CD pipeline in GitLab?\"\n- \"Can you explain the difference between issues and epics?\"\n- \"What are some best practices for code reviews in merge requests?\"\n- \"How can I implement security scanning in my GitLab project?\"\n\nRemember, while I have access to a lot of information, I don't have real-time access to your specific GitLab instance or projects unless you provide specific identifiers or URLs.\n\nIs there a particular area of GitLab or software development you'd like to know more about?\n\nYour feedback is valuable to us. After our interaction, please feel free to let me know how I did or if there's anything I can improve on.",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:09:51Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "e993609f-97a9-4238-a73e-52ad9bc06231",
          "content": "How can I create an issue?",
          "role": "USER",
          "timestamp": "2025-01-16T09:10:32Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "e993609f-97a9-4238-a73e-52ad9bc06231",
          "content": "You can create an issue in GitLab in several ways:\n\n1. From a project:\n   - Navigate to your project\n   - Go to \"Plan > Issues\" and select \"New issue\" in the upper-right corner, or\n   - Select the plus sign at the top of the left sidebar and choose \"New issue\" under \"In this project\"\n\n2. From a group:\n   - Go to your group\n   - Select \"Plan > Issues\"\n   - Choose \"Select project to create issue\" in the upper-right corner\n   - Pick the project and click \"New issue in [project name]\"\n\n3. From an issue board:\n   - Go to your project or group\n   - Select \"Plan > Issue boards\"\n   - Click \"Create new issue\" at the top of a board list\n\n4. From another issue or incident:\n   - In an existing issue, select \"Issue actions\" (ellipsis icon)\n   - Choose \"New related issue\"\n\n5. By sending an email (if configured)\n\n6. Using a URL with prefilled values\n\n7. Using Service Desk\n\nFor all methods, you'll need to complete the required fields in the new issue form and then select \"Create issue\".",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:10:50Z",
          "chunkId": null,
          "errors": []
        }
      ]
    }
  },
  "correlationId": "01JHQ64R4WA3TADX4MTNFQV57J"
}

Example aiMessages query - specific conversation type

query {
  aiMessages(conversationType: DUO_CHAT) {
    nodes {
      requestId
      content
      role
      timestamp
      chunkId
      errors
    }
  }
}

Response:

{
  "data": {
    "aiMessages": {
      "nodes": [
        {
          "requestId": "f4ce3daf-df2e-4338-b2a6-56e63ec2d27b",
          "content": "Hi",
          "role": "USER",
          "timestamp": "2025-01-16T09:07:47Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "f4ce3daf-df2e-4338-b2a6-56e63ec2d27b",
          "content": "Hello! I'm GitLab Duo Chat, an AI assistant created by GitLab to help with DevSecOps-related questions and tasks. How can I assist you today? Whether you have questions about GitLab features, need help with code, or want information about software development practices, I'm here to help. Please feel free to ask any questions you may have!\n\nYour feedback is important to us. After our interaction, please don't hesitate to let me know how I did or if there's anything I can improve on. How may I help you today?",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:07:53Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "21596337-b9ad-4f8d-b73c-87284c06c542",
          "content": "Can you elaborate?",
          "role": "USER",
          "timestamp": "2025-01-16T09:09:40Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "21596337-b9ad-4f8d-b73c-87284c06c542",
          "content": "Certainly! I'd be happy to elaborate on how I can assist you. As GitLab Duo Chat, I'm designed to help with a wide range of DevSecOps and software development topics. Here's a more detailed overview of what I can do:\n\n1. GitLab Features: I can explain various GitLab features, such as projects, groups, issues, merge requests, epics, work items, milestones, labels, CI/CD pipelines, and git repositories.\n\n2. Code Assistance: I can help generate code examples, explain code snippets, and provide guidance on best practices in software development.\n\n3. DevSecOps Practices: I can offer information and advice on DevSecOps methodologies, including continuous integration, continuous deployment, and security practices in the development lifecycle.\n\n4. GitLab Resource Information: If you're viewing a specific GitLab resource (like an issue, merge request, epic, or commit) and provide the ID or URL, I can retrieve and explain information about that resource.\n\n5. Documentation: I can provide information based on GitLab's documentation to answer questions about how to use various GitLab features.\n\n6. General Software Development: I can assist with questions related to programming languages, development tools, methodologies, and best practices.\n\nTo get the most out of our interaction, it's helpful if you can provide specific questions or topics you'd like to discuss. For example, you might ask:\n\n- \"How do I set up a CI/CD pipeline in GitLab?\"\n- \"Can you explain the difference between issues and epics?\"\n- \"What are some best practices for code reviews in merge requests?\"\n- \"How can I implement security scanning in my GitLab project?\"\n\nRemember, while I have access to a lot of information, I don't have real-time access to your specific GitLab instance or projects unless you provide specific identifiers or URLs.\n\nIs there a particular area of GitLab or software development you'd like to know more about?\n\nYour feedback is valuable to us. After our interaction, please feel free to let me know how I did or if there's anything I can improve on.",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:09:51Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "e993609f-97a9-4238-a73e-52ad9bc06231",
          "content": "How can I create an issue?",
          "role": "USER",
          "timestamp": "2025-01-16T09:10:32Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "e993609f-97a9-4238-a73e-52ad9bc06231",
          "content": "You can create an issue in GitLab in several ways:\n\n1. From a project:\n   - Navigate to your project\n   - Go to \"Plan > Issues\" and select \"New issue\" in the upper-right corner, or\n   - Select the plus sign at the top of the left sidebar and choose \"New issue\" under \"In this project\"\n\n2. From a group:\n   - Go to your group\n   - Select \"Plan > Issues\"\n   - Choose \"Select project to create issue\" in the upper-right corner\n   - Pick the project and click \"New issue in [project name]\"\n\n3. From an issue board:\n   - Go to your project or group\n   - Select \"Plan > Issue boards\"\n   - Click \"Create new issue\" at the top of a board list\n\n4. From another issue or incident:\n   - In an existing issue, select \"Issue actions\" (ellipsis icon)\n   - Choose \"New related issue\"\n\n5. By sending an email (if configured)\n\n6. Using a URL with prefilled values\n\n7. Using Service Desk\n\nFor all methods, you'll need to complete the required fields in the new issue form and then select \"Create issue\".",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:10:50Z",
          "chunkId": null,
          "errors": []
        }
      ]
    }
  },
  "correlationId": "01JHQ67M886VAS99244HNQ2HR1"
}

Example aiMessages query - legacy param

query {
  aiMessages {
    nodes {
      requestId
      content
      role
      timestamp
      chunkId
      errors
    }
  }
}

Response:

{
  "data": {
    "aiMessages": {
      "nodes": [
        {
          "requestId": "f4ce3daf-df2e-4338-b2a6-56e63ec2d27b",
          "content": "Hi",
          "role": "USER",
          "timestamp": "2025-01-16T09:07:47Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "f4ce3daf-df2e-4338-b2a6-56e63ec2d27b",
          "content": "Hello! I'm GitLab Duo Chat, an AI assistant created by GitLab to help with DevSecOps-related questions and tasks. How can I assist you today? Whether you have questions about GitLab features, need help with code, or want information about software development practices, I'm here to help. Please feel free to ask any questions you may have!\n\nYour feedback is important to us. After our interaction, please don't hesitate to let me know how I did or if there's anything I can improve on. How may I help you today?",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:07:53Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "21596337-b9ad-4f8d-b73c-87284c06c542",
          "content": "Can you elaborate?",
          "role": "USER",
          "timestamp": "2025-01-16T09:09:40Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "21596337-b9ad-4f8d-b73c-87284c06c542",
          "content": "Certainly! I'd be happy to elaborate on how I can assist you. As GitLab Duo Chat, I'm designed to help with a wide range of DevSecOps and software development topics. Here's a more detailed overview of what I can do:\n\n1. GitLab Features: I can explain various GitLab features, such as projects, groups, issues, merge requests, epics, work items, milestones, labels, CI/CD pipelines, and git repositories.\n\n2. Code Assistance: I can help generate code examples, explain code snippets, and provide guidance on best practices in software development.\n\n3. DevSecOps Practices: I can offer information and advice on DevSecOps methodologies, including continuous integration, continuous deployment, and security practices in the development lifecycle.\n\n4. GitLab Resource Information: If you're viewing a specific GitLab resource (like an issue, merge request, epic, or commit) and provide the ID or URL, I can retrieve and explain information about that resource.\n\n5. Documentation: I can provide information based on GitLab's documentation to answer questions about how to use various GitLab features.\n\n6. General Software Development: I can assist with questions related to programming languages, development tools, methodologies, and best practices.\n\nTo get the most out of our interaction, it's helpful if you can provide specific questions or topics you'd like to discuss. For example, you might ask:\n\n- \"How do I set up a CI/CD pipeline in GitLab?\"\n- \"Can you explain the difference between issues and epics?\"\n- \"What are some best practices for code reviews in merge requests?\"\n- \"How can I implement security scanning in my GitLab project?\"\n\nRemember, while I have access to a lot of information, I don't have real-time access to your specific GitLab instance or projects unless you provide specific identifiers or URLs.\n\nIs there a particular area of GitLab or software development you'd like to know more about?\n\nYour feedback is valuable to us. After our interaction, please feel free to let me know how I did or if there's anything I can improve on.",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:09:51Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "e993609f-97a9-4238-a73e-52ad9bc06231",
          "content": "How can I create an issue?",
          "role": "USER",
          "timestamp": "2025-01-16T09:10:32Z",
          "chunkId": null,
          "errors": []
        },
        {
          "requestId": "e993609f-97a9-4238-a73e-52ad9bc06231",
          "content": "You can create an issue in GitLab in several ways:\n\n1. From a project:\n   - Navigate to your project\n   - Go to \"Plan > Issues\" and select \"New issue\" in the upper-right corner, or\n   - Select the plus sign at the top of the left sidebar and choose \"New issue\" under \"In this project\"\n\n2. From a group:\n   - Go to your group\n   - Select \"Plan > Issues\"\n   - Choose \"Select project to create issue\" in the upper-right corner\n   - Pick the project and click \"New issue in [project name]\"\n\n3. From an issue board:\n   - Go to your project or group\n   - Select \"Plan > Issue boards\"\n   - Click \"Create new issue\" at the top of a board list\n\n4. From another issue or incident:\n   - In an existing issue, select \"Issue actions\" (ellipsis icon)\n   - Choose \"New related issue\"\n\n5. By sending an email (if configured)\n\n6. Using a URL with prefilled values\n\n7. Using Service Desk\n\nFor all methods, you'll need to complete the required fields in the new issue form and then select \"Create issue\".",
          "role": "ASSISTANT",
          "timestamp": "2025-01-16T09:10:50Z",
          "chunkId": null,
          "errors": []
        }
      ]
    }
  },
  "correlationId": "01JHQ68NJ7R5AKZX2JTS0720EA"
}

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Edited by Shinya Maeda

Merge request reports

Loading