export function parseStreamJsonEvent(line) {
    try {
        const parsed = JSON.parse(line);
        if (parsed !== null && typeof parsed === 'object') {
            return parsed;
        }
        return null;
    }
    catch {
        return null;
    }
}
export function extractText(event) {
    if (typeof event.text === 'string') {
        return event.text;
    }
    if (event.delta !== undefined && typeof event.delta.text === 'string') {
        return event.delta.text;
    }
    const content = event.message?.content;
    if (Array.isArray(content)) {
        const text = content
            .filter((part) => part.type === 'text' && typeof part.text === 'string')
            .map((part) => part.text ?? '')
            .join('');
        return text.length > 0 ? text : null;
    }
    return null;
}
export function isTurnComplete(event) {
    if (event.type === 'result' || event.type === 'message_stop') {
        return true;
    }
    if (event.type === 'system' && event.subtype === 'turn_duration') {
        return true;
    }
    return event.type === 'assistant' && event.message?.stop_reason === 'end_turn';
}
//# sourceMappingURL=emberStreamJson.parser.js.map