import { asRecord, normalizeText } from './helpers.js';
function optionalString(value) {
    const normalized = normalizeText(value);
    return normalized || undefined;
}
function optionalContentString(value) {
    return typeof value === 'string' ? value : undefined;
}
export function parseTranscript(value) {
    if (!Array.isArray(value)) {
        return undefined;
    }
    const transcript = value.flatMap((item) => {
        const payload = asRecord(item);
        const role = normalizeText(payload.role);
        const content = optionalContentString(payload.content);
        const name = optionalString(payload.name);
        if (!role || content === undefined) {
            return [];
        }
        return [{
                role,
                content,
                ...(name ? { name } : {}),
            }];
    });
    return transcript.length > 0 ? transcript : undefined;
}
//# sourceMappingURL=runtime-agent-transcript-parsers.js.map