Commit Graph
9 Commits
Author SHA1 Message Date
MythEclipseandClaude 9bd6acddc5 feat: implement session-based sticky proxy pool with auto-failover
Add SessionProxyPool for per-session sticky proxy allocation with
load-balanced least-used selection and auto-rotation on failure.
Introduce fetchWithSessionRetry for transparent retry with proxy
rotation. Wire into AI proxy handlers (OpenAI + Anthropic) with
stream lifecycle cleanup.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-16 23:50:47 +07:00
MythEclipse b09bca8def feat(core): implement robust fetch utilities and stream management
Introduce a centralized `fetch-utils.ts` to handle retry logic with proxy fallback, SSE line buffering to prevent chunk-boundary corruption, and graceful shutdown via active reader tracking.

Key changes:
- Add `fetchWithRetry` for automatic direct-to-proxy failover.
- Implement `SSELineBuffer` to ensure reliable parsing of split SSE chunks.
- Add `createStreamBodyLimiter` to enforce payload limits on streaming requests.
- Refactor `ProxyPool` to decouple failure marking from rotation.
- Standardize CORS handling and environment variable configuration.
- Clean up documentation and remove obsolete skill files.
2026-06-11 03:56:26 +07:00
MythEclipse db065f788d style(anthropic-proxy): update comment formatting and add SSE utility functions
Standardize comment separators and arrow usage in documentation headers.
Additionally, introduce `accumulateSSEText` and `extractTextFromSSE` to
provide robust parsing for various SSE stream formats, including
Claude Code and OpenAI-compatible deltas.
2026-06-11 01:43:23 +07:00
MythEclipse 261f84a96e refactor(anthropic-proxy): improve SSE stream transformation logic
Refactor the backend-to-Anthropic SSE transformation to use a more robust
state machine approach. This replaces manual string building with a
structured phase-based system (`init`, `block`, `done`) to better
manage the Anthropic streaming protocol, including `message_start` and
`content_block_delta` events.

- Extract `formatContentBlockDelta` helper for consistent event formatting
- Implement phase-based state machine in `transformAnthropicStream`
- Delegate `[DONE]` handling to the stream transformer instead of
  manually emitting `message_stop`
- Improve reliability of message ID generation and event sequencing
2026-06-11 01:24:54 +07:00
MythEclipseandClaude Fable 5 2fead57d0f fix: use MODEL_ROUTES directly for Anthropic proxy routing
Remove the ANTHROPIC_MODEL_MAP layer — /v1/messages now uses the
same model names as /v1/chat/completions (deepseek-v4-flash-free,
gpt-5.4-mini-no-login, deepseek/deepseek-v4-flash). This way users
send the original model name and it routes to the correct backend.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:42:21 +07:00
MythEclipseandClaude Fable 5 2fca9febe4 fix: pass original model name to backend in Anthropic proxy
Use anthReq.model instead of backendModel so the backend receives
the user-sent model name (e.g. claude-sonnet-4) rather than the
internal mapped name.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:20:20 +07:00
MythEclipseandClaude Fable 5 5974d31164 fix: avoid double markFailed in AI proxy retry loop
Response handler already calls markFailed() on non-2xx and network
errors (which rotates the proxy). The preamble at attempt >= 2 was
calling markFailed() again, double-rotating and skipping a proxy.
Changed preamble to use rotate() instead of markFailed().

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:02:40 +07:00
MythEclipseandClaude Fable 5 2dfb87eac6 fix: retry AI proxy with next proxy on HTTP errors too
Previously only retried on network errors (fetch exceptions). Now also
rotates to next proxy when upstream returns non-2xx (429 rate limit,
5xx, etc). Applies to both OpenAI and Anthropic endpoints.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 23:57:24 +07:00
MythEclipseandClaude Fable 5 4168a087a0 feat: add Anthropic-compatible AI proxy endpoint
- Create src/lib/anthropic-proxy.ts: accepts Anthropic Messages API
  format (POST /v1/messages) and routes to the same backend providers
- Anthropic model names (claude-sonnet-4, claude-3-haiku, claude-opus-4)
  map to backend models with full request/response translation
- Streaming (SSE) via Anthropic protocol: message_start,
  content_block_delta, message_stop events
- Add /v1/messages route to server with CORS and proxy pool fallback
- Reuses MODEL_ROUTES from ai-proxy.ts for consistent backend routing

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 23:08:32 +07:00