import type { Logger } from "../logger";
import type { Character } from "./agent";
import type { Action, ActionResult, Evaluator, HandlerCallback, PreEvaluatorResult, Provider } from "./components";
import type { IDatabaseAdapter } from "./database";
import type { Entity, Room, World } from "./environment";
import type { EventHandler, EventPayload, EventPayloadMap } from "./events";
import type { Memory, MemoryMetadata } from "./memory";
import type { IMessageService } from "./message-service";
import type { SendHandlerFunction, TargetInfo } from "./messaging";
import type { GenerateTextOptions, GenerateTextParams, GenerateTextResult, ModelParamsMap, ModelResultMap, ModelTypeName, TextGenerationModelType } from "./model";
import type { Plugin, Route, RuntimeEventStorage, ServiceClass } from "./plugin";
import type { ChannelType, Content, UUID } from "./primitives";
import type { JsonValue } from "./proto.js";
import type { Service, ServiceTypeName } from "./service";
import type { State } from "./state";
import type { TaskWorker } from "./task";
import type { ToolPolicyConfig, ToolProfileId } from "./tools";
/**
 * Represents the core runtime environment for an agent.
 * Defines methods for database interaction, plugin management, event handling,
 * state composition, model usage, and task management.
 */
export interface IAgentRuntime extends IDatabaseAdapter<object> {
    agentId: UUID;
    character: Character;
    enableAutonomy: boolean;
    initPromise: Promise<void>;
    messageService: IMessageService | null;
    providers: Provider[];
    actions: Action[];
    evaluators: Evaluator[];
    plugins: Plugin[];
    services: Map<ServiceTypeName, Service[]>;
    events: RuntimeEventStorage;
    fetch?: typeof fetch | null;
    routes: Route[];
    logger: Logger;
    stateCache: Map<string, State>;
    logLevelOverrides: Map<string, string>;
    /** Whether the runtime is operating in sandbox mode. Default: false. */
    sandboxMode?: boolean;
    /** Token manager for sandbox secret obfuscation. Undefined/null when sandbox mode is off. */
    sandboxTokenManager?: import("../security/sandbox-token-manager.js").SandboxTokenManager | null;
    registerPlugin(plugin: Plugin): Promise<void>;
    initialize(options?: {
        skipMigrations?: boolean;
    }): Promise<void>;
    /** Get the underlying database connection. Type depends on the adapter implementation. */
    getConnection(): Promise<object>;
    getService<T extends Service>(service: ServiceTypeName | string): T | null;
    getServicesByType<T extends Service>(service: ServiceTypeName | string): T[];
    getAllServices(): Map<ServiceTypeName, Service[]>;
    registerService(service: ServiceClass): Promise<void>;
    getServiceLoadPromise(serviceType: ServiceTypeName): Promise<Service>;
    getRegisteredServiceTypes(): ServiceTypeName[];
    hasService(serviceType: ServiceTypeName | string): boolean;
    registerDatabaseAdapter(adapter: IDatabaseAdapter): void;
    setSetting(key: string, value: string | boolean | null, secret?: boolean): void;
    getSetting(key: string): string | boolean | number | null;
    getConversationLength(): number;
    /**
     * Check if action planning mode is enabled.
     *
     * When enabled (default), the agent can plan and execute multiple actions per response.
     * When disabled, the agent executes only a single action per response - a performance
     * optimization useful for game situations where state updates with every action.
     *
     * Priority: constructor option > character setting ACTION_PLANNING > default (true)
     */
    isActionPlanningEnabled(): boolean;
    /**
     * Get the LLM mode for model selection override.
     *
     * - `DEFAULT`: Use the model type specified in the useModel call (no override)
     * - `SMALL`: Override all text generation model calls to use TEXT_SMALL
     * - `LARGE`: Override all text generation model calls to use TEXT_LARGE
     *
     * This is useful for cost optimization (force SMALL) or quality (force LARGE).
     *
     * Priority: constructor option > character setting LLM_MODE > default (DEFAULT)
     */
    getLLMMode(): import("./model").LLMModeType;
    /**
     * Check if the shouldRespond evaluation is enabled.
     *
     * When enabled (default: true), the agent evaluates whether to respond to each message.
     * When disabled, the agent always responds (ChatGPT mode) - useful for direct chat interfaces.
     *
     * Priority: constructor option > character setting CHECK_SHOULD_RESPOND > default (true)
     */
    isCheckShouldRespondEnabled(): boolean;
    processActions(message: Memory, responses: Memory[], state?: State, callback?: HandlerCallback, options?: {
        onStreamChunk?: (chunk: string, messageId?: string) => Promise<void>;
    }): Promise<void>;
    getActionResults(messageId: UUID): ActionResult[];
    evaluate(message: Memory, state?: State, didRespond?: boolean, callback?: HandlerCallback, responses?: Memory[]): Promise<Evaluator[] | null>;
    /**
     * Run pre-phase evaluators on a message before memory storage.
     * Pre-evaluators act as security gates — they can block the message
     * entirely or rewrite it (e.g. redact credentials).
     *
     * @param message - The incoming message to evaluate
     * @param state - Optional state context
     * @returns A merged PreEvaluatorResult
     */
    evaluatePre(message: Memory, state?: State): Promise<PreEvaluatorResult>;
    registerProvider(provider: Provider): void;
    registerAction(action: Action): void;
    /**
     * Get all registered actions.
     */
    getAllActions(): Action[];
    /**
     * Get actions filtered by tool policy.
     *
     * @param context - Optional policy context for filtering
     * @returns Filtered actions based on policy
     */
    getFilteredActions(context?: {
        profile?: ToolProfileId;
        characterPolicy?: ToolPolicyConfig;
        channelPolicy?: ToolPolicyConfig;
        providerPolicy?: ToolPolicyConfig;
        worldPolicy?: ToolPolicyConfig;
        roomPolicy?: ToolPolicyConfig;
    }): Action[];
    /**
     * Check if a specific action is allowed by tool policy.
     *
     * @param actionName - The action name to check
     * @param context - Optional policy context
     * @returns Whether the action is allowed
     */
    isActionAllowed(actionName: string, context?: {
        profile?: ToolProfileId;
        characterPolicy?: ToolPolicyConfig;
        channelPolicy?: ToolPolicyConfig;
        providerPolicy?: ToolPolicyConfig;
        worldPolicy?: ToolPolicyConfig;
        roomPolicy?: ToolPolicyConfig;
    }): {
        allowed: boolean;
        reason: string;
    };
    registerEvaluator(evaluator: Evaluator): void;
    ensureConnections(entities: Entity[], rooms: Room[], source: string, world: World): Promise<void>;
    ensureConnection({ entityId, roomId, metadata, userName, worldName, name, source, channelId, messageServerId, type, worldId, userId, }: {
        entityId: UUID;
        roomId: UUID;
        userName?: string;
        name?: string;
        worldName?: string;
        source?: string;
        channelId?: string;
        messageServerId?: UUID;
        type?: ChannelType | string;
        worldId: UUID;
        userId?: UUID;
        metadata?: Record<string, JsonValue>;
    }): Promise<void>;
    ensureParticipantInRoom(entityId: UUID, roomId: UUID): Promise<void>;
    ensureWorldExists(world: World): Promise<void>;
    ensureRoomExists(room: Room): Promise<void>;
    composeState(message: Memory, includeList?: string[], onlyInclude?: boolean, skipCache?: boolean, trajectoryPhase?: string): Promise<State>;
    /**
     * Use a model for inference with proper type inference based on parameters.
     *
     * For text generation models (TEXT_SMALL, TEXT_LARGE, TEXT_REASONING_*):
     * - Always returns `string`
     * - If streaming context is active, chunks are sent to callback automatically
     *
     * @example
     * ```typescript
     * // Simple usage - streaming happens automatically if context is active
     * const text = await runtime.useModel(ModelType.TEXT_LARGE, { prompt: "Hello" });
     * ```
     */
    useModel(modelType: TextGenerationModelType, params: GenerateTextParams, provider?: string): Promise<string>;
    useModel<T extends keyof ModelParamsMap, R = ModelResultMap[T]>(modelType: T, params: ModelParamsMap[T], provider?: string): Promise<R>;
    generateText(input: string, options?: GenerateTextOptions): Promise<GenerateTextResult>;
    /**
     * Register a model handler for a specific model type.
     * Model handlers process inference requests for specific model types.
     * @param modelType - The type of model to register
     * @param handler - The handler function that processes model requests
     * @param provider - The name of the provider (plugin) registering this handler
     * @param priority - Optional priority for handler selection (higher = preferred)
     */
    registerModel(modelType: ModelTypeName | string, handler: (runtime: IAgentRuntime, params: Record<string, JsonValue | object>) => Promise<JsonValue | object>, provider: string, priority?: number): void;
    /**
     * Get the registered model handler for a specific model type.
     * Returns the highest priority handler if multiple are registered.
     * @param modelType - The type of model to retrieve
     * @returns The model handler function or undefined if not found
     */
    getModel(modelType: ModelTypeName | string): ((runtime: IAgentRuntime, params: Record<string, JsonValue | object>) => Promise<JsonValue | object>) | undefined;
    /**
     * Get the registered model handler configuration for a specific model type.
     * Returns the highest priority handler configuration if multiple are registered.
     * @param modelType - The type of model to retrieve
     * @returns The model handler configuration or undefined if not found
     */
    getModelConfiguration(modelType: ModelTypeName | string): import("./model").ModelHandler | undefined;
    registerEvent<T extends keyof EventPayloadMap>(event: T, handler: EventHandler<T>): void;
    registerEvent<P extends EventPayload = EventPayload>(event: string, handler: (params: P) => Promise<void>): void;
    getEvent<T extends keyof EventPayloadMap>(event: T): EventHandler<T>[] | undefined;
    getEvent(event: string): ((params: EventPayload) => Promise<void>)[] | undefined;
    emitEvent<T extends keyof EventPayloadMap>(event: T | T[], params: EventPayloadMap[T]): Promise<void>;
    emitEvent(event: string | string[], params: EventPayload): Promise<void>;
    registerTaskWorker(taskHandler: TaskWorker): void;
    getTaskWorker(name: string): TaskWorker | undefined;
    /**
     * Dynamic prompt execution with state injection, schema-based parsing, and validation-aware streaming.
     *
     * WHY THIS EXISTS:
     * LLMs are powerful but unreliable for structured outputs. They can:
     * - Silently truncate output when hitting token limits
     * - Skip fields or produce malformed structures
     * - Hallucinate or ignore parts of the prompt
     *
     * This method addresses these issues by:
     * 1. Validation codes: Injects UUID codes the LLM must echo back. If codes match,
     *    we know the LLM actually read and followed the prompt.
     * 2. Streaming with safety: Enables streaming while detecting truncation.
     * 3. Performance tracking: Tracks success/failure rates per model+schema.
     *
     * VALIDATION LEVELS:
     * - Level 0 (Trusted): No codes. Maximum speed. Use for reliable models.
     * - Level 1 (Progressive): Per-field codes. Balance of safety + speed.
     * - Level 2 (First Checkpoint): Codes at start. Default. Catches ignored prompts.
     * - Level 3 (Full): Codes at start AND end. Maximum correctness.
     *
     * @param state - State object to inject into the prompt template
     * @param params - LLM parameters with a prompt template
     * @param schema - Array of field definitions for structured output
     * @param options - Configuration (modelSize, validation level, streaming callbacks, etc.)
     * @returns Parsed structured response object, or null on failure
     */
    dynamicPromptExecFromState(args: {
        state: State;
        params: Omit<GenerateTextParams, "prompt"> & {
            prompt: string | ((ctx: {
                state: State;
            }) => string);
        };
        schema: import("./state").SchemaRow[];
        options?: {
            key?: string;
            modelSize?: "small" | "large";
            model?: string;
            preferredEncapsulation?: "json" | "xml";
            forceFormat?: "json" | "xml";
            requiredFields?: string[];
            contextCheckLevel?: 0 | 1 | 2 | 3;
            maxRetries?: number;
            retryBackoff?: number | import("./state").RetryBackoffConfig;
            disableCache?: boolean;
            cacheTTL?: number;
            onStreamChunk?: (chunk: string, messageId?: string) => void | Promise<void>;
            onStreamEvent?: (event: import("./state").StreamEvent, messageId?: string) => void | Promise<void>;
            abortSignal?: AbortSignal;
        };
    }): Promise<Record<string, unknown> | null>;
    stop(): Promise<void>;
    addEmbeddingToMemory(memory: Memory): Promise<Memory>;
    /**
     * Queue a memory for async embedding generation.
     * This method is non-blocking and returns immediately.
     * The embedding will be generated asynchronously via event handlers.
     * @param memory The memory to generate embeddings for
     * @param priority Priority level for the embedding generation
     */
    queueEmbeddingGeneration(memory: Memory, priority?: "high" | "normal" | "low"): Promise<void>;
    getAllMemories(): Promise<Memory[]>;
    clearAllAgentMemories(): Promise<void>;
    updateMemory(memory: Partial<Memory> & {
        id: UUID;
        metadata?: MemoryMetadata;
    }): Promise<boolean>;
    createRunId(): UUID;
    startRun(roomId?: UUID): UUID;
    endRun(): void;
    getCurrentRunId(): UUID;
    getEntityById(entityId: UUID): Promise<Entity | null>;
    getRoom(roomId: UUID): Promise<Room | null>;
    createEntity(entity: Entity): Promise<boolean>;
    createRoom({ id, name, source, type, channelId, messageServerId, worldId, }: Room): Promise<UUID>;
    addParticipant(entityId: UUID, roomId: UUID): Promise<boolean>;
    getRooms(worldId: UUID): Promise<Room[]>;
    registerSendHandler(source: string, handler: SendHandlerFunction): void;
    sendMessageToTarget(target: TargetInfo, content: Content): Promise<void>;
    updateWorld(world: World): Promise<void>;
    /**
     * Redact secrets from a text string.
     * @param text - The text to redact secrets from
     * @returns The text with secrets redacted
     */
    redactSecrets(text: string): string;
}
//# sourceMappingURL=runtime.d.ts.map