/**
 * Normalize chat messages (including function responses) so that the OpenAI
 * Chat Completions API receives the full conversation context.
 */
export function serializeChatMessagesForOpenAI(messages) {
    return messages.map((message, index) => {
        if (message.role === "function") {
            return {
                role: "function",
                name: message.name && message.name.length > 0 ? message.name : `function_call_${index}`,
                content: message.content ?? "",
            };
        }
        return {
            role: message.role,
            content: message.content ?? "",
        };
    });
}
//# sourceMappingURL=chat.js.map