import { type Actor, type Executor, type ExecutorKind } from "./executors.js"; import type { CallbackRouteV1 } from "./callback-transport.js"; export type MessageType = "task" | "question" | "answer" | "progress" | "blocked" | "done" | "error" | "control"; /** * `callback_pending` and `callback_failed` are retained only so Stores written * by earlier releases can still be read. New writes keep callback transport state in * `conversation.callback_delivery` and use a TurnPhaseStatus here. */ export type ConversationStatus = "created" | "running" | "waiting_for_agent" | "waiting_for_openclaw" | "idle" | "stalled" | "callback_pending" | "callback_failed" | "failed" | "closed" | "cancelled" | "cancelling"; export type TurnPhaseStatus = Exclude; export type BudgetLevel = "normal" | "converge" | "warning" | "soft_stop" | "hard_stop"; export type { Actor, Executor, ExecutorKind } from "./executors.js"; export { ACTORS, EXECUTORS, resolveExecutor } from "./executors.js"; export interface Conversation { /** Authoritative identity for the continuing managed agent context. */ session_id: string; /** Authoritative identity for this accepted dispatch lifecycle. */ turn_id: string; /** Immutable terminal binding that authorized this Turn. */ terminal_binding_id?: string; /** Session-local binding epoch that fences stale asynchronous work. */ terminal_binding_generation?: number; /** Exact native Codex/Claude thread observed when this Turn was created. */ native_thread_id?: string; /** Legacy Store/path alias. New records keep this equal to turn_id. */ conversation_id: string; user_request: string; openclaw_session: string; claude_session: string; executor: Executor; workspace: string; status: ConversationStatus; response_rounds_used: number; soft_limit: number; hard_limit: number; created_at: string; updated_at: string; idle_since?: string; closed_at?: string; close_reason?: string; cancel_requested_at?: string; gateway_url?: string; gateway_method?: string; gateway_session?: string; openclaw_bin?: string; gateway_token?: string; callback_route?: CallbackRouteV1; store_dir?: string; conversation_dir?: string; event_log_path?: string; state_path?: string; [key: string]: unknown; } export declare function isActiveConversationStatus(status: unknown): boolean; export declare function isWaitingForAgentStatus(status: unknown): boolean; export declare function isTerminalBridgeCallbackSupersedeStatus(status: unknown): boolean; export declare function isTerminalDispatchOwnerReleasedStatus(status: unknown): boolean; export declare function isExplicitUserAbandonedManagementTurn(conversation: Partial | null | undefined): boolean; export declare function isSessionSendBlockingStatus(status: unknown): boolean; /** * Resolve the semantic Turn phase for both current and legacy callback state. * Invalid legacy records fail closed instead of guessing that a Turn is idle. */ export declare function effectiveTurnStatus(conversation: Partial | null | undefined): TurnPhaseStatus; /** Materialize a legacy callback-owned status as an ordinary Turn phase. */ export declare function normalizeLegacyCallbackStatus(conversation: Conversation): Conversation; export declare function isTurnPhaseStatus(value: unknown): value is TurnPhaseStatus; export interface AgentMessage { id: string; ts: string; conversation_id: string; /** Authoritative session identity. Optional only when reading legacy messages. */ session_id?: string; /** Exact dispatch identity. Optional only when reading legacy messages. */ turn_id?: string; from: Actor; to: Actor; type: MessageType; requires_response: boolean; round: number; max_rounds: number; body: string; metadata: Record; } export interface BudgetAction { level: BudgetLevel; message: string; } interface CreateConversationOptions { userRequest: string; sessionId?: string; turnId?: string; workspace?: string; openclawSession?: string; claudeSession?: string; executorKind?: ExecutorKind | string; executorSession?: string; softLimit?: number; hardLimit?: number; now?: Date; } interface CreateMessageOptions { conversation: Conversation; /** Stable internal id used when a persisted callback outbox is reconstructed. */ id?: string; from: Actor; to: Actor; type: MessageType; body: string; requiresResponse?: boolean | undefined; metadata?: Record; now?: Date; } interface ExtractStructuredMessageOptions { conversation: Conversation; input: string; defaultFrom?: Actor; defaultTo?: Actor; now?: Date; } export declare const MESSAGE_TYPES: Set; export declare const DEFAULT_REQUIRES_RESPONSE: Record; export declare const ALLOWED_MESSAGE_TYPES_BY_ROUTE: Record>; export declare function createConversation({ userRequest, sessionId, turnId, workspace, openclawSession, claudeSession, executorKind, executorSession, softLimit, hardLimit, now }: CreateConversationOptions): Conversation; /** * Return the authoritative managed-session identity, falling back to the * historical Store alias for records written before session_id existed. */ export declare function sessionIdForConversation(conversation: Partial | null | undefined): string; /** * Return the authoritative dispatch identity, falling back to the historical * Store alias for records written before turn_id existed. */ export declare function turnIdForConversation(conversation: Partial | null | undefined): string; export declare function executorForConversation(conversation: Partial | null | undefined): Executor; export declare function createMessage({ conversation, id, from, to, type, body, requiresResponse, metadata, now }: CreateMessageOptions): AgentMessage; export declare function validateMessage(message: unknown): message is AgentMessage; export declare function validateMessageForConversation(conversation: Conversation, message: AgentMessage): true; export declare function applyMessageToConversation(conversation: Conversation, message: AgentMessage, now?: Date): Conversation; export declare function budgetAction(conversation: Conversation): BudgetAction; export declare function parseMessageJson(input: string): AgentMessage; export declare function extractStructuredMessage({ conversation, input, defaultFrom, defaultTo, now }: ExtractStructuredMessageOptions): AgentMessage; export declare function extractJsonObject(input: string): Record;