1 ; inf3r peer protocol — wire 2 (wire 1 remains valid)2 ;3 ; The header is binary and is not CBOR:4 ;5 ; u32 length (little-endian) payload bytes, header excluded, at most 0xFFFFFF6 ; u16 stream (little-endian) 0 = session frame7 ; u8 type frame type from this grammar8 ; u8 flags must be 09 ;10 ; One frame = one message. The body is one CBOR item of the type that the11 ; header names. Payloads inside `event`, `done`, and `open` parts are opaque12 ; byte strings. This grammar never describes them.13 14 wire = 215 ; A peer range [1, 2] is legal. Cache frames exist only on 2.16 17 ; ---- session ---------------------------------------------------------------18 19 hello = { v: version-range, role: "call" / "serve", id: tstr }20 version-range = [ min: uint, max: uint ]21 welcome = { v: uint, max_inflight: uint }22 catalogue = { target: target, models: [* model],23 ? runtime: runtime, ? cache: cache-spec }24 target = { id: tstr, backend: tstr, arch: [* tstr], devices: uint,25 vram_mb: [* uint] }26 runtime = { name: tstr, version: tstr }27 cache-spec = {28 codec_version: uint,29 slots: uint,30 state_kind: "prefix_truncatable" / "checkpoint_exact",31 max_entry_bytes: uint,32 local_ram_bytes: uint,33 supports_save: bool,34 supports_restore: bool,35 supports_erase: bool36 }37 model = { serve: tstr, alias_of: tstr / null, weights_bytes: uint,38 load_ms: uint,39 capabilities: { * tstr => capability } }40 capability = { vocab: tstr, parts: [* part-kind], channels: [* tstr],41 limits: { * tstr => uint }, cancel: cancel-mode,42 stops: stops-owner, queue: queue-mode }43 ; token, frame, request. A peer keeps an unknown word as written.44 cancel-mode = tstr45 ; plugin, native, none. A peer keeps an unknown word as written.46 stops-owner = tstr47 ; none, internal. A peer keeps an unknown word as written.48 queue-mode = tstr49 part-kind = "text" / "image" / "audio" / "video" / "tokens" / "json"50 51 grant = { deps: [* dependency] }52 dependency = { role: tstr, fd: uint, len: uint, path: tstr }53 54 ready = { load_ms: uint, ? cache_fingerprint: bstr .size 32 }55 window = { credit: uint }56 ping = { t: uint }57 pong = { t: uint }58 bye = { reason: tstr }59 fatal = { code: error-code, detail: tstr / null }60 61 ; ---- job -------------------------------------------------------------------62 63 open = { request_id: tstr, model: tstr, capability: tstr,64 credit: uint, budget_ms: uint,65 parts: [* part], params: any }66 part = { kind: part-kind, mime: tstr, role: tstr / null, len: uint,67 ( inline: bstr // fd: uint ) }68 69 accept = { est_ms: uint / null }70 event = { ch: tstr, mime: tstr, data: bstr }71 done = { outcome: outcome, artifacts: [* artifact],72 usage: { * tstr => uint },73 ? meta: { * tstr => any } }74 artifact = { ch: tstr, mime: tstr, len: uint,75 ( inline: bstr // fd: uint ) }76 reject = { code: error-code, detail: tstr / null }77 cancel = { reason: tstr }78 79 ; ---- cache (wire 2, stream 0) ---------------------------------------------80 81 cache_lookup = { req_id: uint, keys: [+ bstr .size 32],82 ? lineage: bstr .size 32 }83 cache_lookup_res = { req_id: uint,84 hit: null / {85 key: bstr .size 32, lease_id: uint, bytes: uint,86 crc32c: uint, token_count: uint, tier: tstr, fd: uint87 } }88 cache_release = { lease_id: uint, ok: bool, restore_ms: uint, abandoned: bool }89 cache_reserve = { req_id: uint, key: bstr .size 32,90 ? lineage: bstr .size 32,91 ? supersedes: bstr .size 32,92 kind: "tip" / "anchor", est_bytes: uint,93 prefill_ms: uint, token_count: uint, pin: bool }94 cache_grant = { req_id: uint,95 grant: null / {96 lease_id: uint, max_bytes: uint, tier: tstr, fd: uint97 },98 ? reason: tstr }99 cache_commit = { lease_id: uint, ok: bool, bytes: uint, crc32c: uint,100 token_count: uint, save_ms: uint }101 cache_flush = { req_id: uint, budget_ms: uint }102 cache_flushed = { req_id: uint, saved: uint, skipped: uint,103 dirty_remaining: uint }104 105 outcome = "completed" / "failed" / "cancelled" / "expired"106 107 error-code = "version" / "frame" / "stream" / "size" / "credit" / "busy"108 / "unknown_model" / "capability" / "part" / "dependency"109 / "timeout" / "cancelled" / "internal"