UnrealVoxta 0.1.1
 
Loading...
Searching...
No Matches
ChatSession.h
Go to the documentation of this file.
1// Copyright(c) 2025 grrimgrriefer & DZnnah, see LICENSE for details.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "ChatMessage.h"
7#include "VoxtaServiceType.h"
9#include "AiCharData.h"
10#include "ChatSession.generated.h"
11
18USTRUCT(BlueprintType, Category = "Voxta")
19struct VOXTADATA_API FChatSession
20{
21 GENERATED_BODY()
22
23#pragma region public API
24public:
32 const TArray<FChatMessage>& GetChatMessages()
33 {
34 return m_chatMessages;
35 }
36
43 FGuid GetSessionId() const { return m_sessionId; }
44
51 const TMap<VoxtaServiceType, FVoxtaServiceEntryData>& GetActiveServices() const
52 {
53 return m_services;
54 }
55
61 void UpdateContext(const FString& newContext)
62 {
63 m_chatContext = newContext;
64 }
65
71 void AddChatMessage(const FChatMessage& message)
72 {
73 m_chatMessages.Add(message);
74 }
75
81 void RemoveChatMessage(const FGuid& messageID)
82 {
83 int index = m_chatMessages.IndexOfByPredicate([messageID] (const FChatMessage& InItem)
84 {
85 return InItem.GetMessageId() == messageID;
86 });
87
88 if (index != INDEX_NONE)
89 {
90 m_chatMessages.RemoveAt(index);
91 }
92 }
93
101 FChatMessage* GetChatMessageById(const FGuid& messageId)
102 {
103 return m_chatMessages.FindByPredicate([&messageId] (const FChatMessage& msg)
104 {
105 return msg.GetMessageId() == messageId;
106 });
107 }
108
117 explicit FChatSession(const TArray<const FAiCharData*>& characters,
118 FGuid chatId,
119 FGuid sessionId,
120 const TMap<VoxtaServiceType, FVoxtaServiceEntryData>& services,
121 FStringView chatContext) :
122 m_chatId(chatId),
123 m_sessionId(sessionId),
124 m_chatContext(chatContext),
125 m_characters(characters),
126 m_services(services)
127 {
128 m_characterIds.Reserve(characters.Num());
129 for (const FAiCharData* character : characters)
130 {
131 m_characterIds.Emplace(character->GetId());
132 }
133 }
134
136 FChatSession() = default;
137
144 FGuid GetChatId() const { return m_chatId; }
145
152 FStringView GetChatContext() const { return m_chatContext; }
153
160 const TArray<FGuid>& GetCharacterIds() const { return m_characterIds; }
161#pragma endregion
162
163#pragma region data
164private:
165 UPROPERTY(BlueprintReadOnly, Category = "Voxta", meta = (AllowPrivateAccess = "true", DisplayName = "Chat ID"))
166 FGuid m_chatId;
167
168 UPROPERTY(BlueprintReadOnly, Category = "Voxta", meta = (AllowPrivateAccess = "true", DisplayName = "Session ID"))
169 FGuid m_sessionId;
170
171 UPROPERTY(BlueprintReadOnly, Category = "Voxta", meta = (AllowPrivateAccess = "true", DisplayName = "Character IDs"))
172 TArray<FGuid> m_characterIds;
173
174 UPROPERTY(BlueprintReadOnly, Category = "Voxta", meta = (AllowPrivateAccess = "true", DisplayName = "Context"))
175 FString m_chatContext;
176
177 UPROPERTY(BlueprintReadOnly, Category = "Voxta", meta = (AllowPrivateAccess = "true", DisplayName = "Messages so far"))
178 TArray<FChatMessage> m_chatMessages;
179
180 TArray<const FAiCharData*> m_characters;
181
182 UPROPERTY(BlueprintReadOnly, Category = "Voxta", meta = (AllowPrivateAccess = "true", DisplayName = "Services"))
184#pragma endregion
185};
VoxtaServiceType
VoxtaServiceType All the possible VoxtaServer Services that the UnrealVoxta client currently supports...
Definition VoxtaServiceType.h:20
FAiCharData Read-only data struct containing all the relevant information for an AI character.
Definition AiCharData.h:21
FChatMessage Represents a single message in a chat conversation, containing both text and audio data.
Definition ChatMessage.h:16
const FGuid & GetMessageId() const
Get the unique identifier assigned to this message.
Definition ChatMessage.h:27
FGuid GetChatId() const
Get the VoxtaServer assigned ID of this chat session.
Definition ChatSession.h:144
void UpdateContext(const FString &newContext)
Update the context of the ongoing chat session.
Definition ChatSession.h:61
const TMap< VoxtaServiceType, FVoxtaServiceEntryData > & GetActiveServices() const
Get the services that were enabled when the chat session was started.
Definition ChatSession.h:51
FChatSession()=default
Default constructor.
void AddChatMessage(const FChatMessage &message)
Add a new chat message to the session.
Definition ChatSession.h:71
const TArray< FGuid > & GetCharacterIds() const
Get the list of character IDs in the chat session.
Definition ChatSession.h:160
void RemoveChatMessage(const FGuid &messageID)
Remove a chat message from the session by message ID.
Definition ChatSession.h:81
FChatMessage * GetChatMessageById(const FGuid &messageId)
Fetch a raw pointer to the ChatMessage that matches the given ID.
Definition ChatSession.h:101
FChatSession(const TArray< const FAiCharData * > &characters, FGuid chatId, FGuid sessionId, const TMap< VoxtaServiceType, FVoxtaServiceEntryData > &services, FStringView chatContext)
Create a new instance of the ChatSession, containing all relevant data to it.
Definition ChatSession.h:117
const TArray< FChatMessage > & GetChatMessages()
Get the chat message history for this session.
Definition ChatSession.h:32
FGuid GetSessionId() const
Get the VoxtaServer assigned ID of this session.
Definition ChatSession.h:43
FStringView GetChatContext() const
Get the current context of the chat session.
Definition ChatSession.h:152
FVoxtaServiceEntryData Data struct representing a specific serviceEntry provided within the VoxtaServ...
Definition VoxtaServiceEntryData.h:17