MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / saveChat

Method saveChat

app/src/AI/ChatStore.cpp:182–209  ·  view source on GitHub ↗

* @brief Writes a chat's snapshot and refreshes its index metadata. */

Source from the content-addressed store, hash-verified

180 * @brief Writes a chat's snapshot and refreshes its index metadata.
181 */
182void AI::ChatStore::saveChat(const QString& id,
183 const QJsonObject& snapshot,
184 const QString& title,
185 int count)
186{
187 const int idx = indexOf(id);
188 if (idx < 0) {
189 qCWarning(serialStudioAI) << "ChatStore: saveChat for unknown id" << id;
190 return;
191 }
192
193 QDir().mkpath(chatsDir());
194 QFile f(chatPath(id));
195 if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
196 qCWarning(serialStudioAI) << "ChatStore: cannot write chat" << id << f.errorString();
197 return;
198 }
199
200 f.write(QJsonDocument(snapshot).toJson(QJsonDocument::Compact));
201 f.close();
202
203 m_chats[idx].updatedAt = QDateTime::currentMSecsSinceEpoch();
204 m_chats[idx].count = count;
205 if (!title.isEmpty() && m_chats[idx].title.isEmpty())
206 m_chats[idx].title = title;
207
208 writeIndex();
209}
210
211/**
212 * @brief Deletes a chat's snapshot file and index entry.

Callers 2

~AssistantMethod · 0.80
persistActiveChatMethod · 0.80

Calls 6

errorStringMethod · 0.80
isEmptyMethod · 0.80
openMethod · 0.45
writeMethod · 0.45
toJsonMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected