/** * Intent envelope construction (API §11). The typed payload/reply projections of * a registry entry, the wire constants, and `intentMessage` — the single builder * both directions (send + reply) share. */ import type { IntentMessage, IntentRegistry, PayloadOf, ReplyOf } from '@astrale-os/shell' /** Payload declared by the canonical Shell intent registry entry. */ export type IntentPayload = PayloadOf /** Reply declared by the canonical Shell intent registry entry. */ export type IntentReply = ReplyOf /** Sentinel `ctx.sender` carries for a parent-delivered intent (the shell stamps it). */ export const PARENT_SENDER = '' /** Outbound `sender.windowId`; the receiver re-stamps it with the trusted id. */ const SELF_SENDER = 'self' /** Correlated-reply channel name (the shell's fire-and-forget reply protocol). */ export const INTENT_REPLY = 'intentReply' export const NOOP = (): void => {} /** * Build an intent wire message. The cast bridges the correlated name↔payload * relation that the generic union type cannot express. */ export function intentMessage( name: string, payload: unknown, correlationId?: string, ): IntentMessage { return { type: 'intent', version: 1, envelope: { name, payload, sender: { windowId: SELF_SENDER }, correlationId }, } as IntentMessage }