/** * Streaming-polish layer: while an agent is mid-stream, the buffer is * usually an *unfinished* markdown document — an open code fence, an * unclosed `**`, etc. If we send the unbalanced text straight to Discord, * the rest of the message renders broken (a stray ``` will turn the rest * of the Discord message into a code block until the closer arrives). * * `autoCloseOpenMarkdown` returns a balanced copy of the buffer by * appending the minimum set of closers needed so that the markdown is * well-formed for display. When the agent later emits the real closer, * the buffer becomes balanced on its own and this function adds nothing * — i.e. no double-close in the committed Discord message. * * Operates in **markdown space** (i.e. on the raw text from the agent). * Discord renders a Markdown subset natively, so a balanced document * displays correctly without further translation. * * What it handles, in priority order: * * 1. Unclosed fenced code blocks ``` … (most severe — leaks code styling * through the rest of the Discord message) * 2. Unclosed inline code `…` * 3. Unclosed bold `**…` / `__…` * 4. Unclosed italic `*…` / `_…` * 5. Unclosed strike `~~…` * * Heuristics: * * - A marker with no content after it (e.g. trailing `**`) is **not** * closed — the agent might be just opening the bracket; closing would * produce a transient `****` which looks worse than `**`. * - Markers inside code/fence regions don't count. * - When closing, we emit closers in reverse stack order (innermost * first) so the rendered structure is well-nested. */ export declare function autoCloseOpenMarkdown(text: string): string; /** * What markdown context is *still open* at the end of `text`? Used to * decide what opening marker(s) the NEXT chunk needs prepended when we * split a long buffer across multiple Discord messages mid-formatting * — without this, a chunk boundary inside a ` ```python … ``` ` block * would have the second Discord message start with raw code that Discord * renders as plain text. */ export interface OpenMarkdownContext { /** If inside an unclosed fence, the language tag (may be ""). null otherwise. */ fenceLang: string | null; /** True if an unclosed single-backtick inline-code span is in flight. */ inlineCode: boolean; /** Bold/italic/strike markers still open, in stack order (outermost first). */ brackets: string[]; } export declare function detectOpenContext(text: string): OpenMarkdownContext; /** * Render the opener prefix for a continuation chunk so it can stand on * its own as a self-renderable markdown fragment. E.g. for an open * `` ```python `` fence, returns ` ```python\n `; for an open `**` bold, * returns `**`. */ export declare function renderContextOpener(ctx: OpenMarkdownContext): string; //# sourceMappingURL=auto-close-streaming.d.ts.map