import type { Elysia, SingletonBase } from 'elysia';
import type { ReadableStream } from 'node:stream/web';
import type { Backend } from './index';
export type HumanReadableUnit = number | string;
type NormalizeKeys = 'max_body_size' | 'session_timeout' | 'max_size_bytes';
export type DeepNormalize<T> = T extends object ? {
    [K in keyof T]: K extends NormalizeKeys ? number : DeepNormalize<T[K]>;
} : T;
export type HumanReadableServerConfig = {
    id?: string;
    name?: string;
    port?: number;
    log_level?: 'debug' | 'info' | 'warn' | 'error';
    max_body_size?: HumanReadableUnit;
    session_timeout?: HumanReadableUnit;
    temp_file_dir?: string;
};
export type SessionCacheConfig = {
    enabled?: boolean;
    max_size_bytes?: HumanReadableUnit;
    max_entries?: number;
};
export type RuntimeConfig = {
    cache_dir?: string;
    huggingface_token?: string;
    session_cache?: SessionCacheConfig;
} & Record<string, any>;
export type GeneratorType = 'ggml-llm' | 'ggml-stt' | 'mlx-llm' | 'onnx-stt' | 'onnx-tts';
export type GeneratorConfig = {
    type: GeneratorType;
} & Record<string, any>;
export type GlobalConfig = {
    runtime?: RuntimeConfig;
    openai_compat?: {
        enabled?: boolean;
        cors_allowed_origins?: string | string[];
    };
    anthropic_messages?: {
        enabled?: boolean;
        cors_allowed_origins?: string | string[];
    };
} & Record<string, any>;
export type AutodiscoverConfig = {
    udp: {
        port?: number;
        announcements: {
            enabled: boolean;
            interval?: number;
        };
        requests: {
            enabled: boolean;
            responseDelay?: number;
        };
    };
    http: {
        enabled: boolean;
        path?: string;
        cors?: boolean;
    };
    mdns?: {
        enabled: boolean;
    };
};
export type HumanReadableConfig = {
    autodiscover?: AutodiscoverConfig | boolean;
    server?: HumanReadableServerConfig;
    generators?: GeneratorConfig[];
} & GlobalConfig;
export type ServerConfig = {
    id: string;
    name: string;
    port: number;
    log_level?: 'debug' | 'info' | 'warn' | 'error';
    max_body_size: number;
    session_timeout: number;
    temp_file_dir: string;
};
export type Config = {
    autodiscover: AutodiscoverConfig | null;
    server: ServerConfig;
    global: GlobalConfig;
    generators: GeneratorConfig[];
};
export type GeneratorInfo = {
    type: GeneratorType;
    /** Performance score 0–100 from buttress-hardware-guardrails. */
    score?: number;
    /** Whether the host has an accelerator (GPU/Metal/etc) for this backend. */
    hasGpu?: boolean;
    /** Usable memory in bytes for this backend (GPU when present, else CPU). */
    usableBytes?: number;
} & Record<string, any>;
export type ServerInfo = {
    id: string;
    name: string;
    version: string;
    address: string;
    addresses?: string[];
    port: number;
    url: string;
    generators: GeneratorInfo[];
    authentication: {
        required: boolean;
        type: string;
        /** Issuer key id (when type === 'workspace-jwt'). */
        kid?: string;
        /** True when buttress is paired with a workspace. */
        bound?: boolean;
    };
    /** Workspace identity (only present when paired). */
    workspace?: {
        id: string;
        name?: string;
    };
};
export type EventStream = {
    event: string;
    data: any;
};
export type StreamReaderEntry = {
    reader: ReadableStreamDefaultReader<EventStream>;
    peerId: string;
};
export type Session = {
    streams: Map<string, ReadableStream<EventStream>>;
    streamReaders: Map<string, StreamReaderEntry>;
    generators: Set<string>;
    fileManager: import('./utils/SessionFileManager').SessionFileManager;
    initializedContexts: Set<string>;
    timeout: ReturnType<typeof setTimeout> | null;
    identity?: import('./utils/buttressAuth').VerifiedIdentity | null;
    ready?: Promise<boolean>;
    currentPeerId?: string | null;
};
export type State = {
    serverInfo: ServerInfo;
    backend: Backend;
    config: Config;
    sessions: Map<string, Session>;
    workspaceState: import('./utils/workspaceState').WorkspaceState;
};
type ButtressSingleton = SingletonBase & {
    store: State;
};
export type ButtressApp = Elysia<any, ButtressSingleton, any, any, any, any, any>;
export type MethodReturnType = string | object | number | boolean | null | ReadableStream<EventStream>;
export type ServiceContext = State & {
    peerId: string;
    session: Session;
};
export type ServiceMethodHandler<InputType = any, OutputType = any> = (ctx: ServiceContext, property: InputType) => OutputType | Promise<OutputType>;
export interface ServiceHandler {
    [method: string]: ServiceMethodHandler;
}
export type Expand<T> = T extends object ? {
    [K in keyof T]: Expand<T[K]>;
} : T;
export {};
