// Main type declarations for @wengine-ai/llms

// Health store types
export interface ProviderHealthState {
  provider: string;
  model: string;
  status: 'closed' | 'open' | 'half-open';
  failureCount: number;
  successCount: number;
  lastFailureTime: number;
  lastProbeTime: number;
  lastError?: string;
}

export interface HealthPoolConfig {
  enabled?: boolean;
  failureThreshold?: number;
  probeIntervalMinutes?: number;
  halfOpenSuccessThreshold?: number;
}

export class ProviderHealthStore {
  constructor(config?: HealthPoolConfig);
  recordSuccess(provider: string, model: string): void;
  recordFailure(provider: string, model: string, error?: string): void;
  getState(provider: string, model: string): ProviderHealthState | undefined;
  isAvailable(provider: string, model: string): boolean;
  getPriority(provider: string, model: string): number;
  needsProbe(state: ProviderHealthState): boolean;
  markProbeAttempt(provider: string, model: string): void;
  clear(): void;
  getAllStates(): ProviderHealthState[];
  getFailPoolModels(): string[];
  getHalfOpenModels(): string[];
  stopProbeTimer(): void;
}

export declare function getHealthStore(config?: HealthPoolConfig): ProviderHealthStore;
export declare function resetHealthStore(): void;

// Core exports
export interface RouterScenarioType {
  'default': 'default';
  'background': 'background';
  'think': 'think';
  'longContext': 'longContext';
  'extendedContext': 'extendedContext';
  'webSearch': 'webSearch';
  'modelMapping': 'modelMapping';
  'image': 'image';
}

export interface RouterFallbackConfig {
  default?: string[];
  background?: string[];
  think?: string[];
  longContext?: string[];
  webSearch?: string[];
  modelMapping?: string[];
  image?: string[];
}

export class ConfigService {
  get<T>(key: string): T | undefined;
  getAll(): Record<string, any>;
}

export class ProviderService {
  getProvider(name: string): any | undefined;
}

export class TransformerService {
  getTransformersWithEndpoint(): Array<{ transformer: any }>;
}

export class TokenizerService {
  countTokens(request: any, config?: any): Promise<{ tokenCount: number }>;
}

export function router(req: any, reply: any, context: any): Promise<void>;
export function calculateTokenCount(messages: any[], system: any, tools: any[]): number;
export function searchProjectBySession(sessionId: string): Promise<string | null>;

// Session cache
export const sessionUsageCache: any;

// SSE utilities
export class SSEParserTransform {}
export class SSESerializerTransform {}
export function rewriteStream(stream: any, handler: any): any;