import { NappletMessage, SerialEvent, SerialOpenResult, SerialOpenRequest } from '@napplet/core'; export { SerialEvent, SerialOpenOptions, SerialOpenRequest, SerialOpenResult, SerialPortFilter, SerialPortInfo, SerialSession, SerialState } from '@napplet/core'; /** * Napplet NAP serial types entrypoint. * * @module */ /** * @napplet/nap/serial -- Runtime-mediated serial access message types for the JSON envelope wire protocol. * * NAP-SERIAL lets a napplet communicate with user-approved serial devices * without receiving raw browser SerialPort objects, native handles, stream * objects, or OS device paths. The runtime owns device selection, permission * prompts, port lifecycle, reads, write ordering, and policy. * * Defines the message types exchanged between napplet and shell: * - Napplet -> Shell: open, write, close * - Shell -> Napplet: open.result, write.result, close.result, event * * All types form a discriminated union on the `type` field. */ /** The NAP domain name for serial messages. */ declare const DOMAIN: "serial"; /** * Base interface for all serial NAP messages. * Concrete message types narrow the `type` field to specific literals. */ interface SerialMessage extends NappletMessage { /** Message type in "serial." format. */ type: `serial.${string}`; } /** Ask the runtime to select and open a serial port. */ interface SerialOpenMessage extends SerialMessage { type: 'serial.open'; /** Correlation ID for this request. */ id: string; /** Open filters, options, and optional UI label. */ request: SerialOpenRequest; } /** Result of a `serial.open` request. */ interface SerialOpenResultMessage extends SerialMessage { type: 'serial.open.result'; /** Correlation ID matching the original request. */ id: string; /** The opened session. Absent when `error` is present. */ session?: SerialOpenResult['session']; /** Error reason when the runtime could not open a session. */ error?: string; } /** Write bytes to an open serial session. */ interface SerialWriteMessage extends SerialMessage { type: 'serial.write'; /** Correlation ID for this request. */ id: string; /** Runtime-assigned session id. */ sessionId: string; /** Byte values in the range 0..255. */ data: number[]; } /** Result of a `serial.write` request. */ interface SerialWriteResultMessage extends SerialMessage { type: 'serial.write.result'; /** Correlation ID matching the original request. */ id: string; /** Error reason when the runtime could not write the bytes. */ error?: string; } /** Close an open serial session. */ interface SerialCloseMessage extends SerialMessage { type: 'serial.close'; /** Correlation ID for this request. */ id: string; /** Runtime-assigned session id. */ sessionId: string; /** Optional close reason supplied by the napplet. */ reason?: string; } /** Result of a `serial.close` request. */ interface SerialCloseResultMessage extends SerialMessage { type: 'serial.close.result'; /** Correlation ID matching the original request. */ id: string; /** Error reason when the runtime could not close the session. */ error?: string; } /** Shell-pushed serial event. Carries no correlation id. */ interface SerialEventMessage extends SerialMessage { type: 'serial.event'; /** State, data, or closed event. */ event: SerialEvent; } /** Napplet -> Shell serial messages. */ type SerialOutboundMessage = SerialOpenMessage | SerialWriteMessage | SerialCloseMessage; /** Shell -> Napplet serial messages. */ type SerialInboundMessage = SerialOpenResultMessage | SerialWriteResultMessage | SerialCloseResultMessage | SerialEventMessage; /** All serial NAP message types (discriminated union on `type` field). */ type SerialNapMessage = SerialOutboundMessage | SerialInboundMessage; export { DOMAIN, type SerialCloseMessage, type SerialCloseResultMessage, type SerialEventMessage, type SerialInboundMessage, type SerialMessage, type SerialNapMessage, type SerialOpenMessage, type SerialOpenResultMessage, type SerialOutboundMessage, type SerialWriteMessage, type SerialWriteResultMessage };