/**
 * Types for real-time audio streaming transcription results and structured errors.
 * Mirrors the C# LiveAudioTranscriptionResponse (extends ConversationItem) and CoreErrorResponse.
 */
/**
 * Parse raw Core JSON response into a LiveAudioTranscriptionResponse.
 * Maps the flat Core format (text, is_final, start_time, end_time) into
 * the ConversationItem-shaped result with content[0].text and content[0].transcript.
 * @internal
 */
export function parseTranscriptionResult(json) {
    const raw = JSON.parse(json);
    return {
        id: raw.id ?? null,
        is_final: raw.is_final ?? false,
        start_time: raw.start_time ?? null,
        end_time: raw.end_time ?? null,
        content: [
            {
                text: raw.text ?? '',
                transcript: raw.text ?? ''
            }
        ]
    };
}
/**
 * Attempt to parse a native error string as a structured CoreErrorResponse.
 * Handles both raw JSON and CoreInterop-prefixed messages
 * (e.g., "Command 'X' failed: {...}").
 * Returns null if no valid CoreErrorResponse JSON is found.
 * @internal
 */
export function tryParseCoreError(errorString) {
    // Try raw JSON first, then extract JSON after "failed: " prefix
    const candidates = [errorString];
    const prefixIdx = errorString.indexOf('failed: ');
    if (prefixIdx !== -1) {
        candidates.push(errorString.substring(prefixIdx + 8));
    }
    for (const candidate of candidates) {
        try {
            const parsed = JSON.parse(candidate);
            if (typeof parsed.code === 'string' && typeof parsed.message === 'string' && typeof parsed.isTransient === 'boolean') {
                return parsed;
            }
        }
        catch {
            // not valid JSON, try next candidate
        }
    }
    return null;
}
