const RESEARCH_CONTEXT_REGEX = /<research-context\s+from="([^"]+)"\s+label="([^"]+)"[^>]*>([\s\S]*?)<\/research-context>/g;
export function parseResearchContext(content) {
    const researchContexts = [];
    let cleanContent = content;
    const regex = new RegExp(RESEARCH_CONTEXT_REGEX);
    let match = regex.exec(content);
    while (match !== null) {
        const [fullMatch, from, label, innerContent] = match;
        researchContexts.push({
            id: from,
            from,
            label,
            content: innerContent.trim(),
        });
        cleanContent = cleanContent.replace(fullMatch, '');
        match = regex.exec(content);
    }
    cleanContent = cleanContent.trim();
    return {
        researchContexts,
        cleanContent,
    };
}
export function formatResearchContextForMessage(contexts) {
    if (contexts.length === 0)
        return '';
    // content is already the full XML from server, just join them
    return contexts.map((ctx) => ctx.content).join('\n\n');
}
//# sourceMappingURL=parseResearchContext.js.map