import type { ModelMessage } from 'ai';
import type { ApprovalRequest, PendingToolCall } from './hooks';
/** A decision made for a pending approval request. */
export type ApprovalDecision = {
    toolCallId: string;
    approved: true;
} | {
    toolCallId: string;
    approved: false;
    denialReason?: string;
};
/** A record of a single approval request and the decision made for it. */
export interface ApprovalHistoryEntry {
    toolCallId: string;
    toolName: string;
    input: Record<string, unknown>;
    /** The structured approval request metadata (message, etc.) */
    approval: ApprovalRequest;
    /** The decision that was applied */
    decision: ApprovalDecision;
}
/**
 * A path into the sub-agent tree, represented as an ordered array of agentId strings.
 *
 * An empty array refers to the root agent.
 * `['child-1']` refers to the direct sub-agent with id 'child-1'.
 * `['child-1', 'grandchild-a']` refers to the grandchild nested within child-1.
 */
export type AgentPath = string[];
/**
 * Plain serializable state token for agent.run().
 *
 * Captures everything needed to resume a conversation: messages, pending tool
 * calls (both approval-gated and stopped), and accumulated approval history.
 *
 * Designed to survive JSON.stringify → store → JSON.parse → pass to agent.run().
 */
export interface AgentState {
    messages: ModelMessage[];
    /** Tool calls that are pending (awaiting approval or stopped by ctx.stop()). */
    pendingToolCalls?: PendingToolCall[];
    /** Approval history accumulated across runs. */
    approvalHistory?: ApprovalHistoryEntry[];
    /** Persistent state for stateful tools, keyed by each tool's stateKey. */
    toolState?: Record<string, unknown>;
    /**
     * States for active sub-agents, keyed by agentId.
     * Each value is a nested AgentState capturing the sub-agent's conversation.
     */
    subAgents?: Record<string, AgentState>;
    /** Estimated tokens in context window after the most recent streamText call (input + output). */
    contextWindowTokens?: number;
}
/**
 * Create an initial AgentState from a message array.
 *
 * @example
 * ```ts
 * const result = await agent.run({ state: startState([userMessage('do stuff')]) }).result
 * ```
 */
export declare function startState(messages: ModelMessage[], toolState?: Record<string, unknown>): AgentState;
/**
 * Sanitize AgentState for persistence by stripping provider-specific fields
 * that are only valid within a single API session.
 *
 * This prevents errors like "Item with id 'xxx' not found. Items are not persisted
 * when `store` is set to false." when resuming sessions with OpenAI/Codex providers.
 *
 * Call this before saving state to the database.
 *
 * @example
 * ```ts
 * const result = await agent.run({ state }).result
 * const sanitized = sanitizeStateForPersistence(result.state)
 * await saveState(sessionId, sanitized)
 * ```
 */
export declare function sanitizeStateForPersistence(state: AgentState): AgentState;
/**
 * Traverse the sub-agent tree to find the AgentState at the given path.
 *
 * - Empty path (`[]`) returns the root state itself.
 * - Each element of path is an agentId key in `state.subAgents`.
 * - Returns `undefined` if any segment is missing.
 *
 * @example
 * ```ts
 * const child = getAgentState(rootState, ['worker-1'])
 * const grandchild = getAgentState(rootState, ['worker-1', 'subworker-a'])
 * ```
 */
export declare function getAgentState(state: AgentState, path: AgentPath): AgentState | undefined;
/**
 * Collect all pending approval entries across the entire sub-agent tree, annotated with their path.
 *
 * Returns an array of `{ path, pending }` pairs where:
 * - `path` is the AgentPath to the agent that has this pending entry
 * - `pending` is the PendingToolCall (only `type: 'approval'` entries — stopped/subAgent are excluded)
 *
 * Traverses depth-first: root pending entries first, then sub-agent entries.
 *
 * @example
 * ```ts
 * const allPending = getAllPendingApprovals(rootState)
 * for (const { path, pending } of allPending) {
 *   console.log(path, pending.toolCallId)
 * }
 * ```
 */
export declare function getAllPendingApprovals(state: AgentState): Array<{
    path: AgentPath;
    pending: PendingToolCall;
}>;
/**
 * Apply approval decisions to pending tool calls in state. Supports partial
 * decisions — you can approve/deny 1 of 3 pending, and the other 2 stay in
 * `pendingToolCalls`.
 *
 * Behavior per pending tool call:
 * - Matched + approved: entry removed from `pendingToolCalls`, recorded in `approvalHistory`
 *   (the loop will auto-execute the tool call on resume)
 * - Matched + denied: denial tool-result message injected into `messages`, entry
 *   removed from `pendingToolCalls`, recorded in `approvalHistory`
 * - Unmatched (no decision): stays in `pendingToolCalls`
 * - `type: 'stopped'` entries: untouched — not approval-gated
 * - `type: 'subAgent'` entries: unmatched decisions are passed down recursively
 *   into each `subAgents` entry
 *
 * Returns a new AgentState (immutable).
 *
 * @example
 * ```ts
 * const result2 = await agent.run({
 *   state: withApprovals(result1.state, [{ toolCallId: id, approved: true }]),
 * }).result
 * ```
 */
export declare function withApprovals(state: AgentState, decisions: ApprovalDecision[]): AgentState;
//# sourceMappingURL=state.d.ts.map