mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-12 12:54:07 -07:00
refactor(core): improve type safety in apiContentToMessageRecords
This commit is contained in:
@@ -227,17 +227,22 @@ export class ChatRecordingService {
|
|||||||
* Converts API Content array to storage-compatible MessageRecord array.
|
* Converts API Content array to storage-compatible MessageRecord array.
|
||||||
*/
|
*/
|
||||||
private apiContentToMessageRecords(history: Content[]): MessageRecord[] {
|
private apiContentToMessageRecords(history: Content[]): MessageRecord[] {
|
||||||
return history.map((content) => {
|
return history.map((content): MessageRecord => {
|
||||||
const type = content.role === 'model' ? 'gemini' : 'user';
|
if (content.role === 'model') {
|
||||||
const record = {
|
return {
|
||||||
id: randomUUID(),
|
id: randomUUID(),
|
||||||
timestamp: new Date().toISOString(),
|
timestamp: new Date().toISOString(),
|
||||||
type,
|
type: 'gemini',
|
||||||
content: content.parts,
|
content: content.parts || [],
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
return {
|
||||||
return record as MessageRecord;
|
id: randomUUID(),
|
||||||
|
timestamp: new Date().toISOString(),
|
||||||
|
type: 'user',
|
||||||
|
content: content.parts || [],
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user