import * as v from "valibot" import { customBlockReadyErrorSchema } from "../loadManifest.js" import { manifestSchema } from "../manifest.js" const readyMessageCommonEntries = { type: v.literal("ready"), /** * Used to ensure that the host and client are using the same version of the bridge protocol. A * single host needs to support multiple custom blocks built with different versions of the bridge * protocol. Increment this number any time a breaking change is made to the bridge protocol. */ bridgeProtocolVersion: v.number(), /** * Semver version of the SDK package that sent this ready message. Should only be used for * analytics purposes. Business logic should compare against `bridgeProtocolVersion` instead. */ sdkVersion: v.string(), } /** * First message the sandbox sends after mount, kicking off the bridge handshake. The host replies * with `init`. */ export const readyMessageSchema = v.union([ v.object({ status: v.literal("success"), /** * The data sources and settings the custom block expects, or null when the * block has no manifest and no declared data requirements. */ manifest: v.union([manifestSchema, v.null_()]), ...readyMessageCommonEntries, }), v.object({ status: v.literal("error"), error: customBlockReadyErrorSchema, ...readyMessageCommonEntries, }), ]) export type ReadyMessage = v.InferOutput