MP: cleanup conversions

This commit is contained in:
Enrico Ros
2024-05-16 18:36:41 -07:00
parent 9d347f4a5a
commit 6727fcd111
2 changed files with 18 additions and 9 deletions
+6 -5
View File
@@ -16,17 +16,17 @@ export interface DConversation {
userTitle?: string;
autoTitle?: string;
// TODO: @deprecated - this should be the system purpose of current head of the conversation
// TODO: [x Head] - this should be the system purpose of current head of the conversation
// there should be the concept of the audience of the current head
systemPurposeId: SystemPurposeId; // system purpose of this conversation
// TODO: @deprecated - should be a view-related cache
tokenCount: number; // f(messages, llmId)
// when updated is null, we don't have messages yet (timestamps as Date.now())
created: number; // creation timestamp
updated: number | null; // last update timestamp
// TODO: @deprecated - should be a view-related cache
tokenCount: number; // f(messages, llmId)
// Not persisted, used while in-memory, or temporarily by the UI
// TODO: @deprecated - shouls not be in here - it's actually a per-message/operation thing
abortController: AbortController | null;
@@ -101,7 +101,8 @@ export function duplicateCConversation(conversation: DConversation, lastMessageI
// helpers - conversion
export function convertCConversation_V3_V4(conversation: DConversation) {
conversation.messages.forEach(message => convertDMessage_V3_V4(message));
// .messages
conversation.messages.forEach(convertDMessage_V3_V4);
}
+12 -4
View File
@@ -153,11 +153,19 @@ export function duplicateDMessage(message: DMessage): DMessage {
// helpers - conversion
export function convertDMessage_V3_V4(message: DMessage) {
const v3 = message as DMessage & { text: string };
if (!message.content || message.content.length === 0) {
message.content = [createTextPart(v3.text || '')];
delete (v3 as any).text;
// .content
if (!message.content || !Array.isArray(message.content)) {
// v3.text -> v4.content
message.content = [
createTextPart((message as any).text || ''),
];
delete (message as any).text;
}
// .userAttachments
if (!message.userAttachments?.length)
message.userAttachments = [];
}