@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, and professional CLI. Built-in tools operational, 58+ external MCP servers discoverable. Connect to filesystem, GitHub, database operations, and more. Build, test, and
118 lines (117 loc) • 3.79 kB
TypeScript
/**
* Structured Output Streaming Parser (Phase 2.3)
*
* This module provides partial JSON parsing for streaming structured output
* responses from SageMaker endpoints with real-time validation.
*/
import type { SageMakerStructuredOutput } from "./types.js";
/**
* Partial JSON parser for streaming structured output
*/
export declare class StructuredOutputParser {
private buffer;
private currentObject;
private currentPath;
private schema?;
private inString;
private escapeNext;
private bracketCount;
private arrayBracketCount;
private lastProcessedLength;
private lastKeyValueParsePosition;
private bracketTypeStack;
constructor(schema?: Record<string, unknown>);
/**
* Parse a chunk of JSON text and return structured output info
*/
parseChunk(chunk: string): SageMakerStructuredOutput;
/**
* Parse partial JSON by tracking structure with consolidated bracket counting
*/
private parsePartialJSON;
/**
* Consolidated bracket structure processing - handles both counting and path navigation
* Uses shared bracket counting logic to reduce code duplication
*/
private processBracketStructure;
/**
* Extract partial object from buffer by finding valid JSON fragments
* Optimized for large JSON strings using true incremental parsing to prevent O(n²) performance
*/
private extractPartialObject;
/**
* Efficiently parse key-value pairs from JSON buffer using true incremental approach
* Optimized for large JSON strings to avoid O(n²) performance by only processing new content
*/
private parseKeyValuePairsIncrementally;
/**
* Parse a quoted string from buffer starting at given index
*/
private parseQuotedString;
/**
* Parse a JSON value (string, number, boolean, null) from buffer
*/
private parseJsonValue;
/**
* Parse a number from buffer starting at given index
*/
private parseNumber;
/**
* Validate partial object against schema
*/
private validatePartialObject;
/**
* Validate complete object against schema
*/
private validateAgainstSchema;
/**
* Validate a single property against its schema
*/
private validateProperty;
/**
* Check if the current object appears to be complete using efficient bracket counting
*/
private isObjectComplete;
/**
* Optimized whitespace check to replace regex for performance with large strings
*/
private isWhitespace;
/**
* Optimized digit check to replace regex for performance with large strings
*/
private isDigit;
/**
* Optimized hex string validation to replace regex for unicode escape sequences
*/
private isValidHexString;
/**
* Reset parser state
*/
reset(): void;
/**
* Get current parsing state for debugging
*/
getState(): {
bufferLength: number;
currentPath: string[];
inString: boolean;
objectKeys: string[];
bracketCount: number;
arrayBracketCount: number;
lastProcessedLength: number;
lastKeyValueParsePosition: number;
bracketTypeStack: string[];
};
}
/**
* Factory function to create structured output parser
*/
export declare function createStructuredOutputParser(schema?: Record<string, unknown>): StructuredOutputParser;
/**
* Utility function to detect if content is structured JSON
*/
export declare function isStructuredContent(content: string): boolean;
/**
* Utility function to extract JSON schema from response format
*/
export declare function extractSchemaFromResponseFormat(responseFormat: Record<string, unknown>): Record<string, unknown> | undefined;