import { z } from 'zod';

/** Where a photo came from. */
interface PhotoSource {
    /** Channel that delivered the photo: 'telegram', 'email', 'upload', 'web'. */
    channel: string;
    /** Channel-specific identifier (e.g. Telegram file_id, email message-id). */
    externalId: string;
    /** Fetch the raw bytes for vision processing. Implementation channel-specific. */
    fetchBytes: () => Promise<Buffer>;
    /** Optional MIME type hint (e.g. 'image/jpeg', 'image/png', 'image/webp'). */
    mimeType?: string;
    /** Optional caption / accompanying text. */
    caption?: string;
}
/** Pluggable durable storage for photos. */
interface PhotoStorage {
    /**
     * Persist the photo, return a stable URL and storage key. The orchestrator
     * calls `source.fetchBytes()` exactly once and hands the buffer in via a
     * memoised source, so adapters can call `source.fetchBytes()` freely
     * without triggering a second network fetch.
     */
    persist: (source: PhotoSource, opts: {
        agentId: string;
        userId?: string;
    }) => Promise<{
        url: string;
        key: string;
    }>;
}
interface PhotoExtractionResult<T> {
    /** Successfully extracted typed data, or null if extraction failed. */
    data: T | null;
    /** 0-1 confidence score (from the schema's `confidence` field, or 1 if absent and 0 on failure). */
    confidence: number;
    /** If extraction failed or was partial, the reason. */
    partial?: {
        reason: string;
        rawText?: string;
    };
    /** The persisted photo URL (for linking to a record later). */
    photoUrl: string;
    /** The storage key (for backend cleanup / migration if needed). */
    storageKey: string;
}
/**
 * Base64-encoded image source. This is the shape the Anthropic Messages
 * API accepts for inline image blocks:
 *
 *   { type: "image", source: { type: "base64", media_type, data } }
 *
 * Anthropic also accepts `{ type: "url", url }` and `{ type: "file", file_id }`
 * sources, but the orchestrator persists bytes itself so it always sends
 * base64. If you need URL-source forwarding, do it outside the orchestrator.
 */
interface AnthropicImageBlockBase64 {
    type: "image";
    source: {
        type: "base64";
        media_type: string;
        data: string;
    };
}
interface AnthropicVisionTextBlock {
    type: "text";
    text: string;
}
interface AnthropicVisionToolUseBlock {
    type: "tool_use";
    id: string;
    name: string;
    input: unknown;
}
type AnthropicVisionUserBlock = AnthropicImageBlockBase64 | AnthropicVisionTextBlock;
type AnthropicVisionAssistantBlock = AnthropicVisionTextBlock | AnthropicVisionToolUseBlock;
interface AnthropicVisionMessage {
    role: "user" | "assistant";
    content: string | AnthropicVisionUserBlock[] | AnthropicVisionAssistantBlock[];
}
interface AnthropicVisionToolDefinition {
    name: string;
    description: string;
    input_schema: Record<string, unknown>;
}
type AnthropicVisionToolChoice = {
    type: "auto";
} | {
    type: "any";
} | {
    type: "tool";
    name: string;
};
interface AnthropicVisionMessagesCreateArgs {
    model: string;
    max_tokens: number;
    system?: string;
    messages: AnthropicVisionMessage[];
    tools?: AnthropicVisionToolDefinition[];
    tool_choice?: AnthropicVisionToolChoice;
}
type AnthropicVisionStopReason = "end_turn" | "tool_use" | "max_tokens" | "stop_sequence" | (string & {});
interface AnthropicVisionResponse {
    id: string;
    role: "assistant";
    content: AnthropicVisionAssistantBlock[];
    stop_reason: AnthropicVisionStopReason;
    usage?: Record<string, unknown>;
}
/**
 * Structural type for the subset of the Anthropic SDK the vision
 * extractor uses. A real `Anthropic` instance satisfies this — mocks
 * for testing satisfy it just as well.
 */
interface AnthropicVisionClient {
    messages: {
        create(args: AnthropicVisionMessagesCreateArgs): Promise<AnthropicVisionResponse>;
    };
}
interface VisionConfig {
    client: AnthropicVisionClient;
    /** Model id, e.g. 'claude-sonnet-4-6' or 'claude-opus-4-7'. */
    model: string;
    /** Cap on tool-use retry attempts when extraction fails validation. Defaults to 2. */
    maxRetries?: number;
    /** Max output tokens. Defaults to 2048. */
    maxTokens?: number;
}
interface ExtractWithVisionArgs<T> {
    client: AnthropicVisionClient;
    model: string;
    imageBytes: Buffer;
    mimeType: string;
    schema: z.ZodType<T>;
    systemPrompt: string;
    userPrompt: string;
    /** Cap on retries when Claude returns data that fails Zod validation. Defaults to 2. */
    maxRetries?: number;
    /** Max output tokens. Defaults to 2048. */
    maxTokens?: number;
    /** Optional override for the synthetic tool name Claude is forced to call. Defaults to 'extract'. */
    toolName?: string;
}
interface ExtractWithVisionResult<T> {
    data: T | null;
    confidence: number;
    rawText?: string;
    reason?: string;
}

declare function extractWithVision<T>(args: ExtractWithVisionArgs<T>): Promise<ExtractWithVisionResult<T>>;

interface ProcessPhotoArgs<T> {
    source: PhotoSource;
    storage: PhotoStorage;
    vision: VisionConfig;
    schema: z.ZodType<T>;
    systemPrompt: string;
    userPrompt: string;
    ctx: {
        agentId: string;
        userId?: string;
    };
}
declare function processPhoto<T>(args: ProcessPhotoArgs<T>): Promise<PhotoExtractionResult<T>>;

declare class MemoryPhotoStorage implements PhotoStorage {
    private readonly store;
    persist(source: PhotoSource, opts: {
        agentId: string;
        userId?: string;
    }): Promise<{
        url: string;
        key: string;
    }>;
    get(key: string): Buffer | undefined;
    has(key: string): boolean;
    size(): number;
    clear(): void;
}

type index_AnthropicImageBlockBase64 = AnthropicImageBlockBase64;
type index_AnthropicVisionAssistantBlock = AnthropicVisionAssistantBlock;
type index_AnthropicVisionClient = AnthropicVisionClient;
type index_AnthropicVisionMessage = AnthropicVisionMessage;
type index_AnthropicVisionMessagesCreateArgs = AnthropicVisionMessagesCreateArgs;
type index_AnthropicVisionResponse = AnthropicVisionResponse;
type index_AnthropicVisionStopReason = AnthropicVisionStopReason;
type index_AnthropicVisionTextBlock = AnthropicVisionTextBlock;
type index_AnthropicVisionToolChoice = AnthropicVisionToolChoice;
type index_AnthropicVisionToolDefinition = AnthropicVisionToolDefinition;
type index_AnthropicVisionToolUseBlock = AnthropicVisionToolUseBlock;
type index_AnthropicVisionUserBlock = AnthropicVisionUserBlock;
type index_ExtractWithVisionArgs<T> = ExtractWithVisionArgs<T>;
type index_ExtractWithVisionResult<T> = ExtractWithVisionResult<T>;
type index_MemoryPhotoStorage = MemoryPhotoStorage;
declare const index_MemoryPhotoStorage: typeof MemoryPhotoStorage;
type index_PhotoExtractionResult<T> = PhotoExtractionResult<T>;
type index_PhotoSource = PhotoSource;
type index_PhotoStorage = PhotoStorage;
type index_ProcessPhotoArgs<T> = ProcessPhotoArgs<T>;
type index_VisionConfig = VisionConfig;
declare const index_extractWithVision: typeof extractWithVision;
declare const index_processPhoto: typeof processPhoto;
declare namespace index {
  export { type index_AnthropicImageBlockBase64 as AnthropicImageBlockBase64, type index_AnthropicVisionAssistantBlock as AnthropicVisionAssistantBlock, type index_AnthropicVisionClient as AnthropicVisionClient, type index_AnthropicVisionMessage as AnthropicVisionMessage, type index_AnthropicVisionMessagesCreateArgs as AnthropicVisionMessagesCreateArgs, type index_AnthropicVisionResponse as AnthropicVisionResponse, type index_AnthropicVisionStopReason as AnthropicVisionStopReason, type index_AnthropicVisionTextBlock as AnthropicVisionTextBlock, type index_AnthropicVisionToolChoice as AnthropicVisionToolChoice, type index_AnthropicVisionToolDefinition as AnthropicVisionToolDefinition, type index_AnthropicVisionToolUseBlock as AnthropicVisionToolUseBlock, type index_AnthropicVisionUserBlock as AnthropicVisionUserBlock, type index_ExtractWithVisionArgs as ExtractWithVisionArgs, type index_ExtractWithVisionResult as ExtractWithVisionResult, index_MemoryPhotoStorage as MemoryPhotoStorage, type index_PhotoExtractionResult as PhotoExtractionResult, type index_PhotoSource as PhotoSource, type index_PhotoStorage as PhotoStorage, type index_ProcessPhotoArgs as ProcessPhotoArgs, type index_VisionConfig as VisionConfig, index_extractWithVision as extractWithVision, index_processPhoto as processPhoto };
}

export { type AnthropicImageBlockBase64 as A, type ExtractWithVisionArgs as E, MemoryPhotoStorage as M, type PhotoExtractionResult as P, type VisionConfig as V, type AnthropicVisionAssistantBlock as a, type AnthropicVisionClient as b, type AnthropicVisionMessage as c, type AnthropicVisionMessagesCreateArgs as d, type AnthropicVisionResponse as e, type AnthropicVisionStopReason as f, type AnthropicVisionTextBlock as g, type AnthropicVisionToolChoice as h, type AnthropicVisionToolDefinition as i, type AnthropicVisionToolUseBlock as j, type AnthropicVisionUserBlock as k, type ExtractWithVisionResult as l, type PhotoSource as m, type PhotoStorage as n, type ProcessPhotoArgs as o, extractWithVision as p, index as q, processPhoto as r };
