/**
 * Follow-up suggestion marker parsing.
 *
 * The system prompt instructs the agent to end every response with an HTML
 * comment of the form:
 *
 *   <!-- followups: ["prompt 1", "prompt 2", "prompt 3"] -->
 *
 * Each transport (web, CLI, MCP) must strip this marker from the content it
 * displays and surface the suggestions in whatever form fits its UI — chips
 * in the web client, a dim numbered list in the CLI, a `suggestions` field
 * in MCP, etc.
 *
 * Keep the parser in one place so a new transport can't silently leak the
 * raw marker.
 */
/** Matches the trailing followups HTML comment at end of text (with optional trailing whitespace). */
const FOLLOWUPS_RE = /<!--\s*followups:\s*(\[[\s\S]*?\])\s*-->\s*$/;
/**
 * Parse a raw agent response and split it into clean content plus optional
 * follow-up suggestions. Malformed markers are left in place (the caller can
 * choose to strip or render as-is), matching the existing web behaviour.
 */
export function parseFollowups(raw) {
    const match = raw.match(FOLLOWUPS_RE);
    if (!match)
        return { content: raw };
    try {
        const parsed = JSON.parse(match[1]);
        if (!Array.isArray(parsed) || !parsed.every((s) => typeof s === 'string')) {
            return { content: raw };
        }
        const content = raw.slice(0, match.index).trimEnd();
        return { content, suggestions: parsed };
    }
    catch {
        return { content: raw };
    }
}
/**
 * Return true if `text` contains an *unclosed* followups marker — used by
 * streaming consumers to know whether to defer rendering the tail of a
 * delta until the closing `-->` arrives.
 */
export function hasOpenFollowupsMarker(text) {
    const lastOpen = text.lastIndexOf('<!--');
    if (lastOpen < 0)
        return false;
    const lastClose = text.lastIndexOf('-->');
    return lastClose < lastOpen;
}
//# sourceMappingURL=followups.js.map