import { type NormalizedError } from '../../utils/error-display.js';
import type { RuntimeEventBus, RuntimeEventDomain } from '../events/index.js';
import type { RuntimeStore } from '../store/index.js';
import type { TelemetryDomainState } from '../store/domains/telemetry.js';
import type { ReadableSpan } from './types.js';
export type TelemetrySeverity = 'debug' | 'info' | 'warn' | 'error';
export type TelemetryViewMode = 'safe' | 'raw';
export interface TelemetryFilter {
    readonly limit?: number | undefined;
    readonly since?: number | undefined;
    readonly until?: number | undefined;
    readonly domains?: readonly RuntimeEventDomain[] | undefined;
    readonly eventTypes?: readonly string[] | undefined;
    readonly severity?: TelemetrySeverity | undefined;
    readonly traceId?: string | undefined;
    readonly sessionId?: string | undefined;
    readonly turnId?: string | undefined;
    readonly agentId?: string | undefined;
    readonly taskId?: string | undefined;
    readonly cursor?: string | undefined;
    readonly view?: TelemetryViewMode | undefined;
}
export interface TelemetryRecord {
    readonly id: string;
    readonly domain: RuntimeEventDomain;
    readonly type: string;
    readonly timestamp: number;
    readonly severity: TelemetrySeverity;
    readonly traceId: string;
    readonly sessionId: string;
    readonly turnId?: string | undefined;
    readonly agentId?: string | undefined;
    readonly taskId?: string | undefined;
    readonly source: string;
    readonly message: string;
    readonly payload: unknown;
    readonly attributes: Record<string, unknown>;
    readonly error?: NormalizedError | undefined;
}
export interface TelemetryCapabilities {
    readonly signals: {
        readonly events: true;
        readonly errors: true;
        readonly metrics: true;
        readonly traces: boolean;
    };
    readonly encodings: {
        readonly json: true;
        readonly sse: true;
        readonly otlpJson: {
            readonly traces: true;
            readonly metrics: true;
            readonly logs: true;
        };
    };
}
export interface TelemetryAggregates {
    readonly totalEvents: number;
    readonly totalErrors: number;
    readonly totalWarnings: number;
    readonly totalSpans: number;
    readonly byDomain: Readonly<Record<string, number>>;
    readonly byEventType: Readonly<Record<string, number>>;
    readonly errorsByCategory: Readonly<Record<string, number>>;
}
export interface TelemetryRuntimeSnapshot {
    readonly sessionId: string;
    readonly sessionStatus: string;
    readonly traceContext?: TelemetryDomainState['traceContext'] | undefined;
    readonly sessionCorrelationId: string;
    readonly currentTurnCorrelationId?: string | undefined;
    readonly dbAvailable: boolean;
    readonly dbPath?: string | undefined;
    readonly tasks: {
        readonly total: number;
        readonly queued: number;
        readonly running: number;
        readonly blocked: number;
    };
    readonly agents: {
        readonly total: number;
        readonly active: number;
    };
    readonly approvals: {
        readonly pending: number;
    };
}
export interface TelemetrySnapshot {
    readonly version: 1;
    readonly view: TelemetryViewMode;
    readonly rawAccessible: boolean;
    readonly generatedAt: number;
    readonly service: {
        readonly name: string;
        readonly version: string;
    };
    readonly capabilities: TelemetryCapabilities;
    readonly runtime: TelemetryRuntimeSnapshot;
    readonly sessionMetrics: TelemetryDomainState['sessionMetrics'];
    readonly aggregates: TelemetryAggregates;
    readonly recent: {
        readonly events: TelemetryListResponse<TelemetryRecord>;
        readonly errors: TelemetryListResponse<TelemetryRecord>;
        readonly spans: TelemetryListResponse<ReadableSpan>;
    };
}
export interface TelemetryPageInfo {
    readonly limit: number;
    readonly returned: number;
    readonly hasMore: boolean;
    readonly cursor?: string | undefined;
    readonly nextCursor?: string | undefined;
}
export interface TelemetryListResponse<T> {
    readonly version: 1;
    readonly view: TelemetryViewMode;
    readonly rawAccessible: boolean;
    readonly items: readonly T[];
    readonly pageInfo: TelemetryPageInfo;
}
interface TelemetryApiServiceOptions {
    readonly runtimeBus: RuntimeEventBus;
    readonly runtimeStore: RuntimeStore;
    readonly eventLimit?: number | undefined;
    readonly errorLimit?: number | undefined;
    readonly spanLimit?: number | undefined;
}
export declare class TelemetryApiService {
    private readonly runtimeBus;
    private readonly runtimeStore;
    private readonly eventLimit;
    private readonly errorLimit;
    private readonly spanLimit;
    private readonly records;
    private readonly errors;
    private readonly spans;
    private readonly eventCountsByDomain;
    private readonly eventCountsByType;
    private readonly errorCountsByCategory;
    private readonly subscribers;
    private readonly unsubs;
    private readonly activeTurnSpans;
    private readonly activeTaskSpans;
    private readonly activeAgentSpans;
    private readonly activeToolSpans;
    private readonly turnSpanIds;
    private readonly taskSpanIds;
    private readonly agentSpanIds;
    private seq;
    constructor(options: TelemetryApiServiceOptions);
    dispose(): void;
    subscribe(listener: (record: TelemetryRecord) => void): () => void;
    getCapabilities(): TelemetryCapabilities;
    getSnapshot(filter?: TelemetryFilter, view?: TelemetryViewMode, rawAccessible?: boolean): TelemetrySnapshot;
    getAggregates(): TelemetryAggregates;
    listEvents(filter?: TelemetryFilter, view?: TelemetryViewMode): readonly TelemetryRecord[];
    listErrors(filter?: TelemetryFilter, view?: TelemetryViewMode): readonly TelemetryRecord[];
    listSpans(filter?: TelemetryFilter, view?: TelemetryViewMode): readonly ReadableSpan[];
    listEventPage(filter?: TelemetryFilter, view?: TelemetryViewMode, rawAccessible?: boolean): TelemetryListResponse<TelemetryRecord>;
    listErrorPage(filter?: TelemetryFilter, view?: TelemetryViewMode, rawAccessible?: boolean): TelemetryListResponse<TelemetryRecord>;
    listSpanPage(filter?: TelemetryFilter, view?: TelemetryViewMode, rawAccessible?: boolean): TelemetryListResponse<ReadableSpan>;
    createStream(request: Request, filter?: TelemetryFilter, view?: TelemetryViewMode, rawAccessible?: boolean): Response;
    buildOtlpTraceDocument(filter?: TelemetryFilter, view?: TelemetryViewMode): Record<string, unknown>;
    buildOtlpLogDocument(filter?: TelemetryFilter, view?: TelemetryViewMode): Record<string, unknown>;
    buildOtlpMetricDocument(): Record<string, unknown>;
    private subscribeAllDomains;
    private handleEnvelope;
    private captureSyntheticSpan;
    private completeSyntheticSpan;
    private buildSpanAttributes;
    /**
     * Implement TelemetryIngestSink.ingestLogs — delegates to ingestExternalLogs.
     * Satisfies the interface expected by DaemonHttpRouterContext.ingestSink.
     */
    ingestLogs(payload: Record<string, unknown>): void;
    /**
     * Implement TelemetryIngestSink.ingestTraces — delegates to ingestExternalTraces.
     */
    ingestTraces(payload: Record<string, unknown>): void;
    /**
     * Implement TelemetryIngestSink.ingestMetrics — delegates to ingestExternalMetrics.
     */
    ingestMetrics(payload: Record<string, unknown>): void;
    /**
     * Ingest an externally-received OTLP log payload into this service's event
     * buffer. Each entry in `resourceLogs[].scopeLogs[].logRecords[]` is mapped
     * to a TelemetryRecord and appended to `this.records` with domain 'telemetry'.
     * Records are bounded by eventLimit (default 500). Subscribers are notified.
     * Call is synchronous and never throws.
     */
    ingestExternalLogs(payload: Record<string, unknown>): void;
    /**
     * Ingest an externally-received OTLP trace payload into this service's span
     * buffer. Each entry in `resourceSpans[].scopeSpans[].spans[]` is mapped
     * to a ReadableSpan and appended to `this.spans`, bounded by spanLimit.
     */
    ingestExternalTraces(payload: Record<string, unknown>): void;
    /**
     * Ingest an externally-received OTLP metrics payload. Creates a synthetic
     * TelemetryRecord tagged 'OTLP_METRICS_INGEST' and appends it to the event
     * buffer so it is visible on GET /api/v1/telemetry/events.
     * Sentinel is only emitted when at least one metric datapoint is present.
     */
    ingestExternalMetrics(payload: Record<string, unknown>): void;
    private recordIngestedEvent;
    private notify;
}
export {};
//# sourceMappingURL=api.d.ts.map