import type { RailDeckDirectIntegrationClient as Client } from '@raildeck/frontend-sdk/direct-integration'; /** * Send an explicitly requested emergency Stop without delaying it for another read. * @param client - Configured client; the caller owns current authority. * @param accountId - Authorised account for this workflow. * @param layoutId - Explicitly selected layout within the account. * @param controllerId - Explicitly selected command station. * @param track - Selected track output; this helper only requests power off. * @returns The SDK command response; physical Stop still needs its own evidence. */ export async function stopSelectedTrack( client: Client, accountId: string, layoutId: string, controllerId: string, track: string, ) { return client.liveCommands.emergencyStop(accountId, controllerId, layoutId, track); } /** * Recover the original accessory command and read the current layout observation. * @param client - Configured client; the caller owns current authority. * @param accountId - Authorised account for this workflow. * @param layoutId - Explicitly selected layout within the account. * @param controllerId - Explicitly selected command station. * @param commandId - Original command identity; never replace it to retry. * @param signal - Caller-owned cancellation signal. * @returns Both observations without submitting a replacement command or replaying movement. */ export async function recoverAccessoryOutcome( client: Client, accountId: string, layoutId: string, controllerId: string, commandId: string, signal: AbortSignal, ) { const options = { signal, timeoutMs: 15_000 }; const outcome = await client.liveCommands.recoverAccessoryCommand( accountId, controllerId, commandId, { layoutId }, options, ); const snapshot = await client.currentState.getLayoutSnapshot(accountId, layoutId, options); return { outcome, snapshot }; }