// Frames on the agent socket. The agent dials out, so the instance never needs // to reach a machine behind NAT and the browser never talks to localhost. export type BuildRequest = { type: 'build'; id: string; fqbn: string; sketch: string; }; export type CloudFrame = BuildRequest | { type: 'ping' }; export type AgentFrame = | { type: 'hello'; version: string; platform: string; arch: string; cli: string | null } | { type: 'log'; build: string; line: string } | { type: 'result'; build: string; ok: true; fqbn: string } | { type: 'result'; build: string; ok: false; error: string }; export function parseCloudFrame(raw: string): CloudFrame | null { let msg: unknown; try { msg = JSON.parse(raw); } catch { return null; } if (!msg || typeof msg !== 'object') return null; const m = msg as Record; if (m['type'] === 'ping') return { type: 'ping' }; if (m['type'] !== 'build') return null; const { id, fqbn, sketch } = m; if (typeof id !== 'string' || typeof fqbn !== 'string' || typeof sketch !== 'string') return null; return { type: 'build', id, fqbn, sketch }; }