Commit Graph
84 Commits
Author SHA1 Message Date
MythEclipseandClaude 6c945dcbf4 feat: add API test page at /test endpoint
- New public/test-api.html — browser-based test UI for all proxy endpoints
- Health check, model listing, Chat Completions (stream+non-stream),
  Anthropic Messages (stream+non-stream), and generic HTTP relay
- Server serves /test route from public/test-api.html

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-16 22:58:17 +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 47b85fb396 chore: use hardcoded dummy API key
- Replace env-based API_KEY with sk-dummy-key hardcoded
- All entry points use same key: Authorization: Bearer sk-dummy-key
- Simplifies usage for library/client consumption

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:59:01 +07:00
MythEclipseandClaude Fable 5 c0a02279bd feat: add API key authentication for AI proxy endpoints
- Add API_KEY config (env var) to all entry points
- requireAuth helper checks Authorization: Bearer or x-api-key header
- Auth applied to /v1/chat/completions, /v1/messages, /v1/models
- When API_KEY is empty/unset, auth is disabled (backward compatible)
- Update wrangler.toml with API_KEY variable documentation

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:56:18 +07:00
MythEclipseandClaude Fable 5 2be57c0838 fix: handle surfsense stream format correctly
Surfsense sends data: {"type":"text-delta","delta":"text"} — use
raw.delta (not raw.content) and filter events by type. Skip non-text
events (thinking steps, start, etc) to produce clean Anthropic SSE.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 00:49:36 +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 38d7a83fe9 feat: add AI proxy routes to Workers and Vercel entry points
- Add /v1/chat/completions, /v1/messages, /v1/models routes to
  src/worker.ts (Cloudflare Workers) and api/relay.ts (Vercel)
- Import handleChatCompletion, handleAnthropicMessages handlers
- Using the same backend routing as the standalone server

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 23:45:38 +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
MythEclipseandClaude Fable 5 567ed52db5 feat: add OpenAI-compatible AI proxy endpoint
- Create src/lib/ai-proxy.ts: routes OpenAI chat completions requests
  to backend providers (opencode.ai, surfsense.com, deep-seek.ai)
  based on model name with request/response translation
- Add POST /v1/chat/completions route to server with streaming (SSE)
  support, CORS, and proxy pool fallback on failure
- Add GET /v1/models route returning available model list
- Direct-first strategy: try backend directly, fall back to proxy pool
  on network failure (consistent with relay behavior)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 22:52:45 +07:00
MythEclipseandClaude Fable 5 c61f8d9db6 fix: try direct connection first, fall back to proxy
Change proxy strategy: first attempt goes direct (no proxy).
Only if direct fails, fall back to proxy pool with rotation.
This way healthy upstreams don't pay the proxy latency.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 22:15:47 +07:00
MythEclipseandClaude Fable 5 03427cae8c feat: auto-rotate proxy pool with retry on network failure
- Add src/lib/proxy-pool.ts: round-robin proxy pool that reads
  proxy.txt (host:port:user:pass), tracks consecutive failures,
  and rotates on threshold
- Integrate into src/index.ts: on fetch network error, mark proxy
  as failed, rotate to next, and retry the request once
- proxy.txt loaded from PROXY_FILE/PROXY_LIST env var or ./proxy.txt
- Graceful no-op when proxy.txt doesn't exist (Vercel/Workers)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 22:12:59 +07:00
MythEclipseandClaude Fable 5 3f96d8a6e7 fix: relay requests to / with x-relay-target instead of showing index
When a GET request hits / with an x-relay-target header, it should relay
the request — not display the index page. Fixed in all three entry points
(src/index.ts, api/relay.ts, src/worker.ts).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:59:25 +07:00
MythEclipseandClaude Fable 5 2ac23f199d chore: configure Cloudflare Workers deployment
- Enable workers_dev deploy to edge-proxy-relay.workers.dev
- Set account_id in wrangler.toml
- Configure CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID as
  GitHub Actions secrets via gh CLI (from .env)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:46:13 +07:00
MythEclipseandClaude Fable 5 7a4df35371 feat: add Cloudflare Workers deployment support
- Create src/worker.ts: Workers-compatible relay handler using env
  bindings instead of process.env, exports { fetch } for Workers runtime
- Update wrangler.toml: point to new src/worker.ts entry point
- Update deploy.yml: add wrangler-action deploy step after tests pass
- The worker reuses the same relay logic from src/lib/ and src/middleware/

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:38:22 +07:00
MythEclipseandClaude Fable 5 58553f936e fix: disable Vercel Next.js framework detection
Add "framework": null to vercel.json so Vercel doesn't try to
run Next.js build flow (looking for .next/routes-manifest.json).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:22:37 +07:00
MythEclipseandClaude Fable 5 9dc32e8b10 fix: correct Vercel Bun runtime config and handler export format
Per Vercel docs (vercel.com/docs/functions/runtimes/bun):
- Use top-level "bunVersion": "1.x" in vercel.json (NOT functions block)
- Export default { async fetch(request) { ... } } — object with fetch method
  (not a bare default function)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:20:16 +07:00
MythEclipseandClaude Fable 5 591c1fa199 fix: add Vercel-compatible relay handler and fix vercel.json runtime
- Create api/relay.ts: Vercel serverless function handler that reuses
  relay logic from src/lib/relay-utils.ts and src/middleware/
- Export default fetch handler (no Bun.serve()) for Vercel Functions
- Fix vercel.json: use @vercel/node@5 runtime with proper routing via
  rewrites to catch all traffic to the relay handler
- Remove stale buildCommand/outputDirectory (Vercel handles function builds)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 21:17:21 +07:00
MythEclipseandClaude Fable 5 f58a92e2aa feat: migrate from Next.js to pure Bun relay proxy
- Replace Next.js app router with standalone Bun.serve() entry point
- Add middleware stack: rate limiter, body limiter, structured logger, SSRF protection
- Add WebSocket bidirectional relay via x-relay-target header
- Implement error classification (DNS→502, timeouts→504, SSRF→403, rate→429)
- Remove all Next.js dependencies and config files
- Update deploy workflow, tsconfig, wrangler config for Bun deployment

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 19:54:55 +07:00
MythEclipse 124dab98a2 docs: improve README with comprehensive examples and protocol support info 2026-05-08 19:12:18 +07:00
MythEclipse 694f14a316 fix: add node 22 + set secrets to correct repo 2026-05-08 19:03:24 +07:00
MythEclipse eba4fbe00a fix: remove wrong working-directory from workflow 2026-05-08 19:01:49 +07:00
MythEclipse 443ff77be9 ci: add CF Workers deploy workflow + fix relay header forwarding 2026-05-08 18:58:50 +07:00
MythEclipse dfb0f5942f docs: add alternative deployment endpoint to README 2026-05-08 17:32:56 +07:00
MythEclipseandClaude Opus 4.7 75731af9b6 Remove edge runtime directive from route handler
Cloudflare Workers via OpenNext tidak support Next.js edge runtime.
Hapus export const runtime = "edge" agar handler jalan di Workers runtime.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 17:32:35 +07:00
MythEclipseandClaude Opus 4.7 765bcdca44 Add Cloudflare Workers deploy config via OpenNext
- Fix build:worker script to use opennextjs-cloudflare build
- Add open-next.config.ts required by OpenNext Cloudflare
- Update wrangler.toml main entry to .open-next/worker.js
- Ignore .open-next/ and .wrangler/ build artifacts

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 17:27:06 +07:00
MythEclipse d211c40fa1 docs: update example usage in README for clarity and formatting 2026-05-07 23:45:00 +07:00
MythEclipse ef436182fc docs: update live deployment section by removing trailing slashes from URLs 2026-05-07 23:26:17 +07:00
MythEclipse 240866c0d0 docs: add alternative deployment endpoint to README 2026-05-07 23:25:58 +07:00
MythEclipse 6a82a834eb refactor: remove unnecessary targetUrl parameter and prevent compressed responses in relay 2026-05-07 23:09:49 +07:00
MythEclipse c1772d6b6b docs: update live deployment section in README for clarity 2026-05-07 22:56:38 +07:00
MythEclipse 6f91d93672 feat: restructure API and documentation with new relay handler and UI components 2026-05-07 22:55:23 +07:00
MythEclipse fff35f02fe docs: add secondary deployment endpoint to README 2026-05-07 22:52:22 +07:00
MythEclipse 1df328ad96 docs: update README with live deployment info and correct example commands 2026-05-07 22:47:49 +07:00
MythEclipse 6588c2bc39 test: add unit tests for relay-utils functions 2026-05-07 22:41:08 +07:00
MythEclipse d848b903e8 fix: update example proxy commands in README for clarity 2026-05-07 22:37:48 +07:00
MythEclipse 932bc192fa feat: integrate Geist font and enhance layout with utility classes
feat: update Home component with new UI elements and improved request handling

chore: add components.json for component configuration

feat: implement Badge component for status indication

feat: create Button component for consistent styling

feat: develop Card component structure for content display

feat: add Input component for user input fields

feat: implement Label component for form accessibility

feat: create Select component for dropdown functionality

feat: add Separator component for visual separation

feat: implement Toaster component for notifications

feat: create Tabs component for tabbed navigation

feat: add Textarea component for multi-line input

feat: add utility functions for class name management
2026-05-07 22:30:50 +07:00
MythEclipse f691476046 fix: prevent encoding issues by removing problematic headers in relay responses 2026-05-07 22:25:39 +07:00
MythEclipse 1a0a947674 Refactor code structure for improved readability and maintainability 2026-05-07 22:22:35 +07:00
MythEclipse 83e66805c4 refactor: remove Tailwind CSS configuration and update dependencies 2026-05-07 21:34:39 +07:00
MythEclipse 001bba1d24 fix: add CORS headers to relay responses and OPTIONS method handling 2026-05-07 21:31:00 +07:00
MythEclipse 7416bfb2bd feat: migrate proxy logic to new structure and implement new relay route 2026-05-07 21:26:27 +07:00
MythEclipse 083d77e252 fix: migrate proxy handler logic from pages/api/proxy.ts to app/api/proxy/route.ts and remove old file 2026-05-07 21:22:30 +07:00
MythEclipse 52845da832 fix: update proxy configuration to use 'config' export and move allowed methods inside handler 2026-05-07 21:20:31 +07:00
MythEclipse 751eb083c4 fix: migrate proxy route logic from route.ts to pages/api/proxy.ts 2026-05-07 21:19:20 +07:00
MythEclipse f3ec82cbbf fix: replace stripRelayHeaders with filterHeaders and add BLOCKED_HEADERS set 2026-05-07 21:16:31 +07:00
MythEclipse f2ebba51bb fix: remove commented console log for request headers in Home component 2026-05-07 21:11:44 +07:00
MythEclipse 3fdbaf3ced fix: update .gitignore and tsconfig for Next.js compatibility 2026-05-07 21:09:09 +07:00
MythEclipse 9d1ef77cda fix: update duplex type assertion in buildRelayRequest function 2026-05-07 21:07:39 +07:00
MythEclipse b11763a7ab fix: update devDependencies to include TypeScript and type definitions for React 2026-05-07 21:05:58 +07:00
MythEclipse e553ed3e02 fix: update PostCSS configuration to correctly reference '@tailwindcss/postcss' 2026-05-07 21:04:45 +07:00
MythEclipse 262dbfafbe chore: migrate PostCSS and Tailwind configuration to .mjs format 2026-05-07 21:03:30 +07:00
MythEclipse b0dde3c885 refactor: migrate to Next.js with edge functions and update relay utilities
- Removed old relay utilities and tests, replacing them with a new structure under `src/lib/relay-utils.ts`.
- Implemented a new edge function in `app/api/proxy/route.ts` to handle proxy requests.
- Created a new Next.js layout and page structure for the frontend, including a user interface for testing the proxy.
- Added Tailwind CSS for styling and configured PostCSS.
- Updated TypeScript configuration for better compatibility with Next.js.
- Removed unused files and configurations related to the previous setup.
2026-05-07 20:59:23 +07:00
MythEclipse 4c30f2a6e1 chore: remove index.html and update vercel.json for API routing 2026-05-07 20:45:18 +07:00
MythEclipse db175e6e95 fix: update fetch options to include target URL in buildRelayRequest 2026-05-07 20:43:09 +07:00
MythEclipse cc38b7c7c6 feat: add isAllowedTarget function to validate URL protocols 2026-05-07 20:37:10 +07:00
MythEclipse 9e2f4d39b1 feat: implement API handler for edge runtime with method validation and target normalization 2026-05-07 20:35:18 +07:00
MythEclipse a6333750e4 feat: update project structure and enhance UI for Edge Proxy Test
- Add .gitignore to exclude api directory
- Remove deprecated api/index.ts file
- Create new public/index.html with improved UI and functionality
- Update package.json build script to copy index.html to dist
- Enhance request handling in index.html with custom headers and presets
- Improve response display with status, time, and size metrics
2026-05-07 20:26:51 +07:00
MythEclipse 9c05003e70 fix: remove .vercelignore file 2026-05-07 20:15:27 +07:00
MythEclipse 7df78ad117 fix: remove rewrites configuration from vercel.json 2026-05-07 20:14:43 +07:00
MythEclipse c0bfce3d26 Revert "feat: update build output directory to 'dist' in package.json and set outputDirectory in vercel.json"
This reverts commit cfbc4609b5.
2026-05-07 20:13:41 +07:00
MythEclipse 149a646fea fix: correct typo in comment for allowed methods 2026-05-07 20:08:04 +07:00
MythEclipse 9759d63b38 feat: add index.html for Edge Proxy Relay interface and remove rewrites from vercel.json 2026-05-07 20:03:57 +07:00
MythEclipse 49f50b7aa8 fix: update fetch request URL to use '/api' endpoint 2026-05-07 20:00:43 +07:00
MythEclipse e5de4bbbfb fix: update fetch API endpoint and adjust rewrites in vercel.json 2026-05-07 19:59:34 +07:00
MythEclipse 6f28d18b95 feat: refactor header handling and update module path in package.json 2026-05-07 19:55:39 +07:00
MythEclipse 1b86a33b4e fix: remove functions configuration from vercel.json 2026-05-07 19:54:25 +07:00
MythEclipse 8e0cf9d0f3 fix: update import path for relay-utils and restore functions configuration in vercel.json 2026-05-07 19:53:20 +07:00
MythEclipse 212ce32480 feat: implement Edge Proxy Relay with request handling and header filtering 2026-05-07 19:49:52 +07:00
MythEclipse d8e1e125b1 feat: update vercel.json to restore build and install commands, and adjust routing configuration 2026-05-07 19:46:08 +07:00
MythEclipse 4cf3a520d5 feat: add index.html for Edge Proxy Relay interface with request handling 2026-05-07 19:46:00 +07:00
MythEclipse cfbc4609b5 feat: update build output directory to 'dist' in package.json and set outputDirectory in vercel.json 2026-05-07 19:41:56 +07:00
MythEclipse 2a82012910 feat: simplify vercel.json by removing function configuration and updating bunVersion 2026-05-07 19:39:31 +07:00
MythEclipse 098eabe5bf feat: add 'api' directory to .gitignore and update build script in package.json 2026-05-07 19:32:04 +07:00
MythEclipse c49c1d7441 feat: add schema and bunVersion to vercel.json configuration 2026-05-07 19:28:51 +07:00
MythEclipse 42cf7a89c7 feat: add function configuration for Bun runtime in vercel.json 2026-05-07 19:26:05 +07:00
MythEclipse b4f5bad19d feat: enhance request handling with method validation and target URL checks 2026-05-07 19:22:28 +07:00
MythEclipse 9448a9cc7a feat: add code-review-graph integration and update project configuration 2026-05-07 19:13:00 +07:00
MythEclipse 86ca59ad8e refactor: restructure project by moving and renaming files, and implementing relay utilities 2026-05-07 19:12:46 +07:00
MythEclipse a4fcbbcca9 initial commit for proxy-bun 2026-05-07 18:42:09 +07:00