export function extractStrictRespondText(value) {
    if (!value)
        return null;
    if (typeof value === 'object' && !Array.isArray(value)) {
        const record = value;
        return String(record.kind ?? '').trim() === 'respond' && typeof record.text === 'string'
            ? record.text
            : null;
    }
    if (typeof value !== 'string')
        return null;
    const trimmed = value.trim();
    if (!trimmed)
        return null;
    const fencedMatch = /^```(?:json)?\s*\n([\s\S]*?)\n```$/i.exec(trimmed);
    if (fencedMatch)
        return extractStrictRespondText(fencedMatch[1]);
    if ((trimmed.startsWith('{') && trimmed.endsWith('}'))
        || (trimmed.startsWith('"') && trimmed.endsWith('"'))) {
        try {
            return extractStrictRespondText(JSON.parse(trimmed));
        }
        catch {
            return null;
        }
    }
    return null;
}
export function unwrapStrictRespondText(value) {
    return extractStrictRespondText(value) ?? String(value ?? '');
}
//# sourceMappingURL=strict-respond.js.map