@humanspeak/svelte-markdown
Version:
Markdown and HTML renderer for Svelte 5 — built for rendering streaming AI agent output from Claude Code, ChatGPT, and agentic workflows. XSS-safe defaults, streaming-aware sanitization, token caching, TypeScript types, and Svelte 5 runes.
41 lines (40 loc) • 1.79 kB
TypeScript
import type { StreamingChunk, StreamingOffsetChunk } from '../types.js';
export declare const STREAM_BATCH_FALLBACK_MS = 16;
export declare const STREAM_BATCH_MAX_CHARS = 256;
export declare const STREAM_MAX_OFFSET_GAP = 1000000;
export type StreamingInputMode = 'append' | 'offset' | null;
export type StreamingChunkInstruction = {
kind: 'append';
value: string;
nextMode: 'append';
} | {
kind: 'offset';
chunk: StreamingOffsetChunk;
nextMode: 'offset';
} | {
kind: 'drop';
message: string;
};
export interface StreamingChunkInstructionOptions {
currentBufferLength?: number;
maxOffsetGap?: number;
}
export interface ApplyStreamingOffsetChunkOptions {
maxOffsetGap?: number;
}
/**
* Checks whether a streaming chunk uses offset-based patching.
*
* @param chunk Streaming chunk passed to the imperative streaming API.
* @returns True when the chunk has an `offset` field.
*/
export declare const isStreamingOffsetChunk: (chunk: StreamingChunk) => chunk is StreamingOffsetChunk;
export declare const getStreamingChunkInstruction: (chunk: StreamingChunk, currentMode: StreamingInputMode, { currentBufferLength, maxOffsetGap }?: StreamingChunkInstructionOptions) => StreamingChunkInstruction;
export declare const appendStreamingChunk: (pendingBuffer: string, value: string) => string;
export declare const commitStreamingAppendBuffer: (sourceBuffer: string, pendingBuffer: string) => {
committed: boolean;
sourceBuffer: string;
pendingBuffer: string;
};
export declare const shouldFlushStreamingAppendBuffer: (pendingBuffer: string, maxChars?: number) => boolean;
export declare const applyStreamingOffsetChunk: (source: string, { value, offset }: StreamingOffsetChunk, { maxOffsetGap }?: ApplyStreamingOffsetChunkOptions) => string;