@juspay/neurolink
Version:
Universal AI Development Platform with working MCP integration, multi-provider support, voice (TTS/STT/realtime), and professional CLI. 58+ external MCP servers discoverable, multimodal file processing, RAG pipelines. Build, test, and deploy AI applicatio
112 lines (111 loc) • 3.97 kB
TypeScript
/**
* SageMaker Streaming Response Parsers
*
* This module provides protocol-specific parsers for different streaming
* formats used by SageMaker endpoints (HuggingFace, LLaMA, custom models).
*/
import type { SageMakerStreamChunk, SageMakerUsage, SageMakerStructuredOutput, BracketCountingState, StreamingParser } from "../../types/index.js";
import { type StructuredOutputParser } from "./structured-parser.js";
/**
* Process a single character for bracket counting logic
* Shared utility to avoid code duplication between parsers
*/
export declare function processBracketCharacter(char: string, state: BracketCountingState): {
isValid: boolean;
reason?: string;
};
/**
* Utility function to validate JSON completeness using efficient bracket counting
* Extracted from parseArgumentsForToolCall for reusability
*/
export declare function validateJSONCompleteness(jsonString: string): {
isComplete: boolean;
reason?: string;
};
/**
* Utility function to parse tool call arguments with robust validation
* Extracted from parseArgumentsForToolCall for reusability
*/
export declare function parseToolCallArguments(args: string): {
arguments?: string;
complete?: boolean;
argumentsDelta?: string;
};
/**
* Abstract base parser with common functionality
*/
declare abstract class BaseStreamingParser implements StreamingParser {
protected buffer: string;
protected isCompleted: boolean;
protected totalUsage?: SageMakerUsage;
protected structuredParser?: StructuredOutputParser;
protected responseSchema?: Record<string, unknown>;
abstract parse(chunk: Uint8Array): SageMakerStreamChunk[];
abstract getName(): string;
isComplete(chunk: SageMakerStreamChunk): boolean;
extractUsage(finalChunk: SageMakerStreamChunk): SageMakerUsage | undefined;
reset(): void;
/**
* Enable structured output parsing with optional schema
*/
enableStructuredOutput(schema?: Record<string, unknown>): void;
/**
* Parse structured content if enabled
*/
protected parseStructuredContent(content: string): SageMakerStructuredOutput | undefined;
protected decodeChunk(chunk: Uint8Array): string;
protected parseJSON(text: string): unknown;
}
/**
* HuggingFace Transformers streaming parser (Server-Sent Events)
*/
export declare class HuggingFaceStreamParser extends BaseStreamingParser {
getName(): string;
parse(chunk: Uint8Array): SageMakerStreamChunk[];
private parseHuggingFaceChunk;
private parseHuggingFaceUsage;
private mapFinishReason;
}
/**
* LLaMA/OpenAI-compatible streaming parser (JSON Lines)
*/
export declare class LlamaStreamParser extends BaseStreamingParser {
getName(): string;
parse(chunk: Uint8Array): SageMakerStreamChunk[];
private parseLlamaChunk;
/**
* Parse tool call arguments with robust validation and error handling
*/
private parseToolCallArguments;
/**
* Parse streaming tool call from OpenAI-compatible format (Phase 2.3)
*/
private parseStreamingToolCall;
private parseLlamaUsage;
private mapFinishReason;
}
/**
* Custom/Generic streaming parser (Chunked Transfer)
*/
export declare class CustomStreamParser extends BaseStreamingParser {
private expectedFormat;
constructor(format?: "json" | "text");
getName(): string;
parse(chunk: Uint8Array): SageMakerStreamChunk[];
private parseJSONFormat;
private parseTextFormat;
private parseCustomChunk;
private parseCustomUsage;
}
/**
* Parser factory to create appropriate parser for detected protocol
*/
export declare class StreamingParserFactory {
static createParser(protocol: string, options?: Record<string, unknown>): StreamingParser;
static getSupportedProtocols(): string[];
}
/**
* Utility function to estimate token usage when not provided
*/
export declare function estimateTokenUsage(prompt: string, completion: string): SageMakerUsage;
export {};