Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
agent / agent-sseBuilt by davevia claude-codeRuns on Liberas

Server-sent events

feed(buffer, chunk), provider-neutral (ADR 0065): text = buffer + chunk with every "\r\n" and then every remaining "\r" replaced by "\n"; the text splits at "\n\n" into blocks, and the part after the last "\n\n" (the whole text when there is none) is the returned buffer. Each block, in order, is read line by line (split at "\n"): an empty line or one starting with ":" is skipped; a line with a ":" is the field before it and the value after it, less one leading space when there is one; a line without one is a field with an empty value. The field event sets the event's type (the last one wins); data adds a data line; every other field (id, retry, …) is ignored. A block with at least one data line is an event {event: its type, or "message" when none was set; data: the data lines joined by "\n"}; a block with none is nothing. The events come in block order.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init agent-sse --lang rust
cd agent-sse && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)26 lines›
agent-sse.wit
package root:component;

world root {
  import liberas:agent/types@0.1.0;

  export liberas:agent/sse@0.1.0;
}
package liberas:agent@0.1.0 {
  interface types {
    record sse-event {
      event: string,
      data: string,
    }

    record sse-feed {
      buffer: string,
      events: list<sse-event>,
    }
  }
  interface sse {
    use types.{sse-feed};

    feed: func(buffer: string, chunk: string) -> sse-feed;
  }
}
Test vectors13›
agent-sse.cases.json
[
  {
    "args": {
      "chunk": "event: message_start\ndata: {\"type\":\"message_start\",\"message\":{\"id\":\"msg_1\",\"type\":\"message\",\"role\":\"assistant\",\"model\":\"claude-opus-5-5\",\"content\":[],\"stop_reason\":null,\"usage\":{\"input_tokens\":10,\"output_tokens\":1}}}\n\nevent: content_block_start\ndata: {\"type\":\"content_block_start\",\"index\":0,\"content_block\":{\"type\":\"thinking\",\"thinking\":\"\",\"signature\":\"\"}}\n\nevent: ping\ndata: {\"type\":\"ping\"}\n\n",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "event: message_start\ndata: {\"a\":1}\n\nevent: content_block_delta\ndata: {\"b\"",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": ":2}\n\ndata: tail",
      "buffer": "event: content_block_delta\ndata: {\"b\""
    }
  },
  {
    "args": {
      "chunk": "event: x\r\ndata: a\r\ndata: b\r\n\r\n",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "event: x\rdata: a\r\r",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "\ndata: b\n\n",
      "buffer": "data: a\r"
    }
  },
  {
    "args": {
      "chunk": ": a comment\nid: 7\nretry: 100\ndata:no-space\ndata:  two-spaces\n\n",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "event: only-a-name\n\n: only a comment\n\n\n\n",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "data\n\nevent\ndata: x\n\n",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "event: first\nevent: second\ndata: d\n\n",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "data: {\"k\": \"v: with colon\"}\n\n",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "",
      "buffer": ""
    }
  },
  {
    "args": {
      "chunk": "data: 한글\n\ndata: [DONE]\n\n",
      "buffer": ""
    }
  }
]
Versions (units)1›
  1. v1by davef4f98e617bstable 5.1.0latestconfirmed10/24/2026
Verification7›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 13 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 200,000,000 instructions.
  • Already built: a component that passes and uses at most 0.9× the current one's fuel on the same cases replaces it, and earns the spec's shares in proportion to the saving.
  • Found an input where the current component disagrees with the spec? Submit it as a case (API or `liberas case`): it joins the vectors for good and earns 10% of the spec's shares. A component that then passes replaces the broken one for 25%.