Commit Graph
20 Commits
Author SHA1 Message Date
Jason Xu fd4c1c6d40 feat(free-tier): prefix client tools with clint_ and complete the official set
Shaped free-model requests now look like an official CLI session on every
lane. Each client tool is renamed to a sanitized, collision-free clint_ name
and the full official tool set for the lane is appended (11 tools on the 1.x
/zen lane, 13 on 2.x /inference and /zen/go). Requests without tools, with an
empty array, or with a legacy functions array receive the official set too,
and tool_choice, function_call and the tool-call history are rewritten to
match.

Responses, streaming and not, are restored to the names the client declared,
including a Chat in a stream split across chunks. Unmapped names pass through,
so an official tool the client never declared is never hidden or replayed.
2026-10-25 05:58:02 +08:00
Jason Xu 394acb5de3 fix(protocol): preserve explicit reasoning disable (#150) 2026-10-23 08:38:15 +08:00
Jason Xu a70e77fe62 Fix audited gateway issues 2026-10-19 05:27:50 +08:00
Jason Xu 81ad2842c7 refactor: drop new prefixes, unify v1/v2 lane naming, audit comments
- Remove the new/New prefix from constructors; rename the colliding
  types semantically (ModelCatalog, RuntimeController, Metrics,
  LogBroker, Redactor, proxyTransports, upstreamNodes, ...).
- Unify upstream lane naming on v1 (/zen, OpenCode 1.x shape) and v2
  (/inference and /zen/go, 2.x CLI shape); add models.IsV1Upstream and
  drop the duplicated lane detection.
- Fix inaccurate, truncated and stale comments across all packages and
  document exported symbols plus non-obvious internals.
- Fix anthropicThinking passing "enabled"/"adaptive" through as an
  effort; derive the level from the budget instead.
- Delete dead code (identity.StableID, unused protocol decoders and
  stream parser wrappers).
- Export EffectiveListeners, rename modelsDev* metadata constants, and
  describe the metadata source as the OpenCode endpoint.
- Rename the forced-collapse log event to stream_collapse_failed and
  add an anonymous field.
- Correct the README upstream.zen default and add upstream.anonymous.
2026-10-19 03:46:09 +08:00
Jason Xu a9470df4fc fix(upstream): alias the client read tool to "read" on the legacy /zen/v1 lane
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.
2026-10-17 07:13:19 +08:00
Jason Xu 6d83806939 fix(protocol): skip non-function Responses tools during cross-protocol bridging
Closes #95
2026-10-17 02:09:55 +08:00
Jason Xuandahoo 7a6c1f9386 fix: floor responses max_output_tokens to 16 for tiny budgets (#63)
Zen's Responses endpoint rejects max_output_tokens below 16, and clients
such as Claude Code send tiny budgets for background tasks. The 400 was
retried across every anonymous exit before reaching the client. Raise
budgets in (0, 16) to 16 on both the bridged and the same-protocol
Responses paths; nil and larger budgets pass through unchanged.

Co-authored-by: ahoo <ahoo@hroze.org>
2026-10-15 07:52:13 +08:00
Jason Xu 77818beb02 chore: drop tool image tests merged with #62 2026-10-15 02:30:31 +08:00
ai-daming e98f386712 fix: preserve images in cross-protocol tool results 2026-10-10 11:01:03 +08:00
Jason Xu 31c35704be Merge pull request #36: model rotation, quotas and API key management 2026-10-07 19:37:30 +08:00
sk-dev-ai 51639af3ef chore: remove orphaned stream helpers
transcodeStream, transcodeStreamWithUsage, forwardSSEWithUsage and
forceStreamBody have no callers since the package refactor; the live
paths use the request-aware TranscodeStream/ForwardStream and
prepareAnonymousBody directly. Also fix the stale comment reference.
2026-10-04 19:56:41 +05:30
asas6661 4fed6e4d31 feat: serve System One decision models on /v1/systemone
OpenCode Zen publishes System One models (jev-1.13, jev-1.13-free) on a
/v1/systemone endpoint. A request pairs a free-form state with typed
questions and the reply carries typed answers, so the payload shares no
shape with the chat/responses bridge and cannot be translated.

- protocol: add SystemOne with its endpoint path.
- discovery: read "systemone" rows from the upstream endpoint tables so
  those models stop being bucketed as unsupported.
- gateway: add POST /v1/systemone, which relays the body verbatim
  through the existing tier and anonymous machinery and returns the
  answer document unchanged. Models on another protocol are rejected
  with a clear error instead of being forwarded to a message API.
- anonymous lane: keep System One bodies verbatim. Forcing streaming or
  injecting the core agent tools, which the free tier requires for chat
  traffic, would invalidate a decision request.

Verified end-to-end against the live upstream: jev-1.13-free answers
through the gateway with cost 0, chat and responses models keep working,
and the endpoint rejects mismatched payloads.
2026-09-23 12:11:45 +08:00
Jason Xu 683b7e9af0 feat: expose configurable reasoning effort 2026-09-21 14:34:00 +08:00
haverainlilili 3440273f43 feat: 新增模型轮转、额度看板和密钥管理 2026-09-21 10:18:21 +08:00
Jason Xu 41b9453d42 fix: demote phantom tool_use stop when no tool block was assembled
Merge pull request #27
2026-09-19 13:05:36 +08:00
Jason Xu 82e88f2b7f fix: filter phantom non-stream tool blocks 2026-09-19 12:46:32 +08:00
sk-dev-ai 3f8763d9da feat: forward native cache-affinity knobs (prompt_cache_key et al)
Native opencode sends prompt_cache_key (session-sliced ID), plus
safety_identifier, store, and service_tier. The translator dropped
all four, so proxied turns never rode prompt-cache affinity while
native did. Decode, carry, and re-emit on both Chat and Responses
paths, omit-when-absent. Verified live: same-session turns hit 99%
cached upstream after warm-up.
2026-09-18 19:39:17 +05:30
58 2ce1f9e44b fix: serve anonymous free tier as agent-shaped streams
Upstream now rejects anonymous free-tier requests unless they look
like real agent traffic: stream:true plus the core agent tools
(bash/edit/glob/grep/read), returning 403 FreeTierError otherwise.

Normalize the anonymous-lane wire body (force stream:true, inject
minimal definitions for any missing core tools) and collapse the
SSE stream back into the single JSON document non-streaming
clients asked for. Authenticated tiers are untouched.
2026-09-18 09:09:20 +08:00
xiechen 278b0bb8e2 fix: demote phantom tool_use stop when no tool block was assembled
Upstream Chat/Responses turns sometimes end with finish_reason
tool_calls while delivering no usable tool call (empty tool_calls
array, or deltas without a name). The bridge forwarded that as
stop_reason tool_use with zero tool_use content blocks. Strict
clients then end the turn running nothing and reporting no error,
which stalls agent loops mid-task with no visible failure.

Guard both the streaming (Finish) and non-streaming
(encodeBridgeResponse) paths: a tool stop with no assembled tool is
demoted to a plain stop so the client treats it as text end-of-turn
and continues.
2026-09-15 18:06:45 +08:00
Jason Xu 46def7fedc refactor: organize Go packages and remove test files
Move the command to cmd/opencode2api and group production code into
configuration, gateway, protocol, model, admin, telemetry and helper packages.
Keep shared state private behind context, metrics and runtime interfaces.

Remove the requested test files and replace test-only CI jobs with vet/build
checks. Update Docker and release build paths, preserve version injection and
make the WebUI an explicit embedded asset package.

Add directory trees and source reading guides to both READMEs. Anchor binary
ignore rules so the command package is tracked.
2026-09-15 01:28:44 +08:00