/** * OpenKernel — MOLTFED / InfiniBot Gateway Connector * * Logs an infinicode node into an InfiniBot gateway over WebSocket and streams * it onto InfiniBot's neural-mesh map + hardware panels — WITHOUT editing * InfiniBot. It speaks InfiniBot's gateway protocol (observed in InfiniBot * src/mcp/server.ts): * * 1. open ws://:18789 * 2. optionally receive event `connect.challenge` → nonce * 3. send { type:'req', id, method:'connect', params:{ minProtocol, client, * auth, role, scopes, device } } * 4. receive `hello-ok` → connected * 5. push request frames: { type:'req', id, method, params } * * Auth is PLUGGABLE (token/password by default; a device-signer can be supplied * for gateways that require signed device identity). Push method names are * CONFIGURABLE so this adapts to a gateway's exact method registry without code * changes. The WebSocket impl is injectable for testing. * * NOTE: verify end-to-end against a live InfiniBot gateway; the frame shapes * here mirror the observed protocol but a given gateway version may differ. */ import type { Logger } from '../types.js'; import type { NodeStatus, HardwareSnapshot, StreamFrame } from './types.js'; /** Minimal browser-style WebSocket surface (Node global WebSocket / ws both fit). */ export interface WsLike { send(data: string): void; close(): void; onopen: ((ev?: unknown) => void) | null; onmessage: ((ev: { data: unknown; }) => void) | null; onclose: ((ev?: unknown) => void) | null; onerror: ((ev?: unknown) => void) | null; } export type WsFactory = (url: string) => WsLike; export interface DeviceAuth { id: string; publicKey: string; /** Sign the connect payload (nonce-bound). Return a signature string. */ sign: (payload: unknown, nonce: string | null, signedAt: number) => string; } export interface MoltfedConnectorOptions { gatewayUrl: string; token?: string; password?: string; client?: { id: string; version: string; platform: string; mode: string; }; role?: string; scopes?: string[]; device?: DeviceAuth; minProtocol?: number; maxProtocol?: number; pushIntervalMs?: number; logger: Logger; /** Data sources — usually bound to a Federation instance. */ getNodeStatuses: () => NodeStatus[]; getHardware: () => HardwareSnapshot | undefined; subscribeFrames: (cb: (peerId: string, f: StreamFrame) => void) => () => void; /** Gateway method names (defaults chosen to match observed InfiniBot usage). */ methodNodes?: string; methodHardware?: string; methodAgent?: string; /** Injectable WS constructor for tests; defaults to global WebSocket. */ wsFactory?: WsFactory; } export declare class MoltfedConnector { private opts; private ws; private connected; private nonce; private connectId; private connectSent; private pushTimer?; private connectTimer?; private unsubFrames?; private stopped; private reconnectAttempts; constructor(opts: MoltfedConnectorOptions); get isConnected(): boolean; start(): void; private open; private onMessage; private buildConnectFrame; private sendConnect; private onConnected; private pushSnapshot; /** Send a request frame (fire-and-forget; gateway acks via res). */ request(method: string, params: unknown): void; private scheduleReconnect; private stopPush; stop(): void; }