Commit Graph
148 Commits
Author SHA1 Message Date
Gabriel Tavares 197a8a604f fix(gateway): stamp Responses tool strictness only for Anthropic conversions
Native /v1/responses clients omit strict as API semantics; forcing false opted them out of strict tool schemas.
2026-08-30 01:19:28 +01:00
Gabriel Tavares 54f57a35d5 fix(gateway): opt OpenAI Responses tools out of implicit strict mode
Claude Code omits tool.strict, so Responses promotes optional fields to required and models emit both Monitor command and ws.
2026-08-25 23:30:35 +01:00
musi 99f24806c6 update sponsor 2026-08-25 22:03:48 +08:00
musistudio 19e5d4909e Release 3.0.22 2026-08-24 20:16:17 +08:00
musistudio f2360ac046 Merge branch 'main' into dev/3.1 2026-08-24 20:02:57 +08:00
musi 17c8744de9 Merge pull request #1695 from songkuan-zheng/fix/fusion-vision-validate-image-inputs
fix(fusion-vision): validate and repair image inputs before forwarding
2026-08-24 20:02:20 +08:00
musistudio 70e7fd1a80 Secure gateway preload file permissions 2026-08-24 19:29:15 +08:00
musistudio 9e7d4f782c Implement router enhancements 2026-08-24 19:02:41 +08:00
pacocartones 6c98ea2adf fix(media): release artifact response body on early download failures
GatewayMediaExecutor.download() left the fetch Response body un-read and un-cancelled on several early-exit paths: a terminal non-ok HTTP status, an oversized declared content-length (declaredLength > maxApiArtifactBytes), and a mid-stream writeSync failure in the download loop. In each case the underlying undici connection/socket is leaked, so repeated failed downloads accumulate open connections and exhaust the pool.

Cancel the response body before throwing on those paths, and cancel the reader in the write-error handler, matching the cancellation already done on the retry branch and the in-loop size-limit branch.
2026-08-24 04:28:06 +00:00
musi 1347c868b4 Merge pull request #1691 from dylanpulver/fix/responses-session-affinity
Forward session id as prompt_cache_key on openai_responses
2026-08-22 18:34:25 +08:00
musistudio ccd00632ac Update project files 2026-08-22 16:12:46 +08:00
musistudio d515556574 Fix profile-specific model routing and gateway shutdown 2026-08-22 10:18:18 +08:00
kskada acf75d1280 Add Claude Code regression test for local agent auth provider hook 2026-08-21 16:29:58 +03:00
musistudio 46daaad92e Resolve Claude Code routes with one-million-context model suffixes 2026-08-20 16:45:54 +08:00
songkuan-zheng 3dab369ce3 test(fusion-vision): regression coverage for data-URL base64, local SVG, label restriction 2026-08-20 04:13:13 +00:00
musi 6e1a9617ff Merge pull request #1672 from pacocartones/fix/sse-utf8-chunk-boundary
fix(gateway): SSE transforms corrupt multi-byte characters split across chunks
2026-08-20 11:23:31 +08:00
musistudio 3ba195f893 Improve Claude Code router configuration and provider support 2026-08-19 17:19:07 +08:00
musistudio b073ebef31 Add Fusion vision instructions and image capabilities 2026-08-19 16:06:21 +08:00
Dylan Pulver 51c0fe7d12 Forward session id as prompt_cache_key on openai_responses
Requests converted to the OpenAI Responses protocol left the outbound
body without any session-stable field: prompt_cache_key was never set
and the inbound Anthropic metadata.user_id was dropped. Multi-channel
Responses upstreams that pin sessions on body fields hashed each turn
onto a different channel, so channel-bound encrypted_content
continuations failed with 400 invalid_encrypted_content and prefix
cache hits were lost.

The gateway boundary plugin now fills prompt_cache_key on outbound
openai_responses JSON bodies from the first non-empty of
x-claude-code-session-id, x-claude-session-id, or the inbound
metadata.user_id, and carries metadata.user_id onto the outbound body
when no metadata was set. A caller-supplied non-empty prompt_cache_key
always wins, and other protocols pass through untouched.

Fixes #1688
2026-08-18 12:15:21 +03:00
musistudio 4344a2d6a7 Refactor routing configuration and improve provider support 2026-08-18 11:45:39 +08:00
songkuan-zheng 17fd745898 Normalize usage token conventions per source
normalizeUsageInputTokens decides whether input_tokens already includes the
cached prefix, and it asked the upstream provider protocol first. Both usage
call sites merge the billing headers and the response body into one snapshot
and then normalize that merge once — but on a translated response the two
sources use different conventions:

  - x-gateway-billing-* headers restate the upstream provider's own counters
    verbatim, so for an OpenAI-compatible upstream they are cache-inclusive.
  - The response body is whatever the gateway emitted. An Anthropic body is
    cache-exclusive regardless of what it was translated from.

So an Anthropic response served from an OpenAI-compatible upstream had the
body's already-excluded prefix subtracted a second time. Non-streaming
responses were unaffected by luck: the headers win the merge and are
inclusive, making the subtraction correct. Streaming responses carry no
billing headers at all, leaving the body alone to be over-subtracted and then
clamped by Math.max(0, ...) — on a long cached conversation input_tokens
reports 0 on nearly every turn, and the derived cache ratio is pinned at
100%.

Tag each source with a UsageConventionSource and normalize the two separately
before merging them. Reordering the precedence instead is not sufficient: it
moves the defect onto the non-streaming path, which depends on the headers
being reduced.

Raw-trace updates carry no provider protocol, so their billing headers keep
falling back to the request path; only the body side changes there.
2026-08-17 05:21:30 +00:00
musistudio 22b68fd907 Qualify target model selectors with routed provider 2026-08-15 23:47:32 +08:00
musistudio 83e01c3077 Sanitize target model header while preserving Unicode body 2026-08-15 23:16:15 +08:00
pacocartones 79f48c0070 fix(gateway): SSE transforms corrupt multi-byte characters split across chunks
Four SSE response transforms decode every upstream chunk in isolation with
chunk.toString(). A UTF-8 character whose bytes straddle a chunk boundary is
therefore decoded twice as two invalid fragments, and each fragment becomes
U+FFFD. The character is destroyed before the block is ever parsed, so no
downstream code can recover it: the JSON still parses, the event still
validates, and the replacement characters are forwarded to the client.

The pending buffer these transforms already keep does not help. It joins
partial SSE *blocks*, not partial *characters* — by the time the bytes reach
it they have already been decoded and lost.

Affected sites, all in the response chain built in gateway/request/pipeline.ts:

  codex-patch-bridge.ts               transformSseChunk
  codex-multi-agent-bridge.ts         transformSseChunk
  hosted-web-search/response-transform.ts
                                      hostedWebSearchProtocolSseStream
                                      anthropicHostedWebSearchProtocolSseStream

The correct pattern is already in this repository. anthropic-response-model.ts,
the last transform in that same chain, runs the identical block-splitting loop
over a node:string_decoder StringDecoder, which holds back an incomplete
trailing sequence until the next chunk supplies the rest.

Apply that pattern to the other four. Each transform now owns one decoder for
its lifetime, writes every chunk through it, and drains decoder.end() in flush
so a truncated stream still emits what the decoder was holding.

Any non-ASCII output is affected — CJK, Cyrillic, accented Latin, emoji — and
the apply_patch bridge carries file contents, so a corrupted character there is
written to disk.
2026-08-14 12:40:55 +02:00
musistudio e4072137d4 Increase route script source size limit to 5 MiB 2026-08-14 11:44:33 +08:00
musistudio 48956f98cd Ensure request log tests close stores and cover row limit 2026-08-14 11:28:48 +08:00
musistudio 0104474e95 Merge branch 'main' into dev/3.1
# Conflicts:
#	packages/core/test/integration/observability/request-log-store.test.mjs
2026-08-14 11:17:06 +08:00
pacocartones 2eb05b0e47 test(core): close request log stores before cleanup 2026-08-11 18:56:38 +02:00
musistudio 2a7aa9286b Update router configuration and provider handling 2026-08-11 16:15:53 +08:00
musistudio 3cb188c064 Report bounded agent analysis and handle missing session details 2026-08-11 15:00:59 +08:00
musi 56d7b37c64 Support multiple WorkBuddy models and generic app paths 2026-08-11 12:36:44 +08:00
musistudio 8fb38278f5 Merge branch 'main' of github.com:musistudio/claude-code-router into dev/3.1 2026-08-11 10:56:16 +08:00
musistudio e38f9bc2dd Refactor router configuration and request handling 2026-08-11 10:53:45 +08:00
musistudio 28f0a2f2b9 Merge remote-tracking branch 'origin/dev/3.1' into dev/3.1
# Conflicts:
#	packages/core/src/profiles/service.ts
#	packages/ui/src/pages/home/components/profiles.tsx
#	packages/ui/src/pages/home/shared/profiles.ts
2026-08-11 10:05:44 +08:00
musistudio 551fc0e8ef Reuse healthy external gateways and decode Claude App routes 2026-08-11 10:00:33 +08:00
musi c8e5e2b53d Add WorkBuddy app integration 2026-08-11 09:25:53 +08:00
musistudio e8db9406a7 Add automatic provider model refresh and dialog Escape handling 2026-08-10 15:40:48 +08:00
musi 186fa619d2 Merge pull request #1640 from pacocartones/fix/raw-trace-directory-fsync-eperm-windows
fix(observability): raw trace spool never persists a bundle on Windows
2026-08-10 13:36:19 +08:00
musistudio d48fd17105 Attribute Claude App encoded models to routed upstream usage 2026-08-10 13:04:07 +08:00
musistudio 6e34da7fca Enforce profile model allowlists across agent catalogs 2026-08-10 12:55:54 +08:00
musi 0d178f3732 Improve compact handoff fidelity and token limit sanitization 2026-08-10 08:34:21 +08:00
jesieleo f39ab4d5c4 feat(providers): 增加小米 MiMo 及 Token Plan 预设 2026-08-08 19:08:47 +08:00
pacocartones 92eeec11a9 fix(observability): raw trace spool never persists a bundle on Windows
Windows implements fsync as FlushFileBuffers, which behaves differently
from POSIX in two ways the raw trace spool relied on.

Flushing a directory handle is rejected outright with EPERM. syncDirectory
only tolerated EINVAL, ENOTSUP and EISDIR, so the durability barrier that
follows every rename threw instead of being skipped.

Flushing a file handle requires that handle to carry write access, and both
file flush sites opened their target read-only, so they also failed with
EPERM.

Together these made every durable write fail on Windows: with
observability.requestLogs enabled the sync handler answered 503
spool_unavailable for every bundle and nothing was ever persisted.

Tolerate EPERM alongside the other directory-flush rejections, and reopen
files as "r+" so their flush stays a real barrier rather than a tolerated
error. The tolerated set is extracted into a predicate so a test can pin
down which codes are skipped and, just as importantly, which ones still
propagate.

Fixes #1635
2026-08-07 21:45:10 +02:00
musistudio 47b23298fb Implement requested changes 2026-08-07 22:49:28 +08:00
musistudio 8cab2dbb7a Merge dev/3.1 into main for v3.0.20 2026-08-07 15:41:27 +08:00
musistudio 1f5cc499f1 Improve Claude Design asset discovery and product runtime support 2026-08-07 11:51:19 +08:00
musistudio 4097bbe5e7 Improve router configuration and request handling 2026-08-06 17:41:41 +08:00
musi 70b51b08d4 Merge pull request #1634 from flaviomartil/fix/grok-peer-rotated-credential
fix(grok): adopt peer-rotated credential on refresh 401
2026-08-06 16:12:24 +08:00
musistudio 89081a2082 Preserve target-provider slash model routing 2026-08-06 14:07:56 +08:00
Flavio martil 01d275892e fix(grok): coalesce in-process refreshes and unexport GrokRefreshAuthError
Address review on #1634:

- keep GrokRefreshAuthError module-private, consistent with the updated
  Kimi implementation, avoiding new public API surface;
- dedupe concurrent resolveGrokAuth calls with a per-credential in-flight
  refresh map keyed by sourceFile + authRecordKey, mirroring
  kimiRefreshInFlight, so parallel requests share one refresh (and its
  peer-rotation adoption outcome) instead of racing the same stale
  refresh token;
- add a test proving concurrent refreshes coalesce into a single token
  request.
2026-08-06 01:14:09 -03:00