import type { MastraLanguageModel } from '../../../llm/model/shared.types.js';
import type { StreamInternal } from '../../../loop/types.js';
import type { Mastra } from '../../../mastra/index.js';
import type { MastraMemory } from '../../../memory/memory.js';
import type { ProcessorState, ErrorProcessorOrWorkflow, InputProcessorOrWorkflow, OutputProcessorOrWorkflow } from '../../../processors/index.js';
import type { CoreTool, RequireToolApproval, ToolApprovalContext } from '../../../tools/types.js';
import type { Workspace } from '../../../workspace/index.js';
import { MessageList } from '../../message-list/index.js';
import { SaveQueueManager } from '../../save-queue/index.js';
import type { SerializableDurableState, SerializableDurableOptions, SerializableModelConfig, SerializableModelListEntry, SerializableToolMetadata, DurableAgenticWorkflowInput, RegistryModelListEntry } from '../types.js';
/**
 * Runtime dependencies that need to be resolved at step execution time.
 * These cannot be serialized and must be recreated from available context.
 */
export interface ResolvedRuntimeDependencies {
    /** Reconstructed _internal object for compatibility with existing code */
    _internal: StreamInternal;
    /** Resolved tools with execute functions */
    tools: Record<string, CoreTool>;
    /** Resolved language model */
    model: MastraLanguageModel;
    /** Resolved model list for fallback support (actual model instances) */
    modelList?: RegistryModelListEntry[];
    /** Deserialized MessageList */
    messageList: MessageList;
    /** Memory instance (if available) */
    memory?: MastraMemory;
    /** SaveQueueManager for message persistence */
    saveQueueManager?: SaveQueueManager;
    /** Workspace for file/sandbox operations */
    workspace?: Workspace;
    /** Resolved input processors (rebuilt from the agent when the registry is empty) */
    inputProcessors?: InputProcessorOrWorkflow[];
    /** Uncombined input processors for processLLMRequest */
    llmRequestInputProcessors?: InputProcessorOrWorkflow[];
    /** Resolved output processors */
    outputProcessors?: OutputProcessorOrWorkflow[];
    /** Resolved error processors */
    errorProcessors?: ErrorProcessorOrWorkflow[];
    /** Processor state map */
    processorStates?: Map<string, ProcessorState>;
}
/**
 * Options for resolving runtime dependencies
 */
export interface ResolveRuntimeOptions {
    /** Mastra instance for accessing services */
    mastra?: Mastra;
    /** Run identifier */
    runId: string;
    /** Agent identifier */
    agentId: string;
    /** Workflow input containing serialized state */
    input: DurableAgenticWorkflowInput;
    /** Logger for debugging */
    logger?: {
        debug?: (...args: any[]) => void;
        error?: (...args: any[]) => void;
    };
}
/**
 * Thrown when the per-request processor pipeline cannot be rebuilt during
 * cross-process rehydration. Propagated (not swallowed) because continuing
 * without the rebuilt processors would silently drop skills / workspace
 * instructions — the exact failure mode this rebuild exists to fix.
 */
export declare class DurableProcessorRebuildError extends Error {
    constructor(agentId: string, cause: unknown);
}
/**
 * Resolve all runtime dependencies needed for durable step execution.
 *
 * This function reconstructs the non-serializable state needed to execute
 * agent steps from:
 * 1. The Mastra instance (for agent lookup, tools, model)
 * 2. The serialized workflow input (for MessageList, state)
 *
 * Unlike the registry-based approach, this reconstructs tools and model
 * from the agent registered with Mastra, making it truly durable across
 * process restarts.
 */
export declare function resolveRuntimeDependencies(options: ResolveRuntimeOptions): Promise<ResolvedRuntimeDependencies>;
/**
 * Tool + workspace state rebuilt for the durable tool-call step.
 */
export interface RebuiltRunTools {
    tools: Record<string, CoreTool>;
    workspace?: Workspace;
    memory?: MastraMemory;
    saveQueueManager?: SaveQueueManager;
}
/**
 * Rebuild the run's tools (and workspace/memory) from the agent registered on
 * the Mastra instance, then write them back into the per-process run registry.
 *
 * The durable tool-call step runs as a SEPARATE step from the LLM-execution
 * step and, on a cross-process engine (e.g. the @mastra/inngest connect()
 * worker), can execute in a different process than the one that prepared the
 * run. In that process `globalRunRegistry.get(runId)` is empty (or a minimal
 * placeholder), so per-request closure tools (workspace/skill tools:
 * `skill`, `skill_read`, `skill_search`, `mastra_workspace_*`) are absent and
 * the model's tool call rejects with `ToolNotFoundError`.
 *
 * The LLM step already rebuilds the full toolset via
 * `resolveRuntimeDependencies` → `getToolsForExecution`; this helper gives the
 * tool-call step the same rebuild so tool resolution is symmetric cross-process.
 * The writeback means the first unresolved tool call rebuilds once and later
 * calls in the same process hit the registry.
 *
 * Returns `undefined` when no Mastra instance is available or the agent can't
 * be resolved — callers fall back to their existing `ToolNotFoundError`.
 */
export declare function rebuildRunToolsFromMastra(options: {
    mastra?: Mastra;
    runId: string;
    agentId: string;
    state: SerializableDurableState;
    options?: SerializableDurableOptions;
    /** JSON-safe request-context snapshot from the workflow input (see preparation.ts). */
    requestContextEntries?: Record<string, unknown>;
    logger?: {
        debug?: (...args: any[]) => void;
    };
}): Promise<RebuiltRunTools | undefined>;
/**
 * Resolve the language model from serialized config.
 *
 * Note: This is a fallback when the model is not in the run registry.
 * The preferred approach is to store the actual model instance in the
 * run registry during preparation and retrieve it via runRegistry.getModel().
 *
 * This fallback returns a metadata-only stub that will fail the
 * isSupportedLanguageModel check with a descriptive error message.
 */
export declare function resolveModel(config: SerializableModelConfig, _mastra?: Mastra): MastraLanguageModel;
/**
 * Reconstruct the _internal (StreamInternal) object from available state
 */
export declare function resolveInternalState(options: {
    state: SerializableDurableState;
    memory?: MastraMemory;
    saveQueueManager?: SaveQueueManager;
    tools?: Record<string, CoreTool>;
}): StreamInternal;
/**
 * Resolve a single tool by name from Mastra's global tool registry
 */
export declare function resolveTool(toolName: string, mastra?: Mastra): CoreTool | undefined;
/**
 * Check if a tool requires human approval.
 *
 * Mirrors the non-durable precedence:
 *  - Function-form global `requireToolApproval` is evaluated per call with
 *    `(toolName, args, ...)`. Throwing defaults to "require approval" (safe).
 *  - Boolean global / tool-level `requireApproval` seed the decision.
 *  - A per-tool `needsApprovalFn` (e.g. skill tools) is authoritative when
 *    present and overrides the seed.
 *
 * In durable execution the function form lives on the run registry, not on
 * the serialized workflow input — pass the resolved value from the caller.
 */
export declare function toolRequiresApproval(tool: CoreTool, globalRequireApproval?: RequireToolApproval, args?: Record<string, unknown>, approvalContext?: Partial<ToolApprovalContext> & {
    toolName: string;
}): Promise<boolean>;
/**
 * Extract tool metadata needed for LLM from resolved tools
 * This is useful when we need to pass tool info to the model
 */
export declare function extractToolsForModel(tools: Record<string, CoreTool>, _toolsMetadata: SerializableToolMetadata[]): Record<string, CoreTool>;
/**
 * Resolve a language model from a serialized model config.
 *
 * This is used during durable execution to reconstruct models from
 * serialized configuration. It uses the originalConfig string (e.g., 'openai/gpt-4o')
 * to resolve the model through the standard model resolution pipeline.
 *
 * @param config The serialized model configuration
 * @param mastra Optional Mastra instance for custom gateways
 * @returns Resolved language model
 */
export declare function resolveModelFromConfig(config: SerializableModelConfig, mastra?: Mastra): Promise<MastraLanguageModel>;
/**
 * Resolve a model from a model list entry.
 *
 * @param entry The model list entry with config, maxRetries, enabled
 * @param mastra Optional Mastra instance
 * @returns Resolved language model
 */
export declare function resolveModelFromListEntry(entry: SerializableModelListEntry, mastra?: Mastra): Promise<MastraLanguageModel>;
//# sourceMappingURL=resolve-runtime.d.ts.map