Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .github/workflows/edgee-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
set -euo pipefail
go test \
./cmd/server \
./internal/auth/claude \
./internal/config \
./internal/logging \
./internal/runtime/executor \
Expand All @@ -36,7 +37,8 @@ jobs:
./sdk/api/handlers \
./sdk/api/handlers/claude \
./sdk/cliproxy \
./sdk/cliproxy/auth
./sdk/cliproxy/auth \
./sdk/proxyutil
go test ./internal/api -run '^TestCodexOAuthRoute' -count=1
- name: Race-test concurrency and route isolation
run: >-
Expand All @@ -46,6 +48,14 @@ jobs:
./internal/api/handlers/management
./internal/runtime/executor
./sdk/cliproxy/auth
- name: Race-test shared proxy connections
run: >-
go test -race -count=1
-run 'Test(UtlsClient|InvalidProxyURL|ClientsForTheSameProxy|Connect|RetryBackoff|ReviewNotEstablishedConnIsReused|EquivalentProxySettings|NewClaudeAuth|PatchAuthFileFields|ConfigHandlersRejectInvalidProxyURL|UploadAuthFileRejectsBadProxyURL)'
./internal/api/handlers/management
./internal/auth/claude
./internal/runtime/executor/helps
./sdk/proxyutil

build-windows-arm64:
needs: test-gate
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN go mod download

COPY . .

ARG VERSION=7.2.62+edgee.7
ARG VERSION=7.2.62+edgee.8
ARG COMMIT=none
ARG BUILD_DATE=unknown

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ English | [中文](README_CN.md) | [日本語](README_JA.md)
A proxy server that provides OpenAI/Gemini/Claude/Codex/Grok compatible API interfaces for CLI.

> [!NOTE]
> **This is the `claude-all` edgee fork.** It adds opt-in per-request routing through `codex-oauth-base-url` for selected inbound API keys, bumps the version string to `7.2.62+edgee.7`, and ships a pinned windows/arm64 release via `.github/workflows/edgee-release.yml` (upstream tag-triggered release workflows are disabled here). Edgee-routed non-streaming Codex calls return the upstream's real terminal error, or, for Claude-format requests, the partial reply for `response.incomplete`, instead of stock's 408; unmarked requests are unchanged. The closed upstream [PR #4258](https://github.com/router-for-me/CLIProxyAPI/pull/4258) contains only the older v1 change and is not the complete current patch series.
> **This is the `claude-all` edgee fork.** It adds opt-in per-request routing through `codex-oauth-base-url` for selected inbound API keys, bumps the version string to `7.2.62+edgee.8`, and ships a pinned windows/arm64 release via `.github/workflows/edgee-release.yml` (upstream tag-triggered release workflows are disabled here). Edgee-routed non-streaming Codex calls return the upstream's real terminal error, or, for Claude-format requests, the partial reply for `response.incomplete`, instead of stock's 408; unmarked requests are unchanged. Proxied requests share one connection pool per proxy URL and account (HTTP/2 for uTLS hosts), and a malformed proxy-url fails loudly at config load and on every request instead of going direct. The closed upstream [PR #4258](https://github.com/router-for-me/CLIProxyAPI/pull/4258) contains only the older v1 change and is not the complete current patch series.
>
> **Rebase procedure** (adopting a newer upstream version): `git fetch upstream --tags`, branch from the new upstream tag, then cherry-pick both feature commits in order: `a0d9081c7d8dbd0095788bccc178cfe75ff2ad0f` followed by `4e23ea9598c7ec1660e83097b5ca6149cf7f24ec`. Apply the edgee.3 repair series as the complete range `git cherry-pick 24d7b959681fcfed91cfdc0a4aa9b147e94dcbc9..v7.2.62-edgee.7`; do not substitute PR #4258 for either feature commit or omit any commit in that range. Cherry-pick the release-workflow/documentation commits as needed, resolve conflicts, run the release workflow's test gate, bump the fork version string to `<upstream>+edgee.N` (current: `7.2.62+edgee.7`), tag `v<upstream>-edgee.N`, let `edgee-release.yml` publish, then update the minimum version, release tag, and both SHA pins in claude-all's `scripts/claude-all.ps1` (the sole pin location).
> **Rebase procedure** (adopting a newer upstream version): `git fetch upstream --tags`, branch from the new upstream tag, then cherry-pick both feature commits in order: `a0d9081c7d8dbd0095788bccc178cfe75ff2ad0f` followed by `4e23ea9598c7ec1660e83097b5ca6149cf7f24ec`. Apply the edgee.3 repair series as the complete range `git cherry-pick 24d7b959681fcfed91cfdc0a4aa9b147e94dcbc9..v7.2.62-edgee.8`; do not substitute PR #4258 for either feature commit or omit any commit in that range. Cherry-pick the release-workflow/documentation commits as needed, resolve conflicts, run the release workflow's test gate, bump the fork version string to `<upstream>+edgee.N` (current: `7.2.62+edgee.8`), tag `v<upstream>-edgee.N`, let `edgee-release.yml` publish, then update the minimum version, release tag, and both SHA pins in claude-all's `scripts/claude-all.ps1` (the sole pin location).
>
> **Un-fork / return to upstream** (once the PR lands in an official release): point claude-all's edgee-mode download back at the upstream release asset, restore the upstream version-probe regex, replace both fork SHA pins with the upstream archive/binary hashes, and archive this repository.

Expand Down
2 changes: 1 addition & 1 deletion cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
)

var (
Version = "7.2.62+edgee.7"
Version = "7.2.62+edgee.8"
Commit = "none"
BuildDate = "unknown"
DefaultConfigPath = ""
Expand Down
4 changes: 2 additions & 2 deletions cmd/server/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import "testing"

func TestEmbeddedVersion(t *testing.T) {
if Version != "7.2.62+edgee.7" {
t.Fatalf("Version = %q, want 7.2.62+edgee.7", Version)
if Version != "7.2.62+edgee.8" {
t.Fatalf("Version = %q, want 7.2.62+edgee.8", Version)
}
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
context: .
dockerfile: Dockerfile
args:
VERSION: ${VERSION:-7.2.62+edgee.7}
VERSION: ${VERSION:-7.2.62+edgee.8}
COMMIT: ${COMMIT:-none}
BUILD_DATE: ${BUILD_DATE:-unknown}
container_name: cli-proxy-api
Expand Down
116 changes: 98 additions & 18 deletions internal/api/handlers/management/auth_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ type codexOAuthService interface {
}

var (
callbackForwardersMu sync.Mutex
callbackForwarders = make(map[int]*callbackForwarder)
errAuthFileMustBeJSON = errors.New("auth file must be .json")
errAuthFileNotFound = errors.New("auth file not found")
errPluginVirtualAuth = errors.New("plugin virtual auth cannot be modified directly; edit or delete the source auth file")
newCodexOAuthService = func(cfg *config.Config) codexOAuthService { return codex.NewCodexAuth(cfg) }
callbackForwardersMu sync.Mutex
callbackForwarders = make(map[int]*callbackForwarder)
errAuthFileMustBeJSON = errors.New("auth file must be .json")
errAuthFileInvalidProxy = errors.New("auth file has an invalid proxy_url")
errAuthFileNotFound = errors.New("auth file not found")
errPluginVirtualAuth = errors.New("plugin virtual auth cannot be modified directly; edit or delete the source auth file")
newCodexOAuthService = func(cfg *config.Config) codexOAuthService { return codex.NewCodexAuth(cfg) }
)

func extractLastRefreshTimestamp(meta map[string]any) (time.Time, bool) {
Expand Down Expand Up @@ -751,6 +752,10 @@ func (h *Handler) UploadAuthFile(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": "file must be .json"})
return
}
if errors.Is(errUpload, errAuthFileInvalidProxy) {
c.JSON(http.StatusBadRequest, gin.H{"error": errUpload.Error()})
return
}
c.JSON(http.StatusInternalServerError, gin.H{"error": errUpload.Error()})
return
}
Expand Down Expand Up @@ -807,7 +812,11 @@ func (h *Handler) UploadAuthFile(c *gin.Context) {
return
}
if err = h.writeAuthFile(ctx, filepath.Base(name), data); err != nil {
c.JSON(500, gin.H{"error": err.Error()})
status := 500
if errors.Is(err, errAuthFileInvalidProxy) {
status = 400
}
c.JSON(status, gin.H{"error": err.Error()})
return
}
c.JSON(200, gin.H{"status": "ok"})
Expand Down Expand Up @@ -1161,6 +1170,11 @@ func (h *Handler) buildAuthFromFileData(path string, data []byte) (*coreauth.Aut
if err := json.Unmarshal(data, &metadata); err != nil {
return nil, fmt.Errorf("invalid auth file: %w", err)
}
if value, ok := metadata["proxy_url"]; ok {
if errProxy := validateAuthFileProxyURL("proxy_url", value); errProxy != nil {
return nil, fmt.Errorf("%w: %v", errAuthFileInvalidProxy, errProxy)
}
}
provider, _ := metadata["type"].(string)
if provider == "" {
provider = "unknown"
Expand Down Expand Up @@ -1481,8 +1495,12 @@ func (h *Handler) PatchAuthFileFields(c *gin.Context) {
return
}

changed := false
touchedRoots := make(map[string]struct{}, len(req))
// Validate the whole patch before touching anything, so a rejected patch changes nothing.
type fieldPatch struct {
path string
value any
}
patches := make([]fieldPatch, 0, len(req))
for key, rawValue := range req {
fieldPath := strings.TrimSpace(key)
if fieldPath == "" {
Expand All @@ -1494,17 +1512,30 @@ func (h *Handler) PatchAuthFileFields(c *gin.Context) {
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf("invalid field %s", fieldPath)})
return
}
if targetAuth.Metadata == nil {
targetAuth.Metadata = make(map[string]any)
if rootAuthFileField(fieldPath) == "proxy_url" {
if errProxy := validateAuthFileProxyURL(fieldPath, value); errProxy != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": errProxy.Error()})
return
}
}
patches = append(patches, fieldPatch{path: fieldPath, value: value})
}

if fieldPath == "headers" {
applyAuthFileHeadersPatch(targetAuth, value)
} else if errSet := setAuthFileMetadataValue(targetAuth.Metadata, fieldPath, value); errSet != nil {
// GetByID clones only the top level, so detach nested metadata from the live record.
targetAuth.Metadata = cloneAuthMetadata(targetAuth.Metadata)
if targetAuth.Metadata == nil {
targetAuth.Metadata = make(map[string]any)
}
changed := false
touchedRoots := make(map[string]struct{}, len(patches))
for _, patch := range patches {
if patch.path == "headers" {
applyAuthFileHeadersPatch(targetAuth, patch.value)
} else if errSet := setAuthFileMetadataValue(targetAuth.Metadata, patch.path, patch.value); errSet != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": errSet.Error()})
return
}
if root := rootAuthFileField(fieldPath); root != "" {
if root := rootAuthFileField(patch.path); root != "" {
touchedRoots[root] = struct{}{}
}
changed = true
Expand All @@ -1528,6 +1559,55 @@ func (h *Handler) PatchAuthFileFields(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"status": "ok"})
}

// validateAuthFileProxyURL requires proxy_url to be set whole, as a string that is a usable proxy setting.
func validateAuthFileProxyURL(fieldPath string, value any) error {
if fieldPath != "proxy_url" {
return fmt.Errorf("%s: proxy_url must be set as a whole string", fieldPath)
}
if value == nil {
return nil
}
raw, isString := value.(string)
if !isString {
return fmt.Errorf("proxy_url must be a string")
}
return config.ValidateProxyURL("proxy_url", raw)
}

func cloneAuthMetadata(metadata map[string]any) map[string]any {
if metadata == nil {
return nil
}
out := make(map[string]any, len(metadata))
for key, value := range metadata {
out[key] = cloneAuthMetadataValue(value)
}
return out
}

func cloneAuthMetadataValue(value any) any {
switch typed := value.(type) {
case map[string]any:
return cloneAuthMetadata(typed)
case map[string]string:
out := make(map[string]string, len(typed))
for key, item := range typed {
out[key] = item
}
return out
case []any:
out := make([]any, len(typed))
for i, item := range typed {
out[i] = cloneAuthMetadataValue(item)
}
return out
case []string:
return append([]string(nil), typed...)
default:
return value
}
}

func decodeAuthFileFieldValue(raw json.RawMessage) (any, error) {
decoder := json.NewDecoder(bytes.NewReader(raw))
decoder.UseNumber()
Expand Down Expand Up @@ -1645,9 +1725,9 @@ func syncAuthFileMetadataFields(auth *coreauth.Auth, touchedRoots map[string]str
}
}
if _, ok := touchedRoots["proxy_url"]; ok {
if proxyURL, okString := auth.Metadata["proxy_url"].(string); okString {
auth.ProxyURL = strings.TrimSpace(proxyURL)
}
// A null or removed proxy_url clears the live setting, matching the saved file.
proxyURL, _ := auth.Metadata["proxy_url"].(string)
auth.ProxyURL = strings.TrimSpace(proxyURL)
}
if _, ok := touchedRoots["headers"]; ok {
syncAuthFileHeaderAttributes(auth)
Expand Down
13 changes: 12 additions & 1 deletion internal/api/handlers/management/config_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,18 @@ func (h *Handler) PutRoutingStrategy(c *gin.Context) {
// Proxy URL
func (h *Handler) GetProxyURL(c *gin.Context) { c.JSON(200, gin.H{"proxy-url": h.cfg.ProxyURL}) }
func (h *Handler) PutProxyURL(c *gin.Context) {
h.updateStringField(c, func(v string) { h.cfg.ProxyURL = v })
var body struct {
Value *string `json:"value"`
}
if err := c.ShouldBindJSON(&body); err != nil || body.Value == nil {
c.JSON(400, gin.H{"error": "invalid body"})
return
}
if rejectInvalidProxyURL(c, "proxy-url", *body.Value) {
return
}
h.cfg.ProxyURL = *body.Value
h.persist(c)
}
func (h *Handler) DeleteProxyURL(c *gin.Context) {
h.cfg.ProxyURL = ""
Expand Down
Loading
Loading