Accept/expose conversation thread ID to AI actions API
Background
As part of Iteration 1: Multi-threaded conversations in the chat, this issue aims to make chat API endpoints work with multi-threads.
Key Concepts
-
duo_chat thread: A thread with
conversation_type == 'duo_chat' -
quick chat thread: A thread with another
conversation_type(yet to be determined)
Implementation Details
- Add
thread_idandconversation_typeto bothResolvers::Ai::ChatMessagesResolverandMutations::Ai::Actionas optional arguments.- (for backward compatibility, refer to
conversation_typeabsent routes below)
- (for backward compatibility, refer to
- For read operation (
Resolvers::Ai::ChatMessagesResolver)- If
conversation_typeis absent, read from latest duo_chat thread.- If no thread is found, return empty result.
- If
conversation_typeis present, fetch thread fromthread_id(and return empty result ifthread_idis nil).
- If
- For write operation (
Mutations::Ai::Action)- If
conversation_typeis absent, add message to user's latest duo_chat thread.- If no thread is available, create a new duo_chat thread first
- If
conversation_typeis present andthread_id=value, add message to the existing thread. - If
conversation_typeis present andthread_id=nil, create a new thread with specifiedconversation_type, and add message to it.
- If
- For both read and write, the thread must be scoped to the user and conversation_type to keep things secure.
- When creating thread, it should be done in
Llm::ChatService, and thethread_idshould be returned as part ofMutations::Ai::Action's response. - thread ID is added to websocket messages
- thread ID is also exposed for each message when listing AI messages
Edited by Mark Chao