import type { CoreCommandPayload } from "../core-commands.js"; import type { PublicCommandPayload } from "../host/sdk-types.js"; type HostOwnedPublicCommandPayload = Extract< PublicCommandPayload, { kind: "setContainer" | "setDefaultContainerPolicy" } >; export type CoreTranslatablePublicCommandPayload = Exclude< PublicCommandPayload, HostOwnedPublicCommandPayload >; const unreachablePublicCommand = (command: never): never => { throw new Error(`Unsupported public command kind: ${String(command)}`); }; /** * Translate a parsed public command into the payload accepted by core. * * Host-owned container commands intentionally return null because they are * handled by the host adapter rather than forwarded to core. */ export function toCoreCommandPayload( command: CoreTranslatablePublicCommandPayload, ): CoreCommandPayload; export function toCoreCommandPayload( command: PublicCommandPayload, ): CoreCommandPayload | null; export function toCoreCommandPayload( command: PublicCommandPayload, ): CoreCommandPayload | null { switch (command.kind) { case "open": { const { container: _container, ...coreCommand } = command; return coreCommand; } case "prefetch": case "prerender": case "identify": case "track": case "configure": case "init": case "close": case "reset": case "instanceFeedback.capture": case "instanceFeedback.listMine": return command; case "updateHostContext": return { kind: "hostContextUpdated", context: command.context, }; case "emitHostSignal": return { kind: "hostSignal", name: command.name, data: command.data, }; case "setContainer": case "setDefaultContainerPolicy": return null; default: return unreachablePublicCommand(command); } }