/** * Structured Output - XML Element Builder for tool outputs * * Provides structured XML output format for better parsing by LLMs. * Inspired by Forge's Element builder pattern. * * @example * ```typescript * const output = Element.create('file_content') * .attr('path', '/src/main.ts') * .attr('lines', '1-50') * .cdata(fileContent) * .render(); * ``` */ export interface ElementAttributes { [key: string]: string | number | boolean | undefined; } export declare class Element { private tag; private attributes; private children; private textContent?; private isCData; constructor(tag: string); /** * Create a new element */ static create(tag: string): Element; /** * Create a file content element */ static fileContent(path: string, content: string, options?: { startLine?: number; endLine?: number; totalLines?: number; language?: string; }): Element; /** * Create a directory listing element */ static directoryListing(path: string, entries: Array<{ name: string; type: 'file' | 'directory'; size?: number; modified?: Date; }>): Element; /** * Create a search results element */ static searchResults(pattern: string, results: Array<{ path: string; line: number; column?: number; match: string; context?: string; }>, options?: { totalResults?: number; truncated?: boolean; }): Element; /** * Create a command output element */ static commandOutput(command: string, output: string, options?: { exitCode?: number; executionTimeMs?: number; workingDirectory?: string; }): Element; /** * Create an error element */ static error(message: string, options?: { type?: string; code?: string; suggestion?: string; recoverable?: boolean; }): Element; /** * Create a success element */ static success(message: string, details?: Record): Element; /** * Escape XML special characters for attribute values */ private escapeXml; /** * Add an attribute */ attr(key: string, value: string | number | boolean | undefined): this; /** * Add multiple attributes */ attrs(attributes: ElementAttributes): this; /** * Set text content (XML escaped) */ text(content: string): this; /** * Set CDATA content (not XML escaped) */ cdata(content: string): this; /** * Add a child element */ child(child: Element): this; /** * Add multiple child elements */ addChildren(children: Element[]): this; /** * Render the element as XML string */ render(indent?: string): string; /** * Render as compact XML (no indentation) */ renderCompact(): string; /** * Get the tag name */ getTag(): string; /** * Get an attribute value */ getAttr(key: string): string | undefined; /** * Get all attributes */ getAttrs(): Record; /** * Get text content */ getText(): string | undefined; /** * Get children */ getChildren(): Element[]; /** * Check if element has children */ hasChildren(): boolean; /** * Check if element has text content */ hasText(): boolean; /** * Clone the element */ clone(): Element; /** * Convert to JSON representation */ toJSON(): object; /** * Create from JSON */ static fromJSON(json: any): Element; } export declare class XMLParser { /** * Parse XML string to Element * Note: This is a simple parser for the output format, not a full XML parser */ static parse(xml: string): Element | null; private static parseAttributes; } export declare const StructuredOutput: { Element: typeof Element; XMLParser: typeof XMLParser; fileContent: typeof Element.fileContent; directoryListing: typeof Element.directoryListing; searchResults: typeof Element.searchResults; commandOutput: typeof Element.commandOutput; error: typeof Element.error; success: typeof Element.success; renderList(elements: Element[], separator?: string): string; wrapInRoot(rootTag: string, children: Element[]): Element; }; export default StructuredOutput;