import * as react_jsx_runtime from 'react/jsx-runtime';
import * as _tanstack_react_query from '@tanstack/react-query';

type MessageType = MessageEvent['type'];
interface ChatMessage {
    id: string;
    role: 'user' | 'assistant';
    messageType: MessageType;
    text: string;
    metadata?: MessageEvent;
    turnNumber: number;
    messageIndex?: number;
    createdAt: Date;
}
/** Token usage data sent with turn:complete WebSocket events */
interface SessionTokenUsage {
    /** Tokens consumed by this turn's input */
    turnInputTokens: number;
    /** Tokens generated by this turn's output */
    turnOutputTokens: number;
    /** Total tokens for this turn (turnInputTokens + turnOutputTokens) */
    turnTotalTokens: number;
    /** Cumulative input tokens across all turns in this session */
    cumulativeInputTokens: number;
    /** Cumulative output tokens across all turns in this session */
    cumulativeOutputTokens: number;
    /** The model's context window size for this session (e.g., 200K) */
    contextWindowSize: number;
}

/**
 * Base Execution Engine type definitions
 * Core types shared across all Execution Engine resources
 */

/**
 * Unified message event type - covers all message types in sessions
 * Replaces separate SessionTurnMessages and AgentActivityEvent mechanisms
 */
/**
 * Structured action metadata attached to assistant messages.
 * Frontend reads this instead of parsing text prefixes.
 */
type AssistantAction = {
    kind: 'navigate';
    path: string;
    reason: string;
} | {
    kind: 'update_filters';
    timeRange: string | null;
    statusFilter: string | null;
    searchQuery: string | null;
};
type MessageEvent = {
    type: 'user_message';
    text: string;
} | {
    type: 'assistant_message';
    text: string;
    _action?: AssistantAction;
} | {
    type: 'agent:started';
} | {
    type: 'agent:completed';
} | {
    type: 'agent:error';
    error: string;
} | {
    type: 'agent:reasoning';
    iteration: number;
    reasoning: string;
} | {
    type: 'agent:tool_call';
    toolName: string;
    args: Record<string, unknown>;
} | {
    type: 'agent:tool_result';
    toolName: string;
    success: boolean;
    result?: unknown;
    error?: string;
};

interface PublicAgentChatGrant {
    slug: string;
    resourceId: string;
    mode: 'public' | 'code' | string;
    requiresCode: boolean;
    branding?: unknown;
    captureFields?: unknown;
    maxTurnsPerSession?: number;
}
interface PublicAgentChatMetadataResponse {
    grant: PublicAgentChatGrant;
}
interface PublicAgentChatAuthorizeResponse {
    capabilityToken: string;
    expiresAt: string;
    grant: PublicAgentChatGrant;
}
interface PublicAgentChatSessionResponse {
    sessionId: string;
    resourceId: string;
    turnCount: number;
    isEnded: boolean;
    title: string | null;
    createdAt?: string;
    updatedAt?: string;
    capabilityToken?: string;
    capabilityExpiresAt?: string;
}
interface PublicAgentChatMessagesResponse {
    sessionId: string;
    messages: Array<Omit<ChatMessage, 'createdAt'> & {
        createdAt?: string;
    }>;
    limit: number;
    cursor: number | null;
    nextCursor: number | null;
    total: number;
    hasMore: boolean;
}
interface PublicAgentChatConnectionState {
    isConnected: boolean;
    isProcessing: boolean;
    error: string | null;
}

interface PublicAgentChatProps {
    apiUrl: string;
    slug: string;
    visitorId?: string;
    metadata?: Record<string, unknown>;
    title?: string;
    className?: string;
    style?: React.CSSProperties;
    onSessionReady?: (session: PublicAgentChatSessionResponse) => void;
    /**
     * Whether to render agent-activity bubbles (reasoning, tool calls/results,
     * errors) alongside the conversation. Defaults to false on the public surface
     * so visitors see a clean message-only chat; pass true to expose activity for
     * a specific public agent.
     */
    showAgentActivity?: boolean;
}
declare function PublicAgentChat({ apiUrl, slug, visitorId, metadata, title, className, style, onSessionReady, showAgentActivity }: PublicAgentChatProps): react_jsx_runtime.JSX.Element;

interface PublicAgentChatRoutePageProps extends PublicAgentChatProps {
    pageStyle?: React.CSSProperties;
}
declare function PublicAgentChatRoutePage({ pageStyle, style, ...props }: PublicAgentChatRoutePageProps): react_jsx_runtime.JSX.Element;

declare function usePublicAgentChatMessages(apiUrl: string, sessionId: string | null, capabilityToken: string | null): _tanstack_react_query.UseQueryResult<ChatMessage[], Error>;

interface WebSocketState {
    isConnected: boolean;
    isProcessing: boolean;
    error: string | null;
}

declare function usePublicAgentChatWebSocket(sessionId: string | null, apiUrl: string, capabilityToken: string | null): {
    messages: ChatMessage[];
    state: WebSocketState;
    sendMessage: (text: string) => void;
    clearError: () => void;
    lastTokenUsage: SessionTokenUsage | null;
};

declare const publicAgentChatKeys: {
    all: readonly ["public-agent-chat"];
    messages: (sessionId: string) => readonly ["public-agent-chat", "messages", string];
};

export { PublicAgentChat, PublicAgentChatRoutePage, publicAgentChatKeys, usePublicAgentChatMessages, usePublicAgentChatWebSocket };
export type { PublicAgentChatAuthorizeResponse, PublicAgentChatConnectionState, PublicAgentChatGrant, PublicAgentChatMessagesResponse, PublicAgentChatMetadataResponse, PublicAgentChatProps, PublicAgentChatRoutePageProps, PublicAgentChatSessionResponse };
