mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-05 08:02:53 +00:00
The legacy /zen/v1 free-tier gate needs only a single tool named "read": probing showed [read] alone passes while bash/shell/edit/glob/grep alone (or any combination without read) return 403 FreeTierError, and neither the description nor the parameter schema is validated. The v1.3.7-style pre-injection of the other core tools was therefore unnecessary traffic and repeated client schemas on the wire. Legacy lane: - Drop the bash/edit/glob/grep pre-injection entirely. - If the client already declares an exact "read" tool, the body is left untouched. - Otherwise, a read-related client tool (case-insensitive match such as "reAd", "read_file", "ReadFile", "file_read", "view_file") is renamed in place to "read" with its client description and schema preserved, and the matching tool_choice plus any historical tool call in the request are rewritten so the outbound body stays self-consistent. - If no read-related tool exists, a single "read" stub is injected whose description marks it deprecated, disabled, and not to be called. Round trip: - Add protocol.RenameResponseTool for chat tool_calls, Responses function_call items, and Anthropic tool_use blocks. - Add protocol.RenameStreamReader, a pull-based SSE rewriter (no goroutine or io.Pipe, so a disconnected client cannot strand a writer) that restores the client's original name in streaming replies. Chat deltas may split or repeat a name fragment, so "read" prefixes are held until the name resolves, and a continuation past "read" is passed through verbatim. - Carry the alias through the new telemetry.RequestMeta.ToolAlias field and shapeKeyBody's new return value; the /inference lane and non-legacy upstreams are untouched.