Files
opencode2api/internal/jsonutil
FLYFandAiFLYF 5c5100c470 feat(upstream): match the 2.x client's chat body byte for byte (#142)
The v2 gate fingerprints the body as well as the headers, and five details
still differed from a captured 2.1.1 request:

- The client sends max_completion_tokens: 32000 on every chat body. The
  gateway now adds it when the caller asked for no ceiling; an explicit
  max_tokens or max_completion_tokens still wins.
- Every client tool carries "strict": false, so a tool that omits the field
  is byte-different from the client's on every request that carries tools.
- The shell tool description names the shell the client actually has, so a
  Windows host advertises a different one than the captured Unix wording.
- Chat bodies keep the client's key order, model first. Go writes map keys
  alphabetically, which puts max_completion_tokens at the front where a real
  client starts with model.
- Bodies are encoded without HTML escaping. encoding/json writes \u003c,
  \u003e and \u0026 by default where JSON.stringify writes the characters,
  and tool descriptions are full of both.

The ordered encoder falls back to plain encoding/json for every lane except
the v2 chat one, and both re-encode points in the request path use it.

Co-authored-by: AiFLYF <AiFLYF@users.noreply.github.com>
2026-10-23 09:24:20 +08:00
..