import type { AgentRuntimeMediaAttachment, TranscriptEntry } from "@rudderhq/agent-runtime-utils";
import type { RudderSkillEntry } from "@rudderhq/agent-runtime-utils/server-utils";
import type { AgentRuntimeType, ChatContextLink, ChatConversation, ChatMessage, ChatRuntimeDescriptor, IssueLabel, OperatorProfileSettings } from "@rudderhq/shared";
import type { AgentRuntimeInvocationMeta, AgentRuntimeLoadedSkillMeta } from "../agent-runtimes/index.js";
import type { AgentRuntimeExecutionContext, AgentRuntimeExecutionResult } from "../agent-runtimes/types.js";
import type { StorageService } from "../storage/types.js";
import { type AgentRunContextAgent } from "./agent-run-context.js";
export declare const CHAT_UNSUPPORTED_ADAPTER_TYPES: Set<"process" | "http" | "claude_local" | "codex_local" | "gemini_local" | "opencode_local" | "pi_local" | "cursor" | "openclaw_gateway" | "hermes_local">;
export declare const CHAT_RESULT_SENTINEL_PREFIX = "__RUDDER_RESULT_";
export declare const CHAT_RESULT_TEXT_BLOCK_BEGIN = "RUDDER_RESULT_BEGIN";
export declare const CHAT_RESULT_TEXT_BLOCK_END = "RUDDER_RESULT_END";
export declare const CHAT_ASSISTANT_USER_ERROR_MESSAGE = "The assistant hit a system-level issue. Rudder saved the details for diagnostics; retry when ready.";
export declare const CHAT_ASSISTANT_RECOVERABLE_FAILURE_MESSAGE = "The assistant reply could not be completed. Rudder saved this attempt for diagnostics; retry when ready.";
export type ChatRecoverableFailureCode = "chat_result_missing_sentinel" | "chat_result_malformed_json" | "chat_timed_out" | "chat_adapter_failed" | "chat_runtime_exception";
export interface ChatAttachmentPromptReference {
    localPath?: string;
    localPathError?: string;
}
export interface ResolvedChatRuntimeSource {
    descriptor: ChatRuntimeDescriptor;
    runtimeAgent: AgentRunContextAgent | null;
    agentRuntimeType: AgentRuntimeType | null;
    agentRuntimeConfig: Record<string, unknown> | null;
    runtimeSkills: AgentRuntimeLoadedSkillMeta[];
}
export interface ChatAssistantResult {
    kind: "message" | "ask_user" | "issue_proposal" | "operation_proposal" | "automation_create";
    body: string;
    structuredPayload: Record<string, unknown> | null;
    replyingAgentId?: string | null;
    generatedAttachments?: ChatGeneratedAttachment[];
}
export interface ChatGeneratedAttachment {
    source: "codex_image_generation";
    originalFilename: string;
    contentType: string;
    body: Buffer;
    toolCallId?: string | null;
}
export interface GenerateChatAssistantReplyInput {
    conversation: ChatConversation;
    messages: ChatMessage[];
    contextLinks: ChatContextLink[];
    issueLabels?: IssueLabel[] | null;
    operatorProfile?: OperatorProfileSettings | null;
}
export interface StreamChatAssistantReplyInput extends GenerateChatAssistantReplyInput {
    userMessageId?: string | null;
    chatTurnId?: string | null;
    turnVariant?: number | null;
    runContext?: Record<string, unknown> | null;
    stream?: boolean;
    abortSignal?: AbortSignal;
    onRunCreated?: (runId: string) => Promise<void> | void;
    onAssistantDelta?: (delta: string) => Promise<void> | void;
    onAssistantState?: (state: "streaming" | "finalizing" | "stopped") => Promise<void> | void;
    onInvocationMeta?: (meta: AgentRuntimeInvocationMeta) => Promise<void> | void;
    onTranscriptEntry?: (entry: TranscriptEntry) => Promise<void> | void;
    onObservedTranscriptEntry?: (entry: TranscriptEntry) => Promise<void> | void;
}
export type StreamChatAssistantReplyResult = {
    outcome: "completed";
    reply: ChatAssistantResult;
    partialBody: string;
    replyingAgentId: string | null;
} | {
    outcome: "stopped";
    partialBody: string;
    replyingAgentId: string | null;
};
export declare class ChatAssistantStreamError extends Error {
    partialBody: string;
    partialBodyUserVisible: boolean;
    generatedAttachments: ChatGeneratedAttachment[];
    errorCode: ChatRecoverableFailureCode;
    userMessage: string;
    constructor(message: string, partialBody: string, generatedAttachments?: ChatGeneratedAttachment[], options?: {
        partialBodyUserVisible?: boolean;
        errorCode?: ChatRecoverableFailureCode;
        userMessage?: string;
    });
}
export declare function recoverableFailureMessage(code: ChatRecoverableFailureCode): "The assistant reply could not be completed. Rudder saved this attempt for diagnostics; retry when ready." | "The assistant reply could not be completed. Rudder saved the attempt for diagnostics; retry when ready." | "The assistant returned an incomplete final reply. Rudder saved the attempt and transcript; retry when ready." | "The assistant timed out before finishing. Rudder saved the partial attempt; retry when ready." | "The assistant runtime failed before finishing. Rudder saved the attempt for diagnostics; retry when ready.";
export declare function buildMissingResultSentinelRepairPrompt(input: {
    resultSentinel: string;
    priorText: string;
}): string;
export declare function safeTrim(value: string | null | undefined): string | null;
export declare function asString(value: unknown): string;
export declare function summarizeBody(value: string, maxChars?: number): string;
export declare function modelLabel(config: Record<string, unknown> | null | undefined): string | null;
export declare function unconfiguredDescriptor(error: string): ChatRuntimeDescriptor;
export declare function unavailableAgentDescriptor(input: {
    sourceLabel: string;
    runtimeAgentId: string | null;
    agentRuntimeType: AgentRuntimeType | null;
    model: string | null;
    error: string;
}): ChatRuntimeDescriptor;
export declare function buildPrompt(input: GenerateChatAssistantReplyInput, attachmentReferences?: Map<string, ChatAttachmentPromptReference>): string;
export declare function buildCurrentUserAttachmentPromptSection(messages: ChatMessage[], attachmentReferences?: Map<string, ChatAttachmentPromptReference>): string | null;
export declare function buildOperatorProfilePromptSection(profile: OperatorProfileSettings | null | undefined): string | null;
export declare function buildSelectedProjectPromptSection(contextLinks: ChatContextLink[]): string | null;
export declare function buildSelectedIssuePromptSection(conversation: Pick<ChatConversation, "primaryIssue">, contextLinks: ChatContextLink[]): string | null;
export declare function buildIssueLabelsPromptSection(labels: IssueLabel[] | null | undefined): string | null;
export declare function buildChatSpeakerPromptSection(runtimeSource: ResolvedChatRuntimeSource): string;
export declare function buildChatResponseQualityPromptSection(): string;
export declare function buildAutomationRunInputPromptSection(messages: ChatMessage[]): string | null;
export declare function buildBaseSystemPromptSections(runtimeSource: ResolvedChatRuntimeSource, resultSentinel: string): string[];
export declare function buildTerminalResultEnvelopePromptSection(resultSentinel: string): string;
export declare function buildPlanModePromptSection(): string;
export declare function buildResponseSchemaPromptSection(planMode: boolean): string;
export declare function systemPrompt(runtimeSource: ResolvedChatRuntimeSource, conversation: Pick<ChatConversation, "planMode">, resultSentinel: string): string;
export declare function extractJsonObject(text: string): Record<string, unknown> | null;
export declare function asRecord(value: unknown): Record<string, unknown> | null;
export declare function extractImageGenerationItem(event: Record<string, unknown>): Record<string, unknown> | null;
export declare function base64PngToBuffer(value: unknown): Buffer<ArrayBuffer> | null;
export declare function extractGeneratedAttachments(result: AgentRuntimeExecutionResult): ChatGeneratedAttachment[];
export declare function isImageAttachment(attachment: Pick<ChatMessage["attachments"][number], "contentType">): boolean;
export declare function extensionForContentType(contentType: string): "" | ".svg" | ".png" | ".jpg" | ".gif" | ".webp";
export declare function safeAttachmentFilename(attachment: Pick<ChatMessage["attachments"][number], "id" | "assetId" | "originalFilename" | "contentType">, index: number): string;
export declare function prepareChatAttachmentReferences(input: {
    runtimeType: AgentRuntimeType;
    messages: ChatMessage[];
    storage?: StorageService;
    runId: string;
}): Promise<{
    references: Map<string, ChatAttachmentPromptReference>;
    media: AgentRuntimeMediaAttachment[];
    cleanup: () => Promise<void>;
}>;
export declare function validateAssistantResult(payload: Record<string, unknown>, options?: {
    bodyOverride?: string | null;
    bodyFallback?: string | null;
}): ChatAssistantResult;
export declare function buildConversationPrompt(input: GenerateChatAssistantReplyInput, runtimeSource: ResolvedChatRuntimeSource, resultSentinel: string, orgResourcesPrompt: string, attachmentReferences?: Map<string, ChatAttachmentPromptReference>): string;
export declare function resultText(result: AgentRuntimeExecutionResult): string;
export declare function configArgs(agentRuntimeConfig: Record<string, unknown>): string[];
export declare function stripCliArgs(args: string[], input: {
    flagsWithValues?: string[];
    standaloneFlags?: string[];
    prefixedFlags?: string[];
}): string[];
export declare function applyPlanModeRuntimeOverlay(agentRuntimeType: AgentRuntimeType, agentRuntimeConfig: Record<string, unknown>): Record<string, unknown>;
export declare function chatExecutionConfig(conversation: Pick<ChatConversation, "planMode">, agentRuntimeType: AgentRuntimeType, agentRuntimeConfig: Record<string, unknown>): Record<string, unknown>;
export declare function linkedIssueIdsForChat(conversation: Pick<ChatConversation, "primaryIssueId">, contextLinks: ChatContextLink[]): string[];
export declare function linkedProjectIdForChat(contextLinks: ChatContextLink[]): string | null;
export declare function stubAgent(input: {
    orgId: string;
    agentRuntimeType: AgentRuntimeType;
    agentRuntimeConfig: Record<string, unknown>;
    sourceLabel: string;
    sourceId: string;
}): AgentRuntimeExecutionContext["agent"];
export declare function summarizeRuntimeSkills(entries: RudderSkillEntry[]): AgentRuntimeLoadedSkillMeta[];
export declare function longestSentinelPrefixSuffix(value: string, sentinel: string): number;
export declare function createAssistantTextAccumulator(): {
    readonly fullText: string;
    push(fragment: string, isDelta?: boolean): string;
};
export declare function createSentinelStream(resultSentinel: string): {
    readonly visibleText: string;
    readonly resultPayloadText: string;
    readonly seenSentinel: boolean;
    push(text: string): string;
    finish(): string;
};
export declare function parseAssistantEnvelope(rawText: string, resultSentinel: string): {
    visibleBody: string;
    jsonPayload: Record<string, unknown> | null;
    usedSentinel: boolean;
};
export declare function parseAssistantTextBlock(rawText: string): {
    visibleBody: string;
    body: string;
} | null;
export declare function parseCompletedAssistantReply(rawText: string, resultSentinel: string, options?: {
    requireSentinel?: boolean;
}): ChatAssistantResult;
export declare function partialBodyFromRawAssistantText(rawText: string, resultSentinel: string): string;
export declare function finalBodyFromRawAssistantText(rawText: string, resultSentinel: string): string;
export declare function userVisiblePartialBodyFromError(error: unknown): string;
export declare function maybeEmitAssistantState(callback: StreamChatAssistantReplyInput["onAssistantState"], state: "streaming" | "finalizing" | "stopped"): Promise<void>;
export declare function maybeEmitAssistantDelta(callback: StreamChatAssistantReplyInput["onAssistantDelta"], delta: string): Promise<void>;
export declare function maybeEmitTranscriptEntry(callback: StreamChatAssistantReplyInput["onTranscriptEntry"], entry: TranscriptEntry): Promise<void>;
export declare function maybeEmitObservedTranscriptEntry(callback: StreamChatAssistantReplyInput["onObservedTranscriptEntry"], entry: TranscriptEntry): Promise<void>;
export declare function shouldSuppressChatTranscriptEntry(entry: TranscriptEntry, resultSentinel: string): boolean;
//# sourceMappingURL=chat-assistant.helpers.d.ts.map