/** * Local telemetry sink that emits structured events to the TUI log panel. * * Implements `TelemetryProvider` so it can be injected into `createAgentSession` * without any HTTP or OpenTelemetry overhead. Instead of exporting spans over a * network, it converts each lifecycle event (trace start/end, span start/end, * generation, metric) into a {@link TelemetryLogEntry} and forwards it via the * `onEvent` callback. The REPL uses this to optionally display timing and token * cost inline when `--verbose` is active. * * @docLink packages/tui/concepts#tui-telemetry-provider */ import type { Attributes, GenerationEvent, Span, SpanKind, SpanOptions, SpanResult, TelemetryProvider, Trace, TraceOptions } from "@skaile/workspaces/telemetry"; /** * A structured telemetry event emitted by {@link TuiTelemetryProvider}. * * Discriminated union over `kind`. The TUI renders a subset of these (generation, * span_end for tool/turn, trace lifecycle) and suppresses the rest. Used as input * to {@link formatTelemetryEntry} and {@link renderLog}. * * @docLink packages/tui/concepts#tui-telemetry-provider */ export type TelemetryLogEntry = { kind: "trace_start"; traceId: string; name: string; traceKind: string; } | { kind: "trace_end"; traceId: string; status: string; durationMs: number; } | { kind: "span_start"; spanId: string; name: string; spanKind: SpanKind; } | { kind: "span_end"; spanId: string; name: string; spanKind: SpanKind; status: string; durationMs: number; } | { kind: "generation"; model: string; inputTokens: number; outputTokens: number; costUsd: number; durationMs: number; } | { kind: "metric"; name: string; value: number; }; export declare class TuiTelemetryProvider implements TelemetryProvider { private readonly onEvent; private readonly spans; private readonly traces; constructor(onEvent: (entry: TelemetryLogEntry) => void); startTrace(opts: TraceOptions): Trace; endTrace(trace: Trace, result?: SpanResult): void; startSpan(parent: Trace | Span, opts: SpanOptions): Span; endSpan(span: Span, result?: SpanResult): void; addEvent(_span: Span, _name: string, _attrs?: Attributes): void; logGeneration(_span: Span, generation: GenerationEvent): void; recordMetric(name: string, value: number, _tags?: Record): void; flush(): Promise; shutdown(): Promise; } /** * Format a {@link TelemetryLogEntry} into a human-readable string for the log panel. * * Produces plain (no ANSI) strings suitable for structured logging or non-terminal * output. The format mirrors {@link renderLog} but without colour codes: generation * entries include model, token counts, cost, and duration; span_end entries for * `tool_call` and `agent_turn` kinds include name, status, and duration; trace * lifecycle entries include name and elapsed time. Returns `null` for entry kinds * that should not be displayed. * * @param entry - The structured telemetry event to format. * @returns Human-readable string, or `null` if the entry should be suppressed. * * @docLink packages/tui/concepts#tui-telemetry-provider */ export declare function formatTelemetryEntry(entry: TelemetryLogEntry): string | null; //# sourceMappingURL=telemetry.d.ts.map