const stringifyPromptSegment = (segment) => {
    if (segment === null || segment === undefined) {
        return '';
    }
    if (typeof segment === 'string' || typeof segment === 'number' || typeof segment === 'boolean') {
        return String(segment);
    }
    if (Array.isArray(segment)) {
        return segment
            .map((entry) => stringifyPromptSegment(entry))
            .filter((entry) => entry.length > 0)
            .join('\n\n');
    }
    if (typeof segment === 'object') {
        const typed = segment;
        if (typeof typed.text === 'string') {
            return typed.text;
        }
        if (typed.type === 'text' && typeof typed.text === 'string') {
            return String(typed.text);
        }
        return JSON.stringify(typed, null, 2);
    }
    return JSON.stringify(segment);
};
export const stringifyPromptContent = (content) => {
    if (content === undefined || content === null) {
        return '';
    }
    const segments = Array.isArray(content) ? content : [content];
    return segments
        .map((segment) => stringifyPromptSegment(segment))
        .filter((entry) => entry.length > 0)
        .join('\n\n');
};
