Commit Graph
73 Commits
Author SHA1 Message Date
Jason Xu 3cb9837d25 Merge pull request #49: remove orphaned stream helpers 2026-10-07 19:34:34 +08:00
Jason Xu c6797b73af Merge pull request #50: record per-attempt legs 2026-10-07 19:34:34 +08:00
Jason Xu 2603eff66a Merge pull request #53: fill missing model limits 2026-10-07 19:34:34 +08:00
CheerC 5dddf26d1e feat: fill missing model limits from models.dev
`/v1/models` only advertised context and token limits for models that
OpenCode's capability catalog describes. Everything else fell back to the
defaults a discovery client hardcodes (128k context / 16k output), which
made every such model look identically small to CLIProxyAPI and Pi.

models.dev already publishes `limit.context`, `limit.input` and
`limit.output` for the OpenCode providers, and the gateway already fetched
that file for pricing and deprecation only. Store those limits in the
metadata cache and fill the fields the capability catalog omitted.

The capability catalog stays authoritative: capability flags always come
from it, and a limit it published is never overwritten. This also merges
the other OpenCode provider tiers instead of returning the first provider
alone, so models that only one tier describes keep their cost, anonymous
eligibility and limits.

Clients holding a metadata cache written by an earlier build keep their
old data until the next refresh; deleting config.json.models.dev.json
forces an immediate refetch.
2026-10-06 18:03:51 +08:00
sk-dev-ai 4c4e6b10d7 log: record per-attempt legs on the request line
Fill in the Legs field the request log already renders: append one
key:status:ms entry per upstream attempt (anonymized label for the
public lane, redacted key suffix otherwise; timeout/transport markers
for errors). A multi-attempt turn now reads as a single chain instead
of requiring attempt-log correlation.
2026-10-04 19:57:11 +05:30
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
Jason Xu 79a208a467 Merge pull request #41 from asas6661/feat/systemone-protocol
feat: serve System One decision models on /v1/systemone
v1.3.5
2026-09-23 14:05:01 +08:00
asas6661 a65ff83d71 feat: accept decision payloads on message endpoints too
The dedicated /v1/systemone route is the correct surface, but many
deployments only reach the gateway through an OpenAI-shaped proxy that
pins every request to /v1/responses (sub2api forwards OpenAI-platform
accounts to Responses only). Such a proxy can never address
/v1/systemone, so a System One model stays unreachable even though the
gateway supports it.

Route System One models through the same verbatim relay when they are
requested on /v1/chat/completions or /v1/responses. The payload still
carries state and typed questions; nothing is converted, and models on
another protocol keep their normal bridge path.

Verified through a sub2api group pointed at this gateway:
  POST /v1/responses {"model":"jev-1.13-free","state":"...",
                      "questions":{"is_urgent":{"type":"noul",...}}}
  -> 200 {"answers":{"is_urgent":{"noul":0.94}},"cost":"0"}
Sending the decision fields alongside OpenAI message fields does not
work: the proxy rewrites the body and the decision fields are lost, so
the relayed request is rejected upstream.
2026-09-23 13:35:30 +08:00
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 c75a792b8c Revert "fix: drop unsupported tools for Mimo 2.6 Flash"
This reverts commit 7194c49452.
2026-09-23 10:11:40 +08:00
Jason Xu 7194c49452 fix: drop unsupported tools for Mimo 2.6 Flash 2026-09-23 10:00:36 +08:00
Jason Xu 3fb18e1950 fix: set example reasoning defaults 2026-09-21 14:50:33 +08:00
Jason Xu 8e776c43b5 style: format webui and documentation v1.3.4 2026-09-21 14:38:30 +08:00
Jason Xu 683b7e9af0 feat: expose configurable reasoning effort 2026-09-21 14:34:00 +08:00
Jason Xu e5f4e3a583 fix: shape key-tier free-model bodies to agent shape
Merge pull request #33
v1.3.3
2026-09-19 13:05:54 +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 2be83f9796 feat: forward native cache-affinity knobs (prompt_cache_key et al)
Merge pull request #34
2026-09-19 13:04:04 +08:00
Jason Xu b689a5b3a6 fix: preserve Chat usage for shaped free requests 2026-09-19 12:46:32 +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
sk-dev-ai 79378c8744 fix: shape key-tier free-model bodies to agent shape
Upstream now rejects non-agent-shaped free-tier requests on every lane
with 403 FreeTierError (#29); #31 covered the anonymous lane only, so
keyed-only configs still 403 on bare probes. Mirror the normalization
(stream + core agent tools) for catalog-free models on key tiers; paid
bodies untouched. Non-streaming clients get the same stream collapse
as the anonymous lane. Free check uses catalog pricing metadata, not
the -free name, so nameless free models are covered.
2026-09-18 19:38:29 +05:30
Jason Xu 5cf3b590ee Merge pull request #31 from smile89/fix/anonymous-agent-shaping
fix: serve anonymous free tier as agent-shaped streams
v1.3.2
2026-09-18 13:22:09 +08:00
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
Jason Xu fcd61ff58b Merge pull request #28 from smile89/fix/zen-free-tier-session-format
fix: use canonical OpenCode session IDs for Zen free tier
v1.3.1
2026-09-17 15:24:34 +08:00
58 8185202382 fix: use canonical OpenCode session IDs for Zen free tier
Upstream began rejecting anonymous free-tier requests whose
x-opencode-session does not match ses_[0-9a-f]{12}[0-9A-Za-z]{14}
with 403 FreeTierError. Map every downstream identity into that
shape deterministically (preserving native sessions), and bump
the impersonated client version to 1.18.31.
2026-09-17 14:07:36 +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.
v1.3.0
2026-09-15 01:28:44 +08:00
Jason Xu 28474f8702 Merge pull request #26 from jasonxu114514/fix/bridge-fidelity-and-upstream-guards
fix: harden gateway routing and protocol fidelity
2026-09-15 00:47:13 +08:00
Jason Xu ea29a62eca fix: harden gateway routing and protocol fidelity
Preserve request parameters, tool-call completion reasons and retry session
affinity. Bound upstream header waits, stop expired-context scans and add
opt-in redacted request-body diagnostics.

Isolate Playground diagnostics from production pools, report stream failures
accurately, align readiness with discoverable models and honor Docker listen
configuration.

Split Go and WebUI modules by responsibility, add regression tests and CI,
standardize formatting and rewrite the English and Chinese READMEs.

Refs: #6, #18, #19, #20, #21, #22, #23, #24, #25
2026-09-15 00:43:35 +08:00
Jason Xu 6d1a3c1098 chore: remove PR test files v1.2.4 2026-09-05 19:47:07 +08:00
Jason Xu bd9ced463a Merge remote-tracking branch 'origin/pr-17' 2026-09-05 19:46:26 +08:00
Jason Xu 908de8dc3d Merge remote-tracking branch 'origin/pr-15' 2026-09-05 19:45:57 +08:00
sk-dev-ai ce89cc01cb fix: nested modalities, per-tier metadata, drop committed cache
- capabilityModel now reads the nested modalities.{input,output} object
  the catalog actually serves; the old top-level input/output tags
  never matched and left both arrays permanently empty.
- Metadata is stored per tier and /v1/models selects by route.Tier,
  so same-named Zen/Go models (glm-5, minimax-m3, ...) advertise the
  limits of the tier that will serve them. Anonymous routes resolve
  to TierZen, keeping the keyless path on Zen metadata.
- Cache schema 2 -> 3; stale flat caches are refused and fall back
  to live refresh.
- Untrack config.json.models.catalog.json and ignore
  *.models.catalog.json: it is a runtime snapshot, not source.
- Add models_test.go fixtures: nested modalities, tier-split limits,
  tier selection, v3 round-trip, v2 rejection.
2026-09-05 12:29:36 +05:30
xiechen 74348cb46f fix: harden stale-reasoning retry per review
- Only treat a retry as success on 2xx; on non-2xx/transport failure
  close the retry response and restore the original 400 body, logging
  reasoning_reference_retry_failed with the retry status.
- Always close the original network body after caching its bytes, and
  hand downstream a fresh in-memory reader (also on read errors).
- Narrow the matcher to explicit 'reasoning item/reference ... not
  found/expired' errors; add negative cases (unknown reasoning field,
  bad reasoning_effort, unrelated 400s).
- Thread a cumulative attempt offset through doUpstreamTiers and the
  anonymous path so retry attempts keep numbering [1 2] per request.
- Add HTTP-level tests via httptest upstream: retry success (with
  stripped-payload assertion), retry non-2xx restore, non-matching
  passthrough, no-op (nothing to strip), cumulative attempt numbers.
2026-09-05 09:37:56 +08:00
sk-dev-ai f3593e3790 feat: emit top-level context_window and capability flags in /v1/models
Discovery clients (jcode, Pi, etc.) read context_length/context_window and
supported_reasoning_levels at the TOP LEVEL of each /v1/models entry, not
inside a nested metadata object. Emit both: keep the rich nested metadata
object AND mirror context_window/context_length/max_input/max_output/
reasoning/tool_call/structured_output at the top level so standard OpenAI
model-discovery clients get correct context windows without config.
2026-09-04 10:56:13 +05:30
sk-dev-ai 04ce09cc9c feat: expose per-model metadata (context window, reasoning, tool call, modalities) in /v1/models
fetchProtocolCapabilities already parses the full opencode catalog but
discards everything except protocol. Capture limit/reasoning/tool_call/
structured_output/modalities per model and expose them in /v1/models so
auto-discovering clients (e.g. jcode, which defaults every model to 200k
when context_window is absent) get correct context and feature flags.

Purely additive: routing/decision logic untouched, legacy response shape
preserved, cache schema bumped to v2 (old v1 caches load fine).
2026-09-04 10:52:11 +05:30
xiechen 462a6c8e36 feat: auto-retry upstream 400 on stale reasoning references
When Zen returns 400 such as "Referenced reasoning item 'rs_...' was
not found or has expired", replay once without the Responses reasoning
input items and previous_response_id under a fresh upstream session
instead of failing the client request. Other 400s pass through
unchanged. Adds unit tests for the classifier and payload stripping.
2026-09-04 11:21:23 +08:00
Jason Xu 2c87495826 feat: improve stream monitoring and model catalog reliability v1.2.3 2026-09-04 02:22:27 +08:00
Jason Xu 3be4b393c0 feat: show upstream key suffix per request v1.2.2 2026-08-27 21:36:17 +08:00
Jason Xu 6a03be875d Merge pull request #14 from Fance-rest/fix/models-dev-refresh-via-proxy
fix: fetch models.dev metadata through configured proxies
2026-08-27 21:16:54 +08:00
Fance-rest f63d8dd0b7 fix: fetch models.dev metadata through configured proxies
The models.dev metadata store used its own plain http.Client, so the
periodic price/deprecation refresh always bypassed the configured proxy
pool and failed on networks where direct access to models.dev is
unreliable or blocked.

Introduce a client provider on the store that resolves candidates at
refresh time: the active runtime's healthy proxy transports first, then
the original direct client as fallback. The provider reads the current
runtime atomically, so WebUI hot reloads automatically pick up new proxy
transports without touching the long-lived store.
2026-08-26 14:26:30 +08:00
Jason Xu 2615455b87 feat: align protocol content conversion with public APIs v1.2.1 2026-08-23 23:17:59 +08:00
Jason Xu 3776da76ec fix: harden cross-protocol streaming semantics 2026-08-23 22:53:22 +08:00
Jason Xu 4f0f26711a fix: preserve cache usage across protocol conversion v1.2.0 2026-08-23 22:12:22 +08:00
Jason Xu c4c1f36d61 fix: sync OpenCode model capabilities dynamically 2026-08-23 22:06:27 +08:00
Jason Xu 39de3d74ae Merge pull request #8 from Scotlight/fix/anthropic-inline-system-roles
fix: accept inline system/developer roles in Anthropic requests
v1.1.3
2026-08-23 21:08:22 +08:00
Scotlight 37afbbaa15 fix: accept inline system/developer roles in Anthropic requests 2026-08-23 18:36:46 +08:00
Jason Xu 25885c4e25 Remove DeepSeek default protocol override 2026-08-22 23:24:20 +08:00
Jason Xu 948ef0be11 feat: publish container images to GHCR v1.1.2 2026-08-20 04:45:14 +08:00
Jason Xu cc71ba8aff feat: revise free model routing fallback v1.1.1 2026-08-20 04:01:39 +08:00