import type { Shell } from '@astrale-os/shell' export type IntentTarget = | { readonly kind: 'parent' } | { readonly kind: 'child'; readonly windowId: string } | { readonly kind: 'invalid'; readonly reason: string } export function resolveIntentTarget(shell: Shell, to: string | undefined): IntentTarget { if (to === undefined) { return shell.parent !== null ? { kind: 'parent' } : { kind: 'invalid', reason: 'no target — pass opts.to (a child windowId) from a root shell' } } if (to === 'parent') { return shell.parent !== null ? { kind: 'parent' } : { kind: 'invalid', reason: "opts.to 'parent' but this shell has no parent channel" } } return { kind: 'child', windowId: to } }