/** UI-facing snapshot of session state (messages + stop reason) plus its guards. */
import { isUserMessageUiMetadata } from './user-message-ui-metadata.js';
export const RuntimeMessageRole = {
    Assistant: 'assistant',
    Tool: 'tool',
    User: 'user'
};
export const AgentStopReason = {
    Cancelled: 'cancelled',
    Completed: 'completed',
    Failed: 'failed',
    Running: 'running'
};
/**
 * Categorical reason for a `Failed` stop. Mirrors backend's user-visible
 * error codes (`chat_context_too_long`, `chat_llm_unavailable`,
 * `chat_internal_error`) so the UI can render the right error card.
 */
export const AgentProtocolErrorKind = {
    ContextTooLong: 'context_too_long',
    LlmUnavailable: 'llm_unavailable',
    Internal: 'internal'
};
export const RuntimeInFlightKind = {
    Llm: 'llm',
    Tool: 'tool',
    HostTool: 'host_tool',
    Subagent: 'subagent',
    Compaction: 'compaction'
};
export function isRuntimeMessage(value) {
    if (!value || typeof value !== 'object')
        return false;
    const candidate = value;
    const toolCallsValid = candidate.toolCalls === undefined ||
        (Array.isArray(candidate.toolCalls) &&
            candidate.toolCalls.every((toolCall) => toolCall != null &&
                typeof toolCall === 'object' &&
                typeof toolCall.id === 'string' &&
                typeof toolCall.name === 'string' &&
                typeof toolCall.args === 'object' &&
                toolCall.args != null));
    return (typeof candidate.id === 'string' &&
        typeof candidate.text === 'string' &&
        typeof candidate.role === 'string' &&
        Object.values(RuntimeMessageRole).includes(candidate.role) &&
        (candidate.thinking === undefined || typeof candidate.thinking === 'string') &&
        (candidate.toolCallId === undefined || typeof candidate.toolCallId === 'string') &&
        (candidate.toolName === undefined || typeof candidate.toolName === 'string') &&
        (candidate.isError === undefined || typeof candidate.isError === 'boolean') &&
        (candidate.uiMetadata === undefined || isUserMessageUiMetadata(candidate.uiMetadata)) &&
        toolCallsValid);
}
export function isRuntimeInFlightOp(value) {
    if (!value || typeof value !== 'object')
        return false;
    const candidate = value;
    return (typeof candidate.opId === 'string' &&
        typeof candidate.kind === 'string' &&
        Object.values(RuntimeInFlightKind).includes(candidate.kind) &&
        typeof candidate.startedAt === 'number' &&
        typeof candidate.elapsedMs === 'number' &&
        (candidate.label === undefined || typeof candidate.label === 'string') &&
        (candidate.toolName === undefined || typeof candidate.toolName === 'string') &&
        (candidate.toolCallId === undefined || typeof candidate.toolCallId === 'string'));
}
export function isAgentSnapshot(value) {
    if (!value || typeof value !== 'object')
        return false;
    const candidate = value;
    return (typeof candidate.sessionId === 'string' &&
        typeof candidate.isStreaming === 'boolean' &&
        typeof candidate.stopReason === 'string' &&
        Object.values(AgentStopReason).includes(candidate.stopReason) &&
        (candidate.errorKind === undefined ||
            Object.values(AgentProtocolErrorKind).includes(candidate.errorKind)) &&
        !('streamMessage' in candidate) &&
        Array.isArray(candidate.messages) &&
        candidate.messages.every((message) => isRuntimeMessage(message)) &&
        Array.isArray(candidate.inFlight) &&
        candidate.inFlight.every((op) => isRuntimeInFlightOp(op)) &&
        (candidate.runId === undefined || typeof candidate.runId === 'string'));
}
//# sourceMappingURL=agent-snapshot.js.map