/** * Enhanced Token Stream Capture — the raw voice of an agent. * * Treats the token stream as the primary identity signal. Captures * per-token data, logprob distributions, chunk boundaries, and burst * patterns. The streaming topology — how tokens arrive in time — is a * physical artifact of inference hardware that cannot be faked without * literally running the same model on the same infrastructure. */ import type { StreamingTrace } from "../experiment/signals.js"; /** Logprob data for a single token — the computational DNA. */ export interface TokenLogprob { token: string; logprob: number; topAlternatives: Array<{ token: string; logprob: number; }>; } /** A burst — a sequence of tokens arriving in rapid succession. */ export interface BurstPattern { startIndex: number; endIndex: number; duration: number; tokenCount: number; } /** * Enhanced token stream capture — the full phenotypic recording. * * Extends StreamingTrace with logprobs, chunk boundaries, burst patterns, * and heart metadata. This is the primary input to the sensorium. */ export interface TokenStreamCapture { tokens: string[]; timestamps: number[]; interTokenIntervals: number[]; logprobs: TokenLogprob[] | null; chunkBoundaries: number[]; chunkSizes: number[]; burstPattern: BurstPattern[]; seedApplied: string; heartbeatCount: number; birthCertificateCount: number; startTime: number; firstTokenTime: number | null; endTime: number; } /** * Convert a basic StreamingTrace to a TokenStreamCapture. * Fills in derived fields (intervals, bursts, chunks) from the raw data. */ export declare function fromStreamingTrace(trace: StreamingTrace, logprobs?: TokenLogprob[] | null, chunkBoundaries?: number[], heartMeta?: { seedApplied?: string; heartbeatCount?: number; birthCertificateCount?: number; }): TokenStreamCapture; /** * Convert a TokenStreamCapture back to a StreamingTrace (for backward compat). */ export declare function toStreamingTrace(capture: TokenStreamCapture): StreamingTrace; /** Compute inter-token intervals from timestamps. */ export declare function computeIntervals(timestamps: number[]): number[]; /** * Infer chunk boundaries from token timestamps. * * When multiple tokens arrive with near-zero inter-token interval (< 0.5ms), * they likely came in the same network chunk. Each boundary is the index * where a new chunk starts. */ export declare function inferChunkBoundaries(tokens: string[], timestamps: number[], sameChunkThreshold?: number): number[]; /** Compute chunk sizes from boundaries. */ export declare function computeChunkSizes(boundaries: number[], totalTokens: number): number[]; /** * Detect burst patterns in the token stream. * * A "burst" is a sequence of tokens where each inter-token interval is * below `mean_interval * 0.5`. A "pause" is a gap above this threshold. * Different models produce different burst patterns due to their KV cache, * batching, and attention mechanisms. */ export declare function detectBursts(intervals: number[], burstThresholdMultiplier?: number): BurstPattern[]; /** Summary statistics for a captured token stream. */ export interface StreamStats { tokenCount: number; chunkCount: number; burstCount: number; avgChunkSize: number; avgBurstLength: number; burstFraction: number; hasLogprobs: boolean; meanInterval: number; stdInterval: number; medianInterval: number; } /** Compute summary statistics from a capture. */ export declare function computeStreamStats(capture: TokenStreamCapture): StreamStats; //# sourceMappingURL=stream-capture.d.ts.map