/** * ThinkHive SDK v3.2 - Business Metrics API * * Industry-driven business metrics with historical tracking and external data support */ /** * Metric trend information */ export interface MetricTrend { direction: 'up' | 'down' | 'stable'; value: number; isPositive: boolean; } /** * Current metric status */ export type MetricStatus = 'ready' | 'insufficient_data' | 'awaiting_external' | 'stale'; /** * Current metric response from the API */ export interface CurrentMetricResponse { metricName: string; metricType: 'trace_calculated' | 'external'; value: number | null; valueFormatted: string; unit?: string; status: MetricStatus; statusMessage?: string; trend?: MetricTrend; traceCount?: number; minTraceThreshold?: number; progressPercent?: number; lastExternalUpdate?: string; } /** * Historical data point */ export interface MetricHistoryPoint { periodStart: string; periodEnd: string; value: number; valueFormatted?: string; source: string; traceCount?: number; } /** * Historical summary statistics */ export interface MetricHistorySummary { current: number | null; previous: number | null; changePercent: number | null; isPositive: boolean; dataPointCount: number; } /** * Full history response */ export interface MetricHistoryResponse { metricName: string; unit: string; higherIsBetter: boolean; dataPoints: MetricHistoryPoint[]; summary: MetricHistorySummary; } /** * Options for recording external metric values */ export interface RecordMetricOptions { metricName: string; value: number; unit?: string; periodStart: string | Date; periodEnd: string | Date; source?: string; sourceDetails?: Record; } /** * Response from recording a metric value */ export interface RecordMetricResponse { success: boolean; id: string; recordedAt: string; } /** * Business Metrics API client for industry-driven metrics with historical tracking */ export declare const businessMetrics: { /** * Get current metric value with status information * * @example * ```typescript * const metric = await businessMetrics.current('agent_123', 'Deflection Rate'); * console.log(`${metric.metricName}: ${metric.valueFormatted}`); * * if (metric.status === 'insufficient_data') { * console.log(`Need ${metric.minTraceThreshold - metric.traceCount} more traces`); * } * ``` */ current(agentId: string, metricName?: string): Promise; /** * Get historical metric data for graphing * * @example * ```typescript * const history = await businessMetrics.history('agent_123', 'Deflection Rate', { * startDate: new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), * endDate: new Date(), * granularity: 'daily', * }); * * console.log(`${history.dataPoints.length} data points`); * console.log(`Change: ${history.summary.changePercent}%`); * ``` */ history(agentId: string, metricName: string, options?: { startDate?: string | Date; endDate?: string | Date; granularity?: "hourly" | "daily" | "weekly" | "monthly"; }): Promise; /** * Record an external metric value * * Use this to ingest metrics from external data sources (CRM, surveys, billing, etc.) * * @example * ```typescript * // Record CSAT score from survey system * await businessMetrics.record('agent_123', { * metricName: 'CSAT/NPS', * value: 4.5, * unit: 'score', * periodStart: '2024-01-01T00:00:00Z', * periodEnd: '2024-01-07T23:59:59Z', * source: 'survey_system', * sourceDetails: { surveyId: 'survey_456', responseCount: 150 }, * }); * ``` */ record(agentId: string, options: RecordMetricOptions): Promise; /** * Batch record multiple external metric values * * @example * ```typescript * await businessMetrics.recordBatch('agent_123', [ * { metricName: 'CSAT/NPS', value: 4.5, ... }, * { metricName: 'Hours Saved', value: 120, ... }, * ]); * ``` */ recordBatch(agentId: string, metrics: RecordMetricOptions[]): Promise; }; /** * Check if a metric is ready to display */ export declare function isMetricReady(metric: CurrentMetricResponse): boolean; /** * Check if a metric needs more trace data */ export declare function needsMoreTraces(metric: CurrentMetricResponse): boolean; /** * Check if a metric is waiting for external data */ export declare function awaitingExternalData(metric: CurrentMetricResponse): boolean; /** * Check if metric data is stale */ export declare function isMetricStale(metric: CurrentMetricResponse): boolean; /** * Get human-readable status message */ export declare function getStatusMessage(metric: CurrentMetricResponse): string; /** * Calculate progress toward minimum trace threshold */ export declare function getTraceProgress(metric: CurrentMetricResponse): number; /** * Format metric value for display based on unit */ export declare function formatMetricValue(value: number, unit: string): string; /** * Get trend direction as emoji */ export declare function getTrendEmoji(trend: MetricTrend): string;