From 663048f2f8420c434d258680d4c6a94e743d206f Mon Sep 17 00:00:00 2001 From: Abhijit Balaji Date: Thu, 5 Mar 2026 16:22:02 -0800 Subject: [PATCH] refactor(core): improve type safety in apiContentToMessageRecords --- .../core/src/services/chatRecordingService.ts | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/packages/core/src/services/chatRecordingService.ts b/packages/core/src/services/chatRecordingService.ts index d970dc01b5..ed589113a7 100644 --- a/packages/core/src/services/chatRecordingService.ts +++ b/packages/core/src/services/chatRecordingService.ts @@ -227,17 +227,22 @@ export class ChatRecordingService { * Converts API Content array to storage-compatible MessageRecord array. */ private apiContentToMessageRecords(history: Content[]): MessageRecord[] { - return history.map((content) => { - const type = content.role === 'model' ? 'gemini' : 'user'; - const record = { - id: randomUUID(), - timestamp: new Date().toISOString(), - type, - content: content.parts, - }; - - // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion - return record as MessageRecord; + return history.map((content): MessageRecord => { + if (content.role === 'model') { + return { + id: randomUUID(), + timestamp: new Date().toISOString(), + type: 'gemini', + content: content.parts || [], + }; + } else { + return { + id: randomUUID(), + timestamp: new Date().toISOString(), + type: 'user', + content: content.parts || [], + }; + } }); }