/** * Remote Substrate, State Sync * * Mirrors remote task and health state into * local runtime store domains (AcpDomainState, TaskDomainState). * * The sync layer is a one-way bridge: remote data flows into local store * domains via the provided mutation callbacks. The store remains the * single source of truth for local rendering, remote state is a projection. */ import type { RemoteTask, RemoteHealth, RemoteSession } from './types.js'; import type { AcpDomainState, AcpConnection } from '../store/domains/acp.js'; import type { RuntimeTask, TaskDomainState } from '../store/domains/tasks.js'; /** * Callbacks supplied by the runtime store to apply state mutations. * * The sync layer never touches the store directly, it calls these * callbacks and lets the store manage its own invariants. */ export interface SyncStoreCallbacks { /** * Update ACP connection entry for the remote session. * * @param agentId - Durable agent ID of the remote connection. * @param patch - Partial AcpConnection fields to update. */ updateAcpConnection(agentId: string, patch: Partial): void; /** * Upsert a remote task into the tasks domain. * * @param task - Remote task snapshot to sync. */ upsertRemoteTask(task: RuntimeTask): void; /** * Mark a remote task as terminal in the tasks domain. * * @param taskId - Task ID to finalize. * @param status - Terminal status. * @param error - Optional error message. */ finalizeRemoteTask(taskId: string, status: Extract, error?: string): void; } /** * RemoteStateSyncer, applies incoming remote state snapshots into local domains. * * Owns the translation from `RemoteTask`/`RemoteHealth` types (remote-facing) * into `RuntimeTask` / ACP domain types (local store-facing). * * @example * ```ts * const syncer = new RemoteStateSyncer(storeCallbacks); * * // Called by the transport layer when a STATE_SNAPSHOT message arrives: * syncer.syncSnapshot(session, incomingTasks, incomingHealth); * * // Called for incremental task updates: * syncer.syncTaskUpdate(session, remoteTask); * ``` */ export declare class RemoteStateSyncer { private readonly callbacks; constructor(callbacks: SyncStoreCallbacks); /** * Sync a full remote state snapshot into local store domains. * * Called when a STATE_SNAPSHOT data message arrives after reconnect sync. * Applies all tasks and the health status in a single pass. * * @param session - Current remote session (provides identity context). * @param tasks - Remote tasks from the snapshot. * @param health - Remote health snapshot. */ syncSnapshot(session: RemoteSession, tasks: readonly RemoteTask[], health: RemoteHealth): void; /** * Sync an incremental task update. * * Called when a TASK_UPDATE or TASK_SUBMIT data message arrives. * * @param session - Current remote session. * @param task - Updated remote task. */ syncTaskUpdate(session: RemoteSession, task: RemoteTask): void; /** * Sync an incremental health update. * * Called when a HEALTH_REPORT data message arrives. * * @param session - Current remote session. * @param health - Updated health snapshot. */ syncHealthUpdate(session: RemoteSession, health: RemoteHealth): void; /** * Sync transport state change into the ACP connection entry. * * Called by the reconnect engine on every state transition. * * @param session - Current remote session. */ syncTransportState(session: RemoteSession): void; private _applyRemoteTask; private _applyHealth; } /** * Returns a no-op SyncStoreCallbacks implementation. * Useful when the store is not yet initialized or sync is disabled. */ export declare function createNoOpSyncCallbacks(): SyncStoreCallbacks; /** * Build an initial AcpConnection domain entry from a remote session. * * Call this when registering a new remote connection with the ACP store domain. * * @param session - Remote session snapshot. * @param label - Human-readable connection label. * @returns An AcpConnection suitable for inserting into AcpDomainState.connections. */ export declare function buildAcpConnectionEntry(session: RemoteSession, label: string): AcpConnection; /** * Count active remote connections in an ACP domain state snapshot. * * @param state - ACP domain state snapshot. * @returns Number of connections that are not yet completing. */ export declare function countActiveRemoteConnections(state: AcpDomainState): number; /** * Extract remote task IDs from a tasks domain snapshot. * * @param state - Tasks domain state snapshot. * @returns Array of task IDs whose kind === 'acp'. */ export declare function extractRemoteTaskIds(state: TaskDomainState): string[]; //# sourceMappingURL=sync.d.ts.map