import { type NormalizedError } from '@pellux/goodvibes-sdk/platform/utils/error-display';
import type { RuntimeEventBus, RuntimeEventDomain } from '../events/index.js';
import type { RuntimeStore } from '../store/index.js';
import type { TelemetryDomainState } from '@pellux/goodvibes-sdk/platform/runtime/store/domains/telemetry';
import type { ReadableSpan } from '@pellux/goodvibes-sdk/platform/runtime/telemetry/types';
export type TelemetrySeverity = 'debug' | 'info' | 'warn' | 'error';
export type TelemetryViewMode = 'safe' | 'raw';
export interface TelemetryFilter {
    readonly limit?: number;
    readonly since?: number;
    readonly until?: number;
    readonly domains?: readonly RuntimeEventDomain[];
    readonly eventTypes?: readonly string[];
    readonly severity?: TelemetrySeverity;
    readonly traceId?: string;
    readonly sessionId?: string;
    readonly turnId?: string;
    readonly agentId?: string;
    readonly taskId?: string;
    readonly cursor?: string;
    readonly view?: TelemetryViewMode;
}
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;
    readonly agentId?: string;
    readonly taskId?: string;
    readonly source: string;
    readonly message: string;
    readonly payload: unknown;
    readonly attributes: Record<string, unknown>;
    readonly error?: NormalizedError;
}
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'];
    readonly sessionCorrelationId: string;
    readonly currentTurnCorrelationId?: string;
    readonly dbAvailable: boolean;
    readonly dbPath?: string;
    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;
    readonly nextCursor?: string;
}
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;
    readonly errorLimit?: number;
    readonly spanLimit?: number;
}
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;
    private applyRecordFilter;
    private applySpanFilter;
    private recordMatches;
    private resolveCursor;
    private resolveSpanCursor;
    private notify;
}
export {};
//# sourceMappingURL=api.d.ts.map