227 Commits
Author SHA1 Message Date
Jason Xu fc7744a509 fix(warp): add opt-in anonymous proxy fallback and retirement handling (#196) v1.5.2 2026-11-30 04:40:43 +08:00
Jason Xu fac8dd3d7c feat(stream): safely continue interrupted anonymous chat streams (#75) 2026-11-30 04:40:43 +08:00
Jason Xu 30d6c08a9c feat(logging): add safe hot-reloadable rotating file sink (#116) 2026-11-30 04:40:43 +08:00
Jason Xu 9b44a031ca feat(models): add collision-safe aliases and model echoes (#125) 2026-11-30 04:40:43 +08:00
Jason Xu a0fbd6b6cb feat(proxy): pin manual keys to direct routes (#113) 2026-11-30 04:40:43 +08:00
Jason Xu a256090eab feat(proxy): support IPv4 and IPv6 direct routes (#193) 2026-11-30 03:40:43 +08:00
Jason Xu 7927714032 docs: remove sponsor sections from READMEs 2026-11-28 02:53:12 +08:00
Jason Xu 6575c623d7 fix(gateway): use NBSP in client tool descriptions (#188)
Replace ASCII spaces with non-breaking spaces in client tool top-level descriptions during free-model shaping. Preserve parameter schemas, appended official tools and tool name restoration.

Validation: Windows build, go vet, 36 tool integration checks, 167 environment regression checks, and the original DSH fixture completing with HTTP 200 through the production default.
v1.5.1
2026-11-20 23:25:05 +08:00
Jason Xu 8f691a0d00 fix(gateway): isolate client prompt environments (#190)
Resolve client environment declarations before protocol conversion and keep a separate snapshot per request. Remove host directory, platform, workspace and Git assumptions, preserving explicit deployment defaults and official client prompts.

Validation: Windows build, go vet, 167 integration checks, and live DeepSeek requests with unknown environment fields.
2026-11-20 23:16:53 +08:00
Jason Xu e2b2a7c281 refactor: harden gateway and document Go/Zen OAuth
Preserve Go and Zen OAuth routing while fixing authentication, secret redaction, streaming, transport, and configuration issues.

Refresh README and management guides in four languages while preserving sponsors, LinuxDo acknowledgements, and Linux/Docker quick start instructions.
v1.5.0
2026-11-18 03:01:56 +08:00
Jason Xu 0d05fe9393 feat(admin): add bulk proxy management and opt-in anonymous access 2026-11-17 06:14:45 +08:00
Jason Xu 159d7fdf0f feat(go): add browser device OAuth subscription sign-in
Add WebUI device authorization, organization selection, persisted token refresh, and fail-closed official Go subscription routing. Preserve manual keys without PAYG fallback and keep OAuth quota unknown.

Validation: offline regression checks, go vet, JavaScript syntax, and Windows/Linux amd64 compilation passed. Live subscription authorization and inference are not yet verified.

Refs #168
v1.4.8
2026-11-17 05:28:09 +08:00
Ray 95575c5fd6 fix(protocol): rename client tools under an ordinary namespace (#182)
The free tier refuses the literal "clint_" in a tool name: the same shaped
body is answered with 429 FreeUsageLimitError under clint_ and completes
normally under any other prefix, so the rename itself is accepted and the
prefix alone is what the gate matches.

Keep the wire-name namespace a plain tool-like name instead of a gateway
marker, and stop printing the literal in the READMEs so the docs do not pin
a value that has to rotate.

Verified live on a build of this commit: the captured 20-tool CLI body
returns 200 and its tool call round-trips; the same build with the constant
reverted returns 429. vet, gofmt, Linux and Windows builds pass.
2026-11-17 03:23:21 +08:00
Jason Xu 14faec7654 fix(gateway): harden free-tier retries and client compatibility
Preserve upstream HTTP failures across transport retries, classify title requests before shaping, and rename legacy functions exactly once.

Keep adjacent Responses assistant items together, including interleaved text and calls. Add opt-in prompt environment overrides with matching shell descriptions, strict validation, and WebUI round-trip preservation.

Document compatibility boundaries and retain existing defaults. Include the requested test/ ignore rule. Offline zz_ regressions passed and were removed after validation as requested; vet and Windows/Linux builds passed.

Refs #173, #175, #176, #178, #179, #181
2026-11-17 01:00:29 +08:00
Ray b296a61d0e feat(diagnostics): pin a Playground request to one relay (#167)
Resolved against #170 so a relay pin clears the per-attempt WARP choice
(attemptUseWARP). The relay list is now credential-redacted, and a pin may
name a relay by its redacted URL.
v1.4.7
2026-11-05 12:56:56 +08:00
Jason Xu 46eb13ea03 fix(gateway): restore the build after #169 and tidy the merged batch
#169 called anonymousNodes.CursorForOffset, warp.Pool.ReportWithRetryAfter and
warp.Pool.HasUntriedActive without defining them, so main did not compile.
Add the three methods: an attempt offset shifts the anonymous start node, a
longer Retry-After extends the egress cooldown, and HasUntriedActive matches
the pool's egress keys.

Also:
- rewrite title.go in house style: named limits, a prompt table, no issue
  numbers in comments, and a titleFallback helper shared by both lanes
- document the held-back tool-call helpers in protocol/stream.go
- gofmt internal/admin/server.go
- drop the _test.go files from #169, #170 and #171
2026-11-05 12:09:28 +08:00
NEKOMYAandNekomyaDev cee32f7047 feat(models): add passive availability tracking and opt-in probes (#171)
* feat(models): add passive availability tracking and opt-in probes

* test(models): harden passive availability telemetry and catalog refresh overlap protection

---------

Co-authored-by: NekomyaDev <neko@nekomya.dev>
2026-11-05 11:41:52 +08:00
NEKOMYAandNekomyaDev 6fbe12c4df feat(gateway): add optional per-key proxy binding with fail-closed routing (fixes #149) (#170)
- Allow operators to associate Zen and Go credentials with configured proxy
  routes via optional proxy_bindings in config.
- Keys are mapped to their 16-hex fingerprint during normalization so
  secrets are never stored twice or exposed in diagnostics.
- Bound credentials fail closed: when their assigned proxy becomes unavailable,
  they do not silently migrate to other proxies or fall back to direct egress.
- When an assigned proxy recovers, traffic resumes immediately without
  changing bindings.
- Removed or invalid proxy references fail config validation, leaving the
  previous running runtime untouched on failed reloads.
- Unbound configurations, anonymous routing, and session affinity continue
  to behave exactly as before.
- Note in config documentation that binding to a #pool proxy endpoint pins the
  transport route and does not guarantee a static public egress IP.
- Add unit and acceptance tests covering binding resolution, fail-closed isolation,
  persistence, and secret masking.

Co-authored-by: NekomyaDev <neko@nekomya.dev>
2026-11-05 11:41:44 +08:00
NEKOMYAandNekomyaDev 86be64bfbe fix(gateway): preserve OpenCode v2 title requests and avoid WARP pool churn (#169)
Co-authored-by: NekomyaDev <neko@nekomya.dev>
2026-11-05 11:41:29 +08:00
CheerCandClaude Code 87e798318d fix(free-tier): restore official tool names and drop ghost calls (#166)
A shaped free-tier body appends the lane's official tool set (shell, grep,
glob, read, task, …) and the official system prompt names those tools. Models
follow it and call `shell` / `grep` / `glob`, but the downstream client never
declared those names, so Claude Code answers "No such tool available: shell".
The same happens to mangled wire names (`clit_…`, `clnt_…`) and to leftover
tool calls such as `d4e3b...`, which were forwarded verbatim and then imitated
on later turns.

Response mapping now resolves an official name to the client tool the client
actually declared (`shell`/`bash` → `Bash`, `read` → `Read`, `edit` → `Edit`,
`task`/`subagent` → `Agent`, `question` → `AskUserQuestion`, …). When the
client declared no equivalent, the name stays unchanged instead of being
guessed.

Request history is sanitised for Anthropic, Chat and Responses: a call whose
name is neither declared nor equivalent to a declared tool is removed together
with its paired result (tool_use_id / tool_call_id / call_id), an official name
with a declared equivalent is rewritten to that tool's wire name, and a named
tool_choice pointing at a removed tool is dropped.

Chat stream rewriting no longer treats a name as complete just because the
same delta carries an `arguments` field. While the accumulated name is still a
prefix of a known wire name the arguments are held back and released with the
resolved name, or flushed verbatim at finish_reason / EOF, so a name split over
chunks cannot leak a partial or wire name to the client.

Verified in a scratch copy against a captured Claude Code request: shell, bash,
read, edit, write and webfetch resolve to the declared client tools while
`clit_…`/`clnt_…` pass through untouched and undeclared official names are not
mapped; history sanitisation leaves zero orphan tool results across 586 tool
blocks; a split name with interleaved arguments emits `Read` with intact
arguments and a single-frame call is unchanged. gofmt, go vet and go build
pass.

Co-authored-by: Claude Code <noreply@anthropic.com>
2026-11-05 11:41:21 +08:00
Quheng Dengandlocal 079cd7b434 fix(proxy): probe the OpenCode origin instead of cloudflare.com (#153)
Co-authored-by: local <local@local>
2026-11-05 11:41:13 +08:00
Jason Xu 58f56676ba feat(webui): theme toggle, paged ledger, working refresh status, and collapsed proxy chips
- Dark theme: an auto/light/dark cycle in the topbar, persisted per
  browser and applied before first paint by an inline head script; the
  dark palette moves behind data-theme so the runtime choice wins over
  the media query (#122).
- Request routing and upstream attempts tables are paged (50/100/200/500
  rows per page) instead of a hard last-100 cap, with translated pager
  controls (#122).
- Free-model refresh status now calls POST /api/models/probe, which
  marks every automatic model due and wakes the probe loop, then reloads
  the snapshot; the button re-probes instead of only rereading the cache
  (#122).
- The config page renders long key/proxy lists collapsed behind a
  100-chip cap with an expand toggle, so a large proxy pool no longer
  freezes the page (#146).
- New strings translated for en/vi/it; READMEs document the new
  admin endpoint.
v1.4.6
2026-10-30 04:16:18 +08:00
Jason Xu 2bf547c0d9 chore: drop _test.go files to keep the released tree test-free
Strips the tests that arrived with #152 and #139 after their squash
merges.
2026-10-29 21:59:15 +08:00
sri krishna d07ee0e23d fix(gateway): report client-actionable status codes (#139)
Two client-facing errors were uninformative, and a harness cannot recover
from either.

1. An unknown model was reported as 400 "the model uses an upstream protocol
   that opencode2api does not expose". That phrasing is accurate for a model
   the catalog KNOWS but cannot serve (a capability or routing problem), and
   wrong for a model the upstream has never offered. A model the upstream
   retired (it answers 410 Gone) produced this 400, so a harness kept
   retrying a model that no longer exists. The catalog can now tell the two
   cases apart (ModelCatalog.Known), and an unknown model returns 404 with
   code model_not_found.

2. A request whose every attempt failed while WRITING the body was reported
   as 504 "upstream request timed out". The upstream never finished reading
   the body, so the payload is too large, and a client that can shrink the
   request knows to shrink it. Harnesses that recover from an oversized
   payload generally key on HTTP 413 (and image rejection on 400), so a 504
   sent the same oversized payload around forever. A write-phase failure
   while the request budget is still alive now returns 413 with code
   payload_too_large; every other phase (headers, first_event) stays a 504,
   because a slow upstream or a thinking model is not the client's fault.

Both paths are applied to the chat, responses and messages endpoints as well as
to /v1/systemone.

Tests: the 404 vs 400 split, and the 413 vs 504 split. Both mutation-proved:
reverting either change fails the matching test.
2026-10-29 21:58:31 +08:00
daming 大铭 5371ada2eb fix(protocol): preserve whitespace in streamed reasoning deltas (#152) 2026-10-29 21:57:29 +08:00
Jason Xu d8bcebd8ea chore: drop _test.go files to keep the released tree test-free
The repository ships without test files; strips the tests that arrived
with #160, #161 and #162 after their squash merges.
2026-10-29 21:41:13 +08:00
CheerC 6bb3487f7f fix(probe): give probes and the Playground bench their own identity (#162)
The hourly free-model probe presented one pinned identity: project
"opencode2api:default-project" together with a session derived from the
model name. The free tier meters per project id and egress, so every
deployment running the same probe shared one bucket; once a popular exit
had charged that bucket, every probe answered 429 FreeUsageLimitError and
the model was cached as unavailable for an hour while live traffic on the
same process and egress succeeded.

The Playground bench pinned a session indirectly: it sent no session
signal, so DeriveRequestIDs fell back to conversationSeed — the system
prompt plus the first user turn — and every click replaying the same
prompt produced the same session.

Neither path is a conversation, so neither should present one. Each now
mints fresh identity per attempt: a canonical session and a random project
id for the probe, a canonical session per Playground click. Canonical ids
are forwarded verbatim, so the scope mixin does not apply and the shape the
free tier accepts is what goes out.

Verified end to end with the admin UI enabled on a temporary instance.
Three Playground clicks before the change logged the same upstream session
three times (ses_ea4eb1680ffe0B8cZBh0nKJ03A); two clicks after logged
ses_eb2c888f1ffe4Y0DodMQdwvu6c and ses_ed8748efdffe2ez6IH352OdMpV, both
200. Probes on this build measured 8/8 probe_succeeded with a fresh
availability cache — they already succeeded on this exit before the change,
so this is hardening for the charged-bucket case in the report, not a
reproduction of it.
2026-10-29 21:40:31 +08:00
CheerC 4a4db10387 fix(free-tier): hide client tool names from shaped requests (#161)
The free tier refuses a shaped body whose tool list still reads as another
client's session. A Claude Code request that declares both ReportFindings and
ScheduleWakeup is answered with FreeUsageLimitError — the same 429 a genuinely
exhausted IP receives — and the refusal is deterministic: rename either name
and the same request succeeds, and two empty placeholder tools carrying just
those two names reproduce it. Schema, size and tool count do not matter.

The gateway forwarded client tools as clint_<name>, so every Claude Code
session behind CLIProxyAPI was refused (14 tools, both markers present) while
the official CLI kept working and small requests through the gateway were
fine.

Client tools now get an opaque wire name: clint_ plus 12 hex characters of the
name's SHA-256, collision-suffixed like before. Descriptions and schemas are
untouched, so the model still knows what a tool does, and the response path
still restores the names the client declared, streaming included.

Verified against the captured Claude Code request (95 KB, 14 tools):
3/3 429 before the change, 3/3 200 after, and the same request replayed
through CLIProxyAPI (Anthropic /v1/messages -> chat -> /inference) returns
200. Session ids are unaffected: they are normalized by CanonicalSessionID,
and an implausible session timestamp is a separate 429 trigger documented
there.
2026-10-29 21:39:19 +08:00
CheerC 9946e66fa6 fix(identity): salt derived session ids per process (#160)
CanonicalSessionID re-encodes a conversation signal from the server key and
the seed alone, so the upstream `x-opencode-session` was identical in every
process on the same UTC day. The free tier keeps charging that session, so
after a 429 a gateway restart no longer changed anything upstream: the same
`ses_…` walked into the new exit's bucket and 429'd again.

Mix a 16-byte nonce, minted once per process, into the hash. A running
gateway still derives one stable session per conversation, while a restart
re-mints the ids and starts a fresh upstream identity. Official client
sessions are still forwarded verbatim.

Refs #159, #158
2026-10-29 21:38:45 +08:00
Jason Xu b13bf6989c docs: use the IPWO sponsor card in every README
Replace the remote banner and the prose line with the logo-plus-text card
that ships as assets/IPWO.png, translated per language.
2026-10-27 19:16:36 +08:00
Jason Xu a4ccac76b7 fix(warp): schedule pool timers under the pool lock
after() added to the pool wait group outside the lock, so a timer scheduled just as Close began Wait could be missed by the shutdown wait. Increment under the lock and refuse to schedule after Close, which removes the Add/Wait race.
2026-10-27 18:58:54 +08:00
Jason Xu 54fe16ebb7 feat(free-tier): use only the v2 lane and fold response tool names
The anonymous free tier now calls the configured v2 /inference origin only; the retired v1 /zen fallback is commented out rather than deleted, so the lane order can be restored in one edit. Catalog refresh and probes follow anonymousUpstreams, so they stop trying /zen too.

A request whose client names no project now gets a fresh 40-hex project id. The free tier ledges quota per project id and egress, and the old per-caller default was one shared bucket that popular exits had already burned.

Response tool names now resolve in the order exact wire name, clint_ prefix, case fold, separator fold. A fold two declared tools share is never guessed between. The stream and JSON rewriters share the resolver, and their fast path now recognizes unprefixed tool-call frames.
2026-10-27 18:58:54 +08:00
Jason Xu 1de0f3fa47 fix(warp): wait out a rate limit during the first registration
Startup registers the first exit synchronously and failed closed on any
error, including Cloudflare's rate limit — which a fresh process can still
receive because the limit follows the source address. Wait out the pause
inside the initialization deadline instead, and give WARP initialization
one full rate-limit window so a deploy does not fail on a limit that is
about to expire.
2026-10-27 18:58:54 +08:00
Jason Xu a8e2576171 fix(warp): pace registration from Cloudflare and stop probe churn
A Cloudflare 429 on /reg no longer sleeps inside the registration path:
the registrar records the Retry-After window and fails fast, and the pool
schedules its next attempt after that window. Registration can no longer
hold createMu for minutes while requests wait for an exit.

Refill backs off when the colo hands out fewer distinct egress blocks
than the preload: three consecutive duplicate registrations pause it for
1-5 minutes instead of registering into a saturated colo forever.

Automatic free-model probes skip a pool with fewer than two exits and
stop the sweep after one probe retires an exit, so they cannot drain the
warm bench. Diagnostics are unaffected.
2026-10-27 18:58:54 +08:00
Jason Xu 3136a5c4ab feat(warp): preload half the pool and register without a fixed gap
Registrations were paced by a fixed 12-second gap, which made a cold pool
and a 429 replacement wait minutes for capacity. Remove the gap: the
registrar now issues registrations back to back in the background,
serialized by the pool's create mutex, and only a rejected attempt backs
off (doJSON still honours Retry-After).

Keep half of warp.pool_size (at least one) hot as a preload: the first
exit still gates readiness, the rest register in the background, and
desiredLocked/scaleDown treat the preload as a floor so idle surplus is
still retired after 60 seconds but the warm bench survives. A 429 or 403
removes the exit from the ring and the next request uses a preloaded exit
immediately.

/healthz reports warp.preload, and the WebUI and all four READMEs
describe the behaviour.
2026-10-27 18:58:53 +08:00
Jason Xu 082cce2167 Change IPWO sponsor image to full width
Updated the image tag for IPWO sponsor in README.
2026-10-27 14:32:43 +08:00
Jason Xu d60b53137d Adjust sponsor image width in README.zh-CN.md
Updated sponsor image width in the Chinese README.
2026-10-27 14:30:22 +08:00
Jason Xu a28748ea1c Change IPWO sponsor image in README
Updated sponsor image for IPWO in the README.
2026-10-27 14:25:28 +08:00
Jason Xu 6797d2bf80 Update README.zh-CN.md 2026-10-27 14:25:01 +08:00
Jason Xu 48f208359b 更新 README.it.md 2026-10-27 12:02:46 +08:00
Jason Xu c02e3b805f 更新 README.vi.md 2026-10-27 12:00:47 +08:00
Jason Xu b6fb76ae3b 更新 README.zh-CN.md 2026-10-27 11:59:19 +08:00
Jason Xu cbd1f7bec5 更新 README.md 2026-10-27 11:58:40 +08:00
Jason Xu ded9a6c59c 更新 README.it.md 2026-10-27 11:55:35 +08:00
Jason Xu 3b2d75da21 更新 README.vi.md 2026-10-27 11:55:16 +08:00
Jason Xu b36ea8c8cd 更新 README.zh-CN.md 2026-10-27 11:54:38 +08:00
Jason Xu 0c3251c852 更新 README.md 2026-10-27 11:54:18 +08:00
Jason Xu b8b1454a0e fix(warp): rotate exits on a live pool and size it to concurrency
The WARP pool could never rotate: its lifetime context was derived from the
startup deadline, so every standby registration and replacement died with
"context canceled" and requests stayed on the first egress forever. Give the
first registration the caller's deadline and the pool a context that only
Close cancels.

- warp.pool_size is an upper bound. The active ring follows concurrency (one
  exit per lease, one per queued request, plus a spare) and trims idle surplus
  after 60 seconds, so a burst expands it and quiet periods shrink it.
- An IPv6 exit is deduplicated and cooled by its /64 for 30 minutes (IPv4 by
  its /32), since the free quota is scoped to that block.
- 429/403 retires an exit immediately and re-registers right away; a free
  model request keeps switching exits and only returns the last 429 after
  retry.max_attempts, on both the anonymous and the Zen-key lane. 429s no
  longer trip the anonymous breaker or cool the key.
- Pin HTTP/1.1 ALPN and TLSNextProto on the WARP transport: a clone of
  DefaultTransport made after its first dial negotiated h2 and fed SETTINGS
  frames to the HTTP/1.x reader, breaking catalog refresh.
- Default to the IPv6 stack and, with warp.source_ipv6, let each exit bind its
  own outer source from a routed prefix via IPV6_FREEBIND. Endpoints try IPv6
  first and fall back to IPv4, so IPv4-only hosts keep working.
- WebUI, config example and all READMEs describe the new pool and rotation
  behaviour.
v1.4.4
2026-10-25 06:49:00 +08:00
Jason Xu 953310117d fix(free-tier): keep ses_ session timestamps inside the upstream window
The upstream decodes ses_ as ~((ms << 12) | counter) and rejects an
implausible timestamp with the same 429 Free usage limit it returns for an
exhausted quota, so a hash-derived id made healthy egresses look blocked.
Anchor the timestamp to the current UTC day minus a hash-chosen offset of
at most 30 days, keeping the id deterministic for a given request signal
while staying inside the accepted window.
2026-10-25 06:48:54 +08:00
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