import { ReadableSpan, ReadableSpan as ReadableSpan$1, Span, SpanProcessor } from "@opentelemetry/sdk-trace-base"; import { Context } from "@opentelemetry/api"; import { SpanKind, SpanStatusCode } from "autotel"; import { PrettyConsoleExporter, PrettyConsoleExporterOptions } from "autotel/exporters"; //#region src/streaming-processor.d.ts /** * Span processor that wraps another processor and emits spans to subscribers * * This processor forwards all span operations to a wrapped processor while * also emitting completed spans to registered subscribers. This enables * real-time streaming of spans to terminal dashboards, loggers, or other * consumers without interfering with normal span processing. */ declare class StreamingSpanProcessor implements SpanProcessor { private wrappedProcessor; private subscribers; /** * Create a new streaming span processor * * @param wrappedProcessor - The processor to wrap and forward spans to. * If null, spans are only emitted to subscribers (no forwarding). */ constructor(wrappedProcessor?: SpanProcessor | null); onStart(span: Span, parentContext: Context): void; onEnd(span: ReadableSpan$1): void; /** * Subscribe to span end events * * @param callback - Function called when a span ends * @returns Unsubscribe function * * @example * ```typescript * const unsubscribe = processor.subscribe((span) => { * console.log('Span ended:', span.name) * }) * * // Later, unsubscribe * unsubscribe() * ``` */ subscribe(callback: (span: ReadableSpan$1) => void): () => void; forceFlush(): Promise; shutdown(): Promise; } //#endregion //#region src/span-stream.d.ts /** Span event (e.g. exception, log annotation) */ interface SpanEvent { /** Event name */ name: string; /** Time in milliseconds since epoch */ timeMs: number; /** Event attributes */ attributes?: Record; } /** Span link (cross-trace reference) */ interface SpanLink { /** Linked trace ID */ traceId: string; /** Linked span ID */ spanId: string; /** Link attributes */ attributes?: Record; } /** * Span event format for terminal dashboard consumption */ interface TerminalSpanEvent { /** Span name */ name: string; /** Span ID (hex string) */ spanId: string; /** Trace ID (hex string) */ traceId: string; /** Parent span ID (hex string, optional) */ parentSpanId?: string; /** Start time in milliseconds since epoch */ startTime: number; /** End time in milliseconds since epoch */ endTime: number; /** Duration in milliseconds */ durationMs: number; /** Span status */ status: 'OK' | 'ERROR' | 'UNSET'; /** Span kind (INTERNAL, SERVER, CLIENT, etc.) */ kind?: string; /** Span attributes */ attributes?: Record; /** Span events (exceptions, annotations) */ events?: SpanEvent[]; /** Span links (cross-trace references) */ links?: SpanLink[]; } /** * Stream interface for terminal dashboard */ interface TerminalSpanStream { /** * Subscribe to span end events * * @param callback - Called when a span ends * @returns Unsubscribe function */ onSpanEnd(callback: (event: TerminalSpanEvent) => void): () => void; } /** * Create a terminal span stream from a streaming processor * * @param processor - The streaming span processor to subscribe to * @returns Terminal span stream interface * * @example * ```typescript * import { StreamingSpanProcessor } from 'autotel-terminal' * import { createTerminalSpanStream } from 'autotel-terminal' * * const processor = new StreamingSpanProcessor(baseProcessor) * const stream = createTerminalSpanStream(processor) * * stream.onSpanEnd((event) => { * console.log('Span:', event.name, event.durationMs + 'ms') * }) * ``` */ declare function createTerminalSpanStream(processor: StreamingSpanProcessor): TerminalSpanStream; //#endregion //#region src/ai/types.d.ts type AIProviderType = 'ollama' | 'openai' | 'openai-compatible'; type AIConfig = { provider: AIProviderType; model: string; apiKey?: string; baseUrl?: string; }; //#endregion //#region src/lib/log-model.d.ts /** * Log model utilities - pure logic for log grouping, filtering, and timelines. */ type LogLevel = 'debug' | 'info' | 'warn' | 'error'; /** * Log event format for terminal dashboard consumption. * Designed to align with Autotel canonical log lines / request-logger output. */ interface TerminalLogEvent { /** Log timestamp in milliseconds since epoch */ time: number; /** Log level */ level: LogLevel; /** Short message */ message: string; /** Optional trace correlation */ traceId?: string; /** Optional span correlation */ spanId?: string; /** Structured attributes / fields */ attributes?: Record; } //#endregion //#region src/log-stream.d.ts /** * Stream interface for terminal log events. */ interface TerminalLogStream { /** * Subscribe to log events. * * @param callback - Called when a log event is emitted * @returns Unsubscribe function */ onLog(callback: (event: TerminalLogEvent) => void): () => void; } /** * Internal in-memory implementation used for the global log stream. */ declare class InMemoryTerminalLogStream implements TerminalLogStream { private subscribers; onLog(callback: (event: TerminalLogEvent) => void): () => void; emit(event: TerminalLogEvent): void; } /** * Get or create the global terminal log stream. * * This is intended to be used from Autotel canonical log line drains * or request logger hooks: * * ```ts * import { getTerminalLogStream } from 'autotel-terminal'; * * const logStream = getTerminalLogStream(); * logStream.emit({ * time: Date.now(), * level: 'info', * message: 'request completed', * traceId, * spanId, * attributes: { route: '/users/:id', status: 200 }, * }); * ``` */ declare function getTerminalLogStream(): InMemoryTerminalLogStream; //#endregion //#region src/index.d.ts /** * Terminal dashboard options */ interface TerminalOptions { /** * Dashboard title * @default 'Autotel Trace Inspector' */ title?: string; /** * Show statistics bar (span count, error rate, avg duration) * @default true */ showStats?: boolean; /** * Maximum number of spans to display * @default 100 */ maxSpans?: number; /** * Enable colors (auto-detect by default) * @default true if TTY */ colors?: boolean; /** * AI assistant configuration. Auto-detects Ollama/OpenAI if not provided. */ ai?: Partial; } /** * Render the terminal dashboard * * Automatically wires up a streaming processor from the current tracer provider * if no stream is provided. Otherwise uses the provided stream. * * @param options - Dashboard configuration options * @param stream - Optional manual stream (for advanced use cases) * * @example Auto-wire (recommended) * ```typescript * import { init } from 'autotel' * import { renderTerminal } from 'autotel-terminal' * * init({ service: 'my-app' }) * renderTerminal() // Automatically creates stream from current tracer provider * ``` * * @example Manual stream * ```typescript * import { StreamingSpanProcessor } from 'autotel-terminal' * import { createTerminalSpanStream } from 'autotel-terminal' * * const processor = new StreamingSpanProcessor(baseProcessor) * const stream = createTerminalSpanStream(processor) * renderTerminal({}, stream) * ``` */ declare function renderTerminal(options?: TerminalOptions, stream?: TerminalSpanStream): void; //#endregion export { PrettyConsoleExporter, type PrettyConsoleExporterOptions, type ReadableSpan, type SpanEvent, SpanKind, type SpanLink, SpanStatusCode, StreamingSpanProcessor, type TerminalLogEvent, type TerminalLogStream, TerminalOptions, type TerminalSpanEvent, type TerminalSpanStream, createTerminalSpanStream, getTerminalLogStream, renderTerminal }; //# sourceMappingURL=index.d.cts.map