const DEFAULT_CHAT_NAME = 'Chat';
function getConversationName(metadata) {
    var _a;
    const title = (_a = metadata === null || metadata === void 0 ? void 0 : metadata.title) !== null && _a !== void 0 ? _a : metadata === null || metadata === void 0 ? void 0 : metadata.name;
    return title && title.trim() ? title.trim() : DEFAULT_CHAT_NAME;
}
export function mapOpenAIConversationsToChats(conversations) {
    if (!Array.isArray(conversations)) {
        return [];
    }
    return conversations.map((conv) => {
        var _a, _b;
        const createTime = conv.created_at ? new Date(conv.created_at * 1000).toISOString() : null;
        return {
            id: conv.id,
            name: getConversationName(conv.metadata),
            createTime,
            lastMessage: ((_a = conv.metadata) === null || _a === void 0 ? void 0 : _a.last_message) || undefined,
            metadata: (_b = conv.metadata) !== null && _b !== void 0 ? _b : undefined,
        };
    });
}
//# sourceMappingURL=mapOpenAIConversationsToChats.js.map
