UNPKG

@juspay/neurolink

Version:

The pipe layer of an AI nervous system: one interface connecting provider neurons to your application, across three inference types — generate, stream and decide. `decide` returns typed, calibrated judgements from a non-generative model (~400ms, ~$0.00002

49 lines (48 loc) • 2.33 kB
/** * Streaming response handling for Amazon SageMaker Provider (Phase 2) * * This module provides full streaming support with automatic protocol detection * and model-specific parsing for various SageMaker deployment patterns. */ import { ReadableStream } from "stream/web"; import type { SageMakerStreamChunk, SageMakerUsage, SageMakerConfig } from "../../types/index.js"; /** * Create a SageMaker streaming response with automatic protocol detection * * @param responseStream - Raw response stream from SageMaker endpoint * @param endpointName - SageMaker endpoint name for capability detection * @param config - SageMaker configuration * @param options - Stream options and metadata * @returns Promise resolving to ReadableStream compatible with AI SDK */ export declare function createSageMakerStream(responseStream: AsyncIterable<Uint8Array>, endpointName: string, config: SageMakerConfig, options?: { prompt?: string; abortSignal?: AbortSignal; onChunk?: (chunk: SageMakerStreamChunk) => void; onComplete?: (usage: SageMakerUsage) => void; onError?: (error: Error) => void; }): Promise<ReadableStream<unknown>>; /** * Create a synthetic stream from complete text (for backward compatibility) */ export declare function createSyntheticStream(text: string, usage: SageMakerUsage, options?: { onChunk?: (chunk: SageMakerStreamChunk) => void; onComplete?: (usage: SageMakerUsage) => void; }): Promise<ReadableStream<unknown>>; /** * Extract REAL token usage from a complete (non-streaming) SageMaker * response body when the endpoint reports it. Covers the OpenAI-compatible * shape (vLLM / TGI-OpenAI: usage.prompt_tokens/completion_tokens), the * generic input_tokens/output_tokens shape, and the HuggingFace TGI shape * (details.tokens.input/generated). Returns undefined when no real counts * are present so callers can fall back to estimateTokenUsage. */ export declare function parseUsageFromResponseBody(body: Record<string, unknown> | Array<Record<string, unknown>>): SageMakerUsage | undefined; /** * Estimate token usage from text content * * @param prompt - Input prompt text * @param completion - Generated completion text * @returns Estimated usage information */ export declare function estimateTokenUsage(prompt: string, completion: string): SageMakerUsage;