@nhtio/adk/batteries/generation/local_diffusion/protocol
Pure protocol constants, frame parsing, and byte-safe line framing for local diffusion backends.
Remarks
The line framer is byte-oriented: it retains raw bytes (never a decoded string), enforces the maxLineBytes cap while consuming input (so an unbounded no-newline write cannot balloon memory), discards the remainder of an over-sized physical line up to its next newline before resuming, and decodes each bounded, complete line with a fatal UTF-8 decoder (invalid encoding → a malformed frame, never a silent mis-parse). parseFrame is total — it classifies every line as a typed frame and never throws.
Type Aliases
| Type Alias | Description |
|---|---|
| DoneFrame | A parsed request completion frame. |
| ErrorFrame | A parsed request error frame. |
| ImageFrame | A parsed image result frame. |
| MalformedFrame | A prefix-matched frame whose fields or JSON do not satisfy the protocol. |
| ModelLoadFrame | A parsed startup model-loading progress frame. |
| ParsedFrame | The total, discriminated result of parsing one backend stdout line. |
| ProgressFrame | A parsed request progress frame. |
| ProtocolConfig | The configurable wire tags used by a local diffusion backend. |
| ProtocolErrorFrame | A stream-level protocol problem, such as an over-sized line. |
| ReadyFrame | A parsed backend-ready frame. |
| UnknownFrame | A frame with a tag this protocol version does not understand. |
Variables
| Variable | Description |
|---|---|
| DEFAULT_PROTOCOL | The DiffusionBee-compatible default local diffusion protocol configuration. |
Functions
| Function | Description |
|---|---|
| buildEditCommand | Build an edit command frame, including its terminating newline. |
| buildGenerateCommand | Build a generate command frame, including its terminating newline. |
| buildShutdownCommand | Build a backend shutdown command frame, including its terminating newline. |
| buildStopCommand | Build a best-effort stop command frame, including its terminating newline. |
| createFrameReader | Create an incremental, byte-oriented line reader. Raw bytes are retained (never a decoded string), the maxLineBytes cap is enforced while consuming so an unbounded no-newline write cannot balloon memory, an over-sized physical line reports exactly one protocolError and is then discarded through its next newline (its continuation is NOT re-parsed as a fresh frame), and each bounded, complete line is decoded with a fatal UTF-8 decoder — invalid encoding yields a malformed frame. Malformed protocol lines are reported as malformed rather than thrown. |
| parseFrame | Parse one already-split backend stdout line into a typed ParsedFrame. Total by contract — it never throws: malformed input yields a malformed/unknown frame, and a runtime-invalid or hostile config (null, partial, or a throwing accessor) is caught and reported as malformed. |