import { ContentBlockParam, MessageParam, RedactedThinkingBlockParam, TextBlockParam, ThinkingBlockParam } from '@anthropic-ai/sdk/resources';
import { Raw } from '@vscode/prompt-tsx';
import { Response } from '../../../platform/networking/common/fetcherService';
import { AsyncIterableObject } from '../../../util/vs/base/common/async';
import { IInstantiationService, ServicesAccessor } from '../../../util/vs/platform/instantiation/common/instantiation';
import { ILogService } from '../../log/common/logService';
import { AnthropicMessagesTool, ContextManagementResponse } from '../../networking/common/anthropic';
import { FinishedCallback } from '../../networking/common/fetch';
import { IChatEndpoint, ICreateEndpointBodyOptions, IEndpointBody } from '../../networking/common/networking';
import { ChatCompletion } from '../../networking/common/openai';
import { ITelemetryService } from '../../telemetry/common/telemetry';
import { TelemetryData } from '../../telemetry/common/telemetryData';
/**
 * Build the `input_schema` for an Anthropic tool from an arbitrary JSON Schema
 * object. Ensures `type: 'object'` and `properties` default, preserves extra
 * keys like `$defs` and `additionalProperties`, and strips `$schema` which the
 * Anthropic API rejects.
 */
export declare function buildToolInputSchema(schema: Record<string, unknown> | undefined): Record<string, unknown> & {
    type: 'object';
};
/** IP Code Citation annotation from Messages API copilot_annotations */
interface AnthropicIPCodeCitation {
    id: number;
    start_offset: number;
    end_offset: number;
    details: Record<string, unknown>;
    citations: {
        snippet: string;
        url: string;
        ip_type?: string;
        license: string;
    };
}
interface AnthropicStreamEvent {
    type: string;
    message?: {
        id: string;
        type: string;
        role: string;
        content: ContentBlockParam[];
        model: string;
        stop_reason: string | null;
        stop_sequence: string | null;
        usage: {
            input_tokens: number;
            output_tokens: number;
            cache_creation_input_tokens?: number;
            cache_read_input_tokens?: number;
        };
    };
    index?: number;
    content_block?: ContentBlockParam | ThinkingBlockParam | RedactedThinkingBlockParam;
    delta?: {
        type: string;
        text?: string;
        partial_json?: string;
        thinking?: string;
        signature?: string;
        stop_reason?: string;
        stop_sequence?: string;
        stop_details?: {
            category?: string;
            explanation?: string;
            type?: string;
        };
    };
    copilot_annotations?: {
        IPCodeCitations?: AnthropicIPCodeCitation[];
    };
    usage?: {
        output_tokens: number;
        input_tokens?: number;
        cache_creation_input_tokens?: number;
        cache_read_input_tokens?: number;
    };
    copilot_usage?: {
        total_nano_aiu: number;
    };
    context_management?: ContextManagementResponse;
}
export declare function createMessagesRequestBody(accessor: ServicesAccessor, options: ICreateEndpointBodyOptions, model: string, endpoint: IChatEndpoint): IEndpointBody;
export declare function rawMessagesToMessagesAPI(messages: readonly Raw.ChatMessage[], validToolNames?: Set<string>): {
    messages: MessageParam[];
    system?: TextBlockParam[];
};
/** Removes any cache_control fields from system and message blocks. */
export declare function clearAllCacheControl(messagesResult: {
    messages: MessageParam[];
    system?: TextBlockParam[];
}): void;
/**
 * Marks the last non-deferred tool and the last system block for caching.
 *
 * When {@link cacheTtl} is `'1h'`, the breakpoints request the extended cache
 * TTL. Sending this requires the `extended-cache-ttl-2025-04-11` Anthropic
 * beta header — see {@link IChatEndpoint.getExtraHeaders}. When omitted, the
 * default 5 minute TTL is used.
 */
export declare function addToolsAndSystemCacheControl(tools: AnthropicMessagesTool[], messagesResult: {
    messages: MessageParam[];
    system?: TextBlockParam[];
}, cacheTtl?: '1h'): void;
/**
 * Marks the last cacheable block of the two most recent cacheable messages.
 *
 * Anthropic's prompt cache matches on content prefix, so a single tail anchor
 * is sufficient under steady-state. The second (older) anchor is intended to
 * improve the chance of retaining a useful fallback within Anthropic's
 * lookback window: if the tail anchor misses (TTL expiry on a slow tool call,
 * or rare content drift), the older anchor can still serve a cache hit
 * covering everything up to it, so we typically lose at most one exchange
 * instead of resetting the entire conversation cache.
 *
 * Combined with the tools + system breakpoints, this can produce up to 4
 * cache_control markers, which matches Anthropic's per-request limit.
 */
export declare function addMessagesApiCacheControl(messagesResult: {
    messages: MessageParam[];
    system?: TextBlockParam[];
}, cacheTtl?: '1h'): void;
export declare function processResponseFromMessagesEndpoint(instantiationService: IInstantiationService, telemetryService: ITelemetryService, logService: ILogService, response: Response, finishCallback: FinishedCallback, telemetryData: TelemetryData): Promise<AsyncIterableObject<ChatCompletion>>;
/**
 * Process a non-streaming response from the Anthropic Messages API.
 * Returns the same `ChatCompletion` shape as the streaming path.
 *
 * NOTE: Thinking / redacted_thinking content blocks are intentionally
 * not surfaced. If a future caller needs them, this function must be
 * extended to include them in the `ChatCompletion.message` and in the
 * `finishCallback` delta.
 */
export declare function processNonStreamingResponseFromMessagesEndpoint(telemetryService: ITelemetryService, logService: ILogService, response: Response, finishCallback: FinishedCallback, telemetryData: TelemetryData): Promise<AsyncIterableObject<ChatCompletion>>;
export declare class AnthropicMessagesProcessor {
    private readonly telemetryData;
    private readonly requestId;
    private readonly ghRequestId;
    private readonly serverExperiments;
    private readonly logService;
    private readonly telemetryService;
    private textAccumulator;
    private toolCallAccumulator;
    private thinkingAccumulator;
    private completedToolCalls;
    private messageId;
    private model;
    private inputTokens;
    private outputTokens;
    private cacheCreationTokens;
    private cacheReadTokens;
    private copilotUsage?;
    private contextManagementResponse?;
    private stopReason;
    private stopDetails?;
    constructor(telemetryData: TelemetryData, requestId: string, ghRequestId: string, serverExperiments: string, logService: ILogService, telemetryService: ITelemetryService);
    /**
     * Extract IP code citations from copilot_annotations and convert to IIPCodeCitation format
     */
    private extractIPCodeCitations;
    push(chunk: AnthropicStreamEvent, _onProgress: FinishedCallback): ChatCompletion | undefined;
}
export {};
//# sourceMappingURL=messagesApi.d.ts.map