llm-credit-sdk
Version:
SDK for estimating and reconciling LLM token costs using a credit system.
70 lines • 2.14 kB
TypeScript
import { DashboardSyncConfig, ReconciliationLog, SDKConfig } from './types';
declare global {
const EventSource: {
new (url: string, eventSourceInitDict?: any): EventSource;
readonly CONNECTING: number;
readonly OPEN: number;
readonly CLOSED: number;
};
interface EventSource extends EventTarget {
readonly readyState: number;
onopen: ((event: Event) => void) | null;
onmessage: ((event: MessageEvent) => void) | null;
onerror: ((event: Event) => void) | null;
close(): void;
}
}
/**
* Dashboard client for communicating with the Tokenix Dashboard API
* Handles reconciliation log posting and real-time config subscriptions
*/
export declare class DashboardClient {
private config;
private configSubscription;
private pollingInterval;
private isSubscribed;
constructor(config: DashboardSyncConfig);
/**
* Validate and normalize the dashboard configuration
*/
private validateAndNormalizeConfig;
/**
* Post reconciliation log to dashboard
* Includes retry logic and graceful error handling
*/
postReconciliation(log: ReconciliationLog): Promise<void>;
/**
* Subscribe to real-time config updates via SSE
* Falls back to polling if subscription fails
*/
subscribeToConfigUpdates(onUpdate: (config: SDKConfig) => void): void;
/**
* Unsubscribe from config updates and cleanup resources
*/
unsubscribe(): void;
/**
* Get current config from dashboard (used for polling fallback)
*/
getConfig(): Promise<SDKConfig>;
/**
* Try Server-Sent Events subscription for real-time updates
*/
private trySSESubscription;
/**
* Start polling for config updates as fallback
*/
private startPolling;
/**
* Retry logic with exponential backoff
*/
private retryRequest;
/**
* Log info messages (can be enhanced with proper logger)
*/
private logInfo;
/**
* Log error messages without throwing
*/
private logError;
}
//# sourceMappingURL=dashboardClient.d.ts.map