diff --git a/app/MindWork AI Studio/Chat/ChatThread.cs b/app/MindWork AI Studio/Chat/ChatThread.cs index 7709db7e..d7dbf9a4 100644 --- a/app/MindWork AI Studio/Chat/ChatThread.cs +++ b/app/MindWork AI Studio/Chat/ChatThread.cs @@ -1,6 +1,7 @@ using AIStudio.Components; using AIStudio.Settings; using AIStudio.Settings.DataModel; +using AIStudio.Tools.ERIClient.DataModel; namespace AIStudio.Chat; @@ -150,4 +151,46 @@ public sealed record ChatThread // Remove the block from the chat thread: this.Blocks.Remove(block); } + + /// + /// Transforms this chat thread to an ERI chat thread. + /// + /// The cancellation token. + /// The ERI chat thread. + public async Task ToERIChatThread(CancellationToken token = default) + { + // + // Transform the content blocks: + // + var contentBlocks = new List(this.Blocks.Count); + foreach (var block in this.Blocks) + { + var (contentData, contentType) = block.Content switch + { + ContentImage image => (await image.AsBase64(token), Tools.ERIClient.DataModel.ContentType.IMAGE), + ContentText text => (text.Text, Tools.ERIClient.DataModel.ContentType.TEXT), + + _ => (string.Empty, Tools.ERIClient.DataModel.ContentType.UNKNOWN), + }; + + contentBlocks.Add(new Tools.ERIClient.DataModel.ContentBlock + { + Role = block.Role switch + { + ChatRole.AI => Role.AI, + ChatRole.USER => Role.USER, + ChatRole.AGENT => Role.AGENT, + ChatRole.SYSTEM => Role.SYSTEM, + ChatRole.NONE => Role.NONE, + + _ => Role.UNKNOW, + }, + + Content = contentData, + Type = contentType, + }); + } + + return new Tools.ERIClient.DataModel.ChatThread { ContentBlocks = contentBlocks }; + } } \ No newline at end of file