import { Agent, AgentOutputType } from '../agent';
import { RunInputItem, RunItem } from '../items';
import { ModelResponse } from '../model';
import { RunContext } from '../runContext';
import { AgentInputItem } from '../types';
import { type ReasoningItemIdPolicy } from './items';
export { getTurnInput } from './items';
export type ModelInputData = {
    input: AgentInputItem[];
    instructions?: string;
};
export type CallModelInputFilterArgs<TContext = unknown> = {
    modelData: ModelInputData;
    agent: Agent<TContext, AgentOutputType>;
    context: TContext | undefined;
};
export type CallModelInputFilter<TContext = unknown> = ((args: CallModelInputFilterArgs<TContext>) => ModelInputData | Promise<ModelInputData>) & {
    /**
     * Preserve prepared input item identities by passing a shallow-copied array
     * to the filter. The SDK does not freeze these items; enable this only when
     * the filter and every helper it calls treat each input item and its nested
     * values as immutable. Model and session inputs remain isolated copies after
     * the filter returns.
     */
    preserveInputIdentity?: boolean;
};
/**
 * Result of applying a `callModelInputFilter`.
 * - `modelInput` is the payload that goes to the model.
 * - `sourceItems` maps each filtered item back to the original turn item (or `undefined` when none).
 *   This lets the conversation tracker know which originals reached the model.
 * - `persistedItems` are the normalized clones we should commit to session memory so the stored
 *   history reflects identity-aware replacement plus any redactions or truncation from the filter.
 * - `filterApplied` signals whether a filter ran so callers can distinguish empty filtered results
 *   from the filter being skipped entirely.
 */
export type FilterApplicationResult = {
    modelInput: {
        input: AgentInputItem[];
        instructions?: string;
    };
    sourceItems: (AgentInputItem | undefined)[];
    persistedItems: AgentInputItem[];
    sourceMatchKinds: Array<'identity' | 'content' | 'fallback' | 'injected'>;
    filterApplied: boolean;
    preserveInputIdentity: boolean;
};
export type ServerConversationOwner = {
    type: 'conversation';
    id: string;
} | {
    type: 'previous_response';
    id: string;
};
/**
 * Resolves the single server-side continuation owner for an accepted response.
 */
export declare function getServerConversationOwner(conversationId: string | undefined, previousResponseId: string | undefined): ServerConversationOwner | undefined;
/**
 * Applies the optional callModelInputFilter and returns the filtered input alongside the original
 * items so downstream tracking and session persistence stay in sync with what the model saw.
 */
export declare function applyCallModelInputFilter<TContext>(agent: Agent<TContext, AgentOutputType>, callModelInputFilter: CallModelInputFilter<any> | undefined, context: RunContext<TContext>, inputItems: AgentInputItem[], systemInstructions: string | undefined): Promise<FilterApplicationResult>;
/**
 * Tracks which items have already been sent to or received from the Responses API when the caller
 * supplies `conversationId`/`previousResponseId`. This ensures we only send the delta each turn.
 */
export declare class ServerConversationTracker {
    conversationId?: string;
    previousResponseId?: string;
    private readonly reasoningItemIdPolicy?;
    private sentInitialInput;
    private sentItems;
    private serverItems;
    private preparedItemSources;
    private remainingInitialInput;
    constructor({ conversationId, previousResponseId, reasoningItemIdPolicy, }: {
        conversationId?: string;
        previousResponseId?: string;
        reasoningItemIdPolicy?: ReasoningItemIdPolicy;
    });
    /**
     * Pre-populates tracker caches from an existing RunState when resuming server-managed runs.
     */
    primeFromState({ originalInput, generatedItems, modelResponses, }: {
        originalInput: string | AgentInputItem[];
        generatedItems: RunItem[];
        modelResponses: ModelResponse[];
    }): void;
    /**
     * Records the raw items returned by the server so future delta calculations skip them.
     * Also captures the latest response identifier to chain follow-up calls when possible.
     */
    trackServerItems(modelResponse: ModelResponse | undefined, processedItems?: RunItem[]): void;
    /**
     * Returns the minimum set of items that still need to be delivered to the server for the
     * current turn. This includes the original turn inputs (until acknowledged) plus any
     * newly generated items that have not yet been echoed back by the API.
     */
    prepareInput(originalInput: string | AgentInputItem[], generatedItems: RunItem[], supplementalGeneratedItems?: AgentInputItem[], pendingInputItems?: RunInputItem[]): AgentInputItem[];
    /**
     * Marks the provided originals as delivered so future turns do not resend them and any
     * pending initial inputs can be dropped once the server acknowledges receipt.
     */
    markInputAsSent(items: (AgentInputItem | undefined)[], options?: {
        filterApplied?: boolean;
        allTurnItems?: AgentInputItem[];
    }): void;
    private addDeliveredItems;
    private registerPreparedItemSource;
    private resolvePreparedItemSource;
    private updateRemainingInitialInput;
}
