/** * March Agent SDK - TextBlock Structural Streamer * Port of Python march_agent/structural/text_block.py * * TextBlock structural streamer for collapsible text content. */ import { StructuralStreamer, generateShortId } from './base.js' /** * Manages collapsible text block with title and body. * * Both title and body support streaming (append) and update (replace). * TextBlock events are NOT persisted to database. * * @example * ```typescript * const block = new TextBlock() // ID auto-generated * s.streamBy(block).setVariant("thinking") * s.streamBy(block).streamTitle("Deep ") * s.streamBy(block).streamTitle("Analysis...") * s.streamBy(block).streamBody("Step 1: Check patterns\n") * s.streamBy(block).streamBody("Step 2: Validate\n") * s.streamBy(block).updateTitle("Analysis Complete") * s.streamBy(block).done() * ``` */ export class TextBlock extends StructuralStreamer { readonly initialTitle?: string constructor(options?: { id?: string; title?: string }) { super(options?.id) this.initialTitle = options?.title } protected _generateId(): string { return `text_block-${generateShortId()}` } getEventTypePrefix(): string { return 'text_block' } /** * Stream title content (appends to existing). * * @param content - Content to append to title * @returns this for method chaining */ streamTitle(content: string): this { return this._sendEvent('stream_title', { content }) } /** * Stream body content (appends to existing). * * @param content - Content to append to body * @returns this for method chaining */ streamBody(content: string): this { return this._sendEvent('stream_body', { content }) } /** * Replace entire title. * * @param title - New title (replaces existing) * @returns this for method chaining */ updateTitle(title: string): this { return this._sendEvent('update_title', { title }) } /** * Replace entire body. * * @param body - New body (replaces existing) * @returns this for method chaining */ updateBody(body: string): this { return this._sendEvent('update_body', { body }) } /** * Set visual variant. * * @param variant - Visual style (thinking, note, warning, error, success) * @returns this for method chaining */ setVariant(variant: 'thinking' | 'note' | 'warning' | 'error' | 'success' | string): this { return this._sendEvent('set_variant', { variant }) } /** * Mark text block as complete. * * @returns this for method chaining */ done(): this { return this._sendEvent('done') } }