/** * BoundMethod → MountableContract translator. * * The narrow view carries only what the server's mount planner reads — * `ref` plus optional `binding` — because the SDK's SdkDispatcher * handles dispatch via KernelAPI.call, not via runtime contract hooks. */ import type { AuthPolicy, FunctionBinding, MountableContract, RouteBinding, } from '@astrale-os/kernel-api/routed' import type { BoundMethod } from '@astrale-os/kernel-core/domain' import type { AnyRemoteHandler } from '../method/single.js' export function toSdkContract(method: BoundMethod): MountableContract { const handler = method.handler as { route?: RouteBinding remoteUrl?: string auth?: AuthPolicy } const binding = extractBinding(handler) return binding === undefined ? { ref: method.ref } : { ref: method.ref, binding } } export function extractBinding(handler: { route?: RouteBinding remoteUrl?: string auth?: AuthPolicy }): FunctionBinding | undefined { const { route, remoteUrl, auth } = handler if (route === undefined && remoteUrl === undefined && auth === undefined) return undefined const binding: FunctionBinding = {} if (remoteUrl !== undefined) binding.remoteUrl = remoteUrl if (route !== undefined) binding.route = route if (auth !== undefined) binding.auth = auth return binding }