/** * Reply delivery (API §11) — route a correlated reply to whichever channel the * request arrived on (parent vs a child window). Best-effort: a gone counterparty * drops the reply safely (counterparty-death cleanup). */ import type { Shell } from '@astrale-os/shell' import { INTENT_REPLY, PARENT_SENDER, intentMessage } from './envelope.js' /** Deliver a reply to whichever channel the request arrived on. Best-effort. */ export function sendReply( shell: Shell, sender: string, correlationId: string, result: unknown, ): void { const message = intentMessage(INTENT_REPLY, { correlationId, result }) try { if (sender === PARENT_SENDER) shell.parent?.send(message) else shell.children.send(sender, message) // no-op if the child has detached } catch { // Counterparty gone — the reply is safely dropped. } }