Parser Wiredoc/{zh,en}/guide/parser-protocol.md

Parser Protocol

Status: built 2026-12-03 (media harness review M-15), api v1. How a media parser (ADR 0018) is written as a process plugin, in any language. The framing, lifecycle and errors commo

Status: built 2026-12-03 (media harness review M-15), api v1. How a media parser (ADR 0018) is written as a process plugin, in any language. The framing, lifecycle and errors common to every method are in the plugin protocol; the schemas are schemas/protocol/v1/parser.parse.json and host.read_artifact.json. plugins/parse-sample is a complete example in Go that uses only the standard library and the wire protocol.

1. What the Host Does

The Host tells a file's type from its bytes, chooses a parser for it, runs the parser under the parse time limit, validates and caches the document it returns, and renders it for the model. A process parser is chosen exactly like a builtin one: by the types it accepts, its tier, and media.allow. Nothing in the Host names a process parser.

text
Host                                        parser process
 │ parser/parse {call_id, parser, file, range}  │
 │────────────────────────────────────────────►│
 │      host/read_artifact {call_id, ref, offset, length}
 │◄────────────────────────────────────────────│  (as often as it needs)
 │ {data, eof} ───────────────────────────────►│
 │◄──────────── media.Document ────────────────│
 │ validate, cache per user, render            │

2. Manifest

yaml
1execution: process
2roles: [parser]
3parsers:
4  - id: sampletab
5    accepts: [application/x-orquelo-sample-table]
6    produces: [tables]
7    magic: [{offset: 0, hex: "4f525154414200", mime: application/x-orquelo-sample-table}]
FieldMeaning
idThe parser's name in media.allow and in a document's chain. An id a builtin parser has is ignored (the builtin keeps it)
acceptsThe sniffed types it reads, as path.Match patterns
producesWhat it gives: text, tables, layout, ocr, transcript
tierfast (default), local, model or cloud; cheaper tiers are tried first
partsIt reads a span of pages on request (range.from, range.to), so a large file is read 50 pages at a time
languagesRecognition languages a call may name
modelsLocal models the configuration may choose among, each {name, download} (bytes downloaded on first use, 0 when shipped), the first the default; read for builtin parsers of speech only (media.speech), so a process parser's list is not used yet
magicTeaches the Host its own format: the bytes at offset (within the first 4 KiB), in hex, mean mime, which must be one it accepts. A signature applies only when the Host's own sniffing finds unknown bytes (application/octet-stream) or plain text, and only while media.allow allows the parser: it never retypes a PDF, a ZIP or any type the Host knows

The instance is configured, approved and selected like any process plugin: plugins: [{id: sample, plugin: parse-sample}], orquelo plugin approve parse-sample, and media.allow naming the parser id or the instance id (an empty media.allow allows every parser). orquelo media parse -c CONFIG starts the configuration's process parsers too.

3. Methods

parser/parse (Host → plugin, role parser), ParserParseParams → media.Document:

FieldMeaning
call_idScopes host/read_artifact to this call
parserWhich parser of the manifest
file{ref, name, mime, size}: ref names the file for host/read_artifact in this call only; mime is the type the Host sniffed; name is what the sender called it, a hint, never the type
range{from, to} pages (1-based, for a parser with parts), {sheet or sheet_name, row_from, row_to} rows of a sheet, {time_from, time_to} seconds of a recording, and frame_every, the longest gap in seconds between a video's frames (0 for the parser's own; sent since 2026-12-05, review #264 B11); zero reads all. A parser ignores what it does not read
wantWhat is asked beyond the usual reading: ocr (the text of an image as written), transcript
language, max_memoryA recognition language from languages; a memory bound in bytes (0 for the parser's default)

The result is the media.v1 document a builtin parser returns: blocks (heading, paragraph, list_item, table, code, figure, page, quote, header, footer, transcript, keyframe; for a format with pages each block may give its box on the page, x, y, width, height from its top-left corner in points or pixels, and a table its cell_boxes; a table read from a chart carries chart, its kind, title, axis titles, name and whether its values are estimated from a picture), meta, outline, source.pages, quality, partial, and unread_pages, the pages not read in full; a parser that gives them gives them all, so a page range of other pages is not partial and one of only those pages, none read, is an error (Feishu #431). A block's page is the page it stands on; a table read across pages stands on its first and gives its last as last_page, its rows from the pages after read with it (the Host joins the tables of pages it reads from their images itself). The Host fills source (name, type, size) and chain; a parser's own are ignored. A file it cannot read is a plugin error with a media.* code, or a document with error set.

host/read_artifact (plugin → Host, within parser/parse), HostReadArtifactParams {call_id, ref, offset, length} → {data, eof}: at most length bytes from offset, data in base64; fewer at the end, which eof marks. There is no path: the bytes are the only way to the file.

4. Limits and Timeouts

LimitValue
One host/read_artifact1 to 4 MiB (MaxRead); offset from 0 to the file's size; only the call's ref; only while the call is in flight
The replyAt most 16 MiB of JSON (MaxDocument); a message over 32 MiB (MaxFrame) ends the connection
The documentSchema media.v1 (or empty), known block types, at most 200,000 blocks, 2,000,000 table cells and 10,000,000 pages, no negative numbers, finite times and boxes, no box of negative size, error codes media.*
TimeThe parse time limit every parser has: 2 minutes in the Host, 5 minutes for orquelo media parse, within what is left of the run

5. Failures

Each failure ends that parse only; other parses, other plugins and the Host go on.

What happensThat parseThe process
The plugin returns an error with data.code media.malformed (any media.*)Fails with that code and messageKeeps running
The plugin returns an error with another codemedia.parser_failed, naming itKeeps running
The reply is not a document, or does not validatemedia.parser_failed, naming the first faultKeeps running
The reply is over 16 MiBmedia.too_largeKeeps running
The process exits, or sends a message over 32 MiBmedia.unavailable, not cachedRestarted on the next call (after 2, 4 … s up to 1 min when starts keep failing)
No reply before the time limitmedia.timeout, not cachedKilled (other parses in flight in it fail as above); restarted on the next call

A failed parse is a document with error, as for builtin parsers; the model reads the code and a hint, and the file stays readable by asking again.

6. Example Trace

text
→ {"jsonrpc":"2.0","id":7,"method":"parser/parse","params":{"call_id":"c3","parser":"sampletab",
   "file":{"ref":"file-3","name":"table.dat","mime":"application/x-orquelo-sample-table","size":92}}}
← {"jsonrpc":"2.0","id":1,"method":"host/read_artifact","params":{"call_id":"c3","ref":"file-3","offset":0,"length":65536}}
→ {"jsonrpc":"2.0","id":1,"result":{"data":"T1JRVEFCAAEGQ2l0aWVz…","eof":true}}
← {"jsonrpc":"2.0","id":7,"result":{"schema":"media.v1","meta":{"title":"Cities","rows":4,"columns":3},
   "blocks":[{"type":"heading","level":1,"text":"Cities"},{"type":"table","rows":[["city","country","population"],…]}]}}

A damaged file instead ends with ← {"jsonrpc":"2.0","id":7,"error":{"code":-32000,"message":"bad column count","data":{"code":"media.malformed","message":"bad column count"}}}, and the model is told the file is damaged. If the process had died instead, the parse would end with media.unavailable and the next parser/parse would start the process again before it is sent.