import { type MessageFamily } from "./families.ts"; /** * Minimal per-family payload contract. This is the wire-level shape every * family module (S1 hub, S2 presence, S3 vocab, S5 relay, S7 blackboard) builds * on — the single source of truth for the payload of each message family, held * to by both this repo's codec and the c8ctl client. * * Validators are STRUCTURAL and forward-compatible: they require the core * fields with correct types and otherwise tolerate additional properties, so a * later slice may enrich a payload without breaking older peers. * * Capability (cognition/weight/family/host) travels on `register` as an * enrolment attribute — it is NEVER a routing token. */ export interface Capability { readonly cognition?: string; readonly weight?: number; readonly family?: string; readonly host?: string; } export interface RegisterPayload { readonly instance: string; readonly capability: Capability; } export interface HeartbeatPayload { readonly instance: string; } export interface DeregisterPayload { readonly instance: string; readonly reason?: string; } export interface ServePayload { readonly instance: string; readonly tokens: readonly string[]; } export interface DemandPayload { readonly network: string; readonly missing: readonly string[]; } /** * A worker declares it now OWNS a job. `claim` opens the authoritative ownership * window; its matching {@link ReleasePayload} closes it. `instance` is the * OWNING worker — carried EXPLICITLY in the frame, never inferred from the * connection id — which is what lets one supervisor connection multiplex the * ownership frames of N distinct workers. Idempotent: a duplicate `claim` for * the same `{ instance, jobKey }` is a no-op re-assertion. */ export interface ClaimPayload { readonly instance: string; readonly jobKey: string; } /** * A worker declares it has RELEASED a job (the job finished, failed, or moved * on). Idempotent: a duplicate or late `release` — including one with no * preceding `claim` — is a no-op. `instance` is carried explicitly, exactly as * for {@link ClaimPayload}. */ export interface ReleasePayload { readonly instance: string; readonly jobKey: string; } export type BlackboardOp = "append" | "read"; export interface BlackboardPayload { readonly op: BlackboardOp; readonly dedupeKey?: string; readonly since?: number; } /** * The `relay` family multiplexes two roles on one message family: * * - CONTROL frames a peer sends the hub: a producer's {@link RelayProducePayload} * (`op: "produce"`), and a consumer's {@link RelaySubscribePayload} / * {@link RelayCreditPayload}. * - DELIVERY frames the hub sends a consumer: a data chunk ({@link RelayPayload}, * no `op`) and a resume ack ({@link RelaySubscribedPayload}, `op: "subscribed"`). * * {@link RelayPayload} is the DELIVERY data chunk specifically (`{ stream, offset, * chunk }`, no `op`) — the hub assigns the authoritative `offset` from its ring. * A producer must NOT send this shape; it sends {@link RelayProducePayload}. */ export interface RelayPayload { readonly stream: string; readonly offset: number; readonly chunk: string; } /** A producer appends bytes to a stream. `incarnation` is the producer's * generation, stamped so the hub can fence a stale predecessor (a retried job on * a fresh runner takes over with a strictly higher incarnation). The hub assigns * the offset — a producer never carries one. */ export interface RelayProducePayload { readonly op: "produce"; readonly stream: string; readonly incarnation: number; readonly chunk: string; } /** A consumer subscribes to a stream, optionally resuming from `from` with an * initial `credit` budget. */ export interface RelaySubscribePayload { readonly op: "subscribe"; readonly stream: string; readonly from?: number; readonly credit?: number; } /** A consumer replenishes its flow-control budget. */ export interface RelayCreditPayload { readonly op: "credit"; readonly credit: number; } /** The hub's ack to a subscribe: `gap` is true when `from` predated the retained * ring (bytes were missed), `nextOffset` is where delivery resumes. */ export interface RelaySubscribedPayload { readonly op: "subscribed"; readonly stream: string; readonly gap: boolean; readonly nextOffset: number; } export interface PayloadError { readonly code: string; readonly message: string; } export type PayloadValidationResult = { readonly ok: true; } | { readonly ok: false; readonly errors: readonly PayloadError[]; }; /** * Validate a decoded payload against its family's minimal contract. */ export declare function validatePayload(family: MessageFamily, payload: unknown): PayloadValidationResult;