Commit graph

44 commits

Author SHA1 Message Date
sid
8e550b9785 Local fork: hardening + ops improvements (timeout knob, demotion, /livez, drain)
This commit captures both the prior accumulated work-in-progress
(framework migration web/→svelte/, postgres storage, conversation
viewer, dashboard auth, OpenAPI spec, integration tests) AND today's
operational improvements layered on top. History wasn't checkpointed
incrementally; happy to split it via interactive rebase if a reviewer
wants smaller commits.

Today's changes (in addition to the older WIP):

1. Configurable upstream response-header timeout
   - ANTHROPIC_RESPONSE_HEADER_TIMEOUT env (default 300s)
   - Replaces hardcoded 300s in provider/anthropic.go that was firing
     on opus + 1M-context + extended thinking non-streaming requests
   - Files: internal/config/config.go, internal/provider/anthropic.go

2. Structured forward-error diagnostic logging
   - When a forward to Anthropic fails, log a single key=value line
     with request_id, model, stream, body_bytes, has_thinking,
     anthropic_beta, query, elapsed, ctx_err — alongside the existing
     human-readable error line for back-compat
   - Files: internal/handler/handlers.go (logForwardFailure)

3. Full SSE protocol passthrough + Flusher fix
   - handler/handlers.go: forward all SSE lines verbatim (event:, id:,
     retry:, : comments, blank-line terminators), not only data:.
     Previous code produced malformed SSE for strict parsers.
   - middleware/logging.go: explicit Flush() method on responseWriter.
     Embedding http.ResponseWriter (interface) does not auto-promote
     Flush(), so every w.(http.Flusher) check in the streaming
     handler was returning ok=false and SSE writes buffered in net/http
     until the body closed.

4. Non-streaming → streaming demotion (feature-flagged)
   - ANTHROPIC_DEMOTE_NONSTREAMING env (default false)
   - When enabled and the routed provider is anthropic, force stream=true
     upstream for clients that asked for stream=false. Receive SSE,
     accumulate via accumulateSSEToMessage (handles text, tool_use with
     partial_json reassembly, thinking, signature, citations_delta,
     usage merge), and synthesize a single non-streaming JSON response.
   - Eliminates the ResponseHeaderTimeout class of failure entirely.
   - Body rewrite uses json.Decoder + UseNumber() to preserve integer
     precision in unknown nested fields (tool inputs from prior turns).
   - Files: internal/config/config.go, internal/handler/handlers.go,
     cmd/proxy/main.go, cmd/proxy/main_test.go

5. Live operational state: /livez gauge + graceful drain
   - New internal/runtime package: atomic in-flight counter + draining flag
   - New middleware/inflight.go: increments runtime gauge, applied to
     /v1/* subrouter so Messages, ChatCompletions, and ProxyPassthrough
     are all counted
   - /v1/* moved to a gorilla/mux subrouter so the InFlight middleware
     applies surgically; /health, /livez, /openapi.* remain on parent
     router (unauthenticated, uncounted)
   - Health handler returns 503 draining when runtime.IsDraining() is
     true, so Traefik stops routing to a slot before drain begins
   - New /livez handler returns {status, in_flight, draining, timestamp}
   - SIGTERM handler in main.go: SetDraining(true), poll for in_flight==0
     with 32-min ceiling and 1s tick (logs every 10s), then srv.Shutdown
   - Auth bypass list extended with /livez
   - Files: internal/runtime/runtime.go (new),
     internal/middleware/inflight.go (new),
     internal/middleware/auth.go,
     internal/handler/handlers.go (Health, Livez, runtime import),
     cmd/proxy/main.go (subrouter, drain loop)

6. OpenAPI spec updates
   - Document Health 503 response and new DrainingResponse schema
   - Add /livez path with LivezResponse schema
   - Files: internal/handler/openapi.go

Verified: go build ./... clean, go test ./... all pass, go vet clean.
Three rounds of codex peer review across changes 1-5; all feedback
addressed (citations_delta, json.Number precision, drain-loop logging
via lastLog timestamp, PathPrefix tightened to "/v1/").
2026-05-02 15:15:58 -06:00
sid
b9da198e1f Harden proxy auth, storage, and conversation access 2026-03-19 19:00:24 -06:00
sid
6cda36312a Harden streaming, pagination, and config loading 2026-03-19 18:52:09 -06:00
Seif Ghazi
02c9c76667
Merge pull request #29 from seifghazi/cleanup-routing
Model routing
2026-01-04 15:04:54 -05:00
Seif Ghazi
fd480c67ef
routing 2026-01-04 15:04:34 -05:00
Seif Ghazi
8d1f9d2277
Merge pull request #27 from seifghazi/sg/opus-45
Add support for opus 4.5
2025-12-16 12:22:12 -05:00
Seif Ghazi
b9fc71ecf9 add support for opus 4.5 2025-12-16 19:21:14 +02:00
Seif Ghazi
62da19ae2d
Merge pull request #25 from elifarley/elifarley-secret-as-hash
Replace API key redaction with SHA256 hash display
2025-12-16 12:19:14 -05:00
Elifarley C
a86d7cd3d6 Replace API key redaction with SHA256 hash display
Instead of showing generic "[REDACTED]" for sensitive headers, the SanitizeHeaders
function now calculates and displays the SHA256 hash of each API key. This provides:
- Better debugging capabilities by allowing key identification via hash
- Traceability of specific API keys across requests
- Maintained security as actual keys are never exposed

Changes in proxy/internal/handler/utils.go

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-08 12:13:34 -03:00
Seif Ghazi
dd812ab15e
Merge pull request #18 from seifghazi/add-support-for-claude-4.5
Add Claude Sonnet 4.5
2025-09-29 17:27:30 -04:00
Seif Ghazi
305a5375f3
Add Claude Sonnet 4.5 2025-09-29 17:27:05 -04:00
Seif Ghazi
f48bea6516
Merge pull request #17 from idachev/add-opus-4-1-model
Add claude-opus-4-1-20250805 model to Anthropic provider
2025-08-17 15:47:40 -04:00
Ivan Dachev
62a168f46d Add claude-opus-4-1-20250805 model to Anthropic provider
Added support for the new Claude Opus 4.1 model released in August 2025
to enable routing through the proxy.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-13 08:09:59 +03:00
Seif Ghazi
2d09a3a234
Merge pull request #13 from kennethgoodman/main 2025-08-09 20:43:51 -04:00
Kenneth Goodman
17437e1d46 Adding gpt5 2025-08-07 23:03:10 -04:00
Seif Ghazi
7ab69a1081
Merge pull request #12 from seifghazi/sg/clean-model-check
Standardize model check logic in react
2025-08-04 23:09:04 -04:00
Seif Ghazi
fc4075b129
Standardize model check logic in react 2025-08-04 23:08:47 -04:00
Seif Ghazi
547d4b620c
Standardize model check logic in react 2025-08-04 23:05:28 -04:00
Seif Ghazi
44c27e9c22
Merge pull request #11 from seifghazi/sg/update-readme
Update Readme Docker setup with updated `config.yaml` support
2025-08-04 22:57:56 -04:00
Seif Ghazi
33e1fd1a84
Update Readme with docker setup with config 2025-08-04 22:57:07 -04:00
Seif Ghazi
7574829604
Merge pull request #10 from seifghazi/sg/subagent-support
Route Subagents to OpenAI  Models
2025-08-04 22:49:03 -04:00
Seif Ghazi
40de1c3027
Merge branch 'sg/subagent-support' of github.com:seifghazi/claude-code-proxy into sg/subagent-support 2025-08-04 22:41:41 -04:00
Seif Ghazi
b8bbcb38c5
add warning 2025-08-04 22:41:12 -04:00
Seif Ghazi
c8f05577b4
Merge branch 'main' into sg/subagent-support 2025-08-04 22:21:00 -04:00
Seif Ghazi
a60a0981d5
Merge pull request #8 from freeatnet/main
Add Dockerfile for a faster quick start
2025-08-04 22:18:23 -04:00
Seif Ghazi
cc6e1d80bf
clean up 2025-08-04 22:01:42 -04:00
Seif Ghazi
4675fee4a3
route cleanup
working

Working version
2025-08-04 21:57:44 -04:00
Arseniy Ivanov
cb36631b7a Fix Docker implementation with working SQLite and healthcheck
- Enable CGO in Go build stage for SQLite support (add gcc, musl-dev, sqlite-dev)
- Replace PM2 with direct process management for simpler container operation
- Fix network binding to 0.0.0.0 for external access from host
- Simplify healthcheck command to avoid spider mode issues
- Remove PM2 dependency and use background processes with proper signal handling
- Both proxy (3001) and web (5173) services now start and respond correctly

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-03 19:30:32 -04:00
Arseniy Ivanov
602452b162 Add Docker support with comprehensive deployment options
- Add multi-stage Dockerfile with optimized builds for Go backend and Node.js frontend
- Create docker-entrypoint.sh script for managing both services with PM2
- Add .dockerignore for optimal build context
- Update README.md with Docker deployment documentation including:
  - Docker build and run instructions
  - Persistent data configuration with volume mounts
  - Complete environment variable reference table
  - Docker Compose example configuration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-03 19:30:32 -04:00
Seif Ghazi
1e0173c768
Working version with openai 2025-08-02 22:40:01 -04:00
Seif Ghazi
80a25f7ba7
temp 2025-08-01 21:19:30 -04:00
Seif Ghazi
9cb513019d
Merge pull request #7 from seifghazi/feat/tools
Displays tools
2025-07-25 09:55:04 -04:00
Seif Ghazi
1228c3929e
Displays tools 2025-07-24 23:00:34 -04:00
Seif Ghazi
9000631b36
Update README.md 2025-07-14 12:47:27 -04:00
Seif Ghazi
5e6b32ed6a
Merge pull request #5 from seifghazi/fix/readme
Remove outdate ref to api key requirement
2025-07-10 14:50:07 +03:00
Seif Ghazi
30b7003810
Remove outdate ref to api key requirement 2025-07-10 07:49:03 -04:00
Seif Ghazi
15dbb56887
Merge pull request #4 from seifghazi/feat/update-gif
Update ReadMe gif with new design
2025-07-09 20:13:03 +03:00
Seif Ghazi
80948115d6
Update ReadMe gif with new design 2025-07-09 13:10:14 -04:00
Seif Ghazi
2978d0617d
Merge pull request #3 from seifghazi/feat/proxy-v2
Feat: implement proxy v2 with backend and frontend enhancements
2025-07-09 20:02:39 +03:00
Seif Ghazi
70d71e812e
Merge branch 'main' into feat/proxy-v2 2025-07-09 20:01:58 +03:00
Seif Ghazi
bd126e3d8a
feat: implement proxy v2 with backend and frontend enhancements
- Enhanced proxy handlers and Anthropic service integration
- Improved SQLite storage and configuration
- Updated web UI and request handling

temp

WIP: additional changes
2025-07-09 12:57:10 -04:00
Seif Ghazi
812a8f321c Adds godotenv and fixes filtering logic 2025-07-01 09:10:09 -04:00
Seif Ghazi
20c25e2f2d
README fix 2025-06-29 21:14:03 -04:00
Seif Ghazi
ae71ec4f72
Ready 2025-06-29 20:50:04 -04:00