import type { LlmUsageStats } from '@longrun-ai/kernel/types/context-health';
import type { DialogDisplayTextI18n } from '@longrun-ai/kernel/types/display-state';
import type { ProviderData, ReasoningPayload, ToolResultImageArtifact, ToolResultImageDisposition } from '@longrun-ai/kernel/types/storage';
import { Team } from '../team';
import { FuncTool } from '../tool';
import { ChatMessage, ProviderConfig } from './client';
export interface LlmStreamResult {
    usage: LlmUsageStats;
    llmGenModel?: string;
}
export declare class LlmStreamErrorEmittedError extends Error {
    readonly detail: string;
    readonly i18nStopReason: DialogDisplayTextI18n;
    constructor(args: {
        detail: string;
        message?: string;
        i18nStopReason: DialogDisplayTextI18n;
    });
}
export type LlmBatchOutput = {
    kind: 'message';
    message: ChatMessage;
} | {
    kind: 'answering';
    content: string;
} | {
    kind: 'invalid_func_call';
    call: LlmInvalidFuncCall;
} | {
    kind: 'web_search_call';
    call: LlmWebSearchCall;
} | {
    kind: 'native_tool_call';
    call: OpenAiResponsesNativeToolCall;
} | {
    kind: 'tool_result_image_ingest';
    ingest: ToolResultImageIngest;
} | {
    kind: 'user_image_ingest';
    ingest: UserImageIngest;
};
export interface LlmBatchResult {
    messages: ChatMessage[];
    outputs?: LlmBatchOutput[];
    usage: LlmUsageStats;
    llmGenModel?: string;
}
export type LlmRetryStrategy = 'aggressive' | 'conservative' | 'smart_rate';
export type LlmFailureDisposition = {
    kind: 'retriable' | 'rejected' | 'fatal';
    message: string;
    status?: number;
    code?: string;
    retryStrategy?: LlmRetryStrategy;
    retryAfterMs?: number;
};
export type LlmFailureClassifier = (error: unknown) => LlmFailureDisposition | undefined;
export interface LlmRequestContext {
    dialogSelfId: string;
    dialogRootId: string;
    providerKey?: string;
    modelKey?: string;
    promptCacheKey?: string;
    toolUseRequirement?: 'none' | 'auto' | 'required';
}
export type ToolResultImageIngest = {
    toolCallId: string;
    toolName: string;
    artifact: ToolResultImageArtifact;
    provider: string;
    model: string;
    disposition: ToolResultImageDisposition;
    message: string;
    detail?: string;
};
export type UserImageIngest = {
    msgId?: string;
    artifact: ToolResultImageArtifact;
    provider: string;
    model: string;
    disposition: ToolResultImageDisposition;
    message: string;
    detail?: string;
};
export type CodexLlmWebSearchAction = {
    type: 'search';
    query?: string;
} | {
    type: 'open_page';
    url?: string;
} | {
    type: 'find_in_page';
    url?: string;
    pattern?: string;
};
export type OpenAiResponsesLlmWebSearchAction = {
    type: 'search';
    query?: string;
    queries?: string[];
} | {
    type: 'open_page';
    url?: string;
} | {
    type: 'find_in_page';
    url?: string;
    pattern?: string;
};
export type CodexLlmWebSearchCall = {
    source: 'codex';
    phase: 'added' | 'done';
    itemId: string;
    status?: string;
    action?: CodexLlmWebSearchAction;
};
export type OpenAiResponsesLlmWebSearchCall = {
    source: 'openai_responses';
    phase: 'added' | 'done';
    itemId: string;
    status?: string;
    action?: OpenAiResponsesLlmWebSearchAction;
};
export type LlmWebSearchCall = CodexLlmWebSearchCall | OpenAiResponsesLlmWebSearchCall;
export type OpenAiResponsesNativeToolItemType = 'file_search_call' | 'code_interpreter_call' | 'image_generation_call' | 'mcp_call' | 'mcp_list_tools' | 'mcp_approval_request' | 'custom_tool_call';
export type OpenAiResponsesNonCustomNativeToolItemType = Exclude<OpenAiResponsesNativeToolItemType, 'custom_tool_call'>;
export type OpenAiResponsesNonCustomNativeToolCall = {
    source: 'openai_responses';
    itemType: OpenAiResponsesNonCustomNativeToolItemType;
    phase: 'added' | 'done';
    itemId: string;
    status?: string;
    title?: string;
    summary?: string;
    detail?: string;
};
export type OpenAiResponsesCustomToolCall = {
    source: 'openai_responses';
    itemType: 'custom_tool_call';
    phase: 'added' | 'done';
    callId: string;
    itemId?: string;
    status?: string;
    title?: string;
    summary?: string;
    detail?: string;
};
export type OpenAiResponsesNativeToolCall = OpenAiResponsesNonCustomNativeToolCall | OpenAiResponsesCustomToolCall;
export type LlmInvalidFuncCall = Readonly<{
    provider: string;
    callId: string;
    detail: string;
    toolCallIndex?: number;
    rawFunctionName?: string;
    rawArgumentsText?: string;
}>;
export interface LlmStreamReceiver {
    thinkingStart: () => Promise<void>;
    thinkingChunk: (chunk: string) => Promise<void>;
    thinkingFinish: (reasoning?: ReasoningPayload, providerData?: ProviderData) => Promise<void>;
    sayingStart: () => Promise<void>;
    sayingChunk: (chunk: string) => Promise<void>;
    sayingFinish: () => Promise<void>;
    answering?: (content: string) => Promise<void>;
    funcCall: (callId: string, name: string, args: string, ids?: {
        rawCallId?: string;
        effectiveCallId?: string;
    }) => Promise<void>;
    invalidFuncCall?: (call: LlmInvalidFuncCall) => Promise<void>;
    webSearchCall?: (call: LlmWebSearchCall) => Promise<void>;
    nativeToolCall?: (call: OpenAiResponsesNativeToolCall) => Promise<void>;
    toolResultImageIngest?: (ingest: ToolResultImageIngest) => Promise<void>;
    userImageIngest?: (ingest: UserImageIngest) => Promise<void>;
    streamError?: (detail: string) => Promise<void>;
}
export interface LlmGenerator {
    readonly apiType: string;
    classifyFailure?: LlmFailureClassifier;
    genToReceiver: (providerConfig: ProviderConfig, agent: Team.Member, systemPrompt: string, funcTools: FuncTool[], requestContext: LlmRequestContext, context: ChatMessage[], receiver: LlmStreamReceiver, genseq: number, abortSignal?: AbortSignal) => Promise<LlmStreamResult>;
    genMoreMessages: (providerConfig: ProviderConfig, agent: Team.Member, systemPrompt: string, funcTools: FuncTool[], requestContext: LlmRequestContext, context: ChatMessage[], genseq: number, abortSignal?: AbortSignal) => Promise<LlmBatchResult>;
}
